diff options
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 398 |
1 files changed, 174 insertions, 224 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index bd2f4aa6a..331203471 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -419,8 +419,7 @@ plugin_tcp_access_check (void *cls, | |||
419 | * @param addrlen actual lenght of the address | 419 | * @param addrlen actual lenght of the address |
420 | */ | 420 | */ |
421 | static void | 421 | static void |
422 | tcp_nat_port_map_callback (void *cls, | 422 | tcp_nat_port_map_callback (void *cls, int add_remove, |
423 | int add_remove, | ||
424 | const struct sockaddr *addr, socklen_t addrlen) | 423 | const struct sockaddr *addr, socklen_t addrlen) |
425 | { | 424 | { |
426 | struct Plugin *plugin = cls; | 425 | struct Plugin *plugin = cls; |
@@ -429,10 +428,9 @@ tcp_nat_port_map_callback (void *cls, | |||
429 | void *arg; | 428 | void *arg; |
430 | size_t args; | 429 | size_t args; |
431 | 430 | ||
432 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 431 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
433 | "tcp", | 432 | "NPMC called with %d for address `%s'\n", add_remove, |
434 | "NPMC called with %d for address `%s'\n", | 433 | GNUNET_a2s (addr, addrlen)); |
435 | add_remove, GNUNET_a2s (addr, addrlen)); | ||
436 | /* convert 'addr' to our internal format */ | 434 | /* convert 'addr' to our internal format */ |
437 | switch (addr->sa_family) | 435 | switch (addr->sa_family) |
438 | { | 436 | { |
@@ -445,8 +443,7 @@ tcp_nat_port_map_callback (void *cls, | |||
445 | break; | 443 | break; |
446 | case AF_INET6: | 444 | case AF_INET6: |
447 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); | 445 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); |
448 | memcpy (&t6.ipv6_addr, | 446 | memcpy (&t6.ipv6_addr, &((struct sockaddr_in6 *) addr)->sin6_addr, |
449 | &((struct sockaddr_in6 *) addr)->sin6_addr, | ||
450 | sizeof (struct in6_addr)); | 447 | sizeof (struct in6_addr)); |
451 | t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port; | 448 | t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port; |
452 | arg = &t6; | 449 | arg = &t6; |
@@ -503,8 +500,7 @@ tcp_address_to_string (void *cls, const void *addr, size_t addrlen) | |||
503 | } | 500 | } |
504 | else | 501 | else |
505 | { | 502 | { |
506 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 503 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp", |
507 | "tcp", | ||
508 | _("Unexpected address length: %u bytes\n"), | 504 | _("Unexpected address length: %u bytes\n"), |
509 | (unsigned int) addrlen); | 505 | (unsigned int) addrlen); |
510 | GNUNET_break (0); | 506 | GNUNET_break (0); |
@@ -515,9 +511,8 @@ tcp_address_to_string (void *cls, const void *addr, size_t addrlen) | |||
515 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); | 511 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); |
516 | return NULL; | 512 | return NULL; |
517 | } | 513 | } |
518 | GNUNET_snprintf (rbuf, | 514 | GNUNET_snprintf (rbuf, sizeof (rbuf), (af == AF_INET6) ? "[%s]:%u" : "%s:%u", |
519 | sizeof (rbuf), | 515 | buf, port); |
520 | (af == AF_INET6) ? "[%s]:%u" : "%s:%u", buf, port); | ||
521 | return rbuf; | 516 | return rbuf; |
522 | } | 517 | } |
523 | 518 | ||
@@ -554,8 +549,7 @@ find_session_by_client (struct Plugin *plugin, | |||
554 | * @return new session object | 549 | * @return new session object |
555 | */ | 550 | */ |
556 | static struct Session * | 551 | static struct Session * |
557 | create_session (struct Plugin *plugin, | 552 | create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, |
558 | const struct GNUNET_PeerIdentity *target, | ||
559 | struct GNUNET_SERVER_Client *client, int is_nat) | 553 | struct GNUNET_SERVER_Client *client, int is_nat) |
560 | { | 554 | { |
561 | struct Session *ret; | 555 | struct Session *ret; |
@@ -567,8 +561,7 @@ create_session (struct Plugin *plugin, | |||
567 | else | 561 | else |
568 | GNUNET_assert (client == NULL); | 562 | GNUNET_assert (client == NULL); |
569 | #if DEBUG_TCP | 563 | #if DEBUG_TCP |
570 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 564 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
571 | "tcp", | ||
572 | "Creating new session for peer `%4s'\n", | 565 | "Creating new session for peer `%4s'\n", |
573 | GNUNET_i2s (target)); | 566 | GNUNET_i2s (target)); |
574 | #endif | 567 | #endif |
@@ -600,8 +593,8 @@ create_session (struct Plugin *plugin, | |||
600 | ret->pending_messages_tail, pm); | 593 | ret->pending_messages_tail, pm); |
601 | if (is_nat != GNUNET_YES) | 594 | if (is_nat != GNUNET_YES) |
602 | GNUNET_STATISTICS_update (plugin->env->stats, | 595 | GNUNET_STATISTICS_update (plugin->env->stats, |
603 | gettext_noop ("# TCP sessions active"), | 596 | gettext_noop ("# TCP sessions active"), 1, |
604 | 1, GNUNET_NO); | 597 | GNUNET_NO); |
605 | return ret; | 598 | return ret; |
606 | } | 599 | } |
607 | 600 | ||
@@ -645,8 +638,7 @@ do_transmit (void *cls, size_t size, void *buf) | |||
645 | if (buf == NULL) | 638 | if (buf == NULL) |
646 | { | 639 | { |
647 | #if DEBUG_TCP | 640 | #if DEBUG_TCP |
648 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 641 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
649 | "tcp", | ||
650 | "Timeout trying to transmit to peer `%4s', discarding message queue.\n", | 642 | "Timeout trying to transmit to peer `%4s', discarding message queue.\n", |
651 | GNUNET_i2s (&session->target)); | 643 | GNUNET_i2s (&session->target)); |
652 | #endif | 644 | #endif |
@@ -661,8 +653,7 @@ do_transmit (void *cls, size_t size, void *buf) | |||
661 | GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, | 653 | GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, |
662 | session->pending_messages_tail, pos); | 654 | session->pending_messages_tail, pos); |
663 | #if DEBUG_TCP | 655 | #if DEBUG_TCP |
664 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 656 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
665 | "tcp", | ||
666 | "Failed to transmit %u byte message to `%4s'.\n", | 657 | "Failed to transmit %u byte message to `%4s'.\n", |
667 | pos->message_size, GNUNET_i2s (&session->target)); | 658 | pos->message_size, GNUNET_i2s (&session->target)); |
668 | #endif | 659 | #endif |
@@ -729,15 +720,15 @@ do_transmit (void *cls, size_t size, void *buf) | |||
729 | GNUNET_assert (hd == NULL); | 720 | GNUNET_assert (hd == NULL); |
730 | GNUNET_assert (tl == NULL); | 721 | GNUNET_assert (tl == NULL); |
731 | #if DEBUG_TCP > 1 | 722 | #if DEBUG_TCP > 1 |
732 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 723 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", "Transmitting %u bytes\n", |
733 | "tcp", "Transmitting %u bytes\n", ret); | 724 | ret); |
734 | #endif | 725 | #endif |
735 | GNUNET_STATISTICS_update (plugin->env->stats, | 726 | GNUNET_STATISTICS_update (plugin->env->stats, |
736 | gettext_noop ("# bytes currently in TCP buffers"), | 727 | gettext_noop ("# bytes currently in TCP buffers"), |
737 | -(int64_t) ret, GNUNET_NO); | 728 | -(int64_t) ret, GNUNET_NO); |
738 | GNUNET_STATISTICS_update (plugin->env->stats, | 729 | GNUNET_STATISTICS_update (plugin->env->stats, |
739 | gettext_noop ("# bytes transmitted via TCP"), | 730 | gettext_noop ("# bytes transmitted via TCP"), ret, |
740 | ret, GNUNET_NO); | 731 | GNUNET_NO); |
741 | return ret; | 732 | return ret; |
742 | } | 733 | } |
743 | 734 | ||
@@ -759,12 +750,11 @@ process_pending_messages (struct Session *session) | |||
759 | if (NULL == (pm = session->pending_messages_head)) | 750 | if (NULL == (pm = session->pending_messages_head)) |
760 | return; | 751 | return; |
761 | 752 | ||
762 | session->transmit_handle | 753 | session->transmit_handle = |
763 | = GNUNET_SERVER_notify_transmit_ready (session->client, | 754 | GNUNET_SERVER_notify_transmit_ready (session->client, pm->message_size, |
764 | pm->message_size, | 755 | GNUNET_TIME_absolute_get_remaining |
765 | GNUNET_TIME_absolute_get_remaining | 756 | (pm->timeout), &do_transmit, |
766 | (pm->timeout), | 757 | session); |
767 | &do_transmit, session); | ||
768 | } | 758 | } |
769 | 759 | ||
770 | 760 | ||
@@ -783,14 +773,14 @@ disconnect_session (struct Session *session) | |||
783 | struct PendingMessage *pm; | 773 | struct PendingMessage *pm; |
784 | 774 | ||
785 | #if DEBUG_TCP | 775 | #if DEBUG_TCP |
786 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 776 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
787 | "tcp", | ||
788 | "Disconnecting from `%4s' at %s.\n", | 777 | "Disconnecting from `%4s' at %s.\n", |
789 | GNUNET_i2s (&session->target), | 778 | GNUNET_i2s (&session->target), |
790 | (session->connect_addr != NULL) ? | 779 | (session->connect_addr != |
791 | tcp_address_to_string (session->plugin, | 780 | NULL) ? tcp_address_to_string (session->plugin, |
792 | session->connect_addr, | 781 | session->connect_addr, |
793 | session->connect_alen) : "*"); | 782 | session-> |
783 | connect_alen) : "*"); | ||
794 | #endif | 784 | #endif |
795 | /* remove from session list */ | 785 | /* remove from session list */ |
796 | prev = NULL; | 786 | prev = NULL; |
@@ -816,11 +806,10 @@ disconnect_session (struct Session *session) | |||
816 | while (NULL != (pm = session->pending_messages_head)) | 806 | while (NULL != (pm = session->pending_messages_head)) |
817 | { | 807 | { |
818 | #if DEBUG_TCP | 808 | #if DEBUG_TCP |
819 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 809 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
820 | "tcp", | 810 | pm->transmit_cont != |
821 | pm->transmit_cont != NULL | 811 | NULL ? "Could not deliver message to `%4s'.\n" : |
822 | ? "Could not deliver message to `%4s'.\n" | 812 | "Could not deliver message to `%4s', notifying.\n", |
823 | : "Could not deliver message to `%4s', notifying.\n", | ||
824 | GNUNET_i2s (&session->target)); | 813 | GNUNET_i2s (&session->target)); |
825 | #endif | 814 | #endif |
826 | GNUNET_STATISTICS_update (session->plugin->env->stats, | 815 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
@@ -833,8 +822,8 @@ disconnect_session (struct Session *session) | |||
833 | GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, | 822 | GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, |
834 | session->pending_messages_tail, pm); | 823 | session->pending_messages_tail, pm); |
835 | if (NULL != pm->transmit_cont) | 824 | if (NULL != pm->transmit_cont) |
836 | pm->transmit_cont (pm->transmit_cont_cls, | 825 | pm->transmit_cont (pm->transmit_cont_cls, &session->target, |
837 | &session->target, GNUNET_SYSERR); | 826 | GNUNET_SYSERR); |
838 | GNUNET_free (pm); | 827 | GNUNET_free (pm); |
839 | } | 828 | } |
840 | GNUNET_break (session->client != NULL); | 829 | GNUNET_break (session->client != NULL); |
@@ -850,8 +839,8 @@ disconnect_session (struct Session *session) | |||
850 | session->client = NULL; | 839 | session->client = NULL; |
851 | } | 840 | } |
852 | GNUNET_STATISTICS_update (session->plugin->env->stats, | 841 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
853 | gettext_noop ("# TCP sessions active"), | 842 | gettext_noop ("# TCP sessions active"), -1, |
854 | -1, GNUNET_NO); | 843 | GNUNET_NO); |
855 | GNUNET_free_non_null (session->connect_addr); | 844 | GNUNET_free_non_null (session->connect_addr); |
856 | GNUNET_assert (NULL == session->transmit_handle); | 845 | GNUNET_assert (NULL == session->transmit_handle); |
857 | GNUNET_free (session); | 846 | GNUNET_free (session); |
@@ -928,16 +917,10 @@ select_better_session (struct Session *s1, struct Session *s2) | |||
928 | * and does NOT mean that the message was not transmitted (DV and NAT) | 917 | * and does NOT mean that the message was not transmitted (DV and NAT) |
929 | */ | 918 | */ |
930 | static ssize_t | 919 | static ssize_t |
931 | tcp_plugin_send (void *cls, | 920 | tcp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, |
932 | const struct GNUNET_PeerIdentity *target, | 921 | const char *msg, size_t msgbuf_size, uint32_t priority, |
933 | const char *msg, | 922 | struct GNUNET_TIME_Relative timeout, struct Session *session, |
934 | size_t msgbuf_size, | 923 | const void *addr, size_t addrlen, int force_address, |
935 | uint32_t priority, | ||
936 | struct GNUNET_TIME_Relative timeout, | ||
937 | struct Session *session, | ||
938 | const void *addr, | ||
939 | size_t addrlen, | ||
940 | int force_address, | ||
941 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) | 924 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) |
942 | { | 925 | { |
943 | struct Plugin *plugin = cls; | 926 | struct Plugin *plugin = cls; |
@@ -969,8 +952,9 @@ tcp_plugin_send (void *cls, | |||
969 | { | 952 | { |
970 | next = session->next; | 953 | next = session->next; |
971 | GNUNET_assert (session->client != NULL); | 954 | GNUNET_assert (session->client != NULL); |
972 | if (0 != memcmp (target, | 955 | if (0 != |
973 | &session->target, sizeof (struct GNUNET_PeerIdentity))) | 956 | memcmp (target, &session->target, |
957 | sizeof (struct GNUNET_PeerIdentity))) | ||
974 | continue; | 958 | continue; |
975 | if (((GNUNET_SYSERR == force_address) && | 959 | if (((GNUNET_SYSERR == force_address) && |
976 | (session->expecting_welcome == GNUNET_NO)) || | 960 | (session->expecting_welcome == GNUNET_NO)) || |
@@ -989,8 +973,8 @@ tcp_plugin_send (void *cls, | |||
989 | } | 973 | } |
990 | if ((addrlen != session->connect_alen) && (session->is_nat == GNUNET_NO)) | 974 | if ((addrlen != session->connect_alen) && (session->is_nat == GNUNET_NO)) |
991 | continue; | 975 | continue; |
992 | if ((0 != memcmp (session->connect_addr, | 976 | if ((0 != memcmp (session->connect_addr, addr, addrlen)) && |
993 | addr, addrlen)) && (session->is_nat == GNUNET_NO)) | 977 | (session->is_nat == GNUNET_NO)) |
994 | continue; | 978 | continue; |
995 | cand_session = select_better_session (cand_session, session); | 979 | cand_session = select_better_session (cand_session, session); |
996 | } | 980 | } |
@@ -999,8 +983,7 @@ tcp_plugin_send (void *cls, | |||
999 | if ((session == NULL) && (addr == NULL)) | 983 | if ((session == NULL) && (addr == NULL)) |
1000 | { | 984 | { |
1001 | #if DEBUG_TCP | 985 | #if DEBUG_TCP |
1002 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 986 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
1003 | "tcp", | ||
1004 | "Asked to transmit to `%4s' without address and I have no existing connection (failing).\n", | 987 | "Asked to transmit to `%4s' without address and I have no existing connection (failing).\n", |
1005 | GNUNET_i2s (target)); | 988 | GNUNET_i2s (target)); |
1006 | #endif | 989 | #endif |
@@ -1046,8 +1029,8 @@ tcp_plugin_send (void *cls, | |||
1046 | } | 1029 | } |
1047 | else | 1030 | else |
1048 | { | 1031 | { |
1049 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 1032 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp", |
1050 | "tcp", _("Address of unexpected length: %u\n"), addrlen); | 1033 | _("Address of unexpected length: %u\n"), addrlen); |
1051 | GNUNET_break (0); | 1034 | GNUNET_break (0); |
1052 | return -1; | 1035 | return -1; |
1053 | } | 1036 | } |
@@ -1057,15 +1040,13 @@ tcp_plugin_send (void *cls, | |||
1057 | if (0 == plugin->max_connections) | 1040 | if (0 == plugin->max_connections) |
1058 | return -1; /* saturated */ | 1041 | return -1; /* saturated */ |
1059 | 1042 | ||
1060 | if ((is_natd == GNUNET_YES) && | 1043 | if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) && |
1061 | (NULL != plugin->nat) && | ||
1062 | (GNUNET_NO == | 1044 | (GNUNET_NO == |
1063 | GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns, | 1045 | GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns, |
1064 | &target->hashPubKey))) | 1046 | &target->hashPubKey))) |
1065 | { | 1047 | { |
1066 | #if DEBUG_TCP_NAT | 1048 | #if DEBUG_TCP_NAT |
1067 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1049 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
1068 | "tcp", | ||
1069 | _("Found valid IPv4 NAT address (creating session)!\n")); | 1050 | _("Found valid IPv4 NAT address (creating session)!\n")); |
1070 | #endif | 1051 | #endif |
1071 | session = create_session (plugin, target, NULL, GNUNET_YES); | 1052 | session = create_session (plugin, target, NULL, GNUNET_YES); |
@@ -1088,14 +1069,12 @@ tcp_plugin_send (void *cls, | |||
1088 | session->pending_messages_tail, | 1069 | session->pending_messages_tail, |
1089 | session->pending_messages_tail, pm); | 1070 | session->pending_messages_tail, pm); |
1090 | 1071 | ||
1091 | GNUNET_assert (GNUNET_CONTAINER_multihashmap_put (plugin->nat_wait_conns, | 1072 | GNUNET_assert (GNUNET_CONTAINER_multihashmap_put |
1092 | &target->hashPubKey, | 1073 | (plugin->nat_wait_conns, &target->hashPubKey, session, |
1093 | session, | 1074 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) == |
1094 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) | 1075 | GNUNET_OK); |
1095 | == GNUNET_OK); | ||
1096 | #if DEBUG_TCP_NAT | 1076 | #if DEBUG_TCP_NAT |
1097 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1077 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
1098 | "tcp", | ||
1099 | "Created NAT WAIT connection to `%4s' at `%s'\n", | 1078 | "Created NAT WAIT connection to `%4s' at `%s'\n", |
1100 | GNUNET_i2s (target), GNUNET_a2s (sb, sbs)); | 1079 | GNUNET_i2s (target), GNUNET_a2s (sb, sbs)); |
1101 | #endif | 1080 | #endif |
@@ -1114,8 +1093,7 @@ tcp_plugin_send (void *cls, | |||
1114 | if (sa == NULL) | 1093 | if (sa == NULL) |
1115 | { | 1094 | { |
1116 | #if DEBUG_TCP | 1095 | #if DEBUG_TCP |
1117 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1096 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
1118 | "tcp", | ||
1119 | "Failed to create connection to `%4s' at `%s'\n", | 1097 | "Failed to create connection to `%4s' at `%s'\n", |
1120 | GNUNET_i2s (target), GNUNET_a2s (sb, sbs)); | 1098 | GNUNET_i2s (target), GNUNET_a2s (sb, sbs)); |
1121 | #endif | 1099 | #endif |
@@ -1128,15 +1106,14 @@ tcp_plugin_send (void *cls, | |||
1128 | GNUNET_assert (0 != plugin->max_connections); | 1106 | GNUNET_assert (0 != plugin->max_connections); |
1129 | plugin->max_connections--; | 1107 | plugin->max_connections--; |
1130 | #if DEBUG_TCP_NAT | 1108 | #if DEBUG_TCP_NAT |
1131 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1109 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
1132 | "tcp", | ||
1133 | "Asked to transmit to `%4s', creating fresh session using address `%s'.\n", | 1110 | "Asked to transmit to `%4s', creating fresh session using address `%s'.\n", |
1134 | GNUNET_i2s (target), GNUNET_a2s (sb, sbs)); | 1111 | GNUNET_i2s (target), GNUNET_a2s (sb, sbs)); |
1135 | #endif | 1112 | #endif |
1136 | session = create_session (plugin, | 1113 | session = |
1137 | target, | 1114 | create_session (plugin, target, |
1138 | GNUNET_SERVER_connect_socket (plugin->server, | 1115 | GNUNET_SERVER_connect_socket (plugin->server, sa), |
1139 | sa), GNUNET_NO); | 1116 | GNUNET_NO); |
1140 | session->connect_addr = GNUNET_malloc (addrlen); | 1117 | session->connect_addr = GNUNET_malloc (addrlen); |
1141 | memcpy (session->connect_addr, addr, addrlen); | 1118 | memcpy (session->connect_addr, addr, addrlen); |
1142 | session->connect_alen = addrlen; | 1119 | session->connect_alen = addrlen; |
@@ -1177,8 +1154,7 @@ tcp_plugin_send (void *cls, | |||
1177 | session->pending_messages_tail, | 1154 | session->pending_messages_tail, |
1178 | session->pending_messages_tail, pm); | 1155 | session->pending_messages_tail, pm); |
1179 | #if DEBUG_TCP | 1156 | #if DEBUG_TCP |
1180 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1157 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
1181 | "tcp", | ||
1182 | "Asked to transmit %u bytes to `%s', added message to list.\n", | 1158 | "Asked to transmit %u bytes to `%s', added message to list.\n", |
1183 | msgbuf_size, GNUNET_i2s (target)); | 1159 | msgbuf_size, GNUNET_i2s (target)); |
1184 | #endif | 1160 | #endif |
@@ -1212,16 +1188,15 @@ tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) | |||
1212 | struct PendingMessage *pm; | 1188 | struct PendingMessage *pm; |
1213 | 1189 | ||
1214 | #if DEBUG_TCP | 1190 | #if DEBUG_TCP |
1215 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1191 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
1216 | "tcp", | ||
1217 | "Asked to cancel session with `%4s'\n", GNUNET_i2s (target)); | 1192 | "Asked to cancel session with `%4s'\n", GNUNET_i2s (target)); |
1218 | #endif | 1193 | #endif |
1219 | next = plugin->sessions; | 1194 | next = plugin->sessions; |
1220 | while (NULL != (session = next)) | 1195 | while (NULL != (session = next)) |
1221 | { | 1196 | { |
1222 | next = session->next; | 1197 | next = session->next; |
1223 | if (0 != memcmp (target, | 1198 | if (0 != |
1224 | &session->target, sizeof (struct GNUNET_PeerIdentity))) | 1199 | memcmp (target, &session->target, sizeof (struct GNUNET_PeerIdentity))) |
1225 | continue; | 1200 | continue; |
1226 | pm = session->pending_messages_head; | 1201 | pm = session->pending_messages_head; |
1227 | while (pm != NULL) | 1202 | while (pm != NULL) |
@@ -1300,10 +1275,8 @@ append_port (void *cls, const char *hostname) | |||
1300 | * @param asc_cls closure for asc | 1275 | * @param asc_cls closure for asc |
1301 | */ | 1276 | */ |
1302 | static void | 1277 | static void |
1303 | tcp_plugin_address_pretty_printer (void *cls, | 1278 | tcp_plugin_address_pretty_printer (void *cls, const char *type, |
1304 | const char *type, | 1279 | const void *addr, size_t addrlen, |
1305 | const void *addr, | ||
1306 | size_t addrlen, | ||
1307 | int numeric, | 1280 | int numeric, |
1308 | struct GNUNET_TIME_Relative timeout, | 1281 | struct GNUNET_TIME_Relative timeout, |
1309 | GNUNET_TRANSPORT_AddressStringCallback asc, | 1282 | GNUNET_TRANSPORT_AddressStringCallback asc, |
@@ -1408,8 +1381,8 @@ tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen) | |||
1408 | if (GNUNET_OK != check_port (plugin, ntohs (v4->t4_port))) | 1381 | if (GNUNET_OK != check_port (plugin, ntohs (v4->t4_port))) |
1409 | return GNUNET_SYSERR; | 1382 | return GNUNET_SYSERR; |
1410 | if (GNUNET_OK != | 1383 | if (GNUNET_OK != |
1411 | GNUNET_NAT_test_address (plugin->nat, | 1384 | GNUNET_NAT_test_address (plugin->nat, &v4->ipv4_addr, |
1412 | &v4->ipv4_addr, sizeof (struct in_addr))) | 1385 | sizeof (struct in_addr))) |
1413 | return GNUNET_SYSERR; | 1386 | return GNUNET_SYSERR; |
1414 | } | 1387 | } |
1415 | else | 1388 | else |
@@ -1423,8 +1396,8 @@ tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen) | |||
1423 | if (GNUNET_OK != check_port (plugin, ntohs (v6->t6_port))) | 1396 | if (GNUNET_OK != check_port (plugin, ntohs (v6->t6_port))) |
1424 | return GNUNET_SYSERR; | 1397 | return GNUNET_SYSERR; |
1425 | if (GNUNET_OK != | 1398 | if (GNUNET_OK != |
1426 | GNUNET_NAT_test_address (plugin->nat, | 1399 | GNUNET_NAT_test_address (plugin->nat, &v6->ipv6_addr, |
1427 | &v6->ipv6_addr, sizeof (struct in6_addr))) | 1400 | sizeof (struct in6_addr))) |
1428 | return GNUNET_SYSERR; | 1401 | return GNUNET_SYSERR; |
1429 | } | 1402 | } |
1430 | return GNUNET_OK; | 1403 | return GNUNET_OK; |
@@ -1441,8 +1414,7 @@ tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen) | |||
1441 | * @param message the actual message | 1414 | * @param message the actual message |
1442 | */ | 1415 | */ |
1443 | static void | 1416 | static void |
1444 | handle_tcp_nat_probe (void *cls, | 1417 | handle_tcp_nat_probe (void *cls, struct GNUNET_SERVER_Client *client, |
1445 | struct GNUNET_SERVER_Client *client, | ||
1446 | const struct GNUNET_MessageHeader *message) | 1418 | const struct GNUNET_MessageHeader *message) |
1447 | { | 1419 | { |
1448 | struct Plugin *plugin = cls; | 1420 | struct Plugin *plugin = cls; |
@@ -1472,34 +1444,36 @@ handle_tcp_nat_probe (void *cls, | |||
1472 | } | 1444 | } |
1473 | 1445 | ||
1474 | tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *) message; | 1446 | tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *) message; |
1475 | if (0 == memcmp (&tcp_nat_probe->clientIdentity, | 1447 | if (0 == |
1476 | plugin->env->my_identity, | 1448 | memcmp (&tcp_nat_probe->clientIdentity, plugin->env->my_identity, |
1477 | sizeof (struct GNUNET_PeerIdentity))) | 1449 | sizeof (struct GNUNET_PeerIdentity))) |
1478 | { | 1450 | { |
1479 | /* refuse connections from ourselves */ | 1451 | /* refuse connections from ourselves */ |
1480 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1452 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1481 | return; | 1453 | return; |
1482 | } | 1454 | } |
1483 | 1455 | ||
1484 | session = GNUNET_CONTAINER_multihashmap_get (plugin->nat_wait_conns, | 1456 | session = |
1485 | &tcp_nat_probe-> | 1457 | GNUNET_CONTAINER_multihashmap_get (plugin->nat_wait_conns, |
1486 | clientIdentity.hashPubKey); | 1458 | &tcp_nat_probe->clientIdentity. |
1459 | hashPubKey); | ||
1487 | if (session == NULL) | 1460 | if (session == NULL) |
1488 | { | 1461 | { |
1489 | #if DEBUG_TCP_NAT | 1462 | #if DEBUG_TCP_NAT |
1490 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1463 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
1491 | "tcp", "Did NOT find session for NAT probe!\n"); | 1464 | "Did NOT find session for NAT probe!\n"); |
1492 | #endif | 1465 | #endif |
1493 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1466 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1494 | return; | 1467 | return; |
1495 | } | 1468 | } |
1496 | #if DEBUG_TCP_NAT | 1469 | #if DEBUG_TCP_NAT |
1497 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1470 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
1498 | "tcp", "Found session for NAT probe!\n"); | 1471 | "Found session for NAT probe!\n"); |
1499 | #endif | 1472 | #endif |
1500 | GNUNET_assert (GNUNET_CONTAINER_multihashmap_remove (plugin->nat_wait_conns, | 1473 | GNUNET_assert (GNUNET_CONTAINER_multihashmap_remove |
1501 | &tcp_nat_probe->clientIdentity.hashPubKey, | 1474 | (plugin->nat_wait_conns, |
1502 | session) == GNUNET_YES); | 1475 | &tcp_nat_probe->clientIdentity.hashPubKey, |
1476 | session) == GNUNET_YES); | ||
1503 | if (GNUNET_OK != GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) | 1477 | if (GNUNET_OK != GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) |
1504 | { | 1478 | { |
1505 | GNUNET_break (0); | 1479 | GNUNET_break (0); |
@@ -1514,8 +1488,7 @@ handle_tcp_nat_probe (void *cls, | |||
1514 | session->inbound = GNUNET_NO; | 1488 | session->inbound = GNUNET_NO; |
1515 | 1489 | ||
1516 | #if DEBUG_TCP_NAT | 1490 | #if DEBUG_TCP_NAT |
1517 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1491 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
1518 | "tcp", | ||
1519 | "Found address `%s' for incoming connection\n", | 1492 | "Found address `%s' for incoming connection\n", |
1520 | GNUNET_a2s (vaddr, alen)); | 1493 | GNUNET_a2s (vaddr, alen)); |
1521 | #endif | 1494 | #endif |
@@ -1540,8 +1513,8 @@ handle_tcp_nat_probe (void *cls, | |||
1540 | default: | 1513 | default: |
1541 | GNUNET_break_op (0); | 1514 | GNUNET_break_op (0); |
1542 | #if DEBUG_TCP_NAT | 1515 | #if DEBUG_TCP_NAT |
1543 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1516 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
1544 | "tcp", "Bad address for incoming connection!\n"); | 1517 | "Bad address for incoming connection!\n"); |
1545 | #endif | 1518 | #endif |
1546 | GNUNET_free (vaddr); | 1519 | GNUNET_free (vaddr); |
1547 | GNUNET_SERVER_client_drop (client); | 1520 | GNUNET_SERVER_client_drop (client); |
@@ -1554,8 +1527,8 @@ handle_tcp_nat_probe (void *cls, | |||
1554 | session->next = plugin->sessions; | 1527 | session->next = plugin->sessions; |
1555 | plugin->sessions = session; | 1528 | plugin->sessions = session; |
1556 | GNUNET_STATISTICS_update (plugin->env->stats, | 1529 | GNUNET_STATISTICS_update (plugin->env->stats, |
1557 | gettext_noop ("# TCP sessions active"), | 1530 | gettext_noop ("# TCP sessions active"), 1, |
1558 | 1, GNUNET_NO); | 1531 | GNUNET_NO); |
1559 | process_pending_messages (session); | 1532 | process_pending_messages (session); |
1560 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1533 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1561 | } | 1534 | } |
@@ -1570,8 +1543,7 @@ handle_tcp_nat_probe (void *cls, | |||
1570 | * @param message the actual message | 1543 | * @param message the actual message |
1571 | */ | 1544 | */ |
1572 | static void | 1545 | static void |
1573 | handle_tcp_welcome (void *cls, | 1546 | handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client, |
1574 | struct GNUNET_SERVER_Client *client, | ||
1575 | const struct GNUNET_MessageHeader *message) | 1547 | const struct GNUNET_MessageHeader *message) |
1576 | { | 1548 | { |
1577 | struct Plugin *plugin = cls; | 1549 | struct Plugin *plugin = cls; |
@@ -1584,30 +1556,28 @@ handle_tcp_welcome (void *cls, | |||
1584 | const struct sockaddr_in *s4; | 1556 | const struct sockaddr_in *s4; |
1585 | const struct sockaddr_in6 *s6; | 1557 | const struct sockaddr_in6 *s6; |
1586 | 1558 | ||
1587 | if (0 == memcmp (&wm->clientIdentity, | 1559 | if (0 == |
1588 | plugin->env->my_identity, | 1560 | memcmp (&wm->clientIdentity, plugin->env->my_identity, |
1589 | sizeof (struct GNUNET_PeerIdentity))) | 1561 | sizeof (struct GNUNET_PeerIdentity))) |
1590 | { | 1562 | { |
1591 | /* refuse connections from ourselves */ | 1563 | /* refuse connections from ourselves */ |
1592 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1564 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1593 | return; | 1565 | return; |
1594 | } | 1566 | } |
1595 | #if DEBUG_TCP | 1567 | #if DEBUG_TCP |
1596 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1568 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
1597 | "tcp", | 1569 | "Received %s message from `%4s'.\n", "WELCOME", |
1598 | "Received %s message from `%4s'.\n", | 1570 | GNUNET_i2s (&wm->clientIdentity)); |
1599 | "WELCOME", GNUNET_i2s (&wm->clientIdentity)); | ||
1600 | #endif | 1571 | #endif |
1601 | GNUNET_STATISTICS_update (plugin->env->stats, | 1572 | GNUNET_STATISTICS_update (plugin->env->stats, |
1602 | gettext_noop ("# TCP WELCOME messages received"), | 1573 | gettext_noop ("# TCP WELCOME messages received"), 1, |
1603 | 1, GNUNET_NO); | 1574 | GNUNET_NO); |
1604 | session = find_session_by_client (plugin, client); | 1575 | session = find_session_by_client (plugin, client); |
1605 | 1576 | ||
1606 | if (session == NULL) | 1577 | if (session == NULL) |
1607 | { | 1578 | { |
1608 | #if DEBUG_TCP_NAT | 1579 | #if DEBUG_TCP_NAT |
1609 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1580 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
1610 | "tcp", | ||
1611 | "Received %s message from a `%4s', creating new session\n", | 1581 | "Received %s message from a `%4s', creating new session\n", |
1612 | "WELCOME", GNUNET_i2s (&wm->clientIdentity)); | 1582 | "WELCOME", GNUNET_i2s (&wm->clientIdentity)); |
1613 | #endif | 1583 | #endif |
@@ -1617,8 +1587,7 @@ handle_tcp_welcome (void *cls, | |||
1617 | if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) | 1587 | if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) |
1618 | { | 1588 | { |
1619 | #if DEBUG_TCP_NAT | 1589 | #if DEBUG_TCP_NAT |
1620 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1590 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
1621 | "tcp", | ||
1622 | "Found address `%s' for incoming connection\n", | 1591 | "Found address `%s' for incoming connection\n", |
1623 | GNUNET_a2s (vaddr, alen)); | 1592 | GNUNET_a2s (vaddr, alen)); |
1624 | #endif | 1593 | #endif |
@@ -1646,8 +1615,7 @@ handle_tcp_welcome (void *cls, | |||
1646 | else | 1615 | else |
1647 | { | 1616 | { |
1648 | #if DEBUG_TCP | 1617 | #if DEBUG_TCP |
1649 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1618 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
1650 | "tcp", | ||
1651 | "Did not obtain TCP socket address for incoming connection\n"); | 1619 | "Did not obtain TCP socket address for incoming connection\n"); |
1652 | #endif | 1620 | #endif |
1653 | } | 1621 | } |
@@ -1658,8 +1626,7 @@ handle_tcp_welcome (void *cls, | |||
1658 | #if DEBUG_TCP_NAT | 1626 | #if DEBUG_TCP_NAT |
1659 | if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) | 1627 | if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) |
1660 | { | 1628 | { |
1661 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1629 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
1662 | "tcp", | ||
1663 | "Found address `%s' (already have session)\n", | 1630 | "Found address `%s' (already have session)\n", |
1664 | GNUNET_a2s (vaddr, alen)); | 1631 | GNUNET_a2s (vaddr, alen)); |
1665 | GNUNET_free (vaddr); | 1632 | GNUNET_free (vaddr); |
@@ -1695,9 +1662,10 @@ delayed_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1695 | struct GNUNET_TIME_Relative delay; | 1662 | struct GNUNET_TIME_Relative delay; |
1696 | 1663 | ||
1697 | session->receive_delay_task = GNUNET_SCHEDULER_NO_TASK; | 1664 | session->receive_delay_task = GNUNET_SCHEDULER_NO_TASK; |
1698 | delay = session->plugin->env->receive (session->plugin->env->cls, | 1665 | delay = |
1699 | &session->target, | 1666 | session->plugin->env->receive (session->plugin->env->cls, |
1700 | NULL, NULL, 0, session, NULL, 0); | 1667 | &session->target, NULL, NULL, 0, session, |
1668 | NULL, 0); | ||
1701 | if (delay.rel_value == 0) | 1669 | if (delay.rel_value == 0) |
1702 | GNUNET_SERVER_receive_done (session->client, GNUNET_OK); | 1670 | GNUNET_SERVER_receive_done (session->client, GNUNET_OK); |
1703 | else | 1671 | else |
@@ -1715,8 +1683,7 @@ delayed_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1715 | * @param message the actual message | 1683 | * @param message the actual message |
1716 | */ | 1684 | */ |
1717 | static void | 1685 | static void |
1718 | handle_tcp_data (void *cls, | 1686 | handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client, |
1719 | struct GNUNET_SERVER_Client *client, | ||
1720 | const struct GNUNET_MessageHeader *message) | 1687 | const struct GNUNET_MessageHeader *message) |
1721 | { | 1688 | { |
1722 | struct Plugin *plugin = cls; | 1689 | struct Plugin *plugin = cls; |
@@ -1740,8 +1707,7 @@ handle_tcp_data (void *cls, | |||
1740 | } | 1707 | } |
1741 | session->last_activity = GNUNET_TIME_absolute_get (); | 1708 | session->last_activity = GNUNET_TIME_absolute_get (); |
1742 | #if DEBUG_TCP > 1 | 1709 | #if DEBUG_TCP > 1 |
1743 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1710 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
1744 | "tcp", | ||
1745 | "Passing %u bytes of type %u from `%4s' to transport service.\n", | 1711 | "Passing %u bytes of type %u from `%4s' to transport service.\n", |
1746 | (unsigned int) ntohs (message->size), | 1712 | (unsigned int) ntohs (message->size), |
1747 | (unsigned int) ntohs (message->type), | 1713 | (unsigned int) ntohs (message->type), |
@@ -1756,14 +1722,14 @@ handle_tcp_data (void *cls, | |||
1756 | distance[0].value = htonl (1); | 1722 | distance[0].value = htonl (1); |
1757 | distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); | 1723 | distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); |
1758 | distance[1].value = htonl (0); | 1724 | distance[1].value = htonl (0); |
1759 | delay = plugin->env->receive (plugin->env->cls, &session->target, message, | 1725 | delay = |
1760 | (const struct GNUNET_TRANSPORT_ATS_Information | 1726 | plugin->env->receive (plugin->env->cls, &session->target, message, |
1761 | *) &distance, 2, session, | 1727 | (const struct GNUNET_TRANSPORT_ATS_Information *) |
1762 | (GNUNET_YES == | 1728 | &distance, 2, session, |
1763 | session-> | 1729 | (GNUNET_YES == |
1764 | inbound) ? NULL : session->connect_addr, | 1730 | session->inbound) ? NULL : session->connect_addr, |
1765 | (GNUNET_YES == | 1731 | (GNUNET_YES == |
1766 | session->inbound) ? 0 : session->connect_alen); | 1732 | session->inbound) ? 0 : session->connect_alen); |
1767 | if (delay.rel_value == 0) | 1733 | if (delay.rel_value == 0) |
1768 | { | 1734 | { |
1769 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1735 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -1771,8 +1737,7 @@ handle_tcp_data (void *cls, | |||
1771 | else | 1737 | else |
1772 | { | 1738 | { |
1773 | #if DEBUG_TCP | 1739 | #if DEBUG_TCP |
1774 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1740 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
1775 | "tcp", | ||
1776 | "Throttling receiving from `%s' for %llu ms\n", | 1741 | "Throttling receiving from `%s' for %llu ms\n", |
1777 | GNUNET_i2s (&session->target), | 1742 | GNUNET_i2s (&session->target), |
1778 | (unsigned long long) delay.rel_value); | 1743 | (unsigned long long) delay.rel_value); |
@@ -1804,14 +1769,14 @@ disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client) | |||
1804 | if (session == NULL) | 1769 | if (session == NULL) |
1805 | return; /* unknown, nothing to do */ | 1770 | return; /* unknown, nothing to do */ |
1806 | #if DEBUG_TCP | 1771 | #if DEBUG_TCP |
1807 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1772 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
1808 | "tcp", | ||
1809 | "Destroying session of `%4s' with %s due to network-level disconnect.\n", | 1773 | "Destroying session of `%4s' with %s due to network-level disconnect.\n", |
1810 | GNUNET_i2s (&session->target), | 1774 | GNUNET_i2s (&session->target), |
1811 | (session->connect_addr != NULL) ? | 1775 | (session->connect_addr != |
1812 | tcp_address_to_string (session->plugin, | 1776 | NULL) ? tcp_address_to_string (session->plugin, |
1813 | session->connect_addr, | 1777 | session->connect_addr, |
1814 | session->connect_alen) : "*"); | 1778 | session-> |
1779 | connect_alen) : "*"); | ||
1815 | #endif | 1780 | #endif |
1816 | GNUNET_STATISTICS_update (session->plugin->env->stats, | 1781 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
1817 | gettext_noop | 1782 | gettext_noop |
@@ -1837,8 +1802,8 @@ notify_send_probe (void *cls, size_t size, void *buf) | |||
1837 | size_t ret; | 1802 | size_t ret; |
1838 | 1803 | ||
1839 | tcp_probe_ctx->transmit_handle = NULL; | 1804 | tcp_probe_ctx->transmit_handle = NULL; |
1840 | GNUNET_CONTAINER_DLL_remove (plugin->probe_head, | 1805 | GNUNET_CONTAINER_DLL_remove (plugin->probe_head, plugin->probe_tail, |
1841 | plugin->probe_tail, tcp_probe_ctx); | 1806 | tcp_probe_ctx); |
1842 | if (buf == NULL) | 1807 | if (buf == NULL) |
1843 | { | 1808 | { |
1844 | GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock, GNUNET_NO); | 1809 | GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock, GNUNET_NO); |
@@ -1865,8 +1830,8 @@ notify_send_probe (void *cls, size_t size, void *buf) | |||
1865 | * @param addrlen number of bytes in addr | 1830 | * @param addrlen number of bytes in addr |
1866 | */ | 1831 | */ |
1867 | static void | 1832 | static void |
1868 | try_connection_reversal (void *cls, | 1833 | try_connection_reversal (void *cls, const struct sockaddr *addr, |
1869 | const struct sockaddr *addr, socklen_t addrlen) | 1834 | socklen_t addrlen) |
1870 | { | 1835 | { |
1871 | struct Plugin *plugin = cls; | 1836 | struct Plugin *plugin = cls; |
1872 | struct GNUNET_CONNECTION_Handle *sock; | 1837 | struct GNUNET_CONNECTION_Handle *sock; |
@@ -1886,23 +1851,23 @@ try_connection_reversal (void *cls, | |||
1886 | /* FIXME: do we need to track these probe context objects so that | 1851 | /* FIXME: do we need to track these probe context objects so that |
1887 | * we can clean them up on plugin unload? */ | 1852 | * we can clean them up on plugin unload? */ |
1888 | tcp_probe_ctx = GNUNET_malloc (sizeof (struct TCPProbeContext)); | 1853 | tcp_probe_ctx = GNUNET_malloc (sizeof (struct TCPProbeContext)); |
1889 | tcp_probe_ctx->message.header.size | 1854 | tcp_probe_ctx->message.header.size = |
1890 | = htons (sizeof (struct TCP_NAT_ProbeMessage)); | 1855 | htons (sizeof (struct TCP_NAT_ProbeMessage)); |
1891 | tcp_probe_ctx->message.header.type | 1856 | tcp_probe_ctx->message.header.type = |
1892 | = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE); | 1857 | htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE); |
1893 | memcpy (&tcp_probe_ctx->message.clientIdentity, | 1858 | memcpy (&tcp_probe_ctx->message.clientIdentity, plugin->env->my_identity, |
1894 | plugin->env->my_identity, sizeof (struct GNUNET_PeerIdentity)); | 1859 | sizeof (struct GNUNET_PeerIdentity)); |
1895 | tcp_probe_ctx->plugin = plugin; | 1860 | tcp_probe_ctx->plugin = plugin; |
1896 | tcp_probe_ctx->sock = sock; | 1861 | tcp_probe_ctx->sock = sock; |
1897 | GNUNET_CONTAINER_DLL_insert (plugin->probe_head, | 1862 | GNUNET_CONTAINER_DLL_insert (plugin->probe_head, plugin->probe_tail, |
1898 | plugin->probe_tail, tcp_probe_ctx); | 1863 | tcp_probe_ctx); |
1899 | tcp_probe_ctx->transmit_handle | 1864 | tcp_probe_ctx->transmit_handle = |
1900 | = GNUNET_CONNECTION_notify_transmit_ready (sock, | 1865 | GNUNET_CONNECTION_notify_transmit_ready (sock, |
1901 | ntohs (tcp_probe_ctx-> | 1866 | ntohs (tcp_probe_ctx->message. |
1902 | message.header.size), | 1867 | header.size), |
1903 | GNUNET_TIME_UNIT_FOREVER_REL, | 1868 | GNUNET_TIME_UNIT_FOREVER_REL, |
1904 | ¬ify_send_probe, | 1869 | ¬ify_send_probe, |
1905 | tcp_probe_ctx); | 1870 | tcp_probe_ctx); |
1906 | 1871 | ||
1907 | } | 1872 | } |
1908 | 1873 | ||
@@ -1938,27 +1903,21 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
1938 | socklen_t *addrlens; | 1903 | socklen_t *addrlens; |
1939 | 1904 | ||
1940 | if (GNUNET_OK != | 1905 | if (GNUNET_OK != |
1941 | GNUNET_CONFIGURATION_get_value_number (env->cfg, | 1906 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", |
1942 | "transport-tcp", | ||
1943 | "MAX_CONNECTIONS", | 1907 | "MAX_CONNECTIONS", |
1944 | &max_connections)) | 1908 | &max_connections)) |
1945 | max_connections = 128; | 1909 | max_connections = 128; |
1946 | 1910 | ||
1947 | aport = 0; | 1911 | aport = 0; |
1948 | if ((GNUNET_OK != | 1912 | if ((GNUNET_OK != |
1949 | GNUNET_CONFIGURATION_get_value_number (env->cfg, | 1913 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", "PORT", |
1950 | "transport-tcp", | 1914 | &bport)) || (bport > 65535) || |
1951 | "PORT", | ||
1952 | &bport)) || | ||
1953 | (bport > 65535) || | ||
1954 | ((GNUNET_OK == | 1915 | ((GNUNET_OK == |
1955 | GNUNET_CONFIGURATION_get_value_number (env->cfg, | 1916 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", |
1956 | "transport-tcp", | 1917 | "ADVERTISED-PORT", &aport)) && |
1957 | "ADVERTISED-PORT", | 1918 | (aport > 65535))) |
1958 | &aport)) && (aport > 65535))) | ||
1959 | { | 1919 | { |
1960 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 1920 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp", |
1961 | "tcp", | ||
1962 | _ | 1921 | _ |
1963 | ("Require valid port number for service `%s' in configuration!\n"), | 1922 | ("Require valid port number for service `%s' in configuration!\n"), |
1964 | "transport-tcp"); | 1923 | "transport-tcp"); |
@@ -1973,8 +1932,8 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
1973 | service = GNUNET_SERVICE_start ("transport-tcp", env->cfg); | 1932 | service = GNUNET_SERVICE_start ("transport-tcp", env->cfg); |
1974 | if (service == NULL) | 1933 | if (service == NULL) |
1975 | { | 1934 | { |
1976 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, | 1935 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "tcp", |
1977 | "tcp", _("Failed to start service.\n")); | 1936 | _("Failed to start service.\n")); |
1978 | return NULL; | 1937 | return NULL; |
1979 | } | 1938 | } |
1980 | } | 1939 | } |
@@ -1991,18 +1950,15 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
1991 | plugin->lsock = NULL; | 1950 | plugin->lsock = NULL; |
1992 | if ((service != NULL) && | 1951 | if ((service != NULL) && |
1993 | (GNUNET_SYSERR != | 1952 | (GNUNET_SYSERR != |
1994 | (ret = GNUNET_SERVICE_get_server_addresses ("transport-tcp", | 1953 | (ret = |
1995 | env->cfg, | 1954 | GNUNET_SERVICE_get_server_addresses ("transport-tcp", env->cfg, &addrs, |
1996 | &addrs, &addrlens)))) | 1955 | &addrlens)))) |
1997 | { | 1956 | { |
1998 | plugin->nat = GNUNET_NAT_register (env->cfg, | 1957 | plugin->nat = |
1999 | GNUNET_YES, | 1958 | GNUNET_NAT_register (env->cfg, GNUNET_YES, aport, (unsigned int) ret, |
2000 | aport, | 1959 | (const struct sockaddr **) addrs, addrlens, |
2001 | (unsigned int) ret, | 1960 | &tcp_nat_port_map_callback, |
2002 | (const struct sockaddr **) addrs, | 1961 | &try_connection_reversal, plugin); |
2003 | addrlens, | ||
2004 | &tcp_nat_port_map_callback, | ||
2005 | &try_connection_reversal, plugin); | ||
2006 | while (ret > 0) | 1962 | while (ret > 0) |
2007 | { | 1963 | { |
2008 | ret--; | 1964 | ret--; |
@@ -2014,11 +1970,9 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2014 | } | 1970 | } |
2015 | else | 1971 | else |
2016 | { | 1972 | { |
2017 | plugin->nat = GNUNET_NAT_register (env->cfg, | 1973 | plugin->nat = |
2018 | GNUNET_YES, | 1974 | GNUNET_NAT_register (env->cfg, GNUNET_YES, 0, 0, NULL, NULL, NULL, |
2019 | 0, | 1975 | &try_connection_reversal, plugin); |
2020 | 0, NULL, NULL, | ||
2021 | NULL, &try_connection_reversal, plugin); | ||
2022 | } | 1976 | } |
2023 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 1977 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); |
2024 | api->cls = plugin; | 1978 | api->cls = plugin; |
@@ -2035,12 +1989,10 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2035 | else | 1989 | else |
2036 | { | 1990 | { |
2037 | if (GNUNET_OK != | 1991 | if (GNUNET_OK != |
2038 | GNUNET_CONFIGURATION_get_value_time (env->cfg, | 1992 | GNUNET_CONFIGURATION_get_value_time (env->cfg, "transport-tcp", |
2039 | "transport-tcp", | ||
2040 | "TIMEOUT", &idle_timeout)) | 1993 | "TIMEOUT", &idle_timeout)) |
2041 | { | 1994 | { |
2042 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 1995 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp", |
2043 | "tcp", | ||
2044 | _("Failed to find option %s in section %s!\n"), | 1996 | _("Failed to find option %s in section %s!\n"), |
2045 | "TIMEOUT", "transport-tcp"); | 1997 | "TIMEOUT", "transport-tcp"); |
2046 | if (plugin->nat != NULL) | 1998 | if (plugin->nat != NULL) |
@@ -2063,16 +2015,14 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2063 | GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin); | 2015 | GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin); |
2064 | plugin->nat_wait_conns = GNUNET_CONTAINER_multihashmap_create (16); | 2016 | plugin->nat_wait_conns = GNUNET_CONTAINER_multihashmap_create (16); |
2065 | if (bport != 0) | 2017 | if (bport != 0) |
2066 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, | 2018 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "tcp", |
2067 | "tcp", _("TCP transport listening on port %llu\n"), bport); | 2019 | _("TCP transport listening on port %llu\n"), bport); |
2068 | else | 2020 | else |
2069 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, | 2021 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "tcp", |
2070 | "tcp", | ||
2071 | _ | 2022 | _ |
2072 | ("TCP transport not listening on any port (client only)\n")); | 2023 | ("TCP transport not listening on any port (client only)\n")); |
2073 | if (aport != bport) | 2024 | if (aport != bport) |
2074 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, | 2025 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "tcp", |
2075 | "tcp", | ||
2076 | _ | 2026 | _ |
2077 | ("TCP transport advertises itself as being on port %llu\n"), | 2027 | ("TCP transport advertises itself as being on port %llu\n"), |
2078 | aport); | 2028 | aport); |
@@ -2102,8 +2052,8 @@ libgnunet_plugin_transport_tcp_done (void *cls) | |||
2102 | GNUNET_NAT_unregister (plugin->nat); | 2052 | GNUNET_NAT_unregister (plugin->nat); |
2103 | while (NULL != (tcp_probe = plugin->probe_head)) | 2053 | while (NULL != (tcp_probe = plugin->probe_head)) |
2104 | { | 2054 | { |
2105 | GNUNET_CONTAINER_DLL_remove (plugin->probe_head, | 2055 | GNUNET_CONTAINER_DLL_remove (plugin->probe_head, plugin->probe_tail, |
2106 | plugin->probe_tail, tcp_probe); | 2056 | tcp_probe); |
2107 | GNUNET_CONNECTION_destroy (tcp_probe->sock, GNUNET_NO); | 2057 | GNUNET_CONNECTION_destroy (tcp_probe->sock, GNUNET_NO); |
2108 | GNUNET_free (tcp_probe); | 2058 | GNUNET_free (tcp_probe); |
2109 | } | 2059 | } |