2 This file is part of GNUnet
3 (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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, 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 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.
181 * Sessions with pending messages (!) are kept in a DLL.
183 struct Session *next;
186 * Sessions with pending messages (!) are kept in a DLL.
188 struct 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 GNUNET_SCHEDULER_TaskIdentifier 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 GNUNET_SCHEDULER_TaskIdentifier address_update_task;
263 GNUNET_SCHEDULER_TaskIdentifier read_task;
268 GNUNET_SCHEDULER_TaskIdentifier 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 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
323 struct GNUNET_ATS_Information ats_network;
326 * Are we using an abstract UNIX domain socket?
334 * If a session monitor is attached, notify it about the new
337 * @param plugin our plugin
338 * @param session session that changed state
339 * @param state new state of the session
342 notify_session_monitor (struct Plugin *plugin,
343 struct Session *session,
344 enum GNUNET_TRANSPORT_SessionState state)
346 struct GNUNET_TRANSPORT_SessionInfo info;
348 if (NULL == plugin->sic)
350 memset (&info, 0, sizeof (info));
352 info.is_inbound = GNUNET_SYSERR; /* hard to say */
353 info.num_msg_pending = session->msgs_in_queue;
354 info.num_bytes_pending = session->bytes_in_queue;
355 /* info.receive_delay remains zero as this is not supported by UNIX
356 (cannot selectively not receive from 'some' peer while continuing
357 to receive from others) */
358 info.session_timeout = session->timeout;
359 info.address = session->address;
360 plugin->sic (plugin->sic_cls,
367 * Function called for a quick conversion of the binary address to
368 * a numeric address. Note that the caller must not free the
369 * address and that the next call to this function is allowed
370 * to override the address again.
373 * @param addr binary address
374 * @param addrlen length of the @a addr
375 * @return string representing the same address
378 unix_plugin_address_to_string (void *cls,
382 static char rbuf[1024];
383 struct UnixAddress *ua = (struct UnixAddress *) addr;
388 if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen))
393 addrstr = (char *) &ua[1];
394 addr_str_len = ntohl (ua->addrlen);
396 if (addr_str_len != addrlen - sizeof(struct UnixAddress))
401 if ('\0' != addrstr[addr_str_len - 1])
406 if (strlen (addrstr) + 1 != addr_str_len)
413 if ('\0' == addrstr[0])
415 memset (rbuf, 0, sizeof (rbuf));
416 GNUNET_snprintf (rbuf,
421 (off == 1) ? "@" : "",
422 (int) (addr_str_len - off),
429 * Functions with this signature are called whenever we need
430 * to close a session due to a disconnect or failure to
431 * establish a connection.
433 * @param cls closure with the `struct Plugin *`
434 * @param session session to close down
435 * @return #GNUNET_OK on success
438 unix_plugin_session_disconnect (void *cls,
439 struct Session *session)
441 struct Plugin *plugin = cls;
442 struct UNIXMessageWrapper *msgw;
443 struct UNIXMessageWrapper *next;
445 LOG (GNUNET_ERROR_TYPE_DEBUG,
446 "Disconnecting session for peer `%s' `%s'\n",
447 GNUNET_i2s (&session->target),
448 unix_plugin_address_to_string (NULL,
449 session->address->address,
450 session->address->address_length));
451 plugin->env->session_end (plugin->env->cls,
454 next = plugin->msg_head;
459 if (msgw->session != session)
461 GNUNET_CONTAINER_DLL_remove (plugin->msg_head,
464 session->msgs_in_queue--;
465 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
466 session->bytes_in_queue -= msgw->msgsize;
467 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
468 plugin->bytes_in_queue -= msgw->msgsize;
469 if (NULL != msgw->cont)
470 msgw->cont (msgw->cont_cls,
471 &msgw->session->target,
474 GNUNET_free (msgw->msg);
477 GNUNET_assert (GNUNET_YES ==
478 GNUNET_CONTAINER_multipeermap_remove (plugin->session_map,
481 GNUNET_STATISTICS_set (plugin->env->stats,
482 "# UNIX sessions active",
483 GNUNET_CONTAINER_multipeermap_size (plugin->session_map),
485 if (GNUNET_SCHEDULER_NO_TASK != session->timeout_task)
487 GNUNET_SCHEDULER_cancel (session->timeout_task);
488 session->timeout_task = GNUNET_SCHEDULER_NO_TASK;
489 session->timeout = GNUNET_TIME_UNIT_ZERO_ABS;
491 notify_session_monitor (plugin,
493 GNUNET_TRANSPORT_SS_DOWN);
494 GNUNET_HELLO_address_free (session->address);
495 GNUNET_break (0 == session->bytes_in_queue);
496 GNUNET_break (0 == session->msgs_in_queue);
497 GNUNET_free (session);
503 * Session was idle for too long, so disconnect it
505 * @param cls the `struct Session *` to disconnect
506 * @param tc scheduler context
509 session_timeout (void *cls,
510 const struct GNUNET_SCHEDULER_TaskContext *tc)
512 struct Session *session = cls;
513 struct GNUNET_TIME_Relative left;
515 session->timeout_task = GNUNET_SCHEDULER_NO_TASK;
516 left = GNUNET_TIME_absolute_get_remaining (session->timeout);
517 if (0 != left.rel_value_us)
519 /* not actually our turn yet, but let's at least update
520 the monitor, it may think we're about to die ... */
521 notify_session_monitor (session->plugin,
523 GNUNET_TRANSPORT_SS_UP);
524 session->timeout_task = GNUNET_SCHEDULER_add_delayed (left,
529 LOG (GNUNET_ERROR_TYPE_DEBUG,
530 "Session %p was idle for %s, disconnecting\n",
532 GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
534 unix_plugin_session_disconnect (session->plugin, session);
539 * Increment session timeout due to activity. We do not immediately
540 * notify the monitor here as that might generate excessive
543 * @param session session for which the timeout should be rescheduled
546 reschedule_session_timeout (struct Session *session)
548 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != session->timeout_task);
549 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
554 * Convert unix path to a `struct sockaddr_un *`
556 * @param unixpath path to convert
557 * @param[out] sock_len set to the length of the address
558 * @return converted unix path
560 static struct sockaddr_un *
561 unix_address_to_sockaddr (const char *unixpath,
564 struct sockaddr_un *un;
567 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
568 un = GNUNET_new (struct sockaddr_un);
569 un->sun_family = AF_UNIX;
570 slen = strlen (unixpath);
571 if (slen >= sizeof (un->sun_path))
572 slen = sizeof (un->sun_path) - 1;
573 memcpy (un->sun_path, unixpath, slen);
574 un->sun_path[slen] = '\0';
575 slen = sizeof (struct sockaddr_un);
576 #if HAVE_SOCKADDR_IN_SIN_LEN
577 un->sun_len = (u_char) slen;
585 * Closure to #lookup_session_it().
590 * Location to store the session, if found.
595 * Address we are looking for.
597 const struct GNUNET_HELLO_Address *address;
602 * Function called to find a session by address.
604 * @param cls the `struct LookupCtx *`
605 * @param key peer we are looking for (unused)
606 * @param value a session
607 * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success
610 lookup_session_it (void *cls,
611 const struct GNUNET_PeerIdentity * key,
614 struct LookupCtx *lctx = cls;
615 struct Session *session = value;
617 if (0 == GNUNET_HELLO_address_cmp (lctx->address,
628 * Find an existing session by address.
630 * @param plugin the plugin
631 * @param address the address to find
632 * @return NULL if session was not found
634 static struct Session *
635 lookup_session (struct Plugin *plugin,
636 const struct GNUNET_HELLO_Address *address)
638 struct LookupCtx lctx;
640 lctx.address = address;
642 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map,
644 &lookup_session_it, &lctx);
650 * Function that is called to get the keepalive factor.
651 * #GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to
652 * calculate the interval between keepalive packets.
654 * @param cls closure with the `struct Plugin`
655 * @return keepalive factor
658 unix_plugin_query_keepalive_factor (void *cls)
665 * Actually send out the message, assume we've got the address and
666 * send_handle squared away!
669 * @param send_handle which handle to send message on
670 * @param target who should receive this message (ignored by UNIX)
671 * @param msgbuf one or more GNUNET_MessageHeader(s) strung together
672 * @param msgbuf_size the size of the @a msgbuf to send
673 * @param priority how important is the message (ignored by UNIX)
674 * @param timeout when should we time out (give up) if we can not transmit?
675 * @param addr the addr to send the message to, needs to be a sockaddr for us
676 * @param addrlen the len of @a addr
677 * @param payload bytes payload to send
678 * @param cont continuation to call once the message has
679 * been transmitted (or if the transport is ready
680 * for the next transmission call; or if the
681 * peer disconnected...)
682 * @param cont_cls closure for @a cont
683 * @return on success the number of bytes written, RETRY for retry, -1 on errors
686 unix_real_send (void *cls,
687 struct GNUNET_NETWORK_Handle *send_handle,
688 const struct GNUNET_PeerIdentity *target,
691 unsigned int priority,
692 struct GNUNET_TIME_Absolute timeout,
693 const struct UnixAddress *addr,
696 GNUNET_TRANSPORT_TransmitContinuation cont,
699 struct Plugin *plugin = cls;
701 struct sockaddr_un *un;
703 const char *unixpath;
705 if (NULL == send_handle)
707 GNUNET_break (0); /* We do not have a send handle */
708 return GNUNET_SYSERR;
710 if ((NULL == addr) || (0 == addrlen))
712 GNUNET_break (0); /* Can never send if we don't have an address */
713 return GNUNET_SYSERR;
716 /* Prepare address */
717 unixpath = (const char *) &addr[1];
718 if (NULL == (un = unix_address_to_sockaddr (unixpath,
725 if ((GNUNET_YES == plugin->is_abstract) &&
726 (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl(addr->options) )) )
728 un->sun_path[0] = '\0';
732 sent = GNUNET_NETWORK_socket_sendto (send_handle,
735 (const struct sockaddr *) un,
737 if (GNUNET_SYSERR == sent)
739 if ( (EAGAIN == errno) ||
743 return RETRY; /* We have to retry later */
745 if (EMSGSIZE == errno)
748 socklen_t len = sizeof (size);
750 GNUNET_NETWORK_socket_getsockopt ((struct GNUNET_NETWORK_Handle *)
751 send_handle, SOL_SOCKET, SO_SNDBUF, &size,
753 if (size < msgbuf_size)
755 LOG (GNUNET_ERROR_TYPE_DEBUG,
756 "Trying to increase socket buffer size from %u to %u for message size %u\n",
758 (unsigned int) ((msgbuf_size / 1000) + 2) * 1000,
759 (unsigned int) msgbuf_size);
760 size = ((msgbuf_size / 1000) + 2) * 1000;
762 GNUNET_NETWORK_socket_setsockopt ((struct GNUNET_NETWORK_Handle *) send_handle,
763 SOL_SOCKET, SO_SNDBUF,
764 &size, sizeof (size)))
765 goto resend; /* Increased buffer size, retry sending */
768 /* Could not increase buffer size: error, no retry */
769 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt");
771 return GNUNET_SYSERR;
776 /* Buffer is bigger than message: error, no retry
777 * This should never happen!*/
780 return GNUNET_SYSERR;
785 LOG (GNUNET_ERROR_TYPE_DEBUG,
786 "UNIX transmitted %u-byte message to %s (%d: %s)\n",
787 (unsigned int) msgbuf_size,
788 GNUNET_a2s ((const struct sockaddr *)un, un_len),
790 (sent < 0) ? STRERROR (errno) : "ok");
797 * Function obtain the network type for a session
799 * @param cls closure ('struct Plugin*')
800 * @param session the session
801 * @return the network type in HBO or #GNUNET_SYSERR
803 static enum GNUNET_ATS_Network_Type
804 unix_plugin_get_network (void *cls,
805 struct Session *session)
807 GNUNET_assert (NULL != session);
808 return GNUNET_ATS_NET_LOOPBACK;
813 * Creates a new outbound session the transport service will use to send data to the
816 * @param cls the plugin
817 * @param address the address
818 * @return the session or NULL of max connections exceeded
820 static struct Session *
821 unix_plugin_get_session (void *cls,
822 const struct GNUNET_HELLO_Address *address)
824 struct Plugin *plugin = cls;
825 struct Session *session;
826 struct UnixAddress *ua;
828 uint32_t addr_str_len;
829 uint32_t addr_option;
831 ua = (struct UnixAddress *) address->address;
832 if ((NULL == address->address) || (0 == address->address_length) ||
833 (sizeof (struct UnixAddress) > address->address_length))
838 addrstr = (char *) &ua[1];
839 addr_str_len = ntohl (ua->addrlen);
840 addr_option = ntohl (ua->options);
842 if ( (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & addr_option)) &&
843 (GNUNET_NO == plugin->is_abstract))
848 if (addr_str_len != address->address_length - sizeof (struct UnixAddress))
850 return NULL; /* This can be a legacy address */
853 if ('\0' != addrstr[addr_str_len - 1])
858 if (strlen (addrstr) + 1 != addr_str_len)
864 /* Check if a session for this address already exists */
865 if (NULL != (session = lookup_session (plugin,
868 LOG (GNUNET_ERROR_TYPE_DEBUG,
869 "Found existing session %p for address `%s'\n",
871 unix_plugin_address_to_string (NULL,
873 address->address_length));
877 /* create a new session */
878 session = GNUNET_new (struct Session);
879 session->target = address->peer;
880 session->address = GNUNET_HELLO_address_copy (address);
881 session->plugin = plugin;
882 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
883 session->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
886 LOG (GNUNET_ERROR_TYPE_DEBUG,
887 "Creating a new session %p for address `%s'\n",
889 unix_plugin_address_to_string (NULL,
891 address->address_length));
892 (void) GNUNET_CONTAINER_multipeermap_put (plugin->session_map,
893 &address->peer, session,
894 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
895 GNUNET_STATISTICS_set (plugin->env->stats,
896 "# UNIX sessions active",
897 GNUNET_CONTAINER_multipeermap_size (plugin->session_map),
899 notify_session_monitor (plugin,
901 GNUNET_TRANSPORT_SS_UP);
907 * Function that will be called whenever the transport service wants
908 * to notify the plugin that a session is still active and in use and
909 * therefore the session timeout for this session has to be updated
911 * @param cls closure with the `struct Plugin *`
912 * @param peer which peer was the session for
913 * @param session which session is being updated
916 unix_plugin_update_session_timeout (void *cls,
917 const struct GNUNET_PeerIdentity *peer,
918 struct Session *session)
920 struct Plugin *plugin = cls;
923 GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map,
930 reschedule_session_timeout (session);
935 * Demultiplexer for UNIX messages
937 * @param plugin the main plugin for this transport
938 * @param sender from which peer the message was received
939 * @param currhdr pointer to the header of the message
940 * @param ua address to look for
941 * @param ua_len length of the address @a ua
944 unix_demultiplexer (struct Plugin *plugin,
945 struct GNUNET_PeerIdentity *sender,
946 const struct GNUNET_MessageHeader *currhdr,
947 const struct UnixAddress *ua, size_t ua_len)
949 struct Session *session;
950 struct GNUNET_HELLO_Address *address;
952 GNUNET_break (ntohl(plugin->ats_network.value) != GNUNET_ATS_NET_UNSPECIFIED);
953 GNUNET_assert (ua_len >= sizeof (struct UnixAddress));
954 LOG (GNUNET_ERROR_TYPE_DEBUG,
955 "Received message from %s\n",
956 unix_plugin_address_to_string (NULL, ua, ua_len));
957 GNUNET_STATISTICS_update (plugin->env->stats,
958 "# bytes received via UNIX",
959 ntohs (currhdr->size),
962 /* Look for existing session */
963 address = GNUNET_HELLO_address_allocate (sender,
966 GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */
967 session = lookup_session (plugin, address);
970 session = unix_plugin_get_session (plugin, address);
971 /* Notify transport and ATS about new inbound session */
972 plugin->env->session_start (NULL,
975 &plugin->ats_network, 1);
976 notify_session_monitor (plugin,
978 GNUNET_TRANSPORT_SS_UP);
982 reschedule_session_timeout (session);
984 GNUNET_HELLO_address_free (address);
985 plugin->env->receive (plugin->env->cls,
989 plugin->env->update_address_metrics (plugin->env->cls,
992 &plugin->ats_network, 1);
997 * Read from UNIX domain socket (it is ready).
999 * @param plugin the plugin
1002 unix_plugin_do_read (struct Plugin *plugin)
1004 char buf[65536] GNUNET_ALIGN;
1005 struct UnixAddress *ua;
1006 struct UNIXMessage *msg;
1007 struct GNUNET_PeerIdentity sender;
1008 struct sockaddr_un un;
1015 const struct GNUNET_MessageHeader *currhdr;
1019 addrlen = sizeof (un);
1020 memset (&un, 0, sizeof (un));
1021 ret = GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc,
1023 (struct sockaddr *) &un,
1025 if ((GNUNET_SYSERR == ret) && ((errno == EAGAIN) || (errno == ENOBUFS)))
1027 if (GNUNET_SYSERR == ret)
1029 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
1035 LOG (GNUNET_ERROR_TYPE_DEBUG,
1036 "Read %d bytes from socket %s\n",
1041 GNUNET_assert (AF_UNIX == (un.sun_family));
1042 is_abstract = GNUNET_NO;
1043 if ('\0' == un.sun_path[0])
1045 un.sun_path[0] = '@';
1046 is_abstract = GNUNET_YES;
1049 ua_len = sizeof (struct UnixAddress) + strlen (un.sun_path) + 1;
1050 ua = GNUNET_malloc (ua_len);
1051 ua->addrlen = htonl (strlen (&un.sun_path[0]) +1);
1052 memcpy (&ua[1], &un.sun_path[0], strlen (un.sun_path) + 1);
1054 ua->options = htonl(UNIX_OPTIONS_USE_ABSTRACT_SOCKETS);
1056 ua->options = htonl(UNIX_OPTIONS_NONE);
1058 msg = (struct UNIXMessage *) buf;
1059 csize = ntohs (msg->header.size);
1060 if ((csize < sizeof (struct UNIXMessage)) || (csize > ret))
1062 GNUNET_break_op (0);
1066 msgbuf = (char *) &msg[1];
1069 sizeof (struct GNUNET_PeerIdentity));
1071 tsize = csize - sizeof (struct UNIXMessage);
1072 while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize)
1074 currhdr = (struct GNUNET_MessageHeader *) &msgbuf[offset];
1075 csize = ntohs (currhdr->size);
1076 if ((csize < sizeof (struct GNUNET_MessageHeader)) ||
1077 (csize > tsize - offset))
1079 GNUNET_break_op (0);
1082 unix_demultiplexer (plugin, &sender, currhdr, ua, ua_len);
1090 * Write to UNIX domain socket (it is ready).
1092 * @param plugin handle to the plugin
1095 unix_plugin_do_write (struct Plugin *plugin)
1098 struct UNIXMessageWrapper *msgw;
1099 struct Session *session;
1103 did_delete = GNUNET_NO;
1104 while (NULL != (msgw = plugin->msg_head))
1106 if (GNUNET_TIME_absolute_get_remaining (msgw->timeout).rel_value_us > 0)
1107 break; /* Message is ready for sending */
1108 /* Message has a timeout */
1109 did_delete = GNUNET_YES;
1110 LOG (GNUNET_ERROR_TYPE_DEBUG,
1111 "Timeout for message with %u bytes \n",
1112 (unsigned int) msgw->msgsize);
1113 GNUNET_CONTAINER_DLL_remove (plugin->msg_head,
1116 session = msgw->session;
1117 session->msgs_in_queue--;
1118 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
1119 session->bytes_in_queue -= msgw->msgsize;
1120 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
1121 plugin->bytes_in_queue -= msgw->msgsize;
1122 GNUNET_STATISTICS_set (plugin->env->stats,
1123 "# bytes currently in UNIX buffers",
1124 plugin->bytes_in_queue,
1126 GNUNET_STATISTICS_update (plugin->env->stats,
1127 "# UNIX bytes discarded",
1130 if (NULL != msgw->cont)
1131 msgw->cont (msgw->cont_cls,
1132 &msgw->session->target,
1136 GNUNET_free (msgw->msg);
1141 if (GNUNET_YES == did_delete)
1142 notify_session_monitor (plugin,
1144 GNUNET_TRANSPORT_SS_UP);
1145 return; /* Nothing to send at the moment */
1148 sent = unix_real_send (plugin,
1149 plugin->unix_sock.desc,
1150 &msgw->session->target,
1151 (const char *) msgw->msg,
1155 msgw->session->address->address,
1156 msgw->session->address->address_length,
1158 msgw->cont, msgw->cont_cls);
1161 GNUNET_STATISTICS_update (plugin->env->stats,
1162 "# UNIX retry attempts",
1164 notify_session_monitor (plugin,
1166 GNUNET_TRANSPORT_SS_UP);
1169 GNUNET_CONTAINER_DLL_remove (plugin->msg_head,
1172 session = msgw->session;
1173 session->msgs_in_queue--;
1174 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
1175 session->bytes_in_queue -= msgw->msgsize;
1176 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
1177 plugin->bytes_in_queue -= msgw->msgsize;
1178 GNUNET_STATISTICS_set (plugin->env->stats,
1179 "# bytes currently in UNIX buffers",
1180 plugin->bytes_in_queue, GNUNET_NO);
1181 notify_session_monitor (plugin,
1183 GNUNET_TRANSPORT_SS_UP);
1184 if (GNUNET_SYSERR == sent)
1186 /* failed and no retry */
1187 if (NULL != msgw->cont)
1188 msgw->cont (msgw->cont_cls,
1189 &msgw->session->target,
1192 GNUNET_STATISTICS_update (plugin->env->stats,
1193 "# UNIX bytes discarded",
1196 GNUNET_free (msgw->msg);
1200 /* successfully sent bytes */
1201 GNUNET_break (sent > 0);
1202 GNUNET_STATISTICS_update (plugin->env->stats,
1203 "# bytes transmitted via UNIX",
1206 if (NULL != msgw->cont)
1207 msgw->cont (msgw->cont_cls,
1208 &msgw->session->target,
1212 GNUNET_free (msgw->msg);
1218 * We have been notified that our socket has something to read.
1219 * Then reschedule this function to be called again once more is available.
1221 * @param cls the plugin handle
1222 * @param tc the scheduling context
1225 unix_plugin_select_read (void *cls,
1226 const struct GNUNET_SCHEDULER_TaskContext *tc)
1228 struct Plugin *plugin = cls;
1230 plugin->read_task = GNUNET_SCHEDULER_NO_TASK;
1231 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1233 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
1234 unix_plugin_do_read (plugin);
1236 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1237 plugin->unix_sock.desc,
1238 &unix_plugin_select_read, plugin);
1243 * We have been notified that our socket is ready to write.
1244 * Then reschedule this function to be called again once more is available.
1246 * @param cls the plugin handle
1247 * @param tc the scheduling context
1250 unix_plugin_select_write (void *cls,
1251 const struct GNUNET_SCHEDULER_TaskContext *tc)
1253 struct Plugin *plugin = cls;
1255 plugin->write_task = GNUNET_SCHEDULER_NO_TASK;
1256 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1258 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))
1259 unix_plugin_do_write (plugin);
1260 if (NULL == plugin->msg_head)
1261 return; /* write queue empty */
1262 plugin->write_task =
1263 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
1264 plugin->unix_sock.desc,
1265 &unix_plugin_select_write, plugin);
1270 * Function that can be used by the transport service to transmit
1271 * a message using the plugin. Note that in the case of a
1272 * peer disconnecting, the continuation MUST be called
1273 * prior to the disconnect notification itself. This function
1274 * will be called with this peer's HELLO message to initiate
1275 * a fresh connection to another peer.
1277 * @param cls closure
1278 * @param session which session must be used
1279 * @param msgbuf the message to transmit
1280 * @param msgbuf_size number of bytes in @a msgbuf
1281 * @param priority how important is the message (most plugins will
1282 * ignore message priority and just FIFO)
1283 * @param to how long to wait at most for the transmission (does not
1284 * require plugins to discard the message after the timeout,
1285 * just advisory for the desired delay; most plugins will ignore
1287 * @param cont continuation to call once the message has
1288 * been transmitted (or if the transport is ready
1289 * for the next transmission call; or if the
1290 * peer disconnected...); can be NULL
1291 * @param cont_cls closure for @a cont
1292 * @return number of bytes used (on the physical network, with overheads);
1293 * -1 on hard errors (i.e. address invalid); 0 is a legal value
1294 * and does NOT mean that the message was not transmitted (DV)
1297 unix_plugin_send (void *cls,
1298 struct Session *session,
1301 unsigned int priority,
1302 struct GNUNET_TIME_Relative to,
1303 GNUNET_TRANSPORT_TransmitContinuation cont,
1306 struct Plugin *plugin = cls;
1307 struct UNIXMessageWrapper *wrapper;
1308 struct UNIXMessage *message;
1312 GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map,
1316 LOG (GNUNET_ERROR_TYPE_ERROR,
1317 "Invalid session for peer `%s' `%s'\n",
1318 GNUNET_i2s (&session->target),
1319 unix_plugin_address_to_string (NULL,
1320 session->address->address,
1321 session->address->address_length));
1323 return GNUNET_SYSERR;
1325 LOG (GNUNET_ERROR_TYPE_DEBUG,
1326 "Sending %u bytes with session for peer `%s' `%s'\n",
1328 GNUNET_i2s (&session->target),
1329 unix_plugin_address_to_string (NULL,
1330 session->address->address,
1331 session->address->address_length));
1332 ssize = sizeof (struct UNIXMessage) + msgbuf_size;
1333 message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size);
1334 message->header.size = htons (ssize);
1335 message->header.type = htons (0);
1336 memcpy (&message->sender, plugin->env->my_identity,
1337 sizeof (struct GNUNET_PeerIdentity));
1338 memcpy (&message[1], msgbuf, msgbuf_size);
1339 wrapper = GNUNET_new (struct UNIXMessageWrapper);
1340 wrapper->msg = message;
1341 wrapper->msgsize = ssize;
1342 wrapper->payload = msgbuf_size;
1343 wrapper->priority = priority;
1344 wrapper->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
1346 wrapper->cont = cont;
1347 wrapper->cont_cls = cont_cls;
1348 wrapper->session = session;
1349 GNUNET_CONTAINER_DLL_insert_tail (plugin->msg_head,
1352 plugin->bytes_in_queue += ssize;
1353 session->bytes_in_queue += ssize;
1354 session->msgs_in_queue++;
1355 GNUNET_STATISTICS_set (plugin->env->stats,
1356 "# bytes currently in UNIX buffers",
1357 plugin->bytes_in_queue,
1359 notify_session_monitor (plugin,
1361 GNUNET_TRANSPORT_SS_UP);
1362 if (GNUNET_SCHEDULER_NO_TASK == plugin->write_task)
1363 plugin->write_task =
1364 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
1365 plugin->unix_sock.desc,
1366 &unix_plugin_select_write, plugin);
1372 * Create a slew of UNIX sockets. If possible, use IPv6 and IPv4.
1374 * @param cls closure for server start, should be a `struct Plugin *`
1375 * @return number of sockets created or #GNUNET_SYSERR on error
1378 unix_transport_server_start (void *cls)
1380 struct Plugin *plugin = cls;
1381 struct sockaddr_un *un;
1384 un = unix_address_to_sockaddr (plugin->unix_socket_path,
1386 if (GNUNET_YES == plugin->is_abstract)
1388 plugin->unix_socket_path[0] = '@';
1389 un->sun_path[0] = '\0';
1391 plugin->ats_network = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) un, un_len);
1392 plugin->unix_sock.desc =
1393 GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0);
1394 if (NULL == plugin->unix_sock.desc)
1396 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
1397 return GNUNET_SYSERR;
1399 if ('\0' != un->sun_path[0])
1401 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path))
1403 LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot create path to `%s'\n"),
1405 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
1406 plugin->unix_sock.desc = NULL;
1408 return GNUNET_SYSERR;
1412 GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc,
1413 (const struct sockaddr *) un, un_len))
1415 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
1416 LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot bind to `%s'\n"),
1418 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
1419 plugin->unix_sock.desc = NULL;
1421 return GNUNET_SYSERR;
1423 LOG (GNUNET_ERROR_TYPE_DEBUG,
1425 plugin->unix_socket_path);
1427 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1428 plugin->unix_sock.desc,
1429 &unix_plugin_select_read, plugin);
1436 * Function that will be called to check if a binary address for this
1437 * plugin is well-formed and corresponds to an address for THIS peer
1438 * (as per our configuration). Naturally, if absolutely necessary,
1439 * plugins can be a bit conservative in their answer, but in general
1440 * plugins should make sure that the address does not redirect
1441 * traffic to a 3rd party that might try to man-in-the-middle our
1444 * @param cls closure, should be our handle to the Plugin
1445 * @param addr pointer to the address
1446 * @param addrlen length of @a addr
1447 * @return #GNUNET_OK if this is a plausible address for this peer
1448 * and transport, #GNUNET_SYSERR if not
1452 unix_plugin_check_address (void *cls,
1456 struct Plugin* plugin = cls;
1457 const struct UnixAddress *ua = addr;
1459 size_t addr_str_len;
1461 if ( (NULL == addr) ||
1463 (sizeof (struct UnixAddress) > addrlen) )
1466 return GNUNET_SYSERR;
1468 addrstr = (char *) &ua[1];
1469 addr_str_len = ntohl (ua->addrlen);
1470 if ('\0' != addrstr[addr_str_len - 1])
1473 return GNUNET_SYSERR;
1475 if (strlen (addrstr) + 1 != addr_str_len)
1478 return GNUNET_SYSERR;
1481 if (0 == strcmp (plugin->unix_socket_path, addrstr))
1483 return GNUNET_SYSERR;
1488 * Convert the transports address to a nice, human-readable
1491 * @param cls closure
1492 * @param type name of the transport that generated the address
1493 * @param addr one of the addresses of the host, NULL for the last address
1494 * the specific address format depends on the transport
1495 * @param addrlen length of the @a addr
1496 * @param numeric should (IP) addresses be displayed in numeric form?
1497 * @param timeout after how long should we give up?
1498 * @param asc function to call on each string
1499 * @param asc_cls closure for @a asc
1502 unix_plugin_address_pretty_printer (void *cls, const char *type,
1506 struct GNUNET_TIME_Relative timeout,
1507 GNUNET_TRANSPORT_AddressStringCallback asc,
1512 if ( (NULL != addr) && (addrlen > 0))
1513 ret = unix_plugin_address_to_string (NULL,
1520 (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
1521 asc (asc_cls, NULL, GNUNET_OK);
1526 * Function called to convert a string address to
1529 * @param cls closure (`struct Plugin *`)
1530 * @param addr string address
1531 * @param addrlen length of the @a addr (strlen(addr) + '\0')
1532 * @param buf location to store the buffer
1533 * If the function returns #GNUNET_SYSERR, its contents are undefined.
1534 * @param added length of created address
1535 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
1538 unix_plugin_string_to_address (void *cls,
1541 void **buf, size_t *added)
1543 struct UnixAddress *ua;
1550 /* Format unix.options.address */
1555 if ((NULL == addr) || (addrlen == 0))
1558 return GNUNET_SYSERR;
1560 if ('\0' != addr[addrlen - 1])
1563 return GNUNET_SYSERR;
1565 if (strlen (addr) != addrlen - 1)
1568 return GNUNET_SYSERR;
1570 plugin = GNUNET_strdup (addr);
1571 optionstr = strchr (plugin, '.');
1572 if (NULL == optionstr)
1575 GNUNET_free (plugin);
1576 return GNUNET_SYSERR;
1578 optionstr[0] = '\0';
1580 options = atol (optionstr);
1581 address = strchr (optionstr, '.');
1582 if (NULL == address)
1585 GNUNET_free (plugin);
1586 return GNUNET_SYSERR;
1590 if (0 != strcmp(plugin, PLUGIN_NAME))
1593 GNUNET_free (plugin);
1594 return GNUNET_SYSERR;
1597 ua_size = sizeof (struct UnixAddress) + strlen (address) + 1;
1598 ua = GNUNET_malloc (ua_size);
1599 ua->options = htonl (options);
1600 ua->addrlen = htonl (strlen (address) + 1);
1601 memcpy (&ua[1], address, strlen (address) + 1);
1602 GNUNET_free (plugin);
1611 * Notify transport service about address
1613 * @param cls the plugin
1617 address_notification (void *cls,
1618 const struct GNUNET_SCHEDULER_TaskContext *tc)
1620 struct Plugin *plugin = cls;
1621 struct GNUNET_HELLO_Address *address;
1623 struct UnixAddress *ua;
1626 len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1;
1627 ua = GNUNET_malloc (len);
1628 ua->options = htonl (plugin->myoptions);
1629 ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1);
1630 unix_path = (char *) &ua[1];
1631 memcpy (unix_path, plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1);
1633 plugin->address_update_task = GNUNET_SCHEDULER_NO_TASK;
1634 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1638 GNUNET_HELLO_ADDRESS_INFO_NONE);
1639 plugin->env->notify_address (plugin->env->cls,
1643 GNUNET_free (address);
1648 * Function called on sessions to disconnect
1650 * @param cls the plugin
1651 * @param key peer identity (unused)
1652 * @param value the `struct Session *` to disconnect
1653 * @return #GNUNET_YES (always, continue to iterate)
1656 get_session_delete_it (void *cls,
1657 const struct GNUNET_PeerIdentity *key,
1660 struct Plugin *plugin = cls;
1661 struct Session *session = value;
1663 unix_plugin_session_disconnect (plugin, session);
1669 * Disconnect from a remote node. Clean up session if we have one for this peer
1671 * @param cls closure for this call (should be handle to Plugin)
1672 * @param target the peeridentity of the peer to disconnect
1673 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed
1676 unix_plugin_peer_disconnect (void *cls,
1677 const struct GNUNET_PeerIdentity *target)
1679 struct Plugin *plugin = cls;
1681 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map,
1683 &get_session_delete_it, plugin);
1688 * Return information about the given session to the
1691 * @param cls the `struct Plugin` with the monitor callback (`sic`)
1692 * @param peer peer we send information about
1693 * @param value our `struct Session` to send information about
1694 * @return #GNUNET_OK (continue to iterate)
1697 send_session_info_iter (void *cls,
1698 const struct GNUNET_PeerIdentity *peer,
1701 struct Plugin *plugin = cls;
1702 struct Session *session = value;
1704 notify_session_monitor (plugin,
1706 GNUNET_TRANSPORT_SS_UP);
1712 * Begin monitoring sessions of a plugin. There can only
1713 * be one active monitor per plugin (i.e. if there are
1714 * multiple monitors, the transport service needs to
1715 * multiplex the generated events over all of them).
1717 * @param cls closure of the plugin
1718 * @param sic callback to invoke, NULL to disable monitor;
1719 * plugin will being by iterating over all active
1720 * sessions immediately and then enter monitor mode
1721 * @param sic_cls closure for @a sic
1724 unix_plugin_setup_monitor (void *cls,
1725 GNUNET_TRANSPORT_SessionInfoCallback sic,
1728 struct Plugin *plugin = cls;
1731 plugin->sic_cls = sic_cls;
1734 GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map,
1735 &send_session_info_iter,
1737 /* signal end of first iteration */
1738 sic (sic_cls, NULL, NULL);
1744 * The exported method. Initializes the plugin and returns a
1745 * struct with the callbacks.
1747 * @param cls the plugin's execution environment
1748 * @return NULL on error, plugin functions otherwise
1751 libgnunet_plugin_transport_unix_init (void *cls)
1753 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
1754 struct GNUNET_TRANSPORT_PluginFunctions *api;
1755 struct Plugin *plugin;
1756 int sockets_created;
1758 if (NULL == env->receive)
1760 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
1761 initialze the plugin or the API */
1762 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
1764 api->address_pretty_printer = &unix_plugin_address_pretty_printer;
1765 api->address_to_string = &unix_plugin_address_to_string;
1766 api->string_to_address = &unix_plugin_string_to_address;
1770 plugin = GNUNET_new (struct Plugin);
1772 GNUNET_CONFIGURATION_get_value_filename (env->cfg,
1775 &plugin->unix_socket_path))
1777 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1780 GNUNET_free (plugin);
1786 /* Initialize my flags */
1788 plugin->is_abstract = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
1790 "USE_ABSTRACT_SOCKETS");
1792 plugin->myoptions = UNIX_OPTIONS_NONE;
1793 if (GNUNET_YES == plugin->is_abstract)
1794 plugin->myoptions = UNIX_OPTIONS_USE_ABSTRACT_SOCKETS;
1796 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
1798 api->get_session = &unix_plugin_get_session;
1799 api->send = &unix_plugin_send;
1800 api->disconnect_peer = &unix_plugin_peer_disconnect;
1801 api->disconnect_session = &unix_plugin_session_disconnect;
1802 api->query_keepalive_factor = &unix_plugin_query_keepalive_factor;
1803 api->address_pretty_printer = &unix_plugin_address_pretty_printer;
1804 api->address_to_string = &unix_plugin_address_to_string;
1805 api->check_address = &unix_plugin_check_address;
1806 api->string_to_address = &unix_plugin_string_to_address;
1807 api->get_network = &unix_plugin_get_network;
1808 api->update_session_timeout = &unix_plugin_update_session_timeout;
1809 api->setup_monitor = &unix_plugin_setup_monitor;
1810 sockets_created = unix_transport_server_start (plugin);
1811 if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created))
1813 LOG (GNUNET_ERROR_TYPE_WARNING,
1814 _("Failed to open UNIX listen socket\n"));
1816 GNUNET_free (plugin->unix_socket_path);
1817 GNUNET_free (plugin);
1820 plugin->session_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1821 plugin->address_update_task = GNUNET_SCHEDULER_add_now (&address_notification,
1828 * Shutdown the plugin.
1830 * @param cls the plugin API returned from the initialization function
1831 * @return NULL (always)
1834 libgnunet_plugin_transport_unix_done (void *cls)
1836 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1837 struct Plugin *plugin = api->cls;
1838 struct GNUNET_HELLO_Address *address;
1839 struct UNIXMessageWrapper * msgw;
1840 struct UnixAddress *ua;
1842 struct Session *session;
1849 len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1;
1850 ua = GNUNET_malloc (len);
1851 ua->options = htonl (plugin->myoptions);
1852 ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1);
1854 plugin->unix_socket_path,
1855 strlen (plugin->unix_socket_path) + 1);
1856 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1859 GNUNET_HELLO_ADDRESS_INFO_NONE);
1860 plugin->env->notify_address (plugin->env->cls,
1864 GNUNET_free (address);
1867 while (NULL != (msgw = plugin->msg_head))
1869 GNUNET_CONTAINER_DLL_remove (plugin->msg_head,
1872 session = msgw->session;
1873 session->msgs_in_queue--;
1874 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
1875 session->bytes_in_queue -= msgw->msgsize;
1876 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
1877 plugin->bytes_in_queue -= msgw->msgsize;
1878 if (NULL != msgw->cont)
1879 msgw->cont (msgw->cont_cls,
1880 &msgw->session->target,
1883 GNUNET_free (msgw->msg);
1887 if (GNUNET_SCHEDULER_NO_TASK != plugin->read_task)
1889 GNUNET_SCHEDULER_cancel (plugin->read_task);
1890 plugin->read_task = GNUNET_SCHEDULER_NO_TASK;
1892 if (GNUNET_SCHEDULER_NO_TASK != plugin->write_task)
1894 GNUNET_SCHEDULER_cancel (plugin->write_task);
1895 plugin->write_task = GNUNET_SCHEDULER_NO_TASK;
1897 if (GNUNET_SCHEDULER_NO_TASK != plugin->address_update_task)
1899 GNUNET_SCHEDULER_cancel (plugin->address_update_task);
1900 plugin->address_update_task = GNUNET_SCHEDULER_NO_TASK;
1902 if (NULL != plugin->unix_sock.desc)
1904 GNUNET_break (GNUNET_OK ==
1905 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc));
1906 plugin->unix_sock.desc = NULL;
1908 GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map,
1909 &get_session_delete_it,
1911 GNUNET_CONTAINER_multipeermap_destroy (plugin->session_map);
1912 GNUNET_break (0 == plugin->bytes_in_queue);
1913 GNUNET_free (plugin->unix_socket_path);
1914 GNUNET_free (plugin);
1919 /* end of plugin_transport_unix.c */