aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-01-14 13:33:15 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-01-14 13:33:15 +0000
commit46c20b1b6925ce1879794a1f369809132629068b (patch)
treeb6f6115dce57e7c429d9c2a35096dfb9ec4caeb7 /src
parent4def9d37a92933d763f5882f1e25be1f5aad2ba9 (diff)
downloadgnunet-46c20b1b6925ce1879794a1f369809132629068b.tar.gz
gnunet-46c20b1b6925ce1879794a1f369809132629068b.zip
fix for creating session
Diffstat (limited to 'src')
-rw-r--r--src/transport/plugin_transport_tcp.c41
1 files changed, 26 insertions, 15 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index a2fbc7c8a..025dd4fa0 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -885,8 +885,10 @@ reschedule_session_timeout (struct Session *s)
885 * @return new session object 885 * @return new session object
886 */ 886 */
887static struct Session * 887static struct Session *
888create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, 888create_session (struct Plugin *plugin,
889 struct GNUNET_SERVER_Client *client, int is_nat) 889 const struct GNUNET_HELLO_Address *address,
890 struct GNUNET_SERVER_Client *client,
891 int is_nat)
890{ 892{
891 struct Session *session; 893 struct Session *session;
892 struct PendingMessage *pm; 894 struct PendingMessage *pm;
@@ -898,13 +900,14 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
898 GNUNET_assert(NULL == client); 900 GNUNET_assert(NULL == client);
899 901
900 LOG(GNUNET_ERROR_TYPE_DEBUG, "Creating new session for peer `%4s'\n", 902 LOG(GNUNET_ERROR_TYPE_DEBUG, "Creating new session for peer `%4s'\n",
901 GNUNET_i2s (target)); 903 GNUNET_i2s (&address->peer));
902 session = GNUNET_new (struct Session); 904 session = GNUNET_new (struct Session);
903 session->last_activity = GNUNET_TIME_absolute_get (); 905 session->last_activity = GNUNET_TIME_absolute_get ();
904 session->plugin = plugin; 906 session->plugin = plugin;
905 session->is_nat = is_nat; 907 session->is_nat = is_nat;
906 session->client = client; 908 session->client = client;
907 session->target = *target; 909 session->address = GNUNET_HELLO_address_copy (address);
910 session->target = address->peer;
908 session->expecting_welcome = GNUNET_YES; 911 session->expecting_welcome = GNUNET_YES;
909 session->ats_address_network_type = GNUNET_ATS_NET_UNSPECIFIED; 912 session->ats_address_network_type = GNUNET_ATS_NET_UNSPECIFIED;
910 pm = GNUNET_malloc (sizeof (struct PendingMessage) + 913 pm = GNUNET_malloc (sizeof (struct PendingMessage) +
@@ -1351,6 +1354,12 @@ tcp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
1351 tcp_address_to_string(NULL, address->address, address->address_length), 1354 tcp_address_to_string(NULL, address->address, address->address_length),
1352 GNUNET_i2s (&address->peer)); 1355 GNUNET_i2s (&address->peer));
1353 1356
1357 if (GNUNET_HELLO_address_check_option(address, GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1358 {
1359 GNUNET_break (0);
1360 return NULL;
1361 }
1362
1354 /* look for existing session */ 1363 /* look for existing session */
1355 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap, 1364 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap,
1356 &address->peer)) 1365 &address->peer))
@@ -1448,8 +1457,7 @@ tcp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
1448 { 1457 {
1449 LOG (GNUNET_ERROR_TYPE_DEBUG, 1458 LOG (GNUNET_ERROR_TYPE_DEBUG,
1450 "Found valid IPv4 NAT address (creating session)!\n"); 1459 "Found valid IPv4 NAT address (creating session)!\n");
1451 session = create_session (plugin, &address->peer, NULL, GNUNET_YES); 1460 session = create_session (plugin, address, NULL, GNUNET_YES);
1452 session->address = GNUNET_HELLO_address_copy (address);
1453 session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl ( 1461 session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl (
1454 ats.value); 1462 ats.value);
1455 GNUNET_break( 1463 GNUNET_break(
@@ -1457,8 +1465,8 @@ tcp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
1457 session->nat_connection_timeout = GNUNET_SCHEDULER_add_delayed (NAT_TIMEOUT, 1465 session->nat_connection_timeout = GNUNET_SCHEDULER_add_delayed (NAT_TIMEOUT,
1458 &nat_connect_timeout, session); 1466 &nat_connect_timeout, session);
1459 GNUNET_assert(session != NULL); 1467 GNUNET_assert(session != NULL);
1460 GNUNET_assert( 1468 GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (plugin->nat_wait_conns,
1461 GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (plugin->nat_wait_conns, &session->target, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1469 &session->target, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1462 1470
1463 LOG(GNUNET_ERROR_TYPE_DEBUG, 1471 LOG(GNUNET_ERROR_TYPE_DEBUG,
1464 "Created NAT WAIT connection to `%4s' at `%s'\n", 1472 "Created NAT WAIT connection to `%4s' at `%s'\n",
@@ -1494,7 +1502,7 @@ tcp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
1494 "Asked to transmit to `%4s', creating fresh session using address `%s'.\n", 1502 "Asked to transmit to `%4s', creating fresh session using address `%s'.\n",
1495 GNUNET_i2s (&address->peer), GNUNET_a2s (sb, sbs)); 1503 GNUNET_i2s (&address->peer), GNUNET_a2s (sb, sbs));
1496 1504
1497 session = create_session (plugin, &address->peer, 1505 session = create_session (plugin, address,
1498 GNUNET_SERVER_connect_socket (plugin->server, sa), GNUNET_NO); 1506 GNUNET_SERVER_connect_socket (plugin->server, sa), GNUNET_NO);
1499 session->address = GNUNET_HELLO_address_copy (address); 1507 session->address = GNUNET_HELLO_address_copy (address);
1500 session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl ( 1508 session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl (
@@ -1982,6 +1990,7 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client,
1982{ 1990{
1983 struct Plugin *plugin = cls; 1991 struct Plugin *plugin = cls;
1984 const struct WelcomeMessage *wm = (const struct WelcomeMessage *) message; 1992 const struct WelcomeMessage *wm = (const struct WelcomeMessage *) message;
1993 struct GNUNET_HELLO_Address *address;
1985 struct Session *session; 1994 struct Session *session;
1986 size_t alen; 1995 size_t alen;
1987 void *vaddr; 1996 void *vaddr;
@@ -2029,7 +2038,6 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client,
2029 if (plugin->cur_connections == plugin->max_connections) 2038 if (plugin->cur_connections == plugin->max_connections)
2030 GNUNET_SERVER_suspend (plugin->server); /* Maximum number of connections rechead */ 2039 GNUNET_SERVER_suspend (plugin->server); /* Maximum number of connections rechead */
2031 2040
2032 session = create_session (plugin, &wm->clientIdentity, client, GNUNET_NO);
2033 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) 2041 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
2034 { 2042 {
2035 if (alen == sizeof(struct sockaddr_in)) 2043 if (alen == sizeof(struct sockaddr_in))
@@ -2039,7 +2047,7 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client,
2039 t4.options = htonl (0); 2047 t4.options = htonl (0);
2040 t4.t4_port = s4->sin_port; 2048 t4.t4_port = s4->sin_port;
2041 t4.ipv4_addr = s4->sin_addr.s_addr; 2049 t4.ipv4_addr = s4->sin_addr.s_addr;
2042 session->address = GNUNET_HELLO_address_allocate (&wm->clientIdentity, 2050 address = GNUNET_HELLO_address_allocate (&wm->clientIdentity,
2043 PLUGIN_NAME, &t4, sizeof(struct IPv4TcpAddress), 2051 PLUGIN_NAME, &t4, sizeof(struct IPv4TcpAddress),
2044 GNUNET_HELLO_ADDRESS_INFO_INBOUND); 2052 GNUNET_HELLO_ADDRESS_INFO_INBOUND);
2045 } 2053 }
@@ -2050,16 +2058,19 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client,
2050 t6.options = htonl (0); 2058 t6.options = htonl (0);
2051 t6.t6_port = s6->sin6_port; 2059 t6.t6_port = s6->sin6_port;
2052 memcpy (&t6.ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); 2060 memcpy (&t6.ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr));
2053 session->address = GNUNET_HELLO_address_allocate (&wm->clientIdentity, 2061 address = GNUNET_HELLO_address_allocate (&wm->clientIdentity,
2054 PLUGIN_NAME, &t6, sizeof(struct IPv6TcpAddress), 2062 PLUGIN_NAME, &t6, sizeof(struct IPv6TcpAddress),
2055 GNUNET_HELLO_ADDRESS_INFO_INBOUND); 2063 GNUNET_HELLO_ADDRESS_INFO_INBOUND);
2056 } 2064 }
2057 2065 session = create_session (plugin, address, client, GNUNET_NO);
2066 GNUNET_HELLO_address_free (address);
2058 ats = plugin->env->get_address_type (plugin->env->cls, vaddr, alen); 2067 ats = plugin->env->get_address_type (plugin->env->cls, vaddr, alen);
2059 session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl ( 2068 session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl (
2060 ats.value); 2069 ats.value);
2061 LOG(GNUNET_ERROR_TYPE_DEBUG, "Creating new session %p for peer `%s'\n", 2070 LOG(GNUNET_ERROR_TYPE_DEBUG, "Creating new%s session %p for peer `%s'\n",
2062 session, GNUNET_a2s (vaddr, alen)); 2071 GNUNET_HELLO_address_check_option (session->address, GNUNET_HELLO_ADDRESS_INFO_INBOUND) ? " inbound" : "",
2072 session,
2073 tcp_address_to_string(NULL, (void *) session->address->address,session->address->address_length));
2063 GNUNET_free(vaddr); 2074 GNUNET_free(vaddr);
2064 GNUNET_SERVER_client_set_user_context(session->client, session); 2075 GNUNET_SERVER_client_set_user_context(session->client, session);
2065 GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, &session->target, 2076 GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, &session->target,