diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-08-17 16:35:47 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-08-17 16:35:47 +0000 |
commit | 84ac615276e428c6d941aa83dbd99f63d8b08865 (patch) | |
tree | 67379948b7b53476df51104012aefb81338fc996 /src/transport/plugin_transport_tcp.c | |
parent | ec734f16ea5d9f1c35ecd05508541e0bbe0c36a3 (diff) | |
download | gnunet-84ac615276e428c6d941aa83dbd99f63d8b08865.tar.gz gnunet-84ac615276e428c6d941aa83dbd99f63d8b08865.zip |
fixing tcp nat implementation, WINDOWS SUPPORT NOTWITHSTANDING
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 5e9e2b80c..a872ecd3b 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -935,6 +935,7 @@ run_gnunet_nat_client (struct Plugin *plugin, const char *addr, size_t addrlen) | |||
935 | char *port_as_string; | 935 | char *port_as_string; |
936 | pid_t pid; | 936 | pid_t pid; |
937 | const struct sockaddr *sa = (const struct sockaddr *)addr; | 937 | const struct sockaddr *sa = (const struct sockaddr *)addr; |
938 | |||
938 | #if DEBUG_TCP_NAT | 939 | #if DEBUG_TCP_NAT |
939 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 940 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
940 | _("called run_gnunet_nat_client addrlen %d others are %d and %d\n"), addrlen, sizeof (struct sockaddr), sizeof (struct sockaddr_in)); | 941 | _("called run_gnunet_nat_client addrlen %d others are %d and %d\n"), addrlen, sizeof (struct sockaddr), sizeof (struct sockaddr_in)); |
@@ -1187,7 +1188,7 @@ tcp_plugin_send (void *cls, | |||
1187 | GNUNET_i2s (target), | 1188 | GNUNET_i2s (target), |
1188 | GNUNET_a2s (sb, sbs)); | 1189 | GNUNET_a2s (sb, sbs)); |
1189 | #endif | 1190 | #endif |
1190 | run_gnunet_nat_client(plugin, sb, sbs); | 1191 | run_gnunet_nat_client (plugin, sb, sbs); |
1191 | return 0; | 1192 | return 0; |
1192 | } | 1193 | } |
1193 | else if ((plugin->allow_nat == GNUNET_YES) && (is_natd == GNUNET_YES) && (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(plugin->nat_wait_conns, &target->hashPubKey))) | 1194 | else if ((plugin->allow_nat == GNUNET_YES) && (is_natd == GNUNET_YES) && (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(plugin->nat_wait_conns, &target->hashPubKey))) |
@@ -1541,7 +1542,7 @@ handle_tcp_nat_probe (void *cls, | |||
1541 | struct IPv6TcpAddress *t6; | 1542 | struct IPv6TcpAddress *t6; |
1542 | const struct sockaddr_in *s4; | 1543 | const struct sockaddr_in *s4; |
1543 | const struct sockaddr_in6 *s6; | 1544 | const struct sockaddr_in6 *s6; |
1544 | 1545 | static struct GNUNET_MessageHeader fake_pong; | |
1545 | #if DEBUG_TCP_NAT | 1546 | #if DEBUG_TCP_NAT |
1546 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "received tcp NAT probe\n"); | 1547 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "received tcp NAT probe\n"); |
1547 | #endif | 1548 | #endif |
@@ -1572,7 +1573,12 @@ handle_tcp_nat_probe (void *cls, | |||
1572 | GNUNET_SERVER_client_keep (client); | 1573 | GNUNET_SERVER_client_keep (client); |
1573 | session->client = client; | 1574 | session->client = client; |
1574 | session->last_activity = GNUNET_TIME_absolute_get (); | 1575 | session->last_activity = GNUNET_TIME_absolute_get (); |
1575 | 1576 | /* FIXME: Should this be inbound or outbound? | |
1577 | * I think it should be outbound because we technically | ||
1578 | * initiated it... But something goes wrong somewhere. */ | ||
1579 | /* session->inbound = GNUNET_YES; */ | ||
1580 | //session->inbound = GNUNET_YES; | ||
1581 | //session->expecting_welcome = GNUNET_NO; | ||
1576 | if (GNUNET_OK == | 1582 | if (GNUNET_OK == |
1577 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) | 1583 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) |
1578 | { | 1584 | { |
@@ -1611,7 +1617,12 @@ handle_tcp_nat_probe (void *cls, | |||
1611 | } | 1617 | } |
1612 | GNUNET_free (vaddr); | 1618 | GNUNET_free (vaddr); |
1613 | } | 1619 | } |
1614 | 1620 | fake_pong.size = sizeof(struct GNUNET_MessageHeader); | |
1621 | fake_pong.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PONG); | ||
1622 | plugin->env->receive(session->plugin->env->cls, &session->target, &fake_pong, 1, session, session->connect_addr, session->connect_alen); | ||
1623 | #if DEBUG_TCP_NAT | ||
1624 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Giving fake pong to transport service so hopefully it will schedule validation of THIS address!\n"); | ||
1625 | #endif | ||
1615 | session->next = plugin->sessions; | 1626 | session->next = plugin->sessions; |
1616 | plugin->sessions = session; | 1627 | plugin->sessions = session; |
1617 | GNUNET_STATISTICS_update (plugin->env->stats, | 1628 | GNUNET_STATISTICS_update (plugin->env->stats, |
@@ -1626,6 +1637,8 @@ handle_tcp_nat_probe (void *cls, | |||
1626 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Did NOT find session for NAT probe!\n"); | 1637 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Did NOT find session for NAT probe!\n"); |
1627 | #endif | 1638 | #endif |
1628 | } | 1639 | } |
1640 | |||
1641 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
1629 | } | 1642 | } |
1630 | 1643 | ||
1631 | /** | 1644 | /** |
@@ -1651,7 +1664,6 @@ handle_tcp_welcome (void *cls, | |||
1651 | const struct sockaddr_in *s4; | 1664 | const struct sockaddr_in *s4; |
1652 | const struct sockaddr_in6 *s6; | 1665 | const struct sockaddr_in6 *s6; |
1653 | 1666 | ||
1654 | |||
1655 | #if DEBUG_TCP | 1667 | #if DEBUG_TCP |
1656 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1668 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1657 | "Received %s message from a `%4s/%p'.\n", | 1669 | "Received %s message from a `%4s/%p'.\n", |
@@ -2088,6 +2100,8 @@ tcp_plugin_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
2088 | */ | 2100 | */ |
2089 | sock = GNUNET_CONNECTION_create_from_sockaddr (plugin->env->sched, AF_INET, (struct sockaddr *)&in_addr, | 2101 | sock = GNUNET_CONNECTION_create_from_sockaddr (plugin->env->sched, AF_INET, (struct sockaddr *)&in_addr, |
2090 | sizeof(in_addr)); | 2102 | sizeof(in_addr)); |
2103 | |||
2104 | |||
2091 | if (sock == NULL) | 2105 | if (sock == NULL) |
2092 | { | 2106 | { |
2093 | plugin->server_read_task = | 2107 | plugin->server_read_task = |
@@ -2098,10 +2112,10 @@ tcp_plugin_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
2098 | } | 2112 | } |
2099 | else | 2113 | else |
2100 | { | 2114 | { |
2101 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2102 | _("Sending TCP probe message!\n"), &mybuf, port); | 2116 | _("Sending TCP probe message!\n"), &mybuf, port); |
2103 | tcp_probe_ctx = GNUNET_malloc(sizeof(struct TCPProbeContext)); | ||
2104 | 2117 | ||
2118 | tcp_probe_ctx = GNUNET_malloc(sizeof(struct TCPProbeContext)); | ||
2105 | tcp_probe_ctx->message.header.size = htons(sizeof(struct TCP_NAT_ProbeMessage)); | 2119 | tcp_probe_ctx->message.header.size = htons(sizeof(struct TCP_NAT_ProbeMessage)); |
2106 | tcp_probe_ctx->message.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE); | 2120 | tcp_probe_ctx->message.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE); |
2107 | memcpy(&tcp_probe_ctx->message.clientIdentity, plugin->env->my_identity, sizeof(struct GNUNET_PeerIdentity)); | 2121 | memcpy(&tcp_probe_ctx->message.clientIdentity, plugin->env->my_identity, sizeof(struct GNUNET_PeerIdentity)); |
@@ -2114,6 +2128,7 @@ tcp_plugin_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
2114 | 2128 | ||
2115 | } | 2129 | } |
2116 | 2130 | ||
2131 | /*GNUNET_SERVER_connect_socket(plugin->server, sock);*/ | ||
2117 | plugin->server_read_task = | 2132 | plugin->server_read_task = |
2118 | GNUNET_SCHEDULER_add_read_file (plugin->env->sched, | 2133 | GNUNET_SCHEDULER_add_read_file (plugin->env->sched, |
2119 | GNUNET_TIME_UNIT_FOREVER_REL, | 2134 | GNUNET_TIME_UNIT_FOREVER_REL, |
@@ -2456,6 +2471,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2456 | { | 2471 | { |
2457 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Notifying transport of address %s:0\n", plugin->external_address); | 2472 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Notifying transport of address %s:0\n", plugin->external_address); |
2458 | t4.t_port = htons(0); | 2473 | t4.t_port = htons(0); |
2474 | add_to_address_list (plugin, &t4.ipv4_addr, sizeof (uint32_t)); | ||
2459 | plugin->env->notify_address (plugin->env->cls, | 2475 | plugin->env->notify_address (plugin->env->cls, |
2460 | "tcp", | 2476 | "tcp", |
2461 | &t4, sizeof(t4), GNUNET_TIME_UNIT_FOREVER_REL); | 2477 | &t4, sizeof(t4), GNUNET_TIME_UNIT_FOREVER_REL); |
@@ -2463,6 +2479,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2463 | else if ((plugin->external_address != NULL) && (inet_pton(AF_INET, plugin->external_address, &t4.ipv4_addr) == 1)) | 2479 | else if ((plugin->external_address != NULL) && (inet_pton(AF_INET, plugin->external_address, &t4.ipv4_addr) == 1)) |
2464 | { | 2480 | { |
2465 | t4.t_port = htons(plugin->adv_port); | 2481 | t4.t_port = htons(plugin->adv_port); |
2482 | add_to_address_list (plugin, &t4.ipv4_addr, sizeof (uint32_t)); | ||
2466 | plugin->env->notify_address (plugin->env->cls, | 2483 | plugin->env->notify_address (plugin->env->cls, |
2467 | "tcp", | 2484 | "tcp", |
2468 | &t4, sizeof(t4), GNUNET_TIME_UNIT_FOREVER_REL); | 2485 | &t4, sizeof(t4), GNUNET_TIME_UNIT_FOREVER_REL); |