From 9c77c63d6b19db8f679eaf17c9760bcb1b8b06c1 Mon Sep 17 00:00:00 2001 From: "Nathan S. Evans" Date: Tue, 14 Sep 2010 15:28:08 +0000 Subject: [PATCH] don't ignore sessions marked as inbound when checking whether addresses match --- src/transport/gnunet-service-transport.c | 21 +++++++- src/transport/plugin_transport_tcp.c | 64 ++++++++++++++++++++---- 2 files changed, 74 insertions(+), 11 deletions(-) diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 1d0e0cc15..c117b06da 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -3288,7 +3288,9 @@ send_periodic_ping (void *cls, ping.challenge = htonl(va->challenge); memcpy(&ping.target, &neighbour->id, sizeof(struct GNUNET_PeerIdentity)); if (peer_address->validated != GNUNET_YES) - memcpy(message_buf, our_hello, hello_size); + { + memcpy(message_buf, our_hello, hello_size); + } if (peer_address->addr != NULL) { @@ -3325,7 +3327,12 @@ send_periodic_ping (void *cls, #endif if (peer_address->validated != GNUNET_YES) GNUNET_STATISTICS_update (stats, - gettext_noop ("# PING+HELLO messages sent"), + gettext_noop ("# PING with HELLO messages sent"), + 1, + GNUNET_NO); + else + GNUNET_STATISTICS_update (stats, + gettext_noop ("# PING without HELLO messages sent"), 1, GNUNET_NO); @@ -4209,6 +4216,16 @@ process_hello (struct TransportPlugin *plugin, GNUNET_HELLO_size(hello))); chvc = chvc->next; } + +#if BREAK_TESTS + struct NeighbourList *temp_neighbor = find_neighbour(&target); + if ((NULL != temp_neighbor)) + { + fprintf(stderr, "Already know peer, ignoring hello\n"); + return GNUNET_OK; + } +#endif + #if DEBUG_TRANSPORT_HELLO > 2 if (plugin != NULL) { diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 8c1d3d333..208a113f4 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -39,7 +39,7 @@ #define DEBUG_TCP GNUNET_NO #define DEBUG_TCP_NAT GNUNET_NO - +#define MULTIPLE_PEER_SESSIONS GNUNET_YES /** * How long until we give up on transmitting the welcome message? */ @@ -564,6 +564,25 @@ find_session_by_client (struct Plugin *plugin, return ret; } +#if !MULTIPLE_PEER_SESSIONS +/** + * Find the session handle for the given client. + * + * @return NULL if no matching session exists + */ +static struct Session * +find_session_by_id (struct Plugin *plugin, + const struct GNUNET_PeerIdentity *peer) +{ + struct Session *ret; + + ret = plugin->sessions; + while ((ret != NULL) && (0 != memcmp(peer, &ret->target, sizeof(struct GNUNET_PeerIdentity)))) + ret = ret->next; + return ret; +} +#endif + /** * Create a new session. Also queues a welcome message. * @@ -1082,8 +1101,13 @@ tcp_plugin_send (void *cls, GNUNET_break (0); break; } - if (session->inbound == GNUNET_YES) - continue; +#if IGNORE_INBOUND + if (session->inbound == GNUNET_YES) /* FIXME: why do we ignore inbound sessions? */ + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Ignoring inbound session\n"); + continue; + } +#endif if ((addrlen != session->connect_alen) && (session->is_nat == GNUNET_NO)) continue; if ((0 != memcmp (session->connect_addr, @@ -1218,7 +1242,7 @@ tcp_plugin_send (void *cls, GNUNET_NO); return -1; } -#if DEBUG_TCP +#if DEBUG_TCP_NAT GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Asked to transmit to `%4s', creating fresh session using address `%s'.\n", GNUNET_i2s (target), @@ -1586,7 +1610,7 @@ handle_tcp_nat_probe (void *cls, { #if DEBUG_TCP_NAT GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Found address `%s' for incoming connection %p\n", + "handle_tcp_nat_probe Found address `%s' for incoming connection %p\n", GNUNET_a2s (vaddr, alen), client); #endif @@ -1671,7 +1695,12 @@ handle_tcp_welcome (void *cls, gettext_noop ("# TCP WELCOME messages received"), 1, GNUNET_NO); +#if MULTIPLE_PEER_SESSIONS session = find_session_by_client (plugin, client); +#else + session = find_session_by_id(plugin, &wm->clientIdentity); +#endif + if (session == NULL) { GNUNET_SERVER_client_keep (client); @@ -1687,8 +1716,8 @@ handle_tcp_welcome (void *cls, if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) { -#if DEBUG_TCP - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, +#if DEBUG_TCP_NAT + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Found address `%s' for incoming connection %p\n", GNUNET_a2s (vaddr, alen), client); @@ -1713,6 +1742,7 @@ handle_tcp_welcome (void *cls, session->connect_addr = t6; session->connect_alen = sizeof (struct IPv6TcpAddress); } + GNUNET_free (vaddr); } else @@ -1729,12 +1759,28 @@ handle_tcp_welcome (void *cls, #endif process_pending_messages (session); } + else + { +#if DEBUG_TCP_NAT + if (GNUNET_OK == + GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Found address `%s' (already have session) for incoming connection %p\n", + GNUNET_a2s (vaddr, alen), + client); + } +#endif + } + +#if MULTIPLE_PEER_SESSIONS if (session->expecting_welcome != GNUNET_YES) { GNUNET_break_op (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } +#endif session->last_activity = GNUNET_TIME_absolute_get (); session->expecting_welcome = GNUNET_NO; GNUNET_SERVER_receive_done (client, GNUNET_OK); @@ -1799,8 +1845,8 @@ handle_tcp_data (void *cls, return; } session->last_activity = GNUNET_TIME_absolute_get (); -#if DEBUG_TCP - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, +#if DEBUG_TCP > 1 + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Passing %u bytes of type %u from `%4s' to transport service.\n", (unsigned int) ntohs (message->size), (unsigned int) ntohs (message->type), -- 2.25.1