From 8254665a4a3f254d4947cf9de6902121f234a29f Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 30 Sep 2011 20:55:21 +0000 Subject: [PATCH] fixing bloomfilter code, fixing testcase --- src/dht/Makefile.am | 4 +- src/dht/dht.h | 2 +- src/dht/gnunet-service-dht_neighbours.c | 64 +++++++++++++++++-------- src/dht/multipeer_topo.dat | 20 ++++++++ src/dht/test_dht_multipeer.c | 61 ++++++++++++++--------- 5 files changed, 105 insertions(+), 46 deletions(-) diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am index a90477108..5a111433c 100644 --- a/src/dht/Makefile.am +++ b/src/dht/Makefile.am @@ -83,8 +83,8 @@ TESTS = test_dht_api $(check_SCRIPTS) \ test_dht_twopeer \ test_dht_twopeer_put_get \ test_dht_twopeer_get_put \ - test_dht_twopeer_path_tracking -# test_dht_multipeer + test_dht_twopeer_path_tracking \ + test_dht_multipeer endif test_dht_api_SOURCES = \ diff --git a/src/dht/dht.h b/src/dht/dht.h index 479c3527d..2a6717788 100644 --- a/src/dht/dht.h +++ b/src/dht/dht.h @@ -31,7 +31,7 @@ /** * Size of the bloom filter the DHT uses to filter peers. */ -#define DHT_BLOOM_SIZE 1024 +#define DHT_BLOOM_SIZE 128 /** diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 8a0e7943c..69d14ab78 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c @@ -56,7 +56,7 @@ /** * What is the maximum number of peers in a given bucket. */ -#define DEFAULT_BUCKET_SIZE 4 +#define DEFAULT_BUCKET_SIZE 8 /** * Desired replication level for FIND PEER requests @@ -559,6 +559,10 @@ add_known_to_bloom (void *cls, const GNUNET_HashCode * key, void *value) GNUNET_HashCode mh; GNUNET_BLOCK_mingle_hash (key, ctx->bf_mutator, &mh); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Adding known peer (%s) to bloomfilter for FIND PEER with mutation %u\n", + GNUNET_h2s (key), + ctx->bf_mutator); GNUNET_CONTAINER_bloomfilter_add (ctx->bloom, &mh); return GNUNET_YES; } @@ -643,7 +647,7 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, /* Check for connect to self message */ if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) return; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected %s to %s\n", GNUNET_i2s (&my_identity), GNUNET_h2s (&peer->hashPubKey)); @@ -705,7 +709,7 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) /* Check for disconnect from self message */ if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) return; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnected %s from %s\n", GNUNET_i2s (&my_identity), GNUNET_h2s (&peer->hashPubKey)); @@ -777,16 +781,28 @@ core_transmit_notify (void *cls, size_t size, void *buf) size_t msize; peer->th = NULL; - if (buf == NULL) + while ( (NULL != (pending = peer->head)) && + (GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value == 0) ) { - /* client disconnected */ - return 0; + peer->pending_count--; + GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending); + GNUNET_free (pending); } - if (peer->head == NULL) + if (pending == NULL) { /* no messages pending */ return 0; } + if (buf == NULL) + { + peer->th + = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, + pending->importance, + GNUNET_TIME_absolute_get_remaining (pending->timeout), + &peer->id, ntohs (pending->msg->size), + &core_transmit_notify, peer); + return 0; + } off = 0; while ( (NULL != (pending = peer->head)) && (size - off >= (msize = ntohs (pending->msg->size))) ) @@ -857,12 +873,12 @@ get_forward_count (uint32_t hop_count, uint32_t forward_count; float target_value; - if (hop_count > GDS_NSE_get () * 4.0) + if (hop_count > GDS_NSE_get () * 6.0) { /* forcefully terminate */ return 0; } - if (hop_count > GDS_NSE_get () * 2.0) + if (hop_count > GDS_NSE_get () * 4.0) { /* Once we have reached our ideal number of hops, only forward to 1 peer */ return 1; @@ -1046,7 +1062,7 @@ select_peer (const GNUNET_HashCode *key, } else { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Excluded peer `%s' due to BF match in greedy routing for %s\n", GNUNET_i2s (&pos->id), GNUNET_h2s (key)); @@ -1080,7 +1096,7 @@ select_peer (const GNUNET_HashCode *key, GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# Peers excluded from routing due to Bloomfilter"), 1, GNUNET_NO); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Excluded peer `%s' due to BF match in random routing for %s\n", GNUNET_i2s (&pos->id), GNUNET_h2s (key)); @@ -1164,15 +1180,15 @@ get_target_peers (const GNUNET_HashCode *key, rtargets[off] = nxt; GNUNET_break (GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (bloom, &nxt->id.hashPubKey)); + GNUNET_CONTAINER_bloomfilter_add (bloom, &rtargets[off]->id.hashPubKey); } - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Selected %u/%u peers at hop %u for %s (target was %u)\n", off, GNUNET_CONTAINER_multihashmap_size (all_known_peers), (unsigned int) hop_count, GNUNET_h2s (key), ret); - if (0 == off) { GNUNET_free (rtargets); @@ -1180,8 +1196,6 @@ get_target_peers (const GNUNET_HashCode *key, return 0; } *targets = rtargets; - for (ret = 0; ret < off; ret++) - GNUNET_CONTAINER_bloomfilter_add (bloom, &rtargets[ret]->id.hashPubKey); return off; } @@ -1228,6 +1242,10 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, struct GNUNET_PeerIdentity *pp; GNUNET_assert (NULL != bf); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Adding myself (%s) to PUT bloomfilter for %s\n", + GNUNET_i2s (&my_identity), + GNUNET_h2s (key)); GNUNET_CONTAINER_bloomfilter_add (bf, &my_identity.hashPubKey); GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# PUT requests routed"), 1, @@ -1237,7 +1255,7 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, &targets); if (0 == target_count) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Routing PUT for %s terminates after %u hops at %s\n", GNUNET_h2s (key), (unsigned int) hop_count, @@ -1261,7 +1279,7 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, for (i=0;ikey), GNUNET_i2s (&my_identity)); @@ -1810,7 +1832,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, &get->key, xquery, xquery_size, reply_bf, get->bf_mutator); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GET for %s at %s after %u hops\n", GNUNET_h2s (&get->key), GNUNET_i2s (&my_identity), diff --git a/src/dht/multipeer_topo.dat b/src/dht/multipeer_topo.dat index cb950a611..1233e6b66 100644 --- a/src/dht/multipeer_topo.dat +++ b/src/dht/multipeer_topo.dat @@ -9,3 +9,23 @@ 8:9 9:10 10:1 +4:2 +5:3 +6:4 +7:5 +8:6 +9:7 +10:8 +1:9 +2:10 +3:1 +6:2 +7:3 +8:4 +9:5 +10:6 +1:7 +2:8 +3:9 +4:10 +5:1 diff --git a/src/dht/test_dht_multipeer.c b/src/dht/test_dht_multipeer.c index 82d9aa55d..76c10701d 100644 --- a/src/dht/test_dht_multipeer.c +++ b/src/dht/test_dht_multipeer.c @@ -34,10 +34,10 @@ #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30) /* Timeout for waiting for replies to get requests */ -#define GET_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) +#define GET_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300) /* */ -#define START_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) +#define START_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) /* Timeout for waiting for gets to complete */ #define GET_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 50) @@ -50,11 +50,11 @@ #define TEST_DATA_SIZE 8 -#define MAX_OUTSTANDING_PUTS 10 +#define MAX_OUTSTANDING_PUTS 100 -#define MAX_OUTSTANDING_GETS 10 +#define MAX_OUTSTANDING_GETS 100 -#define PATH_TRACKING GNUNET_YES +#define PATH_TRACKING GNUNET_NO @@ -348,9 +348,6 @@ get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_DHT_disconnect (test_get->dht_handle); test_get->dht_handle = NULL; - fprintf (stderr, - "%llu gets succeeded, %llu gets failed!\n", - gets_completed, gets_failed); GNUNET_CONTAINER_DLL_remove (all_gets_head, all_gets_tail, test_get); @@ -358,6 +355,9 @@ get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if ((gets_failed > 0) && (outstanding_gets == 0)) /* Had some failures */ { + fprintf (stderr, + "%llu gets succeeded, %llu gets failed!\n", + gets_completed, gets_failed); GNUNET_SCHEDULER_cancel (die_task); die_task = GNUNET_SCHEDULER_add_now (&end_badly, "not all gets succeeded"); return; @@ -394,7 +394,6 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, struct TestGetContext *test_get = cls; GNUNET_HashCode search_key; /* Key stored under */ char original_data[TEST_DATA_SIZE]; /* Made up data to store */ - unsigned int i; memset (original_data, test_get->uid, sizeof (original_data)); GNUNET_CRYPTO_hash (original_data, TEST_DATA_SIZE, &search_key); @@ -404,6 +403,8 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, #if PATH_TRACKING if (put_path != NULL) { + unsigned int i; + fprintf (stderr, "PUT (%u) Path: ", test_get->uid); for (i = 0; iuid); for (i = 0; i < get_path_length; i++) @@ -485,29 +488,20 @@ put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) /** - * Called when the PUT request has been transmitted to the DHT service. - * Schedule the GET request for some time in the future. + * Schedule the GET requests */ static void -put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +start_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - struct TestPutContext *test_put = cls; unsigned long long i; unsigned long long j; struct TestGetContext *test_get; - outstanding_puts--; - puts_completed++; - GNUNET_SCHEDULER_cancel (test_put->task); - test_put->task = - GNUNET_SCHEDULER_add_now (&put_disconnect_task, test_put); - if (puts_completed != num_peers * num_peers) - return; - - GNUNET_assert (outstanding_puts == 0); +#if VERBOSE fprintf (stderr, "Issuing %llu GETs\n", num_peers * num_peers); +#endif for (i = 0; i < num_peers; i++) for (j = 0; j < num_peers; j++) { @@ -523,6 +517,29 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } +/** + * Called when the PUT request has been transmitted to the DHT service. + */ +static void +put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct TestPutContext *test_put = cls; + + outstanding_puts--; + puts_completed++; + GNUNET_SCHEDULER_cancel (test_put->task); + test_put->task = + GNUNET_SCHEDULER_add_now (&put_disconnect_task, test_put); + if (puts_completed != num_peers * num_peers) + return; + + GNUNET_assert (outstanding_puts == 0); + GNUNET_SCHEDULER_add_delayed (START_DELAY, + &start_gets, + NULL); +} + + /** * Set up some data, and call API PUT function */ -- 2.25.1