2 This file is part of GNUnet
3 Copyright (C) 2010-2014, 2018 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file transport/gnunet-communicator-unix.c
23 * @brief Transport plugin using unix domain sockets (!)
24 * Clearly, can only be used locally on Unix/Linux hosts...
25 * ONLY INTENDED FOR TESTING!!!
26 * @author Christian Grothoff
27 * @author Nathan Evans
30 #include "gnunet_util_lib.h"
31 #include "gnunet_protocols.h"
32 #include "gnunet_constants.h"
33 #include "gnunet_nt_lib.h"
34 #include "gnunet_statistics_service.h"
35 #include "gnunet_transport_communication_service.h"
38 * How many messages do we keep at most in the queue to the
39 * transport service before we start to drop (default,
40 * can be changed via the configuration file).
41 * Should be _below_ the level of the communicator API, as
42 * otherwise we may read messages just to have them dropped
43 * by the communicator API.
45 #define DEFAULT_MAX_QUEUE_LENGTH 8
48 * Address prefix used by the communicator.
50 #define COMMUNICATOR_ADDRESS_PREFIX "unix"
53 * Configuration section used by the communicator.
55 #define COMMUNICATOR_CONFIG_SECTION "communicator-unix"
60 #define UNIX_MTU UINT16_MAX
62 GNUNET_NETWORK_STRUCT_BEGIN
65 * UNIX Message-Packet header.
72 struct GNUNET_MessageHeader header;
75 * What is the identity of the sender (GNUNET_hash of public key)
77 struct GNUNET_PeerIdentity sender;
80 GNUNET_NETWORK_STRUCT_END
89 * Queues with pending messages (!) are kept in a DLL.
94 * Queues with pending messages (!) are kept in a DLL.
99 * To whom are we talking to.
101 struct GNUNET_PeerIdentity target;
104 * Address of the other peer.
106 struct sockaddr_un *address;
109 * Length of the address.
111 socklen_t address_len;
114 * Message currently scheduled for transmission, non-NULL if and only
115 * if this queue is in the #queue_head DLL.
117 struct UNIXMessage *msg;
120 * Message queue we are providing for the #ch.
122 struct GNUNET_MQ_Handle *mq;
125 * handle for this queue with the #ch.
127 struct GNUNET_TRANSPORT_QueueHandle *qh;
130 * Number of bytes we currently have in our write queue.
132 unsigned long long bytes_in_queue;
135 * Timeout for this queue.
137 struct GNUNET_TIME_Absolute timeout;
140 * Queue timeout task.
142 struct GNUNET_SCHEDULER_Task *timeout_task;
148 static struct GNUNET_PeerIdentity my_identity;
153 static struct GNUNET_SCHEDULER_Task *read_task;
158 static struct GNUNET_SCHEDULER_Task *write_task;
161 * Number of messages we currently have in our queues towards the transport service.
163 static unsigned long long delivering_messages;
166 * Maximum queue length before we stop reading towards the transport service.
168 static unsigned long long max_queue_length;
171 * For logging statistics.
173 static struct GNUNET_STATISTICS_Handle *stats;
178 static struct GNUNET_TRANSPORT_CommunicatorHandle *ch;
181 * Queues (map from peer identity to `struct Queue`)
183 static struct GNUNET_CONTAINER_MultiPeerMap *queue_map;
186 * Head of queue of messages to transmit.
188 static struct Queue *queue_head;
191 * Tail of queue of messages to transmit.
193 static struct Queue *queue_tail;
196 * socket that we transmit all data with
198 static struct GNUNET_NETWORK_Handle *unix_sock;
201 * Handle to the operation that publishes our address.
203 static struct GNUNET_TRANSPORT_AddressIdentifier *ai;
207 * Functions with this signature are called whenever we need
208 * to close a queue due to a disconnect or failure to
209 * establish a connection.
211 * @param queue queue to close down
214 queue_destroy (struct Queue *queue)
216 struct GNUNET_MQ_Handle *mq;
218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
219 "Disconnecting queue for peer `%s'\n",
220 GNUNET_i2s (&queue->target));
221 if (0 != queue->bytes_in_queue)
223 GNUNET_CONTAINER_DLL_remove (queue_head, queue_tail, queue);
224 queue->bytes_in_queue = 0;
226 if (NULL != (mq = queue->mq))
229 GNUNET_MQ_destroy (mq);
233 GNUNET_CONTAINER_multipeermap_remove (queue_map, &queue->target, queue));
234 GNUNET_STATISTICS_set (stats,
236 GNUNET_CONTAINER_multipeermap_size (queue_map),
238 if (NULL != queue->timeout_task)
240 GNUNET_SCHEDULER_cancel (queue->timeout_task);
241 queue->timeout_task = NULL;
243 GNUNET_free (queue->address);
249 * Queue was idle for too long, so disconnect it
251 * @param cls the `struct Queue *` to disconnect
254 queue_timeout (void *cls)
256 struct Queue *queue = cls;
257 struct GNUNET_TIME_Relative left;
259 queue->timeout_task = NULL;
260 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
261 if (0 != left.rel_value_us)
263 /* not actually our turn yet, but let's at least update
264 the monitor, it may think we're about to die ... */
265 queue->timeout_task =
266 GNUNET_SCHEDULER_add_delayed (left, &queue_timeout, queue);
269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
270 "Queue %p was idle for %s, disconnecting\n",
272 GNUNET_STRINGS_relative_time_to_string (
273 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
275 queue_destroy (queue);
280 * Increment queue timeout due to activity. We do not immediately
281 * notify the monitor here as that might generate excessive
284 * @param queue queue for which the timeout should be rescheduled
287 reschedule_queue_timeout (struct Queue *queue)
289 GNUNET_assert (NULL != queue->timeout_task);
291 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
296 * Convert unix path to a `struct sockaddr_un *`
298 * @param unixpath path to convert
299 * @param[out] sock_len set to the length of the address
300 * @param is_abstract is this an abstract @a unixpath
301 * @return converted unix path
303 static struct sockaddr_un *
304 unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len)
306 struct sockaddr_un *un;
309 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
310 un = GNUNET_new (struct sockaddr_un);
311 un->sun_family = AF_UNIX;
312 slen = strlen (unixpath);
313 if (slen >= sizeof(un->sun_path))
314 slen = sizeof(un->sun_path) - 1;
315 GNUNET_memcpy (un->sun_path, unixpath, slen);
316 un->sun_path[slen] = '\0';
317 slen = sizeof(struct sockaddr_un);
318 #if HAVE_SOCKADDR_UN_SUN_LEN
319 un->sun_len = (u_char) slen;
322 if ('@' == un->sun_path[0])
323 un->sun_path[0] = '\0';
329 * Closure to #lookup_queue_it().
334 * Location to store the queue, if found.
339 * Address we are looking for.
341 const struct sockaddr_un *un;
344 * Number of bytes in @a un
351 * Function called to find a queue by address.
353 * @param cls the `struct LookupCtx *`
354 * @param key peer we are looking for (unused)
355 * @param value a queue
356 * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success
359 lookup_queue_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
361 struct LookupCtx *lctx = cls;
362 struct Queue *queue = value;
364 if ((queue->address_len == lctx->un_len) &&
365 (0 == memcmp (lctx->un, queue->address, queue->address_len)))
375 * Find an existing queue by address.
377 * @param plugin the plugin
378 * @param address the address to find
379 * @return NULL if queue was not found
381 static struct Queue *
382 lookup_queue (const struct GNUNET_PeerIdentity *peer,
383 const struct sockaddr_un *un,
386 struct LookupCtx lctx;
389 lctx.un_len = un_len;
391 GNUNET_CONTAINER_multipeermap_get_multiple (queue_map,
400 * We have been notified that our socket is ready to write.
401 * Then reschedule this function to be called again once more is available.
406 select_write_cb (void *cls)
408 struct Queue *queue = queue_tail;
409 const struct GNUNET_MessageHeader *msg = &queue->msg->header;
410 size_t msg_size = ntohs (msg->size);
413 /* take queue of the ready list */
415 GNUNET_CONTAINER_DLL_remove (queue_head, queue_tail, queue);
416 if (NULL != queue_head)
417 write_task = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
424 GNUNET_MQ_impl_send_continue (queue->mq);
427 sent = GNUNET_NETWORK_socket_sendto (unix_sock,
430 (const struct sockaddr *) queue->address,
432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
433 "UNIX transmitted message to %s (%d/%u: %s)\n",
434 GNUNET_i2s (&queue->target),
436 (unsigned int) msg_size,
437 (sent < 0) ? strerror (errno) : "ok");
440 GNUNET_STATISTICS_update (stats,
444 reschedule_queue_timeout (queue);
445 return; /* all good */
447 GNUNET_STATISTICS_update (stats,
448 "# network transmission failures",
455 /* We should retry later... */
456 GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send");
461 socklen_t len = sizeof(size);
463 GNUNET_NETWORK_socket_getsockopt (unix_sock,
468 if (size > ntohs (msg->size))
470 /* Buffer is bigger than message: error, no retry
471 * This should never happen!*/
476 GNUNET_ERROR_TYPE_DEBUG,
477 "Trying to increase socket buffer size from %u to %u for message size %u\n",
479 (unsigned int) ((msg_size / 1000) + 2) * 1000,
480 (unsigned int) msg_size);
481 size = ((msg_size / 1000) + 2) * 1000;
482 if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt (unix_sock,
487 goto resend; /* Increased buffer size, retry sending */
488 /* Ok, then just try very modest increase */
490 if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt (unix_sock,
495 goto resend; /* Increased buffer size, retry sending */
496 /* Could not increase buffer size: error, no retry */
497 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt");
502 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "send");
509 * Signature of functions implementing the sending functionality of a
512 * @param mq the message queue
513 * @param msg the message to send
514 * @param impl_state our `struct Queue`
517 mq_send (struct GNUNET_MQ_Handle *mq,
518 const struct GNUNET_MessageHeader *msg,
521 struct Queue *queue = impl_state;
522 size_t msize = ntohs (msg->size);
524 GNUNET_assert (mq == queue->mq);
525 GNUNET_assert (NULL == queue->msg);
526 //Convert to UNIXMessage
527 queue->msg = GNUNET_malloc (msize + sizeof (struct UNIXMessage));
528 queue->msg->header.size = htons(msize + sizeof (struct UNIXMessage));
529 queue->msg->sender = my_identity;
530 memcpy (&queue->msg[1], msg, msize);
531 GNUNET_CONTAINER_DLL_insert (queue_head, queue_tail, queue);
532 GNUNET_assert (NULL != unix_sock);
533 if (NULL == write_task)
534 write_task = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
542 * Signature of functions implementing the destruction of a message
543 * queue. Implementations must not free @a mq, but should take care
546 * @param mq the message queue to destroy
547 * @param impl_state our `struct Queue`
550 mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
552 struct Queue *queue = impl_state;
557 queue_destroy (queue);
563 * Implementation function that cancels the currently sent message.
565 * @param mq message queue
566 * @param impl_state our `struct Queue`
569 mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
571 struct Queue *queue = impl_state;
573 GNUNET_assert (NULL != queue->msg);
575 GNUNET_CONTAINER_DLL_remove (queue_head, queue_tail, queue);
576 GNUNET_assert (NULL != write_task);
577 if (NULL == queue_head)
579 GNUNET_SCHEDULER_cancel (write_task);
586 * Generic error handler, called with the appropriate
587 * error code and the same closure specified at the creation of
589 * Not every message queue implementation supports an error handler.
591 * @param cls our `struct Queue`
592 * @param error error code
595 mq_error (void *cls, enum GNUNET_MQ_Error error)
597 struct Queue *queue = cls;
599 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
600 "UNIX MQ error in queue to %s: %d\n",
601 GNUNET_i2s (&queue->target),
603 queue_destroy (queue);
608 * Creates a new outbound queue the transport service will use to send
609 * data to another peer.
611 * @param peer the target peer
612 * @param cs inbound or outbound queue
613 * @param un the address
614 * @param un_len number of bytes in @a un
615 * @return the queue or NULL of max connections exceeded
617 static struct Queue *
618 setup_queue (const struct GNUNET_PeerIdentity *target,
619 enum GNUNET_TRANSPORT_ConnectionStatus cs,
620 const struct sockaddr_un *un,
625 queue = GNUNET_new (struct Queue);
626 queue->target = *target;
627 queue->address = GNUNET_memdup (un, un_len);
628 queue->address_len = un_len;
629 (void) GNUNET_CONTAINER_multipeermap_put (
633 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
634 GNUNET_STATISTICS_set (stats,
636 GNUNET_CONTAINER_multipeermap_size (queue_map),
639 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
640 queue->timeout_task =
641 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
644 queue->mq = GNUNET_MQ_queue_for_callbacks (&mq_send,
654 if ('\0' == un->sun_path[0])
655 GNUNET_asprintf (&foreign_addr,
657 COMMUNICATOR_ADDRESS_PREFIX,
660 GNUNET_asprintf (&foreign_addr,
662 COMMUNICATOR_ADDRESS_PREFIX,
664 queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch,
671 GNUNET_free (foreign_addr);
678 * We have been notified that our socket has something to read. Do the
679 * read and reschedule this function to be called again once more is
685 select_read_cb (void *cls);
689 * Function called when message was successfully passed to
690 * transport service. Continue read activity.
693 * @param success #GNUNET_OK on success
696 receive_complete_cb (void *cls, int success)
699 delivering_messages--;
700 if (GNUNET_OK != success)
701 GNUNET_STATISTICS_update (stats,
702 "# transport transmission failures",
705 GNUNET_assert (NULL != unix_sock);
706 if ((NULL == read_task) && (delivering_messages < max_queue_length))
707 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
715 * We have been notified that our socket has something to read. Do the
716 * read and reschedule this function to be called again once more is
722 select_read_cb (void *cls)
724 char buf[65536] GNUNET_ALIGN;
726 const struct UNIXMessage *msg;
727 struct sockaddr_un un;
732 GNUNET_assert (NULL != unix_sock);
733 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
737 addrlen = sizeof(un);
738 memset (&un, 0, sizeof(un));
739 ret = GNUNET_NETWORK_socket_recvfrom (unix_sock,
742 (struct sockaddr *) &un,
744 if ((-1 == ret) && ((EAGAIN == errno) || (ENOBUFS == errno)))
748 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom");
751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
752 "Read %d bytes from socket %s\n",
755 GNUNET_assert (AF_UNIX == (un.sun_family));
756 msg = (struct UNIXMessage *) buf;
757 msize = ntohs (msg->header.size);
758 if ((msize < sizeof(struct UNIXMessage)) || (msize > ret))
760 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
761 "Wrong message size: %d bytes\n",
766 queue = lookup_queue (&msg->sender, &un, addrlen);
769 setup_queue (&msg->sender, GNUNET_TRANSPORT_CS_INBOUND, &un, addrlen);
771 reschedule_queue_timeout (queue);
775 GNUNET_ERROR_TYPE_ERROR,
777 "Maximum number of UNIX connections exceeded, dropping incoming message\n"));
783 uint16_t tsize = msize - sizeof(struct UNIXMessage);
784 const char *msgbuf = (const char *) &msg[1];
786 while (offset + sizeof(struct GNUNET_MessageHeader) <= tsize)
788 const struct GNUNET_MessageHeader *currhdr;
789 struct GNUNET_MessageHeader al_hdr;
792 currhdr = (const struct GNUNET_MessageHeader *) &msgbuf[offset];
793 /* ensure aligned access */
794 memcpy (&al_hdr, currhdr, sizeof(al_hdr));
795 csize = ntohs (al_hdr.size);
796 if ((csize < sizeof(struct GNUNET_MessageHeader)) ||
797 (csize > tsize - offset))
802 ret = GNUNET_TRANSPORT_communicator_receive (ch,
805 GNUNET_TIME_UNIT_FOREVER_REL,
806 &receive_complete_cb,
808 if (GNUNET_SYSERR == ret)
809 return; /* transport not up */
810 if (GNUNET_NO == ret)
812 delivering_messages++;
816 if (delivering_messages >= max_queue_length)
818 /* we should try to apply 'back pressure' */
819 GNUNET_SCHEDULER_cancel (read_task);
826 * Function called by the transport service to initialize a
827 * message queue given address information about another peer.
828 * If and when the communication channel is established, the
829 * communicator must call #GNUNET_TRANSPORT_communicator_mq_add()
830 * to notify the service that the channel is now up. It is
831 * the responsibility of the communicator to manage sane
832 * retries and timeouts for any @a peer/@a address combination
833 * provided by the transport service. Timeouts and retries
834 * do not need to be signalled to the transport service.
837 * @param peer identity of the other peer
838 * @param address where to send the message, human-readable
839 * communicator-specific format, 0-terminated, UTF-8
840 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is invalid
843 mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
847 struct sockaddr_un *un;
851 if (0 != strncmp (address,
852 COMMUNICATOR_ADDRESS_PREFIX "-",
853 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
856 return GNUNET_SYSERR;
858 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
859 un = unix_address_to_sockaddr (path, &un_len);
860 queue = lookup_queue (peer, un, un_len);
863 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
864 "Address `%s' for %s ignored, queue exists\n",
870 queue = setup_queue (peer, GNUNET_TRANSPORT_CS_OUTBOUND, un, un_len);
874 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
875 "Failed to setup queue to %s at `%s'\n",
885 * Iterator over all message queues to clean up.
888 * @param target unused
889 * @param value the queue to destroy
890 * @return #GNUNET_OK to continue to iterate
893 get_queue_delete_it (void *cls,
894 const struct GNUNET_PeerIdentity *target,
897 struct Queue *queue = value;
901 queue_destroy (queue);
907 * Shutdown the UNIX communicator.
909 * @param cls NULL (always)
912 do_shutdown (void *cls)
914 if (NULL != read_task)
916 GNUNET_SCHEDULER_cancel (read_task);
919 if (NULL != write_task)
921 GNUNET_SCHEDULER_cancel (write_task);
924 if (NULL != unix_sock)
926 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (unix_sock));
929 GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL);
930 GNUNET_CONTAINER_multipeermap_destroy (queue_map);
933 GNUNET_TRANSPORT_communicator_address_remove (ai);
938 GNUNET_TRANSPORT_communicator_disconnect (ch);
943 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
950 * Function called when the transport service has received an
951 * acknowledgement for this communicator (!) via a different return
954 * Not applicable for UNIX.
957 * @param sender which peer sent the notification
961 enc_notify_cb (void *cls,
962 const struct GNUNET_PeerIdentity *sender,
963 const struct GNUNET_MessageHeader *msg)
973 * Setup communicator and launch network interactions.
975 * @param cls NULL (always)
976 * @param args remaining command-line arguments
977 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
978 * @param cfg configuration
984 const struct GNUNET_CONFIGURATION_Handle *cfg)
986 char *unix_socket_path;
987 struct sockaddr_un *un;
990 struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
994 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
995 if (NULL == my_private_key)
998 GNUNET_ERROR_TYPE_ERROR,
1000 "UNIX communicator is lacking key configuration settings. Exiting.\n"));
1001 GNUNET_SCHEDULER_shutdown ();
1004 GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key);
1007 GNUNET_CONFIGURATION_get_value_filename (cfg,
1008 COMMUNICATOR_CONFIG_SECTION,
1012 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1013 COMMUNICATOR_CONFIG_SECTION,
1018 GNUNET_CONFIGURATION_get_value_number (cfg,
1019 COMMUNICATOR_CONFIG_SECTION,
1022 max_queue_length = DEFAULT_MAX_QUEUE_LENGTH;
1024 un = unix_address_to_sockaddr (unix_socket_path, &un_len);
1027 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1028 "Failed to setup UNIX domain socket address with path `%s'\n",
1030 GNUNET_free (unix_socket_path);
1033 unix_sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0);
1034 if (NULL == unix_sock)
1036 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
1038 GNUNET_free (unix_socket_path);
1041 if (('\0' != un->sun_path[0]) &&
1042 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path)))
1044 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1045 _ ("Cannot create path to `%s'\n"),
1047 GNUNET_NETWORK_socket_close (unix_sock);
1050 GNUNET_free (unix_socket_path);
1053 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (unix_sock,
1054 (const struct sockaddr *) un,
1057 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", un->sun_path);
1058 GNUNET_NETWORK_socket_close (unix_sock);
1061 GNUNET_free (unix_socket_path);
1065 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", unix_socket_path);
1066 stats = GNUNET_STATISTICS_create ("C-UNIX", cfg);
1067 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
1068 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1072 queue_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1073 ch = GNUNET_TRANSPORT_communicator_connect (cfg,
1074 COMMUNICATOR_CONFIG_SECTION,
1075 COMMUNICATOR_ADDRESS_PREFIX,
1076 GNUNET_TRANSPORT_CC_RELIABLE,
1084 GNUNET_SCHEDULER_shutdown ();
1085 GNUNET_free (unix_socket_path);
1088 GNUNET_asprintf (&my_addr,
1090 COMMUNICATOR_ADDRESS_PREFIX,
1092 GNUNET_free (unix_socket_path);
1093 ai = GNUNET_TRANSPORT_communicator_address_add (ch,
1096 GNUNET_TIME_UNIT_FOREVER_REL);
1097 GNUNET_free (my_addr);
1102 * The main function for the UNIX communicator.
1104 * @param argc number of arguments from the command line
1105 * @param argv command line arguments
1106 * @return 0 ok, 1 on error
1109 main (int argc, char *const *argv)
1111 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1112 GNUNET_GETOPT_OPTION_END
1116 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1120 GNUNET_PROGRAM_run (argc,
1122 "gnunet-communicator-unix",
1123 _ ("GNUnet UNIX domain socket communicator"),
1129 GNUNET_free ((void *) argv);
1134 #if defined(__linux__) && defined(__GLIBC__)
1138 * MINIMIZE heap size (way below 128k) since this process doesn't need much.
1140 void __attribute__ ((constructor))
1141 GNUNET_ARM_memory_init ()
1143 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
1144 mallopt (M_TOP_PAD, 1 * 1024);
1151 /* end of gnunet-communicator-unix.c */