From 4b5e3086a0813daa6709ee7c0087ece6222bb022 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 14 Aug 2011 20:47:31 +0000 Subject: [PATCH] process keepalive, simplify PONGs --- src/include/gnunet_signatures.h | 2 +- src/transport/gnunet-service-transport-new.c | 3 ++ .../gnunet-service-transport_neighbours.c | 31 ++++++++++++++++--- .../gnunet-service-transport_neighbours.h | 10 ++++++ .../gnunet-service-transport_validation.c | 30 ++++++------------ src/transport/plugin_transport_udp.c | 3 +- 6 files changed, 53 insertions(+), 26 deletions(-) diff --git a/src/include/gnunet_signatures.h b/src/include/gnunet_signatures.h index 9b6a3d6b6..c54df3e85 100644 --- a/src/include/gnunet_signatures.h +++ b/src/include/gnunet_signatures.h @@ -49,7 +49,7 @@ extern "C" /** * Signature for confirming that this peer connected to another peer - * using a particular address. + * using a particular address (LEGACY) */ #define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING 2 diff --git a/src/transport/gnunet-service-transport-new.c b/src/transport/gnunet-service-transport-new.c index 6bc3c2541..3cc1191fd 100644 --- a/src/transport/gnunet-service-transport-new.c +++ b/src/transport/gnunet-service-transport-new.c @@ -226,6 +226,9 @@ plugin_env_receive_callback (void *cls, a fake disconnect message... */ GST_neighbours_force_disconnect (peer); break; + case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE: + GST_neighbours_keepalive (peer); + break; default: /* should be payload */ do_forward = GNUNET_SYSERR; diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index 211595b51..604112560 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c @@ -815,10 +815,6 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender n->quota_violation_count--; } } - GNUNET_SCHEDULER_cancel (n->timeout_task); - n->timeout_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, - &neighbour_timeout_task, n); if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD) { GNUNET_STATISTICS_update (GST_stats, @@ -848,6 +844,33 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender } +/** + * Keep the connection to the given neighbour alive longer, + * we received a KEEPALIVE (or equivalent). + * + * @param neighbour neighbour to keep alive + */ +void +GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour) +{ + struct NeighbourMapEntry *n; + + n = lookup_neighbour (neighbour); + if (NULL == n) + { + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ("# KEEPALIVE messages discarded (not connected)"), + 1, + GNUNET_NO); + return; + } + GNUNET_SCHEDULER_cancel (n->timeout_task); + n->timeout_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, + &neighbour_timeout_task, n); +} + + /** * Change the incoming quota for the given peer. * diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h index 14f223811..a99cd1e96 100644 --- a/src/transport/gnunet-service-transport_neighbours.h +++ b/src/transport/gnunet-service-transport_neighbours.h @@ -121,6 +121,16 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender int *do_forward); +/** + * Keep the connection to the given neighbour alive longer, + * we received a KEEPALIVE (or equivalent). + * + * @param neighbour neighbour to keep alive + */ +void +GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour); + + /** * Change the incoming quota for the given peer. * diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index e07ff7546..86c51c729 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c @@ -132,11 +132,8 @@ struct TransportPongMessage struct GNUNET_CRYPTO_RsaSignature signature; /** - * What are we signing and why? Two possible reason codes can be here: * GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN to confirm that this is a - * plausible address for this peer (pid is set to identity of signer); or - * GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING to confirm that this is - * an address we used to connect to the peer with the given pid. + * plausible address for the signing peer. */ struct GNUNET_CRYPTO_RsaSignaturePurpose purpose; @@ -145,13 +142,6 @@ struct TransportPongMessage */ struct GNUNET_TIME_AbsoluteNBO expiration; - /** - * Either the identity of the peer Who signed this message, or the - * identity of the peer that we're connected to using the given - * address (depending on purpose.type). - */ - struct GNUNET_PeerIdentity pid; - /** * Size of address appended to this message (part of what is * being signed, hence not redundant). @@ -683,11 +673,10 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + sizeof (uint32_t) + sizeof (struct GNUNET_TIME_AbsoluteNBO) + - sizeof (struct GNUNET_PeerIdentity) + alen + slen); + alen + slen); pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN); pong->challenge = ping->challenge; pong->addrlen = htonl(alen + slen); - pong->pid = GST_my_identity; memcpy (&pong[1], addr, slen); memcpy (&((char*)&pong[1])[slen], addrend, alen); if (GNUNET_TIME_absolute_get_remaining (*sig_cache_exp).rel_value < PONG_SIGNATURE_LIFETIME.rel_value / 4) @@ -993,13 +982,6 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, 1, GNUNET_NO); pong = (const struct TransportPongMessage *) hdr; - if (0 != memcmp (&pong->pid, - sender, - sizeof (struct GNUNET_PeerIdentity))) - { - GNUNET_break_op (0); - return; - } addr = (const char*) &pong[1]; alen = ntohs (hdr->size) - sizeof (struct TransportPongMessage); addrend = memchr (addr, '\0', alen); @@ -1025,6 +1007,14 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, return; } /* now check that PONG is well-formed */ + if (0 != memcmp (&ve->pid, + sender, + sizeof (struct GNUNET_PeerIdentity))) + { + GNUNET_break_op (0); + return; + } + if (GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value == 0) { GNUNET_STATISTICS_update (GST_stats, diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index e58d4312e..7d8c1520f 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c @@ -129,7 +129,8 @@ struct Plugin; /** - * Session with another peer. + * Session with another peer. FIXME: why not make this into + * a regular 'struct Session' and pass it around!? */ struct PeerSession { -- 2.25.1