2 This file is part of GNUnet
3 Copyright (C) 2010-2014 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file transport/plugin_transport_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_hello_lib.h"
32 #include "gnunet_protocols.h"
33 #include "gnunet_statistics_service.h"
34 #include "gnunet_transport_service.h"
35 #include "gnunet_transport_plugin.h"
36 #include "transport.h"
40 * Return code we give on 'send' if we failed to send right now
41 * but it makes sense to retry later. (Note: we might want to
42 * move this to the plugin API!?).
49 #define PLUGIN_NAME "unix"
52 * Options for UNIX Domain addresses.
54 enum UNIX_ADDRESS_OPTIONS
59 UNIX_OPTIONS_NONE = 0,
62 * Linux abstract domain sockets should be used.
64 UNIX_OPTIONS_USE_ABSTRACT_SOCKETS = 1
69 * How long until we give up on transmitting the welcome message?
71 #define HOSTNAME_RESOLVE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
73 #define LOG(kind,...) GNUNET_log_from (kind, "transport-unix",__VA_ARGS__)
76 GNUNET_NETWORK_STRUCT_BEGIN
79 * Binary format for an UNIX Domain Socket address in GNUnet.
84 * Options to use for the address, in NBO
86 uint32_t options GNUNET_PACKED;
89 * Length of the address (path length), in NBO
91 uint32_t addrlen GNUNET_PACKED;
93 /* followed by actual path */
98 * UNIX Message-Packet header.
105 struct GNUNET_MessageHeader header;
108 * What is the identity of the sender (GNUNET_hash of public key)
110 struct GNUNET_PeerIdentity sender;
114 GNUNET_NETWORK_STRUCT_END
118 * Information we track for a message awaiting transmission.
120 struct UNIXMessageWrapper
123 * We keep messages in a doubly linked list.
125 struct UNIXMessageWrapper *next;
128 * We keep messages in a doubly linked list.
130 struct UNIXMessageWrapper *prev;
133 * The actual payload (allocated separately right now).
135 struct UNIXMessage *msg;
138 * Session this message belongs to.
140 struct GNUNET_ATS_Session *session;
143 * Function to call upon transmission.
145 GNUNET_TRANSPORT_TransmitContinuation cont;
148 * Closure for @e cont.
153 * Timeout for this message.
155 struct GNUNET_TIME_Absolute timeout;
158 * Number of bytes in @e msg.
163 * Number of bytes of payload encapsulated in @e msg.
168 * Priority of the message (ignored, just dragged along in UNIX).
170 unsigned int priority;
175 * Handle for a session.
177 struct GNUNET_ATS_Session
181 * Sessions with pending messages (!) are kept in a DLL.
183 struct GNUNET_ATS_Session *next;
186 * Sessions with pending messages (!) are kept in a DLL.
188 struct GNUNET_ATS_Session *prev;
191 * To whom are we talking to (set to our identity
192 * if we are still waiting for the welcome message).
194 * FIXME: information duplicated with 'peer' in address!
196 struct GNUNET_PeerIdentity target;
199 * Pointer to the global plugin struct.
201 struct Plugin *plugin;
204 * Address of the other peer.
206 struct GNUNET_HELLO_Address *address;
209 * Number of bytes we currently have in our write queue.
211 unsigned long long bytes_in_queue;
214 * Timeout for this session.
216 struct GNUNET_TIME_Absolute timeout;
219 * Session timeout task.
221 struct GNUNET_SCHEDULER_Task * timeout_task;
224 * Number of messages we currently have in our write queue.
226 unsigned int msgs_in_queue;
232 * Encapsulation of all of the state of the plugin.
238 * Information we keep for each of our listen sockets.
240 struct UNIX_Sock_Info
245 struct GNUNET_NETWORK_Handle *desc;
250 * Encapsulation of all of the state of the plugin.
256 * ID of task used to update our addresses when one expires.
258 struct GNUNET_SCHEDULER_Task * address_update_task;
263 struct GNUNET_SCHEDULER_Task * read_task;
268 struct GNUNET_SCHEDULER_Task * write_task;
271 * Number of bytes we currently have in our write queues.
273 unsigned long long bytes_in_queue;
278 struct GNUNET_TRANSPORT_PluginEnvironment *env;
281 * Sessions (map from peer identity to `struct GNUNET_ATS_Session`)
283 struct GNUNET_CONTAINER_MultiPeerMap *session_map;
286 * Head of queue of messages to transmit.
288 struct UNIXMessageWrapper *msg_head;
291 * Tail of queue of messages to transmit.
293 struct UNIXMessageWrapper *msg_tail;
296 * Path of our unix domain socket (/tmp/unix-plugin)
298 char *unix_socket_path;
301 * Function to call about session status changes.
303 GNUNET_TRANSPORT_SessionInfoCallback sic;
306 * Closure for @e sic.
311 * socket that we transmit all data with
313 struct UNIX_Sock_Info unix_sock;
316 * Address options in HBO
321 * Are we using an abstract UNIX domain socket?
329 * If a session monitor is attached, notify it about the new
332 * @param plugin our plugin
333 * @param session session that changed state
334 * @param state new state of the session
337 notify_session_monitor (struct Plugin *plugin,
338 struct GNUNET_ATS_Session *session,
339 enum GNUNET_TRANSPORT_SessionState state)
341 struct GNUNET_TRANSPORT_SessionInfo info;
343 if (NULL == plugin->sic)
345 memset (&info, 0, sizeof (info));
347 info.is_inbound = GNUNET_SYSERR; /* hard to say */
348 info.num_msg_pending = session->msgs_in_queue;
349 info.num_bytes_pending = session->bytes_in_queue;
350 /* info.receive_delay remains zero as this is not supported by UNIX
351 (cannot selectively not receive from 'some' peer while continuing
352 to receive from others) */
353 info.session_timeout = session->timeout;
354 info.address = session->address;
355 plugin->sic (plugin->sic_cls,
362 * Function called for a quick conversion of the binary address to
363 * a numeric address. Note that the caller must not free the
364 * address and that the next call to this function is allowed
365 * to override the address again.
368 * @param addr binary address
369 * @param addrlen length of the @a addr
370 * @return string representing the same address
373 unix_plugin_address_to_string (void *cls,
377 static char rbuf[1024];
378 struct UnixAddress *ua = (struct UnixAddress *) addr;
383 if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen))
388 addrstr = (char *) &ua[1];
389 addr_str_len = ntohl (ua->addrlen);
391 if (addr_str_len != addrlen - sizeof(struct UnixAddress))
396 if ('\0' != addrstr[addr_str_len - 1])
401 if (strlen (addrstr) + 1 != addr_str_len)
408 if ('\0' == addrstr[0])
410 memset (rbuf, 0, sizeof (rbuf));
411 GNUNET_snprintf (rbuf,
416 (off == 1) ? "@" : "",
417 (int) (addr_str_len - off),
424 * Functions with this signature are called whenever we need
425 * to close a session due to a disconnect or failure to
426 * establish a connection.
428 * @param cls closure with the `struct Plugin *`
429 * @param session session to close down
430 * @return #GNUNET_OK on success
433 unix_plugin_session_disconnect (void *cls,
434 struct GNUNET_ATS_Session *session)
436 struct Plugin *plugin = cls;
437 struct UNIXMessageWrapper *msgw;
438 struct UNIXMessageWrapper *next;
440 LOG (GNUNET_ERROR_TYPE_DEBUG,
441 "Disconnecting session for peer `%s' `%s'\n",
442 GNUNET_i2s (&session->target),
443 unix_plugin_address_to_string (NULL,
444 session->address->address,
445 session->address->address_length));
446 plugin->env->session_end (plugin->env->cls,
449 next = plugin->msg_head;
454 if (msgw->session != session)
456 GNUNET_CONTAINER_DLL_remove (plugin->msg_head,
459 session->msgs_in_queue--;
460 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
461 session->bytes_in_queue -= msgw->msgsize;
462 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
463 plugin->bytes_in_queue -= msgw->msgsize;
464 if (NULL != msgw->cont)
465 msgw->cont (msgw->cont_cls,
466 &msgw->session->target,
469 GNUNET_free (msgw->msg);
472 GNUNET_assert (GNUNET_YES ==
473 GNUNET_CONTAINER_multipeermap_remove (plugin->session_map,
476 GNUNET_STATISTICS_set (plugin->env->stats,
477 "# UNIX sessions active",
478 GNUNET_CONTAINER_multipeermap_size (plugin->session_map),
480 if (NULL != session->timeout_task)
482 GNUNET_SCHEDULER_cancel (session->timeout_task);
483 session->timeout_task = NULL;
484 session->timeout = GNUNET_TIME_UNIT_ZERO_ABS;
486 notify_session_monitor (plugin,
488 GNUNET_TRANSPORT_SS_DONE);
489 GNUNET_HELLO_address_free (session->address);
490 GNUNET_break (0 == session->bytes_in_queue);
491 GNUNET_break (0 == session->msgs_in_queue);
492 GNUNET_free (session);
498 * Session was idle for too long, so disconnect it
500 * @param cls the `struct GNUNET_ATS_Session *` to disconnect
501 * @param tc scheduler context
504 session_timeout (void *cls,
505 const struct GNUNET_SCHEDULER_TaskContext *tc)
507 struct GNUNET_ATS_Session *session = cls;
508 struct GNUNET_TIME_Relative left;
510 session->timeout_task = NULL;
511 left = GNUNET_TIME_absolute_get_remaining (session->timeout);
512 if (0 != left.rel_value_us)
514 /* not actually our turn yet, but let's at least update
515 the monitor, it may think we're about to die ... */
516 notify_session_monitor (session->plugin,
518 GNUNET_TRANSPORT_SS_UPDATE);
519 session->timeout_task = GNUNET_SCHEDULER_add_delayed (left,
524 LOG (GNUNET_ERROR_TYPE_DEBUG,
525 "Session %p was idle for %s, disconnecting\n",
527 GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
529 unix_plugin_session_disconnect (session->plugin, session);
534 * Increment session timeout due to activity. We do not immediately
535 * notify the monitor here as that might generate excessive
538 * @param session session for which the timeout should be rescheduled
541 reschedule_session_timeout (struct GNUNET_ATS_Session *session)
543 GNUNET_assert (NULL != session->timeout_task);
544 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
549 * Convert unix path to a `struct sockaddr_un *`
551 * @param unixpath path to convert
552 * @param[out] sock_len set to the length of the address
553 * @return converted unix path
555 static struct sockaddr_un *
556 unix_address_to_sockaddr (const char *unixpath,
559 struct sockaddr_un *un;
562 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
563 un = GNUNET_new (struct sockaddr_un);
564 un->sun_family = AF_UNIX;
565 slen = strlen (unixpath);
566 if (slen >= sizeof (un->sun_path))
567 slen = sizeof (un->sun_path) - 1;
568 memcpy (un->sun_path, unixpath, slen);
569 un->sun_path[slen] = '\0';
570 slen = sizeof (struct sockaddr_un);
571 #if HAVE_SOCKADDR_IN_SIN_LEN
572 un->sun_len = (u_char) slen;
580 * Closure to #lookup_session_it().
585 * Location to store the session, if found.
587 struct GNUNET_ATS_Session *res;
590 * Address we are looking for.
592 const struct GNUNET_HELLO_Address *address;
597 * Function called to find a session by address.
599 * @param cls the `struct LookupCtx *`
600 * @param key peer we are looking for (unused)
601 * @param value a session
602 * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success
605 lookup_session_it (void *cls,
606 const struct GNUNET_PeerIdentity * key,
609 struct LookupCtx *lctx = cls;
610 struct GNUNET_ATS_Session *session = value;
612 if (0 == GNUNET_HELLO_address_cmp (lctx->address,
623 * Find an existing session by address.
625 * @param plugin the plugin
626 * @param address the address to find
627 * @return NULL if session was not found
629 static struct GNUNET_ATS_Session *
630 lookup_session (struct Plugin *plugin,
631 const struct GNUNET_HELLO_Address *address)
633 struct LookupCtx lctx;
635 lctx.address = address;
637 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map,
639 &lookup_session_it, &lctx);
645 * Function that is called to get the keepalive factor.
646 * #GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to
647 * calculate the interval between keepalive packets.
649 * @param cls closure with the `struct Plugin`
650 * @return keepalive factor
653 unix_plugin_query_keepalive_factor (void *cls)
660 * Actually send out the message, assume we've got the address and
661 * send_handle squared away!
664 * @param send_handle which handle to send message on
665 * @param target who should receive this message (ignored by UNIX)
666 * @param msgbuf one or more GNUNET_MessageHeader(s) strung together
667 * @param msgbuf_size the size of the @a msgbuf to send
668 * @param priority how important is the message (ignored by UNIX)
669 * @param timeout when should we time out (give up) if we can not transmit?
670 * @param addr the addr to send the message to, needs to be a sockaddr for us
671 * @param addrlen the len of @a addr
672 * @param payload bytes payload to send
673 * @param cont continuation to call once the message has
674 * been transmitted (or if the transport is ready
675 * for the next transmission call; or if the
676 * peer disconnected...)
677 * @param cont_cls closure for @a cont
678 * @return on success the number of bytes written, RETRY for retry, -1 on errors
681 unix_real_send (void *cls,
682 struct GNUNET_NETWORK_Handle *send_handle,
683 const struct GNUNET_PeerIdentity *target,
686 unsigned int priority,
687 struct GNUNET_TIME_Absolute timeout,
688 const struct UnixAddress *addr,
691 GNUNET_TRANSPORT_TransmitContinuation cont,
694 struct Plugin *plugin = cls;
696 struct sockaddr_un *un;
698 const char *unixpath;
700 if (NULL == send_handle)
702 GNUNET_break (0); /* We do not have a send handle */
703 return GNUNET_SYSERR;
705 if ((NULL == addr) || (0 == addrlen))
707 GNUNET_break (0); /* Can never send if we don't have an address */
708 return GNUNET_SYSERR;
711 /* Prepare address */
712 unixpath = (const char *) &addr[1];
713 if (NULL == (un = unix_address_to_sockaddr (unixpath,
720 if ((GNUNET_YES == plugin->is_abstract) &&
721 (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl(addr->options) )) )
723 un->sun_path[0] = '\0';
727 sent = GNUNET_NETWORK_socket_sendto (send_handle,
730 (const struct sockaddr *) un,
732 if (GNUNET_SYSERR == sent)
734 if ( (EAGAIN == errno) ||
738 return RETRY; /* We have to retry later */
740 if (EMSGSIZE == errno)
743 socklen_t len = sizeof (size);
745 GNUNET_NETWORK_socket_getsockopt ((struct GNUNET_NETWORK_Handle *)
746 send_handle, SOL_SOCKET, SO_SNDBUF, &size,
748 if (size < msgbuf_size)
750 LOG (GNUNET_ERROR_TYPE_DEBUG,
751 "Trying to increase socket buffer size from %u to %u for message size %u\n",
753 (unsigned int) ((msgbuf_size / 1000) + 2) * 1000,
754 (unsigned int) msgbuf_size);
755 size = ((msgbuf_size / 1000) + 2) * 1000;
757 GNUNET_NETWORK_socket_setsockopt ((struct GNUNET_NETWORK_Handle *) send_handle,
758 SOL_SOCKET, SO_SNDBUF,
759 &size, sizeof (size)))
760 goto resend; /* Increased buffer size, retry sending */
763 /* Could not increase buffer size: error, no retry */
764 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt");
766 return GNUNET_SYSERR;
771 /* Buffer is bigger than message: error, no retry
772 * This should never happen!*/
775 return GNUNET_SYSERR;
780 LOG (GNUNET_ERROR_TYPE_DEBUG,
781 "UNIX transmitted %u-byte message to %s (%d: %s)\n",
782 (unsigned int) msgbuf_size,
783 GNUNET_a2s ((const struct sockaddr *)un, un_len),
785 (sent < 0) ? STRERROR (errno) : "ok");
792 * Function obtain the network type for a session
794 * @param cls closure ('struct Plugin*')
795 * @param session the session
796 * @return the network type in HBO or #GNUNET_SYSERR
798 static enum GNUNET_ATS_Network_Type
799 unix_plugin_get_network (void *cls,
800 struct GNUNET_ATS_Session *session)
802 GNUNET_assert (NULL != session);
803 return GNUNET_ATS_NET_LOOPBACK;
808 * Function obtain the network type for a session
810 * @param cls closure (`struct Plugin *`)
811 * @param address the address
812 * @return the network type
814 static enum GNUNET_ATS_Network_Type
815 unix_plugin_get_network_for_address (void *cls,
816 const struct GNUNET_HELLO_Address *address)
819 return GNUNET_ATS_NET_LOOPBACK;
824 * Creates a new outbound session the transport service will use to send data to the
827 * @param cls the plugin
828 * @param address the address
829 * @return the session or NULL of max connections exceeded
831 static struct GNUNET_ATS_Session *
832 unix_plugin_get_session (void *cls,
833 const struct GNUNET_HELLO_Address *address)
835 struct Plugin *plugin = cls;
836 struct GNUNET_ATS_Session *session;
837 struct UnixAddress *ua;
839 uint32_t addr_str_len;
840 uint32_t addr_option;
842 ua = (struct UnixAddress *) address->address;
843 if ((NULL == address->address) || (0 == address->address_length) ||
844 (sizeof (struct UnixAddress) > address->address_length))
849 addrstr = (char *) &ua[1];
850 addr_str_len = ntohl (ua->addrlen);
851 addr_option = ntohl (ua->options);
853 if ( (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & addr_option)) &&
854 (GNUNET_NO == plugin->is_abstract))
859 if (addr_str_len != address->address_length - sizeof (struct UnixAddress))
861 return NULL; /* This can be a legacy address */
864 if ('\0' != addrstr[addr_str_len - 1])
869 if (strlen (addrstr) + 1 != addr_str_len)
875 /* Check if a session for this address already exists */
876 if (NULL != (session = lookup_session (plugin,
879 LOG (GNUNET_ERROR_TYPE_DEBUG,
880 "Found existing session %p for address `%s'\n",
882 unix_plugin_address_to_string (NULL,
884 address->address_length));
888 /* create a new session */
889 session = GNUNET_new (struct GNUNET_ATS_Session);
890 session->target = address->peer;
891 session->address = GNUNET_HELLO_address_copy (address);
892 session->plugin = plugin;
893 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
894 session->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
897 LOG (GNUNET_ERROR_TYPE_DEBUG,
898 "Creating a new session %p for address `%s'\n",
900 unix_plugin_address_to_string (NULL,
902 address->address_length));
903 (void) GNUNET_CONTAINER_multipeermap_put (plugin->session_map,
904 &address->peer, session,
905 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
906 GNUNET_STATISTICS_set (plugin->env->stats,
907 "# UNIX sessions active",
908 GNUNET_CONTAINER_multipeermap_size (plugin->session_map),
910 notify_session_monitor (plugin,
912 GNUNET_TRANSPORT_SS_INIT);
913 notify_session_monitor (plugin,
915 GNUNET_TRANSPORT_SS_UP);
921 * Function that will be called whenever the transport service wants
922 * to notify the plugin that a session is still active and in use and
923 * therefore the session timeout for this session has to be updated
925 * @param cls closure with the `struct Plugin *`
926 * @param peer which peer was the session for
927 * @param session which session is being updated
930 unix_plugin_update_session_timeout (void *cls,
931 const struct GNUNET_PeerIdentity *peer,
932 struct GNUNET_ATS_Session *session)
934 struct Plugin *plugin = cls;
937 GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map,
944 reschedule_session_timeout (session);
949 * Demultiplexer for UNIX messages
951 * @param plugin the main plugin for this transport
952 * @param sender from which peer the message was received
953 * @param currhdr pointer to the header of the message
954 * @param ua address to look for
955 * @param ua_len length of the address @a ua
958 unix_demultiplexer (struct Plugin *plugin,
959 struct GNUNET_PeerIdentity *sender,
960 const struct GNUNET_MessageHeader *currhdr,
961 const struct UnixAddress *ua,
964 struct GNUNET_ATS_Session *session;
965 struct GNUNET_HELLO_Address *address;
967 GNUNET_assert (ua_len >= sizeof (struct UnixAddress));
968 LOG (GNUNET_ERROR_TYPE_DEBUG,
969 "Received message from %s\n",
970 unix_plugin_address_to_string (NULL, ua, ua_len));
971 GNUNET_STATISTICS_update (plugin->env->stats,
972 "# bytes received via UNIX",
973 ntohs (currhdr->size),
976 /* Look for existing session */
977 address = GNUNET_HELLO_address_allocate (sender,
980 GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */
981 session = lookup_session (plugin, address);
984 session = unix_plugin_get_session (plugin, address);
985 /* Notify transport and ATS about new inbound session */
986 plugin->env->session_start (NULL,
989 GNUNET_ATS_NET_LOOPBACK);
993 reschedule_session_timeout (session);
995 GNUNET_HELLO_address_free (address);
996 plugin->env->receive (plugin->env->cls,
1004 * Read from UNIX domain socket (it is ready).
1006 * @param plugin the plugin
1009 unix_plugin_do_read (struct Plugin *plugin)
1011 char buf[65536] GNUNET_ALIGN;
1012 struct UnixAddress *ua;
1013 struct UNIXMessage *msg;
1014 struct GNUNET_PeerIdentity sender;
1015 struct sockaddr_un un;
1022 const struct GNUNET_MessageHeader *currhdr;
1026 addrlen = sizeof (un);
1027 memset (&un, 0, sizeof (un));
1028 ret = GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc,
1030 (struct sockaddr *) &un,
1032 if ((GNUNET_SYSERR == ret) && ((errno == EAGAIN) || (errno == ENOBUFS)))
1034 if (GNUNET_SYSERR == ret)
1036 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
1042 LOG (GNUNET_ERROR_TYPE_DEBUG,
1043 "Read %d bytes from socket %s\n",
1048 GNUNET_assert (AF_UNIX == (un.sun_family));
1049 is_abstract = GNUNET_NO;
1050 if ('\0' == un.sun_path[0])
1052 un.sun_path[0] = '@';
1053 is_abstract = GNUNET_YES;
1056 ua_len = sizeof (struct UnixAddress) + strlen (un.sun_path) + 1;
1057 ua = GNUNET_malloc (ua_len);
1058 ua->addrlen = htonl (strlen (&un.sun_path[0]) +1);
1059 memcpy (&ua[1], &un.sun_path[0], strlen (un.sun_path) + 1);
1061 ua->options = htonl(UNIX_OPTIONS_USE_ABSTRACT_SOCKETS);
1063 ua->options = htonl(UNIX_OPTIONS_NONE);
1065 msg = (struct UNIXMessage *) buf;
1066 csize = ntohs (msg->header.size);
1067 if ((csize < sizeof (struct UNIXMessage)) || (csize > ret))
1069 GNUNET_break_op (0);
1073 msgbuf = (char *) &msg[1];
1076 sizeof (struct GNUNET_PeerIdentity));
1078 tsize = csize - sizeof (struct UNIXMessage);
1079 while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize)
1081 currhdr = (struct GNUNET_MessageHeader *) &msgbuf[offset];
1082 csize = ntohs (currhdr->size);
1083 if ((csize < sizeof (struct GNUNET_MessageHeader)) ||
1084 (csize > tsize - offset))
1086 GNUNET_break_op (0);
1089 unix_demultiplexer (plugin, &sender, currhdr, ua, ua_len);
1097 * Write to UNIX domain socket (it is ready).
1099 * @param plugin handle to the plugin
1102 unix_plugin_do_write (struct Plugin *plugin)
1105 struct UNIXMessageWrapper *msgw;
1106 struct GNUNET_ATS_Session *session;
1110 did_delete = GNUNET_NO;
1111 while (NULL != (msgw = plugin->msg_head))
1113 if (GNUNET_TIME_absolute_get_remaining (msgw->timeout).rel_value_us > 0)
1114 break; /* Message is ready for sending */
1115 /* Message has a timeout */
1116 did_delete = GNUNET_YES;
1117 LOG (GNUNET_ERROR_TYPE_DEBUG,
1118 "Timeout for message with %u bytes \n",
1119 (unsigned int) msgw->msgsize);
1120 GNUNET_CONTAINER_DLL_remove (plugin->msg_head,
1123 session = msgw->session;
1124 session->msgs_in_queue--;
1125 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
1126 session->bytes_in_queue -= msgw->msgsize;
1127 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
1128 plugin->bytes_in_queue -= msgw->msgsize;
1129 GNUNET_STATISTICS_set (plugin->env->stats,
1130 "# bytes currently in UNIX buffers",
1131 plugin->bytes_in_queue,
1133 GNUNET_STATISTICS_update (plugin->env->stats,
1134 "# UNIX bytes discarded",
1137 if (NULL != msgw->cont)
1138 msgw->cont (msgw->cont_cls,
1139 &msgw->session->target,
1143 GNUNET_free (msgw->msg);
1148 if (GNUNET_YES == did_delete)
1149 notify_session_monitor (plugin,
1151 GNUNET_TRANSPORT_SS_UPDATE);
1152 return; /* Nothing to send at the moment */
1154 session = msgw->session;
1155 sent = unix_real_send (plugin,
1156 plugin->unix_sock.desc,
1158 (const char *) msgw->msg,
1162 msgw->session->address->address,
1163 msgw->session->address->address_length,
1165 msgw->cont, msgw->cont_cls);
1168 GNUNET_STATISTICS_update (plugin->env->stats,
1169 "# UNIX retry attempts",
1171 notify_session_monitor (plugin,
1173 GNUNET_TRANSPORT_SS_UPDATE);
1176 GNUNET_CONTAINER_DLL_remove (plugin->msg_head,
1179 session->msgs_in_queue--;
1180 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
1181 session->bytes_in_queue -= msgw->msgsize;
1182 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
1183 plugin->bytes_in_queue -= msgw->msgsize;
1184 GNUNET_STATISTICS_set (plugin->env->stats,
1185 "# bytes currently in UNIX buffers",
1186 plugin->bytes_in_queue, GNUNET_NO);
1187 notify_session_monitor (plugin,
1189 GNUNET_TRANSPORT_SS_UPDATE);
1190 if (GNUNET_SYSERR == sent)
1192 /* failed and no retry */
1193 if (NULL != msgw->cont)
1194 msgw->cont (msgw->cont_cls,
1195 &msgw->session->target,
1198 GNUNET_STATISTICS_update (plugin->env->stats,
1199 "# UNIX bytes discarded",
1202 GNUNET_free (msgw->msg);
1206 /* successfully sent bytes */
1207 GNUNET_break (sent > 0);
1208 GNUNET_STATISTICS_update (plugin->env->stats,
1209 "# bytes transmitted via UNIX",
1212 if (NULL != msgw->cont)
1213 msgw->cont (msgw->cont_cls,
1214 &msgw->session->target,
1218 GNUNET_free (msgw->msg);
1224 * We have been notified that our socket has something to read.
1225 * Then reschedule this function to be called again once more is available.
1227 * @param cls the plugin handle
1228 * @param tc the scheduling context
1231 unix_plugin_select_read (void *cls,
1232 const struct GNUNET_SCHEDULER_TaskContext *tc)
1234 struct Plugin *plugin = cls;
1236 plugin->read_task = NULL;
1237 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1239 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
1240 unix_plugin_do_read (plugin);
1242 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1243 plugin->unix_sock.desc,
1244 &unix_plugin_select_read, plugin);
1249 * We have been notified that our socket is ready to write.
1250 * Then reschedule this function to be called again once more is available.
1252 * @param cls the plugin handle
1253 * @param tc the scheduling context
1256 unix_plugin_select_write (void *cls,
1257 const struct GNUNET_SCHEDULER_TaskContext *tc)
1259 struct Plugin *plugin = cls;
1261 plugin->write_task = NULL;
1262 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1264 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))
1265 unix_plugin_do_write (plugin);
1266 if (NULL == plugin->msg_head)
1267 return; /* write queue empty */
1268 plugin->write_task =
1269 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
1270 plugin->unix_sock.desc,
1271 &unix_plugin_select_write, plugin);
1276 * Function that can be used by the transport service to transmit
1277 * a message using the plugin. Note that in the case of a
1278 * peer disconnecting, the continuation MUST be called
1279 * prior to the disconnect notification itself. This function
1280 * will be called with this peer's HELLO message to initiate
1281 * a fresh connection to another peer.
1283 * @param cls closure
1284 * @param session which session must be used
1285 * @param msgbuf the message to transmit
1286 * @param msgbuf_size number of bytes in @a msgbuf
1287 * @param priority how important is the message (most plugins will
1288 * ignore message priority and just FIFO)
1289 * @param to how long to wait at most for the transmission (does not
1290 * require plugins to discard the message after the timeout,
1291 * just advisory for the desired delay; most plugins will ignore
1293 * @param cont continuation to call once the message has
1294 * been transmitted (or if the transport is ready
1295 * for the next transmission call; or if the
1296 * peer disconnected...); can be NULL
1297 * @param cont_cls closure for @a cont
1298 * @return number of bytes used (on the physical network, with overheads);
1299 * -1 on hard errors (i.e. address invalid); 0 is a legal value
1300 * and does NOT mean that the message was not transmitted (DV)
1303 unix_plugin_send (void *cls,
1304 struct GNUNET_ATS_Session *session,
1307 unsigned int priority,
1308 struct GNUNET_TIME_Relative to,
1309 GNUNET_TRANSPORT_TransmitContinuation cont,
1312 struct Plugin *plugin = cls;
1313 struct UNIXMessageWrapper *wrapper;
1314 struct UNIXMessage *message;
1318 GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map,
1322 LOG (GNUNET_ERROR_TYPE_ERROR,
1323 "Invalid session for peer `%s' `%s'\n",
1324 GNUNET_i2s (&session->target),
1325 unix_plugin_address_to_string (NULL,
1326 session->address->address,
1327 session->address->address_length));
1329 return GNUNET_SYSERR;
1331 LOG (GNUNET_ERROR_TYPE_DEBUG,
1332 "Sending %u bytes with session for peer `%s' `%s'\n",
1334 GNUNET_i2s (&session->target),
1335 unix_plugin_address_to_string (NULL,
1336 session->address->address,
1337 session->address->address_length));
1338 ssize = sizeof (struct UNIXMessage) + msgbuf_size;
1339 message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size);
1340 message->header.size = htons (ssize);
1341 message->header.type = htons (0);
1342 memcpy (&message->sender, plugin->env->my_identity,
1343 sizeof (struct GNUNET_PeerIdentity));
1344 memcpy (&message[1], msgbuf, msgbuf_size);
1345 wrapper = GNUNET_new (struct UNIXMessageWrapper);
1346 wrapper->msg = message;
1347 wrapper->msgsize = ssize;
1348 wrapper->payload = msgbuf_size;
1349 wrapper->priority = priority;
1350 wrapper->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
1352 wrapper->cont = cont;
1353 wrapper->cont_cls = cont_cls;
1354 wrapper->session = session;
1355 GNUNET_CONTAINER_DLL_insert_tail (plugin->msg_head,
1358 plugin->bytes_in_queue += ssize;
1359 session->bytes_in_queue += ssize;
1360 session->msgs_in_queue++;
1361 GNUNET_STATISTICS_set (plugin->env->stats,
1362 "# bytes currently in UNIX buffers",
1363 plugin->bytes_in_queue,
1365 notify_session_monitor (plugin,
1367 GNUNET_TRANSPORT_SS_UPDATE);
1368 if (NULL == plugin->write_task)
1369 plugin->write_task =
1370 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
1371 plugin->unix_sock.desc,
1372 &unix_plugin_select_write, plugin);
1378 * Create a slew of UNIX sockets. If possible, use IPv6 and IPv4.
1380 * @param cls closure for server start, should be a `struct Plugin *`
1381 * @return number of sockets created or #GNUNET_SYSERR on error
1384 unix_transport_server_start (void *cls)
1386 struct Plugin *plugin = cls;
1387 struct sockaddr_un *un;
1390 un = unix_address_to_sockaddr (plugin->unix_socket_path,
1392 if (GNUNET_YES == plugin->is_abstract)
1394 plugin->unix_socket_path[0] = '@';
1395 un->sun_path[0] = '\0';
1397 plugin->unix_sock.desc =
1398 GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0);
1399 if (NULL == plugin->unix_sock.desc)
1401 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
1403 return GNUNET_SYSERR;
1405 if ('\0' != un->sun_path[0])
1407 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path))
1409 LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot create path to `%s'\n"),
1411 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
1412 plugin->unix_sock.desc = NULL;
1414 return GNUNET_SYSERR;
1418 GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc,
1419 (const struct sockaddr *) un, un_len))
1421 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
1422 LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot bind to `%s'\n"),
1424 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
1425 plugin->unix_sock.desc = NULL;
1427 return GNUNET_SYSERR;
1429 LOG (GNUNET_ERROR_TYPE_DEBUG,
1431 plugin->unix_socket_path);
1433 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1434 plugin->unix_sock.desc,
1435 &unix_plugin_select_read, plugin);
1442 * Function that will be called to check if a binary address for this
1443 * plugin is well-formed and corresponds to an address for THIS peer
1444 * (as per our configuration). Naturally, if absolutely necessary,
1445 * plugins can be a bit conservative in their answer, but in general
1446 * plugins should make sure that the address does not redirect
1447 * traffic to a 3rd party that might try to man-in-the-middle our
1450 * @param cls closure, should be our handle to the Plugin
1451 * @param addr pointer to the address
1452 * @param addrlen length of @a addr
1453 * @return #GNUNET_OK if this is a plausible address for this peer
1454 * and transport, #GNUNET_SYSERR if not
1458 unix_plugin_check_address (void *cls,
1462 struct Plugin* plugin = cls;
1463 const struct UnixAddress *ua = addr;
1465 size_t addr_str_len;
1467 if ( (NULL == addr) ||
1469 (sizeof (struct UnixAddress) > addrlen) )
1472 return GNUNET_SYSERR;
1474 addrstr = (char *) &ua[1];
1475 addr_str_len = ntohl (ua->addrlen);
1476 if ('\0' != addrstr[addr_str_len - 1])
1479 return GNUNET_SYSERR;
1481 if (strlen (addrstr) + 1 != addr_str_len)
1484 return GNUNET_SYSERR;
1487 if (0 == strcmp (plugin->unix_socket_path, addrstr))
1489 return GNUNET_SYSERR;
1494 * Convert the transports address to a nice, human-readable
1497 * @param cls closure
1498 * @param type name of the transport that generated the address
1499 * @param addr one of the addresses of the host, NULL for the last address
1500 * the specific address format depends on the transport
1501 * @param addrlen length of the @a addr
1502 * @param numeric should (IP) addresses be displayed in numeric form?
1503 * @param timeout after how long should we give up?
1504 * @param asc function to call on each string
1505 * @param asc_cls closure for @a asc
1508 unix_plugin_address_pretty_printer (void *cls, const char *type,
1512 struct GNUNET_TIME_Relative timeout,
1513 GNUNET_TRANSPORT_AddressStringCallback asc,
1518 if ( (NULL != addr) && (addrlen > 0))
1519 ret = unix_plugin_address_to_string (NULL,
1526 (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
1527 asc (asc_cls, NULL, GNUNET_OK);
1532 * Function called to convert a string address to
1535 * @param cls closure (`struct Plugin *`)
1536 * @param addr string address
1537 * @param addrlen length of the @a addr (strlen(addr) + '\0')
1538 * @param buf location to store the buffer
1539 * If the function returns #GNUNET_SYSERR, its contents are undefined.
1540 * @param added length of created address
1541 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
1544 unix_plugin_string_to_address (void *cls,
1547 void **buf, size_t *added)
1549 struct UnixAddress *ua;
1556 /* Format unix.options.address */
1561 if ((NULL == addr) || (addrlen == 0))
1564 return GNUNET_SYSERR;
1566 if ('\0' != addr[addrlen - 1])
1569 return GNUNET_SYSERR;
1571 if (strlen (addr) != addrlen - 1)
1574 return GNUNET_SYSERR;
1576 plugin = GNUNET_strdup (addr);
1577 optionstr = strchr (plugin, '.');
1578 if (NULL == optionstr)
1581 GNUNET_free (plugin);
1582 return GNUNET_SYSERR;
1584 optionstr[0] = '\0';
1586 options = atol (optionstr);
1587 address = strchr (optionstr, '.');
1588 if (NULL == address)
1591 GNUNET_free (plugin);
1592 return GNUNET_SYSERR;
1596 if (0 != strcmp(plugin, PLUGIN_NAME))
1599 GNUNET_free (plugin);
1600 return GNUNET_SYSERR;
1603 ua_size = sizeof (struct UnixAddress) + strlen (address) + 1;
1604 ua = GNUNET_malloc (ua_size);
1605 ua->options = htonl (options);
1606 ua->addrlen = htonl (strlen (address) + 1);
1607 memcpy (&ua[1], address, strlen (address) + 1);
1608 GNUNET_free (plugin);
1617 * Notify transport service about address
1619 * @param cls the plugin
1623 address_notification (void *cls,
1624 const struct GNUNET_SCHEDULER_TaskContext *tc)
1626 struct Plugin *plugin = cls;
1627 struct GNUNET_HELLO_Address *address;
1629 struct UnixAddress *ua;
1632 len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1;
1633 ua = GNUNET_malloc (len);
1634 ua->options = htonl (plugin->myoptions);
1635 ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1);
1636 unix_path = (char *) &ua[1];
1637 memcpy (unix_path, plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1);
1639 plugin->address_update_task = NULL;
1640 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1644 GNUNET_HELLO_ADDRESS_INFO_NONE);
1645 plugin->env->notify_address (plugin->env->cls,
1649 GNUNET_free (address);
1654 * Function called on sessions to disconnect
1656 * @param cls the plugin
1657 * @param key peer identity (unused)
1658 * @param value the `struct GNUNET_ATS_Session *` to disconnect
1659 * @return #GNUNET_YES (always, continue to iterate)
1662 get_session_delete_it (void *cls,
1663 const struct GNUNET_PeerIdentity *key,
1666 struct Plugin *plugin = cls;
1667 struct GNUNET_ATS_Session *session = value;
1669 unix_plugin_session_disconnect (plugin, session);
1675 * Disconnect from a remote node. Clean up session if we have one for this peer
1677 * @param cls closure for this call (should be handle to Plugin)
1678 * @param target the peeridentity of the peer to disconnect
1679 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed
1682 unix_plugin_peer_disconnect (void *cls,
1683 const struct GNUNET_PeerIdentity *target)
1685 struct Plugin *plugin = cls;
1687 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map,
1689 &get_session_delete_it, plugin);
1694 * Return information about the given session to the
1697 * @param cls the `struct Plugin` with the monitor callback (`sic`)
1698 * @param peer peer we send information about
1699 * @param value our `struct GNUNET_ATS_Session` to send information about
1700 * @return #GNUNET_OK (continue to iterate)
1703 send_session_info_iter (void *cls,
1704 const struct GNUNET_PeerIdentity *peer,
1707 struct Plugin *plugin = cls;
1708 struct GNUNET_ATS_Session *session = value;
1710 notify_session_monitor (plugin,
1712 GNUNET_TRANSPORT_SS_INIT);
1713 notify_session_monitor (plugin,
1715 GNUNET_TRANSPORT_SS_UP);
1721 * Begin monitoring sessions of a plugin. There can only
1722 * be one active monitor per plugin (i.e. if there are
1723 * multiple monitors, the transport service needs to
1724 * multiplex the generated events over all of them).
1726 * @param cls closure of the plugin
1727 * @param sic callback to invoke, NULL to disable monitor;
1728 * plugin will being by iterating over all active
1729 * sessions immediately and then enter monitor mode
1730 * @param sic_cls closure for @a sic
1733 unix_plugin_setup_monitor (void *cls,
1734 GNUNET_TRANSPORT_SessionInfoCallback sic,
1737 struct Plugin *plugin = cls;
1740 plugin->sic_cls = sic_cls;
1743 GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map,
1744 &send_session_info_iter,
1746 /* signal end of first iteration */
1747 sic (sic_cls, NULL, NULL);
1753 * The exported method. Initializes the plugin and returns a
1754 * struct with the callbacks.
1756 * @param cls the plugin's execution environment
1757 * @return NULL on error, plugin functions otherwise
1760 libgnunet_plugin_transport_unix_init (void *cls)
1762 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
1763 struct GNUNET_TRANSPORT_PluginFunctions *api;
1764 struct Plugin *plugin;
1765 int sockets_created;
1767 if (NULL == env->receive)
1769 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
1770 initialze the plugin or the API */
1771 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
1773 api->address_pretty_printer = &unix_plugin_address_pretty_printer;
1774 api->address_to_string = &unix_plugin_address_to_string;
1775 api->string_to_address = &unix_plugin_string_to_address;
1779 plugin = GNUNET_new (struct Plugin);
1781 GNUNET_CONFIGURATION_get_value_filename (env->cfg,
1784 &plugin->unix_socket_path))
1786 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1789 GNUNET_free (plugin);
1795 /* Initialize my flags */
1797 plugin->is_abstract = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
1799 "USE_ABSTRACT_SOCKETS");
1801 plugin->myoptions = UNIX_OPTIONS_NONE;
1802 if (GNUNET_YES == plugin->is_abstract)
1803 plugin->myoptions = UNIX_OPTIONS_USE_ABSTRACT_SOCKETS;
1805 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
1807 api->get_session = &unix_plugin_get_session;
1808 api->send = &unix_plugin_send;
1809 api->disconnect_peer = &unix_plugin_peer_disconnect;
1810 api->disconnect_session = &unix_plugin_session_disconnect;
1811 api->query_keepalive_factor = &unix_plugin_query_keepalive_factor;
1812 api->address_pretty_printer = &unix_plugin_address_pretty_printer;
1813 api->address_to_string = &unix_plugin_address_to_string;
1814 api->check_address = &unix_plugin_check_address;
1815 api->string_to_address = &unix_plugin_string_to_address;
1816 api->get_network = &unix_plugin_get_network;
1817 api->get_network_for_address = &unix_plugin_get_network_for_address;
1818 api->update_session_timeout = &unix_plugin_update_session_timeout;
1819 api->setup_monitor = &unix_plugin_setup_monitor;
1820 sockets_created = unix_transport_server_start (plugin);
1821 if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created))
1823 LOG (GNUNET_ERROR_TYPE_WARNING,
1824 _("Failed to open UNIX listen socket\n"));
1826 GNUNET_free (plugin->unix_socket_path);
1827 GNUNET_free (plugin);
1830 plugin->session_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1831 plugin->address_update_task = GNUNET_SCHEDULER_add_now (&address_notification,
1838 * Shutdown the plugin.
1840 * @param cls the plugin API returned from the initialization function
1841 * @return NULL (always)
1844 libgnunet_plugin_transport_unix_done (void *cls)
1846 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1847 struct Plugin *plugin = api->cls;
1848 struct GNUNET_HELLO_Address *address;
1849 struct UNIXMessageWrapper * msgw;
1850 struct UnixAddress *ua;
1852 struct GNUNET_ATS_Session *session;
1859 len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1;
1860 ua = GNUNET_malloc (len);
1861 ua->options = htonl (plugin->myoptions);
1862 ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1);
1864 plugin->unix_socket_path,
1865 strlen (plugin->unix_socket_path) + 1);
1866 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1869 GNUNET_HELLO_ADDRESS_INFO_NONE);
1870 plugin->env->notify_address (plugin->env->cls,
1874 GNUNET_free (address);
1877 while (NULL != (msgw = plugin->msg_head))
1879 GNUNET_CONTAINER_DLL_remove (plugin->msg_head,
1882 session = msgw->session;
1883 session->msgs_in_queue--;
1884 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
1885 session->bytes_in_queue -= msgw->msgsize;
1886 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
1887 plugin->bytes_in_queue -= msgw->msgsize;
1888 if (NULL != msgw->cont)
1889 msgw->cont (msgw->cont_cls,
1890 &msgw->session->target,
1893 GNUNET_free (msgw->msg);
1897 if (NULL != plugin->read_task)
1899 GNUNET_SCHEDULER_cancel (plugin->read_task);
1900 plugin->read_task = NULL;
1902 if (NULL != plugin->write_task)
1904 GNUNET_SCHEDULER_cancel (plugin->write_task);
1905 plugin->write_task = NULL;
1907 if (NULL != plugin->address_update_task)
1909 GNUNET_SCHEDULER_cancel (plugin->address_update_task);
1910 plugin->address_update_task = NULL;
1912 if (NULL != plugin->unix_sock.desc)
1914 GNUNET_break (GNUNET_OK ==
1915 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc));
1916 plugin->unix_sock.desc = NULL;
1918 GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map,
1919 &get_session_delete_it,
1921 GNUNET_CONTAINER_multipeermap_destroy (plugin->session_map);
1922 GNUNET_break (0 == plugin->bytes_in_queue);
1923 GNUNET_free (plugin->unix_socket_path);
1924 GNUNET_free (plugin);
1929 /* end of plugin_transport_unix.c */