aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-10-11 16:03:12 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-10-11 16:03:12 +0000
commitc5d1714983fdbb5ca4defa5b18064c9ac35a1518 (patch)
tree53418e27c0d94c218f08d811604385dd7b2dfd7f
parenta09f045ec14e7d61f335149e1587aba99168254a (diff)
downloadgnunet-c5d1714983fdbb5ca4defa5b18064c9ac35a1518.tar.gz
gnunet-c5d1714983fdbb5ca4defa5b18064c9ac35a1518.zip
-rw-r--r--src/transport/plugin_transport_udp.c280
1 files changed, 206 insertions, 74 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index a63c7d3e5..a74f25700 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -38,6 +38,9 @@
38#include "gnunet_transport_plugin.h" 38#include "gnunet_transport_plugin.h"
39#include "transport.h" 39#include "transport.h"
40 40
41#define LOG(kind,...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__)
42
43
41#define DEBUG_UDP GNUNET_EXTRA_LOGGING 44#define DEBUG_UDP GNUNET_EXTRA_LOGGING
42 45
43/** 46/**
@@ -150,6 +153,8 @@ struct PeerSession
150 */ 153 */
151 const struct sockaddr *sock_addr; 154 const struct sockaddr *sock_addr;
152 155
156 size_t addrlen;
157
153 /** 158 /**
154 * Function to call upon completion of the transmission. 159 * Function to call upon completion of the transmission.
155 */ 160 */
@@ -222,6 +227,12 @@ struct Plugin
222 struct GNUNET_CONTAINER_MultiHashMap *sessions; 227 struct GNUNET_CONTAINER_MultiHashMap *sessions;
223 228
224 /** 229 /**
230 * Session of peers with whom we are currently connected,
231 * map of peer identity to 'struct PeerSession'.
232 */
233 struct GNUNET_CONTAINER_MultiHashMap *inbound_sessions;
234
235 /**
225 * Heap with all of our defragmentation activities. 236 * Heap with all of our defragmentation activities.
226 */ 237 */
227 struct GNUNET_CONTAINER_Heap *defrags; 238 struct GNUNET_CONTAINER_Heap *defrags;
@@ -288,6 +299,13 @@ struct Plugin
288 299
289}; 300};
290 301
302struct PeerSessionIteratorContext
303{
304 struct PeerSession * result;
305 const void * addr;
306 size_t addrlen;
307};
308
291 309
292/** 310/**
293 * Lookup the session for the given peer. 311 * Lookup the session for the given peer.
@@ -303,6 +321,44 @@ find_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *peer)
303 &peer->hashPubKey); 321 &peer->hashPubKey);
304} 322}
305 323
324int inbound_session_iterator (void *cls,
325 const GNUNET_HashCode * key,
326 void *value)
327{
328 struct PeerSessionIteratorContext *psc = cls;
329 struct PeerSession *s = value;
330 if (s->addrlen == psc->addrlen)
331 {
332 if (0 == memcmp (&s[1], psc->addr, s->addrlen))
333 psc->result = s;
334 }
335 if (psc->result != NULL)
336 return GNUNET_NO;
337 else
338 return GNUNET_YES;
339};
340
341/**
342 * Lookup the session for the given peer.
343 *
344 * @param plugin the plugin
345 * @param peer peer's identity
346 * @return NULL if we have no session
347 */
348struct PeerSession *
349find_inbound_session (struct Plugin *plugin,
350 const struct GNUNET_PeerIdentity *peer,
351 const void * addr, size_t addrlen)
352{
353 struct PeerSessionIteratorContext psc;
354 psc.result = NULL;
355 psc.addrlen = addrlen;
356 psc.addr = addr;
357
358 GNUNET_CONTAINER_multihashmap_get_multiple(plugin->inbound_sessions, &peer->hashPubKey, &inbound_session_iterator, &psc);
359 return psc.result;
360}
361
306 362
307/** 363/**
308 * Disconnect from a remote node. Clean up session if we have one for this peer 364 * Disconnect from a remote node. Clean up session if we have one for this peer
@@ -367,13 +423,11 @@ udp_send (struct Plugin *plugin, const struct sockaddr *sa,
367 return 0; 423 return 0;
368 } 424 }
369 if (GNUNET_SYSERR == sent) 425 if (GNUNET_SYSERR == sent)
370 GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "sendto"); 426 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto");
371#if DEBUG_UDP 427 LOG (GNUNET_ERROR_TYPE_ERROR,
372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
373 "UDP transmited %u-byte message to %s (%d: %s)\n", 428 "UDP transmited %u-byte message to %s (%d: %s)\n",
374 (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), 429 (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen),
375 (int) sent, (sent < 0) ? STRERROR (errno) : "ok"); 430 (int) sent, (sent < 0) ? STRERROR (errno) : "ok");
376#endif
377 return sent; 431 return sent;
378} 432}
379 433
@@ -396,6 +450,72 @@ send_fragment (void *cls, const struct GNUNET_MessageHeader *msg)
396 GNUNET_FRAGMENT_context_transmission_done (session->frag); 450 GNUNET_FRAGMENT_context_transmission_done (session->frag);
397} 451}
398 452
453static struct PeerSession *
454create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
455 const void *addr, size_t addrlen,
456 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
457{
458 struct PeerSession * peer_session;
459 const struct IPv4UdpAddress *t4;
460 const struct IPv6UdpAddress *t6;
461 struct sockaddr_in *v4;
462 struct sockaddr_in6 *v6;
463 size_t len;
464
465 switch (addrlen)
466 {
467 case sizeof (struct IPv4UdpAddress):
468 if (NULL == plugin->sockv4)
469 {
470 return NULL;
471 }
472 t4 = addr;
473 peer_session =
474 GNUNET_malloc (sizeof (struct PeerSession) +
475 sizeof (struct sockaddr_in));
476 len = sizeof (struct sockaddr_in);
477 v4 = (struct sockaddr_in *) &peer_session[1];
478 v4->sin_family = AF_INET;
479#if HAVE_SOCKADDR_IN_SIN_LEN
480 v4->sin_len = sizeof (struct sockaddr_in);
481#endif
482 v4->sin_port = t4->u4_port;
483 v4->sin_addr.s_addr = t4->ipv4_addr;
484 break;
485 case sizeof (struct IPv6UdpAddress):
486 if (NULL == plugin->sockv6)
487 {
488 return NULL;
489 }
490 t6 = addr;
491 peer_session =
492 GNUNET_malloc (sizeof (struct PeerSession) +
493 sizeof (struct sockaddr_in6));
494 len = sizeof (struct sockaddr_in6);
495 v6 = (struct sockaddr_in6 *) &peer_session[1];
496 v6->sin6_family = AF_INET6;
497#if HAVE_SOCKADDR_IN_SIN_LEN
498 v6->sin6_len = sizeof (struct sockaddr_in6);
499#endif
500 v6->sin6_port = t6->u6_port;
501 v6->sin6_addr = t6->ipv6_addr;
502 break;
503 default:
504 /* Must have a valid address to send to */
505 GNUNET_break_op (0);
506 return NULL;
507 }
508
509 peer_session->addrlen = len;
510 peer_session->target = *target;
511 peer_session->plugin = plugin;
512 peer_session->sock_addr = (const struct sockaddr *) &peer_session[1];
513 peer_session->cont = cont;
514 peer_session->cont_cls = cont_cls;
515
516 return peer_session;
517}
518
399static const char * 519static const char *
400udp_address_to_string (void *cls, const void *addr, size_t addrlen); 520udp_address_to_string (void *cls, const void *addr, size_t addrlen);
401 521
@@ -432,78 +552,45 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
432{ 552{
433 struct Plugin *plugin = cls; 553 struct Plugin *plugin = cls;
434 struct PeerSession *peer_session; 554 struct PeerSession *peer_session;
435 const struct IPv4UdpAddress *t4; 555 struct PeerSession *inbound_session;
436 const struct IPv6UdpAddress *t6;
437 struct sockaddr_in *v4;
438 struct sockaddr_in6 *v6;
439 size_t mlen = msgbuf_size + sizeof (struct UDPMessage); 556 size_t mlen = msgbuf_size + sizeof (struct UDPMessage);
440 char mbuf[mlen]; 557 char mbuf[mlen];
441 struct UDPMessage *udp; 558 struct UDPMessage *udp;
442 559
443 if (force_address == GNUNET_SYSERR)
444 return GNUNET_SYSERR;
445 GNUNET_assert (NULL == session);
446 if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 560 if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
447 { 561 {
448 GNUNET_break (0); 562 GNUNET_break (0);
449 return GNUNET_SYSERR; 563 return GNUNET_SYSERR;
450 } 564 }
451 switch (addrlen) 565
452 { 566 if (force_address == GNUNET_SYSERR)
453 case sizeof (struct IPv4UdpAddress):
454 if (NULL == plugin->sockv4)
455 {
456 if (cont != NULL)
457 cont (cont_cls, target, GNUNET_SYSERR);
458 return 0;
459 }
460 t4 = addr;
461 peer_session =
462 GNUNET_malloc (sizeof (struct PeerSession) +
463 sizeof (struct sockaddr_in));
464 v4 = (struct sockaddr_in *) &peer_session[1];
465 v4->sin_family = AF_INET;
466#if HAVE_SOCKADDR_IN_SIN_LEN
467 v4->sin_len = sizeof (struct sockaddr_in);
468#endif
469 v4->sin_port = t4->u4_port;
470 v4->sin_addr.s_addr = t4->ipv4_addr;
471 break;
472 case sizeof (struct IPv6UdpAddress):
473 if (NULL == plugin->sockv6)
474 {
475 if (cont != NULL)
476 cont (cont_cls, target, GNUNET_SYSERR);
477 return 0;
478 }
479 t6 = addr;
480 peer_session =
481 GNUNET_malloc (sizeof (struct PeerSession) +
482 sizeof (struct sockaddr_in6));
483 v6 = (struct sockaddr_in6 *) &peer_session[1];
484 v6->sin6_family = AF_INET6;
485#if HAVE_SOCKADDR_IN_SIN_LEN
486 v6->sin6_len = sizeof (struct sockaddr_in6);
487#endif
488 v6->sin6_port = t6->u6_port;
489 v6->sin6_addr = t6->ipv6_addr;
490 break;
491 default:
492 /* Must have a valid address to send to */
493 GNUNET_break_op (0);
494 return GNUNET_SYSERR; 567 return GNUNET_SYSERR;
568
569 LOG (GNUNET_ERROR_TYPE_DEBUG,
570 "UDP transmits %u-byte message to `%s' using address `%s' session 0x%X\n",
571 msgbuf_size, GNUNET_i2s (target), udp_address_to_string (NULL, addr, addrlen), session);
572
573 if (session != NULL)
574 {
575 inbound_session = (struct PeerSession *) session;
576 GNUNET_assert (0 == memcmp (&inbound_session->target, target, sizeof (struct GNUNET_PeerIdentity)));
577 }
578
579 peer_session = create_session (plugin, target, addr, addrlen, cont, cont_cls);
580 if (peer_session == NULL)
581 {
582 if (cont != NULL)
583 cont (cont_cls, target, GNUNET_SYSERR);
495 } 584 }
585
586 /* Message */
496 udp = (struct UDPMessage *) mbuf; 587 udp = (struct UDPMessage *) mbuf;
497 udp->header.size = htons (mlen); 588 udp->header.size = htons (mlen);
498 udp->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE); 589 udp->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE);
499 udp->reserved = htonl (0); 590 udp->reserved = htonl (0);
500 udp->sender = *plugin->env->my_identity; 591 udp->sender = *plugin->env->my_identity;
501 memcpy (&udp[1], msgbuf, msgbuf_size); 592 memcpy (&udp[1], msgbuf, msgbuf_size);
502 peer_session->target = *target; 593
503 peer_session->plugin = plugin;
504 peer_session->sock_addr = (const struct sockaddr *) &peer_session[1];
505 peer_session->cont = cont;
506 peer_session->cont_cls = cont_cls;
507 if (mlen <= UDP_MTU) 594 if (mlen <= UDP_MTU)
508 { 595 {
509 mlen = udp_send (plugin, peer_session->sock_addr, &udp->header); 596 mlen = udp_send (plugin, peer_session->sock_addr, &udp->header);
@@ -548,6 +635,8 @@ struct SourceInformation
548 * Number of bytes in source address. 635 * Number of bytes in source address.
549 */ 636 */
550 size_t args; 637 size_t args;
638
639 struct PeerSession * session;
551}; 640};
552 641
553 642
@@ -573,7 +662,9 @@ process_inbound_tokenized_messages (void *cls, void *client,
573 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 662 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
574 distance[1].value = htonl (0); 663 distance[1].value = htonl (0);
575 664
576 plugin->env->receive (plugin->env->cls, &si->sender, hdr, distance, 2, NULL, 665 LOG (GNUNET_ERROR_TYPE_DEBUG,
666 "Giving Session %X %s to transport\n", (struct Session *) si->session, GNUNET_i2s(&si->session->target));
667 plugin->env->receive (plugin->env->cls, &si->sender, hdr, distance, 2, (struct Session *) si->session,
577 si->arg, si->args); 668 si->arg, si->args);
578} 669}
579 670
@@ -631,17 +722,51 @@ process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg,
631 return; 722 return;
632 } 723 }
633#if DEBUG_UDP 724#if DEBUG_UDP
634 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", 725 LOG (GNUNET_ERROR_TYPE_DEBUG,
635 "Received message with %u bytes from peer `%s' at `%s'\n", 726 "Received message with %u bytes from peer `%s' at `%s'\n",
636 (unsigned int) ntohs (msg->header.size), 727 (unsigned int) ntohs (msg->header.size),
637 GNUNET_i2s (&msg->sender), GNUNET_a2s (sender_addr, 728 GNUNET_i2s (&msg->sender), GNUNET_a2s (sender_addr,
638 sender_addr_len)); 729 sender_addr_len));
639#endif 730#endif
640 731
732 /* create a session for inbound connections */
733 const struct UDPMessage * udp_msg = (const struct UDPMessage *) msg;
734 LOG (GNUNET_ERROR_TYPE_DEBUG,
735 "Lookup inbound UDP sessions for peer `%s' address `%s'\n",
736 GNUNET_i2s (&udp_msg->sender),
737 udp_address_to_string(NULL, arg, args));
738
739 struct PeerSession * s = NULL;
740 s = find_inbound_session (plugin, &udp_msg->sender, sender_addr, sender_addr_len);
741
742 if (s != NULL)
743 {
744 LOG (GNUNET_ERROR_TYPE_DEBUG,
745 "Found existing inbound UDP sessions 0x%X for peer `%s' address `%s'\n",
746 s,
747 GNUNET_i2s (&s->target),
748 udp_address_to_string(NULL, arg, args));
749 }
750 else
751 {
752 s = create_session (plugin, &udp_msg->sender, arg, args, NULL, NULL);
753 LOG (GNUNET_ERROR_TYPE_DEBUG,
754 "Creating inbound UDP sessions 0x%X for peer `%s' address `%s'\n",
755 s,
756 GNUNET_i2s (&s->target),
757 udp_address_to_string(NULL, arg, args));
758
759 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (plugin->inbound_sessions,
760 &s->target.hashPubKey,
761 s,
762 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
763 }
764
641 /* iterate over all embedded messages */ 765 /* iterate over all embedded messages */
642 si.sender = msg->sender; 766 si.sender = msg->sender;
643 si.arg = arg; 767 si.arg = arg;
644 si.args = args; 768 si.args = args;
769 si.session = s;
645 GNUNET_SERVER_mst_receive (plugin->mst, &si, (const char *) &msg[1], 770 GNUNET_SERVER_mst_receive (plugin->mst, &si, (const char *) &msg[1],
646 ntohs (msg->header.size) - 771 ntohs (msg->header.size) -
647 sizeof (struct UDPMessage), GNUNET_YES, GNUNET_NO); 772 sizeof (struct UDPMessage), GNUNET_YES, GNUNET_NO);
@@ -690,7 +815,7 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
690 struct UDPMessage *udp; 815 struct UDPMessage *udp;
691 816
692#if DEBUG_UDP 817#if DEBUG_UDP
693 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", "Sending ACK to `%s'\n", 818 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ACK to `%s'\n",
694 GNUNET_a2s (rc->src_addr, 819 GNUNET_a2s (rc->src_addr,
695 (rc->src_addr->sa_family == 820 (rc->src_addr->sa_family ==
696 AF_INET) ? sizeof (struct sockaddr_in) : 821 AF_INET) ? sizeof (struct sockaddr_in) :
@@ -787,7 +912,7 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
787 return; 912 return;
788 } 913 }
789#if DEBUG_UDP 914#if DEBUG_UDP
790 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 915 LOG (GNUNET_ERROR_TYPE_DEBUG,
791 "UDP received %u-byte message from `%s'\n", (unsigned int) ret, 916 "UDP received %u-byte message from `%s'\n", (unsigned int) ret,
792 GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); 917 GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
793#endif 918#endif
@@ -828,7 +953,7 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
828 return; 953 return;
829 } 954 }
830#if DEBUG_UDP 955#if DEBUG_UDP
831 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 956 LOG (GNUNET_ERROR_TYPE_DEBUG,
832 "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", 957 "UDP processes %u-byte acknowledgement from `%s' at `%s'\n",
833 (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp->sender), 958 (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp->sender),
834 GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); 959 GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
@@ -838,7 +963,7 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
838 if (NULL == peer_session) 963 if (NULL == peer_session)
839 { 964 {
840#if DEBUG_UDP 965#if DEBUG_UDP
841 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 966 LOG (GNUNET_ERROR_TYPE_DEBUG,
842 "Session for ACK not found, dropping ACK!\n"); 967 "Session for ACK not found, dropping ACK!\n");
843#endif 968#endif
844 return; 969 return;
@@ -882,7 +1007,7 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
882 now.abs_value); 1007 now.abs_value);
883 } 1008 }
884#if DEBUG_UDP 1009#if DEBUG_UDP
885 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1010 LOG (GNUNET_ERROR_TYPE_DEBUG,
886 "UDP processes %u-byte fragment from `%s'\n", 1011 "UDP processes %u-byte fragment from `%s'\n",
887 (unsigned int) ntohs (msg->size), 1012 (unsigned int) ntohs (msg->size),
888 GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); 1013 GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
@@ -1276,7 +1401,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
1276 aport = port; 1401 aport = port;
1277 if (port > 65535) 1402 if (port > 65535)
1278 { 1403 {
1279 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1404 LOG (GNUNET_ERROR_TYPE_WARNING,
1280 _("Given `%s' option is out of range: %llu > %u\n"), "PORT", 1405 _("Given `%s' option is out of range: %llu > %u\n"), "PORT",
1281 port, 65535); 1406 port, 65535);
1282 return NULL; 1407 return NULL;
@@ -1305,7 +1430,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
1305 GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", 1430 GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp",
1306 "BINDTO", &plugin->bind4_address)) 1431 "BINDTO", &plugin->bind4_address))
1307 { 1432 {
1308 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1433 LOG (GNUNET_ERROR_TYPE_DEBUG,
1309 "Binding udp plugin to specific address: `%s'\n", 1434 "Binding udp plugin to specific address: `%s'\n",
1310 plugin->bind4_address); 1435 plugin->bind4_address);
1311 if (1 != inet_pton (AF_INET, plugin->bind4_address, &serverAddrv4.sin_addr)) 1436 if (1 != inet_pton (AF_INET, plugin->bind4_address, &serverAddrv4.sin_addr))
@@ -1321,13 +1446,13 @@ libgnunet_plugin_transport_udp_init (void *cls)
1321 GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", 1446 GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp",
1322 "BINDTO6", &plugin->bind6_address)) 1447 "BINDTO6", &plugin->bind6_address))
1323 { 1448 {
1324 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1449 LOG (GNUNET_ERROR_TYPE_DEBUG,
1325 "Binding udp plugin to specific address: `%s'\n", 1450 "Binding udp plugin to specific address: `%s'\n",
1326 plugin->bind6_address); 1451 plugin->bind6_address);
1327 if (1 != 1452 if (1 !=
1328 inet_pton (AF_INET6, plugin->bind6_address, &serverAddrv6.sin6_addr)) 1453 inet_pton (AF_INET6, plugin->bind6_address, &serverAddrv6.sin6_addr))
1329 { 1454 {
1330 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"), 1455 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"),
1331 plugin->bind6_address); 1456 plugin->bind6_address);
1332 GNUNET_free_non_null (plugin->bind4_address); 1457 GNUNET_free_non_null (plugin->bind4_address);
1333 GNUNET_free (plugin->bind6_address); 1458 GNUNET_free (plugin->bind6_address);
@@ -1342,6 +1467,9 @@ libgnunet_plugin_transport_udp_init (void *cls)
1342 plugin->sessions = 1467 plugin->sessions =
1343 GNUNET_CONTAINER_multihashmap_create (UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG 1468 GNUNET_CONTAINER_multihashmap_create (UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG
1344 * 2); 1469 * 2);
1470 plugin->inbound_sessions =
1471 GNUNET_CONTAINER_multihashmap_create (UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG
1472 * 2);
1345 sockets_created = 0; 1473 sockets_created = 0;
1346 if ((GNUNET_YES != 1474 if ((GNUNET_YES !=
1347 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, "nat", 1475 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, "nat",
@@ -1363,7 +1491,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
1363 addrlen = sizeof (serverAddrv6); 1491 addrlen = sizeof (serverAddrv6);
1364 serverAddr = (struct sockaddr *) &serverAddrv6; 1492 serverAddr = (struct sockaddr *) &serverAddrv6;
1365#if DEBUG_UDP 1493#if DEBUG_UDP
1366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 port %d\n", 1494 LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 port %d\n",
1367 ntohs (serverAddrv6.sin6_port)); 1495 ntohs (serverAddrv6.sin6_port));
1368#endif 1496#endif
1369 tries = 0; 1497 tries = 0;
@@ -1372,7 +1500,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
1372 { 1500 {
1373 serverAddrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ 1501 serverAddrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */
1374#if DEBUG_UDP 1502#if DEBUG_UDP
1375 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1503 LOG (GNUNET_ERROR_TYPE_DEBUG,
1376 "IPv6 Binding failed, trying new port %d\n", 1504 "IPv6 Binding failed, trying new port %d\n",
1377 ntohs (serverAddrv6.sin6_port)); 1505 ntohs (serverAddrv6.sin6_port));
1378#endif 1506#endif
@@ -1411,7 +1539,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
1411 addrlen = sizeof (serverAddrv4); 1539 addrlen = sizeof (serverAddrv4);
1412 serverAddr = (struct sockaddr *) &serverAddrv4; 1540 serverAddr = (struct sockaddr *) &serverAddrv4;
1413#if DEBUG_UDP 1541#if DEBUG_UDP
1414 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 port %d\n", 1542 LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 port %d\n",
1415 ntohs (serverAddrv4.sin_port)); 1543 ntohs (serverAddrv4.sin_port));
1416#endif 1544#endif
1417 tries = 0; 1545 tries = 0;
@@ -1420,7 +1548,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
1420 { 1548 {
1421 serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ 1549 serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */
1422#if DEBUG_UDP 1550#if DEBUG_UDP
1423 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1551 LOG (GNUNET_ERROR_TYPE_DEBUG,
1424 "IPv4 Binding failed, trying new port %d\n", 1552 "IPv4 Binding failed, trying new port %d\n",
1425 ntohs (serverAddrv4.sin_port)); 1553 ntohs (serverAddrv4.sin_port));
1426#endif 1554#endif
@@ -1499,6 +1627,10 @@ libgnunet_plugin_transport_udp_done (void *cls)
1499 NULL); 1627 NULL);
1500 GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions); 1628 GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions);
1501 plugin->sessions = NULL; 1629 plugin->sessions = NULL;
1630 GNUNET_CONTAINER_multihashmap_iterate (plugin->inbound_sessions, &destroy_session,
1631 NULL);
1632 GNUNET_CONTAINER_multihashmap_destroy (plugin->inbound_sessions);
1633 plugin->inbound_sessions = NULL;
1502 while (NULL != (rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags))) 1634 while (NULL != (rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags)))
1503 { 1635 {
1504 GNUNET_DEFRAGMENT_context_destroy (rc->defrag); 1636 GNUNET_DEFRAGMENT_context_destroy (rc->defrag);