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_new.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 * Closure for 'append_port'.
49 struct PrettyPrinterContext
52 * Function to call with the result.
54 GNUNET_TRANSPORT_AddressStringCallback asc;
62 * Port to add after the IP address.
69 * Function called for a quick conversion of the binary address to
70 * a numeric address. Note that the caller must not free the
71 * address and that the next call to this function is allowed
72 * to override the address again.
75 * @param addr binary address
76 * @param addrlen length of the address
77 * @return string representing the same address
80 udp_address_to_string (void *cls, const void *addr, size_t addrlen)
82 static char rbuf[INET6_ADDRSTRLEN + 10];
83 char buf[INET6_ADDRSTRLEN];
87 const struct IPv4UdpAddress *t4;
88 const struct IPv6UdpAddress *t6;
92 if (addrlen == sizeof (struct IPv6UdpAddress))
96 port = ntohs (t6->u6_port);
97 memcpy (&a6, &t6->ipv6_addr, sizeof (a6));
100 else if (addrlen == sizeof (struct IPv4UdpAddress))
104 port = ntohs (t4->u4_port);
105 memcpy (&a4, &t4->ipv4_addr, sizeof (a4));
113 inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
114 GNUNET_snprintf (rbuf, sizeof (rbuf), (af == AF_INET6) ? "[%s]:%u" : "%s:%u",
121 * Append our port and forward the result.
123 * @param cls a 'struct PrettyPrinterContext'
124 * @param hostname result from DNS resolver
127 append_port (void *cls, const char *hostname)
129 struct PrettyPrinterContext *ppc = cls;
132 if (hostname == NULL)
134 ppc->asc (ppc->asc_cls, NULL);
138 GNUNET_asprintf (&ret, "%s:%d", hostname, ppc->port);
139 ppc->asc (ppc->asc_cls, ret);
145 * Convert the transports address to a nice, human-readable
149 * @param type name of the transport that generated the address
150 * @param addr one of the addresses of the host, NULL for the last address
151 * the specific address format depends on the transport
152 * @param addrlen length of the address
153 * @param numeric should (IP) addresses be displayed in numeric form?
154 * @param timeout after how long should we give up?
155 * @param asc function to call on each string
156 * @param asc_cls closure for asc
159 udp_plugin_address_pretty_printer (void *cls, const char *type,
160 const void *addr, size_t addrlen,
162 struct GNUNET_TIME_Relative timeout,
163 GNUNET_TRANSPORT_AddressStringCallback asc,
166 struct PrettyPrinterContext *ppc;
169 struct sockaddr_in a4;
170 struct sockaddr_in6 a6;
171 const struct IPv4UdpAddress *u4;
172 const struct IPv6UdpAddress *u6;
175 if (addrlen == sizeof (struct IPv6UdpAddress))
178 memset (&a6, 0, sizeof (a6));
179 a6.sin6_family = AF_INET6;
180 #if HAVE_SOCKADDR_IN_SIN_LEN
181 a6.sin6_len = sizeof (a6);
183 a6.sin6_port = u6->u6_port;
184 memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof (struct in6_addr));
185 port = ntohs (u6->u6_port);
189 else if (addrlen == sizeof (struct IPv4UdpAddress))
192 memset (&a4, 0, sizeof (a4));
193 a4.sin_family = AF_INET;
194 #if HAVE_SOCKADDR_IN_SIN_LEN
195 a4.sin_len = sizeof (a4);
197 a4.sin_port = u4->u4_port;
198 a4.sin_addr.s_addr = u4->ipv4_addr;
199 port = ntohs (u4->u4_port);
205 /* invalid address */
210 ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext));
212 ppc->asc_cls = asc_cls;
214 GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, timeout, &append_port, ppc);
219 * Check if the given port is plausible (must be either our listen
220 * port or our advertised port). If it is neither, we return
223 * @param plugin global variables
224 * @param in_port port number to check
225 * @return GNUNET_OK if port is either open_port or adv_port
228 check_port (struct Plugin *plugin, uint16_t in_port)
230 if ((in_port == plugin->port) || (in_port == plugin->aport))
232 return GNUNET_SYSERR;
238 * Function that will be called to check if a binary address for this
239 * plugin is well-formed and corresponds to an address for THIS peer
240 * (as per our configuration). Naturally, if absolutely necessary,
241 * plugins can be a bit conservative in their answer, but in general
242 * plugins should make sure that the address does not redirect
243 * traffic to a 3rd party that might try to man-in-the-middle our
246 * @param cls closure, should be our handle to the Plugin
247 * @param addr pointer to the address
248 * @param addrlen length of addr
249 * @return GNUNET_OK if this is a plausible address for this peer
250 * and transport, GNUNET_SYSERR if not
254 udp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
256 struct Plugin *plugin = cls;
257 struct IPv4UdpAddress *v4;
258 struct IPv6UdpAddress *v6;
260 if ((addrlen != sizeof (struct IPv4UdpAddress)) &&
261 (addrlen != sizeof (struct IPv6UdpAddress)))
264 return GNUNET_SYSERR;
266 if (addrlen == sizeof (struct IPv4UdpAddress))
268 v4 = (struct IPv4UdpAddress *) addr;
269 if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port)))
270 return GNUNET_SYSERR;
272 GNUNET_NAT_test_address (plugin->nat, &v4->ipv4_addr,
273 sizeof (struct in_addr)))
274 return GNUNET_SYSERR;
278 v6 = (struct IPv6UdpAddress *) addr;
279 if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr))
282 return GNUNET_SYSERR;
284 if (GNUNET_OK != check_port (plugin, ntohs (v6->u6_port)))
285 return GNUNET_SYSERR;
287 GNUNET_NAT_test_address (plugin->nat, &v6->ipv6_addr,
288 sizeof (struct in6_addr)))
289 return GNUNET_SYSERR;
296 * Disconnect from a remote node. Clean up session if we have one for this peer
298 * @param cls closure for this call (should be handle to Plugin)
299 * @param target the peeridentity of the peer to disconnect
300 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
303 udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
310 * Creates a new outbound session the transport service will use to send data to the
313 * @param cls the plugin
314 * @param address the address
315 * @return the session or NULL of max connections exceeded
318 static struct Session *
319 udp_plugin_get_session (void *cls,
320 const struct GNUNET_HELLO_Address *address)
322 struct Session * s = NULL;
323 //struct Plugin * plugin = cls;
330 * Function that can be used by the transport service to transmit
331 * a message using the plugin. Note that in the case of a
332 * peer disconnecting, the continuation MUST be called
333 * prior to the disconnect notification itself. This function
334 * will be called with this peer's HELLO message to initiate
335 * a fresh connection to another peer.
338 * @param session which session must be used
339 * @param msgbuf the message to transmit
340 * @param msgbuf_size number of bytes in 'msgbuf'
341 * @param priority how important is the message (most plugins will
342 * ignore message priority and just FIFO)
343 * @param to how long to wait at most for the transmission (does not
344 * require plugins to discard the message after the timeout,
345 * just advisory for the desired delay; most plugins will ignore
347 * @param cont continuation to call once the message has
348 * been transmitted (or if the transport is ready
349 * for the next transmission call; or if the
350 * peer disconnected...); can be NULL
351 * @param cont_cls closure for cont
352 * @return number of bytes used (on the physical network, with overheads);
353 * -1 on hard errors (i.e. address invalid); 0 is a legal value
354 * and does NOT mean that the message was not transmitted (DV)
357 udp_plugin_send (void *cls,
358 struct Session *session,
359 const char *msgbuf, size_t msgbuf_size,
360 unsigned int priority,
361 struct GNUNET_TIME_Relative to,
362 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
371 * Our external IP address/port mapping has changed.
373 * @param cls closure, the 'struct LocalAddrList'
374 * @param add_remove GNUNET_YES to mean the new public IP address, GNUNET_NO to mean
375 * the previous (now invalid) one
376 * @param addr either the previous or the new public IP address
377 * @param addrlen actual lenght of the address
380 udp_nat_port_map_callback (void *cls, int add_remove,
381 const struct sockaddr *addr, socklen_t addrlen)
383 struct Plugin *plugin = cls;
384 struct IPv4UdpAddress u4;
385 struct IPv6UdpAddress u6;
389 /* convert 'addr' to our internal format */
390 switch (addr->sa_family)
393 GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
394 u4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
395 u4.u4_port = ((struct sockaddr_in *) addr)->sin_port;
400 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
401 memcpy (&u6.ipv6_addr, &((struct sockaddr_in6 *) addr)->sin6_addr,
402 sizeof (struct in6_addr));
403 u6.u6_port = ((struct sockaddr_in6 *) addr)->sin6_port;
411 /* modify our published address list */
412 plugin->env->notify_address (plugin->env->cls, add_remove, arg, args);
417 * Read and process a message from the given socket.
419 * @param plugin the overall plugin
420 * @param rsock socket to read from
423 udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
429 const struct GNUNET_MessageHeader *msg;
430 //const struct GNUNET_MessageHeader *ack;
431 //struct Session *peer_session;
432 //const struct UDP_ACK_Message *udp_ack;
433 //struct ReceiveContext *rc;
434 //struct GNUNET_TIME_Absolute now;
435 //struct FindReceiveContext frc;
436 //struct Session *s = NULL;
437 //struct GNUNET_TIME_Relative flow_delay;
438 //struct GNUNET_ATS_Information ats;
440 fromlen = sizeof (addr);
441 memset (&addr, 0, sizeof (addr));
442 size = GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof (buf),
443 (struct sockaddr *) &addr, &fromlen);
444 if (size < sizeof (struct GNUNET_MessageHeader))
449 msg = (const struct GNUNET_MessageHeader *) buf;
451 LOG (GNUNET_ERROR_TYPE_DEBUG,
452 "UDP received %u-byte message from `%s' type %i\n", (unsigned int) size,
453 GNUNET_a2s ((const struct sockaddr *) addr, fromlen), ntohs (msg->type));
455 if (size != ntohs (msg->size))
460 switch (ntohs (msg->type))
462 case GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON:
464 udp_broadcast_receive(plugin, &buf, size, addr, fromlen);
467 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE:
468 if (ntohs (msg->size) < sizeof (struct UDPMessage))
474 process_udp_message (plugin, (const struct UDPMessage *) msg,
475 (const struct sockaddr *) addr, fromlen);
485 * We have been notified that our readset has something to read. We don't
486 * know which socket needs to be read, so we have to check each one
487 * Then reschedule this function to be called again once more is available.
489 * @param cls the plugin handle
490 * @param tc the scheduling context (for rescheduling this function again)
493 udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
495 struct Plugin *plugin = cls;
497 plugin->select_task = GNUNET_SCHEDULER_NO_TASK;
498 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
501 if ((tc->reason & GNUNET_SCHEDULER_REASON_READ_READY) != 0)
503 if ((NULL != plugin->sockv4) &&
504 (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv4)))
505 udp_read (plugin, plugin->sockv4);
506 if ((NULL != plugin->sockv6) &&
507 (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6)))
508 udp_read (plugin, plugin->sockv6);
511 if ((tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0)
516 plugin->select_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
517 GNUNET_SCHEDULER_NO_TASK,
518 GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
519 plugin->ws, &udp_plugin_select, plugin);
525 setup_sockets (struct Plugin *plugin, struct sockaddr_in6 *serverAddrv6, struct sockaddr_in *serverAddrv4)
528 int sockets_created = 0;
529 struct sockaddr *serverAddr;
530 struct sockaddr *addrs[2];
531 socklen_t addrlens[2];
534 /* Create IPv6 socket */
535 if (plugin->enable_ipv6 == GNUNET_YES)
537 plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0);
538 if (NULL == plugin->sockv6)
540 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
544 #if HAVE_SOCKADDR_IN_SIN_LEN
545 serverAddrv6.sin6_len = sizeof (serverAddrv6);
547 serverAddrv6->sin6_family = AF_INET6;
548 serverAddrv6->sin6_addr = in6addr_any;
549 serverAddrv6->sin6_port = htons (plugin->port);
550 addrlen = sizeof (struct sockaddr_in6);
551 serverAddr = (struct sockaddr *) serverAddrv6;
553 LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 port %d\n",
554 ntohs (serverAddrv6->sin6_port));
557 while (GNUNET_NETWORK_socket_bind (plugin->sockv6, serverAddr, addrlen) !=
560 serverAddrv6->sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */
562 LOG (GNUNET_ERROR_TYPE_DEBUG,
563 "IPv6 Binding failed, trying new port %d\n",
564 ntohs (serverAddrv6->sin6_port));
569 GNUNET_NETWORK_socket_close (plugin->sockv6);
570 plugin->sockv6 = NULL;
574 if (plugin->sockv6 != NULL)
577 LOG (GNUNET_ERROR_TYPE_DEBUG,
578 "IPv6 socket created on port %d\n",
579 ntohs (serverAddrv6->sin6_port));
581 addrs[sockets_created] = (struct sockaddr *) serverAddrv6;
582 addrlens[sockets_created] = sizeof (struct sockaddr_in6);
588 /* Create IPv4 socket */
589 plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0);
590 if (NULL == plugin->sockv4)
592 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
596 #if HAVE_SOCKADDR_IN_SIN_LEN
597 serverAddrv4.sin_len = sizeof (serverAddrv4);
599 serverAddrv4->sin_family = AF_INET;
600 serverAddrv4->sin_addr.s_addr = INADDR_ANY;
601 serverAddrv4->sin_port = htons (plugin->port);
602 addrlen = sizeof (struct sockaddr_in);
603 serverAddr = (struct sockaddr *) serverAddrv4;
606 LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 port %d\n",
607 ntohs (serverAddrv4->sin_port));
610 while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen) !=
613 serverAddrv4->sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */
615 LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv4 Binding failed, trying new port %d\n",
616 ntohs (serverAddrv4->sin_port));
621 GNUNET_NETWORK_socket_close (plugin->sockv4);
622 plugin->sockv4 = NULL;
626 if (plugin->sockv4 != NULL)
628 addrs[sockets_created] = (struct sockaddr *) serverAddrv4;
629 addrlens[sockets_created] = sizeof (struct sockaddr_in);
634 /* Create file descriptors */
635 plugin->rs = GNUNET_NETWORK_fdset_create ();
636 plugin->ws = GNUNET_NETWORK_fdset_create ();
637 GNUNET_NETWORK_fdset_zero (plugin->rs);
638 GNUNET_NETWORK_fdset_zero (plugin->ws);
639 if (NULL != plugin->sockv4)
641 GNUNET_NETWORK_fdset_set (plugin->rs, plugin->sockv4);
642 GNUNET_NETWORK_fdset_set (plugin->ws, plugin->sockv4);
644 if (NULL != plugin->sockv6)
646 GNUNET_NETWORK_fdset_set (plugin->rs, plugin->sockv6);
647 GNUNET_NETWORK_fdset_set (plugin->ws, plugin->sockv6);
650 if (sockets_created == 0)
651 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to open UDP sockets\n"));
653 plugin->select_task =
654 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
655 GNUNET_SCHEDULER_NO_TASK,
656 GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
657 plugin->ws, &udp_plugin_select, plugin);
659 plugin->nat = GNUNET_NAT_register (plugin->env->cfg,
660 GNUNET_NO, plugin->port,
662 (const struct sockaddr **) addrs, addrlens,
663 &udp_nat_port_map_callback, NULL, plugin);
665 return sockets_created;
670 * The exported method. Makes the core api available via a global and
671 * returns the udp transport API.
673 * @param cls our 'struct GNUNET_TRANSPORT_PluginEnvironment'
674 * @return our 'struct GNUNET_TRANSPORT_PluginFunctions'
677 libgnunet_plugin_transport_udp_init (void *cls)
679 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
680 struct GNUNET_TRANSPORT_PluginFunctions *api;
681 struct Plugin *plugin;
683 unsigned long long port;
684 unsigned long long aport;
685 unsigned long long broadcast;
686 unsigned long long udp_max_bps;
687 unsigned long long enable_v6;
688 char * bind4_address;
689 char * bind6_address;
690 struct GNUNET_TIME_Relative interval;
692 struct sockaddr_in serverAddrv4;
693 struct sockaddr_in6 serverAddrv6;
697 /* Get port number */
699 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", "PORT",
703 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp",
704 "ADVERTISED_PORT", &aport))
708 LOG (GNUNET_ERROR_TYPE_WARNING,
709 _("Given `%s' option is out of range: %llu > %u\n"), "PORT", port,
716 GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "nat",
719 enable_v6 = GNUNET_NO;
722 enable_v6 = GNUNET_YES;
726 memset (&serverAddrv6, 0, sizeof (serverAddrv6));
727 memset (&serverAddrv4, 0, sizeof (serverAddrv4));
730 GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp",
731 "BINDTO", &bind4_address))
733 LOG (GNUNET_ERROR_TYPE_DEBUG,
734 "Binding udp plugin to specific address: `%s'\n",
736 if (1 != inet_pton (AF_INET, bind4_address, &serverAddrv4.sin_addr))
738 GNUNET_free (bind4_address);
744 GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp",
745 "BINDTO6", &bind6_address))
747 LOG (GNUNET_ERROR_TYPE_DEBUG,
748 "Binding udp plugin to specific address: `%s'\n",
751 inet_pton (AF_INET6, bind6_address, &serverAddrv6.sin6_addr))
753 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"),
755 GNUNET_free_non_null (bind4_address);
756 GNUNET_free (bind6_address);
762 /* Enable neighbour discovery */
763 broadcast = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "transport-udp",
765 if (broadcast == GNUNET_SYSERR)
766 broadcast = GNUNET_NO;
768 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (env->cfg, "transport-udp",
769 "BROADCAST_INTERVAL", &interval))
771 interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
774 /* Maximum datarate */
775 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp",
776 "MAX_BPS", &udp_max_bps))
778 udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */
781 plugin = GNUNET_malloc (sizeof (struct Plugin));
782 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
784 GNUNET_BANDWIDTH_tracker_init (&plugin->tracker,
785 GNUNET_BANDWIDTH_value_init ((uint32_t)udp_max_bps), 30);
788 plugin->aport = aport;
789 plugin->last_expected_delay = GNUNET_TIME_UNIT_SECONDS;
790 plugin->broadcast_interval = interval;
791 plugin->enable_ipv6 = enable_v6;
796 api->disconnect = &udp_disconnect;
797 api->address_pretty_printer = &udp_plugin_address_pretty_printer;
798 api->address_to_string = &udp_address_to_string;
799 api->check_address = &udp_plugin_check_address;
800 api->get_session = &udp_plugin_get_session;
801 api->send_with_session = &udp_plugin_send;
803 LOG (GNUNET_ERROR_TYPE_ERROR, "Setting up sockets\n");
804 res = setup_sockets (plugin, &serverAddrv6, &serverAddrv4);
805 if ((res == 0) || ((plugin->sockv4 == NULL) && (plugin->sockv6 == NULL)))
807 LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to create network sockets, plugin failed\n");
808 GNUNET_free (plugin);
813 LOG (GNUNET_ERROR_TYPE_ERROR, "Starting broadcasting\n");
814 setup_broadcast (plugin, &serverAddrv6, &serverAddrv4);
817 GNUNET_free_non_null (bind4_address);
818 GNUNET_free_non_null (bind6_address);
824 * The exported method. Makes the core api available via a global and
825 * returns the udp transport API.
827 * @param cls our 'struct GNUNET_TRANSPORT_PluginEnvironment'
828 * @return our 'struct GNUNET_TRANSPORT_PluginFunctions'
831 libgnunet_plugin_transport_udp_done (void *cls)
833 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
834 struct Plugin *plugin = api->cls;
836 stop_broadcast (plugin);
838 /* Closing sockets */
839 if (plugin->sockv4 != NULL)
841 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4));
842 plugin->sockv4 = NULL;
844 if (plugin->sockv6 != NULL)
846 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6));
847 plugin->sockv6 = NULL;
849 GNUNET_NETWORK_fdset_destroy (plugin->rs);
850 GNUNET_NETWORK_fdset_destroy (plugin->ws);
852 GNUNET_NAT_unregister (plugin->nat);
854 GNUNET_free (plugin);
860 /* end of plugin_transport_udp.c */