From 67b73a5ef982c8b54245357ca14a60cff868dc64 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 15 Feb 2010 22:07:20 +0000 Subject: [PATCH] found assertion problem in core --- src/core/core.h | 4 +- src/core/gnunet-service-core.c | 201 +++++++++++++++++------------- src/core/test_core_api.c | 5 +- src/core/test_core_api_peer1.conf | 4 +- src/core/test_core_api_peer2.conf | 4 +- 5 files changed, 118 insertions(+), 100 deletions(-) diff --git a/src/core/core.h b/src/core/core.h index 20c3ddc4b..4b59498bd 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -29,12 +29,12 @@ /** * General core debugging. */ -#define DEBUG_CORE GNUNET_YES +#define DEBUG_CORE GNUNET_NO /** * Debugging interaction core-clients. */ -#define DEBUG_CORE_CLIENT GNUNET_YES +#define DEBUG_CORE_CLIENT GNUNET_NO /** * Definition of bits in the InitMessage's options field that specify diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index f9581f4ef..47f6b41c2 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c @@ -375,6 +375,13 @@ struct Neighbour */ struct PingMessage *pending_ping; + /** + * We received a PONG message before we got the "public_key" + * (or the SET_KEY). We keep it here until we have a key + * to decrypt it. NULL if no PONG is pending. + */ + struct PingMessage *pending_pong; + /** * Non-NULL if we are currently looking up HELLOs for this peer. * for this peer. @@ -2314,6 +2321,93 @@ handle_ping (struct Neighbour *n, const struct PingMessage *m) } +/** + * We received a PONG message. Validate and update our status. + * + * @param n sender of the PONG + * @param m the encrypted PONG message itself + */ +static void +handle_pong (struct Neighbour *n, const struct PingMessage *m) +{ + struct PingMessage t; + struct ConnectNotifyMessage cnm; + +#if DEBUG_CORE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Core service receives `%s' request from `%4s'.\n", + "PONG", GNUNET_i2s (&n->peer)); +#endif + if (GNUNET_OK != + do_decrypt (n, + &n->peer.hashPubKey, + &m->challenge, + &t.challenge, + sizeof (struct PingMessage) - + sizeof (struct GNUNET_MessageHeader))) + return; +#if DEBUG_CORE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Decrypted `%s' from `%4s' with challenge %u using key %u\n", + "PONG", + GNUNET_i2s (&t.target), + ntohl (t.challenge), n->decrypt_key.crc32); +#endif + if ((0 != memcmp (&t.target, + &n->peer, + sizeof (struct GNUNET_PeerIdentity))) || + (n->ping_challenge != ntohl (t.challenge))) + { + /* PONG malformed */ +#if DEBUG_CORE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received malformed `%s' wanted sender `%4s' with challenge %u\n", + "PONG", GNUNET_i2s (&n->peer), n->ping_challenge); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received malformed `%s' received from `%4s' with challenge %u\n", + "PONG", GNUNET_i2s (&t.target), ntohl (t.challenge)); +#endif + GNUNET_break_op (0); + return; + } + switch (n->status) + { + case PEER_STATE_DOWN: + GNUNET_break (0); /* should be impossible */ + return; + case PEER_STATE_KEY_SENT: + GNUNET_break (0); /* should be impossible, how did we decrypt? */ + return; + case PEER_STATE_KEY_RECEIVED: + n->status = PEER_STATE_KEY_CONFIRMED; +#if DEBUG_CORE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Confirmed key via `%s' message for peer `%4s'\n", + "PONG", GNUNET_i2s (&n->peer)); +#endif + if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (sched, n->retry_set_key_task); + n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; + } + cnm.header.size = htons (sizeof (struct ConnectNotifyMessage)); + cnm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); + cnm.distance = htonl (n->last_distance); + cnm.latency = GNUNET_TIME_relative_hton (n->last_latency); + cnm.peer = n->peer; + send_to_all_clients (&cnm.header, GNUNET_YES, GNUNET_CORE_OPTION_SEND_CONNECT); + process_encrypted_neighbour_queue (n); + break; + case PEER_STATE_KEY_CONFIRMED: + /* duplicate PONG? */ + break; + default: + GNUNET_break (0); + break; + } +} + + /** * We received a SET_KEY message. Validate and update * our key material and status. @@ -2328,6 +2422,7 @@ handle_set_key (struct Neighbour *n, const struct SetKeyMessage *m) struct GNUNET_TIME_Absolute t; struct GNUNET_CRYPTO_AesSessionKey k; struct PingMessage *ping; + struct PingMessage *pong; enum PeerStateMachine sender_status; #if DEBUG_CORE @@ -2467,92 +2562,12 @@ handle_set_key (struct Neighbour *n, const struct SetKeyMessage *m) handle_ping (n, ping); GNUNET_free (ping); } -} - - -/** - * We received a PONG message. Validate and update our status. - * - * @param n sender of the PONG - * @param m the encrypted PONG message itself - */ -static void -handle_pong (struct Neighbour *n, const struct PingMessage *m) -{ - struct PingMessage t; - struct ConnectNotifyMessage cnm; - -#if DEBUG_CORE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Core service receives `%s' request from `%4s'.\n", - "PONG", GNUNET_i2s (&n->peer)); -#endif - if (GNUNET_OK != - do_decrypt (n, - &n->peer.hashPubKey, - &m->challenge, - &t.challenge, - sizeof (struct PingMessage) - - sizeof (struct GNUNET_MessageHeader))) - return; -#if DEBUG_CORE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Decrypted `%s' from `%4s' with challenge %u using key %u\n", - "PONG", - GNUNET_i2s (&t.target), - ntohl (t.challenge), n->decrypt_key.crc32); -#endif - if ((0 != memcmp (&t.target, - &n->peer, - sizeof (struct GNUNET_PeerIdentity))) || - (n->ping_challenge != ntohl (t.challenge))) + if (n->pending_pong != NULL) { - /* PONG malformed */ -#if DEBUG_CORE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received malformed `%s' wanted sender `%4s' with challenge %u\n", - "PONG", GNUNET_i2s (&n->peer), n->ping_challenge); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received malformed `%s' received from `%4s' with challenge %u\n", - "PONG", GNUNET_i2s (&t.target), ntohl (t.challenge)); -#endif - GNUNET_break_op (0); - return; - } - switch (n->status) - { - case PEER_STATE_DOWN: - GNUNET_break (0); /* should be impossible */ - return; - case PEER_STATE_KEY_SENT: - GNUNET_break (0); /* should be impossible, how did we decrypt? */ - return; - case PEER_STATE_KEY_RECEIVED: - n->status = PEER_STATE_KEY_CONFIRMED; -#if DEBUG_CORE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Confirmed key via `%s' message for peer `%4s'\n", - "PONG", GNUNET_i2s (&n->peer)); -#endif - if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_SCHEDULER_cancel (sched, n->retry_set_key_task); - n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; - } - cnm.header.size = htons (sizeof (struct ConnectNotifyMessage)); - cnm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); - cnm.distance = htonl (n->last_distance); - cnm.latency = GNUNET_TIME_relative_hton (n->last_latency); - cnm.peer = n->peer; - send_to_all_clients (&cnm.header, GNUNET_YES, GNUNET_CORE_OPTION_SEND_CONNECT); - process_encrypted_neighbour_queue (n); - break; - case PEER_STATE_KEY_CONFIRMED: - /* duplicate PONG? */ - break; - default: - GNUNET_break (0); - break; + pong = n->pending_pong; + n->pending_pong = NULL; + handle_pong (n, pong); + GNUNET_free (pong); } } @@ -2909,12 +2924,17 @@ handle_transport_receive (void *cls, GNUNET_break_op (0); return; } - if ((n->status != PEER_STATE_KEY_SENT) && - (n->status != PEER_STATE_KEY_RECEIVED) && - (n->status != PEER_STATE_KEY_CONFIRMED)) + if ( (n->status != PEER_STATE_KEY_RECEIVED) && + (n->status != PEER_STATE_KEY_CONFIRMED) ) { - /* could not decrypt pong, oops! */ - GNUNET_break_op (0); +#if DEBUG_CORE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Core service receives `%s' request from `%4s' but have not processed key; marking as pending.\n", + "PONG", GNUNET_i2s (&n->peer)); +#endif + GNUNET_free_non_null (n->pending_pong); + n->pending_pong = GNUNET_malloc (sizeof (struct PingMessage)); + memcpy (n->pending_pong, message, sizeof (struct PingMessage)); return; } handle_pong (n, (const struct PingMessage *) message); @@ -3121,6 +3141,7 @@ free_neighbour (struct Neighbour *n) GNUNET_SCHEDULER_cancel (sched, n->quota_update_task); GNUNET_free_non_null (n->public_key); GNUNET_free_non_null (n->pending_ping); + GNUNET_free_non_null (n->pending_pong); GNUNET_free (n); } diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c index 3c7529303..1ae9c74e8 100644 --- a/src/core/test_core_api.c +++ b/src/core/test_core_api.c @@ -34,7 +34,7 @@ #include "gnunet_scheduler_lib.h" #include "gnunet_transport_service.h" -#define VERBOSE GNUNET_YES +#define VERBOSE GNUNET_NO #define START_ARM GNUNET_YES @@ -78,9 +78,6 @@ static void terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_assert (ok == 6); -#if VERBOSE - fprintf(stderr, "ENDING WELL %u\n", ok); -#endif GNUNET_CORE_disconnect (p1.ch); GNUNET_CORE_disconnect (p2.ch); GNUNET_TRANSPORT_disconnect (p1.th); diff --git a/src/core/test_core_api_peer1.conf b/src/core/test_core_api_peer1.conf index 8835ee51a..af7605222 100644 --- a/src/core/test_core_api_peer1.conf +++ b/src/core/test_core_api_peer1.conf @@ -13,7 +13,7 @@ PLUGINS = tcp #PREFIX= xterm -e xterm -T transport1 -e gdb --args #PREFIX = xterm -T transport1 -e gdb --args #PREFIX = xterm -T transport1 -e valgrind --tool=memcheck -DEBUG = YES +DEBUG = NO [arm] PORT = 12466 @@ -40,7 +40,7 @@ PORT = 12470 #OPTIONS = -l log-core-1 #PREFIX = xterm -e xterm -T core1 -e gdb --args #PREFIX = xterm -T core1 -e -DEBUG = YES +DEBUG = NO [testing] WEAKRANDOM = YES diff --git a/src/core/test_core_api_peer2.conf b/src/core/test_core_api_peer2.conf index a9875877a..687e8813c 100644 --- a/src/core/test_core_api_peer2.conf +++ b/src/core/test_core_api_peer2.conf @@ -13,7 +13,7 @@ PLUGINS = tcp #PREFIX = xterm -e xterm -T transport2 -e gdb --args #PREFIX = xterm -T transport2 -e #PREFIX = xterm -T transport2 -e valgrind --tool=memcheck -DEBUG = YES +DEBUG = NO [arm] PORT = 22466 @@ -38,7 +38,7 @@ PORT = 22469 PORT = 22470 #PREFIX = xterm -T core2 -e #PREFIX = xterm -T core2 -e valgrind --tool=memcheck -DEBUG = YES +DEBUG = NO [testing] WEAKRANDOM = YES -- 2.25.1