diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-02-06 08:52:04 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-02-06 08:52:04 +0000 |
commit | 44bb5a6082b7f240458abf8b39154cf0d4f06c45 (patch) | |
tree | b822ff6496e6b81dfda9d2176f1ac891b48627ce /src/transport | |
parent | abe14967d9c053b0f327dd5cc0731d2207b71235 (diff) | |
download | gnunet-44bb5a6082b7f240458abf8b39154cf0d4f06c45.tar.gz gnunet-44bb5a6082b7f240458abf8b39154cf0d4f06c45.zip |
-doxygen, indentation, code cleanup
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/plugin_transport_udp.c | 662 | ||||
-rw-r--r-- | src/transport/plugin_transport_udp_broadcasting.c | 2 |
2 files changed, 389 insertions, 275 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index a50aaa436..12e551fef 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2010-2013 Christian Grothoff (and other contributing authors) | 3 | (C) 2010-2014 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -73,6 +73,7 @@ static struct PrettyPrinterContext *ppc_dll_head; | |||
73 | */ | 73 | */ |
74 | static struct PrettyPrinterContext *ppc_dll_tail; | 74 | static struct PrettyPrinterContext *ppc_dll_tail; |
75 | 75 | ||
76 | |||
76 | /** | 77 | /** |
77 | * Closure for 'append_port'. | 78 | * Closure for 'append_port'. |
78 | */ | 79 | */ |
@@ -125,15 +126,6 @@ struct PrettyPrinterContext | |||
125 | uint32_t options; | 126 | uint32_t options; |
126 | }; | 127 | }; |
127 | 128 | ||
128 | enum UDP_MessageType | ||
129 | { | ||
130 | UNDEFINED = 0, | ||
131 | MSG_FRAGMENTED = 1, | ||
132 | MSG_FRAGMENTED_COMPLETE = 2, | ||
133 | MSG_UNFRAGMENTED = 3, | ||
134 | MSG_ACK = 4, | ||
135 | MSG_BEACON = 5 | ||
136 | }; | ||
137 | 129 | ||
138 | struct Session | 130 | struct Session |
139 | { | 131 | { |
@@ -351,6 +343,40 @@ struct UDP_FragmentationContext | |||
351 | 343 | ||
352 | }; | 344 | }; |
353 | 345 | ||
346 | |||
347 | /** | ||
348 | * Message types included in a `struct UDP_MessageWrapper` | ||
349 | */ | ||
350 | enum UDP_MessageType | ||
351 | { | ||
352 | /** | ||
353 | * Uninitialized (error) | ||
354 | */ | ||
355 | UMT_UNDEFINED = 0, | ||
356 | |||
357 | /** | ||
358 | * Fragment of a message. | ||
359 | */ | ||
360 | UMT_MSG_FRAGMENTED = 1, | ||
361 | |||
362 | /** | ||
363 | * | ||
364 | */ | ||
365 | UMT_MSG_FRAGMENTED_COMPLETE = 2, | ||
366 | |||
367 | /** | ||
368 | * Unfragmented message. | ||
369 | */ | ||
370 | UMT_MSG_UNFRAGMENTED = 3, | ||
371 | |||
372 | /** | ||
373 | * Receipt confirmation. | ||
374 | */ | ||
375 | UMT_MSG_ACK = 4 | ||
376 | |||
377 | }; | ||
378 | |||
379 | |||
354 | struct UDP_MessageWrapper | 380 | struct UDP_MessageWrapper |
355 | { | 381 | { |
356 | /** | 382 | /** |
@@ -372,9 +398,8 @@ struct UDP_MessageWrapper | |||
372 | 398 | ||
373 | /** | 399 | /** |
374 | * Message type | 400 | * Message type |
375 | * According to UDP_MessageType | ||
376 | */ | 401 | */ |
377 | int msg_type; | 402 | enum UDP_MessageType msg_type; |
378 | 403 | ||
379 | /** | 404 | /** |
380 | * Message with size msg_size including UDP specific overhead | 405 | * Message with size msg_size including UDP specific overhead |
@@ -402,7 +427,7 @@ struct UDP_MessageWrapper | |||
402 | GNUNET_TRANSPORT_TransmitContinuation cont; | 427 | GNUNET_TRANSPORT_TransmitContinuation cont; |
403 | 428 | ||
404 | /** | 429 | /** |
405 | * Closure for 'cont'. | 430 | * Closure for @e cont. |
406 | */ | 431 | */ |
407 | void *cont_cls; | 432 | void *cont_cls; |
408 | 433 | ||
@@ -414,6 +439,7 @@ struct UDP_MessageWrapper | |||
414 | struct UDP_FragmentationContext *frag_ctx; | 439 | struct UDP_FragmentationContext *frag_ctx; |
415 | }; | 440 | }; |
416 | 441 | ||
442 | |||
417 | /** | 443 | /** |
418 | * UDP ACK Message-Packet header (after defragmentation). | 444 | * UDP ACK Message-Packet header (after defragmentation). |
419 | */ | 445 | */ |
@@ -446,6 +472,7 @@ static uint32_t myoptions; | |||
446 | */ | 472 | */ |
447 | struct Plugin * plugin; | 473 | struct Plugin * plugin; |
448 | 474 | ||
475 | |||
449 | /** | 476 | /** |
450 | * We have been notified that our readset has something to read. We don't | 477 | * We have been notified that our readset has something to read. We don't |
451 | * know which socket needs to be read, so we have to check each one | 478 | * know which socket needs to be read, so we have to check each one |
@@ -521,6 +548,7 @@ schedule_select (struct Plugin *plugin) | |||
521 | } | 548 | } |
522 | } | 549 | } |
523 | 550 | ||
551 | |||
524 | /** | 552 | /** |
525 | * Function called for a quick conversion of the binary address to | 553 | * Function called for a quick conversion of the binary address to |
526 | * a numeric address. Note that the caller must not free the | 554 | * a numeric address. Note that the caller must not free the |
@@ -533,7 +561,9 @@ schedule_select (struct Plugin *plugin) | |||
533 | * @return string representing the same address | 561 | * @return string representing the same address |
534 | */ | 562 | */ |
535 | const char * | 563 | const char * |
536 | udp_address_to_string (void *cls, const void *addr, size_t addrlen) | 564 | udp_address_to_string (void *cls, |
565 | const void *addr, | ||
566 | size_t addrlen) | ||
537 | { | 567 | { |
538 | static char rbuf[INET6_ADDRSTRLEN + 10]; | 568 | static char rbuf[INET6_ADDRSTRLEN + 10]; |
539 | char buf[INET6_ADDRSTRLEN]; | 569 | char buf[INET6_ADDRSTRLEN]; |
@@ -566,7 +596,7 @@ udp_address_to_string (void *cls, const void *addr, size_t addrlen) | |||
566 | } | 596 | } |
567 | else | 597 | else |
568 | { | 598 | { |
569 | return NULL ; | 599 | return NULL; |
570 | } | 600 | } |
571 | inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); | 601 | inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); |
572 | 602 | ||
@@ -576,6 +606,7 @@ udp_address_to_string (void *cls, const void *addr, size_t addrlen) | |||
576 | return rbuf; | 606 | return rbuf; |
577 | } | 607 | } |
578 | 608 | ||
609 | |||
579 | /** | 610 | /** |
580 | * Function called to convert a string address to | 611 | * Function called to convert a string address to |
581 | * a binary address. | 612 | * a binary address. |
@@ -585,12 +616,15 @@ udp_address_to_string (void *cls, const void *addr, size_t addrlen) | |||
585 | * @param addrlen length of the address | 616 | * @param addrlen length of the address |
586 | * @param buf location to store the buffer | 617 | * @param buf location to store the buffer |
587 | * @param added location to store the number of bytes in the buffer. | 618 | * @param added location to store the number of bytes in the buffer. |
588 | * If the function returns GNUNET_SYSERR, its contents are undefined. | 619 | * If the function returns #GNUNET_SYSERR, its contents are undefined. |
589 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | 620 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
590 | */ | 621 | */ |
591 | static int | 622 | static int |
592 | udp_string_to_address (void *cls, const char *addr, uint16_t addrlen, | 623 | udp_string_to_address (void *cls, |
593 | void **buf, size_t *added) | 624 | const char *addr, |
625 | uint16_t addrlen, | ||
626 | void **buf, | ||
627 | size_t *added) | ||
594 | { | 628 | { |
595 | struct sockaddr_storage socket_address; | 629 | struct sockaddr_storage socket_address; |
596 | char *address; | 630 | char *address; |
@@ -639,9 +673,9 @@ udp_string_to_address (void *cls, const char *addr, uint16_t addrlen, | |||
639 | address[0] = '\0'; | 673 | address[0] = '\0'; |
640 | address++; | 674 | address++; |
641 | 675 | ||
642 | if (GNUNET_OK | 676 | if (GNUNET_OK != |
643 | != GNUNET_STRINGS_to_address_ip (address, strlen (address), | 677 | GNUNET_STRINGS_to_address_ip (address, strlen (address), |
644 | &socket_address)) | 678 | &socket_address)) |
645 | { | 679 | { |
646 | GNUNET_break(0); | 680 | GNUNET_break(0); |
647 | GNUNET_free(plugin); | 681 | GNUNET_free(plugin); |
@@ -682,8 +716,10 @@ udp_string_to_address (void *cls, const char *addr, uint16_t addrlen, | |||
682 | } | 716 | } |
683 | } | 717 | } |
684 | 718 | ||
719 | |||
685 | static void | 720 | static void |
686 | ppc_cancel_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 721 | ppc_cancel_task (void *cls, |
722 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
687 | { | 723 | { |
688 | struct PrettyPrinterContext *ppc = cls; | 724 | struct PrettyPrinterContext *ppc = cls; |
689 | 725 | ||
@@ -697,6 +733,7 @@ ppc_cancel_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
697 | GNUNET_free(ppc); | 733 | GNUNET_free(ppc); |
698 | } | 734 | } |
699 | 735 | ||
736 | |||
700 | /** | 737 | /** |
701 | * Append our port and forward the result. | 738 | * Append our port and forward the result. |
702 | * | 739 | * |
@@ -741,6 +778,7 @@ append_port (void *cls, const char *hostname) | |||
741 | GNUNET_free(ret); | 778 | GNUNET_free(ret); |
742 | } | 779 | } |
743 | 780 | ||
781 | |||
744 | /** | 782 | /** |
745 | * Convert the transports address to a nice, human-readable | 783 | * Convert the transports address to a nice, human-readable |
746 | * format. | 784 | * format. |
@@ -756,10 +794,14 @@ append_port (void *cls, const char *hostname) | |||
756 | * @param asc_cls closure for @a asc | 794 | * @param asc_cls closure for @a asc |
757 | */ | 795 | */ |
758 | static void | 796 | static void |
759 | udp_plugin_address_pretty_printer (void *cls, const char *type, | 797 | udp_plugin_address_pretty_printer (void *cls, |
760 | const void *addr, size_t addrlen, int numeric, | 798 | const char *type, |
761 | struct GNUNET_TIME_Relative timeout, | 799 | const void *addr, |
762 | GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls) | 800 | size_t addrlen, |
801 | int numeric, | ||
802 | struct GNUNET_TIME_Relative timeout, | ||
803 | GNUNET_TRANSPORT_AddressStringCallback asc, | ||
804 | void *asc_cls) | ||
763 | { | 805 | { |
764 | struct PrettyPrinterContext *ppc; | 806 | struct PrettyPrinterContext *ppc; |
765 | const void *sb; | 807 | const void *sb; |
@@ -824,15 +866,17 @@ udp_plugin_address_pretty_printer (void *cls, const char *type, | |||
824 | timeout, &append_port, ppc); | 866 | timeout, &append_port, ppc); |
825 | } | 867 | } |
826 | 868 | ||
869 | |||
827 | static void | 870 | static void |
828 | call_continuation (struct UDP_MessageWrapper *udpw, int result) | 871 | call_continuation (struct UDP_MessageWrapper *udpw, |
872 | int result) | ||
829 | { | 873 | { |
830 | size_t overhead; | 874 | size_t overhead; |
831 | 875 | ||
832 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 876 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
833 | "Calling continuation for %u byte message to `%s' with result %s\n", | 877 | "Calling continuation for %u byte message to `%s' with result %s\n", |
834 | udpw->payload_size, GNUNET_i2s (&udpw->session->target), | 878 | udpw->payload_size, GNUNET_i2s (&udpw->session->target), |
835 | (GNUNET_OK == result) ? "OK" : "SYSERR"); | 879 | (GNUNET_OK == result) ? "OK" : "SYSERR"); |
836 | 880 | ||
837 | if (udpw->msg_size >= udpw->payload_size) | 881 | if (udpw->msg_size >= udpw->payload_size) |
838 | overhead = udpw->msg_size - udpw->payload_size; | 882 | overhead = udpw->msg_size - udpw->payload_size; |
@@ -844,7 +888,7 @@ call_continuation (struct UDP_MessageWrapper *udpw, int result) | |||
844 | case GNUNET_OK: | 888 | case GNUNET_OK: |
845 | switch (udpw->msg_type) | 889 | switch (udpw->msg_type) |
846 | { | 890 | { |
847 | case MSG_UNFRAGMENTED: | 891 | case UMT_MSG_UNFRAGMENTED: |
848 | if (NULL != udpw->cont) | 892 | if (NULL != udpw->cont) |
849 | { | 893 | { |
850 | /* Transport continuation */ | 894 | /* Transport continuation */ |
@@ -864,7 +908,7 @@ call_continuation (struct UDP_MessageWrapper *udpw, int result) | |||
864 | GNUNET_STATISTICS_update (plugin->env->stats, | 908 | GNUNET_STATISTICS_update (plugin->env->stats, |
865 | "# UDP, total, bytes payload, sent", udpw->payload_size, GNUNET_NO); | 909 | "# UDP, total, bytes payload, sent", udpw->payload_size, GNUNET_NO); |
866 | break; | 910 | break; |
867 | case MSG_FRAGMENTED_COMPLETE: | 911 | case UMT_MSG_FRAGMENTED_COMPLETE: |
868 | GNUNET_assert(NULL != udpw->frag_ctx); | 912 | GNUNET_assert(NULL != udpw->frag_ctx); |
869 | if (udpw->frag_ctx->cont != NULL ) | 913 | if (udpw->frag_ctx->cont != NULL ) |
870 | udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls, &udpw->session->target, | 914 | udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls, &udpw->session->target, |
@@ -885,7 +929,7 @@ call_continuation (struct UDP_MessageWrapper *udpw, int result) | |||
885 | GNUNET_STATISTICS_update (plugin->env->stats, | 929 | GNUNET_STATISTICS_update (plugin->env->stats, |
886 | "# UDP, fragmented msgs, messages, pending", -1, GNUNET_NO); | 930 | "# UDP, fragmented msgs, messages, pending", -1, GNUNET_NO); |
887 | break; | 931 | break; |
888 | case MSG_FRAGMENTED: | 932 | case UMT_MSG_FRAGMENTED: |
889 | /* Fragmented message: enqueue next fragment */ | 933 | /* Fragmented message: enqueue next fragment */ |
890 | if (NULL != udpw->cont) | 934 | if (NULL != udpw->cont) |
891 | udpw->cont (udpw->cont_cls, &udpw->session->target, result, | 935 | udpw->cont (udpw->cont_cls, &udpw->session->target, result, |
@@ -896,7 +940,7 @@ call_continuation (struct UDP_MessageWrapper *udpw, int result) | |||
896 | "# UDP, fragmented msgs, fragments bytes, sent, success", | 940 | "# UDP, fragmented msgs, fragments bytes, sent, success", |
897 | udpw->msg_size, GNUNET_NO); | 941 | udpw->msg_size, GNUNET_NO); |
898 | break; | 942 | break; |
899 | case MSG_ACK: | 943 | case UMT_MSG_ACK: |
900 | /* No continuation */ | 944 | /* No continuation */ |
901 | GNUNET_STATISTICS_update (plugin->env->stats, | 945 | GNUNET_STATISTICS_update (plugin->env->stats, |
902 | "# UDP, ACK msgs, messages, sent, success", 1, GNUNET_NO); | 946 | "# UDP, ACK msgs, messages, sent, success", 1, GNUNET_NO); |
@@ -906,11 +950,7 @@ call_continuation (struct UDP_MessageWrapper *udpw, int result) | |||
906 | GNUNET_STATISTICS_update (plugin->env->stats, | 950 | GNUNET_STATISTICS_update (plugin->env->stats, |
907 | "# UDP, total, bytes overhead, sent", overhead, GNUNET_NO); | 951 | "# UDP, total, bytes overhead, sent", overhead, GNUNET_NO); |
908 | break; | 952 | break; |
909 | case MSG_BEACON: | ||
910 | GNUNET_break(0); | ||
911 | break; | ||
912 | default: | 953 | default: |
913 | LOG(GNUNET_ERROR_TYPE_ERROR, "ERROR: %u\n", udpw->msg_type); | ||
914 | GNUNET_break(0); | 954 | GNUNET_break(0); |
915 | break; | 955 | break; |
916 | } | 956 | } |
@@ -918,7 +958,7 @@ call_continuation (struct UDP_MessageWrapper *udpw, int result) | |||
918 | case GNUNET_SYSERR: | 958 | case GNUNET_SYSERR: |
919 | switch (udpw->msg_type) | 959 | switch (udpw->msg_type) |
920 | { | 960 | { |
921 | case MSG_UNFRAGMENTED: | 961 | case UMT_MSG_UNFRAGMENTED: |
922 | /* Unfragmented message: failed to send */ | 962 | /* Unfragmented message: failed to send */ |
923 | if (NULL != udpw->cont) | 963 | if (NULL != udpw->cont) |
924 | udpw->cont (udpw->cont_cls, &udpw->session->target, result, | 964 | udpw->cont (udpw->cont_cls, &udpw->session->target, result, |
@@ -932,7 +972,7 @@ call_continuation (struct UDP_MessageWrapper *udpw, int result) | |||
932 | "# UDP, unfragmented msgs, bytes overhead, sent, failure", overhead, | 972 | "# UDP, unfragmented msgs, bytes overhead, sent, failure", overhead, |
933 | GNUNET_NO); | 973 | GNUNET_NO); |
934 | break; | 974 | break; |
935 | case MSG_FRAGMENTED_COMPLETE: | 975 | case UMT_MSG_FRAGMENTED_COMPLETE: |
936 | GNUNET_assert(NULL != udpw->frag_ctx); | 976 | GNUNET_assert(NULL != udpw->frag_ctx); |
937 | if (udpw->frag_ctx->cont != NULL ) | 977 | if (udpw->frag_ctx->cont != NULL ) |
938 | udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls, &udpw->session->target, | 978 | udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls, &udpw->session->target, |
@@ -952,7 +992,7 @@ call_continuation (struct UDP_MessageWrapper *udpw, int result) | |||
952 | GNUNET_STATISTICS_update (plugin->env->stats, | 992 | GNUNET_STATISTICS_update (plugin->env->stats, |
953 | "# UDP, fragmented msgs, messages, pending", -1, GNUNET_NO); | 993 | "# UDP, fragmented msgs, messages, pending", -1, GNUNET_NO); |
954 | break; | 994 | break; |
955 | case MSG_FRAGMENTED: | 995 | case UMT_MSG_FRAGMENTED: |
956 | GNUNET_assert(NULL != udpw->frag_ctx); | 996 | GNUNET_assert(NULL != udpw->frag_ctx); |
957 | /* Fragmented message: failed to send */ | 997 | /* Fragmented message: failed to send */ |
958 | GNUNET_STATISTICS_update (plugin->env->stats, | 998 | GNUNET_STATISTICS_update (plugin->env->stats, |
@@ -961,15 +1001,11 @@ call_continuation (struct UDP_MessageWrapper *udpw, int result) | |||
961 | "# UDP, fragmented msgs, fragments bytes, sent, failure", | 1001 | "# UDP, fragmented msgs, fragments bytes, sent, failure", |
962 | udpw->msg_size, GNUNET_NO); | 1002 | udpw->msg_size, GNUNET_NO); |
963 | break; | 1003 | break; |
964 | case MSG_ACK: | 1004 | case UMT_MSG_ACK: |
965 | /* ACK message: failed to send */ | 1005 | /* ACK message: failed to send */ |
966 | GNUNET_STATISTICS_update (plugin->env->stats, | 1006 | GNUNET_STATISTICS_update (plugin->env->stats, |
967 | "# UDP, ACK msgs, messages, sent, failure", 1, GNUNET_NO); | 1007 | "# UDP, ACK msgs, messages, sent, failure", 1, GNUNET_NO); |
968 | break; | 1008 | break; |
969 | case MSG_BEACON: | ||
970 | /* Beacon message: failed to send */ | ||
971 | GNUNET_break(0); | ||
972 | break; | ||
973 | default: | 1009 | default: |
974 | GNUNET_break(0); | 1010 | GNUNET_break(0); |
975 | break; | 1011 | break; |
@@ -981,6 +1017,7 @@ call_continuation (struct UDP_MessageWrapper *udpw, int result) | |||
981 | } | 1017 | } |
982 | } | 1018 | } |
983 | 1019 | ||
1020 | |||
984 | /** | 1021 | /** |
985 | * Check if the given port is plausible (must be either our listen | 1022 | * Check if the given port is plausible (must be either our listen |
986 | * port or our advertised port). If it is neither, we return | 1023 | * port or our advertised port). If it is neither, we return |
@@ -998,6 +1035,7 @@ check_port (struct Plugin *plugin, uint16_t in_port) | |||
998 | return GNUNET_SYSERR; | 1035 | return GNUNET_SYSERR; |
999 | } | 1036 | } |
1000 | 1037 | ||
1038 | |||
1001 | /** | 1039 | /** |
1002 | * Function that will be called to check if a binary address for this | 1040 | * Function that will be called to check if a binary address for this |
1003 | * plugin is well-formed and corresponds to an address for THIS peer | 1041 | * plugin is well-formed and corresponds to an address for THIS peer |
@@ -1055,6 +1093,7 @@ udp_plugin_check_address (void *cls, const void *addr, size_t addrlen) | |||
1055 | return GNUNET_OK; | 1093 | return GNUNET_OK; |
1056 | } | 1094 | } |
1057 | 1095 | ||
1096 | |||
1058 | /** | 1097 | /** |
1059 | * Function to free last resources associated with a session. | 1098 | * Function to free last resources associated with a session. |
1060 | * | 1099 | * |
@@ -1072,8 +1111,10 @@ free_session (struct Session *s) | |||
1072 | GNUNET_free(s); | 1111 | GNUNET_free(s); |
1073 | } | 1112 | } |
1074 | 1113 | ||
1114 | |||
1075 | static void | 1115 | static void |
1076 | dequeue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw) | 1116 | dequeue (struct Plugin *plugin, |
1117 | struct UDP_MessageWrapper * udpw) | ||
1077 | { | 1118 | { |
1078 | if (plugin->bytes_in_buffer < udpw->msg_size) | 1119 | if (plugin->bytes_in_buffer < udpw->msg_size) |
1079 | GNUNET_break(0); | 1120 | GNUNET_break(0); |
@@ -1096,8 +1137,10 @@ dequeue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw) | |||
1096 | GNUNET_break (0); | 1137 | GNUNET_break (0); |
1097 | } | 1138 | } |
1098 | 1139 | ||
1140 | |||
1099 | static void | 1141 | static void |
1100 | fragmented_message_done (struct UDP_FragmentationContext *fc, int result) | 1142 | fragmented_message_done (struct UDP_FragmentationContext *fc, |
1143 | int result) | ||
1101 | { | 1144 | { |
1102 | struct UDP_MessageWrapper *udpw; | 1145 | struct UDP_MessageWrapper *udpw; |
1103 | struct UDP_MessageWrapper *tmp; | 1146 | struct UDP_MessageWrapper *tmp; |
@@ -1110,7 +1153,7 @@ fragmented_message_done (struct UDP_FragmentationContext *fc, int result) | |||
1110 | 1153 | ||
1111 | /* Call continuation for fragmented message */ | 1154 | /* Call continuation for fragmented message */ |
1112 | memset (&dummy, 0, sizeof(dummy)); | 1155 | memset (&dummy, 0, sizeof(dummy)); |
1113 | dummy.msg_type = MSG_FRAGMENTED_COMPLETE; | 1156 | dummy.msg_type = UMT_MSG_FRAGMENTED_COMPLETE; |
1114 | dummy.msg_size = s->frag_ctx->on_wire_size; | 1157 | dummy.msg_size = s->frag_ctx->on_wire_size; |
1115 | dummy.payload_size = s->frag_ctx->payload_size; | 1158 | dummy.payload_size = s->frag_ctx->payload_size; |
1116 | dummy.frag_ctx = s->frag_ctx; | 1159 | dummy.frag_ctx = s->frag_ctx; |
@@ -1158,6 +1201,7 @@ fragmented_message_done (struct UDP_FragmentationContext *fc, int result) | |||
1158 | GNUNET_free(fc); | 1201 | GNUNET_free(fc); |
1159 | } | 1202 | } |
1160 | 1203 | ||
1204 | |||
1161 | /** | 1205 | /** |
1162 | * Functions with this signature are called whenever we need | 1206 | * Functions with this signature are called whenever we need |
1163 | * to close a session due to a disconnect or failure to | 1207 | * to close a session due to a disconnect or failure to |
@@ -1240,9 +1284,10 @@ udp_disconnect_session (void *cls, struct Session *s) | |||
1240 | return GNUNET_OK; | 1284 | return GNUNET_OK; |
1241 | } | 1285 | } |
1242 | 1286 | ||
1287 | |||
1243 | /** | 1288 | /** |
1244 | * Function that is called to get the keepalive factor. | 1289 | * Function that is called to get the keepalive factor. |
1245 | * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to | 1290 | * #GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to |
1246 | * calculate the interval between keepalive packets. | 1291 | * calculate the interval between keepalive packets. |
1247 | * | 1292 | * |
1248 | * @param cls closure with the `struct Plugin` | 1293 | * @param cls closure with the `struct Plugin` |
@@ -1254,6 +1299,7 @@ udp_query_keepalive_factor (void *cls) | |||
1254 | return 15; | 1299 | return 15; |
1255 | } | 1300 | } |
1256 | 1301 | ||
1302 | |||
1257 | /** | 1303 | /** |
1258 | * Destroy a session, plugin is being unloaded. | 1304 | * Destroy a session, plugin is being unloaded. |
1259 | * | 1305 | * |
@@ -1263,8 +1309,9 @@ udp_query_keepalive_factor (void *cls) | |||
1263 | * @return #GNUNET_OK (continue to iterate) | 1309 | * @return #GNUNET_OK (continue to iterate) |
1264 | */ | 1310 | */ |
1265 | static int | 1311 | static int |
1266 | disconnect_and_free_it (void *cls, const struct GNUNET_PeerIdentity *key, | 1312 | disconnect_and_free_it (void *cls, |
1267 | void *value) | 1313 | const struct GNUNET_PeerIdentity *key, |
1314 | void *value) | ||
1268 | { | 1315 | { |
1269 | struct Plugin *plugin = cls; | 1316 | struct Plugin *plugin = cls; |
1270 | 1317 | ||
@@ -1272,6 +1319,7 @@ disconnect_and_free_it (void *cls, const struct GNUNET_PeerIdentity *key, | |||
1272 | return GNUNET_OK; | 1319 | return GNUNET_OK; |
1273 | } | 1320 | } |
1274 | 1321 | ||
1322 | |||
1275 | /** | 1323 | /** |
1276 | * Disconnect from a remote node. Clean up session if we have one for | 1324 | * Disconnect from a remote node. Clean up session if we have one for |
1277 | * this peer. | 1325 | * this peer. |
@@ -1281,17 +1329,20 @@ disconnect_and_free_it (void *cls, const struct GNUNET_PeerIdentity *key, | |||
1281 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed | 1329 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed |
1282 | */ | 1330 | */ |
1283 | static void | 1331 | static void |
1284 | udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) | 1332 | udp_disconnect (void *cls, |
1333 | const struct GNUNET_PeerIdentity *target) | ||
1285 | { | 1334 | { |
1286 | struct Plugin *plugin = cls; | 1335 | struct Plugin *plugin = cls; |
1287 | 1336 | ||
1288 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer `%s'\n", | 1337 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1289 | GNUNET_i2s (target)); | 1338 | "Disconnecting from peer `%s'\n", |
1339 | GNUNET_i2s (target)); | ||
1290 | /* Clean up sessions */ | 1340 | /* Clean up sessions */ |
1291 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, target, | 1341 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, target, |
1292 | &disconnect_and_free_it, plugin); | 1342 | &disconnect_and_free_it, plugin); |
1293 | } | 1343 | } |
1294 | 1344 | ||
1345 | |||
1295 | /** | 1346 | /** |
1296 | * Session was idle, so disconnect it | 1347 | * Session was idle, so disconnect it |
1297 | * | 1348 | * |
@@ -1299,18 +1350,22 @@ udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) | |||
1299 | * @param tc scheduler context | 1350 | * @param tc scheduler context |
1300 | */ | 1351 | */ |
1301 | static void | 1352 | static void |
1302 | session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1353 | session_timeout (void *cls, |
1354 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1303 | { | 1355 | { |
1304 | struct Session *s = cls; | 1356 | struct Session *s = cls; |
1305 | 1357 | ||
1306 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 1358 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
1307 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1359 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1308 | "Session %p was idle for %s, disconnecting\n", s, | 1360 | "Session %p was idle for %s, disconnecting\n", |
1309 | GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT, GNUNET_YES)); | 1361 | s, |
1362 | GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT, | ||
1363 | GNUNET_YES)); | ||
1310 | /* call session destroy function */ | 1364 | /* call session destroy function */ |
1311 | udp_disconnect_session (plugin, s); | 1365 | udp_disconnect_session (plugin, s); |
1312 | } | 1366 | } |
1313 | 1367 | ||
1368 | |||
1314 | /** | 1369 | /** |
1315 | * Increment session timeout due to activity | 1370 | * Increment session timeout due to activity |
1316 | * | 1371 | * |
@@ -1328,9 +1383,10 @@ reschedule_session_timeout (struct Session *s) | |||
1328 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Timeout restarted for session %p\n", s); | 1383 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Timeout restarted for session %p\n", s); |
1329 | } | 1384 | } |
1330 | 1385 | ||
1386 | |||
1331 | static struct Session * | 1387 | static struct Session * |
1332 | create_session (struct Plugin *plugin, | 1388 | create_session (struct Plugin *plugin, |
1333 | const struct GNUNET_HELLO_Address *address) | 1389 | const struct GNUNET_HELLO_Address *address) |
1334 | { | 1390 | { |
1335 | struct Session *s; | 1391 | struct Session *s; |
1336 | 1392 | ||
@@ -1343,20 +1399,24 @@ create_session (struct Plugin *plugin, | |||
1343 | s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO_ABS; | 1399 | s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO_ABS; |
1344 | s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO; | 1400 | s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO; |
1345 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, | 1401 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, |
1346 | &session_timeout, s); | 1402 | &session_timeout, s); |
1347 | return s; | 1403 | return s; |
1348 | } | 1404 | } |
1349 | 1405 | ||
1406 | |||
1350 | static int | 1407 | static int |
1351 | session_cmp_it (void *cls, const struct GNUNET_PeerIdentity * key, void *value) | 1408 | session_cmp_it (void *cls, |
1409 | const struct GNUNET_PeerIdentity *key, | ||
1410 | void *value) | ||
1352 | { | 1411 | { |
1353 | struct SessionCompareContext * cctx = cls; | 1412 | struct SessionCompareContext *cctx = cls; |
1354 | const struct GNUNET_HELLO_Address *address = cctx->address; | 1413 | const struct GNUNET_HELLO_Address *address = cctx->address; |
1355 | struct Session *s = value; | 1414 | struct Session *s = value; |
1356 | 1415 | ||
1357 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Comparing address %s <-> %s\n", | 1416 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1358 | udp_address_to_string (NULL, (void *) address->address, address->address_length), | 1417 | "Comparing address %s <-> %s\n", |
1359 | udp_address_to_string (NULL, s->address->address, s->address->address_length)); | 1418 | udp_address_to_string (NULL, address->address, address->address_length), |
1419 | udp_address_to_string (NULL, s->address->address, s->address->address_length)); | ||
1360 | 1420 | ||
1361 | if (0 == GNUNET_HELLO_address_cmp(s->address, cctx->address)) | 1421 | if (0 == GNUNET_HELLO_address_cmp(s->address, cctx->address)) |
1362 | { | 1422 | { |
@@ -1366,6 +1426,7 @@ session_cmp_it (void *cls, const struct GNUNET_PeerIdentity * key, void *value) | |||
1366 | return GNUNET_YES; | 1426 | return GNUNET_YES; |
1367 | } | 1427 | } |
1368 | 1428 | ||
1429 | |||
1369 | /** | 1430 | /** |
1370 | * Function obtain the network type for a session | 1431 | * Function obtain the network type for a session |
1371 | * | 1432 | * |
@@ -1374,11 +1435,13 @@ session_cmp_it (void *cls, const struct GNUNET_PeerIdentity * key, void *value) | |||
1374 | * @return the network type | 1435 | * @return the network type |
1375 | */ | 1436 | */ |
1376 | static enum GNUNET_ATS_Network_Type | 1437 | static enum GNUNET_ATS_Network_Type |
1377 | udp_get_network (void *cls, struct Session *session) | 1438 | udp_get_network (void *cls, |
1439 | struct Session *session) | ||
1378 | { | 1440 | { |
1379 | return ntohl (session->ats.value); | 1441 | return ntohl (session->ats.value); |
1380 | } | 1442 | } |
1381 | 1443 | ||
1444 | |||
1382 | /** | 1445 | /** |
1383 | * Creates a new outbound session the transport service will use to | 1446 | * Creates a new outbound session the transport service will use to |
1384 | * send data to the peer | 1447 | * send data to the peer |
@@ -1389,7 +1452,7 @@ udp_get_network (void *cls, struct Session *session) | |||
1389 | */ | 1452 | */ |
1390 | static struct Session * | 1453 | static struct Session * |
1391 | udp_plugin_lookup_session (void *cls, | 1454 | udp_plugin_lookup_session (void *cls, |
1392 | const struct GNUNET_HELLO_Address *address) | 1455 | const struct GNUNET_HELLO_Address *address) |
1393 | { | 1456 | { |
1394 | struct Plugin * plugin = cls; | 1457 | struct Plugin * plugin = cls; |
1395 | struct IPv6UdpAddress * udp_a6; | 1458 | struct IPv6UdpAddress * udp_a6; |
@@ -1398,33 +1461,34 @@ udp_plugin_lookup_session (void *cls, | |||
1398 | GNUNET_assert(plugin != NULL); | 1461 | GNUNET_assert(plugin != NULL); |
1399 | GNUNET_assert(address != NULL); | 1462 | GNUNET_assert(address != NULL); |
1400 | 1463 | ||
1401 | if ((address->address == NULL )|| | 1464 | if ( (address->address == NULL )|| |
1402 | ((address->address_length != sizeof (struct IPv4UdpAddress)) && | 1465 | ((address->address_length != sizeof (struct IPv4UdpAddress)) && |
1403 | (address->address_length != sizeof (struct IPv6UdpAddress)))){ | 1466 | (address->address_length != sizeof (struct IPv6UdpAddress)))) |
1404 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1467 | { |
1405 | _("Trying to create session for address of unexpected length %u (should be %u or %u)\n"), | 1468 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1406 | address->address_length, | 1469 | _("Trying to create session for address of unexpected length %u (should be %u or %u)\n"), |
1407 | sizeof (struct IPv4UdpAddress), | 1470 | address->address_length, |
1408 | sizeof (struct IPv6UdpAddress)); | 1471 | sizeof (struct IPv4UdpAddress), |
1409 | return NULL; | 1472 | sizeof (struct IPv6UdpAddress)); |
1410 | } | 1473 | return NULL; |
1474 | } | ||
1411 | 1475 | ||
1412 | if (address->address_length == sizeof(struct IPv4UdpAddress)) | 1476 | if (address->address_length == sizeof(struct IPv4UdpAddress)) |
1413 | { | 1477 | { |
1414 | if (plugin->sockv4 == NULL ) | 1478 | if (plugin->sockv4 == NULL) |
1415 | return NULL ; | 1479 | return NULL; |
1416 | udp_a4 = (struct IPv4UdpAddress *) address->address; | 1480 | udp_a4 = (struct IPv4UdpAddress *) address->address; |
1417 | if (udp_a4->u4_port == 0) | 1481 | if (udp_a4->u4_port == 0) |
1418 | return NULL ; | 1482 | return NULL; |
1419 | } | 1483 | } |
1420 | 1484 | ||
1421 | if (address->address_length == sizeof(struct IPv6UdpAddress)) | 1485 | if (address->address_length == sizeof(struct IPv6UdpAddress)) |
1422 | { | 1486 | { |
1423 | if (plugin->sockv6 == NULL ) | 1487 | if (plugin->sockv6 == NULL) |
1424 | return NULL ; | 1488 | return NULL; |
1425 | udp_a6 = (struct IPv6UdpAddress *) address->address; | 1489 | udp_a6 = (struct IPv6UdpAddress *) address->address; |
1426 | if (udp_a6->u6_port == 0) | 1490 | if (udp_a6->u6_port == 0) |
1427 | return NULL ; | 1491 | return NULL; |
1428 | } | 1492 | } |
1429 | 1493 | ||
1430 | /* check if session already exists */ | 1494 | /* check if session already exists */ |
@@ -1439,16 +1503,18 @@ udp_plugin_lookup_session (void *cls, | |||
1439 | session_cmp_it, &cctx); | 1503 | session_cmp_it, &cctx); |
1440 | if (cctx.res != NULL ) | 1504 | if (cctx.res != NULL ) |
1441 | { | 1505 | { |
1442 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p\n", cctx.res); | 1506 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1507 | "Found existing session %p\n", | ||
1508 | cctx.res); | ||
1443 | return cctx.res; | 1509 | return cctx.res; |
1444 | } | 1510 | } |
1445 | return NULL ; | 1511 | return NULL; |
1446 | } | 1512 | } |
1447 | 1513 | ||
1448 | 1514 | ||
1449 | static struct Session * | 1515 | static struct Session * |
1450 | udp_plugin_create_session (void *cls, | 1516 | udp_plugin_create_session (void *cls, |
1451 | const struct GNUNET_HELLO_Address *address) | 1517 | const struct GNUNET_HELLO_Address *address) |
1452 | { | 1518 | { |
1453 | struct Session *s; | 1519 | struct Session *s; |
1454 | struct IPv4UdpAddress *udp_v4; | 1520 | struct IPv4UdpAddress *udp_v4; |
@@ -1485,7 +1551,7 @@ udp_plugin_create_session (void *cls, | |||
1485 | } | 1551 | } |
1486 | 1552 | ||
1487 | if (NULL == s) | 1553 | if (NULL == s) |
1488 | return NULL ; /* protocol not supported or address invalid */ | 1554 | return NULL; /* protocol not supported or address invalid */ |
1489 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1555 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1490 | "Creating new %s session %p for peer `%s' address `%s'\n", | 1556 | "Creating new %s session %p for peer `%s' address `%s'\n", |
1491 | GNUNET_HELLO_address_check_option (address, GNUNET_HELLO_ADDRESS_INFO_INBOUND) ? "inbound" : "outbound", | 1557 | GNUNET_HELLO_address_check_option (address, GNUNET_HELLO_ADDRESS_INFO_INBOUND) ? "inbound" : "outbound", |
@@ -1498,13 +1564,15 @@ udp_plugin_create_session (void *cls, | |||
1498 | return s; | 1564 | return s; |
1499 | } | 1565 | } |
1500 | 1566 | ||
1567 | |||
1501 | static void | 1568 | static void |
1502 | udp_plugin_update_session_timeout (void *cls, | 1569 | udp_plugin_update_session_timeout (void *cls, |
1503 | const struct GNUNET_PeerIdentity *peer, struct Session *session) | 1570 | const struct GNUNET_PeerIdentity *peer, |
1571 | struct Session *session) | ||
1504 | { | 1572 | { |
1505 | if (GNUNET_YES | 1573 | if (GNUNET_YES != |
1506 | != GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessions, peer, | 1574 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessions, peer, |
1507 | session)) | 1575 | session)) |
1508 | { | 1576 | { |
1509 | GNUNET_break(0); | 1577 | GNUNET_break(0); |
1510 | return; | 1578 | return; |
@@ -1514,6 +1582,7 @@ udp_plugin_update_session_timeout (void *cls, | |||
1514 | reschedule_session_timeout (session); | 1582 | reschedule_session_timeout (session); |
1515 | } | 1583 | } |
1516 | 1584 | ||
1585 | |||
1517 | /** | 1586 | /** |
1518 | * Creates a new outbound session the transport service will use to send data to the | 1587 | * Creates a new outbound session the transport service will use to send data to the |
1519 | * peer | 1588 | * peer |
@@ -1523,18 +1592,19 @@ udp_plugin_update_session_timeout (void *cls, | |||
1523 | * @return the session or NULL of max connections exceeded | 1592 | * @return the session or NULL of max connections exceeded |
1524 | */ | 1593 | */ |
1525 | static struct Session * | 1594 | static struct Session * |
1526 | udp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) | 1595 | udp_plugin_get_session (void *cls, |
1596 | const struct GNUNET_HELLO_Address *address) | ||
1527 | { | 1597 | { |
1528 | struct Session *s; | 1598 | struct Session *s; |
1529 | 1599 | ||
1530 | if (NULL == address) | 1600 | if (NULL == address) |
1531 | { | 1601 | { |
1532 | GNUNET_break(0); | 1602 | GNUNET_break(0); |
1533 | return NULL ; | 1603 | return NULL; |
1534 | } | 1604 | } |
1535 | if ((address->address_length != sizeof(struct IPv4UdpAddress)) | 1605 | if ( (address->address_length != sizeof(struct IPv4UdpAddress)) && |
1536 | && (address->address_length != sizeof(struct IPv6UdpAddress))) | 1606 | (address->address_length != sizeof(struct IPv6UdpAddress)) ) |
1537 | return NULL ; | 1607 | return NULL; |
1538 | 1608 | ||
1539 | /* otherwise create new */ | 1609 | /* otherwise create new */ |
1540 | if (NULL != (s = udp_plugin_lookup_session (cls, address))) | 1610 | if (NULL != (s = udp_plugin_lookup_session (cls, address))) |
@@ -1542,8 +1612,10 @@ udp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) | |||
1542 | return udp_plugin_create_session (cls, address); | 1612 | return udp_plugin_create_session (cls, address); |
1543 | } | 1613 | } |
1544 | 1614 | ||
1615 | |||
1545 | static void | 1616 | static void |
1546 | enqueue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw) | 1617 | enqueue (struct Plugin *plugin, |
1618 | struct UDP_MessageWrapper *udpw) | ||
1547 | { | 1619 | { |
1548 | if (plugin->bytes_in_buffer + udpw->msg_size > INT64_MAX) | 1620 | if (plugin->bytes_in_buffer + udpw->msg_size > INT64_MAX) |
1549 | GNUNET_break(0); | 1621 | GNUNET_break(0); |
@@ -1565,6 +1637,7 @@ enqueue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw) | |||
1565 | GNUNET_break (0); | 1637 | GNUNET_break (0); |
1566 | } | 1638 | } |
1567 | 1639 | ||
1640 | |||
1568 | /** | 1641 | /** |
1569 | * Fragment message was transmitted via UDP, let fragmentation know | 1642 | * Fragment message was transmitted via UDP, let fragmentation know |
1570 | * to send the next fragment now. | 1643 | * to send the next fragment now. |
@@ -1576,14 +1649,18 @@ enqueue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw) | |||
1576 | * @param physical bytes physical sent | 1649 | * @param physical bytes physical sent |
1577 | */ | 1650 | */ |
1578 | static void | 1651 | static void |
1579 | send_next_fragment (void *cls, const struct GNUNET_PeerIdentity *target, | 1652 | send_next_fragment (void *cls, |
1580 | int result, size_t payload, size_t physical) | 1653 | const struct GNUNET_PeerIdentity *target, |
1654 | int result, | ||
1655 | size_t payload, | ||
1656 | size_t physical) | ||
1581 | { | 1657 | { |
1582 | struct UDP_MessageWrapper *udpw = cls; | 1658 | struct UDP_MessageWrapper *udpw = cls; |
1583 | 1659 | ||
1584 | GNUNET_FRAGMENT_context_transmission_done (udpw->frag_ctx->frag); | 1660 | GNUNET_FRAGMENT_context_transmission_done (udpw->frag_ctx->frag); |
1585 | } | 1661 | } |
1586 | 1662 | ||
1663 | |||
1587 | /** | 1664 | /** |
1588 | * Function that is called with messages created by the fragmentation | 1665 | * Function that is called with messages created by the fragmentation |
1589 | * module. In the case of the 'proc' callback of the | 1666 | * module. In the case of the 'proc' callback of the |
@@ -1612,12 +1689,13 @@ enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1612 | udpw->cont_cls = udpw; | 1689 | udpw->cont_cls = udpw; |
1613 | udpw->timeout = frag_ctx->timeout; | 1690 | udpw->timeout = frag_ctx->timeout; |
1614 | udpw->frag_ctx = frag_ctx; | 1691 | udpw->frag_ctx = frag_ctx; |
1615 | udpw->msg_type = MSG_FRAGMENTED; | 1692 | udpw->msg_type = UMT_MSG_FRAGMENTED; |
1616 | memcpy (udpw->msg_buf, msg, msg_len); | 1693 | memcpy (udpw->msg_buf, msg, msg_len); |
1617 | enqueue (plugin, udpw); | 1694 | enqueue (plugin, udpw); |
1618 | schedule_select (plugin); | 1695 | schedule_select (plugin); |
1619 | } | 1696 | } |
1620 | 1697 | ||
1698 | |||
1621 | /** | 1699 | /** |
1622 | * Function that can be used by the transport service to transmit | 1700 | * Function that can be used by the transport service to transmit |
1623 | * a message using the plugin. Note that in the case of a | 1701 | * a message using the plugin. Note that in the case of a |
@@ -1646,9 +1724,13 @@ enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1646 | * and does NOT mean that the message was not transmitted (DV) | 1724 | * and does NOT mean that the message was not transmitted (DV) |
1647 | */ | 1725 | */ |
1648 | static ssize_t | 1726 | static ssize_t |
1649 | udp_plugin_send (void *cls, struct Session *s, const char *msgbuf, | 1727 | udp_plugin_send (void *cls, |
1650 | size_t msgbuf_size, unsigned int priority, struct GNUNET_TIME_Relative to, | 1728 | struct Session *s, |
1651 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) | 1729 | const char *msgbuf, |
1730 | size_t msgbuf_size, | ||
1731 | unsigned int priority, | ||
1732 | struct GNUNET_TIME_Relative to, | ||
1733 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) | ||
1652 | { | 1734 | { |
1653 | struct Plugin *plugin = cls; | 1735 | struct Plugin *plugin = cls; |
1654 | size_t udpmlen = msgbuf_size + sizeof(struct UDPMessage); | 1736 | size_t udpmlen = msgbuf_size + sizeof(struct UDPMessage); |
@@ -1659,14 +1741,12 @@ udp_plugin_send (void *cls, struct Session *s, const char *msgbuf, | |||
1659 | GNUNET_assert(plugin != NULL); | 1741 | GNUNET_assert(plugin != NULL); |
1660 | GNUNET_assert(s != NULL); | 1742 | GNUNET_assert(s != NULL); |
1661 | 1743 | ||
1662 | if ((s->address->address_length == sizeof(struct IPv6UdpAddress)) && (plugin->sockv6 == NULL )) | 1744 | if ( (s->address->address_length == sizeof(struct IPv6UdpAddress)) && |
1663 | { | 1745 | (plugin->sockv6 == NULL) ) |
1664 | return GNUNET_SYSERR; | 1746 | return GNUNET_SYSERR; |
1665 | } | 1747 | if ( (s->address->address_length == sizeof(struct IPv4UdpAddress)) && |
1666 | if ((s->address->address_length == sizeof(struct IPv4UdpAddress)) && (plugin->sockv4 == NULL )) | 1748 | (plugin->sockv4 == NULL) ) |
1667 | { | ||
1668 | return GNUNET_SYSERR; | 1749 | return GNUNET_SYSERR; |
1669 | } | ||
1670 | if (udpmlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1750 | if (udpmlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1671 | { | 1751 | { |
1672 | GNUNET_break(0); | 1752 | GNUNET_break(0); |
@@ -1679,9 +1759,11 @@ udp_plugin_send (void *cls, struct Session *s, const char *msgbuf, | |||
1679 | GNUNET_break(0); | 1759 | GNUNET_break(0); |
1680 | return GNUNET_SYSERR; | 1760 | return GNUNET_SYSERR; |
1681 | } | 1761 | } |
1682 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1762 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1683 | "UDP transmits %u-byte message to `%s' using address `%s'\n", udpmlen, | 1763 | "UDP transmits %u-byte message to `%s' using address `%s'\n", udpmlen, |
1684 | GNUNET_i2s (&s->target), udp_address_to_string (NULL, s->address->address, s->address->address_length)); | 1764 | GNUNET_i2s (&s->target), |
1765 | udp_address_to_string (NULL, s->address->address, | ||
1766 | s->address->address_length)); | ||
1685 | 1767 | ||
1686 | /* Message */ | 1768 | /* Message */ |
1687 | udp = (struct UDPMessage *) mbuf; | 1769 | udp = (struct UDPMessage *) mbuf; |
@@ -1709,7 +1791,7 @@ udp_plugin_send (void *cls, struct Session *s, const char *msgbuf, | |||
1709 | udpw->cont = cont; | 1791 | udpw->cont = cont; |
1710 | udpw->cont_cls = cont_cls; | 1792 | udpw->cont_cls = cont_cls; |
1711 | udpw->frag_ctx = NULL; | 1793 | udpw->frag_ctx = NULL; |
1712 | udpw->msg_type = MSG_UNFRAGMENTED; | 1794 | udpw->msg_type = UMT_MSG_UNFRAGMENTED; |
1713 | memcpy (udpw->msg_buf, udp, sizeof(struct UDPMessage)); | 1795 | memcpy (udpw->msg_buf, udp, sizeof(struct UDPMessage)); |
1714 | memcpy (&udpw->msg_buf[sizeof(struct UDPMessage)], msgbuf, msgbuf_size); | 1796 | memcpy (&udpw->msg_buf[sizeof(struct UDPMessage)], msgbuf, msgbuf_size); |
1715 | enqueue (plugin, udpw); | 1797 | enqueue (plugin, udpw); |
@@ -1723,7 +1805,7 @@ udp_plugin_send (void *cls, struct Session *s, const char *msgbuf, | |||
1723 | else | 1805 | else |
1724 | { | 1806 | { |
1725 | /* fragmented message */ | 1807 | /* fragmented message */ |
1726 | if (s->frag_ctx != NULL ) | 1808 | if (s->frag_ctx != NULL) |
1727 | return GNUNET_SYSERR; | 1809 | return GNUNET_SYSERR; |
1728 | memcpy (&udp[1], msgbuf, msgbuf_size); | 1810 | memcpy (&udp[1], msgbuf, msgbuf_size); |
1729 | frag_ctx = GNUNET_new (struct UDP_FragmentationContext); | 1811 | frag_ctx = GNUNET_new (struct UDP_FragmentationContext); |
@@ -1751,18 +1833,20 @@ udp_plugin_send (void *cls, struct Session *s, const char *msgbuf, | |||
1751 | return udpmlen; | 1833 | return udpmlen; |
1752 | } | 1834 | } |
1753 | 1835 | ||
1836 | |||
1754 | /** | 1837 | /** |
1755 | * Our external IP address/port mapping has changed. | 1838 | * Our external IP address/port mapping has changed. |
1756 | * | 1839 | * |
1757 | * @param cls closure, the 'struct LocalAddrList' | 1840 | * @param cls closure, the `struct LocalAddrList` |
1758 | * @param add_remove GNUNET_YES to mean the new public IP address, GNUNET_NO to mean | 1841 | * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean |
1759 | * the previous (now invalid) one | 1842 | * the previous (now invalid) one |
1760 | * @param addr either the previous or the new public IP address | 1843 | * @param addr either the previous or the new public IP address |
1761 | * @param addrlen actual lenght of the address | 1844 | * @param addrlen actual lenght of the address |
1762 | */ | 1845 | */ |
1763 | static void | 1846 | static void |
1764 | udp_nat_port_map_callback (void *cls, int add_remove, | 1847 | udp_nat_port_map_callback (void *cls, int add_remove, |
1765 | const struct sockaddr *addr, socklen_t addrlen) | 1848 | const struct sockaddr *addr, |
1849 | socklen_t addrlen) | ||
1766 | { | 1850 | { |
1767 | struct Plugin *plugin = cls; | 1851 | struct Plugin *plugin = cls; |
1768 | struct GNUNET_HELLO_Address *address; | 1852 | struct GNUNET_HELLO_Address *address; |
@@ -1812,6 +1896,7 @@ udp_nat_port_map_callback (void *cls, int add_remove, | |||
1812 | GNUNET_HELLO_address_free (address); | 1896 | GNUNET_HELLO_address_free (address); |
1813 | } | 1897 | } |
1814 | 1898 | ||
1899 | |||
1815 | /** | 1900 | /** |
1816 | * Message tokenizer has broken up an incomming message. Pass it on | 1901 | * Message tokenizer has broken up an incomming message. Pass it on |
1817 | * to the service. | 1902 | * to the service. |
@@ -1843,6 +1928,7 @@ process_inbound_tokenized_messages (void *cls, void *client, | |||
1843 | return GNUNET_OK; | 1928 | return GNUNET_OK; |
1844 | } | 1929 | } |
1845 | 1930 | ||
1931 | |||
1846 | /** | 1932 | /** |
1847 | * We've received a UDP Message. Process it (pass contents to main service). | 1933 | * We've received a UDP Message. Process it (pass contents to main service). |
1848 | * | 1934 | * |
@@ -1852,8 +1938,10 @@ process_inbound_tokenized_messages (void *cls, void *client, | |||
1852 | * @param sender_addr_len number of bytes in sender_addr | 1938 | * @param sender_addr_len number of bytes in sender_addr |
1853 | */ | 1939 | */ |
1854 | static void | 1940 | static void |
1855 | process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, | 1941 | process_udp_message (struct Plugin *plugin, |
1856 | const struct sockaddr *sender_addr, socklen_t sender_addr_len) | 1942 | const struct UDPMessage *msg, |
1943 | const struct sockaddr *sender_addr, | ||
1944 | socklen_t sender_addr_len) | ||
1857 | { | 1945 | { |
1858 | struct SourceInformation si; | 1946 | struct SourceInformation si; |
1859 | struct Session * s; | 1947 | struct Session * s; |
@@ -1928,6 +2016,7 @@ process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, | |||
1928 | free_session (s); | 2016 | free_session (s); |
1929 | } | 2017 | } |
1930 | 2018 | ||
2019 | |||
1931 | /** | 2020 | /** |
1932 | * Scan the heap for a receive context with the given address. | 2021 | * Scan the heap for a receive context with the given address. |
1933 | * | 2022 | * |
@@ -1954,6 +2043,7 @@ find_receive_context (void *cls, struct GNUNET_CONTAINER_HeapNode *node, | |||
1954 | return GNUNET_YES; | 2043 | return GNUNET_YES; |
1955 | } | 2044 | } |
1956 | 2045 | ||
2046 | |||
1957 | /** | 2047 | /** |
1958 | * Process a defragmented message. | 2048 | * Process a defragmented message. |
1959 | * | 2049 | * |
@@ -2006,9 +2096,11 @@ struct LookupContext | |||
2006 | int must_have_frag_ctx; | 2096 | int must_have_frag_ctx; |
2007 | }; | 2097 | }; |
2008 | 2098 | ||
2099 | |||
2009 | static int | 2100 | static int |
2010 | lookup_session_by_sockaddr_it (void *cls, const struct GNUNET_PeerIdentity *key, | 2101 | lookup_session_by_sockaddr_it (void *cls, |
2011 | void *value) | 2102 | const struct GNUNET_PeerIdentity *key, |
2103 | void *value) | ||
2012 | { | 2104 | { |
2013 | struct LookupContext *l_ctx = cls; | 2105 | struct LookupContext *l_ctx = cls; |
2014 | struct Session * s = value; | 2106 | struct Session * s = value; |
@@ -2057,6 +2149,7 @@ lookup_session_by_sockaddr_it (void *cls, const struct GNUNET_PeerIdentity *key, | |||
2057 | return GNUNET_YES; | 2149 | return GNUNET_YES; |
2058 | } | 2150 | } |
2059 | 2151 | ||
2152 | |||
2060 | /** | 2153 | /** |
2061 | * Transmit an acknowledgement. | 2154 | * Transmit an acknowledgement. |
2062 | * | 2155 | * |
@@ -2099,7 +2192,7 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) | |||
2099 | udpw->session = s; | 2192 | udpw->session = s; |
2100 | udpw->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; | 2193 | udpw->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; |
2101 | udpw->msg_buf = (char *) &udpw[1]; | 2194 | udpw->msg_buf = (char *) &udpw[1]; |
2102 | udpw->msg_type = MSG_ACK; | 2195 | udpw->msg_type = UMT_MSG_ACK; |
2103 | udp_ack = (struct UDP_ACK_Message *) udpw->msg_buf; | 2196 | udp_ack = (struct UDP_ACK_Message *) udpw->msg_buf; |
2104 | udp_ack->header.size = htons ((uint16_t) msize); | 2197 | udp_ack->header.size = htons ((uint16_t) msize); |
2105 | udp_ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK); | 2198 | udp_ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK); |
@@ -2110,9 +2203,12 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) | |||
2110 | schedule_select (rc->plugin); | 2203 | schedule_select (rc->plugin); |
2111 | } | 2204 | } |
2112 | 2205 | ||
2206 | |||
2113 | static void | 2207 | static void |
2114 | read_process_msg (struct Plugin *plugin, const struct GNUNET_MessageHeader *msg, | 2208 | read_process_msg (struct Plugin *plugin, |
2115 | const struct sockaddr *addr, socklen_t fromlen) | 2209 | const struct GNUNET_MessageHeader *msg, |
2210 | const struct sockaddr *addr, | ||
2211 | socklen_t fromlen) | ||
2116 | { | 2212 | { |
2117 | if (ntohs (msg->size) < sizeof(struct UDPMessage)) | 2213 | if (ntohs (msg->size) < sizeof(struct UDPMessage)) |
2118 | { | 2214 | { |
@@ -2122,9 +2218,12 @@ read_process_msg (struct Plugin *plugin, const struct GNUNET_MessageHeader *msg, | |||
2122 | process_udp_message (plugin, (const struct UDPMessage *) msg, addr, fromlen); | 2218 | process_udp_message (plugin, (const struct UDPMessage *) msg, addr, fromlen); |
2123 | } | 2219 | } |
2124 | 2220 | ||
2221 | |||
2125 | static void | 2222 | static void |
2126 | read_process_ack (struct Plugin *plugin, const struct GNUNET_MessageHeader *msg, | 2223 | read_process_ack (struct Plugin *plugin, |
2127 | const struct sockaddr *addr, socklen_t fromlen) | 2224 | const struct GNUNET_MessageHeader *msg, |
2225 | const struct sockaddr *addr, | ||
2226 | socklen_t fromlen) | ||
2128 | { | 2227 | { |
2129 | const struct GNUNET_MessageHeader *ack; | 2228 | const struct GNUNET_MessageHeader *ack; |
2130 | const struct UDP_ACK_Message *udp_ack; | 2229 | const struct UDP_ACK_Message *udp_ack; |
@@ -2187,10 +2286,12 @@ read_process_ack (struct Plugin *plugin, const struct GNUNET_MessageHeader *msg, | |||
2187 | fragmented_message_done (s->frag_ctx, GNUNET_OK); | 2286 | fragmented_message_done (s->frag_ctx, GNUNET_OK); |
2188 | } | 2287 | } |
2189 | 2288 | ||
2289 | |||
2190 | static void | 2290 | static void |
2191 | read_process_fragment (struct Plugin *plugin, | 2291 | read_process_fragment (struct Plugin *plugin, |
2192 | const struct GNUNET_MessageHeader *msg, const struct sockaddr *addr, | 2292 | const struct GNUNET_MessageHeader *msg, |
2193 | socklen_t fromlen) | 2293 | const struct sockaddr *addr, |
2294 | socklen_t fromlen) | ||
2194 | { | 2295 | { |
2195 | struct DefragContext *d_ctx; | 2296 | struct DefragContext *d_ctx; |
2196 | struct GNUNET_TIME_Absolute now; | 2297 | struct GNUNET_TIME_Absolute now; |
@@ -2249,6 +2350,7 @@ read_process_fragment (struct Plugin *plugin, | |||
2249 | } | 2350 | } |
2250 | } | 2351 | } |
2251 | 2352 | ||
2353 | |||
2252 | /** | 2354 | /** |
2253 | * Read and process a message from the given socket. | 2355 | * Read and process a message from the given socket. |
2254 | * | 2356 | * |
@@ -2256,7 +2358,8 @@ read_process_fragment (struct Plugin *plugin, | |||
2256 | * @param rsock socket to read from | 2358 | * @param rsock socket to read from |
2257 | */ | 2359 | */ |
2258 | static void | 2360 | static void |
2259 | udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) | 2361 | udp_select_read (struct Plugin *plugin, |
2362 | struct GNUNET_NETWORK_Handle *rsock) | ||
2260 | { | 2363 | { |
2261 | socklen_t fromlen; | 2364 | socklen_t fromlen; |
2262 | struct sockaddr_storage addr; | 2365 | struct sockaddr_storage addr; |
@@ -2341,9 +2444,10 @@ udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) | |||
2341 | } | 2444 | } |
2342 | } | 2445 | } |
2343 | 2446 | ||
2447 | |||
2344 | static struct UDP_MessageWrapper * | 2448 | static struct UDP_MessageWrapper * |
2345 | remove_timeout_messages_and_select (struct UDP_MessageWrapper *head, | 2449 | remove_timeout_messages_and_select (struct UDP_MessageWrapper *head, |
2346 | struct GNUNET_NETWORK_Handle *sock) | 2450 | struct GNUNET_NETWORK_Handle *sock) |
2347 | { | 2451 | { |
2348 | struct UDP_MessageWrapper *udpw = NULL; | 2452 | struct UDP_MessageWrapper *udpw = NULL; |
2349 | struct GNUNET_TIME_Relative remaining; | 2453 | struct GNUNET_TIME_Relative remaining; |
@@ -2358,7 +2462,7 @@ remove_timeout_messages_and_select (struct UDP_MessageWrapper *head, | |||
2358 | /* Message timed out */ | 2462 | /* Message timed out */ |
2359 | switch (udpw->msg_type) | 2463 | switch (udpw->msg_type) |
2360 | { | 2464 | { |
2361 | case MSG_UNFRAGMENTED: | 2465 | case UMT_MSG_UNFRAGMENTED: |
2362 | GNUNET_STATISTICS_update (plugin->env->stats, | 2466 | GNUNET_STATISTICS_update (plugin->env->stats, |
2363 | "# UDP, total, bytes, sent, timeout", udpw->msg_size, GNUNET_NO); | 2467 | "# UDP, total, bytes, sent, timeout", udpw->msg_size, GNUNET_NO); |
2364 | GNUNET_STATISTICS_update (plugin->env->stats, | 2468 | GNUNET_STATISTICS_update (plugin->env->stats, |
@@ -2377,7 +2481,7 @@ remove_timeout_messages_and_select (struct UDP_MessageWrapper *head, | |||
2377 | dequeue (plugin, udpw); | 2481 | dequeue (plugin, udpw); |
2378 | GNUNET_free(udpw); | 2482 | GNUNET_free(udpw); |
2379 | break; | 2483 | break; |
2380 | case MSG_FRAGMENTED: | 2484 | case UMT_MSG_FRAGMENTED: |
2381 | /* Fragmented message */ | 2485 | /* Fragmented message */ |
2382 | GNUNET_STATISTICS_update (plugin->env->stats, | 2486 | GNUNET_STATISTICS_update (plugin->env->stats, |
2383 | "# UDP, total, bytes, sent, timeout", udpw->frag_ctx->on_wire_size, | 2487 | "# UDP, total, bytes, sent, timeout", udpw->frag_ctx->on_wire_size, |
@@ -2397,7 +2501,7 @@ remove_timeout_messages_and_select (struct UDP_MessageWrapper *head, | |||
2397 | /* Remove fragmented message due to timeout */ | 2501 | /* Remove fragmented message due to timeout */ |
2398 | fragmented_message_done (udpw->frag_ctx, GNUNET_SYSERR); | 2502 | fragmented_message_done (udpw->frag_ctx, GNUNET_SYSERR); |
2399 | break; | 2503 | break; |
2400 | case MSG_ACK: | 2504 | case UMT_MSG_ACK: |
2401 | GNUNET_STATISTICS_update (plugin->env->stats, | 2505 | GNUNET_STATISTICS_update (plugin->env->stats, |
2402 | "# UDP, total, bytes, sent, timeout", udpw->msg_size, GNUNET_NO); | 2506 | "# UDP, total, bytes, sent, timeout", udpw->msg_size, GNUNET_NO); |
2403 | GNUNET_STATISTICS_update (plugin->env->stats, | 2507 | GNUNET_STATISTICS_update (plugin->env->stats, |
@@ -2451,9 +2555,11 @@ remove_timeout_messages_and_select (struct UDP_MessageWrapper *head, | |||
2451 | return udpw; | 2555 | return udpw; |
2452 | } | 2556 | } |
2453 | 2557 | ||
2558 | |||
2454 | static void | 2559 | static void |
2455 | analyze_send_error (struct Plugin *plugin, const struct sockaddr * sa, | 2560 | analyze_send_error (struct Plugin *plugin, |
2456 | socklen_t slen, int error) | 2561 | const struct sockaddr *sa, |
2562 | socklen_t slen, int error) | ||
2457 | { | 2563 | { |
2458 | static int network_down_error; | 2564 | static int network_down_error; |
2459 | struct GNUNET_ATS_Information type; | 2565 | struct GNUNET_ATS_Information type; |
@@ -2462,43 +2568,45 @@ analyze_send_error (struct Plugin *plugin, const struct sockaddr * sa, | |||
2462 | if (((GNUNET_ATS_NET_LAN == ntohl (type.value)) | 2568 | if (((GNUNET_ATS_NET_LAN == ntohl (type.value)) |
2463 | || (GNUNET_ATS_NET_WAN == ntohl (type.value))) | 2569 | || (GNUNET_ATS_NET_WAN == ntohl (type.value))) |
2464 | && ((ENETUNREACH == errno)|| (ENETDOWN == errno))) | 2570 | && ((ENETUNREACH == errno)|| (ENETDOWN == errno))) |
2465 | { | 2571 | { |
2466 | if ((network_down_error == GNUNET_NO) && (slen == sizeof (struct sockaddr_in))) | 2572 | if ((network_down_error == GNUNET_NO) && (slen == sizeof (struct sockaddr_in))) |
2467 | { | 2573 | { |
2468 | /* IPv4: "Network unreachable" or "Network down" | 2574 | /* IPv4: "Network unreachable" or "Network down" |
2469 | * | 2575 | * |
2470 | * This indicates we do not have connectivity | 2576 | * This indicates we do not have connectivity |
2471 | */ | 2577 | */ |
2472 | LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 2578 | LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
2473 | _("UDP could not transmit message to `%s': " | 2579 | _("UDP could not transmit message to `%s': " |
2474 | "Network seems down, please check your network configuration\n"), | 2580 | "Network seems down, please check your network configuration\n"), |
2475 | GNUNET_a2s (sa, slen)); | 2581 | GNUNET_a2s (sa, slen)); |
2476 | } | 2582 | } |
2477 | if ((network_down_error == GNUNET_NO) && (slen == sizeof (struct sockaddr_in6))) | 2583 | if ((network_down_error == GNUNET_NO) && (slen == sizeof (struct sockaddr_in6))) |
2478 | { | 2584 | { |
2479 | /* IPv6: "Network unreachable" or "Network down" | 2585 | /* IPv6: "Network unreachable" or "Network down" |
2480 | * | 2586 | * |
2481 | * This indicates that this system is IPv6 enabled, but does not | 2587 | * This indicates that this system is IPv6 enabled, but does not |
2482 | * have a valid global IPv6 address assigned or we do not have | 2588 | * have a valid global IPv6 address assigned or we do not have |
2483 | * connectivity | 2589 | * connectivity |
2484 | */ | 2590 | */ |
2485 | 2591 | ||
2486 | LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 2592 | LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
2487 | _("UDP could not transmit IPv6 message! " | 2593 | _("UDP could not transmit IPv6 message! " |
2488 | "Please check your network configuration and disable IPv6 if your " | 2594 | "Please check your network configuration and disable IPv6 if your " |
2489 | "connection does not have a global IPv6 address\n")); | 2595 | "connection does not have a global IPv6 address\n")); |
2490 | } | ||
2491 | } | ||
2492 | else | ||
2493 | { | ||
2494 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
2495 | "UDP could not transmit message to `%s': `%s'\n", | ||
2496 | GNUNET_a2s (sa, slen), STRERROR (error)); | ||
2497 | } | ||
2498 | } | 2596 | } |
2597 | } | ||
2598 | else | ||
2599 | { | ||
2600 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
2601 | "UDP could not transmit message to `%s': `%s'\n", | ||
2602 | GNUNET_a2s (sa, slen), STRERROR (error)); | ||
2603 | } | ||
2604 | } | ||
2605 | |||
2499 | 2606 | ||
2500 | static size_t | 2607 | static size_t |
2501 | udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) | 2608 | udp_select_send (struct Plugin *plugin, |
2609 | struct GNUNET_NETWORK_Handle *sock) | ||
2502 | { | 2610 | { |
2503 | ssize_t sent; | 2611 | ssize_t sent; |
2504 | socklen_t slen; | 2612 | socklen_t slen; |
@@ -2507,14 +2615,13 @@ udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) | |||
2507 | struct sockaddr_in a4; | 2615 | struct sockaddr_in a4; |
2508 | const struct IPv6UdpAddress *u6; | 2616 | const struct IPv6UdpAddress *u6; |
2509 | struct sockaddr_in6 a6; | 2617 | struct sockaddr_in6 a6; |
2510 | 2618 | struct UDP_MessageWrapper *udpw; | |
2511 | |||
2512 | struct UDP_MessageWrapper *udpw = NULL; | ||
2513 | 2619 | ||
2514 | /* Find message to send */ | 2620 | /* Find message to send */ |
2515 | udpw = remove_timeout_messages_and_select ( | 2621 | udpw = remove_timeout_messages_and_select ((sock == plugin->sockv4) |
2516 | (sock == plugin->sockv4) ? | 2622 | ? plugin->ipv4_queue_head |
2517 | plugin->ipv4_queue_head : plugin->ipv6_queue_head, sock); | 2623 | : plugin->ipv6_queue_head, |
2624 | sock); | ||
2518 | if (NULL == udpw) | 2625 | if (NULL == udpw) |
2519 | return 0; /* No message to send */ | 2626 | return 0; /* No message to send */ |
2520 | 2627 | ||
@@ -2584,6 +2691,7 @@ udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) | |||
2584 | return sent; | 2691 | return sent; |
2585 | } | 2692 | } |
2586 | 2693 | ||
2694 | |||
2587 | /** | 2695 | /** |
2588 | * We have been notified that our readset has something to read. We don't | 2696 | * We have been notified that our readset has something to read. We don't |
2589 | * know which socket needs to be read, so we have to check each one | 2697 | * know which socket needs to be read, so we have to check each one |
@@ -2593,7 +2701,8 @@ udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) | |||
2593 | * @param tc the scheduling context (for rescheduling this function again) | 2701 | * @param tc the scheduling context (for rescheduling this function again) |
2594 | */ | 2702 | */ |
2595 | static void | 2703 | static void |
2596 | udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 2704 | udp_plugin_select (void *cls, |
2705 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
2597 | { | 2706 | { |
2598 | struct Plugin *plugin = cls; | 2707 | struct Plugin *plugin = cls; |
2599 | 2708 | ||
@@ -2611,6 +2720,7 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2611 | schedule_select (plugin); | 2720 | schedule_select (plugin); |
2612 | } | 2721 | } |
2613 | 2722 | ||
2723 | |||
2614 | /** | 2724 | /** |
2615 | * We have been notified that our readset has something to read. We don't | 2725 | * We have been notified that our readset has something to read. We don't |
2616 | * know which socket needs to be read, so we have to check each one | 2726 | * know which socket needs to be read, so we have to check each one |
@@ -2620,7 +2730,8 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2620 | * @param tc the scheduling context (for rescheduling this function again) | 2730 | * @param tc the scheduling context (for rescheduling this function again) |
2621 | */ | 2731 | */ |
2622 | static void | 2732 | static void |
2623 | udp_plugin_select_v6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 2733 | udp_plugin_select_v6 (void *cls, |
2734 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
2624 | { | 2735 | { |
2625 | struct Plugin *plugin = cls; | 2736 | struct Plugin *plugin = cls; |
2626 | 2737 | ||
@@ -2637,13 +2748,19 @@ udp_plugin_select_v6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2637 | schedule_select (plugin); | 2748 | schedule_select (plugin); |
2638 | } | 2749 | } |
2639 | 2750 | ||
2751 | |||
2640 | /** | 2752 | /** |
2753 | * Setup the UDP sockets (for IPv4 and IPv6) for the plugin. | ||
2641 | * | 2754 | * |
2755 | * @param plugin the plugin to initialize | ||
2756 | * @param bind_v6 IPv6 address to bind to (can be NULL, for 'any') | ||
2757 | * @param bind_v4 IPv4 address to bind to (can be NULL, for 'any') | ||
2642 | * @return number of sockets that were successfully bound | 2758 | * @return number of sockets that were successfully bound |
2643 | */ | 2759 | */ |
2644 | static int | 2760 | static int |
2645 | setup_sockets (struct Plugin *plugin, const struct sockaddr_in6 *bind_v6, | 2761 | setup_sockets (struct Plugin *plugin, |
2646 | const struct sockaddr_in *bind_v4) | 2762 | const struct sockaddr_in6 *bind_v6, |
2763 | const struct sockaddr_in *bind_v4) | ||
2647 | { | 2764 | { |
2648 | int tries; | 2765 | int tries; |
2649 | int sockets_created = 0; | 2766 | int sockets_created = 0; |
@@ -2657,7 +2774,7 @@ setup_sockets (struct Plugin *plugin, const struct sockaddr_in6 *bind_v6, | |||
2657 | 2774 | ||
2658 | /* Create IPv6 socket */ | 2775 | /* Create IPv6 socket */ |
2659 | eno = EINVAL; | 2776 | eno = EINVAL; |
2660 | if (plugin->enable_ipv6 == GNUNET_YES) | 2777 | if (GNUNET_YES == plugin->enable_ipv6) |
2661 | { | 2778 | { |
2662 | plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0); | 2779 | plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0); |
2663 | if (NULL == plugin->sockv6) | 2780 | if (NULL == plugin->sockv6) |
@@ -2756,9 +2873,9 @@ setup_sockets (struct Plugin *plugin, const struct sockaddr_in6 *bind_v6, | |||
2756 | 2873 | ||
2757 | if (0 == plugin->port) | 2874 | if (0 == plugin->port) |
2758 | /* autodetect */ | 2875 | /* autodetect */ |
2759 | server_addrv4.sin_port = htons ( | 2876 | server_addrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, |
2760 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) | 2877 | 33537) |
2761 | + 32000); | 2878 | + 32000); |
2762 | else | 2879 | else |
2763 | server_addrv4.sin_port = htons (plugin->port); | 2880 | server_addrv4.sin_port = htons (plugin->port); |
2764 | 2881 | ||
@@ -2768,8 +2885,9 @@ setup_sockets (struct Plugin *plugin, const struct sockaddr_in6 *bind_v6, | |||
2768 | tries = 0; | 2885 | tries = 0; |
2769 | while (tries < 10) | 2886 | while (tries < 10) |
2770 | { | 2887 | { |
2771 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 `%s'\n", | 2888 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2772 | GNUNET_a2s (server_addr, addrlen)); | 2889 | "Binding to IPv4 `%s'\n", |
2890 | GNUNET_a2s (server_addr, addrlen)); | ||
2773 | 2891 | ||
2774 | /* binding */ | 2892 | /* binding */ |
2775 | if (GNUNET_OK | 2893 | if (GNUNET_OK |
@@ -2796,7 +2914,7 @@ setup_sockets (struct Plugin *plugin, const struct sockaddr_in6 *bind_v6, | |||
2796 | plugin->sockv4 = NULL; | 2914 | plugin->sockv4 = NULL; |
2797 | } | 2915 | } |
2798 | 2916 | ||
2799 | if (plugin->sockv4 != NULL ) | 2917 | if (NULL != plugin->sockv4) |
2800 | { | 2918 | { |
2801 | LOG(GNUNET_ERROR_TYPE_DEBUG, "IPv4 socket created on port %s\n", | 2919 | LOG(GNUNET_ERROR_TYPE_DEBUG, "IPv4 socket created on port %s\n", |
2802 | GNUNET_a2s (server_addr, addrlen)); | 2920 | GNUNET_a2s (server_addr, addrlen)); |
@@ -2846,18 +2964,20 @@ setup_sockets (struct Plugin *plugin, const struct sockaddr_in6 *bind_v6, | |||
2846 | 2964 | ||
2847 | schedule_select (plugin); | 2965 | schedule_select (plugin); |
2848 | plugin->nat = GNUNET_NAT_register (plugin->env->cfg, GNUNET_NO, plugin->port, | 2966 | plugin->nat = GNUNET_NAT_register (plugin->env->cfg, GNUNET_NO, plugin->port, |
2849 | sockets_created, (const struct sockaddr **) addrs, addrlens, | 2967 | sockets_created, |
2850 | &udp_nat_port_map_callback, NULL, plugin); | 2968 | (const struct sockaddr **) addrs, addrlens, |
2969 | &udp_nat_port_map_callback, NULL, plugin); | ||
2851 | 2970 | ||
2852 | return sockets_created; | 2971 | return sockets_created; |
2853 | } | 2972 | } |
2854 | 2973 | ||
2974 | |||
2855 | /** | 2975 | /** |
2856 | * The exported method. Makes the core api available via a global and | 2976 | * The exported method. Makes the core api available via a global and |
2857 | * returns the udp transport API. | 2977 | * returns the udp transport API. |
2858 | * | 2978 | * |
2859 | * @param cls our 'struct GNUNET_TRANSPORT_PluginEnvironment' | 2979 | * @param cls our `struct GNUNET_TRANSPORT_PluginEnvironment` |
2860 | * @return our 'struct GNUNET_TRANSPORT_PluginFunctions' | 2980 | * @return our `struct GNUNET_TRANSPORT_PluginFunctions` |
2861 | */ | 2981 | */ |
2862 | void * | 2982 | void * |
2863 | libgnunet_plugin_transport_udp_init (void *cls) | 2983 | libgnunet_plugin_transport_udp_init (void *cls) |
@@ -2871,9 +2991,9 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
2871 | unsigned long long enable_v6; | 2991 | unsigned long long enable_v6; |
2872 | unsigned long long enable_broadcasting; | 2992 | unsigned long long enable_broadcasting; |
2873 | unsigned long long enable_broadcasting_recv; | 2993 | unsigned long long enable_broadcasting_recv; |
2874 | char * bind4_address; | 2994 | char *bind4_address; |
2875 | char * bind6_address; | 2995 | char *bind6_address; |
2876 | char * fancy_interval; | 2996 | char *fancy_interval; |
2877 | struct GNUNET_TIME_Relative interval; | 2997 | struct GNUNET_TIME_Relative interval; |
2878 | struct sockaddr_in server_addrv4; | 2998 | struct sockaddr_in server_addrv4; |
2879 | struct sockaddr_in6 server_addrv6; | 2999 | struct sockaddr_in6 server_addrv6; |
@@ -2893,29 +3013,28 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
2893 | return api; | 3013 | return api; |
2894 | } | 3014 | } |
2895 | 3015 | ||
2896 | GNUNET_assert(NULL != env->stats); | ||
2897 | |||
2898 | /* Get port number: port == 0 : autodetect a port, | 3016 | /* Get port number: port == 0 : autodetect a port, |
2899 | * > 0 : use this port, not given : 2086 default */ | 3017 | * > 0 : use this port, not given : 2086 default */ |
2900 | if (GNUNET_OK | 3018 | if (GNUNET_OK != |
2901 | != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", | 3019 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", |
2902 | "PORT", &port)) | 3020 | "PORT", &port)) |
2903 | port = 2086; | 3021 | port = 2086; |
2904 | if (GNUNET_OK | 3022 | if (GNUNET_OK != |
2905 | != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", | 3023 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", |
2906 | "ADVERTISED_PORT", &aport)) | 3024 | "ADVERTISED_PORT", &aport)) |
2907 | aport = port; | 3025 | aport = port; |
2908 | if (port > 65535) | 3026 | if (port > 65535) |
2909 | { | 3027 | { |
2910 | LOG(GNUNET_ERROR_TYPE_WARNING, | 3028 | LOG (GNUNET_ERROR_TYPE_WARNING, |
2911 | _("Given `%s' option is out of range: %llu > %u\n"), "PORT", port, | 3029 | _("Given `%s' option is out of range: %llu > %u\n"), |
2912 | 65535); | 3030 | "PORT", port, |
2913 | return NULL ; | 3031 | 65535); |
3032 | return NULL; | ||
2914 | } | 3033 | } |
2915 | 3034 | ||
2916 | /* Protocols */ | 3035 | /* Protocols */ |
2917 | if ((GNUNET_YES | 3036 | if (GNUNET_YES == |
2918 | == GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "nat", "DISABLEV6"))) | 3037 | GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "nat", "DISABLEV6")) |
2919 | enable_v6 = GNUNET_NO; | 3038 | enable_v6 = GNUNET_NO; |
2920 | else | 3039 | else |
2921 | enable_v6 = GNUNET_YES; | 3040 | enable_v6 = GNUNET_YES; |
@@ -2923,38 +3042,39 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
2923 | /* Addresses */ | 3042 | /* Addresses */ |
2924 | have_bind4 = GNUNET_NO; | 3043 | have_bind4 = GNUNET_NO; |
2925 | memset (&server_addrv4, 0, sizeof(server_addrv4)); | 3044 | memset (&server_addrv4, 0, sizeof(server_addrv4)); |
2926 | if (GNUNET_YES | 3045 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", |
2927 | == GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", | 3046 | "BINDTO", &bind4_address)) |
2928 | "BINDTO", &bind4_address)) | ||
2929 | { | 3047 | { |
2930 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3048 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2931 | "Binding udp plugin to specific address: `%s'\n", bind4_address); | 3049 | "Binding udp plugin to specific address: `%s'\n", |
3050 | bind4_address); | ||
2932 | if (1 != inet_pton (AF_INET, bind4_address, &server_addrv4.sin_addr)) | 3051 | if (1 != inet_pton (AF_INET, bind4_address, &server_addrv4.sin_addr)) |
2933 | { | 3052 | { |
2934 | GNUNET_free(bind4_address); | 3053 | GNUNET_free (bind4_address); |
2935 | return NULL ; | 3054 | return NULL; |
2936 | } | 3055 | } |
2937 | have_bind4 = GNUNET_YES; | 3056 | have_bind4 = GNUNET_YES; |
2938 | } | 3057 | } |
2939 | GNUNET_free_non_null(bind4_address); | 3058 | GNUNET_free_non_null(bind4_address); |
2940 | have_bind6 = GNUNET_NO; | 3059 | have_bind6 = GNUNET_NO; |
2941 | memset (&server_addrv6, 0, sizeof(server_addrv6)); | 3060 | memset (&server_addrv6, 0, sizeof(server_addrv6)); |
2942 | if (GNUNET_YES | 3061 | if (GNUNET_YES == |
2943 | == GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", | 3062 | GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", |
2944 | "BINDTO6", &bind6_address)) | 3063 | "BINDTO6", &bind6_address)) |
2945 | { | 3064 | { |
2946 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3065 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2947 | "Binding udp plugin to specific address: `%s'\n", bind6_address); | 3066 | "Binding udp plugin to specific address: `%s'\n", bind6_address); |
2948 | if (1 != inet_pton (AF_INET6, bind6_address, &server_addrv6.sin6_addr)) | 3067 | if (1 != inet_pton (AF_INET6, bind6_address, &server_addrv6.sin6_addr)) |
2949 | { | 3068 | { |
2950 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"), | 3069 | LOG (GNUNET_ERROR_TYPE_ERROR, |
2951 | bind6_address); | 3070 | _("Invalid IPv6 address: `%s'\n"), |
2952 | GNUNET_free(bind6_address); | 3071 | bind6_address); |
2953 | return NULL ; | 3072 | GNUNET_free (bind6_address); |
3073 | return NULL; | ||
2954 | } | 3074 | } |
2955 | have_bind6 = GNUNET_YES; | 3075 | have_bind6 = GNUNET_YES; |
2956 | } | 3076 | } |
2957 | GNUNET_free_non_null(bind6_address); | 3077 | GNUNET_free_non_null (bind6_address); |
2958 | 3078 | ||
2959 | /* Initialize my flags */ | 3079 | /* Initialize my flags */ |
2960 | myoptions = 0; | 3080 | myoptions = 0; |
@@ -2987,9 +3107,9 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
2987 | } | 3107 | } |
2988 | 3108 | ||
2989 | /* Maximum datarate */ | 3109 | /* Maximum datarate */ |
2990 | if (GNUNET_OK | 3110 | if (GNUNET_OK != |
2991 | != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", | 3111 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", |
2992 | "MAX_BPS", &udp_max_bps)) | 3112 | "MAX_BPS", &udp_max_bps)) |
2993 | { | 3113 | { |
2994 | udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */ | 3114 | udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */ |
2995 | } | 3115 | } |
@@ -3012,8 +3132,9 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3012 | plugin = p; | 3132 | plugin = p; |
3013 | 3133 | ||
3014 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Setting up sockets\n"); | 3134 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Setting up sockets\n"); |
3015 | res = setup_sockets (p, (GNUNET_YES == have_bind6) ? &server_addrv6 : NULL, | 3135 | res = setup_sockets (p, |
3016 | (GNUNET_YES == have_bind4) ? &server_addrv4 : NULL ); | 3136 | (GNUNET_YES == have_bind6) ? &server_addrv6 : NULL, |
3137 | (GNUNET_YES == have_bind4) ? &server_addrv4 : NULL); | ||
3017 | if ((res == 0) || ((p->sockv4 == NULL )&& (p->sockv6 == NULL))) | 3138 | if ((res == 0) || ((p->sockv4 == NULL )&& (p->sockv6 == NULL))) |
3018 | { | 3139 | { |
3019 | LOG (GNUNET_ERROR_TYPE_ERROR, | 3140 | LOG (GNUNET_ERROR_TYPE_ERROR, |
@@ -3045,24 +3166,37 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3045 | return api; | 3166 | return api; |
3046 | } | 3167 | } |
3047 | 3168 | ||
3169 | |||
3170 | /** | ||
3171 | * Function called on each entry in the defragmentation heap to | ||
3172 | * clean it up. | ||
3173 | * | ||
3174 | * @param cls NULL | ||
3175 | * @param node node in the heap (to be removed) | ||
3176 | * @param element a `struct DefragContext` to be cleaned up | ||
3177 | * @param cost unused | ||
3178 | * @return #GNUNET_YES | ||
3179 | */ | ||
3048 | static int | 3180 | static int |
3049 | heap_cleanup_iterator (void *cls, struct GNUNET_CONTAINER_HeapNode *node, | 3181 | heap_cleanup_iterator (void *cls, |
3050 | void *element, GNUNET_CONTAINER_HeapCostType cost) | 3182 | struct GNUNET_CONTAINER_HeapNode *node, |
3183 | void *element, | ||
3184 | GNUNET_CONTAINER_HeapCostType cost) | ||
3051 | { | 3185 | { |
3052 | struct DefragContext * d_ctx = element; | 3186 | struct DefragContext *d_ctx = element; |
3053 | 3187 | ||
3054 | GNUNET_CONTAINER_heap_remove_node (node); | 3188 | GNUNET_CONTAINER_heap_remove_node (node); |
3055 | GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag); | 3189 | GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag); |
3056 | GNUNET_free(d_ctx); | 3190 | GNUNET_free (d_ctx); |
3057 | |||
3058 | return GNUNET_YES; | 3191 | return GNUNET_YES; |
3059 | } | 3192 | } |
3060 | 3193 | ||
3194 | |||
3061 | /** | 3195 | /** |
3062 | * The exported method. Makes the core api available via a global and | 3196 | * The exported method. Makes the core api available via a global and |
3063 | * returns the udp transport API. | 3197 | * returns the udp transport API. |
3064 | * | 3198 | * |
3065 | * @param cls our 'struct GNUNET_TRANSPORT_PluginEnvironment' | 3199 | * @param cls our `struct GNUNET_TRANSPORT_PluginEnvironment` |
3066 | * @return NULL | 3200 | * @return NULL |
3067 | */ | 3201 | */ |
3068 | void * | 3202 | void * |
@@ -3072,13 +3206,13 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
3072 | struct Plugin *plugin = api->cls; | 3206 | struct Plugin *plugin = api->cls; |
3073 | struct PrettyPrinterContext *cur; | 3207 | struct PrettyPrinterContext *cur; |
3074 | struct PrettyPrinterContext *next; | 3208 | struct PrettyPrinterContext *next; |
3209 | struct UDP_MessageWrapper *udpw; | ||
3075 | 3210 | ||
3076 | if (NULL == plugin) | 3211 | if (NULL == plugin) |
3077 | { | 3212 | { |
3078 | GNUNET_free(api); | 3213 | GNUNET_free(api); |
3079 | return NULL ; | 3214 | return NULL; |
3080 | } | 3215 | } |
3081 | |||
3082 | stop_broadcast (plugin); | 3216 | stop_broadcast (plugin); |
3083 | if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK ) | 3217 | if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK ) |
3084 | { | 3218 | { |
@@ -3096,7 +3230,7 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
3096 | { | 3230 | { |
3097 | if (NULL != plugin->sockv4) | 3231 | if (NULL != plugin->sockv4) |
3098 | { | 3232 | { |
3099 | GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4)); | 3233 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4)); |
3100 | plugin->sockv4 = NULL; | 3234 | plugin->sockv4 = NULL; |
3101 | } | 3235 | } |
3102 | GNUNET_NETWORK_fdset_destroy (plugin->rs_v4); | 3236 | GNUNET_NETWORK_fdset_destroy (plugin->rs_v4); |
@@ -3106,7 +3240,7 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
3106 | { | 3240 | { |
3107 | if (NULL != plugin->sockv6) | 3241 | if (NULL != plugin->sockv6) |
3108 | { | 3242 | { |
3109 | GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6)); | 3243 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6)); |
3110 | plugin->sockv6 = NULL; | 3244 | plugin->sockv6 = NULL; |
3111 | 3245 | ||
3112 | GNUNET_NETWORK_fdset_destroy (plugin->rs_v6); | 3246 | GNUNET_NETWORK_fdset_destroy (plugin->rs_v6); |
@@ -3120,44 +3254,42 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
3120 | } | 3254 | } |
3121 | if (NULL != plugin->defrag_ctxs) | 3255 | if (NULL != plugin->defrag_ctxs) |
3122 | { | 3256 | { |
3123 | GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, heap_cleanup_iterator, | 3257 | GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, |
3124 | NULL ); | 3258 | &heap_cleanup_iterator, NULL); |
3125 | GNUNET_CONTAINER_heap_destroy (plugin->defrag_ctxs); | 3259 | GNUNET_CONTAINER_heap_destroy (plugin->defrag_ctxs); |
3126 | plugin->defrag_ctxs = NULL; | 3260 | plugin->defrag_ctxs = NULL; |
3127 | } | 3261 | } |
3128 | if (plugin->mst != NULL ) | 3262 | if (NULL != plugin->mst) |
3129 | { | 3263 | { |
3130 | GNUNET_SERVER_mst_destroy (plugin->mst); | 3264 | GNUNET_SERVER_mst_destroy (plugin->mst); |
3131 | plugin->mst = NULL; | 3265 | plugin->mst = NULL; |
3132 | } | 3266 | } |
3133 | 3267 | ||
3134 | /* Clean up leftover messages */ | 3268 | /* Clean up leftover messages */ |
3135 | struct UDP_MessageWrapper * udpw; | ||
3136 | udpw = plugin->ipv4_queue_head; | 3269 | udpw = plugin->ipv4_queue_head; |
3137 | while (udpw != NULL ) | 3270 | while (NULL != udpw) |
3138 | { | 3271 | { |
3139 | struct UDP_MessageWrapper *tmp = udpw->next; | 3272 | struct UDP_MessageWrapper *tmp = udpw->next; |
3140 | dequeue (plugin, udpw); | 3273 | dequeue (plugin, udpw); |
3141 | call_continuation (udpw, GNUNET_SYSERR); | 3274 | call_continuation (udpw, GNUNET_SYSERR); |
3142 | GNUNET_free(udpw); | 3275 | GNUNET_free(udpw); |
3143 | |||
3144 | udpw = tmp; | 3276 | udpw = tmp; |
3145 | } | 3277 | } |
3146 | udpw = plugin->ipv6_queue_head; | 3278 | udpw = plugin->ipv6_queue_head; |
3147 | while (udpw != NULL ) | 3279 | while (NULL != udpw) |
3148 | { | 3280 | { |
3149 | struct UDP_MessageWrapper *tmp = udpw->next; | 3281 | struct UDP_MessageWrapper *tmp = udpw->next; |
3150 | dequeue (plugin, udpw); | 3282 | dequeue (plugin, udpw); |
3151 | call_continuation (udpw, GNUNET_SYSERR); | 3283 | call_continuation (udpw, GNUNET_SYSERR); |
3152 | GNUNET_free(udpw); | 3284 | GNUNET_free(udpw); |
3153 | |||
3154 | udpw = tmp; | 3285 | udpw = tmp; |
3155 | } | 3286 | } |
3156 | 3287 | ||
3157 | /* Clean up sessions */ | 3288 | /* Clean up sessions */ |
3158 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up sessions\n"); | 3289 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3290 | "Cleaning up sessions\n"); | ||
3159 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, | 3291 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, |
3160 | &disconnect_and_free_it, plugin); | 3292 | &disconnect_and_free_it, plugin); |
3161 | GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions); | 3293 | GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions); |
3162 | 3294 | ||
3163 | next = ppc_dll_head; | 3295 | next = ppc_dll_head; |
@@ -3170,27 +3302,9 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
3170 | GNUNET_free(cur); | 3302 | GNUNET_free(cur); |
3171 | GNUNET_break(0); | 3303 | GNUNET_break(0); |
3172 | } | 3304 | } |
3173 | 3305 | GNUNET_free (plugin); | |
3174 | plugin->nat = NULL; | 3306 | GNUNET_free (api); |
3175 | GNUNET_free(plugin); | 3307 | return NULL; |
3176 | GNUNET_free(api); | ||
3177 | #if DEBUG_MALLOC | ||
3178 | struct Allocation *allocation; | ||
3179 | while (NULL != ahead) | ||
3180 | { | ||
3181 | allocation = ahead; | ||
3182 | GNUNET_CONTAINER_DLL_remove (ahead, atail, allocation); | ||
3183 | GNUNET_free (allocation); | ||
3184 | } | ||
3185 | struct Allocator *allocator; | ||
3186 | while (NULL != aehead) | ||
3187 | { | ||
3188 | allocator = aehead; | ||
3189 | GNUNET_CONTAINER_DLL_remove (aehead, aetail, allocator); | ||
3190 | GNUNET_free (allocator); | ||
3191 | } | ||
3192 | #endif | ||
3193 | return NULL ; | ||
3194 | } | 3308 | } |
3195 | 3309 | ||
3196 | /* end of plugin_transport_udp.c */ | 3310 | /* end of plugin_transport_udp.c */ |
diff --git a/src/transport/plugin_transport_udp_broadcasting.c b/src/transport/plugin_transport_udp_broadcasting.c index 7dfe86944..cb7e4ddee 100644 --- a/src/transport/plugin_transport_udp_broadcasting.c +++ b/src/transport/plugin_transport_udp_broadcasting.c | |||
@@ -216,7 +216,7 @@ broadcast_ipv4_mst_cb (void *cls, void *client, | |||
216 | 216 | ||
217 | void | 217 | void |
218 | udp_broadcast_receive (struct Plugin *plugin, | 218 | udp_broadcast_receive (struct Plugin *plugin, |
219 | const char * buf, | 219 | const char *buf, |
220 | ssize_t size, | 220 | ssize_t size, |
221 | const struct sockaddr *addr, | 221 | const struct sockaddr *addr, |
222 | size_t addrlen) | 222 | size_t addrlen) |