diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-06-28 10:01:56 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-06-28 10:01:56 +0000 |
commit | 30fd6fcf51409d4adcb4372c8360eaa235919670 (patch) | |
tree | f7df2805e19ecc2924278fa0d0385d4828f38418 /src/transport/plugin_transport_udp.c | |
parent | 7f0876ac6807e818368e71108b56abbc1a513169 (diff) | |
download | gnunet-30fd6fcf51409d4adcb4372c8360eaa235919670.tar.gz gnunet-30fd6fcf51409d4adcb4372c8360eaa235919670.zip |
more portability changes; so NAT punching also should work
Diffstat (limited to 'src/transport/plugin_transport_udp.c')
-rw-r--r-- | src/transport/plugin_transport_udp.c | 204 |
1 files changed, 98 insertions, 106 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 0f424b38a..52e598189 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -296,14 +296,9 @@ struct UDP_NAT_Probes | |||
296 | GNUNET_SCHEDULER_TaskIdentifier task; | 296 | GNUNET_SCHEDULER_TaskIdentifier task; |
297 | 297 | ||
298 | /** | 298 | /** |
299 | * Network address (always ipv4) | 299 | * Network address (always ipv4!) |
300 | */ | 300 | */ |
301 | struct sockaddr_in sock_addr; | 301 | struct IPv4UdpAddress addr; |
302 | |||
303 | /** | ||
304 | * The port to send this probe to, 0 to choose randomly | ||
305 | */ | ||
306 | int port; | ||
307 | 302 | ||
308 | }; | 303 | }; |
309 | 304 | ||
@@ -553,7 +548,7 @@ udp_real_send (void *cls, | |||
553 | 548 | ||
554 | if ((addr == NULL) || (addrlen == 0)) | 549 | if ((addr == NULL) || (addrlen == 0)) |
555 | { | 550 | { |
556 | #if DEBUG_UDP_NAT | 551 | #if DEBUG_UDP |
557 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ | 552 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ |
558 | ("udp_real_send called without address, returning!\n")); | 553 | ("udp_real_send called without address, returning!\n")); |
559 | #endif | 554 | #endif |
@@ -638,35 +633,25 @@ udp_real_send (void *cls, | |||
638 | void | 633 | void |
639 | run_gnunet_nat_client (struct Plugin *plugin, const char *addr, size_t addrlen) | 634 | run_gnunet_nat_client (struct Plugin *plugin, const char *addr, size_t addrlen) |
640 | { | 635 | { |
641 | char inet4[INET_ADDRSTRLEN]; | 636 | char addr_buf[INET_ADDRSTRLEN]; |
642 | char *address_as_string; | 637 | char *address_as_string; |
643 | char *port_as_string; | 638 | char *port_as_string; |
644 | pid_t pid; | 639 | pid_t pid; |
645 | const struct sockaddr *sa = (const struct sockaddr *)addr; | 640 | const struct IPv4UdpAddress *t4; |
646 | 641 | ||
647 | if (addrlen < sizeof (struct sockaddr)) | 642 | GNUNET_assert(addrlen == sizeof(struct IPv4UdpAddress)); |
648 | return; | 643 | t4 = (struct IPv4UdpAddress *)addr; |
649 | switch (sa->sa_family) | 644 | |
645 | if (NULL == inet_ntop (AF_INET, | ||
646 | &t4->u_port, | ||
647 | addr_buf, INET_ADDRSTRLEN)) | ||
650 | { | 648 | { |
651 | case AF_INET: | 649 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); |
652 | if (addrlen != sizeof (struct sockaddr_in)) | ||
653 | return; | ||
654 | if (NULL == inet_ntop (AF_INET, | ||
655 | &((struct sockaddr_in *) sa)->sin_addr, | ||
656 | inet4, INET_ADDRSTRLEN)) | ||
657 | { | ||
658 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); | ||
659 | return; | ||
660 | } | ||
661 | address_as_string = GNUNET_strdup (inet4); | ||
662 | break; | ||
663 | case AF_INET6: | ||
664 | default: | ||
665 | return; | 650 | return; |
666 | } | 651 | } |
667 | 652 | address_as_string = GNUNET_strdup (addr_buf); | |
668 | GNUNET_asprintf(&port_as_string, "%d", plugin->port); | 653 | GNUNET_asprintf(&port_as_string, "%d", plugin->port); |
669 | #if DEBUG_UDP_NAT | 654 | #if DEBUG_UDP |
670 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", | 655 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", |
671 | _("Running gnunet-nat-client with arguments: %s %s %d\n"), plugin->external_address, address_as_string, plugin->port); | 656 | _("Running gnunet-nat-client with arguments: %s %s %d\n"), plugin->external_address, address_as_string, plugin->port); |
672 | #endif | 657 | #endif |
@@ -723,21 +708,18 @@ udp_plugin_send (void *cls, | |||
723 | const struct IPv4UdpAddress *t4; | 708 | const struct IPv4UdpAddress *t4; |
724 | 709 | ||
725 | GNUNET_assert (NULL == session); | 710 | GNUNET_assert (NULL == session); |
726 | other_peer_natd = GNUNET_NO; | ||
727 | 711 | ||
712 | other_peer_natd = GNUNET_NO; | ||
728 | if (addrlen == sizeof(struct IPv4UdpAddress)) | 713 | if (addrlen == sizeof(struct IPv4UdpAddress)) |
729 | { | 714 | { |
730 | t4 = addr; | 715 | t4 = addr; |
731 | if (ntohs(t4->u_port) == 0) | 716 | if (ntohs(t4->u_port) == 0) |
732 | other_peer_natd = GNUNET_YES; | 717 | other_peer_natd = GNUNET_YES; |
733 | } | 718 | } |
734 | else if (addrlen == sizeof(struct IPv6UdpAddress)) | 719 | else if (addrlen != sizeof(struct IPv6UdpAddress)) |
735 | { | ||
736 | |||
737 | } | ||
738 | else | ||
739 | { | 720 | { |
740 | GNUNET_break_op(0); | 721 | GNUNET_break_op(0); |
722 | return -1; /* Must have an address to send to */ | ||
741 | } | 723 | } |
742 | 724 | ||
743 | sent = 0; | 725 | sent = 0; |
@@ -771,7 +753,7 @@ udp_plugin_send (void *cls, | |||
771 | peer_session->messages->timeout = GNUNET_TIME_relative_to_absolute(timeout); | 753 | peer_session->messages->timeout = GNUNET_TIME_relative_to_absolute(timeout); |
772 | peer_session->messages->cont = cont; | 754 | peer_session->messages->cont = cont; |
773 | peer_session->messages->cont_cls = cont_cls; | 755 | peer_session->messages->cont_cls = cont_cls; |
774 | #if DEBUG_UDP_NAT | 756 | #if DEBUG_UDP |
775 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", | 757 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", |
776 | _("Other peer is NAT'd, set up peer session for peer %s\n"), GNUNET_i2s(target)); | 758 | _("Other peer is NAT'd, set up peer session for peer %s\n"), GNUNET_i2s(target)); |
777 | #endif | 759 | #endif |
@@ -958,14 +940,12 @@ send_udp_probe_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
958 | message->header.size = htons(sizeof(struct UDP_NAT_ProbeMessage)); | 940 | message->header.size = htons(sizeof(struct UDP_NAT_ProbeMessage)); |
959 | message->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE); | 941 | message->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE); |
960 | /* If they gave us a port, use that. If not, try our port. */ | 942 | /* If they gave us a port, use that. If not, try our port. */ |
961 | if (probe->port != 0) | 943 | if (ntohs(probe->addr.u_port) == 0) |
962 | probe->sock_addr.sin_port = htons(probe->port); | 944 | probe->addr.u_port = htons(plugin->port); |
963 | else | ||
964 | probe->sock_addr.sin_port = htons(plugin->port); | ||
965 | 945 | ||
966 | #if DEBUG_UDP_NAT | 946 | #if DEBUG_UDP |
967 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", | 947 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", |
968 | _("Sending a probe to port %d\n"), ntohs(probe->sock_addr.sin_port)); | 948 | _("Sending a probe to port %d\n"), ntohs(probe->addr.u_port)); |
969 | #endif | 949 | #endif |
970 | 950 | ||
971 | probe->count++; | 951 | probe->count++; |
@@ -973,7 +953,7 @@ send_udp_probe_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
973 | udp_real_send(plugin, udp_sock.desc, NULL, | 953 | udp_real_send(plugin, udp_sock.desc, NULL, |
974 | (char *)message, ntohs(message->header.size), 0, | 954 | (char *)message, ntohs(message->header.size), 0, |
975 | GNUNET_TIME_relative_get_unit(), | 955 | GNUNET_TIME_relative_get_unit(), |
976 | &probe->sock_addr, sizeof(probe->sock_addr), | 956 | &probe->addr, sizeof(probe->addr), |
977 | &udp_probe_continuation, probe); | 957 | &udp_probe_continuation, probe); |
978 | 958 | ||
979 | GNUNET_free(message); | 959 | GNUNET_free(message); |
@@ -993,7 +973,7 @@ udp_probe_continuation (void *cls, const struct GNUNET_PeerIdentity *target, int | |||
993 | 973 | ||
994 | if ((result == GNUNET_OK) && (probe->count < MAX_PROBES)) | 974 | if ((result == GNUNET_OK) && (probe->count < MAX_PROBES)) |
995 | { | 975 | { |
996 | #if DEBUG_UDP_NAT | 976 | #if DEBUG_UDP |
997 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", | 977 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", |
998 | _("Scheduling next probe for 10000 milliseconds\n")); | 978 | _("Scheduling next probe for 10000 milliseconds\n")); |
999 | #endif | 979 | #endif |
@@ -1001,7 +981,7 @@ udp_probe_continuation (void *cls, const struct GNUNET_PeerIdentity *target, int | |||
1001 | } | 981 | } |
1002 | else /* Destroy the probe context. */ | 982 | else /* Destroy the probe context. */ |
1003 | { | 983 | { |
1004 | #if DEBUG_UDP_NAT | 984 | #if DEBUG_UDP |
1005 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", | 985 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", |
1006 | _("Sending probe didn't go well...\n")); | 986 | _("Sending probe didn't go well...\n")); |
1007 | #endif | 987 | #endif |
@@ -1048,7 +1028,7 @@ udp_plugin_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
1048 | struct UDP_NAT_Probes *temp_probe; | 1028 | struct UDP_NAT_Probes *temp_probe; |
1049 | int port; | 1029 | int port; |
1050 | char *port_start; | 1030 | char *port_start; |
1051 | struct sockaddr_in in_addr; | 1031 | struct IPv4UdpAddress a4; |
1052 | 1032 | ||
1053 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) | 1033 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
1054 | return; | 1034 | return; |
@@ -1057,7 +1037,7 @@ udp_plugin_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
1057 | 1037 | ||
1058 | if (bytes < 1) | 1038 | if (bytes < 1) |
1059 | { | 1039 | { |
1060 | #if DEBUG_UDP_NAT | 1040 | #if DEBUG_UDP |
1061 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", | 1041 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", |
1062 | _("Finished reading from server stdout with code: %d\n"), bytes); | 1042 | _("Finished reading from server stdout with code: %d\n"), bytes); |
1063 | #endif | 1043 | #endif |
@@ -1089,7 +1069,7 @@ udp_plugin_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
1089 | return; | 1069 | return; |
1090 | } | 1070 | } |
1091 | 1071 | ||
1092 | #if DEBUG_UDP_NAT | 1072 | #if DEBUG_UDP |
1093 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", | 1073 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", |
1094 | _("nat-server-read read: %s port %d\n"), &mybuf, port); | 1074 | _("nat-server-read read: %s port %d\n"), &mybuf, port); |
1095 | #endif | 1075 | #endif |
@@ -1098,7 +1078,7 @@ udp_plugin_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
1098 | * We have received an ICMP response, ostensibly from a non-NAT'd peer | 1078 | * We have received an ICMP response, ostensibly from a non-NAT'd peer |
1099 | * that wants to connect to us! Send a message to establish a connection. | 1079 | * that wants to connect to us! Send a message to establish a connection. |
1100 | */ | 1080 | */ |
1101 | if (inet_pton(AF_INET, &mybuf[0], &in_addr.sin_addr) != 1) | 1081 | if (inet_pton(AF_INET, &mybuf[0], &a4.ipv4_addr) != 1) |
1102 | { | 1082 | { |
1103 | 1083 | ||
1104 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "udp", | 1084 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "udp", |
@@ -1117,9 +1097,8 @@ udp_plugin_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
1117 | { | 1097 | { |
1118 | temp_probe = GNUNET_malloc(sizeof(struct UDP_NAT_Probes)); | 1098 | temp_probe = GNUNET_malloc(sizeof(struct UDP_NAT_Probes)); |
1119 | temp_probe->address_string = strdup(&mybuf[0]); | 1099 | temp_probe->address_string = strdup(&mybuf[0]); |
1120 | temp_probe->sock_addr.sin_family = AF_INET; | 1100 | GNUNET_assert (1 == inet_pton(AF_INET, &mybuf[0], &temp_probe->addr.ipv4_addr)); |
1121 | GNUNET_assert(inet_pton(AF_INET, &mybuf[0], &temp_probe->sock_addr.sin_addr) == 1); | 1101 | temp_probe->addr.u_port = htons(port); |
1122 | temp_probe->port = port; | ||
1123 | temp_probe->next = plugin->probes; | 1102 | temp_probe->next = plugin->probes; |
1124 | temp_probe->plugin = plugin; | 1103 | temp_probe->plugin = plugin; |
1125 | temp_probe->task = GNUNET_SCHEDULER_add_delayed(plugin->env->sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500), &send_udp_probe_message, temp_probe); | 1104 | temp_probe->task = GNUNET_SCHEDULER_add_delayed(plugin->env->sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500), &send_udp_probe_message, temp_probe); |
@@ -1158,16 +1137,28 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, | |||
1158 | struct PeerSession *peer_session; | 1137 | struct PeerSession *peer_session; |
1159 | struct MessageQueue *pending_message; | 1138 | struct MessageQueue *pending_message; |
1160 | struct MessageQueue *pending_message_temp; | 1139 | struct MessageQueue *pending_message_temp; |
1140 | uint16_t incoming_port; | ||
1161 | 1141 | ||
1162 | if (memcmp(sender, plugin->env->my_identity, sizeof(struct GNUNET_PeerIdentity)) == 0) | 1142 | if (memcmp(sender, plugin->env->my_identity, sizeof(struct GNUNET_PeerIdentity)) == 0) |
1163 | { | 1143 | { |
1164 | #if DEBUG_UDP_NAT | 1144 | #if DEBUG_UDP |
1165 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", | 1145 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", |
1166 | _("Received a message from myself, dropping!!!\n")); | 1146 | _("Received a message from myself, dropping!!!\n")); |
1167 | #endif | 1147 | #endif |
1168 | return; | 1148 | return; |
1169 | } | 1149 | } |
1170 | 1150 | ||
1151 | incoming_port = 0; | ||
1152 | GNUNET_assert(sender_addr != NULL); /* Can recvfrom have a NULL address? */ | ||
1153 | if (fromlen == sizeof(struct IPv4UdpAddress)) | ||
1154 | { | ||
1155 | incoming_port = ntohs(((struct IPv4UdpAddress *)sender_addr)->u_port); | ||
1156 | } | ||
1157 | else if (fromlen == sizeof(struct IPv6UdpAddress)) | ||
1158 | { | ||
1159 | incoming_port = ntohs(((struct IPv6UdpAddress *)sender_addr)->u6_port); | ||
1160 | } | ||
1161 | |||
1171 | switch (ntohs(currhdr->type)) | 1162 | switch (ntohs(currhdr->type)) |
1172 | { | 1163 | { |
1173 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE: | 1164 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE: |
@@ -1176,35 +1167,35 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, | |||
1176 | outgoing_probe_reply->header.size = htons(sizeof(struct UDP_NAT_ProbeMessageReply)); | 1167 | outgoing_probe_reply->header.size = htons(sizeof(struct UDP_NAT_ProbeMessageReply)); |
1177 | outgoing_probe_reply->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE_REPLY); | 1168 | outgoing_probe_reply->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE_REPLY); |
1178 | 1169 | ||
1179 | #if DEBUG_UDP_NAT | 1170 | #if DEBUG_UDP |
1180 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", | 1171 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", |
1181 | _("Received a probe on listen port %d, sent_from port %d\n"), sockinfo->port, ntohs(((struct sockaddr_in *)sender_addr)->sin_port)); | 1172 | _("Received a probe on listen port %d, sent_from port %d\n"), sockinfo->port, incoming_port); |
1182 | #endif | 1173 | #endif |
1183 | 1174 | ||
1184 | udp_real_send(plugin, sockinfo->desc, NULL, | 1175 | udp_real_send(plugin, sockinfo->desc, NULL, |
1185 | (char *)outgoing_probe_reply, | 1176 | (char *)outgoing_probe_reply, |
1186 | ntohs(outgoing_probe_reply->header.size), 0, | 1177 | ntohs(outgoing_probe_reply->header.size), 0, |
1187 | GNUNET_TIME_relative_get_unit(), | 1178 | GNUNET_TIME_relative_get_unit(), |
1188 | sender_addr, fromlen, | 1179 | sender_addr, fromlen, |
1189 | NULL, NULL); | 1180 | NULL, NULL); |
1190 | 1181 | ||
1191 | #if DEBUG_UDP_NAT | 1182 | #if DEBUG_UDP |
1192 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", | 1183 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", |
1193 | _("Sent PROBE REPLY to port %d on outgoing port %d\n"), ntohs(((struct sockaddr_in *)sender_addr)->sin_port), sockinfo->port); | 1184 | _("Sent PROBE REPLY to port %d on outgoing port %d\n"), incoming_port, sockinfo->port); |
1194 | #endif | 1185 | #endif |
1195 | GNUNET_free(outgoing_probe_reply); | 1186 | GNUNET_free(outgoing_probe_reply); |
1196 | break; | 1187 | break; |
1197 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE_REPLY: | 1188 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE_REPLY: |
1198 | /* Check for existing probe, check ports returned, send confirmation if all is well */ | 1189 | /* Check for existing probe, check ports returned, send confirmation if all is well */ |
1199 | #if DEBUG_UDP_NAT | 1190 | #if DEBUG_UDP |
1200 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", | 1191 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", |
1201 | _("Received PROBE REPLY from port %d on incoming port %d\n"), ntohs(((struct sockaddr_in *)sender_addr)->sin_port), sockinfo->port); | 1192 | _("Received PROBE REPLY from port %d on incoming port %d\n"), incoming_port, sockinfo->port); |
1202 | #endif | 1193 | #endif |
1203 | if ((sender_addr != NULL) && (sizeof(sender_addr) == sizeof(struct IPv4UdpAddress))) | 1194 | if (sizeof(sender_addr) == sizeof(struct IPv4UdpAddress)) |
1204 | { | 1195 | { |
1205 | memset(&addr_buf, 0, sizeof(addr_buf)); | 1196 | memset(&addr_buf, 0, sizeof(addr_buf)); |
1206 | if (NULL == inet_ntop (AF_INET, | 1197 | if (NULL == inet_ntop (AF_INET, |
1207 | &((struct sockaddr_in *) sender_addr)->sin_addr, addr_buf, | 1198 | &((struct IPv4UdpAddress *) sender_addr)->ipv4_addr, addr_buf, |
1208 | INET_ADDRSTRLEN)) | 1199 | INET_ADDRSTRLEN)) |
1209 | { | 1200 | { |
1210 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); | 1201 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); |
@@ -1213,7 +1204,7 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, | |||
1213 | outgoing_probe = find_probe(plugin, &addr_buf[0]); | 1204 | outgoing_probe = find_probe(plugin, &addr_buf[0]); |
1214 | if (outgoing_probe != NULL) | 1205 | if (outgoing_probe != NULL) |
1215 | { | 1206 | { |
1216 | #if DEBUG_UDP_NAT | 1207 | #if DEBUG_UDP |
1217 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", | 1208 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", |
1218 | _("Sending confirmation that we were reached!\n")); | 1209 | _("Sending confirmation that we were reached!\n")); |
1219 | #endif | 1210 | #endif |
@@ -1233,7 +1224,7 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, | |||
1233 | } | 1224 | } |
1234 | else | 1225 | else |
1235 | { | 1226 | { |
1236 | #if DEBUG_UDP_NAT | 1227 | #if DEBUG_UDP |
1237 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", | 1228 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", |
1238 | _("Received a probe reply, but have no record of a sent probe!\n")); | 1229 | _("Received a probe reply, but have no record of a sent probe!\n")); |
1239 | #endif | 1230 | #endif |
@@ -1242,13 +1233,13 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, | |||
1242 | break; | 1233 | break; |
1243 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE_CONFIRM: | 1234 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE_CONFIRM: |
1244 | peer_session = find_session(plugin, sender); | 1235 | peer_session = find_session(plugin, sender); |
1245 | #if DEBUG_UDP_NAT | 1236 | #if DEBUG_UDP |
1246 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", | 1237 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", |
1247 | _("Looking up peer session for peer %s\n"), GNUNET_i2s(sender)); | 1238 | _("Looking up peer session for peer %s\n"), GNUNET_i2s(sender)); |
1248 | #endif | 1239 | #endif |
1249 | if (peer_session == NULL) /* Shouldn't this NOT happen? */ | 1240 | if (peer_session == NULL) /* Shouldn't this NOT happen? */ |
1250 | { | 1241 | { |
1251 | #if DEBUG_UDP_NAT | 1242 | #if DEBUG_UDP |
1252 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", | 1243 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", |
1253 | _("Peer not in list, adding (THIS MAY BE A MISTAKE) %s\n"), GNUNET_i2s(sender)); | 1244 | _("Peer not in list, adding (THIS MAY BE A MISTAKE) %s\n"), GNUNET_i2s(sender)); |
1254 | #endif | 1245 | #endif |
@@ -1270,14 +1261,22 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, | |||
1270 | { | 1261 | { |
1271 | peer_session->expecting_welcome = GNUNET_NO; | 1262 | peer_session->expecting_welcome = GNUNET_NO; |
1272 | peer_session->sock = sockinfo->desc; | 1263 | peer_session->sock = sockinfo->desc; |
1273 | ((struct sockaddr_in *)peer_session->connect_addr)->sin_port = ((struct sockaddr_in *) sender_addr)->sin_port; | 1264 | if (peer_session->connect_alen == sizeof(struct IPv4UdpAddress)) |
1274 | #if DEBUG_UDP_NAT | 1265 | { |
1266 | ((struct IPv4UdpAddress *)peer_session->connect_addr)->u_port = htons(incoming_port); | ||
1267 | } | ||
1268 | else if (peer_session->connect_alen == sizeof(struct IPv4UdpAddress)) | ||
1269 | { | ||
1270 | ((struct IPv6UdpAddress *)peer_session->connect_addr)->u6_port = htons(incoming_port); | ||
1271 | } | ||
1272 | |||
1273 | #if DEBUG_UDP | ||
1275 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", | 1274 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", |
1276 | _("Received a probe confirmation, will send to peer on port %d\n"), ntohs(((struct sockaddr_in *)peer_session->connect_addr)->sin_port)); | 1275 | _("Received a probe confirmation, will send to peer on port %d\n"), incoming_port); |
1277 | #endif | 1276 | #endif |
1278 | if (peer_session->messages != NULL) | 1277 | if (peer_session->messages != NULL) |
1279 | { | 1278 | { |
1280 | #if DEBUG_UDP_NAT | 1279 | #if DEBUG_UDP |
1281 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", | 1280 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", |
1282 | _("Received a probe confirmation, sending queued messages.\n")); | 1281 | _("Received a probe confirmation, sending queued messages.\n")); |
1283 | #endif | 1282 | #endif |
@@ -1285,16 +1284,26 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, | |||
1285 | int count = 0; | 1284 | int count = 0; |
1286 | while (pending_message != NULL) | 1285 | while (pending_message != NULL) |
1287 | { | 1286 | { |
1288 | #if DEBUG_UDP_NAT | 1287 | #if DEBUG_UDP |
1289 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", | 1288 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", |
1290 | _("sending queued message %d\n"), count); | 1289 | _("sending queued message %d\n"), count); |
1291 | #endif | 1290 | #endif |
1292 | udp_real_send(plugin, peer_session->sock, &peer_session->target, pending_message->msgbuf, pending_message->msgbuf_size, 0, GNUNET_TIME_relative_get_unit(), peer_session->connect_addr, peer_session->connect_alen, pending_message->cont, pending_message->cont_cls); | 1291 | udp_real_send(plugin, |
1292 | peer_session->sock, | ||
1293 | &peer_session->target, | ||
1294 | pending_message->msgbuf, | ||
1295 | pending_message->msgbuf_size, 0, | ||
1296 | GNUNET_TIME_relative_get_unit(), | ||
1297 | peer_session->connect_addr, | ||
1298 | peer_session->connect_alen, | ||
1299 | pending_message->cont, | ||
1300 | pending_message->cont_cls); | ||
1301 | |||
1293 | pending_message_temp = pending_message; | 1302 | pending_message_temp = pending_message; |
1294 | pending_message = pending_message->next; | 1303 | pending_message = pending_message->next; |
1295 | GNUNET_free(pending_message_temp->msgbuf); | 1304 | GNUNET_free(pending_message_temp->msgbuf); |
1296 | GNUNET_free(pending_message_temp); | 1305 | GNUNET_free(pending_message_temp); |
1297 | #if DEBUG_UDP_NAT | 1306 | #if DEBUG_UDP |
1298 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", | 1307 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", |
1299 | _("finished sending queued message %d\n"), count); | 1308 | _("finished sending queued message %d\n"), count); |
1300 | #endif | 1309 | #endif |
@@ -1305,7 +1314,7 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, | |||
1305 | } | 1314 | } |
1306 | else | 1315 | else |
1307 | { | 1316 | { |
1308 | #if DEBUG_UDP_NAT | 1317 | #if DEBUG_UDP |
1309 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", | 1318 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", |
1310 | _("Received probe confirmation for already confirmed peer!\n")); | 1319 | _("Received probe confirmation for already confirmed peer!\n")); |
1311 | #endif | 1320 | #endif |
@@ -1317,6 +1326,10 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, | |||
1317 | /* If we receive these just ignore! */ | 1326 | /* If we receive these just ignore! */ |
1318 | break; | 1327 | break; |
1319 | default: | 1328 | default: |
1329 | #if DEBUG_UDP | ||
1330 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1331 | _("Sending message type %d to transport\n!"), ntohs(currhdr->type)); | ||
1332 | #endif | ||
1320 | plugin->env->receive (plugin->env->cls, sender, currhdr, UDP_DIRECT_DISTANCE, | 1333 | plugin->env->receive (plugin->env->cls, sender, currhdr, UDP_DIRECT_DISTANCE, |
1321 | NULL, sender_addr, fromlen); | 1334 | NULL, sender_addr, fromlen); |
1322 | } | 1335 | } |
@@ -1377,7 +1390,7 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1377 | GNUNET_NETWORK_socket_recvfrom (udp_sock.desc, buf, buflen, | 1390 | GNUNET_NETWORK_socket_recvfrom (udp_sock.desc, buf, buflen, |
1378 | (struct sockaddr *)&addr, &fromlen); | 1391 | (struct sockaddr *)&addr, &fromlen); |
1379 | 1392 | ||
1380 | if (fromlen == sizeof (struct sockaddr_in)) | 1393 | if (AF_INET == ((struct sockaddr *)addr)->sa_family) |
1381 | { | 1394 | { |
1382 | s4 = (const struct sockaddr_in*) &addr; | 1395 | s4 = (const struct sockaddr_in*) &addr; |
1383 | t4.u_port = s4->sin_port; | 1396 | t4.u_port = s4->sin_port; |
@@ -1385,7 +1398,7 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1385 | ca = &t4; | 1398 | ca = &t4; |
1386 | calen = sizeof (t4); | 1399 | calen = sizeof (t4); |
1387 | } | 1400 | } |
1388 | else if (fromlen == sizeof (struct sockaddr_in6)) | 1401 | else if (AF_INET6 == ((struct sockaddr *)addr)->sa_family) |
1389 | { | 1402 | { |
1390 | s6 = (const struct sockaddr_in6*) &addr; | 1403 | s6 = (const struct sockaddr_in6*) &addr; |
1391 | t6.u6_port = s6->sin6_port; | 1404 | t6.u6_port = s6->sin6_port; |
@@ -1402,12 +1415,6 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1402 | calen = 0; | 1415 | calen = 0; |
1403 | } | 1416 | } |
1404 | 1417 | ||
1405 | #if DEBUG_UDP_NAT | ||
1406 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ | ||
1407 | ("socket_recv returned %u, src_addr_len is %u\n"), ret, | ||
1408 | fromlen); | ||
1409 | #endif | ||
1410 | |||
1411 | if (ret <= 0) | 1418 | if (ret <= 0) |
1412 | { | 1419 | { |
1413 | GNUNET_free (buf); | 1420 | GNUNET_free (buf); |
@@ -1415,11 +1422,6 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1415 | } | 1422 | } |
1416 | msg = (struct UDPMessage *) buf; | 1423 | msg = (struct UDPMessage *) buf; |
1417 | 1424 | ||
1418 | #if DEBUG_UDP_NAT | ||
1419 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ | ||
1420 | ("header reports message size of %d, type %d\n"), | ||
1421 | ntohs (msg->header.size), ntohs (msg->header.type)); | ||
1422 | #endif | ||
1423 | if (ntohs (msg->header.size) < sizeof (struct UDPMessage)) | 1425 | if (ntohs (msg->header.size) < sizeof (struct UDPMessage)) |
1424 | { | 1426 | { |
1425 | GNUNET_free (buf); | 1427 | GNUNET_free (buf); |
@@ -1437,17 +1439,7 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1437 | while (offset < tsize) | 1439 | while (offset < tsize) |
1438 | { | 1440 | { |
1439 | currhdr = (struct GNUNET_MessageHeader *)&msgbuf[offset]; | 1441 | currhdr = (struct GNUNET_MessageHeader *)&msgbuf[offset]; |
1440 | #if DEBUG_UDP_NAT | ||
1441 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ | ||
1442 | ("processing msg %d: type %d, size %d at offset %d\n"), | ||
1443 | count, ntohs(currhdr->type), ntohs(currhdr->size), offset); | ||
1444 | #endif | ||
1445 | udp_demultiplexer(plugin, sender, currhdr, ca, calen, &udp_sock); | 1442 | udp_demultiplexer(plugin, sender, currhdr, ca, calen, &udp_sock); |
1446 | #if DEBUG_UDP_NAT | ||
1447 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ | ||
1448 | ("processing done msg %d: type %d, size %d at offset %d\n"), | ||
1449 | count, ntohs(currhdr->type), ntohs(currhdr->size), offset); | ||
1450 | #endif | ||
1451 | offset += ntohs(currhdr->size); | 1443 | offset += ntohs(currhdr->size); |
1452 | count++; | 1444 | count++; |
1453 | } | 1445 | } |
@@ -1490,7 +1482,7 @@ udp_transport_server_start (void *cls) | |||
1490 | plugin->server_stdout = GNUNET_DISK_pipe(GNUNET_YES); | 1482 | plugin->server_stdout = GNUNET_DISK_pipe(GNUNET_YES); |
1491 | if (plugin->server_stdout == NULL) | 1483 | if (plugin->server_stdout == NULL) |
1492 | return sockets_created; | 1484 | return sockets_created; |
1493 | #if DEBUG_UDP_NAT | 1485 | #if DEBUG_UDP |
1494 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1486 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1495 | "udp", | 1487 | "udp", |
1496 | "Starting gnunet-nat-server process cmd: %s %s\n", "gnunet-nat-server", plugin->internal_address); | 1488 | "Starting gnunet-nat-server process cmd: %s %s\n", "gnunet-nat-server", plugin->internal_address); |
@@ -1499,7 +1491,7 @@ udp_transport_server_start (void *cls) | |||
1499 | plugin->server_pid = GNUNET_OS_start_process(NULL, plugin->server_stdout, "gnunet-nat-server", "gnunet-nat-server", plugin->internal_address, NULL); | 1491 | plugin->server_pid = GNUNET_OS_start_process(NULL, plugin->server_stdout, "gnunet-nat-server", "gnunet-nat-server", plugin->internal_address, NULL); |
1500 | if (plugin->server_pid == GNUNET_SYSERR) | 1492 | if (plugin->server_pid == GNUNET_SYSERR) |
1501 | { | 1493 | { |
1502 | #if DEBUG_UDP_NAT | 1494 | #if DEBUG_UDP |
1503 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1495 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1504 | "udp", | 1496 | "udp", |
1505 | "Failed to start gnunet-nat-server process\n"); | 1497 | "Failed to start gnunet-nat-server process\n"); |
@@ -1536,7 +1528,7 @@ udp_transport_server_start (void *cls) | |||
1536 | serverAddrv4.sin_port = htons (plugin->port); | 1528 | serverAddrv4.sin_port = htons (plugin->port); |
1537 | addrlen = sizeof (serverAddrv4); | 1529 | addrlen = sizeof (serverAddrv4); |
1538 | serverAddr = (struct sockaddr *) &serverAddrv4; | 1530 | serverAddr = (struct sockaddr *) &serverAddrv4; |
1539 | #if DEBUG_UDP_NAT | 1531 | #if DEBUG_UDP |
1540 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1532 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1541 | "udp", | 1533 | "udp", |
1542 | "Binding to port %d\n", ntohs(serverAddrv4.sin_port)); | 1534 | "Binding to port %d\n", ntohs(serverAddrv4.sin_port)); |
@@ -1545,7 +1537,7 @@ udp_transport_server_start (void *cls) | |||
1545 | GNUNET_OK) | 1537 | GNUNET_OK) |
1546 | { | 1538 | { |
1547 | serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ | 1539 | serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ |
1548 | #if DEBUG_UDP_NAT | 1540 | #if DEBUG_UDP |
1549 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1541 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1550 | "udp", | 1542 | "udp", |
1551 | "Binding failed, trying new port %d\n", ntohs(serverAddrv4.sin_port)); | 1543 | "Binding failed, trying new port %d\n", ntohs(serverAddrv4.sin_port)); |
@@ -1635,7 +1627,7 @@ udp_check_address (void *cls, void *addr, size_t addrlen) | |||
1635 | v6->sin6_port = htons (plugin->port); | 1627 | v6->sin6_port = htons (plugin->port); |
1636 | } | 1628 | } |
1637 | 1629 | ||
1638 | #if DEBUG_UDP_NAT | 1630 | #if DEBUG_UDP |
1639 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1631 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1640 | "udp", | 1632 | "udp", |
1641 | "Informing transport service about my address `%s'.\n", | 1633 | "Informing transport service about my address `%s'.\n", |