From 08b85f24f005ac70168f3cda2b57178e8a3d4b41 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 28 Sep 2011 09:56:18 +0000 Subject: [PATCH] fixes --- src/dht/dht.h | 10 +++- src/dht/gnunet-service-dht_clients.c | 36 ++++++++++++-- src/dht/gnunet-service-dht_neighbours.c | 63 +++++++++++++++---------- src/dht/test_dht_twopeer.c | 3 +- 4 files changed, 78 insertions(+), 34 deletions(-) diff --git a/src/dht/dht.h b/src/dht/dht.h index c8e2baff1..2a6717788 100644 --- a/src/dht/dht.h +++ b/src/dht/dht.h @@ -24,8 +24,14 @@ * @file dht/dht.h */ -#ifndef DHT_H_ -#define DHT_H_ +#ifndef DHT_H +#define DHT_H + + +/** + * Size of the bloom filter the DHT uses to filter peers. + */ +#define DHT_BLOOM_SIZE 128 /** diff --git a/src/dht/gnunet-service-dht_clients.c b/src/dht/gnunet-service-dht_clients.c index 25687d570..5ae25ea4d 100644 --- a/src/dht/gnunet-service-dht_clients.c +++ b/src/dht/gnunet-service-dht_clients.c @@ -26,6 +26,7 @@ */ #include "platform.h" +#include "gnunet_constants.h" #include "gnunet_protocols.h" #include "gnunet_statistics_service.h" #include "gnunet-service-dht.h" @@ -303,6 +304,7 @@ transmit_request (struct ClientQueryRecord *cqr) { int32_t reply_bf_mutator; struct GNUNET_CONTAINER_BloomFilter *reply_bf; + struct GNUNET_CONTAINER_BloomFilter *peer_bf; GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# GET requests from clients injected"), 1, @@ -312,6 +314,9 @@ transmit_request (struct ClientQueryRecord *cqr) reply_bf = GNUNET_BLOCK_construct_bloomfilter (reply_bf_mutator, cqr->seen_replies, cqr->seen_replies_count); + peer_bf = GNUNET_CONTAINER_bloomfilter_init (NULL, + DHT_BLOOM_SIZE, + GNUNET_CONSTANTS_BLOOMFILTER_K); GDS_NEIGHBOURS_handle_get (cqr->type, cqr->msg_options, cqr->replication, @@ -321,8 +326,9 @@ transmit_request (struct ClientQueryRecord *cqr) cqr->xquery_size, reply_bf, reply_bf_mutator, - NULL /* no peers blocked initially */); + peer_bf); GNUNET_CONTAINER_bloomfilter_free (reply_bf); + GNUNET_CONTAINER_bloomfilter_free (peer_bf); /* exponential back-off for retries, max 1h */ cqr->retry_frequency = @@ -380,6 +386,7 @@ handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { const struct GNUNET_DHT_ClientPutMessage *dht_msg; + struct GNUNET_CONTAINER_BloomFilter *peer_bf; uint16_t size; size = ntohs (message->size); @@ -409,16 +416,20 @@ handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client, size - sizeof (struct GNUNET_DHT_ClientPutMessage), &dht_msg[1]); /* route to other peers */ + peer_bf = GNUNET_CONTAINER_bloomfilter_init (NULL, + DHT_BLOOM_SIZE, + GNUNET_CONSTANTS_BLOOMFILTER_K); GDS_NEIGHBOURS_handle_put (ntohl (dht_msg->type), ntohl (dht_msg->options), ntohl (dht_msg->desired_replication_level), GNUNET_TIME_absolute_ntoh (dht_msg->expiration), 0 /* hop count */, - NULL /* peer bloom filter */, + peer_bf, &dht_msg->key, 0, NULL, &dht_msg[1], size - sizeof (struct GNUNET_DHT_ClientPutMessage)); + GNUNET_CONTAINER_bloomfilter_free (peer_bf); GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -698,7 +709,12 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value) if ( (record->type != GNUNET_BLOCK_TYPE_ANY) && (record->type != frc->type) ) - return GNUNET_YES; /* type mismatch */ + { + GNUNET_STATISTICS_update (GDS_stats, + gettext_noop ("# Key match, type mismatches in REPLY to CLIENT"), 1, + GNUNET_NO); + return GNUNET_YES; /* type mismatch */ + } GNUNET_CRYPTO_hash (frc->data, frc->data_size, &ch); @@ -706,7 +722,12 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value) if (0 == memcmp (&record->seen_replies[i], &ch, sizeof (GNUNET_HashCode))) - return GNUNET_YES; /* duplicate */ + { + GNUNET_STATISTICS_update (GDS_stats, + gettext_noop ("# Duplicate REPLIES to CLIENT request dropped"), 1, + GNUNET_NO); + return GNUNET_YES; /* duplicate */ + } eval = GNUNET_BLOCK_evaluate (GDS_block_context, record->type, key, @@ -741,7 +762,7 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value) return GNUNET_NO; case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Unsupported block type (%u) in request!\n", + _("Unsupported block type (%u) in request!\n"), record->type); return GNUNET_NO; } @@ -806,7 +827,12 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, if (NULL == GNUNET_CONTAINER_multihashmap_get (forward_map, key)) + { + GNUNET_STATISTICS_update (GDS_stats, + gettext_noop ("# REPLIES ignored for CLIENTS (no match)"), 1, + GNUNET_NO); return; /* no matching request, fast exit! */ + } msize = sizeof(struct GNUNET_DHT_ClientResultMessage) + data_size + (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity); if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 5e632ef68..d226376c9 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c @@ -46,6 +46,7 @@ #include "gnunet-service-dht_nse.h" #include "gnunet-service-dht_routing.h" #include +#include "dht.h" /** * How many buckets will we allow total. @@ -57,11 +58,6 @@ */ #define DEFAULT_BUCKET_SIZE 4 -/** - * Size of the bloom filter the DHT uses to filter peers. - */ -#define DHT_BLOOM_SIZE 128 - /** * Desired replication level for FIND PEER requests */ @@ -578,6 +574,7 @@ send_find_peer_message (void *cls, { struct GNUNET_TIME_Relative next_send_time; struct BloomConstructorContext bcc; + struct GNUNET_CONTAINER_BloomFilter *peer_bf; find_peer_task = GNUNET_SCHEDULER_NO_TASK; if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) @@ -599,6 +596,9 @@ send_find_peer_message (void *cls, GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# FIND PEER messages initiated"), 1, GNUNET_NO); + peer_bf = GNUNET_CONTAINER_bloomfilter_init (NULL, + DHT_BLOOM_SIZE, + GNUNET_CONSTANTS_BLOOMFILTER_K); // FIXME: pass priority!? GDS_NEIGHBOURS_handle_get (GNUNET_BLOCK_TYPE_DHT_HELLO, GNUNET_DHT_RO_FIND_PEER, @@ -606,7 +606,9 @@ send_find_peer_message (void *cls, 0, &my_identity.hashPubKey, NULL, 0, - bcc.bloom, bcc.bf_mutator, NULL); + bcc.bloom, bcc.bf_mutator, + peer_bf); + GNUNET_CONTAINER_bloomfilter_free (peer_bf); GNUNET_CONTAINER_bloomfilter_free (bcc.bloom); /* schedule next round */ newly_found_peers = 0; @@ -780,12 +782,14 @@ core_transmit_notify (void *cls, size_t size, void *buf) GNUNET_free (pending); } if (peer->head != NULL) - peer->th - = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, - pending->importance, - GNUNET_TIME_absolute_get_remaining (pending->timeout), - &peer->id, msize, - &core_transmit_notify, peer); + { + peer->th + = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, + pending->importance, + GNUNET_TIME_absolute_get_remaining (pending->timeout), + &peer->id, msize, + &core_transmit_notify, peer); + } return off; } @@ -1116,6 +1120,7 @@ get_target_peers (const GNUNET_HashCode *key, struct PeerInfo **rtargets; struct PeerInfo *nxt; + GNUNET_assert (NULL != bloom); ret = get_forward_count (hop_count, target_replication); if (ret == 0) { @@ -1130,6 +1135,8 @@ get_target_peers (const GNUNET_HashCode *key, if (nxt == NULL) break; rtargets[off++] = nxt; + GNUNET_break (GNUNET_NO == + GNUNET_CONTAINER_bloomfilter_test (bloom, &nxt->id.hashPubKey)); GNUNET_CONTAINER_bloomfilter_add (bloom, &nxt->id.hashPubKey); } if (0 == off) @@ -1184,6 +1191,8 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, struct PeerPutMessage *ppm; struct GNUNET_PeerIdentity *pp; + GNUNET_assert (NULL != bf); + GNUNET_CONTAINER_bloomfilter_add (bf, &my_identity.hashPubKey); GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# PUT requests routed"), 1, GNUNET_NO); @@ -1222,11 +1231,11 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, ppm->desired_replication_level = htonl (desired_replication_level); ppm->put_path_length = htonl (put_path_length); ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); - if (NULL != bf) - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_bloomfilter_get_raw_data (bf, - ppm->bloomfilter, - DHT_BLOOM_SIZE)); + GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &target->id.hashPubKey)); + GNUNET_assert (GNUNET_OK == + GNUNET_CONTAINER_bloomfilter_get_raw_data (bf, + ppm->bloomfilter, + DHT_BLOOM_SIZE)); ppm->key = *key; pp = (struct GNUNET_PeerIdentity*) &ppm[1]; memcpy (pp, put_path, sizeof (struct GNUNET_PeerIdentity) * put_path_length); @@ -1279,7 +1288,9 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, struct PeerGetMessage *pgm; char *xq; size_t reply_bf_size; - + + GNUNET_assert (NULL != peer_bf); + GNUNET_CONTAINER_bloomfilter_add (peer_bf, &my_identity.hashPubKey); GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# GET requests routed"), 1, GNUNET_NO); @@ -1315,11 +1326,11 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, pgm->desired_replication_level = htonl (desired_replication_level); pgm->xquery_size = htonl (xquery_size); pgm->bf_mutator = reply_bf_mutator; - if (NULL != peer_bf) - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_bloomfilter_get_raw_data (peer_bf, - pgm->bloomfilter, - DHT_BLOOM_SIZE)); + GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (peer_bf, &target->id.hashPubKey)); + GNUNET_assert (GNUNET_OK == + GNUNET_CONTAINER_bloomfilter_get_raw_data (peer_bf, + pgm->bloomfilter, + DHT_BLOOM_SIZE)); pgm->key = *key; xq = (char *) &pgm[1]; memcpy (xq, xquery, xquery_size); @@ -1508,6 +1519,7 @@ handle_dht_p2p_put (void *cls, bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter, DHT_BLOOM_SIZE, GNUNET_CONSTANTS_BLOOMFILTER_K); + GNUNET_break_op (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &peer->hashPubKey)); { struct GNUNET_PeerIdentity pp[putlen+1]; @@ -1678,7 +1690,8 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_CONTAINER_BloomFilter *reply_bf; struct GNUNET_CONTAINER_BloomFilter *peer_bf; const char *xquery; - + + GNUNET_break (0 != memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))); /* parse and validate message */ msize = ntohs (message->size); if (msize < sizeof (struct PeerGetMessage)) @@ -1724,7 +1737,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, DHT_BLOOM_SIZE, GNUNET_CONSTANTS_BLOOMFILTER_K); - + GNUNET_break_op (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (peer_bf, &peer->hashPubKey)); /* remember request for routing replies */ GDS_ROUTING_add (peer, type, diff --git a/src/dht/test_dht_twopeer.c b/src/dht/test_dht_twopeer.c index 21e817c85..9f13f5136 100644 --- a/src/dht/test_dht_twopeer.c +++ b/src/dht/test_dht_twopeer.c @@ -287,14 +287,13 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), &stop_retry_get, get_context); - get_context->get_handle = GNUNET_DHT_get_start (get_context->dht_handle, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), GNUNET_BLOCK_TYPE_DHT_HELLO, &get_context->peer->hashPubKey, - 1, GNUNET_DHT_RO_NONE, NULL, + 1, GNUNET_DHT_RO_FIND_PEER, NULL, 0, &get_result_iterator, get_context); } -- 2.25.1