From 214424c6576d922dd5076ac5377294d81ccca647 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 14 Nov 2010 13:26:50 +0000 Subject: [PATCH] more checks --- src/core/core_api.c | 66 ++++++++++++++++++++++++++++++++-- src/core/test_core_api.c | 78 +++++++++++++++++++++------------------- 2 files changed, 104 insertions(+), 40 deletions(-) diff --git a/src/core/core_api.c b/src/core/core_api.c index 1d7a32327..2211028fb 100644 --- a/src/core/core_api.c +++ b/src/core/core_api.c @@ -236,6 +236,11 @@ struct GNUNET_CORE_Handle */ struct GNUNET_CONTAINER_MultiHashMap *peers; + /** + * Identity of this peer. + */ + struct GNUNET_PeerIdentity me; + /** * ID of reconnect task (if any). */ @@ -781,7 +786,6 @@ main_notify_handler (void *cls, const struct GNUNET_CORE_MessageHandler *mh; GNUNET_CORE_StartupCallback init; GNUNET_CORE_PeerConfigurationInfoCallback pcic; - struct GNUNET_PeerIdentity my_identity; struct PeerRecord *pr; struct GNUNET_CORE_TransmitHandle *th; unsigned int hpos; @@ -832,8 +836,8 @@ main_notify_handler (void *cls, GNUNET_CRYPTO_hash (&m->publicKey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), - &my_identity.hashPubKey); - init (h->cls, h, &my_identity, &m->publicKey); + &h->me.hashPubKey); + init (h->cls, h, &h->me, &m->publicKey); } break; case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT: @@ -849,6 +853,14 @@ main_notify_handler (void *cls, "Received notification about connection from `%s'.\n", GNUNET_i2s (&cnm->peer)); #endif + if (0 == memcmp (&h->me, + &cnm->peer, + sizeof (struct GNUNET_PeerIdentity))) + { + /* disconnect from self!? */ + GNUNET_break (0); + return; + } pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &cnm->peer.hashPubKey); if (pr != NULL) @@ -878,6 +890,14 @@ main_notify_handler (void *cls, return; } dnm = (const struct DisconnectNotifyMessage *) msg; + if (0 == memcmp (&h->me, + &dnm->peer, + sizeof (struct GNUNET_PeerIdentity))) + { + /* connection to self!? */ + GNUNET_break (0); + return; + } #if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received notification about disconnect from `%s'.\n", @@ -911,6 +931,14 @@ main_notify_handler (void *cls, return; } psnm = (const struct PeerStatusNotifyMessage *) msg; + if (0 == memcmp (&h->me, + &psnm->peer, + sizeof (struct GNUNET_PeerIdentity))) + { + /* self-change!? */ + GNUNET_break (0); + return; + } #if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received notification about status change by `%s'.\n", @@ -941,6 +969,14 @@ main_notify_handler (void *cls, return; } ntm = (const struct NotifyTrafficMessage *) msg; + if (0 == memcmp (&h->me, + &ntm->peer, + sizeof (struct GNUNET_PeerIdentity))) + { + /* self-change!? */ + GNUNET_break (0); + return; + } em = (const struct GNUNET_MessageHeader *) &ntm[1]; #if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -998,6 +1034,14 @@ main_notify_handler (void *cls, return; } ntm = (const struct NotifyTrafficMessage *) msg; + if (0 == memcmp (&h->me, + &ntm->peer, + sizeof (struct GNUNET_PeerIdentity))) + { + /* self-change!? */ + GNUNET_break (0); + return; + } em = (const struct GNUNET_MessageHeader *) &ntm[1]; pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &ntm->peer.hashPubKey); @@ -1035,6 +1079,14 @@ main_notify_handler (void *cls, return; } smr = (const struct SendMessageReady *) msg; + if (0 == memcmp (&h->me, + &smr->peer, + sizeof (struct GNUNET_PeerIdentity))) + { + /* self-change!? */ + GNUNET_break (0); + return; + } pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &smr->peer.hashPubKey); if (pr == NULL) @@ -1077,6 +1129,14 @@ main_notify_handler (void *cls, return; } cim = (const struct ConfigurationInfoMessage*) msg; + if (0 == memcmp (&h->me, + &cim->peer, + sizeof (struct GNUNET_PeerIdentity))) + { + /* self-change!? */ + GNUNET_break (0); + return; + } #if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received notification about configuration update for `%s'.\n", diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c index b41d30450..004486525 100644 --- a/src/core/test_core_api.c +++ b/src/core/test_core_api.c @@ -57,6 +57,7 @@ static struct PeerContext p1; static struct PeerContext p2; +static GNUNET_SCHEDULER_TaskIdentifier err_task; static int ok; @@ -95,6 +96,27 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } +static size_t +transmit_ready (void *cls, size_t size, void *buf) +{ + struct PeerContext *p = cls; + struct GNUNET_MessageHeader *m; + + GNUNET_assert (ok == 4); + OKPP; + GNUNET_assert (p == &p1); + GNUNET_assert (buf != NULL); + m = (struct GNUNET_MessageHeader *) buf; + m->type = htons (MTYPE); + m->size = htons (sizeof (struct GNUNET_MessageHeader)); + err_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120), + &terminate_task_error, NULL); + + return sizeof (struct GNUNET_MessageHeader); +} + + static void connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, @@ -106,6 +128,20 @@ connect_notify (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted connection established to peer `%4s'\n", GNUNET_i2s (peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Asking core (1) for transmission to peer `%4s'\n", + GNUNET_i2s (&p2.id)); + if (NULL == GNUNET_CORE_notify_transmit_ready (p1.ch, + 0, + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 45), + &p2.id, + sizeof (struct GNUNET_MessageHeader), + &transmit_ready, &p1)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", + GNUNET_i2s (&p2.id)); + } } @@ -145,8 +181,6 @@ outbound_notify (void *cls, } -static GNUNET_SCHEDULER_TaskIdentifier err_task; - static int process_mtype (void *cls, @@ -170,27 +204,6 @@ static struct GNUNET_CORE_MessageHandler handlers[] = { }; -static size_t -transmit_ready (void *cls, size_t size, void *buf) -{ - struct PeerContext *p = cls; - struct GNUNET_MessageHeader *m; - - GNUNET_assert (ok == 4); - OKPP; - GNUNET_assert (p == &p1); - GNUNET_assert (buf != NULL); - m = (struct GNUNET_MessageHeader *) buf; - m->type = htons (MTYPE); - m->size = htons (sizeof (struct GNUNET_MessageHeader)); - err_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120), &terminate_task_error, NULL); - - return sizeof (struct GNUNET_MessageHeader); -} - - - static void init_notify (void *cls, struct GNUNET_CORE_Handle *server, @@ -226,21 +239,12 @@ init_notify (void *cls, OKPP; GNUNET_assert (cls == &p2); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Asking core (1) for transmission to peer `%4s'\n", + "Asking core (1) to connect to peer `%4s'\n", GNUNET_i2s (&p2.id)); - - if (NULL == GNUNET_CORE_notify_transmit_ready (p1.ch, - 0, - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 45), - &p2.id, - sizeof (struct GNUNET_MessageHeader), - &transmit_ready, &p1)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", - GNUNET_i2s (&p2.id)); - } - + GNUNET_CORE_peer_request_connect (p1.ch, + GNUNET_TIME_UNIT_SECONDS, + &p2.id, + NULL, NULL); } } -- 2.25.1