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;
248 * The port we bound to (not an actual PORT, as UNIX domain sockets
249 * don't have ports, but rather a number in the path name to make this
257 * Encapsulation of all of the state of the plugin.
263 * ID of task used to update our addresses when one expires.
265 GNUNET_SCHEDULER_TaskIdentifier address_update_task;
270 GNUNET_SCHEDULER_TaskIdentifier read_task;
275 GNUNET_SCHEDULER_TaskIdentifier write_task;
278 * Number of bytes we currently have in our write queues.
280 unsigned long long bytes_in_queue;
285 struct GNUNET_TRANSPORT_PluginEnvironment *env;
288 * Sessions (map from peer identity to `struct Session`)
290 struct GNUNET_CONTAINER_MultiPeerMap *session_map;
293 * Head of queue of messages to transmit.
295 struct UNIXMessageWrapper *msg_head;
298 * Tail of queue of messages to transmit.
300 struct UNIXMessageWrapper *msg_tail;
303 * Path of our unix domain socket (/tmp/unix-plugin-PORT)
305 char *unix_socket_path;
308 * Function to call about session status changes.
310 GNUNET_TRANSPORT_SessionInfoCallback sic;
313 * Closure for @e sic.
318 * socket that we transmit all data with
320 struct UNIX_Sock_Info unix_sock;
323 * Address options in HBO
330 struct GNUNET_ATS_Information ats_network;
333 * Are we using an abstract UNIX domain socket?
341 * If a session monitor is attached, notify it about the new
344 * @param plugin our plugin
345 * @param session session that changed state
346 * @param state new state of the session
349 notify_session_monitor (struct Plugin *plugin,
350 struct Session *session,
351 enum GNUNET_TRANSPORT_SessionState state)
353 struct GNUNET_TRANSPORT_SessionInfo info;
355 if (NULL == plugin->sic)
357 memset (&info, 0, sizeof (info));
359 info.is_inbound = GNUNET_SYSERR; /* hard to say */
360 info.num_msg_pending = session->msgs_in_queue;
361 info.num_bytes_pending = session->bytes_in_queue;
362 /* info.receive_delay remains zero as this is not supported by UNIX
363 (cannot selectively not receive from 'some' peer while continuing
364 to receive from others) */
365 info.session_timeout = session->timeout;
366 info.address = session->address;
367 plugin->sic (plugin->sic_cls,
374 * Function called for a quick conversion of the binary address to
375 * a numeric address. Note that the caller must not free the
376 * address and that the next call to this function is allowed
377 * to override the address again.
380 * @param addr binary address
381 * @param addrlen length of the @a addr
382 * @return string representing the same address
385 unix_plugin_address_to_string (void *cls,
389 static char rbuf[1024];
390 struct UnixAddress *ua = (struct UnixAddress *) addr;
395 if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen))
400 addrstr = (char *) &ua[1];
401 addr_str_len = ntohl (ua->addrlen);
403 if (addr_str_len != addrlen - sizeof(struct UnixAddress))
408 if ('\0' != addrstr[addr_str_len - 1])
413 if (strlen (addrstr) + 1 != addr_str_len)
420 if ('\0' == addrstr[0])
422 memset (rbuf, 0, sizeof (rbuf));
423 GNUNET_snprintf (rbuf,
428 (off == 1) ? "@" : "",
429 (int) (addr_str_len - off),
436 * Functions with this signature are called whenever we need
437 * to close a session due to a disconnect or failure to
438 * establish a connection.
440 * @param cls closure with the `struct Plugin *`
441 * @param session session to close down
442 * @return #GNUNET_OK on success
445 unix_plugin_session_disconnect (void *cls,
446 struct Session *session)
448 struct Plugin *plugin = cls;
449 struct UNIXMessageWrapper *msgw;
450 struct UNIXMessageWrapper *next;
452 LOG (GNUNET_ERROR_TYPE_DEBUG,
453 "Disconnecting session for peer `%s' `%s'\n",
454 GNUNET_i2s (&session->target),
455 unix_plugin_address_to_string (NULL,
456 session->address->address,
457 session->address->address_length));
458 plugin->env->session_end (plugin->env->cls,
461 next = plugin->msg_head;
466 if (msgw->session != session)
468 GNUNET_CONTAINER_DLL_remove (plugin->msg_head,
471 session->msgs_in_queue--;
472 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
473 session->bytes_in_queue -= msgw->msgsize;
474 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
475 plugin->bytes_in_queue -= msgw->msgsize;
476 if (NULL != msgw->cont)
477 msgw->cont (msgw->cont_cls,
478 &msgw->session->target,
481 GNUNET_free (msgw->msg);
484 GNUNET_assert (GNUNET_YES ==
485 GNUNET_CONTAINER_multipeermap_remove (plugin->session_map,
488 GNUNET_STATISTICS_set (plugin->env->stats,
489 "# UNIX sessions active",
490 GNUNET_CONTAINER_multipeermap_size (plugin->session_map),
492 if (GNUNET_SCHEDULER_NO_TASK != session->timeout_task)
494 GNUNET_SCHEDULER_cancel (session->timeout_task);
495 session->timeout_task = GNUNET_SCHEDULER_NO_TASK;
496 session->timeout = GNUNET_TIME_UNIT_ZERO_ABS;
498 notify_session_monitor (plugin,
500 GNUNET_TRANSPORT_SS_DOWN);
501 GNUNET_HELLO_address_free (session->address);
502 GNUNET_break (0 == session->bytes_in_queue);
503 GNUNET_break (0 == session->msgs_in_queue);
504 GNUNET_free (session);
510 * Session was idle for too long, so disconnect it
512 * @param cls the `struct Session *` to disconnect
513 * @param tc scheduler context
516 session_timeout (void *cls,
517 const struct GNUNET_SCHEDULER_TaskContext *tc)
519 struct Session *session = cls;
520 struct GNUNET_TIME_Relative left;
522 session->timeout_task = GNUNET_SCHEDULER_NO_TASK;
523 left = GNUNET_TIME_absolute_get_remaining (session->timeout);
524 if (0 != left.rel_value_us)
526 /* not actually our turn yet, but let's at least update
527 the monitor, it may think we're about to die ... */
528 notify_session_monitor (session->plugin,
530 GNUNET_TRANSPORT_SS_UP);
531 session->timeout_task = GNUNET_SCHEDULER_add_delayed (left,
536 LOG (GNUNET_ERROR_TYPE_DEBUG,
537 "Session %p was idle for %s, disconnecting\n",
539 GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
541 unix_plugin_session_disconnect (session->plugin, session);
546 * Increment session timeout due to activity. We do not immediately
547 * notify the monitor here as that might generate excessive
550 * @param session session for which the timeout should be rescheduled
553 reschedule_session_timeout (struct Session *session)
555 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != session->timeout_task);
556 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
561 * Convert unix path to a `struct sockaddr_un *`
563 * @param unixpath path to convert
564 * @param sock_len[out] set to the length of the address
565 * @return converted unix path
567 static struct sockaddr_un *
568 unix_address_to_sockaddr (const char *unixpath,
571 struct sockaddr_un *un;
574 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
575 un = GNUNET_new (struct sockaddr_un);
576 un->sun_family = AF_UNIX;
577 slen = strlen (unixpath);
578 if (slen >= sizeof (un->sun_path))
579 slen = sizeof (un->sun_path) - 1;
580 memcpy (un->sun_path, unixpath, slen);
581 un->sun_path[slen] = '\0';
582 slen = sizeof (struct sockaddr_un);
583 #if HAVE_SOCKADDR_IN_SIN_LEN
584 un->sun_len = (u_char) slen;
592 * Closure to #lookup_session_it().
597 * Location to store the session, if found.
602 * Address we are looking for.
604 const struct GNUNET_HELLO_Address *address;
609 * Function called to find a session by address.
611 * @param cls the `struct LookupCtx *`
612 * @param key peer we are looking for (unused)
613 * @param value a session
614 * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success
617 lookup_session_it (void *cls,
618 const struct GNUNET_PeerIdentity * key,
621 struct LookupCtx *lctx = cls;
622 struct Session *session = value;
624 if (0 == GNUNET_HELLO_address_cmp (lctx->address,
635 * Find an existing session by address.
637 * @param plugin the plugin
638 * @param address the address to find
639 * @return NULL if session was not found
641 static struct Session *
642 lookup_session (struct Plugin *plugin,
643 const struct GNUNET_HELLO_Address *address)
645 struct LookupCtx lctx;
647 lctx.address = address;
649 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map,
651 &lookup_session_it, &lctx);
657 * Function that is called to get the keepalive factor.
658 * #GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to
659 * calculate the interval between keepalive packets.
661 * @param cls closure with the `struct Plugin`
662 * @return keepalive factor
665 unix_plugin_query_keepalive_factor (void *cls)
672 * Actually send out the message, assume we've got the address and
673 * send_handle squared away!
676 * @param send_handle which handle to send message on
677 * @param target who should receive this message (ignored by UNIX)
678 * @param msgbuf one or more GNUNET_MessageHeader(s) strung together
679 * @param msgbuf_size the size of the @a msgbuf to send
680 * @param priority how important is the message (ignored by UNIX)
681 * @param timeout when should we time out (give up) if we can not transmit?
682 * @param addr the addr to send the message to, needs to be a sockaddr for us
683 * @param addrlen the len of @a addr
684 * @param payload bytes payload to send
685 * @param cont continuation to call once the message has
686 * been transmitted (or if the transport is ready
687 * for the next transmission call; or if the
688 * peer disconnected...)
689 * @param cont_cls closure for @a cont
690 * @return on success the number of bytes written, RETRY for retry, -1 on errors
693 unix_real_send (void *cls,
694 struct GNUNET_NETWORK_Handle *send_handle,
695 const struct GNUNET_PeerIdentity *target,
698 unsigned int priority,
699 struct GNUNET_TIME_Absolute timeout,
700 const struct UnixAddress *addr,
703 GNUNET_TRANSPORT_TransmitContinuation cont,
706 struct Plugin *plugin = cls;
708 struct sockaddr_un *un;
710 const char *unixpath;
712 if (NULL == send_handle)
714 GNUNET_break (0); /* We do not have a send handle */
715 return GNUNET_SYSERR;
717 if ((NULL == addr) || (0 == addrlen))
719 GNUNET_break (0); /* Can never send if we don't have an address */
720 return GNUNET_SYSERR;
723 /* Prepare address */
724 unixpath = (const char *) &addr[1];
725 if (NULL == (un = unix_address_to_sockaddr (unixpath,
732 if ((GNUNET_YES == plugin->is_abstract) &&
733 (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl(addr->options) )) )
735 un->sun_path[0] = '\0';
739 sent = GNUNET_NETWORK_socket_sendto (send_handle,
742 (const struct sockaddr *) un,
744 if (GNUNET_SYSERR == sent)
746 if ( (EAGAIN == errno) ||
750 return RETRY; /* We have to retry later */
752 if (EMSGSIZE == errno)
755 socklen_t len = sizeof (size);
757 GNUNET_NETWORK_socket_getsockopt ((struct GNUNET_NETWORK_Handle *)
758 send_handle, SOL_SOCKET, SO_SNDBUF, &size,
760 if (size < msgbuf_size)
762 LOG (GNUNET_ERROR_TYPE_DEBUG,
763 "Trying to increase socket buffer size from %u to %u for message size %u\n",
765 (unsigned int) ((msgbuf_size / 1000) + 2) * 1000,
766 (unsigned int) msgbuf_size);
767 size = ((msgbuf_size / 1000) + 2) * 1000;
769 GNUNET_NETWORK_socket_setsockopt ((struct GNUNET_NETWORK_Handle *) send_handle,
770 SOL_SOCKET, SO_SNDBUF,
771 &size, sizeof (size)))
772 goto resend; /* Increased buffer size, retry sending */
775 /* Could not increase buffer size: error, no retry */
776 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt");
778 return GNUNET_SYSERR;
783 /* Buffer is bigger than message: error, no retry
784 * This should never happen!*/
787 return GNUNET_SYSERR;
792 LOG (GNUNET_ERROR_TYPE_DEBUG,
793 "UNIX transmitted %u-byte message to %s (%d: %s)\n",
794 (unsigned int) msgbuf_size,
795 GNUNET_a2s ((const struct sockaddr *)un, un_len),
797 (sent < 0) ? STRERROR (errno) : "ok");
804 * Function obtain the network type for a session
806 * @param cls closure ('struct Plugin*')
807 * @param session the session
808 * @return the network type in HBO or #GNUNET_SYSERR
810 static enum GNUNET_ATS_Network_Type
811 unix_plugin_get_network (void *cls,
812 struct Session *session)
814 GNUNET_assert (NULL != session);
815 return GNUNET_ATS_NET_LOOPBACK;
820 * Creates a new outbound session the transport service will use to send data to the
823 * @param cls the plugin
824 * @param address the address
825 * @return the session or NULL of max connections exceeded
827 static struct Session *
828 unix_plugin_get_session (void *cls,
829 const struct GNUNET_HELLO_Address *address)
831 struct Plugin *plugin = cls;
832 struct Session *session;
833 struct UnixAddress *ua;
835 uint32_t addr_str_len;
836 uint32_t addr_option;
838 ua = (struct UnixAddress *) address->address;
839 if ((NULL == address->address) || (0 == address->address_length) ||
840 (sizeof (struct UnixAddress) > address->address_length))
845 addrstr = (char *) &ua[1];
846 addr_str_len = ntohl (ua->addrlen);
847 addr_option = ntohl (ua->options);
849 if ( (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & addr_option)) &&
850 (GNUNET_NO == plugin->is_abstract))
855 if (addr_str_len != address->address_length - sizeof (struct UnixAddress))
857 return NULL; /* This can be a legacy address */
860 if ('\0' != addrstr[addr_str_len - 1])
865 if (strlen (addrstr) + 1 != addr_str_len)
871 /* Check if a session for this address already exists */
872 if (NULL != (session = lookup_session (plugin,
875 LOG (GNUNET_ERROR_TYPE_DEBUG,
876 "Found existing session %p for address `%s'\n",
878 unix_plugin_address_to_string (NULL,
880 address->address_length));
884 /* create a new session */
885 session = GNUNET_new (struct Session);
886 session->target = address->peer;
887 session->address = GNUNET_HELLO_address_copy (address);
888 session->plugin = plugin;
889 session->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
892 LOG (GNUNET_ERROR_TYPE_DEBUG,
893 "Creating a new session %p for address `%s'\n",
895 unix_plugin_address_to_string (NULL,
897 address->address_length));
898 (void) GNUNET_CONTAINER_multipeermap_put (plugin->session_map,
899 &address->peer, session,
900 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
901 GNUNET_STATISTICS_set (plugin->env->stats,
902 "# UNIX sessions active",
903 GNUNET_CONTAINER_multipeermap_size (plugin->session_map),
905 notify_session_monitor (plugin,
907 GNUNET_TRANSPORT_SS_UP);
913 * Function that will be called whenever the transport service wants
914 * to notify the plugin that a session is still active and in use and
915 * therefore the session timeout for this session has to be updated
917 * @param cls closure with the `struct Plugin *`
918 * @param peer which peer was the session for
919 * @param session which session is being updated
922 unix_plugin_update_session_timeout (void *cls,
923 const struct GNUNET_PeerIdentity *peer,
924 struct Session *session)
926 struct Plugin *plugin = cls;
929 GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map,
936 reschedule_session_timeout (session);
941 * Demultiplexer for UNIX messages
943 * @param plugin the main plugin for this transport
944 * @param sender from which peer the message was received
945 * @param currhdr pointer to the header of the message
946 * @param ua address to look for
947 * @param ua_len length of the address @a ua
950 unix_demultiplexer (struct Plugin *plugin,
951 struct GNUNET_PeerIdentity *sender,
952 const struct GNUNET_MessageHeader *currhdr,
953 const struct UnixAddress *ua, size_t ua_len)
955 struct Session *session;
956 struct GNUNET_HELLO_Address *address;
958 GNUNET_break (ntohl(plugin->ats_network.value) != GNUNET_ATS_NET_UNSPECIFIED);
959 GNUNET_assert (ua_len >= sizeof (struct UnixAddress));
960 LOG (GNUNET_ERROR_TYPE_DEBUG,
961 "Received message from %s\n",
962 unix_plugin_address_to_string (NULL, ua, ua_len));
963 GNUNET_STATISTICS_update (plugin->env->stats,
964 "# bytes received via UNIX",
965 ntohs (currhdr->size),
968 /* Look for existing session */
969 address = GNUNET_HELLO_address_allocate (sender,
972 GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */
973 session = lookup_session (plugin, address);
976 session = unix_plugin_get_session (plugin, address);
977 /* Notify transport and ATS about new inbound session */
978 plugin->env->session_start (NULL,
981 &plugin->ats_network, 1);
982 notify_session_monitor (plugin,
984 GNUNET_TRANSPORT_SS_UP);
988 reschedule_session_timeout (session);
990 GNUNET_HELLO_address_free (address);
991 plugin->env->receive (plugin->env->cls,
995 plugin->env->update_address_metrics (plugin->env->cls,
998 &plugin->ats_network, 1);
1003 * Read from UNIX domain socket (it is ready).
1005 * @param plugin the plugin
1008 unix_plugin_do_read (struct Plugin *plugin)
1010 char buf[65536] GNUNET_ALIGN;
1011 struct UnixAddress *ua;
1012 struct UNIXMessage *msg;
1013 struct GNUNET_PeerIdentity sender;
1014 struct sockaddr_un un;
1021 const struct GNUNET_MessageHeader *currhdr;
1025 addrlen = sizeof (un);
1026 memset (&un, 0, sizeof (un));
1027 ret = GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc,
1029 (struct sockaddr *) &un,
1031 if ((GNUNET_SYSERR == ret) && ((errno == EAGAIN) || (errno == ENOBUFS)))
1033 if (GNUNET_SYSERR == ret)
1035 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
1041 LOG (GNUNET_ERROR_TYPE_DEBUG,
1042 "Read %d bytes from socket %s\n",
1047 GNUNET_assert (AF_UNIX == (un.sun_family));
1048 is_abstract = GNUNET_NO;
1049 if ('\0' == un.sun_path[0])
1051 un.sun_path[0] = '@';
1052 is_abstract = GNUNET_YES;
1055 ua_len = sizeof (struct UnixAddress) + strlen (un.sun_path) + 1;
1056 ua = GNUNET_malloc (ua_len);
1057 ua->addrlen = htonl (strlen (&un.sun_path[0]) +1);
1058 memcpy (&ua[1], &un.sun_path[0], strlen (un.sun_path) + 1);
1060 ua->options = htonl(UNIX_OPTIONS_USE_ABSTRACT_SOCKETS);
1062 ua->options = htonl(UNIX_OPTIONS_NONE);
1064 msg = (struct UNIXMessage *) buf;
1065 csize = ntohs (msg->header.size);
1066 if ((csize < sizeof (struct UNIXMessage)) || (csize > ret))
1068 GNUNET_break_op (0);
1072 msgbuf = (char *) &msg[1];
1075 sizeof (struct GNUNET_PeerIdentity));
1077 tsize = csize - sizeof (struct UNIXMessage);
1078 while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize)
1080 currhdr = (struct GNUNET_MessageHeader *) &msgbuf[offset];
1081 csize = ntohs (currhdr->size);
1082 if ((csize < sizeof (struct GNUNET_MessageHeader)) ||
1083 (csize > tsize - offset))
1085 GNUNET_break_op (0);
1088 unix_demultiplexer (plugin, &sender, currhdr, ua, ua_len);
1096 * Write to UNIX domain socket (it is ready).
1098 * @param session session to write data for
1101 unix_plugin_do_write (struct Plugin *plugin)
1104 struct UNIXMessageWrapper *msgw;
1105 struct Session *session;
1108 did_delete = GNUNET_NO;
1109 while (NULL != (msgw = plugin->msg_head))
1111 if (GNUNET_TIME_absolute_get_remaining (msgw->timeout).rel_value_us > 0)
1112 break; /* Message is ready for sending */
1113 /* Message has a timeout */
1114 did_delete = GNUNET_YES;
1115 LOG (GNUNET_ERROR_TYPE_DEBUG,
1116 "Timeout for message with %u bytes \n",
1117 (unsigned int) msgw->msgsize);
1118 GNUNET_CONTAINER_DLL_remove (plugin->msg_head,
1121 session = msgw->session;
1122 session->msgs_in_queue--;
1123 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
1124 session->bytes_in_queue -= msgw->msgsize;
1125 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
1126 plugin->bytes_in_queue -= msgw->msgsize;
1127 GNUNET_STATISTICS_set (plugin->env->stats,
1128 "# bytes currently in UNIX buffers",
1129 plugin->bytes_in_queue,
1131 GNUNET_STATISTICS_update (plugin->env->stats,
1132 "# UNIX bytes discarded",
1135 if (NULL != msgw->cont)
1136 msgw->cont (msgw->cont_cls,
1137 &msgw->session->target,
1141 GNUNET_free (msgw->msg);
1146 if (GNUNET_YES == did_delete)
1147 notify_session_monitor (plugin,
1149 GNUNET_TRANSPORT_SS_UP);
1150 return; /* Nothing to send at the moment */
1153 sent = unix_real_send (plugin,
1154 plugin->unix_sock.desc,
1155 &msgw->session->target,
1156 (const char *) msgw->msg,
1160 msgw->session->address->address,
1161 msgw->session->address->address_length,
1163 msgw->cont, msgw->cont_cls);
1166 GNUNET_STATISTICS_update (plugin->env->stats,
1167 "# UNIX retry attempts",
1169 notify_session_monitor (plugin,
1171 GNUNET_TRANSPORT_SS_UP);
1174 GNUNET_CONTAINER_DLL_remove (plugin->msg_head,
1177 session = msgw->session;
1178 session->msgs_in_queue--;
1179 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
1180 session->bytes_in_queue -= msgw->msgsize;
1181 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
1182 plugin->bytes_in_queue -= msgw->msgsize;
1183 GNUNET_STATISTICS_set (plugin->env->stats,
1184 "# bytes currently in UNIX buffers",
1185 plugin->bytes_in_queue, GNUNET_NO);
1186 notify_session_monitor (plugin,
1188 GNUNET_TRANSPORT_SS_UP);
1189 if (GNUNET_SYSERR == sent)
1191 /* failed and no retry */
1192 if (NULL != msgw->cont)
1193 msgw->cont (msgw->cont_cls,
1194 &msgw->session->target,
1197 GNUNET_STATISTICS_update (plugin->env->stats,
1198 "# UNIX bytes discarded",
1201 GNUNET_free (msgw->msg);
1205 /* successfully sent bytes */
1206 GNUNET_break (sent > 0);
1207 GNUNET_STATISTICS_update (plugin->env->stats,
1208 "# bytes transmitted via UNIX",
1211 if (NULL != msgw->cont)
1212 msgw->cont (msgw->cont_cls,
1213 &msgw->session->target,
1217 GNUNET_free (msgw->msg);
1223 * We have been notified that our socket has something to read.
1224 * Then reschedule this function to be called again once more is available.
1226 * @param cls the plugin handle
1227 * @param tc the scheduling context
1230 unix_plugin_select_read (void *cls,
1231 const struct GNUNET_SCHEDULER_TaskContext *tc)
1233 struct Plugin *plugin = cls;
1235 plugin->read_task = GNUNET_SCHEDULER_NO_TASK;
1236 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1238 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
1239 unix_plugin_do_read (plugin);
1241 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1242 plugin->unix_sock.desc,
1243 &unix_plugin_select_read, plugin);
1248 * We have been notified that our socket is ready to write.
1249 * Then reschedule this function to be called again once more is available.
1251 * @param cls the plugin handle
1252 * @param tc the scheduling context
1255 unix_plugin_select_write (void *cls,
1256 const struct GNUNET_SCHEDULER_TaskContext *tc)
1258 struct Plugin *plugin = cls;
1260 plugin->write_task = GNUNET_SCHEDULER_NO_TASK;
1261 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1263 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))
1264 unix_plugin_do_write (plugin);
1265 if (NULL == plugin->msg_head)
1266 return; /* write queue empty */
1267 plugin->write_task =
1268 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
1269 plugin->unix_sock.desc,
1270 &unix_plugin_select_write, plugin);
1275 * Function that can be used by the transport service to transmit
1276 * a message using the plugin. Note that in the case of a
1277 * peer disconnecting, the continuation MUST be called
1278 * prior to the disconnect notification itself. This function
1279 * will be called with this peer's HELLO message to initiate
1280 * a fresh connection to another peer.
1282 * @param cls closure
1283 * @param session which session must be used
1284 * @param msgbuf the message to transmit
1285 * @param msgbuf_size number of bytes in @a msgbuf
1286 * @param priority how important is the message (most plugins will
1287 * ignore message priority and just FIFO)
1288 * @param to how long to wait at most for the transmission (does not
1289 * require plugins to discard the message after the timeout,
1290 * just advisory for the desired delay; most plugins will ignore
1292 * @param cont continuation to call once the message has
1293 * been transmitted (or if the transport is ready
1294 * for the next transmission call; or if the
1295 * peer disconnected...); can be NULL
1296 * @param cont_cls closure for @a cont
1297 * @return number of bytes used (on the physical network, with overheads);
1298 * -1 on hard errors (i.e. address invalid); 0 is a legal value
1299 * and does NOT mean that the message was not transmitted (DV)
1302 unix_plugin_send (void *cls,
1303 struct Session *session,
1306 unsigned int priority,
1307 struct GNUNET_TIME_Relative to,
1308 GNUNET_TRANSPORT_TransmitContinuation cont,
1311 struct Plugin *plugin = cls;
1312 struct UNIXMessageWrapper *wrapper;
1313 struct UNIXMessage *message;
1317 GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map,
1321 LOG (GNUNET_ERROR_TYPE_ERROR,
1322 "Invalid session for peer `%s' `%s'\n",
1323 GNUNET_i2s (&session->target),
1324 unix_plugin_address_to_string (NULL,
1325 session->address->address,
1326 session->address->address_length));
1328 return GNUNET_SYSERR;
1330 LOG (GNUNET_ERROR_TYPE_DEBUG,
1331 "Sending %u bytes with session for peer `%s' `%s'\n",
1333 GNUNET_i2s (&session->target),
1334 unix_plugin_address_to_string (NULL,
1335 session->address->address,
1336 session->address->address_length));
1337 ssize = sizeof (struct UNIXMessage) + msgbuf_size;
1338 message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size);
1339 message->header.size = htons (ssize);
1340 message->header.type = htons (0);
1341 memcpy (&message->sender, plugin->env->my_identity,
1342 sizeof (struct GNUNET_PeerIdentity));
1343 memcpy (&message[1], msgbuf, msgbuf_size);
1344 wrapper = GNUNET_new (struct UNIXMessageWrapper);
1345 wrapper->msg = message;
1346 wrapper->msgsize = ssize;
1347 wrapper->payload = msgbuf_size;
1348 wrapper->priority = priority;
1349 wrapper->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
1351 wrapper->cont = cont;
1352 wrapper->cont_cls = cont_cls;
1353 wrapper->session = session;
1354 GNUNET_CONTAINER_DLL_insert_tail (plugin->msg_head,
1357 plugin->bytes_in_queue += ssize;
1358 session->bytes_in_queue += ssize;
1359 session->msgs_in_queue++;
1360 GNUNET_STATISTICS_set (plugin->env->stats,
1361 "# bytes currently in UNIX buffers",
1362 plugin->bytes_in_queue,
1364 notify_session_monitor (plugin,
1366 GNUNET_TRANSPORT_SS_UP);
1367 if (GNUNET_SCHEDULER_NO_TASK == plugin->write_task)
1368 plugin->write_task =
1369 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
1370 plugin->unix_sock.desc,
1371 &unix_plugin_select_write, plugin);
1377 * Create a slew of UNIX sockets. If possible, use IPv6 and IPv4.
1379 * @param cls closure for server start, should be a `struct Plugin *`
1380 * @return number of sockets created or #GNUNET_SYSERR on error
1383 unix_transport_server_start (void *cls)
1385 struct Plugin *plugin = cls;
1386 struct sockaddr_un *un;
1389 un = unix_address_to_sockaddr (plugin->unix_socket_path,
1391 if (GNUNET_YES == plugin->is_abstract)
1393 plugin->unix_socket_path[0] = '@';
1394 un->sun_path[0] = '\0';
1396 plugin->ats_network = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) un, un_len);
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");
1402 return GNUNET_SYSERR;
1404 if ('\0' != un->sun_path[0])
1406 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path))
1408 LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot create path to `%s'\n"),
1410 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
1411 plugin->unix_sock.desc = NULL;
1413 return GNUNET_SYSERR;
1417 GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc,
1418 (const struct sockaddr *) un, un_len))
1420 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
1421 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
1422 plugin->unix_sock.desc = NULL;
1424 return GNUNET_SYSERR;
1426 LOG (GNUNET_ERROR_TYPE_DEBUG,
1428 plugin->unix_socket_path);
1430 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1431 plugin->unix_sock.desc,
1432 &unix_plugin_select_read, plugin);
1439 * Function that will be called to check if a binary address for this
1440 * plugin is well-formed and corresponds to an address for THIS peer
1441 * (as per our configuration). Naturally, if absolutely necessary,
1442 * plugins can be a bit conservative in their answer, but in general
1443 * plugins should make sure that the address does not redirect
1444 * traffic to a 3rd party that might try to man-in-the-middle our
1447 * @param cls closure, should be our handle to the Plugin
1448 * @param addr pointer to the address
1449 * @param addrlen length of @a addr
1450 * @return #GNUNET_OK if this is a plausible address for this peer
1451 * and transport, #GNUNET_SYSERR if not
1455 unix_plugin_check_address (void *cls,
1459 struct Plugin* plugin = cls;
1460 const struct UnixAddress *ua = addr;
1462 size_t addr_str_len;
1464 if ( (NULL == addr) ||
1466 (sizeof (struct UnixAddress) > addrlen) )
1469 return GNUNET_SYSERR;
1471 addrstr = (char *) &ua[1];
1472 addr_str_len = ntohl (ua->addrlen);
1473 if ('\0' != addrstr[addr_str_len - 1])
1476 return GNUNET_SYSERR;
1478 if (strlen (addrstr) + 1 != addr_str_len)
1481 return GNUNET_SYSERR;
1484 if (0 == strcmp (plugin->unix_socket_path, addrstr))
1486 return GNUNET_SYSERR;
1491 * Convert the transports address to a nice, human-readable
1494 * @param cls closure
1495 * @param type name of the transport that generated the address
1496 * @param addr one of the addresses of the host, NULL for the last address
1497 * the specific address format depends on the transport
1498 * @param addrlen length of the @a addr
1499 * @param numeric should (IP) addresses be displayed in numeric form?
1500 * @param timeout after how long should we give up?
1501 * @param asc function to call on each string
1502 * @param asc_cls closure for @a asc
1505 unix_plugin_address_pretty_printer (void *cls, const char *type,
1509 struct GNUNET_TIME_Relative timeout,
1510 GNUNET_TRANSPORT_AddressStringCallback asc,
1515 if ( (NULL != addr) && (addrlen > 0))
1516 ret = unix_plugin_address_to_string (NULL,
1523 (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
1524 asc (asc_cls, NULL, GNUNET_OK);
1529 * Function called to convert a string address to
1532 * @param cls closure (`struct Plugin *`)
1533 * @param addr string address
1534 * @param addrlen length of the @a addr (strlen(addr) + '\0')
1535 * @param buf location to store the buffer
1536 * If the function returns #GNUNET_SYSERR, its contents are undefined.
1537 * @param added length of created address
1538 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
1541 unix_plugin_string_to_address (void *cls,
1544 void **buf, size_t *added)
1546 struct UnixAddress *ua;
1553 /* Format unix.options.address */
1558 if ((NULL == addr) || (addrlen == 0))
1561 return GNUNET_SYSERR;
1563 if ('\0' != addr[addrlen - 1])
1566 return GNUNET_SYSERR;
1568 if (strlen (addr) != addrlen - 1)
1571 return GNUNET_SYSERR;
1573 plugin = GNUNET_strdup (addr);
1574 optionstr = strchr (plugin, '.');
1575 if (NULL == optionstr)
1578 GNUNET_free (plugin);
1579 return GNUNET_SYSERR;
1581 optionstr[0] = '\0';
1583 options = atol (optionstr);
1584 address = strchr (optionstr, '.');
1585 if (NULL == address)
1588 GNUNET_free (plugin);
1589 return GNUNET_SYSERR;
1593 if (0 != strcmp(plugin, PLUGIN_NAME))
1596 GNUNET_free (plugin);
1597 return GNUNET_SYSERR;
1600 ua_size = sizeof (struct UnixAddress) + strlen (address) + 1;
1601 ua = GNUNET_malloc (ua_size);
1602 ua->options = htonl (options);
1603 ua->addrlen = htonl (strlen (address) + 1);
1604 memcpy (&ua[1], address, strlen (address) + 1);
1605 GNUNET_free (plugin);
1614 * Notify transport service about address
1616 * @param cls the plugin
1620 address_notification (void *cls,
1621 const struct GNUNET_SCHEDULER_TaskContext *tc)
1623 struct Plugin *plugin = cls;
1624 struct GNUNET_HELLO_Address *address;
1626 struct UnixAddress *ua;
1629 len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1;
1630 ua = GNUNET_malloc (len);
1631 ua->options = htonl (plugin->myoptions);
1632 ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1);
1633 unix_path = (char *) &ua[1];
1634 memcpy (unix_path, plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1);
1636 plugin->address_update_task = GNUNET_SCHEDULER_NO_TASK;
1637 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1641 GNUNET_HELLO_ADDRESS_INFO_NONE);
1642 plugin->env->notify_address (plugin->env->cls,
1646 GNUNET_free (address);
1651 * Function called on sessions to disconnect
1653 * @param cls the plugin
1654 * @param key peer identity (unused)
1655 * @param value the `struct Session *` to disconnect
1656 * @return #GNUNET_YES (always, continue to iterate)
1659 get_session_delete_it (void *cls,
1660 const struct GNUNET_PeerIdentity *key,
1663 struct Plugin *plugin = cls;
1664 struct Session *session = value;
1666 unix_plugin_session_disconnect (plugin, session);
1672 * Disconnect from a remote node. Clean up session if we have one for this peer
1674 * @param cls closure for this call (should be handle to Plugin)
1675 * @param target the peeridentity of the peer to disconnect
1676 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed
1679 unix_plugin_peer_disconnect (void *cls,
1680 const struct GNUNET_PeerIdentity *target)
1682 struct Plugin *plugin = cls;
1684 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map,
1686 &get_session_delete_it, plugin);
1691 * Return information about the given session to the
1694 * @param cls the `struct Plugin` with the monitor callback (`sic`)
1695 * @param peer peer we send information about
1696 * @param value our `struct Session` to send information about
1697 * @return #GNUNET_OK (continue to iterate)
1700 send_session_info_iter (void *cls,
1701 const struct GNUNET_PeerIdentity *peer,
1704 struct Plugin *plugin = cls;
1705 struct Session *session = value;
1707 notify_session_monitor (plugin,
1709 GNUNET_TRANSPORT_SS_UP);
1715 * Begin monitoring sessions of a plugin. There can only
1716 * be one active monitor per plugin (i.e. if there are
1717 * multiple monitors, the transport service needs to
1718 * multiplex the generated events over all of them).
1720 * @param cls closure of the plugin
1721 * @param sic callback to invoke, NULL to disable monitor;
1722 * plugin will being by iterating over all active
1723 * sessions immediately and then enter monitor mode
1724 * @param sic_cls closure for @a sic
1727 unix_plugin_setup_monitor (void *cls,
1728 GNUNET_TRANSPORT_SessionInfoCallback sic,
1731 struct Plugin *plugin = cls;
1734 plugin->sic_cls = sic_cls;
1737 GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map,
1738 &send_session_info_iter,
1740 /* signal end of first iteration */
1741 sic (sic_cls, NULL, NULL);
1747 * The exported method. Initializes the plugin and returns a
1748 * struct with the callbacks.
1750 * @param cls the plugin's execution environment
1751 * @return NULL on error, plugin functions otherwise
1754 libgnunet_plugin_transport_unix_init (void *cls)
1756 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
1757 struct GNUNET_TRANSPORT_PluginFunctions *api;
1758 struct Plugin *plugin;
1759 int sockets_created;
1761 if (NULL == env->receive)
1763 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
1764 initialze the plugin or the API */
1765 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
1767 api->address_pretty_printer = &unix_plugin_address_pretty_printer;
1768 api->address_to_string = &unix_plugin_address_to_string;
1769 api->string_to_address = &unix_plugin_string_to_address;
1773 plugin = GNUNET_new (struct Plugin);
1775 GNUNET_CONFIGURATION_get_value_filename (env->cfg,
1778 &plugin->unix_socket_path))
1780 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1783 GNUNET_free (plugin);
1789 /* Initialize my flags */
1791 plugin->is_abstract = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
1793 "USE_ABSTRACT_SOCKETS");
1795 plugin->myoptions = UNIX_OPTIONS_NONE;
1796 if (GNUNET_YES == plugin->is_abstract)
1797 plugin->myoptions = UNIX_OPTIONS_USE_ABSTRACT_SOCKETS;
1799 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
1801 api->get_session = &unix_plugin_get_session;
1802 api->send = &unix_plugin_send;
1803 api->disconnect_peer = &unix_plugin_peer_disconnect;
1804 api->disconnect_session = &unix_plugin_session_disconnect;
1805 api->query_keepalive_factor = &unix_plugin_query_keepalive_factor;
1806 api->address_pretty_printer = &unix_plugin_address_pretty_printer;
1807 api->address_to_string = &unix_plugin_address_to_string;
1808 api->check_address = &unix_plugin_check_address;
1809 api->string_to_address = &unix_plugin_string_to_address;
1810 api->get_network = &unix_plugin_get_network;
1811 api->update_session_timeout = &unix_plugin_update_session_timeout;
1812 api->setup_monitor = &unix_plugin_setup_monitor;
1813 sockets_created = unix_transport_server_start (plugin);
1814 if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created))
1816 LOG (GNUNET_ERROR_TYPE_WARNING,
1817 _("Failed to open UNIX listen socket\n"));
1819 GNUNET_free (plugin->unix_socket_path);
1820 GNUNET_free (plugin);
1823 plugin->session_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1824 plugin->address_update_task = GNUNET_SCHEDULER_add_now (&address_notification,
1831 * Shutdown the plugin.
1833 * @param cls the plugin API returned from the initialization function
1834 * @return NULL (always)
1837 libgnunet_plugin_transport_unix_done (void *cls)
1839 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1840 struct Plugin *plugin = api->cls;
1841 struct GNUNET_HELLO_Address *address;
1842 struct UNIXMessageWrapper * msgw;
1843 struct UnixAddress *ua;
1845 struct Session *session;
1852 len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1;
1853 ua = GNUNET_malloc (len);
1854 ua->options = htonl (plugin->myoptions);
1855 ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1);
1857 plugin->unix_socket_path,
1858 strlen (plugin->unix_socket_path) + 1);
1859 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1862 GNUNET_HELLO_ADDRESS_INFO_NONE);
1863 plugin->env->notify_address (plugin->env->cls,
1867 GNUNET_free (address);
1870 while (NULL != (msgw = plugin->msg_head))
1872 GNUNET_CONTAINER_DLL_remove (plugin->msg_head,
1875 session = msgw->session;
1876 session->msgs_in_queue--;
1877 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
1878 session->bytes_in_queue -= msgw->msgsize;
1879 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
1880 plugin->bytes_in_queue -= msgw->msgsize;
1881 if (NULL != msgw->cont)
1882 msgw->cont (msgw->cont_cls,
1883 &msgw->session->target,
1886 GNUNET_free (msgw->msg);
1890 if (GNUNET_SCHEDULER_NO_TASK != plugin->read_task)
1892 GNUNET_SCHEDULER_cancel (plugin->read_task);
1893 plugin->read_task = GNUNET_SCHEDULER_NO_TASK;
1895 if (GNUNET_SCHEDULER_NO_TASK != plugin->write_task)
1897 GNUNET_SCHEDULER_cancel (plugin->write_task);
1898 plugin->write_task = GNUNET_SCHEDULER_NO_TASK;
1900 if (GNUNET_SCHEDULER_NO_TASK != plugin->address_update_task)
1902 GNUNET_SCHEDULER_cancel (plugin->address_update_task);
1903 plugin->address_update_task = GNUNET_SCHEDULER_NO_TASK;
1905 if (NULL != plugin->unix_sock.desc)
1907 GNUNET_break (GNUNET_OK ==
1908 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc));
1909 plugin->unix_sock.desc = NULL;
1911 GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map,
1912 &get_session_delete_it,
1914 GNUNET_CONTAINER_multipeermap_destroy (plugin->session_map);
1915 GNUNET_break (0 == plugin->bytes_in_queue);
1916 GNUNET_free (plugin->unix_socket_path);
1917 GNUNET_free (plugin);
1922 /* end of plugin_transport_unix.c */