2 This file is part of GNUnet
3 (C) 2010, 2011 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_udp.c
23 * @brief Implementation of the UDP transport protocol
24 * @author Christian Grothoff
25 * @author Nathan Evans
26 * @author Matthias Wachs
29 #include "plugin_transport_udp.h"
30 #include "gnunet_hello_lib.h"
31 #include "gnunet_util_lib.h"
32 #include "gnunet_fragmentation_lib.h"
33 #include "gnunet_nat_lib.h"
34 #include "gnunet_protocols.h"
35 #include "gnunet_resolver_service.h"
36 #include "gnunet_signatures.h"
37 #include "gnunet_constants.h"
38 #include "gnunet_statistics_service.h"
39 #include "gnunet_transport_service.h"
40 #include "gnunet_transport_plugin.h"
41 #include "transport.h"
43 #define LOG(kind,...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__)
47 * Number of messages we can defragment in parallel. We only really
48 * defragment 1 message at a time, but if messages get re-ordered, we
49 * may want to keep knowledge about the previous message to avoid
50 * discarding the current message in favor of a single fragment of a
51 * previous message. 3 should be good since we don't expect massive
52 * message reorderings with UDP.
54 #define UDP_MAX_MESSAGES_IN_DEFRAG 3
57 * We keep a defragmentation queue per sender address. How many
58 * sender addresses do we support at the same time? Memory consumption
59 * is roughly a factor of 32k * UDP_MAX_MESSAGES_IN_DEFRAG times this
60 * value. (So 128 corresponds to 12 MB and should suffice for
61 * connecting to roughly 128 peers via UDP).
63 #define UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG 128
68 * Closure for 'append_port'.
70 struct PrettyPrinterContext
73 * Function to call with the result.
75 GNUNET_TRANSPORT_AddressStringCallback asc;
83 * Port to add after the IP address.
91 * Which peer is this session for?
93 struct GNUNET_PeerIdentity target;
96 * Address of the other peer
98 const struct sockaddr *sock_addr;
103 * Desired delay for next sending we send to other peer
105 struct GNUNET_TIME_Relative flow_delay_for_other_peer;
108 * Desired delay for next sending we received from other peer
110 struct GNUNET_TIME_Absolute flow_delay_from_other_peer;
113 * expected delay for ACKs
115 struct GNUNET_TIME_Relative last_expected_delay;
118 struct GNUNET_ATS_Information ats;
120 struct FragmentationContext * frag_ctx;
124 struct SessionCompareContext
127 const struct GNUNET_HELLO_Address *addr;
132 * Closure for 'process_inbound_tokenized_messages'
134 struct SourceInformation
139 struct GNUNET_PeerIdentity sender;
147 * Number of bytes in source address.
151 struct Session *session;
156 * Closure for 'find_receive_context'.
158 struct FindReceiveContext
161 * Where to store the result.
163 struct DefragContext *rc;
168 const struct sockaddr *addr;
171 * Number of bytes in 'addr'.
175 struct Session *session;
181 * Data structure to track defragmentation contexts based
182 * on the source of the UDP traffic.
188 * Defragmentation context.
190 struct GNUNET_DEFRAGMENT_Context *defrag;
193 * Source address this receive context is for (allocated at the
194 * end of the struct).
196 const struct sockaddr *src_addr;
199 * Reference to master plugin struct.
201 struct Plugin *plugin;
204 * Node in the defrag heap.
206 struct GNUNET_CONTAINER_HeapNode *hnode;
209 * Length of 'src_addr'
217 * Closure for 'process_inbound_tokenized_messages'
219 struct FragmentationContext
221 struct FragmentationContext * next;
222 struct FragmentationContext * prev;
224 struct Plugin * plugin;
225 struct GNUNET_FRAGMENT_Context * frag;
226 struct Session * session;
228 struct GNUNET_TIME_Absolute timeout;
232 * Function to call upon completion of the transmission.
234 GNUNET_TRANSPORT_TransmitContinuation cont;
237 * Closure for 'cont'.
241 size_t bytes_to_send;
245 struct UDPMessageWrapper
247 struct Session *session;
248 struct UDPMessageWrapper *prev;
249 struct UDPMessageWrapper *next;
253 struct GNUNET_TIME_Absolute timeout;
256 * Function to call upon completion of the transmission.
258 GNUNET_TRANSPORT_TransmitContinuation cont;
261 * Closure for 'cont'.
265 struct FragmentationContext *frag_ctx;
271 * UDP ACK Message-Packet header (after defragmentation).
273 struct UDP_ACK_Message
278 struct GNUNET_MessageHeader header;
281 * Desired delay for flow control
286 * What is the identity of the sender
288 struct GNUNET_PeerIdentity sender;
293 * We have been notified that our readset has something to read. We don't
294 * know which socket needs to be read, so we have to check each one
295 * Then reschedule this function to be called again once more is available.
297 * @param cls the plugin handle
298 * @param tc the scheduling context (for rescheduling this function again)
301 udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
304 * We have been notified that our readset has something to read. We don't
305 * know which socket needs to be read, so we have to check each one
306 * Then reschedule this function to be called again once more is available.
308 * @param cls the plugin handle
309 * @param tc the scheduling context (for rescheduling this function again)
312 udp_plugin_select_v6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
315 * Function called for a quick conversion of the binary address to
316 * a numeric address. Note that the caller must not free the
317 * address and that the next call to this function is allowed
318 * to override the address again.
321 * @param addr binary address
322 * @param addrlen length of the address
323 * @return string representing the same address
326 udp_address_to_string (void *cls, const void *addr, size_t addrlen)
328 static char rbuf[INET6_ADDRSTRLEN + 10];
329 char buf[INET6_ADDRSTRLEN];
333 const struct IPv4UdpAddress *t4;
334 const struct IPv6UdpAddress *t6;
338 if (addrlen == sizeof (struct IPv6UdpAddress))
342 port = ntohs (t6->u6_port);
343 memcpy (&a6, &t6->ipv6_addr, sizeof (a6));
346 else if (addrlen == sizeof (struct IPv4UdpAddress))
350 port = ntohs (t4->u4_port);
351 memcpy (&a4, &t4->ipv4_addr, sizeof (a4));
359 inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
360 GNUNET_snprintf (rbuf, sizeof (rbuf), (af == AF_INET6) ? "[%s]:%u" : "%s:%u",
367 * Function called to convert a string address to
370 * @param cls closure ('struct Plugin*')
371 * @param addr string address
372 * @param addrlen length of the address
373 * @param buf location to store the buffer
374 * @param added location to store the number of bytes in the buffer.
375 * If the function returns GNUNET_SYSERR, its contents are undefined.
376 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
379 udp_string_to_address (void *cls, const char *addr, uint16_t addrlen,
380 void **buf, size_t *added)
382 struct sockaddr_storage socket_address;
384 if ((NULL == addr) || (addrlen == 0))
387 return GNUNET_SYSERR;
390 if ('\0' != addr[addrlen - 1])
392 return GNUNET_SYSERR;
395 if (strlen (addr) != addrlen - 1)
397 return GNUNET_SYSERR;
400 int ret = GNUNET_STRINGS_to_address_ip (addr, strlen (addr),
403 if (ret != GNUNET_OK)
405 return GNUNET_SYSERR;
408 if (socket_address.ss_family == AF_INET)
410 struct IPv4UdpAddress *u4;
411 struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address;
412 u4 = GNUNET_malloc (sizeof (struct IPv4UdpAddress));
413 u4->ipv4_addr = in4->sin_addr.s_addr;
414 u4->u4_port = in4->sin_port;
416 *added = sizeof (struct IPv4UdpAddress);
419 else if (socket_address.ss_family == AF_INET6)
421 struct IPv6UdpAddress *u6;
422 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address;
423 u6 = GNUNET_malloc (sizeof (struct IPv6UdpAddress));
424 u6->ipv6_addr = in6->sin6_addr;
425 u6->u6_port = in6->sin6_port;
427 *added = sizeof (struct IPv6UdpAddress);
430 return GNUNET_SYSERR;
435 * Append our port and forward the result.
437 * @param cls a 'struct PrettyPrinterContext'
438 * @param hostname result from DNS resolver
441 append_port (void *cls, const char *hostname)
443 struct PrettyPrinterContext *ppc = cls;
446 if (hostname == NULL)
448 ppc->asc (ppc->asc_cls, NULL);
452 GNUNET_asprintf (&ret, "%s:%d", hostname, ppc->port);
453 ppc->asc (ppc->asc_cls, ret);
459 * Convert the transports address to a nice, human-readable
463 * @param type name of the transport that generated the address
464 * @param addr one of the addresses of the host, NULL for the last address
465 * the specific address format depends on the transport
466 * @param addrlen length of the address
467 * @param numeric should (IP) addresses be displayed in numeric form?
468 * @param timeout after how long should we give up?
469 * @param asc function to call on each string
470 * @param asc_cls closure for asc
473 udp_plugin_address_pretty_printer (void *cls, const char *type,
474 const void *addr, size_t addrlen,
476 struct GNUNET_TIME_Relative timeout,
477 GNUNET_TRANSPORT_AddressStringCallback asc,
480 struct PrettyPrinterContext *ppc;
483 struct sockaddr_in a4;
484 struct sockaddr_in6 a6;
485 const struct IPv4UdpAddress *u4;
486 const struct IPv6UdpAddress *u6;
489 if (addrlen == sizeof (struct IPv6UdpAddress))
492 memset (&a6, 0, sizeof (a6));
493 a6.sin6_family = AF_INET6;
494 #if HAVE_SOCKADDR_IN_SIN_LEN
495 a6.sin6_len = sizeof (a6);
497 a6.sin6_port = u6->u6_port;
498 memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof (struct in6_addr));
499 port = ntohs (u6->u6_port);
503 else if (addrlen == sizeof (struct IPv4UdpAddress))
506 memset (&a4, 0, sizeof (a4));
507 a4.sin_family = AF_INET;
508 #if HAVE_SOCKADDR_IN_SIN_LEN
509 a4.sin_len = sizeof (a4);
511 a4.sin_port = u4->u4_port;
512 a4.sin_addr.s_addr = u4->ipv4_addr;
513 port = ntohs (u4->u4_port);
517 else if (0 == addrlen)
519 asc (asc_cls, "<inbound connection>");
525 /* invalid address */
530 ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext));
532 ppc->asc_cls = asc_cls;
534 GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, timeout, &append_port, ppc);
539 * Check if the given port is plausible (must be either our listen
540 * port or our advertised port). If it is neither, we return
543 * @param plugin global variables
544 * @param in_port port number to check
545 * @return GNUNET_OK if port is either open_port or adv_port
548 check_port (struct Plugin *plugin, uint16_t in_port)
550 if ((in_port == plugin->port) || (in_port == plugin->aport))
552 return GNUNET_SYSERR;
558 * Function that will be called to check if a binary address for this
559 * plugin is well-formed and corresponds to an address for THIS peer
560 * (as per our configuration). Naturally, if absolutely necessary,
561 * plugins can be a bit conservative in their answer, but in general
562 * plugins should make sure that the address does not redirect
563 * traffic to a 3rd party that might try to man-in-the-middle our
566 * @param cls closure, should be our handle to the Plugin
567 * @param addr pointer to the address
568 * @param addrlen length of addr
569 * @return GNUNET_OK if this is a plausible address for this peer
570 * and transport, GNUNET_SYSERR if not
574 udp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
576 struct Plugin *plugin = cls;
577 struct IPv4UdpAddress *v4;
578 struct IPv6UdpAddress *v6;
580 if ((addrlen != sizeof (struct IPv4UdpAddress)) &&
581 (addrlen != sizeof (struct IPv6UdpAddress)))
584 return GNUNET_SYSERR;
586 if (addrlen == sizeof (struct IPv4UdpAddress))
588 v4 = (struct IPv4UdpAddress *) addr;
589 if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port)))
590 return GNUNET_SYSERR;
592 GNUNET_NAT_test_address (plugin->nat, &v4->ipv4_addr,
593 sizeof (struct in_addr)))
594 return GNUNET_SYSERR;
598 v6 = (struct IPv6UdpAddress *) addr;
599 if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr))
602 return GNUNET_SYSERR;
604 if (GNUNET_OK != check_port (plugin, ntohs (v6->u6_port)))
605 return GNUNET_SYSERR;
607 GNUNET_NAT_test_address (plugin->nat, &v6->ipv6_addr,
608 sizeof (struct in6_addr)))
609 return GNUNET_SYSERR;
616 * Destroy a session, plugin is being unloaded.
619 * @param key hash of public key of target peer
620 * @param value a 'struct PeerSession*' to clean up
621 * @return GNUNET_OK (continue to iterate)
624 disconnect_and_free_it (void *cls, const GNUNET_HashCode * key, void *value)
626 struct Plugin *plugin = cls;
627 struct Session *s = value;
628 struct UDPMessageWrapper *udpw;
629 struct UDPMessageWrapper *next;
631 LOG (GNUNET_ERROR_TYPE_DEBUG,
632 "Session %p to peer `%s' address ended \n",
634 GNUNET_i2s (&s->target),
635 GNUNET_a2s (s->sock_addr, s->addrlen));
636 if (s->frag_ctx != NULL)
638 GNUNET_FRAGMENT_context_destroy(s->frag_ctx->frag);
639 GNUNET_free (s->frag_ctx);
643 udpw = plugin->ipv4_queue_head;
647 if (udpw->session == s)
649 GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, plugin->ipv4_queue_tail, udpw);
651 if (udpw->cont != NULL)
652 udpw->cont (udpw->cont_cls, &s->target, GNUNET_SYSERR);
658 udpw = plugin->ipv6_queue_head;
662 if (udpw->session == s)
664 GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, plugin->ipv6_queue_tail, udpw);
666 if (udpw->cont != NULL)
667 udpw->cont (udpw->cont_cls, &s->target, GNUNET_SYSERR);
673 plugin->env->session_end (plugin->env->cls, &s->target, s);
675 GNUNET_assert (GNUNET_YES ==
676 GNUNET_CONTAINER_multihashmap_remove (plugin->sessions,
677 &s->target.hashPubKey,
680 GNUNET_STATISTICS_set(plugin->env->stats,
681 "# UDP sessions active",
682 GNUNET_CONTAINER_multihashmap_size(plugin->sessions),
691 * Disconnect from a remote node. Clean up session if we have one for this peer
693 * @param cls closure for this call (should be handle to Plugin)
694 * @param target the peeridentity of the peer to disconnect
695 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
698 udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
700 struct Plugin *plugin = cls;
701 GNUNET_assert (plugin != NULL);
703 GNUNET_assert (target != NULL);
704 LOG (GNUNET_ERROR_TYPE_DEBUG,
705 "Disconnecting from peer `%s'\n", GNUNET_i2s (target));
706 /* Clean up sessions */
707 GNUNET_CONTAINER_multihashmap_get_multiple (plugin->sessions, &target->hashPubKey, &disconnect_and_free_it, plugin);
710 static struct Session *
711 create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
712 const void *addr, size_t addrlen,
713 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
716 const struct IPv4UdpAddress *t4;
717 const struct IPv6UdpAddress *t6;
718 struct sockaddr_in *v4;
719 struct sockaddr_in6 *v6;
724 case sizeof (struct IPv4UdpAddress):
725 if (NULL == plugin->sockv4)
730 s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in));
731 len = sizeof (struct sockaddr_in);
732 v4 = (struct sockaddr_in *) &s[1];
733 v4->sin_family = AF_INET;
734 #if HAVE_SOCKADDR_IN_SIN_LEN
735 v4->sin_len = sizeof (struct sockaddr_in);
737 v4->sin_port = t4->u4_port;
738 v4->sin_addr.s_addr = t4->ipv4_addr;
739 s->ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) v4, sizeof (struct sockaddr_in));
741 case sizeof (struct IPv6UdpAddress):
742 if (NULL == plugin->sockv6)
748 GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in6));
749 len = sizeof (struct sockaddr_in6);
750 v6 = (struct sockaddr_in6 *) &s[1];
751 v6->sin6_family = AF_INET6;
752 #if HAVE_SOCKADDR_IN_SIN_LEN
753 v6->sin6_len = sizeof (struct sockaddr_in6);
755 v6->sin6_port = t6->u6_port;
756 v6->sin6_addr = t6->ipv6_addr;
757 s->ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) v6, sizeof (struct sockaddr_in6));
760 /* Must have a valid address to send to */
767 s->sock_addr = (const struct sockaddr *) &s[1];
768 s->flow_delay_for_other_peer = GNUNET_TIME_relative_get_zero();
769 s->flow_delay_from_other_peer = GNUNET_TIME_absolute_get_zero();
770 s->last_expected_delay = GNUNET_TIME_UNIT_SECONDS;
775 static int session_cmp_it (void *cls,
776 const GNUNET_HashCode * key,
779 struct SessionCompareContext * cctx = cls;
780 const struct GNUNET_HELLO_Address *address = cctx->addr;
781 struct Session *s = value;
783 socklen_t s_addrlen = s->addrlen;
786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Comparing address %s <-> %s\n",
787 udp_address_to_string (NULL, (void *) address->address, address->address_length),
788 GNUNET_a2s (s->sock_addr, s->addrlen));
791 if ((address->address_length == sizeof (struct IPv4UdpAddress)) &&
792 (s_addrlen == sizeof (struct sockaddr_in)))
794 struct IPv4UdpAddress * u4 = NULL;
795 u4 = (struct IPv4UdpAddress *) address->address;
796 const struct sockaddr_in *s4 = (const struct sockaddr_in *) s->sock_addr;
797 if ((0 == memcmp ((const void *) &u4->ipv4_addr,(const void *) &s4->sin_addr, sizeof (struct in_addr))) &&
798 (u4->u4_port == s4->sin_port))
805 if ((address->address_length == sizeof (struct IPv6UdpAddress)) &&
806 (s_addrlen == sizeof (struct sockaddr_in6)))
808 struct IPv6UdpAddress * u6 = NULL;
809 u6 = (struct IPv6UdpAddress *) address->address;
810 const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) s->sock_addr;
811 if ((0 == memcmp (&u6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr))) &&
812 (u6->u6_port == s6->sin6_port))
825 * Creates a new outbound session the transport service will use to send data to the
828 * @param cls the plugin
829 * @param address the address
830 * @return the session or NULL of max connections exceeded
832 static struct Session *
833 udp_plugin_get_session (void *cls,
834 const struct GNUNET_HELLO_Address *address)
836 struct Session * s = NULL;
837 struct Plugin * plugin = cls;
838 struct IPv6UdpAddress * udp_a6;
839 struct IPv4UdpAddress * udp_a4;
841 GNUNET_assert (plugin != NULL);
842 GNUNET_assert (address != NULL);
845 if ((address->address == NULL) ||
846 ((address->address_length != sizeof (struct IPv4UdpAddress)) &&
847 (address->address_length != sizeof (struct IPv6UdpAddress))))
853 if (address->address_length == sizeof (struct IPv4UdpAddress))
855 if (plugin->sockv4 == NULL)
857 udp_a4 = (struct IPv4UdpAddress *) address->address;
858 if (udp_a4->u4_port == 0)
862 if (address->address_length == sizeof (struct IPv6UdpAddress))
864 if (plugin->sockv6 == NULL)
866 udp_a6 = (struct IPv6UdpAddress *) address->address;
867 if (udp_a6->u6_port == 0)
871 /* check if session already exists */
872 struct SessionCompareContext cctx;
876 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking for existing session for peer `%s' `%s' \n", GNUNET_i2s (&address->peer), udp_address_to_string(NULL, address->address, address->address_length));
878 GNUNET_CONTAINER_multihashmap_get_multiple(plugin->sessions, &address->peer.hashPubKey, session_cmp_it, &cctx);
879 if (cctx.res != NULL)
882 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p\n", cctx.res);
887 /* otherwise create new */
888 s = create_session (plugin,
891 address->address_length,
894 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
895 "Creating new session %p for peer `%s' address `%s'\n",
897 GNUNET_i2s(&address->peer),
898 udp_address_to_string(NULL,address->address,address->address_length));
900 GNUNET_assert (GNUNET_OK ==
901 GNUNET_CONTAINER_multihashmap_put (plugin->sessions,
902 &s->target.hashPubKey,
904 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
906 GNUNET_STATISTICS_set(plugin->env->stats,
907 "# UDP sessions active",
908 GNUNET_CONTAINER_multihashmap_size(plugin->sessions),
914 static void enqueue (struct Plugin *plugin, struct UDPMessageWrapper * udpw)
917 if (udpw->session->addrlen == sizeof (struct sockaddr_in))
918 GNUNET_CONTAINER_DLL_insert(plugin->ipv4_queue_head, plugin->ipv4_queue_tail, udpw);
919 if (udpw->session->addrlen == sizeof (struct sockaddr_in6))
920 GNUNET_CONTAINER_DLL_insert(plugin->ipv6_queue_head, plugin->ipv6_queue_tail, udpw);
924 * Function that is called with messages created by the fragmentation
925 * module. In the case of the 'proc' callback of the
926 * GNUNET_FRAGMENT_context_create function, this function must
927 * eventually call 'GNUNET_FRAGMENT_context_transmission_done'.
929 * @param cls closure, the 'struct FragmentationContext'
930 * @param msg the message that was created
933 enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg)
935 struct FragmentationContext *frag_ctx = cls;
936 struct Plugin *plugin = frag_ctx->plugin;
937 struct UDPMessageWrapper * udpw;
940 size_t msg_len = ntohs (msg->size);
943 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Enqueuing fragment with %u bytes %u\n", msg_len , sizeof (struct UDPMessageWrapper));
946 udpw = GNUNET_malloc (sizeof (struct UDPMessageWrapper) + msg_len);
947 udpw->session = frag_ctx->session;
949 udpw->udp = (char *) &udpw[1];
951 udpw->msg_size = msg_len;
952 udpw->cont = frag_ctx->cont;
953 udpw->cont_cls = frag_ctx->cont_cls;
954 udpw->timeout = frag_ctx->timeout;
955 udpw->frag_ctx = frag_ctx;
956 memcpy (udpw->udp, msg, msg_len);
958 enqueue (plugin, udpw);
961 if (s->addrlen == sizeof (struct sockaddr_in))
963 if (plugin->with_v4_ws == GNUNET_NO)
965 if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK)
966 GNUNET_SCHEDULER_cancel(plugin->select_task);
968 plugin->select_task =
969 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
970 GNUNET_TIME_UNIT_FOREVER_REL,
973 &udp_plugin_select, plugin);
974 plugin->with_v4_ws = GNUNET_YES;
978 else if (s->addrlen == sizeof (struct sockaddr_in6))
980 if (plugin->with_v6_ws == GNUNET_NO)
982 if (plugin->select_task_v6 != GNUNET_SCHEDULER_NO_TASK)
983 GNUNET_SCHEDULER_cancel(plugin->select_task_v6);
985 plugin->select_task_v6 =
986 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
987 GNUNET_TIME_UNIT_FOREVER_REL,
990 &udp_plugin_select_v6, plugin);
991 plugin->with_v6_ws = GNUNET_YES;
1001 * Function that can be used by the transport service to transmit
1002 * a message using the plugin. Note that in the case of a
1003 * peer disconnecting, the continuation MUST be called
1004 * prior to the disconnect notification itself. This function
1005 * will be called with this peer's HELLO message to initiate
1006 * a fresh connection to another peer.
1008 * @param cls closure
1009 * @param s which session must be used
1010 * @param msgbuf the message to transmit
1011 * @param msgbuf_size number of bytes in 'msgbuf'
1012 * @param priority how important is the message (most plugins will
1013 * ignore message priority and just FIFO)
1014 * @param to how long to wait at most for the transmission (does not
1015 * require plugins to discard the message after the timeout,
1016 * just advisory for the desired delay; most plugins will ignore
1018 * @param cont continuation to call once the message has
1019 * been transmitted (or if the transport is ready
1020 * for the next transmission call; or if the
1021 * peer disconnected...); can be NULL
1022 * @param cont_cls closure for cont
1023 * @return number of bytes used (on the physical network, with overheads);
1024 * -1 on hard errors (i.e. address invalid); 0 is a legal value
1025 * and does NOT mean that the message was not transmitted (DV)
1028 udp_plugin_send (void *cls,
1030 const char *msgbuf, size_t msgbuf_size,
1031 unsigned int priority,
1032 struct GNUNET_TIME_Relative to,
1033 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
1035 struct Plugin *plugin = cls;
1036 size_t mlen = msgbuf_size + sizeof (struct UDPMessage);
1038 struct UDPMessageWrapper * udpw;
1039 struct UDPMessage *udp;
1041 GNUNET_assert (plugin != NULL);
1042 GNUNET_assert (s != NULL);
1044 if ((s->addrlen == sizeof (struct sockaddr_in6)) && (plugin->sockv6 == NULL))
1045 return GNUNET_SYSERR;
1047 if ((s->addrlen == sizeof (struct sockaddr_in)) && (plugin->sockv4 == NULL))
1048 return GNUNET_SYSERR;
1051 if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1054 return GNUNET_SYSERR;
1057 if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains_value(plugin->sessions, &s->target.hashPubKey, s))
1060 return GNUNET_SYSERR;
1063 LOG (GNUNET_ERROR_TYPE_DEBUG,
1064 "UDP transmits %u-byte message to `%s' using address `%s'\n",
1066 GNUNET_i2s (&s->target),
1067 GNUNET_a2s(s->sock_addr, s->addrlen));
1070 udp = (struct UDPMessage *) mbuf;
1071 udp->header.size = htons (mlen);
1072 udp->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE);
1073 udp->reserved = htonl (0);
1074 udp->sender = *plugin->env->my_identity;
1076 if (mlen <= UDP_MTU)
1078 udpw = GNUNET_malloc (sizeof (struct UDPMessageWrapper) + mlen);
1080 udpw->udp = (char *) &udpw[1];
1081 udpw->msg_size = mlen;
1082 udpw->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to);
1084 udpw->cont_cls = cont_cls;
1085 udpw->frag_ctx = NULL;
1087 memcpy (udpw->udp, udp, sizeof (struct UDPMessage));
1088 memcpy (&udpw->udp[sizeof (struct UDPMessage)], msgbuf, msgbuf_size);
1090 enqueue (plugin, udpw);
1094 LOG (GNUNET_ERROR_TYPE_DEBUG,
1095 "UDP has to fragment message \n");
1096 if (s->frag_ctx != NULL)
1097 return GNUNET_SYSERR;
1098 memcpy (&udp[1], msgbuf, msgbuf_size);
1099 struct FragmentationContext * frag_ctx = GNUNET_malloc(sizeof (struct FragmentationContext));
1101 frag_ctx->plugin = plugin;
1102 frag_ctx->session = s;
1103 frag_ctx->cont = cont;
1104 frag_ctx->cont_cls = cont_cls;
1105 frag_ctx->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to);
1106 frag_ctx->bytes_to_send = mlen;
1107 frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats,
1110 s->last_expected_delay,
1115 s->frag_ctx = frag_ctx;
1119 if (s->addrlen == sizeof (struct sockaddr_in))
1121 if (plugin->with_v4_ws == GNUNET_NO)
1123 if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK)
1124 GNUNET_SCHEDULER_cancel(plugin->select_task);
1126 plugin->select_task =
1127 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1128 GNUNET_TIME_UNIT_FOREVER_REL,
1131 &udp_plugin_select, plugin);
1132 plugin->with_v4_ws = GNUNET_YES;
1136 else if (s->addrlen == sizeof (struct sockaddr_in6))
1138 if (plugin->with_v6_ws == GNUNET_NO)
1140 if (plugin->select_task_v6 != GNUNET_SCHEDULER_NO_TASK)
1141 GNUNET_SCHEDULER_cancel(plugin->select_task_v6);
1143 plugin->select_task_v6 =
1144 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1145 GNUNET_TIME_UNIT_FOREVER_REL,
1148 &udp_plugin_select_v6, plugin);
1149 plugin->with_v6_ws = GNUNET_YES;
1158 * Our external IP address/port mapping has changed.
1160 * @param cls closure, the 'struct LocalAddrList'
1161 * @param add_remove GNUNET_YES to mean the new public IP address, GNUNET_NO to mean
1162 * the previous (now invalid) one
1163 * @param addr either the previous or the new public IP address
1164 * @param addrlen actual lenght of the address
1167 udp_nat_port_map_callback (void *cls, int add_remove,
1168 const struct sockaddr *addr, socklen_t addrlen)
1170 struct Plugin *plugin = cls;
1171 struct IPv4UdpAddress u4;
1172 struct IPv6UdpAddress u6;
1176 /* convert 'addr' to our internal format */
1177 switch (addr->sa_family)
1180 GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
1181 u4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
1182 u4.u4_port = ((struct sockaddr_in *) addr)->sin_port;
1187 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
1188 memcpy (&u6.ipv6_addr, &((struct sockaddr_in6 *) addr)->sin6_addr,
1189 sizeof (struct in6_addr));
1190 u6.u6_port = ((struct sockaddr_in6 *) addr)->sin6_port;
1198 /* modify our published address list */
1199 plugin->env->notify_address (plugin->env->cls, add_remove, arg, args);
1205 * Message tokenizer has broken up an incomming message. Pass it on
1208 * @param cls the 'struct Plugin'
1209 * @param client the 'struct SourceInformation'
1210 * @param hdr the actual message
1213 process_inbound_tokenized_messages (void *cls, void *client,
1214 const struct GNUNET_MessageHeader *hdr)
1216 struct Plugin *plugin = cls;
1217 struct SourceInformation *si = client;
1218 struct GNUNET_ATS_Information ats[2];
1219 struct GNUNET_TIME_Relative delay;
1221 GNUNET_assert (si->session != NULL);
1223 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains_value(plugin->sessions,
1224 &si->sender.hashPubKey,
1229 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
1230 ats[0].value = htonl (1);
1231 ats[1] = si->session->ats;
1232 GNUNET_break (ntohl(ats[1].value) != GNUNET_ATS_NET_UNSPECIFIED);
1234 delay = plugin->env->receive (plugin->env->cls,
1237 (const struct GNUNET_ATS_Information *) &ats, 2,
1241 si->session->flow_delay_for_other_peer = delay;
1246 * We've received a UDP Message. Process it (pass contents to main service).
1248 * @param plugin plugin context
1249 * @param msg the message
1250 * @param sender_addr sender address
1251 * @param sender_addr_len number of bytes in sender_addr
1254 process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg,
1255 const struct sockaddr *sender_addr,
1256 socklen_t sender_addr_len)
1258 struct SourceInformation si;
1259 struct Session * s = NULL;
1260 struct IPv4UdpAddress u4;
1261 struct IPv6UdpAddress u6;
1265 if (0 != ntohl (msg->reserved))
1267 GNUNET_break_op (0);
1270 if (ntohs (msg->header.size) <
1271 sizeof (struct GNUNET_MessageHeader) + sizeof (struct UDPMessage))
1273 GNUNET_break_op (0);
1277 /* convert address */
1278 switch (sender_addr->sa_family)
1281 GNUNET_assert (sender_addr_len == sizeof (struct sockaddr_in));
1282 u4.ipv4_addr = ((struct sockaddr_in *) sender_addr)->sin_addr.s_addr;
1283 u4.u4_port = ((struct sockaddr_in *) sender_addr)->sin_port;
1288 GNUNET_assert (sender_addr_len == sizeof (struct sockaddr_in6));
1289 u6.ipv6_addr = ((struct sockaddr_in6 *) sender_addr)->sin6_addr;
1290 u6.u6_port = ((struct sockaddr_in6 *) sender_addr)->sin6_port;
1298 LOG (GNUNET_ERROR_TYPE_DEBUG,
1299 "Received message with %u bytes from peer `%s' at `%s'\n",
1300 (unsigned int) ntohs (msg->header.size), GNUNET_i2s (&msg->sender),
1301 GNUNET_a2s (sender_addr, sender_addr_len));
1303 struct GNUNET_HELLO_Address * address = GNUNET_HELLO_address_allocate(&msg->sender, "udp", arg, args);
1304 s = udp_plugin_get_session(plugin, address);
1305 GNUNET_free (address);
1307 /* iterate over all embedded messages */
1309 si.sender = msg->sender;
1313 GNUNET_SERVER_mst_receive (plugin->mst, &si, (const char *) &msg[1],
1314 ntohs (msg->header.size) -
1315 sizeof (struct UDPMessage), GNUNET_YES, GNUNET_NO);
1320 * Scan the heap for a receive context with the given address.
1322 * @param cls the 'struct FindReceiveContext'
1323 * @param node internal node of the heap
1324 * @param element value stored at the node (a 'struct ReceiveContext')
1325 * @param cost cost associated with the node
1326 * @return GNUNET_YES if we should continue to iterate,
1330 find_receive_context (void *cls, struct GNUNET_CONTAINER_HeapNode *node,
1331 void *element, GNUNET_CONTAINER_HeapCostType cost)
1333 struct FindReceiveContext *frc = cls;
1334 struct DefragContext *e = element;
1336 if ((frc->addr_len == e->addr_len) &&
1337 (0 == memcmp (frc->addr, e->src_addr, frc->addr_len)))
1347 * Process a defragmented message.
1349 * @param cls the 'struct ReceiveContext'
1350 * @param msg the message
1353 fragment_msg_proc (void *cls, const struct GNUNET_MessageHeader *msg)
1355 struct DefragContext *rc = cls;
1357 if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE)
1362 if (ntohs (msg->size) < sizeof (struct UDPMessage))
1367 process_udp_message (rc->plugin, (const struct UDPMessage *) msg,
1368 rc->src_addr, rc->addr_len);
1371 struct LookupContext
1373 const struct sockaddr * addr;
1376 struct Session *res;
1380 lookup_session_by_addr_it (void *cls, const GNUNET_HashCode * key, void *value)
1382 struct LookupContext *l_ctx = cls;
1383 struct Session * s = value;
1385 if ((s->addrlen == l_ctx->addrlen) &&
1386 (0 == memcmp (s->sock_addr, l_ctx->addr, s->addrlen)))
1395 * Transmit an acknowledgement.
1397 * @param cls the 'struct ReceiveContext'
1398 * @param id message ID (unused)
1399 * @param msg ack to transmit
1402 ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
1404 struct DefragContext *rc = cls;
1406 size_t msize = sizeof (struct UDP_ACK_Message) + ntohs (msg->size);
1407 struct UDP_ACK_Message *udp_ack;
1409 struct UDPMessageWrapper *udpw;
1412 struct LookupContext l_ctx;
1413 l_ctx.addr = rc->src_addr;
1414 l_ctx.addrlen = rc->addr_len;
1416 GNUNET_CONTAINER_multihashmap_iterate (rc->plugin->sessions,
1417 &lookup_session_by_addr_it,
1424 if (s->flow_delay_for_other_peer.rel_value <= UINT32_MAX)
1425 delay = s->flow_delay_for_other_peer.rel_value;
1427 LOG (GNUNET_ERROR_TYPE_DEBUG,
1428 "Sending ACK to `%s' including delay of %u ms\n",
1429 GNUNET_a2s (rc->src_addr,
1430 (rc->src_addr->sa_family ==
1431 AF_INET) ? sizeof (struct sockaddr_in) : sizeof (struct
1434 udpw = GNUNET_malloc (sizeof (struct UDPMessageWrapper) + msize);
1436 udpw->cont_cls = NULL;
1437 udpw->frag_ctx = NULL;
1438 udpw->msg_size = msize;
1440 udpw->timeout = GNUNET_TIME_absolute_get_forever();
1441 udpw->udp = (char *)&udpw[1];
1443 udp_ack = (struct UDP_ACK_Message *) udpw->udp;
1444 udp_ack->header.size = htons ((uint16_t) msize);
1445 udp_ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK);
1446 udp_ack->delay = htonl (delay);
1447 udp_ack->sender = *rc->plugin->env->my_identity;
1448 memcpy (&udp_ack[1], msg, ntohs (msg->size));
1450 enqueue (rc->plugin, udpw);
1454 static void read_process_msg (struct Plugin *plugin,
1455 const struct GNUNET_MessageHeader *msg,
1459 if (ntohs (msg->size) < sizeof (struct UDPMessage))
1461 GNUNET_break_op (0);
1464 process_udp_message (plugin, (const struct UDPMessage *) msg,
1465 (const struct sockaddr *) addr, fromlen);
1469 static void read_process_ack (struct Plugin *plugin,
1470 const struct GNUNET_MessageHeader *msg,
1474 const struct GNUNET_MessageHeader *ack;
1475 const struct UDP_ACK_Message *udp_ack;
1476 struct LookupContext l_ctx;
1477 struct Session *s = NULL;
1478 struct GNUNET_TIME_Relative flow_delay;
1480 if (ntohs (msg->size) <
1481 sizeof (struct UDP_ACK_Message) + sizeof (struct GNUNET_MessageHeader))
1483 GNUNET_break_op (0);
1487 udp_ack = (const struct UDP_ACK_Message *) msg;
1489 l_ctx.addr = (const struct sockaddr *) addr;
1490 l_ctx.addrlen = fromlen;
1492 GNUNET_CONTAINER_multihashmap_iterate (plugin->sessions,
1493 &lookup_session_by_addr_it,
1497 if ((s == NULL) || (s->frag_ctx == NULL))
1500 flow_delay.rel_value = (uint64_t) ntohl (udp_ack->delay);
1501 LOG (GNUNET_ERROR_TYPE_DEBUG, "We received a sending delay of %llu\n",
1502 flow_delay.rel_value);
1503 s->flow_delay_from_other_peer =
1504 GNUNET_TIME_relative_to_absolute (flow_delay);
1506 ack = (const struct GNUNET_MessageHeader *) &udp_ack[1];
1507 if (ntohs (ack->size) !=
1508 ntohs (msg->size) - sizeof (struct UDP_ACK_Message))
1510 GNUNET_break_op (0);
1514 if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (s->frag_ctx->frag, ack))
1516 LOG (GNUNET_ERROR_TYPE_DEBUG,
1517 "UDP processes %u-byte acknowledgement from `%s' at `%s'\n",
1518 (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender),
1519 GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
1523 LOG (GNUNET_ERROR_TYPE_DEBUG,
1524 "FULL MESSAGE ACKed\n",
1525 (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender),
1526 GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
1527 s->last_expected_delay = GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag);
1529 struct UDPMessageWrapper * udpw = NULL;
1530 struct UDPMessageWrapper * tmp = NULL;
1531 if (s->addrlen == sizeof (struct sockaddr_in6))
1533 udpw = plugin->ipv6_queue_head;
1537 if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == s->frag_ctx))
1539 GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, plugin->ipv6_queue_tail, udpw);
1545 if (s->addrlen == sizeof (struct sockaddr_in))
1547 udpw = plugin->ipv4_queue_head;
1551 if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == s->frag_ctx))
1553 GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, plugin->ipv4_queue_tail, udpw);
1560 if (s->frag_ctx->cont != NULL)
1562 (s->frag_ctx->cont_cls, &udp_ack->sender, GNUNET_OK);
1563 GNUNET_free (s->frag_ctx);
1568 static void read_process_fragment (struct Plugin *plugin,
1569 const struct GNUNET_MessageHeader *msg,
1573 struct DefragContext *d_ctx;
1574 struct GNUNET_TIME_Absolute now;
1575 struct FindReceiveContext frc;
1579 frc.addr = (const struct sockaddr *) addr;
1580 frc.addr_len = fromlen;
1582 LOG (GNUNET_ERROR_TYPE_DEBUG, "UDP processes %u-byte fragment from `%s'\n",
1583 (unsigned int) ntohs (msg->size),
1584 GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
1585 /* Lookup existing receive context for this address */
1586 GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs,
1587 &find_receive_context,
1589 now = GNUNET_TIME_absolute_get ();
1594 /* Create a new defragmentation context */
1595 d_ctx = GNUNET_malloc (sizeof (struct DefragContext) + fromlen);
1596 memcpy (&d_ctx[1], addr, fromlen);
1597 d_ctx->src_addr = (const struct sockaddr *) &d_ctx[1];
1598 d_ctx->addr_len = fromlen;
1599 d_ctx->plugin = plugin;
1601 GNUNET_DEFRAGMENT_context_create (plugin->env->stats, UDP_MTU,
1602 UDP_MAX_MESSAGES_IN_DEFRAG, d_ctx,
1603 &fragment_msg_proc, &ack_proc);
1605 GNUNET_CONTAINER_heap_insert (plugin->defrag_ctxs, d_ctx,
1606 (GNUNET_CONTAINER_HeapCostType)
1608 LOG (GNUNET_ERROR_TYPE_DEBUG, "Created new defragmentation context for %u-byte fragment from `%s'\n",
1609 (unsigned int) ntohs (msg->size),
1610 GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
1614 LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing defragmentation context for %u-byte fragment from `%s'\n",
1615 (unsigned int) ntohs (msg->size),
1616 GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
1619 if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (d_ctx->defrag, msg))
1621 /* keep this 'rc' from expiring */
1622 GNUNET_CONTAINER_heap_update_cost (plugin->defrag_ctxs, d_ctx->hnode,
1623 (GNUNET_CONTAINER_HeapCostType)
1626 if (GNUNET_CONTAINER_heap_get_size (plugin->defrag_ctxs) >
1627 UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG)
1629 /* remove 'rc' that was inactive the longest */
1630 d_ctx = GNUNET_CONTAINER_heap_remove_root (plugin->defrag_ctxs);
1631 GNUNET_assert (NULL != d_ctx);
1632 GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag);
1633 GNUNET_free (d_ctx);
1638 * Read and process a message from the given socket.
1640 * @param plugin the overall plugin
1641 * @param rsock socket to read from
1644 udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
1648 char buf[65536] GNUNET_ALIGN;
1650 const struct GNUNET_MessageHeader *msg;
1652 fromlen = sizeof (addr);
1653 memset (&addr, 0, sizeof (addr));
1654 size = GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof (buf),
1655 (struct sockaddr *) &addr, &fromlen);
1657 if (size < sizeof (struct GNUNET_MessageHeader))
1659 GNUNET_break_op (0);
1662 msg = (const struct GNUNET_MessageHeader *) buf;
1664 LOG (GNUNET_ERROR_TYPE_DEBUG,
1665 "UDP received %u-byte message from `%s' type %i\n", (unsigned int) size,
1666 GNUNET_a2s ((const struct sockaddr *) addr, fromlen), ntohs (msg->type));
1668 if (size != ntohs (msg->size))
1670 GNUNET_break_op (0);
1674 switch (ntohs (msg->type))
1676 case GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON:
1677 udp_broadcast_receive (plugin, &buf, size, addr, fromlen);
1680 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE:
1681 read_process_msg (plugin, msg, addr, fromlen);
1684 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK:
1685 read_process_ack (plugin, msg, addr, fromlen);
1688 case GNUNET_MESSAGE_TYPE_FRAGMENT:
1689 read_process_fragment (plugin, msg, addr, fromlen);
1693 GNUNET_break_op (0);
1699 udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
1703 struct GNUNET_TIME_Absolute max;
1704 struct GNUNET_TIME_Absolute ;
1706 struct UDPMessageWrapper *udpw = NULL;
1708 if (sock == plugin->sockv4)
1710 udpw = plugin->ipv4_queue_head;
1712 else if (sock == plugin->sockv6)
1714 udpw = plugin->ipv6_queue_head;
1722 const struct sockaddr * sa = udpw->session->sock_addr;
1723 slen = udpw->session->addrlen;
1725 max = GNUNET_TIME_absolute_max(udpw->timeout, GNUNET_TIME_absolute_get());
1727 while (udpw != NULL)
1729 if (max.abs_value != udpw->timeout.abs_value)
1731 /* Message timed out */
1733 if (udpw->cont != NULL)
1734 udpw->cont (udpw->cont_cls, &udpw->session->target, GNUNET_SYSERR);
1735 if (udpw->frag_ctx != NULL)
1737 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fragmented message for peer `%s' with size %u timed out\n",
1738 GNUNET_i2s(&udpw->session->target), udpw->frag_ctx->bytes_to_send);
1739 udpw->session->last_expected_delay = GNUNET_FRAGMENT_context_destroy(udpw->frag_ctx->frag);
1740 GNUNET_free (udpw->frag_ctx);
1741 udpw->session->frag_ctx = NULL;
1745 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message for peer `%s' with size %u timed out\n",
1746 GNUNET_i2s(&udpw->session->target), udpw->msg_size);
1749 if (sock == plugin->sockv4)
1751 GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, plugin->ipv4_queue_tail, udpw);
1753 udpw = plugin->ipv4_queue_head;
1755 else if (sock == plugin->sockv6)
1757 GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, plugin->ipv6_queue_tail, udpw);
1759 udpw = plugin->ipv6_queue_head;
1764 struct GNUNET_TIME_Relative delta = GNUNET_TIME_absolute_get_remaining (udpw->session->flow_delay_from_other_peer);
1765 if (delta.rel_value == 0)
1767 /* this message is not delayed */
1768 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message for peer `%s' (%u bytes) is not delayed \n",
1769 GNUNET_i2s(&udpw->session->target), udpw->msg_size);
1774 /* this message is delayed, try next */
1775 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message for peer `%s' (%u bytes) is delayed for %llu \n",
1776 GNUNET_i2s(&udpw->session->target), udpw->msg_size,
1785 /* No message left */
1789 sent = GNUNET_NETWORK_socket_sendto (sock, udpw->udp, udpw->msg_size, sa, slen);
1791 if (GNUNET_SYSERR == sent)
1793 LOG (GNUNET_ERROR_TYPE_ERROR,
1794 "UDP could not transmit %u-byte message to `%s': `%s'\n",
1795 (unsigned int) (udpw->msg_size), GNUNET_a2s (sa, slen),
1797 if (udpw->cont != NULL)
1798 udpw->cont (udpw->cont_cls, &udpw->session->target, GNUNET_SYSERR);
1802 LOG (GNUNET_ERROR_TYPE_DEBUG,
1803 "UDP transmitted %u-byte message to `%s' (%d: %s)\n",
1804 (unsigned int) (udpw->msg_size), GNUNET_a2s (sa, slen), (int) sent,
1805 (sent < 0) ? STRERROR (errno) : "ok");
1807 /* This was just a message fragment */
1808 if (udpw->frag_ctx != NULL)
1810 GNUNET_FRAGMENT_context_transmission_done (udpw->frag_ctx->frag);
1812 /* This was a complete message*/
1815 if (udpw->cont != NULL)
1816 udpw->cont (udpw->cont_cls, &udpw->session->target, GNUNET_OK);
1819 if (sock == plugin->sockv4)
1820 GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, plugin->ipv4_queue_tail, udpw);
1821 else if (sock == plugin->sockv6)
1822 GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, plugin->ipv6_queue_tail, udpw);
1830 * We have been notified that our readset has something to read. We don't
1831 * know which socket needs to be read, so we have to check each one
1832 * Then reschedule this function to be called again once more is available.
1834 * @param cls the plugin handle
1835 * @param tc the scheduling context (for rescheduling this function again)
1838 udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1840 struct Plugin *plugin = cls;
1842 plugin->select_task = GNUNET_SCHEDULER_NO_TASK;
1843 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
1845 plugin->with_v4_ws = GNUNET_NO;
1847 if ((tc->reason & GNUNET_SCHEDULER_REASON_READ_READY) != 0)
1849 if ((NULL != plugin->sockv4) &&
1850 (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv4)))
1851 udp_select_read (plugin, plugin->sockv4);
1855 if ((tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0)
1857 if ((NULL != plugin->sockv4) && (plugin->ipv4_queue_head != NULL) &&
1858 (GNUNET_NETWORK_fdset_isset (tc->write_ready, plugin->sockv4)))
1860 udp_select_send (plugin, plugin->sockv4);
1864 if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK)
1865 GNUNET_SCHEDULER_cancel (plugin->select_task);
1866 plugin->select_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1867 GNUNET_TIME_UNIT_FOREVER_REL,
1869 (plugin->ipv4_queue_head != NULL) ? plugin->ws_v4 : NULL,
1870 &udp_plugin_select, plugin);
1871 if (plugin->ipv4_queue_head != NULL)
1872 plugin->with_v4_ws = GNUNET_YES;
1874 plugin->with_v4_ws = GNUNET_NO;
1879 * We have been notified that our readset has something to read. We don't
1880 * know which socket needs to be read, so we have to check each one
1881 * Then reschedule this function to be called again once more is available.
1883 * @param cls the plugin handle
1884 * @param tc the scheduling context (for rescheduling this function again)
1887 udp_plugin_select_v6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1889 struct Plugin *plugin = cls;
1891 plugin->select_task_v6 = GNUNET_SCHEDULER_NO_TASK;
1892 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
1895 plugin->with_v6_ws = GNUNET_NO;
1896 if ((tc->reason & GNUNET_SCHEDULER_REASON_READ_READY) != 0)
1898 if ((NULL != plugin->sockv6) &&
1899 (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6)))
1900 udp_select_read (plugin, plugin->sockv6);
1903 if ((tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0)
1905 if ((NULL != plugin->sockv6) && (plugin->ipv6_queue_head != NULL) &&
1906 (GNUNET_NETWORK_fdset_isset (tc->write_ready, plugin->sockv6)))
1908 udp_select_send (plugin, plugin->sockv6);
1911 if (plugin->select_task_v6 != GNUNET_SCHEDULER_NO_TASK)
1912 GNUNET_SCHEDULER_cancel (plugin->select_task_v6);
1913 plugin->select_task_v6 = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1914 GNUNET_TIME_UNIT_FOREVER_REL,
1916 (plugin->ipv6_queue_head != NULL) ? plugin->ws_v6 : NULL,
1917 &udp_plugin_select_v6, plugin);
1918 if (plugin->ipv6_queue_head != NULL)
1919 plugin->with_v6_ws = GNUNET_YES;
1921 plugin->with_v6_ws = GNUNET_NO;
1926 setup_sockets (struct Plugin *plugin, struct sockaddr_in6 *serverAddrv6, struct sockaddr_in *serverAddrv4)
1929 int sockets_created = 0;
1930 struct sockaddr *serverAddr;
1931 struct sockaddr *addrs[2];
1932 socklen_t addrlens[2];
1935 /* Create IPv6 socket */
1936 if (plugin->enable_ipv6 == GNUNET_YES)
1938 plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0);
1939 if (NULL == plugin->sockv6)
1941 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Disabling IPv6 since it is not supported on this system!\n");
1942 plugin->enable_ipv6 = GNUNET_NO;
1946 #if HAVE_SOCKADDR_IN_SIN_LEN
1947 serverAddrv6->sin6_len = sizeof (serverAddrv6);
1949 serverAddrv6->sin6_family = AF_INET6;
1950 serverAddrv6->sin6_addr = in6addr_any;
1951 serverAddrv6->sin6_port = htons (plugin->port);
1952 addrlen = sizeof (struct sockaddr_in6);
1953 serverAddr = (struct sockaddr *) serverAddrv6;
1954 LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 port %d\n",
1955 ntohs (serverAddrv6->sin6_port));
1957 while (GNUNET_NETWORK_socket_bind (plugin->sockv6, serverAddr, addrlen) !=
1960 serverAddrv6->sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */
1961 LOG (GNUNET_ERROR_TYPE_DEBUG,
1962 "IPv6 Binding failed, trying new port %d\n",
1963 ntohs (serverAddrv6->sin6_port));
1967 GNUNET_NETWORK_socket_close (plugin->sockv6);
1968 plugin->sockv6 = NULL;
1972 if (plugin->sockv6 != NULL)
1974 LOG (GNUNET_ERROR_TYPE_DEBUG,
1975 "IPv6 socket created on port %d\n",
1976 ntohs (serverAddrv6->sin6_port));
1977 addrs[sockets_created] = (struct sockaddr *) serverAddrv6;
1978 addrlens[sockets_created] = sizeof (struct sockaddr_in6);
1984 /* Create IPv4 socket */
1985 plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0);
1986 if (NULL == plugin->sockv4)
1988 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
1992 #if HAVE_SOCKADDR_IN_SIN_LEN
1993 serverAddrv4->sin_len = sizeof (serverAddrv4);
1995 serverAddrv4->sin_family = AF_INET;
1996 serverAddrv4->sin_addr.s_addr = INADDR_ANY;
1997 serverAddrv4->sin_port = htons (plugin->port);
1998 addrlen = sizeof (struct sockaddr_in);
1999 serverAddr = (struct sockaddr *) serverAddrv4;
2001 LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 port %d\n",
2002 ntohs (serverAddrv4->sin_port));
2004 while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen) !=
2007 serverAddrv4->sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */
2008 LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv4 Binding failed, trying new port %d\n",
2009 ntohs (serverAddrv4->sin_port));
2013 GNUNET_NETWORK_socket_close (plugin->sockv4);
2014 plugin->sockv4 = NULL;
2018 if (plugin->sockv4 != NULL)
2020 addrs[sockets_created] = (struct sockaddr *) serverAddrv4;
2021 addrlens[sockets_created] = sizeof (struct sockaddr_in);
2026 /* Create file descriptors */
2027 plugin->rs_v4 = GNUNET_NETWORK_fdset_create ();
2028 plugin->ws_v4 = GNUNET_NETWORK_fdset_create ();
2029 GNUNET_NETWORK_fdset_zero (plugin->rs_v4);
2030 GNUNET_NETWORK_fdset_zero (plugin->ws_v4);
2031 if (NULL != plugin->sockv4)
2033 GNUNET_NETWORK_fdset_set (plugin->rs_v4, plugin->sockv4);
2034 GNUNET_NETWORK_fdset_set (plugin->ws_v4, plugin->sockv4);
2037 if (sockets_created == 0)
2038 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to open UDP sockets\n"));
2040 plugin->select_task =
2041 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
2042 GNUNET_TIME_UNIT_FOREVER_REL,
2045 &udp_plugin_select, plugin);
2046 plugin->with_v4_ws = GNUNET_NO;
2048 if (plugin->enable_ipv6 == GNUNET_YES)
2050 plugin->rs_v6 = GNUNET_NETWORK_fdset_create ();
2051 plugin->ws_v6 = GNUNET_NETWORK_fdset_create ();
2052 GNUNET_NETWORK_fdset_zero (plugin->rs_v6);
2053 GNUNET_NETWORK_fdset_zero (plugin->ws_v6);
2054 if (NULL != plugin->sockv6)
2056 GNUNET_NETWORK_fdset_set (plugin->rs_v6, plugin->sockv6);
2057 GNUNET_NETWORK_fdset_set (plugin->ws_v6, plugin->sockv6);
2060 plugin->select_task_v6 =
2061 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
2062 GNUNET_TIME_UNIT_FOREVER_REL,
2065 &udp_plugin_select_v6, plugin);
2066 plugin->with_v6_ws = GNUNET_NO;
2069 plugin->nat = GNUNET_NAT_register (plugin->env->cfg,
2070 GNUNET_NO, plugin->port,
2072 (const struct sockaddr **) addrs, addrlens,
2073 &udp_nat_port_map_callback, NULL, plugin);
2075 return sockets_created;
2080 * The exported method. Makes the core api available via a global and
2081 * returns the udp transport API.
2083 * @param cls our 'struct GNUNET_TRANSPORT_PluginEnvironment'
2084 * @return our 'struct GNUNET_TRANSPORT_PluginFunctions'
2087 libgnunet_plugin_transport_udp_init (void *cls)
2089 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
2090 struct GNUNET_TRANSPORT_PluginFunctions *api;
2091 struct Plugin *plugin;
2093 unsigned long long port;
2094 unsigned long long aport;
2095 unsigned long long broadcast;
2096 unsigned long long udp_max_bps;
2097 unsigned long long enable_v6;
2098 char * bind4_address;
2099 char * bind6_address;
2100 struct GNUNET_TIME_Relative interval;
2102 struct sockaddr_in serverAddrv4;
2103 struct sockaddr_in6 serverAddrv6;
2107 if (NULL == env->receive)
2109 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
2110 initialze the plugin or the API */
2111 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
2113 api->address_pretty_printer = &udp_plugin_address_pretty_printer;
2114 api->address_to_string = &udp_address_to_string;
2115 api->string_to_address = &udp_string_to_address;
2119 GNUNET_assert( NULL != env->stats);
2121 /* Get port number */
2123 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", "PORT",
2127 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp",
2128 "ADVERTISED_PORT", &aport))
2132 LOG (GNUNET_ERROR_TYPE_WARNING,
2133 _("Given `%s' option is out of range: %llu > %u\n"), "PORT", port,
2140 GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "nat",
2143 enable_v6 = GNUNET_NO;
2146 enable_v6 = GNUNET_YES;
2150 memset (&serverAddrv6, 0, sizeof (serverAddrv6));
2151 memset (&serverAddrv4, 0, sizeof (serverAddrv4));
2154 GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp",
2155 "BINDTO", &bind4_address))
2157 LOG (GNUNET_ERROR_TYPE_DEBUG,
2158 "Binding udp plugin to specific address: `%s'\n",
2160 if (1 != inet_pton (AF_INET, bind4_address, &serverAddrv4.sin_addr))
2162 GNUNET_free (bind4_address);
2168 GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp",
2169 "BINDTO6", &bind6_address))
2171 LOG (GNUNET_ERROR_TYPE_DEBUG,
2172 "Binding udp plugin to specific address: `%s'\n",
2175 inet_pton (AF_INET6, bind6_address, &serverAddrv6.sin6_addr))
2177 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"),
2179 GNUNET_free_non_null (bind4_address);
2180 GNUNET_free (bind6_address);
2186 /* Enable neighbour discovery */
2187 broadcast = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "transport-udp",
2189 if (broadcast == GNUNET_SYSERR)
2190 broadcast = GNUNET_NO;
2192 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (env->cfg, "transport-udp",
2193 "BROADCAST_INTERVAL", &interval))
2195 interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
2198 /* Maximum datarate */
2199 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp",
2200 "MAX_BPS", &udp_max_bps))
2202 udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */
2205 plugin = GNUNET_malloc (sizeof (struct Plugin));
2206 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
2208 GNUNET_BANDWIDTH_tracker_init (&plugin->tracker,
2209 GNUNET_BANDWIDTH_value_init ((uint32_t)udp_max_bps), 30);
2212 plugin->sessions = GNUNET_CONTAINER_multihashmap_create (10);
2213 plugin->defrag_ctxs = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
2214 plugin->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages, plugin);
2215 plugin->port = port;
2216 plugin->aport = aport;
2217 plugin->broadcast_interval = interval;
2218 plugin->enable_ipv6 = enable_v6;
2223 api->disconnect = &udp_disconnect;
2224 api->address_pretty_printer = &udp_plugin_address_pretty_printer;
2225 api->address_to_string = &udp_address_to_string;
2226 api->string_to_address = &udp_string_to_address;
2227 api->check_address = &udp_plugin_check_address;
2228 api->get_session = &udp_plugin_get_session;
2229 api->send = &udp_plugin_send;
2231 LOG (GNUNET_ERROR_TYPE_DEBUG, "Setting up sockets\n");
2232 res = setup_sockets (plugin, &serverAddrv6, &serverAddrv4);
2233 if ((res == 0) || ((plugin->sockv4 == NULL) && (plugin->sockv6 == NULL)))
2235 LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to create network sockets, plugin failed\n");
2236 GNUNET_free (plugin);
2241 if (broadcast == GNUNET_YES)
2243 LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting broadcasting\n");
2244 setup_broadcast (plugin, &serverAddrv6, &serverAddrv4);
2247 GNUNET_free_non_null (bind4_address);
2248 GNUNET_free_non_null (bind6_address);
2254 heap_cleanup_iterator (void *cls,
2255 struct GNUNET_CONTAINER_HeapNode *
2256 node, void *element,
2257 GNUNET_CONTAINER_HeapCostType
2260 struct DefragContext * d_ctx = element;
2262 GNUNET_CONTAINER_heap_remove_node (node);
2263 GNUNET_DEFRAGMENT_context_destroy(d_ctx->defrag);
2264 GNUNET_free (d_ctx);
2271 * The exported method. Makes the core api available via a global and
2272 * returns the udp transport API.
2274 * @param cls our 'struct GNUNET_TRANSPORT_PluginEnvironment'
2278 libgnunet_plugin_transport_udp_done (void *cls)
2280 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
2281 struct Plugin *plugin = api->cls;
2289 stop_broadcast (plugin);
2291 if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK)
2293 GNUNET_SCHEDULER_cancel (plugin->select_task);
2294 plugin->select_task = GNUNET_SCHEDULER_NO_TASK;
2296 if (plugin->select_task_v6 != GNUNET_SCHEDULER_NO_TASK)
2298 GNUNET_SCHEDULER_cancel (plugin->select_task_v6);
2299 plugin->select_task_v6 = GNUNET_SCHEDULER_NO_TASK;
2302 /* Closing sockets */
2303 if (plugin->sockv4 != NULL)
2305 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4));
2306 plugin->sockv4 = NULL;
2308 GNUNET_NETWORK_fdset_destroy (plugin->rs_v4);
2309 GNUNET_NETWORK_fdset_destroy (plugin->ws_v4);
2311 if (plugin->sockv6 != NULL)
2313 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6));
2314 plugin->sockv6 = NULL;
2316 GNUNET_NETWORK_fdset_destroy (plugin->rs_v6);
2317 GNUNET_NETWORK_fdset_destroy (plugin->ws_v6);
2320 GNUNET_NAT_unregister (plugin->nat);
2322 if (plugin->defrag_ctxs != NULL)
2324 GNUNET_CONTAINER_heap_iterate(plugin->defrag_ctxs,
2325 heap_cleanup_iterator, NULL);
2326 GNUNET_CONTAINER_heap_destroy(plugin->defrag_ctxs);
2327 plugin->defrag_ctxs = NULL;
2329 if (plugin->mst != NULL)
2331 GNUNET_SERVER_mst_destroy(plugin->mst);
2335 /* Clean up leftover messages */
2336 struct UDPMessageWrapper * udpw;
2337 udpw = plugin->ipv4_queue_head;
2338 while (udpw != NULL)
2340 struct UDPMessageWrapper *tmp = udpw->next;
2341 GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, plugin->ipv4_queue_tail, udpw);
2342 if (udpw->cont != NULL)
2343 udpw->cont (udpw->cont_cls, &udpw->session->target, GNUNET_SYSERR);
2347 udpw = plugin->ipv6_queue_head;
2348 while (udpw != NULL)
2350 struct UDPMessageWrapper *tmp = udpw->next;
2351 GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, plugin->ipv6_queue_tail, udpw);
2352 if (udpw->cont != NULL)
2353 udpw->cont (udpw->cont_cls, &udpw->session->target, GNUNET_SYSERR);
2358 /* Clean up sessions */
2359 LOG (GNUNET_ERROR_TYPE_DEBUG,
2360 "Cleaning up sessions\n");
2361 GNUNET_CONTAINER_multihashmap_iterate (plugin->sessions, &disconnect_and_free_it, plugin);
2362 GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions);
2365 GNUNET_free (plugin);
2371 /* end of plugin_transport_udp.c */