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