aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_udp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/plugin_transport_udp.c')
-rw-r--r--src/transport/plugin_transport_udp.c3988
1 files changed, 1994 insertions, 1994 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index 1d34cdd1a..755809194 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2010-2017 GNUnet e.V. 3 Copyright (C) 2010-2017 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -40,13 +40,13 @@
40#include "gnunet_transport_plugin.h" 40#include "gnunet_transport_plugin.h"
41#include "transport.h" 41#include "transport.h"
42 42
43#define LOG(kind, ...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__) 43#define LOG(kind, ...) GNUNET_log_from(kind, "transport-udp", __VA_ARGS__)
44 44
45/** 45/**
46 * After how much inactivity should a UDP session time out? 46 * After how much inactivity should a UDP session time out?
47 */ 47 */
48#define UDP_SESSION_TIME_OUT \ 48#define UDP_SESSION_TIME_OUT \
49 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) 49 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60)
50 50
51/** 51/**
52 * Number of messages we can defragment in parallel. We only really 52 * Number of messages we can defragment in parallel. We only really
@@ -71,8 +71,7 @@
71/** 71/**
72 * UDP Message-Packet header (after defragmentation). 72 * UDP Message-Packet header (after defragmentation).
73 */ 73 */
74struct UDPMessage 74struct UDPMessage {
75{
76 /** 75 /**
77 * Message header. 76 * Message header.
78 */ 77 */
@@ -93,8 +92,7 @@ struct UDPMessage
93/** 92/**
94 * Closure for #append_port(). 93 * Closure for #append_port().
95 */ 94 */
96struct PrettyPrinterContext 95struct PrettyPrinterContext {
97{
98 /** 96 /**
99 * DLL 97 * DLL
100 */ 98 */
@@ -150,8 +148,7 @@ struct PrettyPrinterContext
150/** 148/**
151 * Session with another peer. 149 * Session with another peer.
152 */ 150 */
153struct GNUNET_ATS_Session 151struct GNUNET_ATS_Session {
154{
155 /** 152 /**
156 * Which peer is this session for? 153 * Which peer is this session for?
157 */ 154 */
@@ -251,9 +248,7 @@ struct GNUNET_ATS_Session
251 * Data structure to track defragmentation contexts based 248 * Data structure to track defragmentation contexts based
252 * on the source of the UDP traffic. 249 * on the source of the UDP traffic.
253 */ 250 */
254struct DefragContext 251struct DefragContext {
255{
256
257 /** 252 /**
258 * Defragmentation context. 253 * Defragmentation context.
259 */ 254 */
@@ -302,8 +297,7 @@ struct DefragContext
302/** 297/**
303 * Context to send fragmented messages 298 * Context to send fragmented messages
304 */ 299 */
305struct UDP_FragmentationContext 300struct UDP_FragmentationContext {
306{
307 /** 301 /**
308 * Next in linked list 302 * Next in linked list
309 */ 303 */
@@ -393,8 +387,7 @@ typedef void (*QueueContinuation) (void *cls,
393/** 387/**
394 * Information we track for each message in the queue. 388 * Information we track for each message in the queue.
395 */ 389 */
396struct UDP_MessageWrapper 390struct UDP_MessageWrapper {
397{
398 /** 391 /**
399 * Session this message belongs to 392 * Session this message belongs to
400 */ 393 */
@@ -478,8 +471,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
478/** 471/**
479 * UDP ACK Message-Packet header. 472 * UDP ACK Message-Packet header.
480 */ 473 */
481struct UDP_ACK_Message 474struct UDP_ACK_Message {
482{
483 /** 475 /**
484 * Message header. 476 * Message header.
485 */ 477 */
@@ -513,9 +505,9 @@ GNUNET_NETWORK_STRUCT_END
513 * @param state new state of the session 505 * @param state new state of the session
514 */ 506 */
515static void 507static void
516notify_session_monitor (struct Plugin *plugin, 508notify_session_monitor(struct Plugin *plugin,
517 struct GNUNET_ATS_Session *session, 509 struct GNUNET_ATS_Session *session,
518 enum GNUNET_TRANSPORT_SessionState state) 510 enum GNUNET_TRANSPORT_SessionState state)
519{ 511{
520 struct GNUNET_TRANSPORT_SessionInfo info; 512 struct GNUNET_TRANSPORT_SessionInfo info;
521 513
@@ -523,7 +515,7 @@ notify_session_monitor (struct Plugin *plugin,
523 return; 515 return;
524 if (GNUNET_YES == session->in_destroy) 516 if (GNUNET_YES == session->in_destroy)
525 return; /* already destroyed, just RC>0 left-over actions */ 517 return; /* already destroyed, just RC>0 left-over actions */
526 memset (&info, 0, sizeof (info)); 518 memset(&info, 0, sizeof(info));
527 info.state = state; 519 info.state = state;
528 info.is_inbound = GNUNET_SYSERR; /* hard to say */ 520 info.is_inbound = GNUNET_SYSERR; /* hard to say */
529 info.num_msg_pending = session->msgs_in_queue; 521 info.num_msg_pending = session->msgs_in_queue;
@@ -533,7 +525,7 @@ notify_session_monitor (struct Plugin *plugin,
533 to receive from others) */ 525 to receive from others) */
534 info.session_timeout = session->timeout; 526 info.session_timeout = session->timeout;
535 info.address = session->address; 527 info.address = session->address;
536 plugin->sic (plugin->sic_cls, session, &info); 528 plugin->sic(plugin->sic_cls, session, &info);
537} 529}
538 530
539 531
@@ -546,15 +538,15 @@ notify_session_monitor (struct Plugin *plugin,
546 * @return #GNUNET_OK (continue to iterate) 538 * @return #GNUNET_OK (continue to iterate)
547 */ 539 */
548static int 540static int
549send_session_info_iter (void *cls, 541send_session_info_iter(void *cls,
550 const struct GNUNET_PeerIdentity *peer, 542 const struct GNUNET_PeerIdentity *peer,
551 void *value) 543 void *value)
552{ 544{
553 struct Plugin *plugin = cls; 545 struct Plugin *plugin = cls;
554 struct GNUNET_ATS_Session *session = value; 546 struct GNUNET_ATS_Session *session = value;
555 547
556 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT); 548 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_INIT);
557 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP); 549 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UP);
558 return GNUNET_OK; 550 return GNUNET_OK;
559} 551}
560 552
@@ -572,22 +564,22 @@ send_session_info_iter (void *cls,
572 * @param sic_cls closure for @a sic 564 * @param sic_cls closure for @a sic
573 */ 565 */
574static void 566static void
575udp_plugin_setup_monitor (void *cls, 567udp_plugin_setup_monitor(void *cls,
576 GNUNET_TRANSPORT_SessionInfoCallback sic, 568 GNUNET_TRANSPORT_SessionInfoCallback sic,
577 void *sic_cls) 569 void *sic_cls)
578{ 570{
579 struct Plugin *plugin = cls; 571 struct Plugin *plugin = cls;
580 572
581 plugin->sic = sic; 573 plugin->sic = sic;
582 plugin->sic_cls = sic_cls; 574 plugin->sic_cls = sic_cls;
583 if (NULL != sic) 575 if (NULL != sic)
584 { 576 {
585 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, 577 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions,
586 &send_session_info_iter, 578 &send_session_info_iter,
587 plugin); 579 plugin);
588 /* signal end of first iteration */ 580 /* signal end of first iteration */
589 sic (sic_cls, NULL, NULL); 581 sic(sic_cls, NULL, NULL);
590 } 582 }
591} 583}
592 584
593 585
@@ -600,25 +592,25 @@ udp_plugin_setup_monitor (void *cls,
600 * @param s session to free 592 * @param s session to free
601 */ 593 */
602static void 594static void
603free_session (struct GNUNET_ATS_Session *s) 595free_session(struct GNUNET_ATS_Session *s)
604{ 596{
605 if (NULL != s->address) 597 if (NULL != s->address)
606 { 598 {
607 GNUNET_HELLO_address_free (s->address); 599 GNUNET_HELLO_address_free(s->address);
608 s->address = NULL; 600 s->address = NULL;
609 } 601 }
610 if (NULL != s->frag_ctx) 602 if (NULL != s->frag_ctx)
611 { 603 {
612 GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag, NULL, NULL); 604 GNUNET_FRAGMENT_context_destroy(s->frag_ctx->frag, NULL, NULL);
613 GNUNET_free (s->frag_ctx); 605 GNUNET_free(s->frag_ctx);
614 s->frag_ctx = NULL; 606 s->frag_ctx = NULL;
615 } 607 }
616 if (NULL != s->mst) 608 if (NULL != s->mst)
617 { 609 {
618 GNUNET_MST_destroy (s->mst); 610 GNUNET_MST_destroy(s->mst);
619 s->mst = NULL; 611 s->mst = NULL;
620 } 612 }
621 GNUNET_free (s); 613 GNUNET_free(s);
622} 614}
623 615
624 616
@@ -631,7 +623,7 @@ free_session (struct GNUNET_ATS_Session *s)
631 * @return keepalive factor 623 * @return keepalive factor
632 */ 624 */
633static unsigned int 625static unsigned int
634udp_query_keepalive_factor (void *cls) 626udp_query_keepalive_factor(void *cls)
635{ 627{
636 return 15; 628 return 15;
637} 629}
@@ -645,7 +637,7 @@ udp_query_keepalive_factor (void *cls)
645 * @return the network type 637 * @return the network type
646 */ 638 */
647static enum GNUNET_NetworkType 639static enum GNUNET_NetworkType
648udp_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session) 640udp_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session)
649{ 641{
650 return session->scope; 642 return session->scope;
651} 643}
@@ -659,8 +651,8 @@ udp_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session)
659 * @return the network type 651 * @return the network type
660 */ 652 */
661static enum GNUNET_NetworkType 653static enum GNUNET_NetworkType
662udp_plugin_get_network_for_address (void *cls, 654udp_plugin_get_network_for_address(void *cls,
663 const struct GNUNET_HELLO_Address *address) 655 const struct GNUNET_HELLO_Address *address)
664{ 656{
665 struct Plugin *plugin = cls; 657 struct Plugin *plugin = cls;
666 size_t addrlen; 658 size_t addrlen;
@@ -672,40 +664,40 @@ udp_plugin_get_network_for_address (void *cls,
672 size_t sbs; 664 size_t sbs;
673 665
674 addrlen = address->address_length; 666 addrlen = address->address_length;
675 if (addrlen == sizeof (struct IPv6UdpAddress)) 667 if (addrlen == sizeof(struct IPv6UdpAddress))
676 { 668 {
677 GNUNET_assert (NULL != address->address); /* make static analysis happy */ 669 GNUNET_assert(NULL != address->address); /* make static analysis happy */
678 u6 = address->address; 670 u6 = address->address;
679 memset (&a6, 0, sizeof (a6)); 671 memset(&a6, 0, sizeof(a6));
680#if HAVE_SOCKADDR_IN_SIN_LEN 672#if HAVE_SOCKADDR_IN_SIN_LEN
681 a6.sin6_len = sizeof (a6); 673 a6.sin6_len = sizeof(a6);
682#endif 674#endif
683 a6.sin6_family = AF_INET6; 675 a6.sin6_family = AF_INET6;
684 a6.sin6_port = u6->u6_port; 676 a6.sin6_port = u6->u6_port;
685 GNUNET_memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof (struct in6_addr)); 677 GNUNET_memcpy(&a6.sin6_addr, &u6->ipv6_addr, sizeof(struct in6_addr));
686 sb = &a6; 678 sb = &a6;
687 sbs = sizeof (a6); 679 sbs = sizeof(a6);
688 } 680 }
689 else if (addrlen == sizeof (struct IPv4UdpAddress)) 681 else if (addrlen == sizeof(struct IPv4UdpAddress))
690 { 682 {
691 GNUNET_assert (NULL != address->address); /* make static analysis happy */ 683 GNUNET_assert(NULL != address->address); /* make static analysis happy */
692 u4 = address->address; 684 u4 = address->address;
693 memset (&a4, 0, sizeof (a4)); 685 memset(&a4, 0, sizeof(a4));
694#if HAVE_SOCKADDR_IN_SIN_LEN 686#if HAVE_SOCKADDR_IN_SIN_LEN
695 a4.sin_len = sizeof (a4); 687 a4.sin_len = sizeof(a4);
696#endif 688#endif
697 a4.sin_family = AF_INET; 689 a4.sin_family = AF_INET;
698 a4.sin_port = u4->u4_port; 690 a4.sin_port = u4->u4_port;
699 a4.sin_addr.s_addr = u4->ipv4_addr; 691 a4.sin_addr.s_addr = u4->ipv4_addr;
700 sb = &a4; 692 sb = &a4;
701 sbs = sizeof (a4); 693 sbs = sizeof(a4);
702 } 694 }
703 else 695 else
704 { 696 {
705 GNUNET_break (0); 697 GNUNET_break(0);
706 return GNUNET_NT_UNSPECIFIED; 698 return GNUNET_NT_UNSPECIFIED;
707 } 699 }
708 return plugin->env->get_address_type (plugin->env->cls, sb, sbs); 700 return plugin->env->get_address_type(plugin->env->cls, sb, sbs);
709} 701}
710 702
711 703
@@ -719,7 +711,7 @@ udp_plugin_get_network_for_address (void *cls,
719 * @param cls the plugin handle 711 * @param cls the plugin handle
720 */ 712 */
721static void 713static void
722udp_plugin_select_v4 (void *cls); 714udp_plugin_select_v4(void *cls);
723 715
724 716
725/** 717/**
@@ -730,7 +722,7 @@ udp_plugin_select_v4 (void *cls);
730 * @param cls the plugin handle 722 * @param cls the plugin handle
731 */ 723 */
732static void 724static void
733udp_plugin_select_v6 (void *cls); 725udp_plugin_select_v6(void *cls);
734 726
735 727
736/** 728/**
@@ -739,7 +731,7 @@ udp_plugin_select_v6 (void *cls);
739 * @param plugin plugin to reschedule 731 * @param plugin plugin to reschedule
740 */ 732 */
741static void 733static void
742schedule_select_v4 (struct Plugin *plugin) 734schedule_select_v4(struct Plugin *plugin)
743{ 735{
744 struct GNUNET_TIME_Relative min_delay; 736 struct GNUNET_TIME_Relative min_delay;
745 struct GNUNET_TIME_Relative delay; 737 struct GNUNET_TIME_Relative delay;
@@ -747,47 +739,47 @@ schedule_select_v4 (struct Plugin *plugin)
747 struct UDP_MessageWrapper *min_udpw; 739 struct UDP_MessageWrapper *min_udpw;
748 740
749 if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4)) 741 if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4))
750 { 742 {
751 /* Find a message ready to send: 743 /* Find a message ready to send:
752 * Flow delay from other peer is expired or not set (0) */ 744 * Flow delay from other peer is expired or not set (0) */
753 min_delay = GNUNET_TIME_UNIT_FOREVER_REL; 745 min_delay = GNUNET_TIME_UNIT_FOREVER_REL;
754 min_udpw = NULL; 746 min_udpw = NULL;
755 for (udpw = plugin->ipv4_queue_head; NULL != udpw; udpw = udpw->next) 747 for (udpw = plugin->ipv4_queue_head; NULL != udpw; udpw = udpw->next)
756 { 748 {
757 delay = GNUNET_TIME_absolute_get_remaining (udpw->transmission_time); 749 delay = GNUNET_TIME_absolute_get_remaining(udpw->transmission_time);
758 if (delay.rel_value_us < min_delay.rel_value_us) 750 if (delay.rel_value_us < min_delay.rel_value_us)
759 { 751 {
760 min_delay = delay; 752 min_delay = delay;
761 min_udpw = udpw; 753 min_udpw = udpw;
762 } 754 }
763 } 755 }
764 if (NULL != plugin->select_task_v4) 756 if (NULL != plugin->select_task_v4)
765 GNUNET_SCHEDULER_cancel (plugin->select_task_v4); 757 GNUNET_SCHEDULER_cancel(plugin->select_task_v4);
766 if (NULL != min_udpw) 758 if (NULL != min_udpw)
767 { 759 {
768 if (min_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 760 if (min_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
769 { 761 {
770 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 762 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
771 "Calculated flow delay for UDPv4 at %s for %s\n", 763 "Calculated flow delay for UDPv4 at %s for %s\n",
772 GNUNET_STRINGS_relative_time_to_string (min_delay, 764 GNUNET_STRINGS_relative_time_to_string(min_delay,
773 GNUNET_YES), 765 GNUNET_YES),
774 GNUNET_i2s (&min_udpw->session->target)); 766 GNUNET_i2s(&min_udpw->session->target));
775 } 767 }
776 else 768 else
777 { 769 {
778 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 770 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
779 "Calculated flow delay for UDPv4 at %s for %s\n", 771 "Calculated flow delay for UDPv4 at %s for %s\n",
780 GNUNET_STRINGS_relative_time_to_string (min_delay, 772 GNUNET_STRINGS_relative_time_to_string(min_delay,
781 GNUNET_YES), 773 GNUNET_YES),
782 GNUNET_i2s (&min_udpw->session->target)); 774 GNUNET_i2s(&min_udpw->session->target));
783 } 775 }
784 } 776 }
785 plugin->select_task_v4 = 777 plugin->select_task_v4 =
786 GNUNET_SCHEDULER_add_read_net (min_delay, 778 GNUNET_SCHEDULER_add_read_net(min_delay,
787 plugin->sockv4, 779 plugin->sockv4,
788 &udp_plugin_select_v4, 780 &udp_plugin_select_v4,
789 plugin); 781 plugin);
790 } 782 }
791} 783}
792 784
793 785
@@ -797,7 +789,7 @@ schedule_select_v4 (struct Plugin *plugin)
797 * @param plugin plugin to reschedule 789 * @param plugin plugin to reschedule
798 */ 790 */
799static void 791static void
800schedule_select_v6 (struct Plugin *plugin) 792schedule_select_v6(struct Plugin *plugin)
801{ 793{
802 struct GNUNET_TIME_Relative min_delay; 794 struct GNUNET_TIME_Relative min_delay;
803 struct GNUNET_TIME_Relative delay; 795 struct GNUNET_TIME_Relative delay;
@@ -805,45 +797,45 @@ schedule_select_v6 (struct Plugin *plugin)
805 struct UDP_MessageWrapper *min_udpw; 797 struct UDP_MessageWrapper *min_udpw;
806 798
807 if ((GNUNET_YES == plugin->enable_ipv6) && (NULL != plugin->sockv6)) 799 if ((GNUNET_YES == plugin->enable_ipv6) && (NULL != plugin->sockv6))
808 { 800 {
809 min_delay = GNUNET_TIME_UNIT_FOREVER_REL; 801 min_delay = GNUNET_TIME_UNIT_FOREVER_REL;
810 min_udpw = NULL; 802 min_udpw = NULL;
811 for (udpw = plugin->ipv6_queue_head; NULL != udpw; udpw = udpw->next) 803 for (udpw = plugin->ipv6_queue_head; NULL != udpw; udpw = udpw->next)
812 { 804 {
813 delay = GNUNET_TIME_absolute_get_remaining (udpw->transmission_time); 805 delay = GNUNET_TIME_absolute_get_remaining(udpw->transmission_time);
814 if (delay.rel_value_us < min_delay.rel_value_us) 806 if (delay.rel_value_us < min_delay.rel_value_us)
815 { 807 {
816 min_delay = delay; 808 min_delay = delay;
817 min_udpw = udpw; 809 min_udpw = udpw;
818 } 810 }
819 } 811 }
820 if (NULL != plugin->select_task_v6) 812 if (NULL != plugin->select_task_v6)
821 GNUNET_SCHEDULER_cancel (plugin->select_task_v6); 813 GNUNET_SCHEDULER_cancel(plugin->select_task_v6);
822 if (NULL != min_udpw) 814 if (NULL != min_udpw)
823 { 815 {
824 if (min_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 816 if (min_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
825 { 817 {
826 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 818 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
827 "Calculated flow delay for UDPv6 at %s for %s\n", 819 "Calculated flow delay for UDPv6 at %s for %s\n",
828 GNUNET_STRINGS_relative_time_to_string (min_delay, 820 GNUNET_STRINGS_relative_time_to_string(min_delay,
829 GNUNET_YES), 821 GNUNET_YES),
830 GNUNET_i2s (&min_udpw->session->target)); 822 GNUNET_i2s(&min_udpw->session->target));
831 } 823 }
832 else 824 else
833 { 825 {
834 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 826 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
835 "Calculated flow delay for UDPv6 at %s for %s\n", 827 "Calculated flow delay for UDPv6 at %s for %s\n",
836 GNUNET_STRINGS_relative_time_to_string (min_delay, 828 GNUNET_STRINGS_relative_time_to_string(min_delay,
837 GNUNET_YES), 829 GNUNET_YES),
838 GNUNET_i2s (&min_udpw->session->target)); 830 GNUNET_i2s(&min_udpw->session->target));
839 } 831 }
840 } 832 }
841 plugin->select_task_v6 = 833 plugin->select_task_v6 =
842 GNUNET_SCHEDULER_add_read_net (min_delay, 834 GNUNET_SCHEDULER_add_read_net(min_delay,
843 plugin->sockv6, 835 plugin->sockv6,
844 &udp_plugin_select_v6, 836 &udp_plugin_select_v6,
845 plugin); 837 plugin);
846 } 838 }
847} 839}
848 840
849 841
@@ -862,7 +854,7 @@ schedule_select_v6 (struct Plugin *plugin)
862 * @return string representing the same address 854 * @return string representing the same address
863 */ 855 */
864const char * 856const char *
865udp_address_to_string (void *cls, const void *addr, size_t addrlen) 857udp_address_to_string(void *cls, const void *addr, size_t addrlen)
866{ 858{
867 static char rbuf[INET6_ADDRSTRLEN + 10]; 859 static char rbuf[INET6_ADDRSTRLEN + 10];
868 char buf[INET6_ADDRSTRLEN]; 860 char buf[INET6_ADDRSTRLEN];
@@ -876,42 +868,42 @@ udp_address_to_string (void *cls, const void *addr, size_t addrlen)
876 uint32_t options; 868 uint32_t options;
877 869
878 if (NULL == addr) 870 if (NULL == addr)
879 { 871 {
880 GNUNET_break_op (0); 872 GNUNET_break_op(0);
881 return NULL; 873 return NULL;
882 } 874 }
883 875
884 if (addrlen == sizeof (struct IPv6UdpAddress)) 876 if (addrlen == sizeof(struct IPv6UdpAddress))
885 { 877 {
886 t6 = addr; 878 t6 = addr;
887 af = AF_INET6; 879 af = AF_INET6;
888 options = ntohl (t6->options); 880 options = ntohl(t6->options);
889 port = ntohs (t6->u6_port); 881 port = ntohs(t6->u6_port);
890 a6 = t6->ipv6_addr; 882 a6 = t6->ipv6_addr;
891 sb = &a6; 883 sb = &a6;
892 } 884 }
893 else if (addrlen == sizeof (struct IPv4UdpAddress)) 885 else if (addrlen == sizeof(struct IPv4UdpAddress))
894 { 886 {
895 t4 = addr; 887 t4 = addr;
896 af = AF_INET; 888 af = AF_INET;
897 options = ntohl (t4->options); 889 options = ntohl(t4->options);
898 port = ntohs (t4->u4_port); 890 port = ntohs(t4->u4_port);
899 a4.s_addr = t4->ipv4_addr; 891 a4.s_addr = t4->ipv4_addr;
900 sb = &a4; 892 sb = &a4;
901 } 893 }
902 else 894 else
903 { 895 {
904 GNUNET_break_op (0); 896 GNUNET_break_op(0);
905 return NULL; 897 return NULL;
906 } 898 }
907 inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); 899 inet_ntop(af, sb, buf, INET6_ADDRSTRLEN);
908 GNUNET_snprintf (rbuf, 900 GNUNET_snprintf(rbuf,
909 sizeof (rbuf), 901 sizeof(rbuf),
910 (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", 902 (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u",
911 PLUGIN_NAME, 903 PLUGIN_NAME,
912 options, 904 options,
913 buf, 905 buf,
914 port); 906 port);
915 return rbuf; 907 return rbuf;
916} 908}
917 909
@@ -928,11 +920,11 @@ udp_address_to_string (void *cls, const void *addr, size_t addrlen)
928 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 920 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
929 */ 921 */
930static int 922static int
931udp_string_to_address (void *cls, 923udp_string_to_address(void *cls,
932 const char *addr, 924 const char *addr,
933 uint16_t addrlen, 925 uint16_t addrlen,
934 void **buf, 926 void **buf,
935 size_t *added) 927 size_t *added)
936{ 928{
937 struct sockaddr_storage socket_address; 929 struct sockaddr_storage socket_address;
938 char *address; 930 char *address;
@@ -946,82 +938,84 @@ udp_string_to_address (void *cls,
946 optionstr = NULL; 938 optionstr = NULL;
947 939
948 if ((NULL == addr) || (0 == addrlen)) 940 if ((NULL == addr) || (0 == addrlen))
949 { 941 {
950 GNUNET_break (0); 942 GNUNET_break(0);
951 return GNUNET_SYSERR; 943 return GNUNET_SYSERR;
952 } 944 }
953 if ('\0' != addr[addrlen - 1]) 945 if ('\0' != addr[addrlen - 1])
954 { 946 {
955 GNUNET_break (0); 947 GNUNET_break(0);
956 return GNUNET_SYSERR; 948 return GNUNET_SYSERR;
957 } 949 }
958 if (strlen (addr) != addrlen - 1) 950 if (strlen(addr) != addrlen - 1)
959 { 951 {
960 GNUNET_break (0); 952 GNUNET_break(0);
961 return GNUNET_SYSERR; 953 return GNUNET_SYSERR;
962 } 954 }
963 plugin = GNUNET_strdup (addr); 955 plugin = GNUNET_strdup(addr);
964 optionstr = strchr (plugin, '.'); 956 optionstr = strchr(plugin, '.');
965 if (NULL == optionstr) 957 if (NULL == optionstr)
966 { 958 {
967 GNUNET_break (0); 959 GNUNET_break(0);
968 GNUNET_free (plugin); 960 GNUNET_free(plugin);
969 return GNUNET_SYSERR; 961 return GNUNET_SYSERR;
970 } 962 }
971 optionstr[0] = '\0'; 963 optionstr[0] = '\0';
972 optionstr++; 964 optionstr++;
973 options = atol (optionstr); 965 options = atol(optionstr);
974 address = strchr (optionstr, '.'); 966 address = strchr(optionstr, '.');
975 if (NULL == address) 967 if (NULL == address)
976 { 968 {
977 GNUNET_break (0); 969 GNUNET_break(0);
978 GNUNET_free (plugin); 970 GNUNET_free(plugin);
979 return GNUNET_SYSERR; 971 return GNUNET_SYSERR;
980 } 972 }
981 address[0] = '\0'; 973 address[0] = '\0';
982 address++; 974 address++;
983 975
984 if (GNUNET_OK != 976 if (GNUNET_OK !=
985 GNUNET_STRINGS_to_address_ip (address, strlen (address), &socket_address)) 977 GNUNET_STRINGS_to_address_ip(address, strlen(address), &socket_address))
986 { 978 {
987 GNUNET_break (0); 979 GNUNET_break(0);
988 GNUNET_free (plugin); 980 GNUNET_free(plugin);
989 return GNUNET_SYSERR; 981 return GNUNET_SYSERR;
990 } 982 }
991 GNUNET_free (plugin); 983 GNUNET_free(plugin);
992 984
993 switch (socket_address.ss_family) 985 switch (socket_address.ss_family)
994 { 986 {
995 case AF_INET: { 987 case AF_INET: {
996 struct IPv4UdpAddress *u4; 988 struct IPv4UdpAddress *u4;
997 const struct sockaddr_in *in4 = 989 const struct sockaddr_in *in4 =
998 (const struct sockaddr_in *) &socket_address; 990 (const struct sockaddr_in *)&socket_address;
999 991
1000 u4 = GNUNET_new (struct IPv4UdpAddress); 992 u4 = GNUNET_new(struct IPv4UdpAddress);
1001 u4->options = htonl (options); 993 u4->options = htonl(options);
1002 u4->ipv4_addr = in4->sin_addr.s_addr; 994 u4->ipv4_addr = in4->sin_addr.s_addr;
1003 u4->u4_port = in4->sin_port; 995 u4->u4_port = in4->sin_port;
1004 *buf = u4; 996 *buf = u4;
1005 *added = sizeof (struct IPv4UdpAddress); 997 *added = sizeof(struct IPv4UdpAddress);
1006 return GNUNET_OK; 998 return GNUNET_OK;
1007 } 999 }
1008 case AF_INET6: { 1000
1009 struct IPv6UdpAddress *u6; 1001 case AF_INET6: {
1010 const struct sockaddr_in6 *in6 = 1002 struct IPv6UdpAddress *u6;
1011 (const struct sockaddr_in6 *) &socket_address; 1003 const struct sockaddr_in6 *in6 =
1012 1004 (const struct sockaddr_in6 *)&socket_address;
1013 u6 = GNUNET_new (struct IPv6UdpAddress); 1005
1014 u6->options = htonl (options); 1006 u6 = GNUNET_new(struct IPv6UdpAddress);
1015 u6->ipv6_addr = in6->sin6_addr; 1007 u6->options = htonl(options);
1016 u6->u6_port = in6->sin6_port; 1008 u6->ipv6_addr = in6->sin6_addr;
1017 *buf = u6; 1009 u6->u6_port = in6->sin6_port;
1018 *added = sizeof (struct IPv6UdpAddress); 1010 *buf = u6;
1019 return GNUNET_OK; 1011 *added = sizeof(struct IPv6UdpAddress);
1020 } 1012 return GNUNET_OK;
1021 default: 1013 }
1022 GNUNET_break (0); 1014
1023 return GNUNET_SYSERR; 1015 default:
1024 } 1016 GNUNET_break(0);
1017 return GNUNET_SYSERR;
1018 }
1025} 1019}
1026 1020
1027 1021
@@ -1032,39 +1026,39 @@ udp_string_to_address (void *cls,
1032 * @param hostname result from DNS resolver 1026 * @param hostname result from DNS resolver
1033 */ 1027 */
1034static void 1028static void
1035append_port (void *cls, const char *hostname) 1029append_port(void *cls, const char *hostname)
1036{ 1030{
1037 struct PrettyPrinterContext *ppc = cls; 1031 struct PrettyPrinterContext *ppc = cls;
1038 struct Plugin *plugin = ppc->plugin; 1032 struct Plugin *plugin = ppc->plugin;
1039 char *ret; 1033 char *ret;
1040 1034
1041 if (NULL == hostname) 1035 if (NULL == hostname)
1042 { 1036 {
1043 /* Final call, done */ 1037 /* Final call, done */
1044 GNUNET_CONTAINER_DLL_remove (plugin->ppc_dll_head, 1038 GNUNET_CONTAINER_DLL_remove(plugin->ppc_dll_head,
1045 plugin->ppc_dll_tail, 1039 plugin->ppc_dll_tail,
1046 ppc); 1040 ppc);
1047 ppc->resolver_handle = NULL; 1041 ppc->resolver_handle = NULL;
1048 ppc->asc (ppc->asc_cls, NULL, GNUNET_OK); 1042 ppc->asc(ppc->asc_cls, NULL, GNUNET_OK);
1049 GNUNET_free (ppc); 1043 GNUNET_free(ppc);
1050 return; 1044 return;
1051 } 1045 }
1052 if (GNUNET_YES == ppc->ipv6) 1046 if (GNUNET_YES == ppc->ipv6)
1053 GNUNET_asprintf (&ret, 1047 GNUNET_asprintf(&ret,
1054 "%s.%u.[%s]:%d", 1048 "%s.%u.[%s]:%d",
1055 PLUGIN_NAME, 1049 PLUGIN_NAME,
1056 ppc->options, 1050 ppc->options,
1057 hostname, 1051 hostname,
1058 ppc->port); 1052 ppc->port);
1059 else 1053 else
1060 GNUNET_asprintf (&ret, 1054 GNUNET_asprintf(&ret,
1061 "%s.%u.%s:%d", 1055 "%s.%u.%s:%d",
1062 PLUGIN_NAME, 1056 PLUGIN_NAME,
1063 ppc->options, 1057 ppc->options,
1064 hostname, 1058 hostname,
1065 ppc->port); 1059 ppc->port);
1066 ppc->asc (ppc->asc_cls, ret, GNUNET_OK); 1060 ppc->asc(ppc->asc_cls, ret, GNUNET_OK);
1067 GNUNET_free (ret); 1061 GNUNET_free(ret);
1068} 1062}
1069 1063
1070 1064
@@ -1083,14 +1077,14 @@ append_port (void *cls, const char *hostname)
1083 * @param asc_cls closure for @a asc 1077 * @param asc_cls closure for @a asc
1084 */ 1078 */
1085static void 1079static void
1086udp_plugin_address_pretty_printer (void *cls, 1080udp_plugin_address_pretty_printer(void *cls,
1087 const char *type, 1081 const char *type,
1088 const void *addr, 1082 const void *addr,
1089 size_t addrlen, 1083 size_t addrlen,
1090 int numeric, 1084 int numeric,
1091 struct GNUNET_TIME_Relative timeout, 1085 struct GNUNET_TIME_Relative timeout,
1092 GNUNET_TRANSPORT_AddressStringCallback asc, 1086 GNUNET_TRANSPORT_AddressStringCallback asc,
1093 void *asc_cls) 1087 void *asc_cls)
1094{ 1088{
1095 struct Plugin *plugin = cls; 1089 struct Plugin *plugin = cls;
1096 struct PrettyPrinterContext *ppc; 1090 struct PrettyPrinterContext *ppc;
@@ -1103,61 +1097,61 @@ udp_plugin_address_pretty_printer (void *cls,
1103 uint16_t port; 1097 uint16_t port;
1104 uint32_t options; 1098 uint32_t options;
1105 1099
1106 if (addrlen == sizeof (struct IPv6UdpAddress)) 1100 if (addrlen == sizeof(struct IPv6UdpAddress))
1107 { 1101 {
1108 u6 = addr; 1102 u6 = addr;
1109 memset (&a6, 0, sizeof (a6)); 1103 memset(&a6, 0, sizeof(a6));
1110 a6.sin6_family = AF_INET6; 1104 a6.sin6_family = AF_INET6;
1111#if HAVE_SOCKADDR_IN_SIN_LEN 1105#if HAVE_SOCKADDR_IN_SIN_LEN
1112 a6.sin6_len = sizeof (a6); 1106 a6.sin6_len = sizeof(a6);
1113#endif 1107#endif
1114 a6.sin6_port = u6->u6_port; 1108 a6.sin6_port = u6->u6_port;
1115 a6.sin6_addr = u6->ipv6_addr; 1109 a6.sin6_addr = u6->ipv6_addr;
1116 port = ntohs (u6->u6_port); 1110 port = ntohs(u6->u6_port);
1117 options = ntohl (u6->options); 1111 options = ntohl(u6->options);
1118 sb = (const struct sockaddr *) &a6; 1112 sb = (const struct sockaddr *)&a6;
1119 sbs = sizeof (a6); 1113 sbs = sizeof(a6);
1120 } 1114 }
1121 else if (addrlen == sizeof (struct IPv4UdpAddress)) 1115 else if (addrlen == sizeof(struct IPv4UdpAddress))
1122 { 1116 {
1123 u4 = addr; 1117 u4 = addr;
1124 memset (&a4, 0, sizeof (a4)); 1118 memset(&a4, 0, sizeof(a4));
1125 a4.sin_family = AF_INET; 1119 a4.sin_family = AF_INET;
1126#if HAVE_SOCKADDR_IN_SIN_LEN 1120#if HAVE_SOCKADDR_IN_SIN_LEN
1127 a4.sin_len = sizeof (a4); 1121 a4.sin_len = sizeof(a4);
1128#endif 1122#endif
1129 a4.sin_port = u4->u4_port; 1123 a4.sin_port = u4->u4_port;
1130 a4.sin_addr.s_addr = u4->ipv4_addr; 1124 a4.sin_addr.s_addr = u4->ipv4_addr;
1131 port = ntohs (u4->u4_port); 1125 port = ntohs(u4->u4_port);
1132 options = ntohl (u4->options); 1126 options = ntohl(u4->options);
1133 sb = (const struct sockaddr *) &a4; 1127 sb = (const struct sockaddr *)&a4;
1134 sbs = sizeof (a4); 1128 sbs = sizeof(a4);
1135 } 1129 }
1136 else 1130 else
1137 { 1131 {
1138 /* invalid address */ 1132 /* invalid address */
1139 GNUNET_break_op (0); 1133 GNUNET_break_op(0);
1140 asc (asc_cls, NULL, GNUNET_SYSERR); 1134 asc(asc_cls, NULL, GNUNET_SYSERR);
1141 asc (asc_cls, NULL, GNUNET_OK); 1135 asc(asc_cls, NULL, GNUNET_OK);
1142 return; 1136 return;
1143 } 1137 }
1144 ppc = GNUNET_new (struct PrettyPrinterContext); 1138 ppc = GNUNET_new(struct PrettyPrinterContext);
1145 ppc->plugin = plugin; 1139 ppc->plugin = plugin;
1146 ppc->asc = asc; 1140 ppc->asc = asc;
1147 ppc->asc_cls = asc_cls; 1141 ppc->asc_cls = asc_cls;
1148 ppc->port = port; 1142 ppc->port = port;
1149 ppc->options = options; 1143 ppc->options = options;
1150 if (addrlen == sizeof (struct IPv6UdpAddress)) 1144 if (addrlen == sizeof(struct IPv6UdpAddress))
1151 ppc->ipv6 = GNUNET_YES; 1145 ppc->ipv6 = GNUNET_YES;
1152 else 1146 else
1153 ppc->ipv6 = GNUNET_NO; 1147 ppc->ipv6 = GNUNET_NO;
1154 GNUNET_CONTAINER_DLL_insert (plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc); 1148 GNUNET_CONTAINER_DLL_insert(plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc);
1155 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, 1149 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get(sb,
1156 sbs, 1150 sbs,
1157 ! numeric, 1151 !numeric,
1158 timeout, 1152 timeout,
1159 &append_port, 1153 &append_port,
1160 ppc); 1154 ppc);
1161} 1155}
1162 1156
1163 1157
@@ -1171,7 +1165,7 @@ udp_plugin_address_pretty_printer (void *cls,
1171 * @return #GNUNET_OK if port is either our open or advertised port 1165 * @return #GNUNET_OK if port is either our open or advertised port
1172 */ 1166 */
1173static int 1167static int
1174check_port (const struct Plugin *plugin, uint16_t in_port) 1168check_port(const struct Plugin *plugin, uint16_t in_port)
1175{ 1169{
1176 if ((plugin->port == in_port) || (plugin->aport == in_port)) 1170 if ((plugin->port == in_port) || (plugin->aport == in_port))
1177 return GNUNET_OK; 1171 return GNUNET_OK;
@@ -1195,56 +1189,56 @@ check_port (const struct Plugin *plugin, uint16_t in_port)
1195 * and transport, #GNUNET_SYSERR if not 1189 * and transport, #GNUNET_SYSERR if not
1196 */ 1190 */
1197static int 1191static int
1198udp_plugin_check_address (void *cls, const void *addr, size_t addrlen) 1192udp_plugin_check_address(void *cls, const void *addr, size_t addrlen)
1199{ 1193{
1200 struct Plugin *plugin = cls; 1194 struct Plugin *plugin = cls;
1201 const struct IPv4UdpAddress *v4; 1195 const struct IPv4UdpAddress *v4;
1202 const struct IPv6UdpAddress *v6; 1196 const struct IPv6UdpAddress *v6;
1203 1197
1204 if (sizeof (struct IPv4UdpAddress) == addrlen) 1198 if (sizeof(struct IPv4UdpAddress) == addrlen)
1205 { 1199 {
1206 struct sockaddr_in s4; 1200 struct sockaddr_in s4;
1207 1201
1208 v4 = (const struct IPv4UdpAddress *) addr; 1202 v4 = (const struct IPv4UdpAddress *)addr;
1209 if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port))) 1203 if (GNUNET_OK != check_port(plugin, ntohs(v4->u4_port)))
1210 return GNUNET_SYSERR; 1204 return GNUNET_SYSERR;
1211 memset (&s4, 0, sizeof (s4)); 1205 memset(&s4, 0, sizeof(s4));
1212 s4.sin_family = AF_INET; 1206 s4.sin_family = AF_INET;
1213#if HAVE_SOCKADDR_IN_SIN_LEN 1207#if HAVE_SOCKADDR_IN_SIN_LEN
1214 s4.sin_len = sizeof (s4); 1208 s4.sin_len = sizeof(s4);
1215#endif 1209#endif
1216 s4.sin_port = v4->u4_port; 1210 s4.sin_port = v4->u4_port;
1217 s4.sin_addr.s_addr = v4->ipv4_addr; 1211 s4.sin_addr.s_addr = v4->ipv4_addr;
1218 1212
1219 if (GNUNET_OK != 1213 if (GNUNET_OK !=
1220 GNUNET_NAT_test_address (plugin->nat, &s4, sizeof (struct sockaddr_in))) 1214 GNUNET_NAT_test_address(plugin->nat, &s4, sizeof(struct sockaddr_in)))
1221 return GNUNET_SYSERR; 1215 return GNUNET_SYSERR;
1222 } 1216 }
1223 else if (sizeof (struct IPv6UdpAddress) == addrlen) 1217 else if (sizeof(struct IPv6UdpAddress) == addrlen)
1224 { 1218 {
1225 struct sockaddr_in6 s6; 1219 struct sockaddr_in6 s6;
1226 1220
1227 v6 = (const struct IPv6UdpAddress *) addr; 1221 v6 = (const struct IPv6UdpAddress *)addr;
1228 if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) 1222 if (IN6_IS_ADDR_LINKLOCAL(&v6->ipv6_addr))
1229 return GNUNET_OK; /* plausible, if unlikely... */ 1223 return GNUNET_OK; /* plausible, if unlikely... */
1230 memset (&s6, 0, sizeof (s6)); 1224 memset(&s6, 0, sizeof(s6));
1231 s6.sin6_family = AF_INET6; 1225 s6.sin6_family = AF_INET6;
1232#if HAVE_SOCKADDR_IN_SIN_LEN 1226#if HAVE_SOCKADDR_IN_SIN_LEN
1233 s6.sin6_len = sizeof (s6); 1227 s6.sin6_len = sizeof(s6);
1234#endif 1228#endif
1235 s6.sin6_port = v6->u6_port; 1229 s6.sin6_port = v6->u6_port;
1236 s6.sin6_addr = v6->ipv6_addr; 1230 s6.sin6_addr = v6->ipv6_addr;
1237 1231
1238 if (GNUNET_OK != GNUNET_NAT_test_address (plugin->nat, 1232 if (GNUNET_OK != GNUNET_NAT_test_address(plugin->nat,
1239 &s6, 1233 &s6,
1240 sizeof (struct sockaddr_in6))) 1234 sizeof(struct sockaddr_in6)))
1241 return GNUNET_SYSERR; 1235 return GNUNET_SYSERR;
1242 } 1236 }
1243 else 1237 else
1244 { 1238 {
1245 GNUNET_break_op (0); 1239 GNUNET_break_op(0);
1246 return GNUNET_SYSERR; 1240 return GNUNET_SYSERR;
1247 } 1241 }
1248 return GNUNET_OK; 1242 return GNUNET_OK;
1249} 1243}
1250 1244
@@ -1262,12 +1256,12 @@ udp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
1262 * @param addrlen actual length of the @a addr 1256 * @param addrlen actual length of the @a addr
1263 */ 1257 */
1264static void 1258static void
1265udp_nat_port_map_callback (void *cls, 1259udp_nat_port_map_callback(void *cls,
1266 void **app_ctx, 1260 void **app_ctx,
1267 int add_remove, 1261 int add_remove,
1268 enum GNUNET_NAT_AddressClass ac, 1262 enum GNUNET_NAT_AddressClass ac,
1269 const struct sockaddr *addr, 1263 const struct sockaddr *addr,
1270 socklen_t addrlen) 1264 socklen_t addrlen)
1271{ 1265{
1272 struct Plugin *plugin = cls; 1266 struct Plugin *plugin = cls;
1273 struct GNUNET_HELLO_Address *address; 1267 struct GNUNET_HELLO_Address *address;
@@ -1276,57 +1270,59 @@ udp_nat_port_map_callback (void *cls,
1276 void *arg; 1270 void *arg;
1277 size_t args; 1271 size_t args;
1278 1272
1279 (void) app_ctx; 1273 (void)app_ctx;
1280 LOG (GNUNET_ERROR_TYPE_DEBUG, 1274 LOG(GNUNET_ERROR_TYPE_DEBUG,
1281 (GNUNET_YES == add_remove) ? "NAT notification to add address `%s'\n" 1275 (GNUNET_YES == add_remove) ? "NAT notification to add address `%s'\n"
1282 : "NAT notification to remove address `%s'\n", 1276 : "NAT notification to remove address `%s'\n",
1283 GNUNET_a2s (addr, addrlen)); 1277 GNUNET_a2s(addr, addrlen));
1284 /* convert 'address' to our internal format */ 1278 /* convert 'address' to our internal format */
1285 switch (addr->sa_family) 1279 switch (addr->sa_family)
1286 { 1280 {
1287 case AF_INET: { 1281 case AF_INET: {
1288 const struct sockaddr_in *i4; 1282 const struct sockaddr_in *i4;
1289 1283
1290 GNUNET_assert (sizeof (struct sockaddr_in) == addrlen); 1284 GNUNET_assert(sizeof(struct sockaddr_in) == addrlen);
1291 i4 = (const struct sockaddr_in *) addr; 1285 i4 = (const struct sockaddr_in *)addr;
1292 if (0 == ntohs (i4->sin_port)) 1286 if (0 == ntohs(i4->sin_port))
1293 return; /* Port = 0 means unmapped, ignore these for UDP. */ 1287 return; /* Port = 0 means unmapped, ignore these for UDP. */
1294 memset (&u4, 0, sizeof (u4)); 1288 memset(&u4, 0, sizeof(u4));
1295 u4.options = htonl (plugin->myoptions); 1289 u4.options = htonl(plugin->myoptions);
1296 u4.ipv4_addr = i4->sin_addr.s_addr; 1290 u4.ipv4_addr = i4->sin_addr.s_addr;
1297 u4.u4_port = i4->sin_port; 1291 u4.u4_port = i4->sin_port;
1298 arg = &u4; 1292 arg = &u4;
1299 args = sizeof (struct IPv4UdpAddress); 1293 args = sizeof(struct IPv4UdpAddress);
1300 break; 1294 break;
1301 } 1295 }
1302 case AF_INET6: { 1296
1303 const struct sockaddr_in6 *i6; 1297 case AF_INET6: {
1304 1298 const struct sockaddr_in6 *i6;
1305 GNUNET_assert (sizeof (struct sockaddr_in6) == addrlen); 1299
1306 i6 = (const struct sockaddr_in6 *) addr; 1300 GNUNET_assert(sizeof(struct sockaddr_in6) == addrlen);
1307 if (0 == ntohs (i6->sin6_port)) 1301 i6 = (const struct sockaddr_in6 *)addr;
1308 return; /* Port = 0 means unmapped, ignore these for UDP. */ 1302 if (0 == ntohs(i6->sin6_port))
1309 memset (&u6, 0, sizeof (u6)); 1303 return; /* Port = 0 means unmapped, ignore these for UDP. */
1310 u6.options = htonl (plugin->myoptions); 1304 memset(&u6, 0, sizeof(u6));
1311 u6.ipv6_addr = i6->sin6_addr; 1305 u6.options = htonl(plugin->myoptions);
1312 u6.u6_port = i6->sin6_port; 1306 u6.ipv6_addr = i6->sin6_addr;
1313 arg = &u6; 1307 u6.u6_port = i6->sin6_port;
1314 args = sizeof (struct IPv6UdpAddress); 1308 arg = &u6;
1315 break; 1309 args = sizeof(struct IPv6UdpAddress);
1316 } 1310 break;
1317 default: 1311 }
1318 GNUNET_break (0); 1312
1319 return; 1313 default:
1320 } 1314 GNUNET_break(0);
1315 return;
1316 }
1321 /* modify our published address list */ 1317 /* modify our published address list */
1322 /* TODO: use 'ac' here in the future... */ 1318 /* TODO: use 'ac' here in the future... */
1323 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, 1319 address = GNUNET_HELLO_address_allocate(plugin->env->my_identity,
1324 PLUGIN_NAME, 1320 PLUGIN_NAME,
1325 arg, 1321 arg,
1326 args, 1322 args,
1327 GNUNET_HELLO_ADDRESS_INFO_NONE); 1323 GNUNET_HELLO_ADDRESS_INFO_NONE);
1328 plugin->env->notify_address (plugin->env->cls, add_remove, address); 1324 plugin->env->notify_address(plugin->env->cls, add_remove, address);
1329 GNUNET_HELLO_address_free (address); 1325 GNUNET_HELLO_address_free(address);
1330} 1326}
1331 1327
1332 1328
@@ -1336,8 +1332,7 @@ udp_nat_port_map_callback (void *cls,
1336/** 1332/**
1337 * Closure for #session_cmp_it(). 1333 * Closure for #session_cmp_it().
1338 */ 1334 */
1339struct GNUNET_ATS_SessionCompareContext 1335struct GNUNET_ATS_SessionCompareContext {
1340{
1341 /** 1336 /**
1342 * Set to session matching the address. 1337 * Set to session matching the address.
1343 */ 1338 */
@@ -1359,17 +1354,17 @@ struct GNUNET_ATS_SessionCompareContext
1359 * @return #GNUNET_NO if we found the session, #GNUNET_OK if not 1354 * @return #GNUNET_NO if we found the session, #GNUNET_OK if not
1360 */ 1355 */
1361static int 1356static int
1362session_cmp_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) 1357session_cmp_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
1363{ 1358{
1364 struct GNUNET_ATS_SessionCompareContext *cctx = cls; 1359 struct GNUNET_ATS_SessionCompareContext *cctx = cls;
1365 struct GNUNET_ATS_Session *s = value; 1360 struct GNUNET_ATS_Session *s = value;
1366 1361
1367 if (0 == GNUNET_HELLO_address_cmp (s->address, cctx->address)) 1362 if (0 == GNUNET_HELLO_address_cmp(s->address, cctx->address))
1368 { 1363 {
1369 GNUNET_assert (GNUNET_NO == s->in_destroy); 1364 GNUNET_assert(GNUNET_NO == s->in_destroy);
1370 cctx->res = s; 1365 cctx->res = s;
1371 return GNUNET_NO; 1366 return GNUNET_NO;
1372 } 1367 }
1373 return GNUNET_OK; 1368 return GNUNET_OK;
1374} 1369}
1375 1370
@@ -1384,8 +1379,8 @@ session_cmp_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
1384 * @return the session if it exists, or NULL if it is not found 1379 * @return the session if it exists, or NULL if it is not found
1385 */ 1380 */
1386static struct GNUNET_ATS_Session * 1381static struct GNUNET_ATS_Session *
1387udp_plugin_lookup_session (void *cls, 1382udp_plugin_lookup_session(void *cls,
1388 const struct GNUNET_HELLO_Address *address) 1383 const struct GNUNET_HELLO_Address *address)
1389{ 1384{
1390 struct Plugin *plugin = cls; 1385 struct Plugin *plugin = cls;
1391 const struct IPv6UdpAddress *udp_a6; 1386 const struct IPv6UdpAddress *udp_a6;
@@ -1393,54 +1388,54 @@ udp_plugin_lookup_session (void *cls,
1393 struct GNUNET_ATS_SessionCompareContext cctx; 1388 struct GNUNET_ATS_SessionCompareContext cctx;
1394 1389
1395 if (NULL == address->address) 1390 if (NULL == address->address)
1396 {
1397 GNUNET_break (0);
1398 return NULL;
1399 }
1400 if (sizeof (struct IPv4UdpAddress) == address->address_length)
1401 {
1402 if (NULL == plugin->sockv4)
1403 return NULL;
1404 udp_a4 = (const struct IPv4UdpAddress *) address->address;
1405 if (0 == udp_a4->u4_port)
1406 { 1391 {
1407 GNUNET_break (0); 1392 GNUNET_break(0);
1408 return NULL; 1393 return NULL;
1409 } 1394 }
1410 } 1395 if (sizeof(struct IPv4UdpAddress) == address->address_length)
1411 else if (sizeof (struct IPv6UdpAddress) == address->address_length)
1412 {
1413 if (NULL == plugin->sockv6)
1414 return NULL;
1415 udp_a6 = (const struct IPv6UdpAddress *) address->address;
1416 if (0 == udp_a6->u6_port)
1417 { 1396 {
1418 GNUNET_break (0); 1397 if (NULL == plugin->sockv4)
1419 return NULL; 1398 return NULL;
1399 udp_a4 = (const struct IPv4UdpAddress *)address->address;
1400 if (0 == udp_a4->u4_port)
1401 {
1402 GNUNET_break(0);
1403 return NULL;
1404 }
1405 }
1406 else if (sizeof(struct IPv6UdpAddress) == address->address_length)
1407 {
1408 if (NULL == plugin->sockv6)
1409 return NULL;
1410 udp_a6 = (const struct IPv6UdpAddress *)address->address;
1411 if (0 == udp_a6->u6_port)
1412 {
1413 GNUNET_break(0);
1414 return NULL;
1415 }
1420 } 1416 }
1421 }
1422 else 1417 else
1423 { 1418 {
1424 GNUNET_break (0); 1419 GNUNET_break(0);
1425 return NULL; 1420 return NULL;
1426 } 1421 }
1427 1422
1428 /* check if session already exists */ 1423 /* check if session already exists */
1429 cctx.address = address; 1424 cctx.address = address;
1430 cctx.res = NULL; 1425 cctx.res = NULL;
1431 LOG (GNUNET_ERROR_TYPE_DEBUG, 1426 LOG(GNUNET_ERROR_TYPE_DEBUG,
1432 "Looking for existing session for peer `%s' with address `%s'\n", 1427 "Looking for existing session for peer `%s' with address `%s'\n",
1433 GNUNET_i2s (&address->peer), 1428 GNUNET_i2s(&address->peer),
1434 udp_address_to_string (plugin, 1429 udp_address_to_string(plugin,
1435 address->address, 1430 address->address,
1436 address->address_length)); 1431 address->address_length));
1437 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, 1432 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions,
1438 &address->peer, 1433 &address->peer,
1439 &session_cmp_it, 1434 &session_cmp_it,
1440 &cctx); 1435 &cctx);
1441 if (NULL == cctx.res) 1436 if (NULL == cctx.res)
1442 return NULL; 1437 return NULL;
1443 LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p\n", cctx.res); 1438 LOG(GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p\n", cctx.res);
1444 return cctx.res; 1439 return cctx.res;
1445} 1440}
1446 1441
@@ -1454,12 +1449,12 @@ udp_plugin_lookup_session (void *cls,
1454 * @param s session to reschedule timeout activity for 1449 * @param s session to reschedule timeout activity for
1455 */ 1450 */
1456static void 1451static void
1457reschedule_session_timeout (struct GNUNET_ATS_Session *s) 1452reschedule_session_timeout(struct GNUNET_ATS_Session *s)
1458{ 1453{
1459 if (GNUNET_YES == s->in_destroy) 1454 if (GNUNET_YES == s->in_destroy)
1460 return; 1455 return;
1461 GNUNET_assert (NULL != s->timeout_task); 1456 GNUNET_assert(NULL != s->timeout_task);
1462 s->timeout = GNUNET_TIME_relative_to_absolute (UDP_SESSION_TIME_OUT); 1457 s->timeout = GNUNET_TIME_relative_to_absolute(UDP_SESSION_TIME_OUT);
1463} 1458}
1464 1459
1465 1460
@@ -1473,22 +1468,22 @@ reschedule_session_timeout (struct GNUNET_ATS_Session *s)
1473 * @param session which session is being updated 1468 * @param session which session is being updated
1474 */ 1469 */
1475static void 1470static void
1476udp_plugin_update_session_timeout (void *cls, 1471udp_plugin_update_session_timeout(void *cls,
1477 const struct GNUNET_PeerIdentity *peer, 1472 const struct GNUNET_PeerIdentity *peer,
1478 struct GNUNET_ATS_Session *session) 1473 struct GNUNET_ATS_Session *session)
1479{ 1474{
1480 struct Plugin *plugin = cls; 1475 struct Plugin *plugin = cls;
1481 1476
1482 if (GNUNET_YES != 1477 if (GNUNET_YES !=
1483 GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessions, 1478 GNUNET_CONTAINER_multipeermap_contains_value(plugin->sessions,
1484 peer, 1479 peer,
1485 session)) 1480 session))
1486 { 1481 {
1487 GNUNET_break (0); 1482 GNUNET_break(0);
1488 return; 1483 return;
1489 } 1484 }
1490 /* Reschedule session timeout */ 1485 /* Reschedule session timeout */
1491 reschedule_session_timeout (session); 1486 reschedule_session_timeout(session);
1492} 1487}
1493 1488
1494 1489
@@ -1503,47 +1498,47 @@ udp_plugin_update_session_timeout (void *cls,
1503 * @param udpw message wrapper to dequeue 1498 * @param udpw message wrapper to dequeue
1504 */ 1499 */
1505static void 1500static void
1506dequeue (struct Plugin *plugin, struct UDP_MessageWrapper *udpw) 1501dequeue(struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
1507{ 1502{
1508 struct GNUNET_ATS_Session *session = udpw->session; 1503 struct GNUNET_ATS_Session *session = udpw->session;
1509 1504
1510 if (plugin->bytes_in_buffer < udpw->msg_size) 1505 if (plugin->bytes_in_buffer < udpw->msg_size)
1511 { 1506 {
1512 GNUNET_break (0); 1507 GNUNET_break(0);
1513 } 1508 }
1514 else 1509 else
1515 { 1510 {
1516 GNUNET_STATISTICS_update (plugin->env->stats, 1511 GNUNET_STATISTICS_update(plugin->env->stats,
1517 "# UDP, total bytes in send buffers", 1512 "# UDP, total bytes in send buffers",
1518 -(long long) udpw->msg_size, 1513 -(long long)udpw->msg_size,
1519 GNUNET_NO); 1514 GNUNET_NO);
1520 plugin->bytes_in_buffer -= udpw->msg_size; 1515 plugin->bytes_in_buffer -= udpw->msg_size;
1521 } 1516 }
1522 GNUNET_STATISTICS_update (plugin->env->stats, 1517 GNUNET_STATISTICS_update(plugin->env->stats,
1523 "# UDP, total messages in send buffers", 1518 "# UDP, total messages in send buffers",
1524 -1, 1519 -1,
1525 GNUNET_NO); 1520 GNUNET_NO);
1526 if (sizeof (struct IPv4UdpAddress) == udpw->session->address->address_length) 1521 if (sizeof(struct IPv4UdpAddress) == udpw->session->address->address_length)
1527 { 1522 {
1528 GNUNET_CONTAINER_DLL_remove (plugin->ipv4_queue_head, 1523 GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head,
1529 plugin->ipv4_queue_tail, 1524 plugin->ipv4_queue_tail,
1530 udpw); 1525 udpw);
1531 } 1526 }
1532 else if (sizeof (struct IPv6UdpAddress) == 1527 else if (sizeof(struct IPv6UdpAddress) ==
1533 udpw->session->address->address_length) 1528 udpw->session->address->address_length)
1534 { 1529 {
1535 GNUNET_CONTAINER_DLL_remove (plugin->ipv6_queue_head, 1530 GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head,
1536 plugin->ipv6_queue_tail, 1531 plugin->ipv6_queue_tail,
1537 udpw); 1532 udpw);
1538 } 1533 }
1539 else 1534 else
1540 { 1535 {
1541 GNUNET_break (0); 1536 GNUNET_break(0);
1542 return; 1537 return;
1543 } 1538 }
1544 GNUNET_assert (session->msgs_in_queue > 0); 1539 GNUNET_assert(session->msgs_in_queue > 0);
1545 session->msgs_in_queue--; 1540 session->msgs_in_queue--;
1546 GNUNET_assert (session->bytes_in_queue >= udpw->msg_size); 1541 GNUNET_assert(session->bytes_in_queue >= udpw->msg_size);
1547 session->bytes_in_queue -= udpw->msg_size; 1542 session->bytes_in_queue -= udpw->msg_size;
1548} 1543}
1549 1544
@@ -1555,56 +1550,56 @@ dequeue (struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
1555 * @param udpw message wrapper to queue 1550 * @param udpw message wrapper to queue
1556 */ 1551 */
1557static void 1552static void
1558enqueue (struct Plugin *plugin, struct UDP_MessageWrapper *udpw) 1553enqueue(struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
1559{ 1554{
1560 struct GNUNET_ATS_Session *session = udpw->session; 1555 struct GNUNET_ATS_Session *session = udpw->session;
1561 1556
1562 if (GNUNET_YES == session->in_destroy) 1557 if (GNUNET_YES == session->in_destroy)
1563 { 1558 {
1564 GNUNET_break (0); 1559 GNUNET_break(0);
1565 GNUNET_free (udpw); 1560 GNUNET_free(udpw);
1566 return; 1561 return;
1567 } 1562 }
1568 if (plugin->bytes_in_buffer > INT64_MAX - udpw->msg_size) 1563 if (plugin->bytes_in_buffer > INT64_MAX - udpw->msg_size)
1569 { 1564 {
1570 GNUNET_break (0); 1565 GNUNET_break(0);
1571 } 1566 }
1572 else 1567 else
1573 { 1568 {
1574 GNUNET_STATISTICS_update (plugin->env->stats, 1569 GNUNET_STATISTICS_update(plugin->env->stats,
1575 "# UDP, total bytes in send buffers", 1570 "# UDP, total bytes in send buffers",
1576 udpw->msg_size, 1571 udpw->msg_size,
1577 GNUNET_NO); 1572 GNUNET_NO);
1578 plugin->bytes_in_buffer += udpw->msg_size; 1573 plugin->bytes_in_buffer += udpw->msg_size;
1579 } 1574 }
1580 GNUNET_STATISTICS_update (plugin->env->stats, 1575 GNUNET_STATISTICS_update(plugin->env->stats,
1581 "# UDP, total messages in send buffers", 1576 "# UDP, total messages in send buffers",
1582 1, 1577 1,
1583 GNUNET_NO); 1578 GNUNET_NO);
1584 if (sizeof (struct IPv4UdpAddress) == udpw->session->address->address_length) 1579 if (sizeof(struct IPv4UdpAddress) == udpw->session->address->address_length)
1585 { 1580 {
1586 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_queue_head, 1581 GNUNET_CONTAINER_DLL_insert(plugin->ipv4_queue_head,
1587 plugin->ipv4_queue_tail, 1582 plugin->ipv4_queue_tail,
1588 udpw); 1583 udpw);
1589 } 1584 }
1590 else if (sizeof (struct IPv6UdpAddress) == 1585 else if (sizeof(struct IPv6UdpAddress) ==
1591 udpw->session->address->address_length) 1586 udpw->session->address->address_length)
1592 { 1587 {
1593 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_queue_head, 1588 GNUNET_CONTAINER_DLL_insert(plugin->ipv6_queue_head,
1594 plugin->ipv6_queue_tail, 1589 plugin->ipv6_queue_tail,
1595 udpw); 1590 udpw);
1596 } 1591 }
1597 else 1592 else
1598 { 1593 {
1599 GNUNET_break (0); 1594 GNUNET_break(0);
1600 udpw->cont (udpw->cont_cls, 1595 udpw->cont(udpw->cont_cls,
1601 &session->target, 1596 &session->target,
1602 GNUNET_SYSERR, 1597 GNUNET_SYSERR,
1603 udpw->msg_size, 1598 udpw->msg_size,
1604 0); 1599 0);
1605 GNUNET_free (udpw); 1600 GNUNET_free(udpw);
1606 return; 1601 return;
1607 } 1602 }
1608 session->msgs_in_queue++; 1603 session->msgs_in_queue++;
1609 session->bytes_in_queue += udpw->msg_size; 1604 session->bytes_in_queue += udpw->msg_size;
1610} 1605}
@@ -1621,7 +1616,7 @@ enqueue (struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
1621 * #GNUNET_SYSERR if the transmission failed 1616 * #GNUNET_SYSERR if the transmission failed
1622 */ 1617 */
1623static void 1618static void
1624fragmented_message_done (struct UDP_FragmentationContext *frag_ctx, int result) 1619fragmented_message_done(struct UDP_FragmentationContext *frag_ctx, int result)
1625{ 1620{
1626 struct Plugin *plugin = frag_ctx->plugin; 1621 struct Plugin *plugin = frag_ctx->plugin;
1627 struct GNUNET_ATS_Session *s = frag_ctx->session; 1622 struct GNUNET_ATS_Session *s = frag_ctx->session;
@@ -1630,122 +1625,122 @@ fragmented_message_done (struct UDP_FragmentationContext *frag_ctx, int result)
1630 size_t overhead; 1625 size_t overhead;
1631 struct GNUNET_TIME_Relative delay; 1626 struct GNUNET_TIME_Relative delay;
1632 1627
1633 LOG (GNUNET_ERROR_TYPE_DEBUG, 1628 LOG(GNUNET_ERROR_TYPE_DEBUG,
1634 "%p: Fragmented message removed with result %s\n", 1629 "%p: Fragmented message removed with result %s\n",
1635 frag_ctx, 1630 frag_ctx,
1636 (result == GNUNET_SYSERR) ? "FAIL" : "SUCCESS"); 1631 (result == GNUNET_SYSERR) ? "FAIL" : "SUCCESS");
1637 /* Call continuation for fragmented message */ 1632 /* Call continuation for fragmented message */
1638 if (frag_ctx->on_wire_size >= frag_ctx->payload_size) 1633 if (frag_ctx->on_wire_size >= frag_ctx->payload_size)
1639 overhead = frag_ctx->on_wire_size - frag_ctx->payload_size; 1634 overhead = frag_ctx->on_wire_size - frag_ctx->payload_size;
1640 else 1635 else
1641 overhead = frag_ctx->on_wire_size; 1636 overhead = frag_ctx->on_wire_size;
1642 delay = GNUNET_TIME_absolute_get_duration (frag_ctx->start_time); 1637 delay = GNUNET_TIME_absolute_get_duration(frag_ctx->start_time);
1643 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 1638 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
1644 { 1639 {
1645 LOG (GNUNET_ERROR_TYPE_WARNING, 1640 LOG(GNUNET_ERROR_TYPE_WARNING,
1646 "Fragmented message acknowledged after %s (expected at %s)\n", 1641 "Fragmented message acknowledged after %s (expected at %s)\n",
1647 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES), 1642 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES),
1648 GNUNET_STRINGS_absolute_time_to_string (frag_ctx->next_frag_time)); 1643 GNUNET_STRINGS_absolute_time_to_string(frag_ctx->next_frag_time));
1649 } 1644 }
1650 else 1645 else
1651 { 1646 {
1652 LOG (GNUNET_ERROR_TYPE_DEBUG, 1647 LOG(GNUNET_ERROR_TYPE_DEBUG,
1653 "Fragmented message acknowledged after %s (expected at %s)\n", 1648 "Fragmented message acknowledged after %s (expected at %s)\n",
1654 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES), 1649 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES),
1655 GNUNET_STRINGS_absolute_time_to_string (frag_ctx->next_frag_time)); 1650 GNUNET_STRINGS_absolute_time_to_string(frag_ctx->next_frag_time));
1656 } 1651 }
1657 1652
1658 if (NULL != frag_ctx->cont) 1653 if (NULL != frag_ctx->cont)
1659 frag_ctx->cont (frag_ctx->cont_cls, 1654 frag_ctx->cont(frag_ctx->cont_cls,
1660 &s->target, 1655 &s->target,
1661 result, 1656 result,
1662 s->frag_ctx->payload_size, 1657 s->frag_ctx->payload_size,
1663 frag_ctx->on_wire_size); 1658 frag_ctx->on_wire_size);
1664 GNUNET_STATISTICS_update (plugin->env->stats, 1659 GNUNET_STATISTICS_update(plugin->env->stats,
1665 "# UDP, fragmented messages active", 1660 "# UDP, fragmented messages active",
1666 -1, 1661 -1,
1667 GNUNET_NO); 1662 GNUNET_NO);
1668 1663
1669 if (GNUNET_OK == result) 1664 if (GNUNET_OK == result)
1670 { 1665 {
1671 GNUNET_STATISTICS_update (plugin->env->stats, 1666 GNUNET_STATISTICS_update(plugin->env->stats,
1672 "# UDP, fragmented msgs, messages, sent, success", 1667 "# UDP, fragmented msgs, messages, sent, success",
1673 1, 1668 1,
1674 GNUNET_NO); 1669 GNUNET_NO);
1675 GNUNET_STATISTICS_update (plugin->env->stats, 1670 GNUNET_STATISTICS_update(plugin->env->stats,
1676 "# UDP, fragmented msgs, bytes payload, sent, success", 1671 "# UDP, fragmented msgs, bytes payload, sent, success",
1677 s->frag_ctx->payload_size, 1672 s->frag_ctx->payload_size,
1678 GNUNET_NO); 1673 GNUNET_NO);
1679 GNUNET_STATISTICS_update ( 1674 GNUNET_STATISTICS_update(
1680 plugin->env->stats, 1675 plugin->env->stats,
1681 "# UDP, fragmented msgs, bytes overhead, sent, success", 1676 "# UDP, fragmented msgs, bytes overhead, sent, success",
1682 overhead, 1677 overhead,
1683 GNUNET_NO); 1678 GNUNET_NO);
1684 GNUNET_STATISTICS_update (plugin->env->stats, 1679 GNUNET_STATISTICS_update(plugin->env->stats,
1685 "# UDP, total, bytes overhead, sent", 1680 "# UDP, total, bytes overhead, sent",
1686 overhead, 1681 overhead,
1687 GNUNET_NO); 1682 GNUNET_NO);
1688 GNUNET_STATISTICS_update (plugin->env->stats, 1683 GNUNET_STATISTICS_update(plugin->env->stats,
1689 "# UDP, total, bytes payload, sent", 1684 "# UDP, total, bytes payload, sent",
1690 s->frag_ctx->payload_size, 1685 s->frag_ctx->payload_size,
1691 GNUNET_NO); 1686 GNUNET_NO);
1692 } 1687 }
1693 else 1688 else
1694 { 1689 {
1695 GNUNET_STATISTICS_update (plugin->env->stats, 1690 GNUNET_STATISTICS_update(plugin->env->stats,
1696 "# UDP, fragmented msgs, messages, sent, failure", 1691 "# UDP, fragmented msgs, messages, sent, failure",
1697 1, 1692 1,
1698 GNUNET_NO); 1693 GNUNET_NO);
1699 GNUNET_STATISTICS_update (plugin->env->stats, 1694 GNUNET_STATISTICS_update(plugin->env->stats,
1700 "# UDP, fragmented msgs, bytes payload, sent, failure", 1695 "# UDP, fragmented msgs, bytes payload, sent, failure",
1701 s->frag_ctx->payload_size, 1696 s->frag_ctx->payload_size,
1702 GNUNET_NO); 1697 GNUNET_NO);
1703 GNUNET_STATISTICS_update (plugin->env->stats, 1698 GNUNET_STATISTICS_update(plugin->env->stats,
1704 "# UDP, fragmented msgs, bytes payload, sent, failure", 1699 "# UDP, fragmented msgs, bytes payload, sent, failure",
1705 overhead, 1700 overhead,
1706 GNUNET_NO); 1701 GNUNET_NO);
1707 GNUNET_STATISTICS_update (plugin->env->stats, 1702 GNUNET_STATISTICS_update(plugin->env->stats,
1708 "# UDP, fragmented msgs, bytes payload, sent, failure", 1703 "# UDP, fragmented msgs, bytes payload, sent, failure",
1709 overhead, 1704 overhead,
1710 GNUNET_NO); 1705 GNUNET_NO);
1711 } 1706 }
1712 1707
1713 /* Remove remaining fragments from queue, no need to transmit those 1708 /* Remove remaining fragments from queue, no need to transmit those
1714 any longer. */ 1709 any longer. */
1715 if (s->address->address_length == sizeof (struct IPv6UdpAddress)) 1710 if (s->address->address_length == sizeof(struct IPv6UdpAddress))
1716 { 1711 {
1717 udpw = plugin->ipv6_queue_head; 1712 udpw = plugin->ipv6_queue_head;
1718 while (NULL != udpw) 1713 while (NULL != udpw)
1719 { 1714 {
1720 tmp = udpw->next; 1715 tmp = udpw->next;
1721 if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == frag_ctx)) 1716 if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == frag_ctx))
1722 { 1717 {
1723 dequeue (plugin, udpw); 1718 dequeue(plugin, udpw);
1724 GNUNET_free (udpw); 1719 GNUNET_free(udpw);
1725 } 1720 }
1726 udpw = tmp; 1721 udpw = tmp;
1727 } 1722 }
1728 } 1723 }
1729 if (s->address->address_length == sizeof (struct IPv4UdpAddress)) 1724 if (s->address->address_length == sizeof(struct IPv4UdpAddress))
1730 { 1725 {
1731 udpw = plugin->ipv4_queue_head; 1726 udpw = plugin->ipv4_queue_head;
1732 while (NULL != udpw) 1727 while (NULL != udpw)
1733 { 1728 {
1734 tmp = udpw->next; 1729 tmp = udpw->next;
1735 if ((NULL != udpw->frag_ctx) && (udpw->frag_ctx == frag_ctx)) 1730 if ((NULL != udpw->frag_ctx) && (udpw->frag_ctx == frag_ctx))
1736 { 1731 {
1737 dequeue (plugin, udpw); 1732 dequeue(plugin, udpw);
1738 GNUNET_free (udpw); 1733 GNUNET_free(udpw);
1739 } 1734 }
1740 udpw = tmp; 1735 udpw = tmp;
1741 } 1736 }
1742 } 1737 }
1743 notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); 1738 notify_session_monitor(s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
1744 GNUNET_FRAGMENT_context_destroy (frag_ctx->frag, 1739 GNUNET_FRAGMENT_context_destroy(frag_ctx->frag,
1745 &s->last_expected_msg_delay, 1740 &s->last_expected_msg_delay,
1746 &s->last_expected_ack_delay); 1741 &s->last_expected_ack_delay);
1747 s->frag_ctx = NULL; 1742 s->frag_ctx = NULL;
1748 GNUNET_free (frag_ctx); 1743 GNUNET_free(frag_ctx);
1749} 1744}
1750 1745
1751 1746
@@ -1758,45 +1753,45 @@ fragmented_message_done (struct UDP_FragmentationContext *frag_ctx, int result)
1758 * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure 1753 * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure
1759 */ 1754 */
1760static void 1755static void
1761qc_fragment_sent (void *cls, struct UDP_MessageWrapper *udpw, int result) 1756qc_fragment_sent(void *cls, struct UDP_MessageWrapper *udpw, int result)
1762{ 1757{
1763 struct Plugin *plugin = cls; 1758 struct Plugin *plugin = cls;
1764 1759
1765 GNUNET_assert (NULL != udpw->frag_ctx); 1760 GNUNET_assert(NULL != udpw->frag_ctx);
1766 if (GNUNET_OK == result) 1761 if (GNUNET_OK == result)
1767 { 1762 {
1768 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1763 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1769 "Fragment of message with %u bytes transmitted to %s\n", 1764 "Fragment of message with %u bytes transmitted to %s\n",
1770 (unsigned int) udpw->payload_size, 1765 (unsigned int)udpw->payload_size,
1771 GNUNET_i2s (&udpw->session->target)); 1766 GNUNET_i2s(&udpw->session->target));
1772 GNUNET_FRAGMENT_context_transmission_done (udpw->frag_ctx->frag); 1767 GNUNET_FRAGMENT_context_transmission_done(udpw->frag_ctx->frag);
1773 GNUNET_STATISTICS_update (plugin->env->stats, 1768 GNUNET_STATISTICS_update(plugin->env->stats,
1774 "# UDP, fragmented msgs, fragments, sent, success", 1769 "# UDP, fragmented msgs, fragments, sent, success",
1775 1, 1770 1,
1776 GNUNET_NO); 1771 GNUNET_NO);
1777 GNUNET_STATISTICS_update ( 1772 GNUNET_STATISTICS_update(
1778 plugin->env->stats, 1773 plugin->env->stats,
1779 "# UDP, fragmented msgs, fragments bytes, sent, success", 1774 "# UDP, fragmented msgs, fragments bytes, sent, success",
1780 udpw->msg_size, 1775 udpw->msg_size,
1781 GNUNET_NO); 1776 GNUNET_NO);
1782 } 1777 }
1783 else 1778 else
1784 { 1779 {
1785 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1780 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1786 "Failed to transmit fragment of message with %u bytes to %s\n", 1781 "Failed to transmit fragment of message with %u bytes to %s\n",
1787 (unsigned int) udpw->payload_size, 1782 (unsigned int)udpw->payload_size,
1788 GNUNET_i2s (&udpw->session->target)); 1783 GNUNET_i2s(&udpw->session->target));
1789 fragmented_message_done (udpw->frag_ctx, GNUNET_SYSERR); 1784 fragmented_message_done(udpw->frag_ctx, GNUNET_SYSERR);
1790 GNUNET_STATISTICS_update (plugin->env->stats, 1785 GNUNET_STATISTICS_update(plugin->env->stats,
1791 "# UDP, fragmented msgs, fragments, sent, failure", 1786 "# UDP, fragmented msgs, fragments, sent, failure",
1792 1, 1787 1,
1793 GNUNET_NO); 1788 GNUNET_NO);
1794 GNUNET_STATISTICS_update ( 1789 GNUNET_STATISTICS_update(
1795 plugin->env->stats, 1790 plugin->env->stats,
1796 "# UDP, fragmented msgs, fragments bytes, sent, failure", 1791 "# UDP, fragmented msgs, fragments bytes, sent, failure",
1797 udpw->msg_size, 1792 udpw->msg_size,
1798 GNUNET_NO); 1793 GNUNET_NO);
1799 } 1794 }
1800} 1795}
1801 1796
1802 1797
@@ -1810,35 +1805,35 @@ qc_fragment_sent (void *cls, struct UDP_MessageWrapper *udpw, int result)
1810 * @param msg the message that was created 1805 * @param msg the message that was created
1811 */ 1806 */
1812static void 1807static void
1813enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg) 1808enqueue_fragment(void *cls, const struct GNUNET_MessageHeader *msg)
1814{ 1809{
1815 struct UDP_FragmentationContext *frag_ctx = cls; 1810 struct UDP_FragmentationContext *frag_ctx = cls;
1816 struct Plugin *plugin = frag_ctx->plugin; 1811 struct Plugin *plugin = frag_ctx->plugin;
1817 struct UDP_MessageWrapper *udpw; 1812 struct UDP_MessageWrapper *udpw;
1818 struct GNUNET_ATS_Session *session = frag_ctx->session; 1813 struct GNUNET_ATS_Session *session = frag_ctx->session;
1819 size_t msg_len = ntohs (msg->size); 1814 size_t msg_len = ntohs(msg->size);
1820 1815
1821 LOG (GNUNET_ERROR_TYPE_DEBUG, "Enqueuing fragment with %u bytes\n", msg_len); 1816 LOG(GNUNET_ERROR_TYPE_DEBUG, "Enqueuing fragment with %u bytes\n", msg_len);
1822 udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msg_len); 1817 udpw = GNUNET_malloc(sizeof(struct UDP_MessageWrapper) + msg_len);
1823 udpw->session = session; 1818 udpw->session = session;
1824 udpw->msg_buf = (char *) &udpw[1]; 1819 udpw->msg_buf = (char *)&udpw[1];
1825 udpw->msg_size = msg_len; 1820 udpw->msg_size = msg_len;
1826 udpw->payload_size = msg_len; /* FIXME: minus fragment overhead */ 1821 udpw->payload_size = msg_len; /* FIXME: minus fragment overhead */
1827 udpw->timeout = frag_ctx->timeout; 1822 udpw->timeout = frag_ctx->timeout;
1828 udpw->start_time = frag_ctx->start_time; 1823 udpw->start_time = frag_ctx->start_time;
1829 udpw->transmission_time = frag_ctx->next_frag_time; 1824 udpw->transmission_time = frag_ctx->next_frag_time;
1830 frag_ctx->next_frag_time = 1825 frag_ctx->next_frag_time =
1831 GNUNET_TIME_absolute_add (frag_ctx->next_frag_time, 1826 GNUNET_TIME_absolute_add(frag_ctx->next_frag_time,
1832 frag_ctx->flow_delay_from_other_peer); 1827 frag_ctx->flow_delay_from_other_peer);
1833 udpw->frag_ctx = frag_ctx; 1828 udpw->frag_ctx = frag_ctx;
1834 udpw->qc = &qc_fragment_sent; 1829 udpw->qc = &qc_fragment_sent;
1835 udpw->qc_cls = plugin; 1830 udpw->qc_cls = plugin;
1836 GNUNET_memcpy (udpw->msg_buf, msg, msg_len); 1831 GNUNET_memcpy(udpw->msg_buf, msg, msg_len);
1837 enqueue (plugin, udpw); 1832 enqueue(plugin, udpw);
1838 if (session->address->address_length == sizeof (struct IPv4UdpAddress)) 1833 if (session->address->address_length == sizeof(struct IPv4UdpAddress))
1839 schedule_select_v4 (plugin); 1834 schedule_select_v4(plugin);
1840 else 1835 else
1841 schedule_select_v6 (plugin); 1836 schedule_select_v6(plugin);
1842} 1837}
1843 1838
1844 1839
@@ -1851,7 +1846,7 @@ enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg)
1851 * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure 1846 * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure
1852 */ 1847 */
1853static void 1848static void
1854qc_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result) 1849qc_message_sent(void *cls, struct UDP_MessageWrapper *udpw, int result)
1855{ 1850{
1856 struct Plugin *plugin = cls; 1851 struct Plugin *plugin = cls;
1857 size_t overhead; 1852 size_t overhead;
@@ -1863,68 +1858,68 @@ qc_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result)
1863 overhead = udpw->msg_size; 1858 overhead = udpw->msg_size;
1864 1859
1865 if (NULL != udpw->cont) 1860 if (NULL != udpw->cont)
1866 { 1861 {
1867 delay = GNUNET_TIME_absolute_get_duration (udpw->start_time); 1862 delay = GNUNET_TIME_absolute_get_duration(udpw->start_time);
1868 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 1863 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
1869 { 1864 {
1870 LOG (GNUNET_ERROR_TYPE_WARNING, 1865 LOG(GNUNET_ERROR_TYPE_WARNING,
1871 "Message sent via UDP with delay of %s\n", 1866 "Message sent via UDP with delay of %s\n",
1872 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); 1867 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES));
1873 } 1868 }
1874 else 1869 else
1875 { 1870 {
1876 LOG (GNUNET_ERROR_TYPE_DEBUG, 1871 LOG(GNUNET_ERROR_TYPE_DEBUG,
1877 "Message sent via UDP with delay of %s\n", 1872 "Message sent via UDP with delay of %s\n",
1878 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); 1873 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES));
1879 } 1874 }
1880 udpw->cont (udpw->cont_cls, 1875 udpw->cont(udpw->cont_cls,
1881 &udpw->session->target, 1876 &udpw->session->target,
1882 result, 1877 result,
1883 udpw->payload_size, 1878 udpw->payload_size,
1884 overhead); 1879 overhead);
1885 } 1880 }
1886 if (GNUNET_OK == result) 1881 if (GNUNET_OK == result)
1887 { 1882 {
1888 GNUNET_STATISTICS_update (plugin->env->stats, 1883 GNUNET_STATISTICS_update(plugin->env->stats,
1889 "# UDP, unfragmented msgs, messages, sent, success", 1884 "# UDP, unfragmented msgs, messages, sent, success",
1890 1, 1885 1,
1891 GNUNET_NO); 1886 GNUNET_NO);
1892 GNUNET_STATISTICS_update ( 1887 GNUNET_STATISTICS_update(
1893 plugin->env->stats, 1888 plugin->env->stats,
1894 "# UDP, unfragmented msgs, bytes payload, sent, success", 1889 "# UDP, unfragmented msgs, bytes payload, sent, success",
1895 udpw->payload_size, 1890 udpw->payload_size,
1896 GNUNET_NO); 1891 GNUNET_NO);
1897 GNUNET_STATISTICS_update ( 1892 GNUNET_STATISTICS_update(
1898 plugin->env->stats, 1893 plugin->env->stats,
1899 "# UDP, unfragmented msgs, bytes overhead, sent, success", 1894 "# UDP, unfragmented msgs, bytes overhead, sent, success",
1900 overhead, 1895 overhead,
1901 GNUNET_NO); 1896 GNUNET_NO);
1902 GNUNET_STATISTICS_update (plugin->env->stats, 1897 GNUNET_STATISTICS_update(plugin->env->stats,
1903 "# UDP, total, bytes overhead, sent", 1898 "# UDP, total, bytes overhead, sent",
1904 overhead, 1899 overhead,
1905 GNUNET_NO); 1900 GNUNET_NO);
1906 GNUNET_STATISTICS_update (plugin->env->stats, 1901 GNUNET_STATISTICS_update(plugin->env->stats,
1907 "# UDP, total, bytes payload, sent", 1902 "# UDP, total, bytes payload, sent",
1908 udpw->payload_size, 1903 udpw->payload_size,
1909 GNUNET_NO); 1904 GNUNET_NO);
1910 } 1905 }
1911 else 1906 else
1912 { 1907 {
1913 GNUNET_STATISTICS_update (plugin->env->stats, 1908 GNUNET_STATISTICS_update(plugin->env->stats,
1914 "# UDP, unfragmented msgs, messages, sent, failure", 1909 "# UDP, unfragmented msgs, messages, sent, failure",
1915 1, 1910 1,
1916 GNUNET_NO); 1911 GNUNET_NO);
1917 GNUNET_STATISTICS_update ( 1912 GNUNET_STATISTICS_update(
1918 plugin->env->stats, 1913 plugin->env->stats,
1919 "# UDP, unfragmented msgs, bytes payload, sent, failure", 1914 "# UDP, unfragmented msgs, bytes payload, sent, failure",
1920 udpw->payload_size, 1915 udpw->payload_size,
1921 GNUNET_NO); 1916 GNUNET_NO);
1922 GNUNET_STATISTICS_update ( 1917 GNUNET_STATISTICS_update(
1923 plugin->env->stats, 1918 plugin->env->stats,
1924 "# UDP, unfragmented msgs, bytes overhead, sent, failure", 1919 "# UDP, unfragmented msgs, bytes overhead, sent, failure",
1925 overhead, 1920 overhead,
1926 GNUNET_NO); 1921 GNUNET_NO);
1927 } 1922 }
1928} 1923}
1929 1924
1930 1925
@@ -1956,54 +1951,54 @@ qc_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result)
1956 * and does NOT mean that the message was not transmitted (DV) 1951 * and does NOT mean that the message was not transmitted (DV)
1957 */ 1952 */
1958static ssize_t 1953static ssize_t
1959udp_plugin_send (void *cls, 1954udp_plugin_send(void *cls,
1960 struct GNUNET_ATS_Session *s, 1955 struct GNUNET_ATS_Session *s,
1961 const char *msgbuf, 1956 const char *msgbuf,
1962 size_t msgbuf_size, 1957 size_t msgbuf_size,
1963 unsigned int priority, 1958 unsigned int priority,
1964 struct GNUNET_TIME_Relative to, 1959 struct GNUNET_TIME_Relative to,
1965 GNUNET_TRANSPORT_TransmitContinuation cont, 1960 GNUNET_TRANSPORT_TransmitContinuation cont,
1966 void *cont_cls) 1961 void *cont_cls)
1967{ 1962{
1968 struct Plugin *plugin = cls; 1963 struct Plugin *plugin = cls;
1969 size_t udpmlen = msgbuf_size + sizeof (struct UDPMessage); 1964 size_t udpmlen = msgbuf_size + sizeof(struct UDPMessage);
1970 struct UDP_FragmentationContext *frag_ctx; 1965 struct UDP_FragmentationContext *frag_ctx;
1971 struct UDP_MessageWrapper *udpw; 1966 struct UDP_MessageWrapper *udpw;
1972 struct UDPMessage *udp; 1967 struct UDPMessage *udp;
1973 char mbuf[udpmlen] GNUNET_ALIGN; 1968 char mbuf[udpmlen] GNUNET_ALIGN;
1974 struct GNUNET_TIME_Relative latency; 1969 struct GNUNET_TIME_Relative latency;
1975 1970
1976 if ((sizeof (struct IPv6UdpAddress) == s->address->address_length) && 1971 if ((sizeof(struct IPv6UdpAddress) == s->address->address_length) &&
1977 (NULL == plugin->sockv6)) 1972 (NULL == plugin->sockv6))
1978 return GNUNET_SYSERR; 1973 return GNUNET_SYSERR;
1979 if ((sizeof (struct IPv4UdpAddress) == s->address->address_length) && 1974 if ((sizeof(struct IPv4UdpAddress) == s->address->address_length) &&
1980 (NULL == plugin->sockv4)) 1975 (NULL == plugin->sockv4))
1981 return GNUNET_SYSERR; 1976 return GNUNET_SYSERR;
1982 if (udpmlen >= GNUNET_MAX_MESSAGE_SIZE) 1977 if (udpmlen >= GNUNET_MAX_MESSAGE_SIZE)
1983 { 1978 {
1984 GNUNET_break (0); 1979 GNUNET_break(0);
1985 return GNUNET_SYSERR; 1980 return GNUNET_SYSERR;
1986 } 1981 }
1987 if (GNUNET_YES != 1982 if (GNUNET_YES !=
1988 GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessions, 1983 GNUNET_CONTAINER_multipeermap_contains_value(plugin->sessions,
1989 &s->target, 1984 &s->target,
1990 s)) 1985 s))
1991 { 1986 {
1992 GNUNET_break (0); 1987 GNUNET_break(0);
1993 return GNUNET_SYSERR; 1988 return GNUNET_SYSERR;
1994 } 1989 }
1995 LOG (GNUNET_ERROR_TYPE_DEBUG, 1990 LOG(GNUNET_ERROR_TYPE_DEBUG,
1996 "UDP transmits %u-byte message to `%s' using address `%s'\n", 1991 "UDP transmits %u-byte message to `%s' using address `%s'\n",
1997 udpmlen, 1992 udpmlen,
1998 GNUNET_i2s (&s->target), 1993 GNUNET_i2s(&s->target),
1999 udp_address_to_string (plugin, 1994 udp_address_to_string(plugin,
2000 s->address->address, 1995 s->address->address,
2001 s->address->address_length)); 1996 s->address->address_length));
2002 1997
2003 udp = (struct UDPMessage *) mbuf; 1998 udp = (struct UDPMessage *)mbuf;
2004 udp->header.size = htons (udpmlen); 1999 udp->header.size = htons(udpmlen);
2005 udp->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE); 2000 udp->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE);
2006 udp->reserved = htonl (0); 2001 udp->reserved = htonl(0);
2007 udp->sender = *plugin->env->my_identity; 2002 udp->sender = *plugin->env->my_identity;
2008 2003
2009 /* We do not update the session time out here! Otherwise this 2004 /* We do not update the session time out here! Otherwise this
@@ -2015,100 +2010,100 @@ udp_plugin_send (void *cls,
2015 * responses! 2010 * responses!
2016 */ 2011 */
2017 if (udpmlen <= UDP_MTU) 2012 if (udpmlen <= UDP_MTU)
2018 { 2013 {
2019 /* unfragmented message */ 2014 /* unfragmented message */
2020 udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + udpmlen); 2015 udpw = GNUNET_malloc(sizeof(struct UDP_MessageWrapper) + udpmlen);
2021 udpw->session = s; 2016 udpw->session = s;
2022 udpw->msg_buf = (char *) &udpw[1]; 2017 udpw->msg_buf = (char *)&udpw[1];
2023 udpw->msg_size = udpmlen; /* message size with UDP overhead */ 2018 udpw->msg_size = udpmlen; /* message size with UDP overhead */
2024 udpw->payload_size = msgbuf_size; /* message size without UDP overhead */ 2019 udpw->payload_size = msgbuf_size; /* message size without UDP overhead */
2025 udpw->start_time = GNUNET_TIME_absolute_get (); 2020 udpw->start_time = GNUNET_TIME_absolute_get();
2026 udpw->timeout = GNUNET_TIME_relative_to_absolute (to); 2021 udpw->timeout = GNUNET_TIME_relative_to_absolute(to);
2027 udpw->transmission_time = s->last_transmit_time; 2022 udpw->transmission_time = s->last_transmit_time;
2028 s->last_transmit_time = 2023 s->last_transmit_time =
2029 GNUNET_TIME_absolute_add (s->last_transmit_time, 2024 GNUNET_TIME_absolute_add(s->last_transmit_time,
2030 s->flow_delay_from_other_peer); 2025 s->flow_delay_from_other_peer);
2031 udpw->cont = cont; 2026 udpw->cont = cont;
2032 udpw->cont_cls = cont_cls; 2027 udpw->cont_cls = cont_cls;
2033 udpw->frag_ctx = NULL; 2028 udpw->frag_ctx = NULL;
2034 udpw->qc = &qc_message_sent; 2029 udpw->qc = &qc_message_sent;
2035 udpw->qc_cls = plugin; 2030 udpw->qc_cls = plugin;
2036 GNUNET_memcpy (udpw->msg_buf, udp, sizeof (struct UDPMessage)); 2031 GNUNET_memcpy(udpw->msg_buf, udp, sizeof(struct UDPMessage));
2037 GNUNET_memcpy (&udpw->msg_buf[sizeof (struct UDPMessage)], 2032 GNUNET_memcpy(&udpw->msg_buf[sizeof(struct UDPMessage)],
2038 msgbuf, 2033 msgbuf,
2039 msgbuf_size); 2034 msgbuf_size);
2040 enqueue (plugin, udpw); 2035 enqueue(plugin, udpw);
2041 GNUNET_STATISTICS_update (plugin->env->stats, 2036 GNUNET_STATISTICS_update(plugin->env->stats,
2042 "# UDP, unfragmented messages queued total", 2037 "# UDP, unfragmented messages queued total",
2043 1, 2038 1,
2044 GNUNET_NO); 2039 GNUNET_NO);
2045 GNUNET_STATISTICS_update (plugin->env->stats, 2040 GNUNET_STATISTICS_update(plugin->env->stats,
2046 "# UDP, unfragmented bytes payload queued total", 2041 "# UDP, unfragmented bytes payload queued total",
2047 msgbuf_size, 2042 msgbuf_size,
2048 GNUNET_NO); 2043 GNUNET_NO);
2049 if (s->address->address_length == sizeof (struct IPv4UdpAddress)) 2044 if (s->address->address_length == sizeof(struct IPv4UdpAddress))
2050 schedule_select_v4 (plugin); 2045 schedule_select_v4(plugin);
2051 else 2046 else
2052 schedule_select_v6 (plugin); 2047 schedule_select_v6(plugin);
2053 } 2048 }
2054 else 2049 else
2055 { 2050 {
2056 /* fragmented message */ 2051 /* fragmented message */
2057 if (NULL != s->frag_ctx) 2052 if (NULL != s->frag_ctx)
2058 return GNUNET_SYSERR; 2053 return GNUNET_SYSERR;
2059 GNUNET_memcpy (&udp[1], msgbuf, msgbuf_size); 2054 GNUNET_memcpy(&udp[1], msgbuf, msgbuf_size);
2060 frag_ctx = GNUNET_new (struct UDP_FragmentationContext); 2055 frag_ctx = GNUNET_new(struct UDP_FragmentationContext);
2061 frag_ctx->plugin = plugin; 2056 frag_ctx->plugin = plugin;
2062 frag_ctx->session = s; 2057 frag_ctx->session = s;
2063 frag_ctx->cont = cont; 2058 frag_ctx->cont = cont;
2064 frag_ctx->cont_cls = cont_cls; 2059 frag_ctx->cont_cls = cont_cls;
2065 frag_ctx->start_time = GNUNET_TIME_absolute_get (); 2060 frag_ctx->start_time = GNUNET_TIME_absolute_get();
2066 frag_ctx->next_frag_time = s->last_transmit_time; 2061 frag_ctx->next_frag_time = s->last_transmit_time;
2067 frag_ctx->flow_delay_from_other_peer = 2062 frag_ctx->flow_delay_from_other_peer =
2068 GNUNET_TIME_relative_divide (s->flow_delay_from_other_peer, 2063 GNUNET_TIME_relative_divide(s->flow_delay_from_other_peer,
2069 1 + (msgbuf_size / UDP_MTU)); 2064 1 + (msgbuf_size / UDP_MTU));
2070 frag_ctx->timeout = GNUNET_TIME_relative_to_absolute (to); 2065 frag_ctx->timeout = GNUNET_TIME_relative_to_absolute(to);
2071 frag_ctx->payload_size = 2066 frag_ctx->payload_size =
2072 msgbuf_size; /* unfragmented message size without UDP overhead */ 2067 msgbuf_size; /* unfragmented message size without UDP overhead */
2073 frag_ctx->on_wire_size = 0; /* bytes with UDP and fragmentation overhead */ 2068 frag_ctx->on_wire_size = 0; /* bytes with UDP and fragmentation overhead */
2074 frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, 2069 frag_ctx->frag = GNUNET_FRAGMENT_context_create(plugin->env->stats,
2075 UDP_MTU, 2070 UDP_MTU,
2076 &plugin->tracker, 2071 &plugin->tracker,
2077 s->last_expected_msg_delay, 2072 s->last_expected_msg_delay,
2078 s->last_expected_ack_delay, 2073 s->last_expected_ack_delay,
2079 &udp->header, 2074 &udp->header,
2080 &enqueue_fragment, 2075 &enqueue_fragment,
2081 frag_ctx); 2076 frag_ctx);
2082 s->frag_ctx = frag_ctx; 2077 s->frag_ctx = frag_ctx;
2083 s->last_transmit_time = frag_ctx->next_frag_time; 2078 s->last_transmit_time = frag_ctx->next_frag_time;
2084 latency = GNUNET_TIME_absolute_get_remaining (s->last_transmit_time); 2079 latency = GNUNET_TIME_absolute_get_remaining(s->last_transmit_time);
2085 if (latency.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 2080 if (latency.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
2086 LOG (GNUNET_ERROR_TYPE_WARNING, 2081 LOG(GNUNET_ERROR_TYPE_WARNING,
2087 "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n", 2082 "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n",
2088 GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_YES), 2083 GNUNET_STRINGS_relative_time_to_string(latency, GNUNET_YES),
2089 GNUNET_i2s (&s->target), 2084 GNUNET_i2s(&s->target),
2090 (unsigned int) s->msgs_in_queue); 2085 (unsigned int)s->msgs_in_queue);
2091 else 2086 else
2092 LOG (GNUNET_ERROR_TYPE_DEBUG, 2087 LOG(GNUNET_ERROR_TYPE_DEBUG,
2093 "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n", 2088 "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n",
2094 GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_YES), 2089 GNUNET_STRINGS_relative_time_to_string(latency, GNUNET_YES),
2095 GNUNET_i2s (&s->target), 2090 GNUNET_i2s(&s->target),
2096 (unsigned int) s->msgs_in_queue); 2091 (unsigned int)s->msgs_in_queue);
2097 2092
2098 GNUNET_STATISTICS_update (plugin->env->stats, 2093 GNUNET_STATISTICS_update(plugin->env->stats,
2099 "# UDP, fragmented messages active", 2094 "# UDP, fragmented messages active",
2100 1, 2095 1,
2101 GNUNET_NO); 2096 GNUNET_NO);
2102 GNUNET_STATISTICS_update (plugin->env->stats, 2097 GNUNET_STATISTICS_update(plugin->env->stats,
2103 "# UDP, fragmented messages, total", 2098 "# UDP, fragmented messages, total",
2104 1, 2099 1,
2105 GNUNET_NO); 2100 GNUNET_NO);
2106 GNUNET_STATISTICS_update (plugin->env->stats, 2101 GNUNET_STATISTICS_update(plugin->env->stats,
2107 "# UDP, fragmented bytes (payload)", 2102 "# UDP, fragmented bytes (payload)",
2108 frag_ctx->payload_size, 2103 frag_ctx->payload_size,
2109 GNUNET_NO); 2104 GNUNET_NO);
2110 } 2105 }
2111 notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); 2106 notify_session_monitor(s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
2112 return udpmlen; 2107 return udpmlen;
2113} 2108}
2114 2109
@@ -2119,8 +2114,7 @@ udp_plugin_send (void *cls,
2119/** 2114/**
2120 * Closure for #find_receive_context(). 2115 * Closure for #find_receive_context().
2121 */ 2116 */
2122struct FindReceiveContext 2117struct FindReceiveContext {
2123{
2124 /** 2118 /**
2125 * Where to store the result. 2119 * Where to store the result.
2126 */ 2120 */
@@ -2154,20 +2148,20 @@ struct FindReceiveContext
2154 * #GNUNET_NO if not. 2148 * #GNUNET_NO if not.
2155 */ 2149 */
2156static int 2150static int
2157find_receive_context (void *cls, 2151find_receive_context(void *cls,
2158 struct GNUNET_CONTAINER_HeapNode *node, 2152 struct GNUNET_CONTAINER_HeapNode *node,
2159 void *element, 2153 void *element,
2160 GNUNET_CONTAINER_HeapCostType cost) 2154 GNUNET_CONTAINER_HeapCostType cost)
2161{ 2155{
2162 struct FindReceiveContext *frc = cls; 2156 struct FindReceiveContext *frc = cls;
2163 struct DefragContext *e = element; 2157 struct DefragContext *e = element;
2164 2158
2165 if ((frc->udp_addr_len == e->udp_addr_len) && 2159 if ((frc->udp_addr_len == e->udp_addr_len) &&
2166 (0 == memcmp (frc->udp_addr, e->udp_addr, frc->udp_addr_len))) 2160 (0 == memcmp(frc->udp_addr, e->udp_addr, frc->udp_addr_len)))
2167 { 2161 {
2168 frc->rc = e; 2162 frc->rc = e;
2169 return GNUNET_NO; 2163 return GNUNET_NO;
2170 } 2164 }
2171 return GNUNET_YES; 2165 return GNUNET_YES;
2172} 2166}
2173 2167
@@ -2181,96 +2175,96 @@ find_receive_context (void *cls,
2181 * @return #GNUNET_OK on success 2175 * @return #GNUNET_OK on success
2182 */ 2176 */
2183static int 2177static int
2184udp_disconnect_session (void *cls, struct GNUNET_ATS_Session *s) 2178udp_disconnect_session(void *cls, struct GNUNET_ATS_Session *s)
2185{ 2179{
2186 struct Plugin *plugin = cls; 2180 struct Plugin *plugin = cls;
2187 struct UDP_MessageWrapper *udpw; 2181 struct UDP_MessageWrapper *udpw;
2188 struct UDP_MessageWrapper *next; 2182 struct UDP_MessageWrapper *next;
2189 struct FindReceiveContext frc; 2183 struct FindReceiveContext frc;
2190 2184
2191 GNUNET_assert (GNUNET_YES != s->in_destroy); 2185 GNUNET_assert(GNUNET_YES != s->in_destroy);
2192 LOG (GNUNET_ERROR_TYPE_DEBUG, 2186 LOG(GNUNET_ERROR_TYPE_DEBUG,
2193 "Session %p to peer `%s' at address %s ended\n", 2187 "Session %p to peer `%s' at address %s ended\n",
2194 s, 2188 s,
2195 GNUNET_i2s (&s->target), 2189 GNUNET_i2s(&s->target),
2196 udp_address_to_string (plugin, 2190 udp_address_to_string(plugin,
2197 s->address->address, 2191 s->address->address,
2198 s->address->address_length)); 2192 s->address->address_length));
2199 if (NULL != s->timeout_task) 2193 if (NULL != s->timeout_task)
2200 { 2194 {
2201 GNUNET_SCHEDULER_cancel (s->timeout_task); 2195 GNUNET_SCHEDULER_cancel(s->timeout_task);
2202 s->timeout_task = NULL; 2196 s->timeout_task = NULL;
2203 } 2197 }
2204 if (NULL != s->frag_ctx) 2198 if (NULL != s->frag_ctx)
2205 { 2199 {
2206 /* Remove fragmented message due to disconnect */ 2200 /* Remove fragmented message due to disconnect */
2207 fragmented_message_done (s->frag_ctx, GNUNET_SYSERR); 2201 fragmented_message_done(s->frag_ctx, GNUNET_SYSERR);
2208 } 2202 }
2209 GNUNET_assert ( 2203 GNUNET_assert(
2210 GNUNET_YES == 2204 GNUNET_YES ==
2211 GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, &s->target, s)); 2205 GNUNET_CONTAINER_multipeermap_remove(plugin->sessions, &s->target, s));
2212 frc.rc = NULL; 2206 frc.rc = NULL;
2213 frc.udp_addr = s->address->address; 2207 frc.udp_addr = s->address->address;
2214 frc.udp_addr_len = s->address->address_length; 2208 frc.udp_addr_len = s->address->address_length;
2215 /* Lookup existing receive context for this address */ 2209 /* Lookup existing receive context for this address */
2216 if (NULL != plugin->defrag_ctxs) 2210 if (NULL != plugin->defrag_ctxs)
2217 {
2218 GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs,
2219 &find_receive_context,
2220 &frc);
2221 if (NULL != frc.rc)
2222 { 2211 {
2223 struct DefragContext *d_ctx = frc.rc; 2212 GNUNET_CONTAINER_heap_iterate(plugin->defrag_ctxs,
2213 &find_receive_context,
2214 &frc);
2215 if (NULL != frc.rc)
2216 {
2217 struct DefragContext *d_ctx = frc.rc;
2224 2218
2225 GNUNET_CONTAINER_heap_remove_node (d_ctx->hnode); 2219 GNUNET_CONTAINER_heap_remove_node(d_ctx->hnode);
2226 GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag); 2220 GNUNET_DEFRAGMENT_context_destroy(d_ctx->defrag);
2227 GNUNET_free (d_ctx); 2221 GNUNET_free(d_ctx);
2222 }
2228 } 2223 }
2229 }
2230 s->in_destroy = GNUNET_YES; 2224 s->in_destroy = GNUNET_YES;
2231 next = plugin->ipv4_queue_head; 2225 next = plugin->ipv4_queue_head;
2232 while (NULL != (udpw = next)) 2226 while (NULL != (udpw = next))
2233 {
2234 next = udpw->next;
2235 if (udpw->session == s)
2236 { 2227 {
2237 dequeue (plugin, udpw); 2228 next = udpw->next;
2238 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); 2229 if (udpw->session == s)
2239 GNUNET_free (udpw); 2230 {
2231 dequeue(plugin, udpw);
2232 udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR);
2233 GNUNET_free(udpw);
2234 }
2240 } 2235 }
2241 }
2242 next = plugin->ipv6_queue_head; 2236 next = plugin->ipv6_queue_head;
2243 while (NULL != (udpw = next)) 2237 while (NULL != (udpw = next))
2244 {
2245 next = udpw->next;
2246 if (udpw->session == s)
2247 { 2238 {
2248 dequeue (plugin, udpw); 2239 next = udpw->next;
2249 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); 2240 if (udpw->session == s)
2250 GNUNET_free (udpw); 2241 {
2242 dequeue(plugin, udpw);
2243 udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR);
2244 GNUNET_free(udpw);
2245 }
2251 } 2246 }
2252 }
2253 if ((NULL != s->frag_ctx) && (NULL != s->frag_ctx->cont)) 2247 if ((NULL != s->frag_ctx) && (NULL != s->frag_ctx->cont))
2254 { 2248 {
2255 /* The 'frag_ctx' itself will be freed in #free_session() a bit 2249 /* The 'frag_ctx' itself will be freed in #free_session() a bit
2256 later, as it might be in use right now */ 2250 later, as it might be in use right now */
2257 LOG (GNUNET_ERROR_TYPE_DEBUG, 2251 LOG(GNUNET_ERROR_TYPE_DEBUG,
2258 "Calling continuation for fragemented message to `%s' with result SYSERR\n", 2252 "Calling continuation for fragemented message to `%s' with result SYSERR\n",
2259 GNUNET_i2s (&s->target)); 2253 GNUNET_i2s(&s->target));
2260 s->frag_ctx->cont (s->frag_ctx->cont_cls, 2254 s->frag_ctx->cont(s->frag_ctx->cont_cls,
2261 &s->target, 2255 &s->target,
2262 GNUNET_SYSERR, 2256 GNUNET_SYSERR,
2263 s->frag_ctx->payload_size, 2257 s->frag_ctx->payload_size,
2264 s->frag_ctx->on_wire_size); 2258 s->frag_ctx->on_wire_size);
2265 } 2259 }
2266 notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_DONE); 2260 notify_session_monitor(s->plugin, s, GNUNET_TRANSPORT_SS_DONE);
2267 plugin->env->session_end (plugin->env->cls, s->address, s); 2261 plugin->env->session_end(plugin->env->cls, s->address, s);
2268 GNUNET_STATISTICS_set (plugin->env->stats, 2262 GNUNET_STATISTICS_set(plugin->env->stats,
2269 "# UDP sessions active", 2263 "# UDP sessions active",
2270 GNUNET_CONTAINER_multipeermap_size (plugin->sessions), 2264 GNUNET_CONTAINER_multipeermap_size(plugin->sessions),
2271 GNUNET_NO); 2265 GNUNET_NO);
2272 if (0 == s->rc) 2266 if (0 == s->rc)
2273 free_session (s); 2267 free_session(s);
2274 return GNUNET_OK; 2268 return GNUNET_OK;
2275} 2269}
2276 2270
@@ -2284,10 +2278,10 @@ udp_disconnect_session (void *cls, struct GNUNET_ATS_Session *s)
2284 * @param udp_addr_len number of bytes in @a udp_addr 2278 * @param udp_addr_len number of bytes in @a udp_addr
2285 */ 2279 */
2286static void 2280static void
2287read_process_ack (struct Plugin *plugin, 2281read_process_ack(struct Plugin *plugin,
2288 const struct GNUNET_MessageHeader *msg, 2282 const struct GNUNET_MessageHeader *msg,
2289 const union UdpAddress *udp_addr, 2283 const union UdpAddress *udp_addr,
2290 socklen_t udp_addr_len) 2284 socklen_t udp_addr_len)
2291{ 2285{
2292 const struct GNUNET_MessageHeader *ack; 2286 const struct GNUNET_MessageHeader *ack;
2293 const struct UDP_ACK_Message *udp_ack; 2287 const struct UDP_ACK_Message *udp_ack;
@@ -2296,93 +2290,93 @@ read_process_ack (struct Plugin *plugin,
2296 struct GNUNET_TIME_Relative flow_delay; 2290 struct GNUNET_TIME_Relative flow_delay;
2297 2291
2298 /* check message format */ 2292 /* check message format */
2299 if (ntohs (msg->size) < 2293 if (ntohs(msg->size) <
2300 sizeof (struct UDP_ACK_Message) + sizeof (struct GNUNET_MessageHeader)) 2294 sizeof(struct UDP_ACK_Message) + sizeof(struct GNUNET_MessageHeader))
2301 { 2295 {
2302 GNUNET_break_op (0); 2296 GNUNET_break_op(0);
2303 return; 2297 return;
2304 } 2298 }
2305 udp_ack = (const struct UDP_ACK_Message *) msg; 2299 udp_ack = (const struct UDP_ACK_Message *)msg;
2306 ack = (const struct GNUNET_MessageHeader *) &udp_ack[1]; 2300 ack = (const struct GNUNET_MessageHeader *)&udp_ack[1];
2307 if (ntohs (ack->size) != ntohs (msg->size) - sizeof (struct UDP_ACK_Message)) 2301 if (ntohs(ack->size) != ntohs(msg->size) - sizeof(struct UDP_ACK_Message))
2308 { 2302 {
2309 GNUNET_break_op (0); 2303 GNUNET_break_op(0);
2310 return; 2304 return;
2311 } 2305 }
2312 2306
2313 /* Locate session */ 2307 /* Locate session */
2314 address = GNUNET_HELLO_address_allocate (&udp_ack->sender, 2308 address = GNUNET_HELLO_address_allocate(&udp_ack->sender,
2315 PLUGIN_NAME, 2309 PLUGIN_NAME,
2316 udp_addr, 2310 udp_addr,
2317 udp_addr_len, 2311 udp_addr_len,
2318 GNUNET_HELLO_ADDRESS_INFO_NONE); 2312 GNUNET_HELLO_ADDRESS_INFO_NONE);
2319 s = udp_plugin_lookup_session (plugin, address); 2313 s = udp_plugin_lookup_session(plugin, address);
2320 if (NULL == s) 2314 if (NULL == s)
2321 { 2315 {
2322 LOG (GNUNET_ERROR_TYPE_WARNING, 2316 LOG(GNUNET_ERROR_TYPE_WARNING,
2323 "UDP session of address %s for ACK not found\n", 2317 "UDP session of address %s for ACK not found\n",
2324 udp_address_to_string (plugin, 2318 udp_address_to_string(plugin,
2325 address->address, 2319 address->address,
2326 address->address_length)); 2320 address->address_length));
2327 GNUNET_HELLO_address_free (address); 2321 GNUNET_HELLO_address_free(address);
2328 return; 2322 return;
2329 } 2323 }
2330 if (NULL == s->frag_ctx) 2324 if (NULL == s->frag_ctx)
2331 { 2325 {
2332 LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 2326 LOG(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2333 "Fragmentation context of address %s for ACK (%s) not found\n", 2327 "Fragmentation context of address %s for ACK (%s) not found\n",
2334 udp_address_to_string (plugin, 2328 udp_address_to_string(plugin,
2335 address->address, 2329 address->address,
2336 address->address_length), 2330 address->address_length),
2337 GNUNET_FRAGMENT_print_ack (ack)); 2331 GNUNET_FRAGMENT_print_ack(ack));
2338 GNUNET_HELLO_address_free (address); 2332 GNUNET_HELLO_address_free(address);
2339 return; 2333 return;
2340 } 2334 }
2341 GNUNET_HELLO_address_free (address); 2335 GNUNET_HELLO_address_free(address);
2342 2336
2343 /* evaluate flow delay: how long should we wait between messages? */ 2337 /* evaluate flow delay: how long should we wait between messages? */
2344 if (UINT32_MAX == ntohl (udp_ack->delay)) 2338 if (UINT32_MAX == ntohl(udp_ack->delay))
2345 { 2339 {
2346 /* Other peer asked for us to terminate the session */ 2340 /* Other peer asked for us to terminate the session */
2347 LOG (GNUNET_ERROR_TYPE_INFO, 2341 LOG(GNUNET_ERROR_TYPE_INFO,
2348 "Asked to disconnect UDP session of %s\n", 2342 "Asked to disconnect UDP session of %s\n",
2349 GNUNET_i2s (&udp_ack->sender)); 2343 GNUNET_i2s(&udp_ack->sender));
2350 udp_disconnect_session (plugin, s); 2344 udp_disconnect_session(plugin, s);
2351 return; 2345 return;
2352 } 2346 }
2353 flow_delay.rel_value_us = (uint64_t) ntohl (udp_ack->delay); 2347 flow_delay.rel_value_us = (uint64_t)ntohl(udp_ack->delay);
2354 if (flow_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 2348 if (flow_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
2355 LOG (GNUNET_ERROR_TYPE_WARNING, 2349 LOG(GNUNET_ERROR_TYPE_WARNING,
2356 "We received a sending delay of %s for %s\n", 2350 "We received a sending delay of %s for %s\n",
2357 GNUNET_STRINGS_relative_time_to_string (flow_delay, GNUNET_YES), 2351 GNUNET_STRINGS_relative_time_to_string(flow_delay, GNUNET_YES),
2358 GNUNET_i2s (&udp_ack->sender)); 2352 GNUNET_i2s(&udp_ack->sender));
2359 else 2353 else
2360 LOG (GNUNET_ERROR_TYPE_DEBUG, 2354 LOG(GNUNET_ERROR_TYPE_DEBUG,
2361 "We received a sending delay of %s for %s\n", 2355 "We received a sending delay of %s for %s\n",
2362 GNUNET_STRINGS_relative_time_to_string (flow_delay, GNUNET_YES), 2356 GNUNET_STRINGS_relative_time_to_string(flow_delay, GNUNET_YES),
2363 GNUNET_i2s (&udp_ack->sender)); 2357 GNUNET_i2s(&udp_ack->sender));
2364 /* Flow delay is for the reassembled packet, however, our delay 2358 /* Flow delay is for the reassembled packet, however, our delay
2365 is per packet, so we need to adjust: */ 2359 is per packet, so we need to adjust: */
2366 s->flow_delay_from_other_peer = flow_delay; 2360 s->flow_delay_from_other_peer = flow_delay;
2367 2361
2368 /* Handle ACK */ 2362 /* Handle ACK */
2369 if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (s->frag_ctx->frag, ack)) 2363 if (GNUNET_OK != GNUNET_FRAGMENT_process_ack(s->frag_ctx->frag, ack))
2370 { 2364 {
2371 LOG (GNUNET_ERROR_TYPE_DEBUG, 2365 LOG(GNUNET_ERROR_TYPE_DEBUG,
2372 "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", 2366 "UDP processes %u-byte acknowledgement from `%s' at `%s'\n",
2373 (unsigned int) ntohs (msg->size), 2367 (unsigned int)ntohs(msg->size),
2374 GNUNET_i2s (&udp_ack->sender), 2368 GNUNET_i2s(&udp_ack->sender),
2375 udp_address_to_string (plugin, udp_addr, udp_addr_len)); 2369 udp_address_to_string(plugin, udp_addr, udp_addr_len));
2376 /* Expect more ACKs to arrive */ 2370 /* Expect more ACKs to arrive */
2377 return; 2371 return;
2378 } 2372 }
2379 2373
2380 /* Remove fragmented message after successful sending */ 2374 /* Remove fragmented message after successful sending */
2381 LOG (GNUNET_ERROR_TYPE_DEBUG, 2375 LOG(GNUNET_ERROR_TYPE_DEBUG,
2382 "Message from %s at %s full ACK'ed\n", 2376 "Message from %s at %s full ACK'ed\n",
2383 GNUNET_i2s (&udp_ack->sender), 2377 GNUNET_i2s(&udp_ack->sender),
2384 udp_address_to_string (plugin, udp_addr, udp_addr_len)); 2378 udp_address_to_string(plugin, udp_addr, udp_addr_len));
2385 fragmented_message_done (s->frag_ctx, GNUNET_OK); 2379 fragmented_message_done(s->frag_ctx, GNUNET_OK);
2386} 2380}
2387 2381
2388 2382
@@ -2395,17 +2389,17 @@ read_process_ack (struct Plugin *plugin,
2395 * @return #GNUNET_OK (always) 2389 * @return #GNUNET_OK (always)
2396 */ 2390 */
2397static int 2391static int
2398process_inbound_tokenized_messages (void *cls, 2392process_inbound_tokenized_messages(void *cls,
2399 const struct GNUNET_MessageHeader *hdr) 2393 const struct GNUNET_MessageHeader *hdr)
2400{ 2394{
2401 struct GNUNET_ATS_Session *session = cls; 2395 struct GNUNET_ATS_Session *session = cls;
2402 struct Plugin *plugin = session->plugin; 2396 struct Plugin *plugin = session->plugin;
2403 2397
2404 if (GNUNET_YES == session->in_destroy) 2398 if (GNUNET_YES == session->in_destroy)
2405 return GNUNET_OK; 2399 return GNUNET_OK;
2406 reschedule_session_timeout (session); 2400 reschedule_session_timeout(session);
2407 session->flow_delay_for_other_peer = 2401 session->flow_delay_for_other_peer =
2408 plugin->env->receive (plugin->env->cls, session->address, session, hdr); 2402 plugin->env->receive(plugin->env->cls, session->address, session, hdr);
2409 return GNUNET_OK; 2403 return GNUNET_OK;
2410} 2404}
2411 2405
@@ -2419,13 +2413,13 @@ process_inbound_tokenized_messages (void *cls,
2419 * @return #GNUNET_OK (continue to iterate) 2413 * @return #GNUNET_OK (continue to iterate)
2420 */ 2414 */
2421static int 2415static int
2422disconnect_and_free_it (void *cls, 2416disconnect_and_free_it(void *cls,
2423 const struct GNUNET_PeerIdentity *key, 2417 const struct GNUNET_PeerIdentity *key,
2424 void *value) 2418 void *value)
2425{ 2419{
2426 struct Plugin *plugin = cls; 2420 struct Plugin *plugin = cls;
2427 2421
2428 udp_disconnect_session (plugin, value); 2422 udp_disconnect_session(plugin, value);
2429 return GNUNET_OK; 2423 return GNUNET_OK;
2430} 2424}
2431 2425
@@ -2439,17 +2433,17 @@ disconnect_and_free_it (void *cls,
2439 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed 2433 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed
2440 */ 2434 */
2441static void 2435static void
2442udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) 2436udp_disconnect(void *cls, const struct GNUNET_PeerIdentity *target)
2443{ 2437{
2444 struct Plugin *plugin = cls; 2438 struct Plugin *plugin = cls;
2445 2439
2446 LOG (GNUNET_ERROR_TYPE_DEBUG, 2440 LOG(GNUNET_ERROR_TYPE_DEBUG,
2447 "Disconnecting from peer `%s'\n", 2441 "Disconnecting from peer `%s'\n",
2448 GNUNET_i2s (target)); 2442 GNUNET_i2s(target));
2449 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, 2443 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions,
2450 target, 2444 target,
2451 &disconnect_and_free_it, 2445 &disconnect_and_free_it,
2452 plugin); 2446 plugin);
2453} 2447}
2454 2448
2455 2449
@@ -2459,29 +2453,29 @@ udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
2459 * @param cls the `struct GNUNET_ATS_Session` to time out 2453 * @param cls the `struct GNUNET_ATS_Session` to time out
2460 */ 2454 */
2461static void 2455static void
2462session_timeout (void *cls) 2456session_timeout(void *cls)
2463{ 2457{
2464 struct GNUNET_ATS_Session *s = cls; 2458 struct GNUNET_ATS_Session *s = cls;
2465 struct Plugin *plugin = s->plugin; 2459 struct Plugin *plugin = s->plugin;
2466 struct GNUNET_TIME_Relative left; 2460 struct GNUNET_TIME_Relative left;
2467 2461
2468 s->timeout_task = NULL; 2462 s->timeout_task = NULL;
2469 left = GNUNET_TIME_absolute_get_remaining (s->timeout); 2463 left = GNUNET_TIME_absolute_get_remaining(s->timeout);
2470 if (left.rel_value_us > 0) 2464 if (left.rel_value_us > 0)
2471 { 2465 {
2472 /* not actually our turn yet, but let's at least update 2466 /* not actually our turn yet, but let's at least update
2473 the monitor, it may think we're about to die ... */ 2467 the monitor, it may think we're about to die ... */
2474 notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); 2468 notify_session_monitor(s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
2475 s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, &session_timeout, s); 2469 s->timeout_task = GNUNET_SCHEDULER_add_delayed(left, &session_timeout, s);
2476 return; 2470 return;
2477 } 2471 }
2478 LOG (GNUNET_ERROR_TYPE_DEBUG, 2472 LOG(GNUNET_ERROR_TYPE_DEBUG,
2479 "Session %p was idle for %s, disconnecting\n", 2473 "Session %p was idle for %s, disconnecting\n",
2480 s, 2474 s,
2481 GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT, 2475 GNUNET_STRINGS_relative_time_to_string(UDP_SESSION_TIME_OUT,
2482 GNUNET_YES)); 2476 GNUNET_YES));
2483 /* call session destroy function */ 2477 /* call session destroy function */
2484 udp_disconnect_session (plugin, s); 2478 udp_disconnect_session(plugin, s);
2485} 2479}
2486 2480
2487 2481
@@ -2497,46 +2491,46 @@ session_timeout (void *cls)
2497 * @return NULL on error, otherwise session handle 2491 * @return NULL on error, otherwise session handle
2498 */ 2492 */
2499static struct GNUNET_ATS_Session * 2493static struct GNUNET_ATS_Session *
2500udp_plugin_create_session (void *cls, 2494udp_plugin_create_session(void *cls,
2501 const struct GNUNET_HELLO_Address *address, 2495 const struct GNUNET_HELLO_Address *address,
2502 enum GNUNET_NetworkType network_type) 2496 enum GNUNET_NetworkType network_type)
2503{ 2497{
2504 struct Plugin *plugin = cls; 2498 struct Plugin *plugin = cls;
2505 struct GNUNET_ATS_Session *s; 2499 struct GNUNET_ATS_Session *s;
2506 2500
2507 s = GNUNET_new (struct GNUNET_ATS_Session); 2501 s = GNUNET_new(struct GNUNET_ATS_Session);
2508 s->mst = GNUNET_MST_create (&process_inbound_tokenized_messages, s); 2502 s->mst = GNUNET_MST_create(&process_inbound_tokenized_messages, s);
2509 s->plugin = plugin; 2503 s->plugin = plugin;
2510 s->address = GNUNET_HELLO_address_copy (address); 2504 s->address = GNUNET_HELLO_address_copy(address);
2511 s->target = address->peer; 2505 s->target = address->peer;
2512 s->last_transmit_time = GNUNET_TIME_absolute_get (); 2506 s->last_transmit_time = GNUNET_TIME_absolute_get();
2513 s->last_expected_ack_delay = 2507 s->last_expected_ack_delay =
2514 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250); 2508 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250);
2515 s->last_expected_msg_delay = GNUNET_TIME_UNIT_MILLISECONDS; 2509 s->last_expected_msg_delay = GNUNET_TIME_UNIT_MILLISECONDS;
2516 s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO; 2510 s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO;
2517 s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO; 2511 s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO;
2518 s->timeout = GNUNET_TIME_relative_to_absolute (UDP_SESSION_TIME_OUT); 2512 s->timeout = GNUNET_TIME_relative_to_absolute(UDP_SESSION_TIME_OUT);
2519 s->timeout_task = 2513 s->timeout_task =
2520 GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, &session_timeout, s); 2514 GNUNET_SCHEDULER_add_delayed(UDP_SESSION_TIME_OUT, &session_timeout, s);
2521 s->scope = network_type; 2515 s->scope = network_type;
2522 2516
2523 LOG (GNUNET_ERROR_TYPE_DEBUG, 2517 LOG(GNUNET_ERROR_TYPE_DEBUG,
2524 "Creating new session %p for peer `%s' address `%s'\n", 2518 "Creating new session %p for peer `%s' address `%s'\n",
2525 s, 2519 s,
2526 GNUNET_i2s (&address->peer), 2520 GNUNET_i2s(&address->peer),
2527 udp_address_to_string (plugin, 2521 udp_address_to_string(plugin,
2528 address->address, 2522 address->address,
2529 address->address_length)); 2523 address->address_length));
2530 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_put ( 2524 GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multipeermap_put(
2531 plugin->sessions, 2525 plugin->sessions,
2532 &s->target, 2526 &s->target,
2533 s, 2527 s,
2534 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 2528 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
2535 GNUNET_STATISTICS_set (plugin->env->stats, 2529 GNUNET_STATISTICS_set(plugin->env->stats,
2536 "# UDP sessions active", 2530 "# UDP sessions active",
2537 GNUNET_CONTAINER_multipeermap_size (plugin->sessions), 2531 GNUNET_CONTAINER_multipeermap_size(plugin->sessions),
2538 GNUNET_NO); 2532 GNUNET_NO);
2539 notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_INIT); 2533 notify_session_monitor(plugin, s, GNUNET_TRANSPORT_SS_INIT);
2540 return s; 2534 return s;
2541} 2535}
2542 2536
@@ -2550,7 +2544,7 @@ udp_plugin_create_session (void *cls,
2550 * @return the session or NULL of max connections exceeded 2544 * @return the session or NULL of max connections exceeded
2551 */ 2545 */
2552static struct GNUNET_ATS_Session * 2546static struct GNUNET_ATS_Session *
2553udp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) 2547udp_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address)
2554{ 2548{
2555 struct Plugin *plugin = cls; 2549 struct Plugin *plugin = cls;
2556 struct GNUNET_ATS_Session *s; 2550 struct GNUNET_ATS_Session *s;
@@ -2559,54 +2553,54 @@ udp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
2559 const struct IPv6UdpAddress *udp_v6; 2553 const struct IPv6UdpAddress *udp_v6;
2560 2554
2561 if (NULL == address) 2555 if (NULL == address)
2562 { 2556 {
2563 GNUNET_break (0); 2557 GNUNET_break(0);
2564 return NULL; 2558 return NULL;
2565 } 2559 }
2566 if ((address->address_length != sizeof (struct IPv4UdpAddress)) && 2560 if ((address->address_length != sizeof(struct IPv4UdpAddress)) &&
2567 (address->address_length != sizeof (struct IPv6UdpAddress))) 2561 (address->address_length != sizeof(struct IPv6UdpAddress)))
2568 { 2562 {
2569 GNUNET_break_op (0); 2563 GNUNET_break_op(0);
2570 return NULL; 2564 return NULL;
2571 } 2565 }
2572 if (NULL != (s = udp_plugin_lookup_session (cls, address))) 2566 if (NULL != (s = udp_plugin_lookup_session(cls, address)))
2573 return s; 2567 return s;
2574 2568
2575 /* need to create new session */ 2569 /* need to create new session */
2576 if (sizeof (struct IPv4UdpAddress) == address->address_length) 2570 if (sizeof(struct IPv4UdpAddress) == address->address_length)
2577 { 2571 {
2578 struct sockaddr_in v4; 2572 struct sockaddr_in v4;
2579 2573
2580 udp_v4 = (const struct IPv4UdpAddress *) address->address; 2574 udp_v4 = (const struct IPv4UdpAddress *)address->address;
2581 memset (&v4, '\0', sizeof (v4)); 2575 memset(&v4, '\0', sizeof(v4));
2582 v4.sin_family = AF_INET; 2576 v4.sin_family = AF_INET;
2583#if HAVE_SOCKADDR_IN_SIN_LEN 2577#if HAVE_SOCKADDR_IN_SIN_LEN
2584 v4.sin_len = sizeof (struct sockaddr_in); 2578 v4.sin_len = sizeof(struct sockaddr_in);
2585#endif 2579#endif
2586 v4.sin_port = udp_v4->u4_port; 2580 v4.sin_port = udp_v4->u4_port;
2587 v4.sin_addr.s_addr = udp_v4->ipv4_addr; 2581 v4.sin_addr.s_addr = udp_v4->ipv4_addr;
2588 network_type = plugin->env->get_address_type (plugin->env->cls, 2582 network_type = plugin->env->get_address_type(plugin->env->cls,
2589 (const struct sockaddr *) &v4, 2583 (const struct sockaddr *)&v4,
2590 sizeof (v4)); 2584 sizeof(v4));
2591 } 2585 }
2592 if (sizeof (struct IPv6UdpAddress) == address->address_length) 2586 if (sizeof(struct IPv6UdpAddress) == address->address_length)
2593 { 2587 {
2594 struct sockaddr_in6 v6; 2588 struct sockaddr_in6 v6;
2595 2589
2596 udp_v6 = (const struct IPv6UdpAddress *) address->address; 2590 udp_v6 = (const struct IPv6UdpAddress *)address->address;
2597 memset (&v6, '\0', sizeof (v6)); 2591 memset(&v6, '\0', sizeof(v6));
2598 v6.sin6_family = AF_INET6; 2592 v6.sin6_family = AF_INET6;
2599#if HAVE_SOCKADDR_IN_SIN_LEN 2593#if HAVE_SOCKADDR_IN_SIN_LEN
2600 v6.sin6_len = sizeof (struct sockaddr_in6); 2594 v6.sin6_len = sizeof(struct sockaddr_in6);
2601#endif 2595#endif
2602 v6.sin6_port = udp_v6->u6_port; 2596 v6.sin6_port = udp_v6->u6_port;
2603 v6.sin6_addr = udp_v6->ipv6_addr; 2597 v6.sin6_addr = udp_v6->ipv6_addr;
2604 network_type = plugin->env->get_address_type (plugin->env->cls, 2598 network_type = plugin->env->get_address_type(plugin->env->cls,
2605 (const struct sockaddr *) &v6, 2599 (const struct sockaddr *)&v6,
2606 sizeof (v6)); 2600 sizeof(v6));
2607 } 2601 }
2608 GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type); 2602 GNUNET_break(GNUNET_NT_UNSPECIFIED != network_type);
2609 return udp_plugin_create_session (cls, address, network_type); 2603 return udp_plugin_create_session(cls, address, network_type);
2610} 2604}
2611 2605
2612 2606
@@ -2620,50 +2614,50 @@ udp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
2620 * @param network_type network type the address belongs to 2614 * @param network_type network type the address belongs to
2621 */ 2615 */
2622static void 2616static void
2623process_udp_message (struct Plugin *plugin, 2617process_udp_message(struct Plugin *plugin,
2624 const struct UDPMessage *msg, 2618 const struct UDPMessage *msg,
2625 const union UdpAddress *udp_addr, 2619 const union UdpAddress *udp_addr,
2626 size_t udp_addr_len, 2620 size_t udp_addr_len,
2627 enum GNUNET_NetworkType network_type) 2621 enum GNUNET_NetworkType network_type)
2628{ 2622{
2629 struct GNUNET_ATS_Session *s; 2623 struct GNUNET_ATS_Session *s;
2630 struct GNUNET_HELLO_Address *address; 2624 struct GNUNET_HELLO_Address *address;
2631 2625
2632 GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type); 2626 GNUNET_break(GNUNET_NT_UNSPECIFIED != network_type);
2633 if (0 != ntohl (msg->reserved)) 2627 if (0 != ntohl(msg->reserved))
2634 { 2628 {
2635 GNUNET_break_op (0); 2629 GNUNET_break_op(0);
2636 return; 2630 return;
2637 } 2631 }
2638 if (ntohs (msg->header.size) < 2632 if (ntohs(msg->header.size) <
2639 sizeof (struct GNUNET_MessageHeader) + sizeof (struct UDPMessage)) 2633 sizeof(struct GNUNET_MessageHeader) + sizeof(struct UDPMessage))
2640 { 2634 {
2641 GNUNET_break_op (0); 2635 GNUNET_break_op(0);
2642 return; 2636 return;
2643 } 2637 }
2644 2638
2645 address = GNUNET_HELLO_address_allocate (&msg->sender, 2639 address = GNUNET_HELLO_address_allocate(&msg->sender,
2646 PLUGIN_NAME, 2640 PLUGIN_NAME,
2647 udp_addr, 2641 udp_addr,
2648 udp_addr_len, 2642 udp_addr_len,
2649 GNUNET_HELLO_ADDRESS_INFO_NONE); 2643 GNUNET_HELLO_ADDRESS_INFO_NONE);
2650 if (NULL == (s = udp_plugin_lookup_session (plugin, address))) 2644 if (NULL == (s = udp_plugin_lookup_session(plugin, address)))
2651 { 2645 {
2652 s = udp_plugin_create_session (plugin, address, network_type); 2646 s = udp_plugin_create_session(plugin, address, network_type);
2653 plugin->env->session_start (plugin->env->cls, address, s, s->scope); 2647 plugin->env->session_start(plugin->env->cls, address, s, s->scope);
2654 notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_UP); 2648 notify_session_monitor(plugin, s, GNUNET_TRANSPORT_SS_UP);
2655 } 2649 }
2656 GNUNET_free (address); 2650 GNUNET_free(address);
2657 2651
2658 s->rc++; 2652 s->rc++;
2659 GNUNET_MST_from_buffer (s->mst, 2653 GNUNET_MST_from_buffer(s->mst,
2660 (const char *) &msg[1], 2654 (const char *)&msg[1],
2661 ntohs (msg->header.size) - sizeof (struct UDPMessage), 2655 ntohs(msg->header.size) - sizeof(struct UDPMessage),
2662 GNUNET_YES, 2656 GNUNET_YES,
2663 GNUNET_NO); 2657 GNUNET_NO);
2664 s->rc--; 2658 s->rc--;
2665 if ((0 == s->rc) && (GNUNET_YES == s->in_destroy)) 2659 if ((0 == s->rc) && (GNUNET_YES == s->in_destroy))
2666 free_session (s); 2660 free_session(s);
2667} 2661}
2668 2662
2669 2663
@@ -2674,29 +2668,29 @@ process_udp_message (struct Plugin *plugin,
2674 * @param msg the message 2668 * @param msg the message
2675 */ 2669 */
2676static void 2670static void
2677fragment_msg_proc (void *cls, const struct GNUNET_MessageHeader *msg) 2671fragment_msg_proc(void *cls, const struct GNUNET_MessageHeader *msg)
2678{ 2672{
2679 struct DefragContext *dc = cls; 2673 struct DefragContext *dc = cls;
2680 const struct UDPMessage *um; 2674 const struct UDPMessage *um;
2681 2675
2682 if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE) 2676 if (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE)
2683 { 2677 {
2684 GNUNET_break_op (0); 2678 GNUNET_break_op(0);
2685 return; 2679 return;
2686 } 2680 }
2687 if (ntohs (msg->size) < sizeof (struct UDPMessage)) 2681 if (ntohs(msg->size) < sizeof(struct UDPMessage))
2688 { 2682 {
2689 GNUNET_break_op (0); 2683 GNUNET_break_op(0);
2690 return; 2684 return;
2691 } 2685 }
2692 um = (const struct UDPMessage *) msg; 2686 um = (const struct UDPMessage *)msg;
2693 dc->sender = um->sender; 2687 dc->sender = um->sender;
2694 dc->have_sender = GNUNET_YES; 2688 dc->have_sender = GNUNET_YES;
2695 process_udp_message (dc->plugin, 2689 process_udp_message(dc->plugin,
2696 um, 2690 um,
2697 dc->udp_addr, 2691 dc->udp_addr,
2698 dc->udp_addr_len, 2692 dc->udp_addr_len,
2699 dc->network_type); 2693 dc->network_type);
2700} 2694}
2701 2695
2702 2696
@@ -2710,24 +2704,24 @@ fragment_msg_proc (void *cls, const struct GNUNET_MessageHeader *msg)
2710 * #GNUNET_SYSERR if we failed to send the ACK 2704 * #GNUNET_SYSERR if we failed to send the ACK
2711 */ 2705 */
2712static void 2706static void
2713ack_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result) 2707ack_message_sent(void *cls, struct UDP_MessageWrapper *udpw, int result)
2714{ 2708{
2715 struct Plugin *plugin = cls; 2709 struct Plugin *plugin = cls;
2716 2710
2717 if (GNUNET_OK == result) 2711 if (GNUNET_OK == result)
2718 { 2712 {
2719 GNUNET_STATISTICS_update (plugin->env->stats, 2713 GNUNET_STATISTICS_update(plugin->env->stats,
2720 "# UDP, ACK messages sent", 2714 "# UDP, ACK messages sent",
2721 1, 2715 1,
2722 GNUNET_NO); 2716 GNUNET_NO);
2723 } 2717 }
2724 else 2718 else
2725 { 2719 {
2726 GNUNET_STATISTICS_update (plugin->env->stats, 2720 GNUNET_STATISTICS_update(plugin->env->stats,
2727 "# UDP, ACK transmissions failed", 2721 "# UDP, ACK transmissions failed",
2728 1, 2722 1,
2729 GNUNET_NO); 2723 GNUNET_NO);
2730 } 2724 }
2731} 2725}
2732 2726
2733 2727
@@ -2739,11 +2733,11 @@ ack_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result)
2739 * @param msg ack to transmit 2733 * @param msg ack to transmit
2740 */ 2734 */
2741static void 2735static void
2742ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) 2736ack_proc(void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
2743{ 2737{
2744 struct DefragContext *rc = cls; 2738 struct DefragContext *rc = cls;
2745 struct Plugin *plugin = rc->plugin; 2739 struct Plugin *plugin = rc->plugin;
2746 size_t msize = sizeof (struct UDP_ACK_Message) + ntohs (msg->size); 2740 size_t msize = sizeof(struct UDP_ACK_Message) + ntohs(msg->size);
2747 struct UDP_ACK_Message *udp_ack; 2741 struct UDP_ACK_Message *udp_ack;
2748 uint32_t delay; 2742 uint32_t delay;
2749 struct UDP_MessageWrapper *udpw; 2743 struct UDP_MessageWrapper *udpw;
@@ -2751,36 +2745,36 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
2751 struct GNUNET_HELLO_Address *address; 2745 struct GNUNET_HELLO_Address *address;
2752 2746
2753 if (GNUNET_NO == rc->have_sender) 2747 if (GNUNET_NO == rc->have_sender)
2754 { 2748 {
2755 /* tried to defragment but never succeeded, hence will not ACK */ 2749 /* tried to defragment but never succeeded, hence will not ACK */
2756 /* This can happen if we just lost msgs */ 2750 /* This can happen if we just lost msgs */
2757 GNUNET_STATISTICS_update (plugin->env->stats, 2751 GNUNET_STATISTICS_update(plugin->env->stats,
2758 "# UDP, fragments discarded without ACK", 2752 "# UDP, fragments discarded without ACK",
2759 1, 2753 1,
2760 GNUNET_NO); 2754 GNUNET_NO);
2761 return; 2755 return;
2762 } 2756 }
2763 address = GNUNET_HELLO_address_allocate (&rc->sender, 2757 address = GNUNET_HELLO_address_allocate(&rc->sender,
2764 PLUGIN_NAME, 2758 PLUGIN_NAME,
2765 rc->udp_addr, 2759 rc->udp_addr,
2766 rc->udp_addr_len, 2760 rc->udp_addr_len,
2767 GNUNET_HELLO_ADDRESS_INFO_NONE); 2761 GNUNET_HELLO_ADDRESS_INFO_NONE);
2768 s = udp_plugin_lookup_session (plugin, address); 2762 s = udp_plugin_lookup_session(plugin, address);
2769 GNUNET_HELLO_address_free (address); 2763 GNUNET_HELLO_address_free(address);
2770 if (NULL == s) 2764 if (NULL == s)
2771 { 2765 {
2772 LOG (GNUNET_ERROR_TYPE_ERROR, 2766 LOG(GNUNET_ERROR_TYPE_ERROR,
2773 "Trying to transmit ACK to peer `%s' but no session found!\n", 2767 "Trying to transmit ACK to peer `%s' but no session found!\n",
2774 udp_address_to_string (plugin, rc->udp_addr, rc->udp_addr_len)); 2768 udp_address_to_string(plugin, rc->udp_addr, rc->udp_addr_len));
2775 GNUNET_CONTAINER_heap_remove_node (rc->hnode); 2769 GNUNET_CONTAINER_heap_remove_node(rc->hnode);
2776 GNUNET_DEFRAGMENT_context_destroy (rc->defrag); 2770 GNUNET_DEFRAGMENT_context_destroy(rc->defrag);
2777 GNUNET_free (rc); 2771 GNUNET_free(rc);
2778 GNUNET_STATISTICS_update (plugin->env->stats, 2772 GNUNET_STATISTICS_update(plugin->env->stats,
2779 "# UDP, ACK transmissions failed", 2773 "# UDP, ACK transmissions failed",
2780 1, 2774 1,
2781 GNUNET_NO); 2775 GNUNET_NO);
2782 return; 2776 return;
2783 } 2777 }
2784 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == 2778 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us ==
2785 s->flow_delay_for_other_peer.rel_value_us) 2779 s->flow_delay_for_other_peer.rel_value_us)
2786 delay = UINT32_MAX; 2780 delay = UINT32_MAX;
@@ -2788,32 +2782,32 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
2788 delay = s->flow_delay_for_other_peer.rel_value_us; 2782 delay = s->flow_delay_for_other_peer.rel_value_us;
2789 else 2783 else
2790 delay = UINT32_MAX - 1; /* largest value we can communicate */ 2784 delay = UINT32_MAX - 1; /* largest value we can communicate */
2791 LOG (GNUNET_ERROR_TYPE_DEBUG, 2785 LOG(GNUNET_ERROR_TYPE_DEBUG,
2792 "Sending ACK to `%s' including delay of %s\n", 2786 "Sending ACK to `%s' including delay of %s\n",
2793 udp_address_to_string (plugin, rc->udp_addr, rc->udp_addr_len), 2787 udp_address_to_string(plugin, rc->udp_addr, rc->udp_addr_len),
2794 GNUNET_STRINGS_relative_time_to_string (s->flow_delay_for_other_peer, 2788 GNUNET_STRINGS_relative_time_to_string(s->flow_delay_for_other_peer,
2795 GNUNET_YES)); 2789 GNUNET_YES));
2796 udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msize); 2790 udpw = GNUNET_malloc(sizeof(struct UDP_MessageWrapper) + msize);
2797 udpw->msg_size = msize; 2791 udpw->msg_size = msize;
2798 udpw->payload_size = 0; 2792 udpw->payload_size = 0;
2799 udpw->session = s; 2793 udpw->session = s;
2800 udpw->start_time = GNUNET_TIME_absolute_get (); 2794 udpw->start_time = GNUNET_TIME_absolute_get();
2801 udpw->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; 2795 udpw->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
2802 udpw->msg_buf = (char *) &udpw[1]; 2796 udpw->msg_buf = (char *)&udpw[1];
2803 udpw->qc = &ack_message_sent; 2797 udpw->qc = &ack_message_sent;
2804 udpw->qc_cls = plugin; 2798 udpw->qc_cls = plugin;
2805 udp_ack = (struct UDP_ACK_Message *) udpw->msg_buf; 2799 udp_ack = (struct UDP_ACK_Message *)udpw->msg_buf;
2806 udp_ack->header.size = htons ((uint16_t) msize); 2800 udp_ack->header.size = htons((uint16_t)msize);
2807 udp_ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK); 2801 udp_ack->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK);
2808 udp_ack->delay = htonl (delay); 2802 udp_ack->delay = htonl(delay);
2809 udp_ack->sender = *plugin->env->my_identity; 2803 udp_ack->sender = *plugin->env->my_identity;
2810 GNUNET_memcpy (&udp_ack[1], msg, ntohs (msg->size)); 2804 GNUNET_memcpy(&udp_ack[1], msg, ntohs(msg->size));
2811 enqueue (plugin, udpw); 2805 enqueue(plugin, udpw);
2812 notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_UPDATE); 2806 notify_session_monitor(plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
2813 if (s->address->address_length == sizeof (struct IPv4UdpAddress)) 2807 if (s->address->address_length == sizeof(struct IPv4UdpAddress))
2814 schedule_select_v4 (plugin); 2808 schedule_select_v4(plugin);
2815 else 2809 else
2816 schedule_select_v6 (plugin); 2810 schedule_select_v6(plugin);
2817} 2811}
2818 2812
2819 2813
@@ -2827,11 +2821,11 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
2827 * @param network_type network type the address belongs to 2821 * @param network_type network type the address belongs to
2828 */ 2822 */
2829static void 2823static void
2830read_process_fragment (struct Plugin *plugin, 2824read_process_fragment(struct Plugin *plugin,
2831 const struct GNUNET_MessageHeader *msg, 2825 const struct GNUNET_MessageHeader *msg,
2832 const union UdpAddress *udp_addr, 2826 const union UdpAddress *udp_addr,
2833 size_t udp_addr_len, 2827 size_t udp_addr_len,
2834 enum GNUNET_NetworkType network_type) 2828 enum GNUNET_NetworkType network_type)
2835{ 2829{
2836 struct DefragContext *d_ctx; 2830 struct DefragContext *d_ctx;
2837 struct GNUNET_TIME_Absolute now; 2831 struct GNUNET_TIME_Absolute now;
@@ -2842,65 +2836,65 @@ read_process_fragment (struct Plugin *plugin,
2842 frc.udp_addr_len = udp_addr_len; 2836 frc.udp_addr_len = udp_addr_len;
2843 2837
2844 /* Lookup existing receive context for this address */ 2838 /* Lookup existing receive context for this address */
2845 GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, 2839 GNUNET_CONTAINER_heap_iterate(plugin->defrag_ctxs,
2846 &find_receive_context, 2840 &find_receive_context,
2847 &frc); 2841 &frc);
2848 now = GNUNET_TIME_absolute_get (); 2842 now = GNUNET_TIME_absolute_get();
2849 d_ctx = frc.rc; 2843 d_ctx = frc.rc;
2850 2844
2851 if (NULL == d_ctx) 2845 if (NULL == d_ctx)
2852 { 2846 {
2853 /* Create a new defragmentation context */ 2847 /* Create a new defragmentation context */
2854 d_ctx = GNUNET_malloc (sizeof (struct DefragContext) + udp_addr_len); 2848 d_ctx = GNUNET_malloc(sizeof(struct DefragContext) + udp_addr_len);
2855 GNUNET_memcpy (&d_ctx[1], udp_addr, udp_addr_len); 2849 GNUNET_memcpy(&d_ctx[1], udp_addr, udp_addr_len);
2856 d_ctx->udp_addr = (const union UdpAddress *) &d_ctx[1]; 2850 d_ctx->udp_addr = (const union UdpAddress *)&d_ctx[1];
2857 d_ctx->udp_addr_len = udp_addr_len; 2851 d_ctx->udp_addr_len = udp_addr_len;
2858 d_ctx->network_type = network_type; 2852 d_ctx->network_type = network_type;
2859 d_ctx->plugin = plugin; 2853 d_ctx->plugin = plugin;
2860 d_ctx->defrag = 2854 d_ctx->defrag =
2861 GNUNET_DEFRAGMENT_context_create (plugin->env->stats, 2855 GNUNET_DEFRAGMENT_context_create(plugin->env->stats,
2862 UDP_MTU, 2856 UDP_MTU,
2863 UDP_MAX_MESSAGES_IN_DEFRAG, 2857 UDP_MAX_MESSAGES_IN_DEFRAG,
2864 d_ctx, 2858 d_ctx,
2865 &fragment_msg_proc, 2859 &fragment_msg_proc,
2866 &ack_proc); 2860 &ack_proc);
2867 d_ctx->hnode = GNUNET_CONTAINER_heap_insert (plugin->defrag_ctxs, 2861 d_ctx->hnode = GNUNET_CONTAINER_heap_insert(plugin->defrag_ctxs,
2868 d_ctx, 2862 d_ctx,
2869 (GNUNET_CONTAINER_HeapCostType) 2863 (GNUNET_CONTAINER_HeapCostType)
2870 now.abs_value_us); 2864 now.abs_value_us);
2871 LOG (GNUNET_ERROR_TYPE_DEBUG, 2865 LOG(GNUNET_ERROR_TYPE_DEBUG,
2872 "Created new defragmentation context for %u-byte fragment from `%s'\n", 2866 "Created new defragmentation context for %u-byte fragment from `%s'\n",
2873 (unsigned int) ntohs (msg->size), 2867 (unsigned int)ntohs(msg->size),
2874 udp_address_to_string (plugin, udp_addr, udp_addr_len)); 2868 udp_address_to_string(plugin, udp_addr, udp_addr_len));
2875 } 2869 }
2876 else 2870 else
2877 { 2871 {
2878 LOG (GNUNET_ERROR_TYPE_DEBUG, 2872 LOG(GNUNET_ERROR_TYPE_DEBUG,
2879 "Found existing defragmentation context for %u-byte fragment from `%s'\n", 2873 "Found existing defragmentation context for %u-byte fragment from `%s'\n",
2880 (unsigned int) ntohs (msg->size), 2874 (unsigned int)ntohs(msg->size),
2881 udp_address_to_string (plugin, udp_addr, udp_addr_len)); 2875 udp_address_to_string(plugin, udp_addr, udp_addr_len));
2882 } 2876 }
2883 2877
2884 if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (d_ctx->defrag, msg)) 2878 if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment(d_ctx->defrag, msg))
2885 { 2879 {
2886 /* keep this 'rc' from expiring */ 2880 /* keep this 'rc' from expiring */
2887 GNUNET_CONTAINER_heap_update_cost (d_ctx->hnode, 2881 GNUNET_CONTAINER_heap_update_cost(d_ctx->hnode,
2888 (GNUNET_CONTAINER_HeapCostType) 2882 (GNUNET_CONTAINER_HeapCostType)
2889 now.abs_value_us); 2883 now.abs_value_us);
2890 } 2884 }
2891 if (GNUNET_CONTAINER_heap_get_size (plugin->defrag_ctxs) > 2885 if (GNUNET_CONTAINER_heap_get_size(plugin->defrag_ctxs) >
2892 UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG) 2886 UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG)
2893 { 2887 {
2894 /* remove 'rc' that was inactive the longest */ 2888 /* remove 'rc' that was inactive the longest */
2895 d_ctx = GNUNET_CONTAINER_heap_remove_root (plugin->defrag_ctxs); 2889 d_ctx = GNUNET_CONTAINER_heap_remove_root(plugin->defrag_ctxs);
2896 GNUNET_assert (NULL != d_ctx); 2890 GNUNET_assert(NULL != d_ctx);
2897 GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag); 2891 GNUNET_DEFRAGMENT_context_destroy(d_ctx->defrag);
2898 GNUNET_free (d_ctx); 2892 GNUNET_free(d_ctx);
2899 GNUNET_STATISTICS_update (plugin->env->stats, 2893 GNUNET_STATISTICS_update(plugin->env->stats,
2900 "# UDP, Defragmentations aborted", 2894 "# UDP, Defragmentations aborted",
2901 1, 2895 1,
2902 GNUNET_NO); 2896 GNUNET_NO);
2903 } 2897 }
2904} 2898}
2905 2899
2906 2900
@@ -2911,7 +2905,7 @@ read_process_fragment (struct Plugin *plugin,
2911 * @param rsock socket to read from 2905 * @param rsock socket to read from
2912 */ 2906 */
2913static void 2907static void
2914udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) 2908udp_select_read(struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
2915{ 2909{
2916 socklen_t fromlen; 2910 socklen_t fromlen;
2917 struct sockaddr_storage addr; 2911 struct sockaddr_storage addr;
@@ -2927,14 +2921,14 @@ udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
2927 size_t int_addr_len; 2921 size_t int_addr_len;
2928 enum GNUNET_NetworkType network_type; 2922 enum GNUNET_NetworkType network_type;
2929 2923
2930 fromlen = sizeof (addr); 2924 fromlen = sizeof(addr);
2931 memset (&addr, 0, sizeof (addr)); 2925 memset(&addr, 0, sizeof(addr));
2932 size = GNUNET_NETWORK_socket_recvfrom (rsock, 2926 size = GNUNET_NETWORK_socket_recvfrom(rsock,
2933 buf, 2927 buf,
2934 sizeof (buf), 2928 sizeof(buf),
2935 (struct sockaddr *) &addr, 2929 (struct sockaddr *)&addr,
2936 &fromlen); 2930 &fromlen);
2937 sa = (const struct sockaddr *) &addr; 2931 sa = (const struct sockaddr *)&addr;
2938#if MINGW 2932#if MINGW
2939 /* On SOCK_DGRAM UDP sockets recvfrom might fail with a 2933 /* On SOCK_DGRAM UDP sockets recvfrom might fail with a
2940 * WSAECONNRESET error to indicate that previous sendto() (yes, sendto!) 2934 * WSAECONNRESET error to indicate that previous sendto() (yes, sendto!)
@@ -2950,111 +2944,117 @@ udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
2950 return; 2944 return;
2951#endif 2945#endif
2952 if (-1 == size) 2946 if (-1 == size)
2953 { 2947 {
2954 LOG (GNUNET_ERROR_TYPE_DEBUG, 2948 LOG(GNUNET_ERROR_TYPE_DEBUG,
2955 "UDP failed to receive data: %s\n", 2949 "UDP failed to receive data: %s\n",
2956 strerror (errno)); 2950 strerror(errno));
2957 /* Connection failure or something. Not a protocol violation. */ 2951 /* Connection failure or something. Not a protocol violation. */
2958 return; 2952 return;
2959 } 2953 }
2960 2954
2961 /* Check if this is a STUN packet */ 2955 /* Check if this is a STUN packet */
2962 if (GNUNET_NO != 2956 if (GNUNET_NO !=
2963 GNUNET_NAT_stun_handle_packet (plugin->nat, 2957 GNUNET_NAT_stun_handle_packet(plugin->nat,
2964 (const struct sockaddr *) &addr, 2958 (const struct sockaddr *)&addr,
2965 fromlen, 2959 fromlen,
2966 buf, 2960 buf,
2967 size)) 2961 size))
2968 return; /* was STUN, do not process further */ 2962 return; /* was STUN, do not process further */
2969 2963
2970 if (size < sizeof (struct GNUNET_MessageHeader)) 2964 if (size < sizeof(struct GNUNET_MessageHeader))
2971 { 2965 {
2972 LOG (GNUNET_ERROR_TYPE_WARNING, 2966 LOG(GNUNET_ERROR_TYPE_WARNING,
2973 "UDP got %u bytes from %s, which is not enough for a GNUnet message header\n", 2967 "UDP got %u bytes from %s, which is not enough for a GNUnet message header\n",
2974 (unsigned int) size, 2968 (unsigned int)size,
2975 GNUNET_a2s (sa, fromlen)); 2969 GNUNET_a2s(sa, fromlen));
2976 /* _MAY_ be a connection failure (got partial message) */ 2970 /* _MAY_ be a connection failure (got partial message) */
2977 /* But it _MAY_ also be that the other side uses non-GNUnet protocol. */ 2971 /* But it _MAY_ also be that the other side uses non-GNUnet protocol. */
2978 GNUNET_break_op (0); 2972 GNUNET_break_op(0);
2979 return; 2973 return;
2980 } 2974 }
2981 2975
2982 msg = (const struct GNUNET_MessageHeader *) buf; 2976 msg = (const struct GNUNET_MessageHeader *)buf;
2983 LOG (GNUNET_ERROR_TYPE_DEBUG, 2977 LOG(GNUNET_ERROR_TYPE_DEBUG,
2984 "UDP received %u-byte message from `%s' type %u\n", 2978 "UDP received %u-byte message from `%s' type %u\n",
2985 (unsigned int) size, 2979 (unsigned int)size,
2986 GNUNET_a2s (sa, fromlen), 2980 GNUNET_a2s(sa, fromlen),
2987 ntohs (msg->type)); 2981 ntohs(msg->type));
2988 if (size != ntohs (msg->size)) 2982 if (size != ntohs(msg->size))
2989 { 2983 {
2990 LOG (GNUNET_ERROR_TYPE_WARNING, 2984 LOG(GNUNET_ERROR_TYPE_WARNING,
2991 "UDP malformed message (size %u) header from %s\n", 2985 "UDP malformed message (size %u) header from %s\n",
2992 (unsigned int) size, 2986 (unsigned int)size,
2993 GNUNET_a2s (sa, fromlen)); 2987 GNUNET_a2s(sa, fromlen));
2994 GNUNET_break_op (0); 2988 GNUNET_break_op(0);
2995 return; 2989 return;
2996 } 2990 }
2997 GNUNET_STATISTICS_update (plugin->env->stats, 2991 GNUNET_STATISTICS_update(plugin->env->stats,
2998 "# UDP, total bytes received", 2992 "# UDP, total bytes received",
2999 size, 2993 size,
3000 GNUNET_NO); 2994 GNUNET_NO);
3001 network_type = plugin->env->get_address_type (plugin->env->cls, sa, fromlen); 2995 network_type = plugin->env->get_address_type(plugin->env->cls, sa, fromlen);
3002 switch (sa->sa_family) 2996 switch (sa->sa_family)
3003 {
3004 case AF_INET:
3005 sa4 = (const struct sockaddr_in *) &addr;
3006 v4.options = 0;
3007 v4.ipv4_addr = sa4->sin_addr.s_addr;
3008 v4.u4_port = sa4->sin_port;
3009 int_addr = (union UdpAddress *) &v4;
3010 int_addr_len = sizeof (v4);
3011 break;
3012 case AF_INET6:
3013 sa6 = (const struct sockaddr_in6 *) &addr;
3014 v6.options = 0;
3015 v6.ipv6_addr = sa6->sin6_addr;
3016 v6.u6_port = sa6->sin6_port;
3017 int_addr = (union UdpAddress *) &v6;
3018 int_addr_len = sizeof (v6);
3019 break;
3020 default:
3021 GNUNET_break (0);
3022 return;
3023 }
3024
3025 switch (ntohs (msg->type))
3026 {
3027 case GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON:
3028 if (GNUNET_YES == plugin->enable_broadcasting_receiving)
3029 udp_broadcast_receive (plugin,
3030 buf,
3031 size,
3032 int_addr,
3033 int_addr_len,
3034 network_type);
3035 return;
3036 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE:
3037 if (ntohs (msg->size) < sizeof (struct UDPMessage))
3038 { 2997 {
3039 GNUNET_break_op (0); 2998 case AF_INET:
2999 sa4 = (const struct sockaddr_in *)&addr;
3000 v4.options = 0;
3001 v4.ipv4_addr = sa4->sin_addr.s_addr;
3002 v4.u4_port = sa4->sin_port;
3003 int_addr = (union UdpAddress *)&v4;
3004 int_addr_len = sizeof(v4);
3005 break;
3006
3007 case AF_INET6:
3008 sa6 = (const struct sockaddr_in6 *)&addr;
3009 v6.options = 0;
3010 v6.ipv6_addr = sa6->sin6_addr;
3011 v6.u6_port = sa6->sin6_port;
3012 int_addr = (union UdpAddress *)&v6;
3013 int_addr_len = sizeof(v6);
3014 break;
3015
3016 default:
3017 GNUNET_break(0);
3018 return;
3019 }
3020
3021 switch (ntohs(msg->type))
3022 {
3023 case GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON:
3024 if (GNUNET_YES == plugin->enable_broadcasting_receiving)
3025 udp_broadcast_receive(plugin,
3026 buf,
3027 size,
3028 int_addr,
3029 int_addr_len,
3030 network_type);
3031 return;
3032
3033 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE:
3034 if (ntohs(msg->size) < sizeof(struct UDPMessage))
3035 {
3036 GNUNET_break_op(0);
3037 return;
3038 }
3039 process_udp_message(plugin,
3040 (const struct UDPMessage *)msg,
3041 int_addr,
3042 int_addr_len,
3043 network_type);
3044 return;
3045
3046 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK:
3047 read_process_ack(plugin, msg, int_addr, int_addr_len);
3048 return;
3049
3050 case GNUNET_MESSAGE_TYPE_FRAGMENT:
3051 read_process_fragment(plugin, msg, int_addr, int_addr_len, network_type);
3052 return;
3053
3054 default:
3055 GNUNET_break_op(0);
3040 return; 3056 return;
3041 } 3057 }
3042 process_udp_message (plugin,
3043 (const struct UDPMessage *) msg,
3044 int_addr,
3045 int_addr_len,
3046 network_type);
3047 return;
3048 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK:
3049 read_process_ack (plugin, msg, int_addr, int_addr_len);
3050 return;
3051 case GNUNET_MESSAGE_TYPE_FRAGMENT:
3052 read_process_fragment (plugin, msg, int_addr, int_addr_len, network_type);
3053 return;
3054 default:
3055 GNUNET_break_op (0);
3056 return;
3057 }
3058} 3058}
3059 3059
3060 3060
@@ -3068,8 +3068,8 @@ udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
3068 * @return message selected for transmission, or NULL for none 3068 * @return message selected for transmission, or NULL for none
3069 */ 3069 */
3070static struct UDP_MessageWrapper * 3070static struct UDP_MessageWrapper *
3071remove_timeout_messages_and_select (struct Plugin *plugin, 3071remove_timeout_messages_and_select(struct Plugin *plugin,
3072 struct GNUNET_NETWORK_Handle *sock) 3072 struct GNUNET_NETWORK_Handle *sock)
3073{ 3073{
3074 struct UDP_MessageWrapper *udpw; 3074 struct UDP_MessageWrapper *udpw;
3075 struct GNUNET_TIME_Relative remaining; 3075 struct GNUNET_TIME_Relative remaining;
@@ -3078,67 +3078,67 @@ remove_timeout_messages_and_select (struct Plugin *plugin,
3078 3078
3079 removed = GNUNET_NO; 3079 removed = GNUNET_NO;
3080 udpw = (sock == plugin->sockv4) ? plugin->ipv4_queue_head 3080 udpw = (sock == plugin->sockv4) ? plugin->ipv4_queue_head
3081 : plugin->ipv6_queue_head; 3081 : plugin->ipv6_queue_head;
3082 while (NULL != udpw) 3082 while (NULL != udpw)
3083 { 3083 {
3084 session = udpw->session; 3084 session = udpw->session;
3085 /* Find messages with timeout */ 3085 /* Find messages with timeout */
3086 remaining = GNUNET_TIME_absolute_get_remaining (udpw->timeout); 3086 remaining = GNUNET_TIME_absolute_get_remaining(udpw->timeout);
3087 if (GNUNET_TIME_UNIT_ZERO.rel_value_us == remaining.rel_value_us) 3087 if (GNUNET_TIME_UNIT_ZERO.rel_value_us == remaining.rel_value_us)
3088 { 3088 {
3089 /* Message timed out */ 3089 /* Message timed out */
3090 removed = GNUNET_YES; 3090 removed = GNUNET_YES;
3091 dequeue (plugin, udpw); 3091 dequeue(plugin, udpw);
3092 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); 3092 udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR);
3093 GNUNET_free (udpw); 3093 GNUNET_free(udpw);
3094 3094
3095 if (sock == plugin->sockv4) 3095 if (sock == plugin->sockv4)
3096 { 3096 {
3097 udpw = plugin->ipv4_queue_head; 3097 udpw = plugin->ipv4_queue_head;
3098 } 3098 }
3099 else if (sock == plugin->sockv6) 3099 else if (sock == plugin->sockv6)
3100 { 3100 {
3101 udpw = plugin->ipv6_queue_head; 3101 udpw = plugin->ipv6_queue_head;
3102 } 3102 }
3103 else 3103 else
3104 { 3104 {
3105 GNUNET_break (0); /* should never happen */ 3105 GNUNET_break(0); /* should never happen */
3106 udpw = NULL; 3106 udpw = NULL;
3107 } 3107 }
3108 GNUNET_STATISTICS_update (plugin->env->stats, 3108 GNUNET_STATISTICS_update(plugin->env->stats,
3109 "# messages discarded due to timeout", 3109 "# messages discarded due to timeout",
3110 1, 3110 1,
3111 GNUNET_NO); 3111 GNUNET_NO);
3112 } 3112 }
3113 else
3114 {
3115 /* Message did not time out, check transmission time */
3116 remaining = GNUNET_TIME_absolute_get_remaining (udpw->transmission_time);
3117 if (0 == remaining.rel_value_us)
3118 {
3119 /* this message is not delayed */
3120 LOG (GNUNET_ERROR_TYPE_DEBUG,
3121 "Message for peer `%s' (%u bytes) is not delayed \n",
3122 GNUNET_i2s (&udpw->session->target),
3123 udpw->payload_size);
3124 break; /* Found message to send, break */
3125 }
3126 else 3113 else
3127 { 3114 {
3128 /* Message is delayed, try next */ 3115 /* Message did not time out, check transmission time */
3129 LOG (GNUNET_ERROR_TYPE_DEBUG, 3116 remaining = GNUNET_TIME_absolute_get_remaining(udpw->transmission_time);
3130 "Message for peer `%s' (%u bytes) is delayed for %s\n", 3117 if (0 == remaining.rel_value_us)
3131 GNUNET_i2s (&udpw->session->target), 3118 {
3132 udpw->payload_size, 3119 /* this message is not delayed */
3133 GNUNET_STRINGS_relative_time_to_string (remaining, GNUNET_YES)); 3120 LOG(GNUNET_ERROR_TYPE_DEBUG,
3134 udpw = udpw->next; 3121 "Message for peer `%s' (%u bytes) is not delayed \n",
3135 } 3122 GNUNET_i2s(&udpw->session->target),
3136 } 3123 udpw->payload_size);
3137 } 3124 break; /* Found message to send, break */
3125 }
3126 else
3127 {
3128 /* Message is delayed, try next */
3129 LOG(GNUNET_ERROR_TYPE_DEBUG,
3130 "Message for peer `%s' (%u bytes) is delayed for %s\n",
3131 GNUNET_i2s(&udpw->session->target),
3132 udpw->payload_size,
3133 GNUNET_STRINGS_relative_time_to_string(remaining, GNUNET_YES));
3134 udpw = udpw->next;
3135 }
3136 }
3137 }
3138 if (GNUNET_YES == removed) 3138 if (GNUNET_YES == removed)
3139 notify_session_monitor (session->plugin, 3139 notify_session_monitor(session->plugin,
3140 session, 3140 session,
3141 GNUNET_TRANSPORT_SS_UPDATE); 3141 GNUNET_TRANSPORT_SS_UPDATE);
3142 return udpw; 3142 return udpw;
3143} 3143}
3144 3144
@@ -3153,50 +3153,50 @@ remove_timeout_messages_and_select (struct Plugin *plugin,
3153 * @param error the errno value returned from the sendto() call 3153 * @param error the errno value returned from the sendto() call
3154 */ 3154 */
3155static void 3155static void
3156analyze_send_error (struct Plugin *plugin, 3156analyze_send_error(struct Plugin *plugin,
3157 const struct sockaddr *sa, 3157 const struct sockaddr *sa,
3158 socklen_t slen, 3158 socklen_t slen,
3159 int error) 3159 int error)
3160{ 3160{
3161 enum GNUNET_NetworkType type; 3161 enum GNUNET_NetworkType type;
3162 3162
3163 type = plugin->env->get_address_type (plugin->env->cls, sa, slen); 3163 type = plugin->env->get_address_type(plugin->env->cls, sa, slen);
3164 if (((GNUNET_NT_LAN == type) || (GNUNET_NT_WAN == type)) && 3164 if (((GNUNET_NT_LAN == type) || (GNUNET_NT_WAN == type)) &&
3165 ((ENETUNREACH == errno) || (ENETDOWN == errno))) 3165 ((ENETUNREACH == errno) || (ENETDOWN == errno)))
3166 { 3166 {
3167 if (slen == sizeof (struct sockaddr_in)) 3167 if (slen == sizeof(struct sockaddr_in))
3168 { 3168 {
3169 /* IPv4: "Network unreachable" or "Network down" 3169 /* IPv4: "Network unreachable" or "Network down"
3170 * 3170 *
3171 * This indicates we do not have connectivity 3171 * This indicates we do not have connectivity
3172 */ 3172 */
3173 LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, 3173 LOG(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
3174 _ ("UDP could not transmit message to `%s': " 3174 _("UDP could not transmit message to `%s': "
3175 "Network seems down, please check your network configuration\n"), 3175 "Network seems down, please check your network configuration\n"),
3176 GNUNET_a2s (sa, slen)); 3176 GNUNET_a2s(sa, slen));
3177 } 3177 }
3178 if (slen == sizeof (struct sockaddr_in6)) 3178 if (slen == sizeof(struct sockaddr_in6))
3179 { 3179 {
3180 /* IPv6: "Network unreachable" or "Network down" 3180 /* IPv6: "Network unreachable" or "Network down"
3181 * 3181 *
3182 * This indicates that this system is IPv6 enabled, but does not 3182 * This indicates that this system is IPv6 enabled, but does not
3183 * have a valid global IPv6 address assigned or we do not have 3183 * have a valid global IPv6 address assigned or we do not have
3184 * connectivity 3184 * connectivity
3185 */ 3185 */
3186 LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, 3186 LOG(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
3187 _ ( 3187 _(
3188 "UDP could not transmit IPv6 message! " 3188 "UDP could not transmit IPv6 message! "
3189 "Please check your network configuration and disable IPv6 if your " 3189 "Please check your network configuration and disable IPv6 if your "
3190 "connection does not have a global IPv6 address\n")); 3190 "connection does not have a global IPv6 address\n"));
3191 } 3191 }
3192 } 3192 }
3193 else 3193 else
3194 { 3194 {
3195 LOG (GNUNET_ERROR_TYPE_WARNING, 3195 LOG(GNUNET_ERROR_TYPE_WARNING,
3196 "UDP could not transmit message to `%s': `%s'\n", 3196 "UDP could not transmit message to `%s': `%s'\n",
3197 GNUNET_a2s (sa, slen), 3197 GNUNET_a2s(sa, slen),
3198 strerror (error)); 3198 strerror(error));
3199 } 3199 }
3200} 3200}
3201 3201
3202 3202
@@ -3208,7 +3208,7 @@ analyze_send_error (struct Plugin *plugin,
3208 * @param sock which socket (v4/v6) to send on 3208 * @param sock which socket (v4/v6) to send on
3209 */ 3209 */
3210static void 3210static void
3211udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) 3211udp_select_send(struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
3212{ 3212{
3213 ssize_t sent; 3213 ssize_t sent;
3214 socklen_t slen; 3214 socklen_t slen;
@@ -3220,95 +3220,95 @@ udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
3220 struct UDP_MessageWrapper *udpw; 3220 struct UDP_MessageWrapper *udpw;
3221 3221
3222 /* Find message(s) to send */ 3222 /* Find message(s) to send */
3223 while (NULL != (udpw = remove_timeout_messages_and_select (plugin, sock))) 3223 while (NULL != (udpw = remove_timeout_messages_and_select(plugin, sock)))
3224 {
3225 if (sizeof (struct IPv4UdpAddress) ==
3226 udpw->session->address->address_length)
3227 { 3224 {
3228 u4 = udpw->session->address->address; 3225 if (sizeof(struct IPv4UdpAddress) ==
3229 memset (&a4, 0, sizeof (a4)); 3226 udpw->session->address->address_length)
3230 a4.sin_family = AF_INET; 3227 {
3228 u4 = udpw->session->address->address;
3229 memset(&a4, 0, sizeof(a4));
3230 a4.sin_family = AF_INET;
3231#if HAVE_SOCKADDR_IN_SIN_LEN 3231#if HAVE_SOCKADDR_IN_SIN_LEN
3232 a4.sin_len = sizeof (a4); 3232 a4.sin_len = sizeof(a4);
3233#endif 3233#endif
3234 a4.sin_port = u4->u4_port; 3234 a4.sin_port = u4->u4_port;
3235 a4.sin_addr.s_addr = u4->ipv4_addr; 3235 a4.sin_addr.s_addr = u4->ipv4_addr;
3236 a = (const struct sockaddr *) &a4; 3236 a = (const struct sockaddr *)&a4;
3237 slen = sizeof (a4); 3237 slen = sizeof(a4);
3238 } 3238 }
3239 else if (sizeof (struct IPv6UdpAddress) == 3239 else if (sizeof(struct IPv6UdpAddress) ==
3240 udpw->session->address->address_length) 3240 udpw->session->address->address_length)
3241 { 3241 {
3242 u6 = udpw->session->address->address; 3242 u6 = udpw->session->address->address;
3243 memset (&a6, 0, sizeof (a6)); 3243 memset(&a6, 0, sizeof(a6));
3244 a6.sin6_family = AF_INET6; 3244 a6.sin6_family = AF_INET6;
3245#if HAVE_SOCKADDR_IN_SIN_LEN 3245#if HAVE_SOCKADDR_IN_SIN_LEN
3246 a6.sin6_len = sizeof (a6); 3246 a6.sin6_len = sizeof(a6);
3247#endif 3247#endif
3248 a6.sin6_port = u6->u6_port; 3248 a6.sin6_port = u6->u6_port;
3249 a6.sin6_addr = u6->ipv6_addr; 3249 a6.sin6_addr = u6->ipv6_addr;
3250 a = (const struct sockaddr *) &a6; 3250 a = (const struct sockaddr *)&a6;
3251 slen = sizeof (a6); 3251 slen = sizeof(a6);
3252 } 3252 }
3253 else 3253 else
3254 { 3254 {
3255 GNUNET_break (0); 3255 GNUNET_break(0);
3256 dequeue (plugin, udpw); 3256 dequeue(plugin, udpw);
3257 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); 3257 udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR);
3258 notify_session_monitor (plugin, 3258 notify_session_monitor(plugin,
3259 udpw->session, 3259 udpw->session,
3260 GNUNET_TRANSPORT_SS_UPDATE); 3260 GNUNET_TRANSPORT_SS_UPDATE);
3261 GNUNET_free (udpw); 3261 GNUNET_free(udpw);
3262 continue; 3262 continue;
3263 } 3263 }
3264 sent = GNUNET_NETWORK_socket_sendto (sock, 3264 sent = GNUNET_NETWORK_socket_sendto(sock,
3265 udpw->msg_buf, 3265 udpw->msg_buf,
3266 udpw->msg_size, 3266 udpw->msg_size,
3267 a, 3267 a,
3268 slen); 3268 slen);
3269 udpw->session->last_transmit_time = 3269 udpw->session->last_transmit_time =
3270 GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_get (), 3270 GNUNET_TIME_absolute_max(GNUNET_TIME_absolute_get(),
3271 udpw->session->last_transmit_time); 3271 udpw->session->last_transmit_time);
3272 dequeue (plugin, udpw); 3272 dequeue(plugin, udpw);
3273 if (GNUNET_SYSERR == sent) 3273 if (GNUNET_SYSERR == sent)
3274 { 3274 {
3275 /* Failure */ 3275 /* Failure */
3276 analyze_send_error (plugin, a, slen, errno); 3276 analyze_send_error(plugin, a, slen, errno);
3277 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); 3277 udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR);
3278 GNUNET_STATISTICS_update (plugin->env->stats, 3278 GNUNET_STATISTICS_update(plugin->env->stats,
3279 "# UDP, total, bytes, sent, failure", 3279 "# UDP, total, bytes, sent, failure",
3280 sent, 3280 sent,
3281 GNUNET_NO); 3281 GNUNET_NO);
3282 GNUNET_STATISTICS_update (plugin->env->stats, 3282 GNUNET_STATISTICS_update(plugin->env->stats,
3283 "# UDP, total, messages, sent, failure", 3283 "# UDP, total, messages, sent, failure",
3284 1, 3284 1,
3285 GNUNET_NO); 3285 GNUNET_NO);
3286 } 3286 }
3287 else 3287 else
3288 { 3288 {
3289 /* Success */ 3289 /* Success */
3290 LOG (GNUNET_ERROR_TYPE_DEBUG, 3290 LOG(GNUNET_ERROR_TYPE_DEBUG,
3291 "UDP transmitted %u-byte message to `%s' `%s' (%d: %s)\n", 3291 "UDP transmitted %u-byte message to `%s' `%s' (%d: %s)\n",
3292 (unsigned int) (udpw->msg_size), 3292 (unsigned int)(udpw->msg_size),
3293 GNUNET_i2s (&udpw->session->target), 3293 GNUNET_i2s(&udpw->session->target),
3294 GNUNET_a2s (a, slen), 3294 GNUNET_a2s(a, slen),
3295 (int) sent, 3295 (int)sent,
3296 (sent < 0) ? strerror (errno) : "ok"); 3296 (sent < 0) ? strerror(errno) : "ok");
3297 GNUNET_STATISTICS_update (plugin->env->stats, 3297 GNUNET_STATISTICS_update(plugin->env->stats,
3298 "# UDP, total, bytes, sent, success", 3298 "# UDP, total, bytes, sent, success",
3299 sent, 3299 sent,
3300 GNUNET_NO); 3300 GNUNET_NO);
3301 GNUNET_STATISTICS_update (plugin->env->stats, 3301 GNUNET_STATISTICS_update(plugin->env->stats,
3302 "# UDP, total, messages, sent, success", 3302 "# UDP, total, messages, sent, success",
3303 1, 3303 1,
3304 GNUNET_NO); 3304 GNUNET_NO);
3305 if (NULL != udpw->frag_ctx) 3305 if (NULL != udpw->frag_ctx)
3306 udpw->frag_ctx->on_wire_size += udpw->msg_size; 3306 udpw->frag_ctx->on_wire_size += udpw->msg_size;
3307 udpw->qc (udpw->qc_cls, udpw, GNUNET_OK); 3307 udpw->qc(udpw->qc_cls, udpw, GNUNET_OK);
3308 } 3308 }
3309 notify_session_monitor (plugin, udpw->session, GNUNET_TRANSPORT_SS_UPDATE); 3309 notify_session_monitor(plugin, udpw->session, GNUNET_TRANSPORT_SS_UPDATE);
3310 GNUNET_free (udpw); 3310 GNUNET_free(udpw);
3311 } 3311 }
3312} 3312}
3313 3313
3314 3314
@@ -3323,7 +3323,7 @@ udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
3323 * @param cls the plugin handle 3323 * @param cls the plugin handle
3324 */ 3324 */
3325static void 3325static void
3326udp_plugin_select_v4 (void *cls) 3326udp_plugin_select_v4(void *cls)
3327{ 3327{
3328 struct Plugin *plugin = cls; 3328 struct Plugin *plugin = cls;
3329 const struct GNUNET_SCHEDULER_TaskContext *tc; 3329 const struct GNUNET_SCHEDULER_TaskContext *tc;
@@ -3331,12 +3331,12 @@ udp_plugin_select_v4 (void *cls)
3331 plugin->select_task_v4 = NULL; 3331 plugin->select_task_v4 = NULL;
3332 if (NULL == plugin->sockv4) 3332 if (NULL == plugin->sockv4)
3333 return; 3333 return;
3334 tc = GNUNET_SCHEDULER_get_task_context (); 3334 tc = GNUNET_SCHEDULER_get_task_context();
3335 if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) && 3335 if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
3336 (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv4))) 3336 (GNUNET_NETWORK_fdset_isset(tc->read_ready, plugin->sockv4)))
3337 udp_select_read (plugin, plugin->sockv4); 3337 udp_select_read(plugin, plugin->sockv4);
3338 udp_select_send (plugin, plugin->sockv4); 3338 udp_select_send(plugin, plugin->sockv4);
3339 schedule_select_v4 (plugin); 3339 schedule_select_v4(plugin);
3340} 3340}
3341 3341
3342 3342
@@ -3348,7 +3348,7 @@ udp_plugin_select_v4 (void *cls)
3348 * @param cls the plugin handle 3348 * @param cls the plugin handle
3349 */ 3349 */
3350static void 3350static void
3351udp_plugin_select_v6 (void *cls) 3351udp_plugin_select_v6(void *cls)
3352{ 3352{
3353 struct Plugin *plugin = cls; 3353 struct Plugin *plugin = cls;
3354 const struct GNUNET_SCHEDULER_TaskContext *tc; 3354 const struct GNUNET_SCHEDULER_TaskContext *tc;
@@ -3356,13 +3356,13 @@ udp_plugin_select_v6 (void *cls)
3356 plugin->select_task_v6 = NULL; 3356 plugin->select_task_v6 = NULL;
3357 if (NULL == plugin->sockv6) 3357 if (NULL == plugin->sockv6)
3358 return; 3358 return;
3359 tc = GNUNET_SCHEDULER_get_task_context (); 3359 tc = GNUNET_SCHEDULER_get_task_context();
3360 if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) && 3360 if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
3361 (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6))) 3361 (GNUNET_NETWORK_fdset_isset(tc->read_ready, plugin->sockv6)))
3362 udp_select_read (plugin, plugin->sockv6); 3362 udp_select_read(plugin, plugin->sockv6);
3363 3363
3364 udp_select_send (plugin, plugin->sockv6); 3364 udp_select_send(plugin, plugin->sockv6);
3365 schedule_select_v6 (plugin); 3365 schedule_select_v6(plugin);
3366} 3366}
3367 3367
3368 3368
@@ -3378,9 +3378,9 @@ udp_plugin_select_v6 (void *cls)
3378 * @return number of sockets that were successfully bound 3378 * @return number of sockets that were successfully bound
3379 */ 3379 */
3380static unsigned int 3380static unsigned int
3381setup_sockets (struct Plugin *plugin, 3381setup_sockets(struct Plugin *plugin,
3382 const struct sockaddr_in6 *bind_v6, 3382 const struct sockaddr_in6 *bind_v6,
3383 const struct sockaddr_in *bind_v4) 3383 const struct sockaddr_in *bind_v4)
3384{ 3384{
3385 int tries; 3385 int tries;
3386 unsigned int sockets_created = 0; 3386 unsigned int sockets_created = 0;
@@ -3395,186 +3395,186 @@ setup_sockets (struct Plugin *plugin,
3395 /* Create IPv6 socket */ 3395 /* Create IPv6 socket */
3396 eno = EINVAL; 3396 eno = EINVAL;
3397 if (GNUNET_YES == plugin->enable_ipv6) 3397 if (GNUNET_YES == plugin->enable_ipv6)
3398 {
3399 plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0);
3400 if (NULL == plugin->sockv6)
3401 { 3398 {
3402 LOG (GNUNET_ERROR_TYPE_INFO, 3399 plugin->sockv6 = GNUNET_NETWORK_socket_create(PF_INET6, SOCK_DGRAM, 0);
3403 _ ("Disabling IPv6 since it is not supported on this system!\n")); 3400 if (NULL == plugin->sockv6)
3404 plugin->enable_ipv6 = GNUNET_NO; 3401 {
3402 LOG(GNUNET_ERROR_TYPE_INFO,
3403 _("Disabling IPv6 since it is not supported on this system!\n"));
3404 plugin->enable_ipv6 = GNUNET_NO;
3405 }
3406 else
3407 {
3408 memset(&server_addrv6, 0, sizeof(struct sockaddr_in6));
3409#if HAVE_SOCKADDR_IN_SIN_LEN
3410 server_addrv6.sin6_len = sizeof(struct sockaddr_in6);
3411#endif
3412 server_addrv6.sin6_family = AF_INET6;
3413 if (NULL != bind_v6)
3414 server_addrv6.sin6_addr = bind_v6->sin6_addr;
3415 else
3416 server_addrv6.sin6_addr = in6addr_any;
3417
3418 if (0 == plugin->port) /* autodetect */
3419 server_addrv6.sin6_port = htons(
3420 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) +
3421 32000);
3422 else
3423 server_addrv6.sin6_port = htons(plugin->port);
3424 addrlen = sizeof(struct sockaddr_in6);
3425 server_addr = (const struct sockaddr *)&server_addrv6;
3426
3427 tries = 0;
3428 while (tries < 10)
3429 {
3430 LOG(GNUNET_ERROR_TYPE_DEBUG,
3431 "Binding to IPv6 `%s'\n",
3432 GNUNET_a2s(server_addr, addrlen));
3433 /* binding */
3434 if (GNUNET_OK ==
3435 GNUNET_NETWORK_socket_bind(plugin->sockv6, server_addr, addrlen))
3436 break;
3437 eno = errno;
3438 if (0 != plugin->port)
3439 {
3440 tries = 10; /* fail immediately */
3441 break; /* bind failed on specific port */
3442 }
3443 /* autodetect */
3444 server_addrv6.sin6_port = htons(
3445 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) +
3446 32000);
3447 tries++;
3448 }
3449 if (tries >= 10)
3450 {
3451 GNUNET_NETWORK_socket_close(plugin->sockv6);
3452 plugin->enable_ipv6 = GNUNET_NO;
3453 plugin->sockv6 = NULL;
3454 }
3455 else
3456 {
3457 plugin->port = ntohs(server_addrv6.sin6_port);
3458 }
3459 if (NULL != plugin->sockv6)
3460 {
3461 LOG(GNUNET_ERROR_TYPE_DEBUG,
3462 "IPv6 UDP socket created listinging at %s\n",
3463 GNUNET_a2s(server_addr, addrlen));
3464 addrs[sockets_created] = server_addr;
3465 addrlens[sockets_created] = addrlen;
3466 sockets_created++;
3467 }
3468 else
3469 {
3470 LOG(GNUNET_ERROR_TYPE_WARNING,
3471 _("Failed to bind UDP socket to %s: %s\n"),
3472 GNUNET_a2s(server_addr, addrlen),
3473 strerror(eno));
3474 }
3475 }
3476 }
3477
3478 /* Create IPv4 socket */
3479 eno = EINVAL;
3480 plugin->sockv4 = GNUNET_NETWORK_socket_create(PF_INET, SOCK_DGRAM, 0);
3481 if (NULL == plugin->sockv4)
3482 {
3483 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "socket");
3484 LOG(GNUNET_ERROR_TYPE_INFO,
3485 _("Disabling IPv4 since it is not supported on this system!\n"));
3486 plugin->enable_ipv4 = GNUNET_NO;
3405 } 3487 }
3406 else 3488 else
3407 { 3489 {
3408 memset (&server_addrv6, 0, sizeof (struct sockaddr_in6)); 3490 memset(&server_addrv4, 0, sizeof(struct sockaddr_in));
3409#if HAVE_SOCKADDR_IN_SIN_LEN 3491#if HAVE_SOCKADDR_IN_SIN_LEN
3410 server_addrv6.sin6_len = sizeof (struct sockaddr_in6); 3492 server_addrv4.sin_len = sizeof(struct sockaddr_in);
3411#endif 3493#endif
3412 server_addrv6.sin6_family = AF_INET6; 3494 server_addrv4.sin_family = AF_INET;
3413 if (NULL != bind_v6) 3495 if (NULL != bind_v4)
3414 server_addrv6.sin6_addr = bind_v6->sin6_addr; 3496 server_addrv4.sin_addr = bind_v4->sin_addr;
3415 else 3497 else
3416 server_addrv6.sin6_addr = in6addr_any; 3498 server_addrv4.sin_addr.s_addr = INADDR_ANY;
3417 3499
3418 if (0 == plugin->port) /* autodetect */ 3500 if (0 == plugin->port)
3419 server_addrv6.sin6_port = htons ( 3501 /* autodetect */
3420 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 3502 server_addrv4.sin_port = htons(
3421 32000); 3503 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000);
3422 else 3504 else
3423 server_addrv6.sin6_port = htons (plugin->port); 3505 server_addrv4.sin_port = htons(plugin->port);
3424 addrlen = sizeof (struct sockaddr_in6); 3506
3425 server_addr = (const struct sockaddr *) &server_addrv6; 3507 addrlen = sizeof(struct sockaddr_in);
3508 server_addr = (const struct sockaddr *)&server_addrv4;
3426 3509
3427 tries = 0; 3510 tries = 0;
3428 while (tries < 10) 3511 while (tries < 10)
3429 {
3430 LOG (GNUNET_ERROR_TYPE_DEBUG,
3431 "Binding to IPv6 `%s'\n",
3432 GNUNET_a2s (server_addr, addrlen));
3433 /* binding */
3434 if (GNUNET_OK ==
3435 GNUNET_NETWORK_socket_bind (plugin->sockv6, server_addr, addrlen))
3436 break;
3437 eno = errno;
3438 if (0 != plugin->port)
3439 { 3512 {
3440 tries = 10; /* fail immediately */ 3513 LOG(GNUNET_ERROR_TYPE_DEBUG,
3441 break; /* bind failed on specific port */ 3514 "Binding to IPv4 `%s'\n",
3515 GNUNET_a2s(server_addr, addrlen));
3516
3517 /* binding */
3518 if (GNUNET_OK ==
3519 GNUNET_NETWORK_socket_bind(plugin->sockv4, server_addr, addrlen))
3520 break;
3521 eno = errno;
3522 if (0 != plugin->port)
3523 {
3524 tries = 10; /* fail */
3525 break; /* bind failed on specific port */
3526 }
3527
3528 /* autodetect */
3529 server_addrv4.sin_port = htons(
3530 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000);
3531 tries++;
3442 } 3532 }
3443 /* autodetect */
3444 server_addrv6.sin6_port = htons (
3445 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) +
3446 32000);
3447 tries++;
3448 }
3449 if (tries >= 10) 3533 if (tries >= 10)
3450 { 3534 {
3451 GNUNET_NETWORK_socket_close (plugin->sockv6); 3535 GNUNET_NETWORK_socket_close(plugin->sockv4);
3452 plugin->enable_ipv6 = GNUNET_NO; 3536 plugin->enable_ipv4 = GNUNET_NO;
3453 plugin->sockv6 = NULL; 3537 plugin->sockv4 = NULL;
3454 } 3538 }
3455 else
3456 {
3457 plugin->port = ntohs (server_addrv6.sin6_port);
3458 }
3459 if (NULL != plugin->sockv6)
3460 {
3461 LOG (GNUNET_ERROR_TYPE_DEBUG,
3462 "IPv6 UDP socket created listinging at %s\n",
3463 GNUNET_a2s (server_addr, addrlen));
3464 addrs[sockets_created] = server_addr;
3465 addrlens[sockets_created] = addrlen;
3466 sockets_created++;
3467 }
3468 else 3539 else
3469 { 3540 {
3470 LOG (GNUNET_ERROR_TYPE_WARNING, 3541 plugin->port = ntohs(server_addrv4.sin_port);
3471 _ ("Failed to bind UDP socket to %s: %s\n"), 3542 }
3472 GNUNET_a2s (server_addr, addrlen),
3473 strerror (eno));
3474 }
3475 }
3476 }
3477 3543
3478 /* Create IPv4 socket */ 3544 if (NULL != plugin->sockv4)
3479 eno = EINVAL; 3545 {
3480 plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0); 3546 LOG(GNUNET_ERROR_TYPE_DEBUG,
3481 if (NULL == plugin->sockv4) 3547 "IPv4 socket created on port %s\n",
3482 { 3548 GNUNET_a2s(server_addr, addrlen));
3483 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); 3549 addrs[sockets_created] = server_addr;
3484 LOG (GNUNET_ERROR_TYPE_INFO, 3550 addrlens[sockets_created] = addrlen;
3485 _ ("Disabling IPv4 since it is not supported on this system!\n")); 3551 sockets_created++;
3486 plugin->enable_ipv4 = GNUNET_NO; 3552 }
3487 } 3553 else
3488 else 3554 {
3489 { 3555 LOG(GNUNET_ERROR_TYPE_ERROR,
3490 memset (&server_addrv4, 0, sizeof (struct sockaddr_in)); 3556 _("Failed to bind UDP socket to %s: %s\n"),
3491#if HAVE_SOCKADDR_IN_SIN_LEN 3557 GNUNET_a2s(server_addr, addrlen),
3492 server_addrv4.sin_len = sizeof (struct sockaddr_in); 3558 strerror(eno));
3493#endif 3559 }
3494 server_addrv4.sin_family = AF_INET;
3495 if (NULL != bind_v4)
3496 server_addrv4.sin_addr = bind_v4->sin_addr;
3497 else
3498 server_addrv4.sin_addr.s_addr = INADDR_ANY;
3499
3500 if (0 == plugin->port)
3501 /* autodetect */
3502 server_addrv4.sin_port = htons (
3503 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000);
3504 else
3505 server_addrv4.sin_port = htons (plugin->port);
3506
3507 addrlen = sizeof (struct sockaddr_in);
3508 server_addr = (const struct sockaddr *) &server_addrv4;
3509
3510 tries = 0;
3511 while (tries < 10)
3512 {
3513 LOG (GNUNET_ERROR_TYPE_DEBUG,
3514 "Binding to IPv4 `%s'\n",
3515 GNUNET_a2s (server_addr, addrlen));
3516
3517 /* binding */
3518 if (GNUNET_OK ==
3519 GNUNET_NETWORK_socket_bind (plugin->sockv4, server_addr, addrlen))
3520 break;
3521 eno = errno;
3522 if (0 != plugin->port)
3523 {
3524 tries = 10; /* fail */
3525 break; /* bind failed on specific port */
3526 }
3527
3528 /* autodetect */
3529 server_addrv4.sin_port = htons (
3530 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000);
3531 tries++;
3532 }
3533 if (tries >= 10)
3534 {
3535 GNUNET_NETWORK_socket_close (plugin->sockv4);
3536 plugin->enable_ipv4 = GNUNET_NO;
3537 plugin->sockv4 = NULL;
3538 }
3539 else
3540 {
3541 plugin->port = ntohs (server_addrv4.sin_port);
3542 } 3560 }
3543 3561
3544 if (NULL != plugin->sockv4) 3562 if (0 == sockets_created)
3545 {
3546 LOG (GNUNET_ERROR_TYPE_DEBUG,
3547 "IPv4 socket created on port %s\n",
3548 GNUNET_a2s (server_addr, addrlen));
3549 addrs[sockets_created] = server_addr;
3550 addrlens[sockets_created] = addrlen;
3551 sockets_created++;
3552 }
3553 else
3554 { 3563 {
3555 LOG (GNUNET_ERROR_TYPE_ERROR, 3564 LOG(GNUNET_ERROR_TYPE_WARNING, _("Failed to open UDP sockets\n"));
3556 _ ("Failed to bind UDP socket to %s: %s\n"), 3565 return 0; /* No sockets created, return */
3557 GNUNET_a2s (server_addr, addrlen),
3558 strerror (eno));
3559 } 3566 }
3560 } 3567 schedule_select_v4(plugin);
3561 3568 schedule_select_v6(plugin);
3562 if (0 == sockets_created) 3569 plugin->nat = GNUNET_NAT_register(plugin->env->cfg,
3563 { 3570 "transport-udp",
3564 LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to open UDP sockets\n")); 3571 IPPROTO_UDP,
3565 return 0; /* No sockets created, return */ 3572 sockets_created,
3566 } 3573 addrs,
3567 schedule_select_v4 (plugin); 3574 addrlens,
3568 schedule_select_v6 (plugin); 3575 &udp_nat_port_map_callback,
3569 plugin->nat = GNUNET_NAT_register (plugin->env->cfg, 3576 NULL,
3570 "transport-udp", 3577 plugin);
3571 IPPROTO_UDP,
3572 sockets_created,
3573 addrs,
3574 addrlens,
3575 &udp_nat_port_map_callback,
3576 NULL,
3577 plugin);
3578 return sockets_created; 3578 return sockets_created;
3579} 3579}
3580 3580
@@ -3587,7 +3587,7 @@ setup_sockets (struct Plugin *plugin,
3587 * @return our `struct GNUNET_TRANSPORT_PluginFunctions` 3587 * @return our `struct GNUNET_TRANSPORT_PluginFunctions`
3588 */ 3588 */
3589void * 3589void *
3590libgnunet_plugin_transport_udp_init (void *cls) 3590libgnunet_plugin_transport_udp_init(void *cls)
3591{ 3591{
3592 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 3592 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
3593 struct GNUNET_TRANSPORT_PluginFunctions *api; 3593 struct GNUNET_TRANSPORT_PluginFunctions *api;
@@ -3608,128 +3608,128 @@ libgnunet_plugin_transport_udp_init (void *cls)
3608 int have_bind6; 3608 int have_bind6;
3609 3609
3610 if (NULL == env->receive) 3610 if (NULL == env->receive)
3611 { 3611 {
3612 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully 3612 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
3613 initialze the plugin or the API */ 3613 initialze the plugin or the API */
3614 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); 3614 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions);
3615 api->cls = NULL; 3615 api->cls = NULL;
3616 api->address_pretty_printer = &udp_plugin_address_pretty_printer; 3616 api->address_pretty_printer = &udp_plugin_address_pretty_printer;
3617 api->address_to_string = &udp_address_to_string; 3617 api->address_to_string = &udp_address_to_string;
3618 api->string_to_address = &udp_string_to_address; 3618 api->string_to_address = &udp_string_to_address;
3619 return api; 3619 return api;
3620 } 3620 }
3621 3621
3622 /* Get port number: port == 0 : autodetect a port, 3622 /* Get port number: port == 0 : autodetect a port,
3623 * > 0 : use this port, not given : 2086 default */ 3623 * > 0 : use this port, not given : 2086 default */
3624 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, 3624 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg,
3625 "transport-udp", 3625 "transport-udp",
3626 "PORT", 3626 "PORT",
3627 &port)) 3627 &port))
3628 port = 2086; 3628 port = 2086;
3629 if (port > 65535) 3629 if (port > 65535)
3630 { 3630 {
3631 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, 3631 GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR,
3632 "transport-udp", 3632 "transport-udp",
3633 "PORT", 3633 "PORT",
3634 _ ("must be in [0,65535]")); 3634 _("must be in [0,65535]"));
3635 return NULL; 3635 return NULL;
3636 } 3636 }
3637 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, 3637 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg,
3638 "transport-udp", 3638 "transport-udp",
3639 "ADVERTISED_PORT", 3639 "ADVERTISED_PORT",
3640 &aport)) 3640 &aport))
3641 aport = port; 3641 aport = port;
3642 if (aport > 65535) 3642 if (aport > 65535)
3643 { 3643 {
3644 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, 3644 GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR,
3645 "transport-udp", 3645 "transport-udp",
3646 "ADVERTISED_PORT", 3646 "ADVERTISED_PORT",
3647 _ ("must be in [0,65535]")); 3647 _("must be in [0,65535]"));
3648 return NULL; 3648 return NULL;
3649 } 3649 }
3650 3650
3651 if (GNUNET_YES == 3651 if (GNUNET_YES ==
3652 GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "nat", "DISABLEV6")) 3652 GNUNET_CONFIGURATION_get_value_yesno(env->cfg, "nat", "DISABLEV6"))
3653 enable_v6 = GNUNET_NO; 3653 enable_v6 = GNUNET_NO;
3654 else 3654 else
3655 enable_v6 = GNUNET_YES; 3655 enable_v6 = GNUNET_YES;
3656 3656
3657 have_bind4 = GNUNET_NO; 3657 have_bind4 = GNUNET_NO;
3658 memset (&server_addrv4, 0, sizeof (server_addrv4)); 3658 memset(&server_addrv4, 0, sizeof(server_addrv4));
3659 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg, 3659 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(env->cfg,
3660 "transport-udp", 3660 "transport-udp",
3661 "BINDTO", 3661 "BINDTO",
3662 &bind4_address)) 3662 &bind4_address))
3663 { 3663 {
3664 LOG (GNUNET_ERROR_TYPE_DEBUG, 3664 LOG(GNUNET_ERROR_TYPE_DEBUG,
3665 "Binding UDP plugin to specific address: `%s'\n", 3665 "Binding UDP plugin to specific address: `%s'\n",
3666 bind4_address); 3666 bind4_address);
3667 if (1 != inet_pton (AF_INET, bind4_address, &server_addrv4.sin_addr)) 3667 if (1 != inet_pton(AF_INET, bind4_address, &server_addrv4.sin_addr))
3668 { 3668 {
3669 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, 3669 GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR,
3670 "transport-udp", 3670 "transport-udp",
3671 "BINDTO", 3671 "BINDTO",
3672 _ ("must be valid IPv4 address")); 3672 _("must be valid IPv4 address"));
3673 GNUNET_free (bind4_address); 3673 GNUNET_free(bind4_address);
3674 return NULL; 3674 return NULL;
3675 }
3676 have_bind4 = GNUNET_YES;
3675 } 3677 }
3676 have_bind4 = GNUNET_YES; 3678 GNUNET_free_non_null(bind4_address);
3677 }
3678 GNUNET_free_non_null (bind4_address);
3679 have_bind6 = GNUNET_NO; 3679 have_bind6 = GNUNET_NO;
3680 memset (&server_addrv6, 0, sizeof (server_addrv6)); 3680 memset(&server_addrv6, 0, sizeof(server_addrv6));
3681 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg, 3681 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(env->cfg,
3682 "transport-udp", 3682 "transport-udp",
3683 "BINDTO6", 3683 "BINDTO6",
3684 &bind6_address)) 3684 &bind6_address))
3685 { 3685 {
3686 LOG (GNUNET_ERROR_TYPE_DEBUG, 3686 LOG(GNUNET_ERROR_TYPE_DEBUG,
3687 "Binding udp plugin to specific address: `%s'\n", 3687 "Binding udp plugin to specific address: `%s'\n",
3688 bind6_address); 3688 bind6_address);
3689 if (1 != inet_pton (AF_INET6, bind6_address, &server_addrv6.sin6_addr)) 3689 if (1 != inet_pton(AF_INET6, bind6_address, &server_addrv6.sin6_addr))
3690 { 3690 {
3691 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, 3691 GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR,
3692 "transport-udp", 3692 "transport-udp",
3693 "BINDTO6", 3693 "BINDTO6",
3694 _ ("must be valid IPv6 address")); 3694 _("must be valid IPv6 address"));
3695 GNUNET_free (bind6_address); 3695 GNUNET_free(bind6_address);
3696 return NULL; 3696 return NULL;
3697 }
3698 have_bind6 = GNUNET_YES;
3697 } 3699 }
3698 have_bind6 = GNUNET_YES; 3700 GNUNET_free_non_null(bind6_address);
3699 }
3700 GNUNET_free_non_null (bind6_address);
3701 3701
3702 enable_broadcasting = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 3702 enable_broadcasting = GNUNET_CONFIGURATION_get_value_yesno(env->cfg,
3703 "transport-udp", 3703 "transport-udp",
3704 "BROADCAST"); 3704 "BROADCAST");
3705 if (enable_broadcasting == GNUNET_SYSERR) 3705 if (enable_broadcasting == GNUNET_SYSERR)
3706 enable_broadcasting = GNUNET_NO; 3706 enable_broadcasting = GNUNET_NO;
3707 3707
3708 enable_broadcasting_recv = 3708 enable_broadcasting_recv =
3709 GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 3709 GNUNET_CONFIGURATION_get_value_yesno(env->cfg,
3710 "transport-udp", 3710 "transport-udp",
3711 "BROADCAST_RECEIVE"); 3711 "BROADCAST_RECEIVE");
3712 if (enable_broadcasting_recv == GNUNET_SYSERR) 3712 if (enable_broadcasting_recv == GNUNET_SYSERR)
3713 enable_broadcasting_recv = GNUNET_YES; 3713 enable_broadcasting_recv = GNUNET_YES;
3714 3714
3715 if (GNUNET_SYSERR == 3715 if (GNUNET_SYSERR ==
3716 GNUNET_CONFIGURATION_get_value_time (env->cfg, 3716 GNUNET_CONFIGURATION_get_value_time(env->cfg,
3717 "transport-udp", 3717 "transport-udp",
3718 "BROADCAST_INTERVAL", 3718 "BROADCAST_INTERVAL",
3719 &interval)) 3719 &interval))
3720 { 3720 {
3721 interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); 3721 interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10);
3722 } 3722 }
3723 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, 3723 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg,
3724 "transport-udp", 3724 "transport-udp",
3725 "MAX_BPS", 3725 "MAX_BPS",
3726 &udp_max_bps)) 3726 &udp_max_bps))
3727 { 3727 {
3728 /* 50 MB/s == infinity for practical purposes */ 3728 /* 50 MB/s == infinity for practical purposes */
3729 udp_max_bps = 1024 * 1024 * 50; 3729 udp_max_bps = 1024 * 1024 * 50;
3730 } 3730 }
3731 3731
3732 p = GNUNET_new (struct Plugin); 3732 p = GNUNET_new(struct Plugin);
3733 p->port = port; 3733 p->port = port;
3734 p->aport = aport; 3734 p->aport = aport;
3735 p->broadcast_interval = interval; 3735 p->broadcast_interval = interval;
@@ -3738,33 +3738,33 @@ libgnunet_plugin_transport_udp_init (void *cls)
3738 p->enable_broadcasting = enable_broadcasting; 3738 p->enable_broadcasting = enable_broadcasting;
3739 p->enable_broadcasting_receiving = enable_broadcasting_recv; 3739 p->enable_broadcasting_receiving = enable_broadcasting_recv;
3740 p->env = env; 3740 p->env = env;
3741 p->sessions = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_NO); 3741 p->sessions = GNUNET_CONTAINER_multipeermap_create(16, GNUNET_NO);
3742 p->defrag_ctxs = 3742 p->defrag_ctxs =
3743 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 3743 GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN);
3744 GNUNET_BANDWIDTH_tracker_init (&p->tracker, 3744 GNUNET_BANDWIDTH_tracker_init(&p->tracker,
3745 NULL, 3745 NULL,
3746 NULL, 3746 NULL,
3747 GNUNET_BANDWIDTH_value_init ( 3747 GNUNET_BANDWIDTH_value_init(
3748 (uint32_t) udp_max_bps), 3748 (uint32_t)udp_max_bps),
3749 30); 3749 30);
3750 res = setup_sockets (p, 3750 res = setup_sockets(p,
3751 (GNUNET_YES == have_bind6) ? &server_addrv6 : NULL, 3751 (GNUNET_YES == have_bind6) ? &server_addrv6 : NULL,
3752 (GNUNET_YES == have_bind4) ? &server_addrv4 : NULL); 3752 (GNUNET_YES == have_bind4) ? &server_addrv4 : NULL);
3753 if ((0 == res) || ((NULL == p->sockv4) && (NULL == p->sockv6))) 3753 if ((0 == res) || ((NULL == p->sockv4) && (NULL == p->sockv6)))
3754 { 3754 {
3755 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Failed to create UDP network sockets\n")); 3755 LOG(GNUNET_ERROR_TYPE_ERROR, _("Failed to create UDP network sockets\n"));
3756 GNUNET_CONTAINER_multipeermap_destroy (p->sessions); 3756 GNUNET_CONTAINER_multipeermap_destroy(p->sessions);
3757 GNUNET_CONTAINER_heap_destroy (p->defrag_ctxs); 3757 GNUNET_CONTAINER_heap_destroy(p->defrag_ctxs);
3758 if (NULL != p->nat) 3758 if (NULL != p->nat)
3759 GNUNET_NAT_unregister (p->nat); 3759 GNUNET_NAT_unregister(p->nat);
3760 GNUNET_free (p); 3760 GNUNET_free(p);
3761 return NULL; 3761 return NULL;
3762 } 3762 }
3763 3763
3764 /* Setup broadcasting and receiving beacons */ 3764 /* Setup broadcasting and receiving beacons */
3765 setup_broadcast (p, &server_addrv6, &server_addrv4); 3765 setup_broadcast(p, &server_addrv6, &server_addrv4);
3766 3766
3767 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); 3767 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions);
3768 api->cls = p; 3768 api->cls = p;
3769 api->disconnect_session = &udp_disconnect_session; 3769 api->disconnect_session = &udp_disconnect_session;
3770 api->query_keepalive_factor = &udp_query_keepalive_factor; 3770 api->query_keepalive_factor = &udp_query_keepalive_factor;
@@ -3794,16 +3794,16 @@ libgnunet_plugin_transport_udp_init (void *cls)
3794 * @return #GNUNET_YES 3794 * @return #GNUNET_YES
3795 */ 3795 */
3796static int 3796static int
3797heap_cleanup_iterator (void *cls, 3797heap_cleanup_iterator(void *cls,
3798 struct GNUNET_CONTAINER_HeapNode *node, 3798 struct GNUNET_CONTAINER_HeapNode *node,
3799 void *element, 3799 void *element,
3800 GNUNET_CONTAINER_HeapCostType cost) 3800 GNUNET_CONTAINER_HeapCostType cost)
3801{ 3801{
3802 struct DefragContext *d_ctx = element; 3802 struct DefragContext *d_ctx = element;
3803 3803
3804 GNUNET_CONTAINER_heap_remove_node (node); 3804 GNUNET_CONTAINER_heap_remove_node(node);
3805 GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag); 3805 GNUNET_DEFRAGMENT_context_destroy(d_ctx->defrag);
3806 GNUNET_free (d_ctx); 3806 GNUNET_free(d_ctx);
3807 return GNUNET_YES; 3807 return GNUNET_YES;
3808} 3808}
3809 3809
@@ -3816,7 +3816,7 @@ heap_cleanup_iterator (void *cls,
3816 * @return NULL 3816 * @return NULL
3817 */ 3817 */
3818void * 3818void *
3819libgnunet_plugin_transport_udp_done (void *cls) 3819libgnunet_plugin_transport_udp_done(void *cls)
3820{ 3820{
3821 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 3821 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
3822 struct Plugin *plugin = api->cls; 3822 struct Plugin *plugin = api->cls;
@@ -3824,77 +3824,77 @@ libgnunet_plugin_transport_udp_done (void *cls)
3824 struct UDP_MessageWrapper *udpw; 3824 struct UDP_MessageWrapper *udpw;
3825 3825
3826 if (NULL == plugin) 3826 if (NULL == plugin)
3827 { 3827 {
3828 GNUNET_free (api); 3828 GNUNET_free(api);
3829 return NULL; 3829 return NULL;
3830 } 3830 }
3831 stop_broadcast (plugin); 3831 stop_broadcast(plugin);
3832 if (NULL != plugin->select_task_v4) 3832 if (NULL != plugin->select_task_v4)
3833 { 3833 {
3834 GNUNET_SCHEDULER_cancel (plugin->select_task_v4); 3834 GNUNET_SCHEDULER_cancel(plugin->select_task_v4);
3835 plugin->select_task_v4 = NULL; 3835 plugin->select_task_v4 = NULL;
3836 } 3836 }
3837 if (NULL != plugin->select_task_v6) 3837 if (NULL != plugin->select_task_v6)
3838 { 3838 {
3839 GNUNET_SCHEDULER_cancel (plugin->select_task_v6); 3839 GNUNET_SCHEDULER_cancel(plugin->select_task_v6);
3840 plugin->select_task_v6 = NULL; 3840 plugin->select_task_v6 = NULL;
3841 } 3841 }
3842 if (NULL != plugin->sockv4) 3842 if (NULL != plugin->sockv4)
3843 { 3843 {
3844 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4)); 3844 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(plugin->sockv4));
3845 plugin->sockv4 = NULL; 3845 plugin->sockv4 = NULL;
3846 } 3846 }
3847 if (NULL != plugin->sockv6) 3847 if (NULL != plugin->sockv6)
3848 { 3848 {
3849 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6)); 3849 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(plugin->sockv6));
3850 plugin->sockv6 = NULL; 3850 plugin->sockv6 = NULL;
3851 } 3851 }
3852 if (NULL != plugin->nat) 3852 if (NULL != plugin->nat)
3853 { 3853 {
3854 GNUNET_NAT_unregister (plugin->nat); 3854 GNUNET_NAT_unregister(plugin->nat);
3855 plugin->nat = NULL; 3855 plugin->nat = NULL;
3856 } 3856 }
3857 if (NULL != plugin->defrag_ctxs) 3857 if (NULL != plugin->defrag_ctxs)
3858 { 3858 {
3859 GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, 3859 GNUNET_CONTAINER_heap_iterate(plugin->defrag_ctxs,
3860 &heap_cleanup_iterator, 3860 &heap_cleanup_iterator,
3861 NULL); 3861 NULL);
3862 GNUNET_CONTAINER_heap_destroy (plugin->defrag_ctxs); 3862 GNUNET_CONTAINER_heap_destroy(plugin->defrag_ctxs);
3863 plugin->defrag_ctxs = NULL; 3863 plugin->defrag_ctxs = NULL;
3864 } 3864 }
3865 while (NULL != (udpw = plugin->ipv4_queue_head)) 3865 while (NULL != (udpw = plugin->ipv4_queue_head))
3866 { 3866 {
3867 dequeue (plugin, udpw); 3867 dequeue(plugin, udpw);
3868 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); 3868 udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR);
3869 GNUNET_free (udpw); 3869 GNUNET_free(udpw);
3870 } 3870 }
3871 while (NULL != (udpw = plugin->ipv6_queue_head)) 3871 while (NULL != (udpw = plugin->ipv6_queue_head))
3872 { 3872 {
3873 dequeue (plugin, udpw); 3873 dequeue(plugin, udpw);
3874 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); 3874 udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR);
3875 GNUNET_free (udpw); 3875 GNUNET_free(udpw);
3876 } 3876 }
3877 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, 3877 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions,
3878 &disconnect_and_free_it, 3878 &disconnect_and_free_it,
3879 plugin); 3879 plugin);
3880 GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions); 3880 GNUNET_CONTAINER_multipeermap_destroy(plugin->sessions);
3881 3881
3882 while (NULL != (cur = plugin->ppc_dll_head)) 3882 while (NULL != (cur = plugin->ppc_dll_head))
3883 { 3883 {
3884 GNUNET_break (0); 3884 GNUNET_break(0);
3885 GNUNET_CONTAINER_DLL_remove (plugin->ppc_dll_head, 3885 GNUNET_CONTAINER_DLL_remove(plugin->ppc_dll_head,
3886 plugin->ppc_dll_tail, 3886 plugin->ppc_dll_tail,
3887 cur); 3887 cur);
3888 GNUNET_RESOLVER_request_cancel (cur->resolver_handle); 3888 GNUNET_RESOLVER_request_cancel(cur->resolver_handle);
3889 if (NULL != cur->timeout_task) 3889 if (NULL != cur->timeout_task)
3890 { 3890 {
3891 GNUNET_SCHEDULER_cancel (cur->timeout_task); 3891 GNUNET_SCHEDULER_cancel(cur->timeout_task);
3892 cur->timeout_task = NULL; 3892 cur->timeout_task = NULL;
3893 } 3893 }
3894 GNUNET_free (cur); 3894 GNUNET_free(cur);
3895 } 3895 }
3896 GNUNET_free (plugin); 3896 GNUNET_free(plugin);
3897 GNUNET_free (api); 3897 GNUNET_free(api);
3898 return NULL; 3898 return NULL;
3899} 3899}
3900 3900