fixing bloomfilter code, fixing testcase
authorChristian Grothoff <christian@grothoff.org>
Fri, 30 Sep 2011 20:55:21 +0000 (20:55 +0000)
committerChristian Grothoff <christian@grothoff.org>
Fri, 30 Sep 2011 20:55:21 +0000 (20:55 +0000)
src/dht/Makefile.am
src/dht/dht.h
src/dht/gnunet-service-dht_neighbours.c
src/dht/multipeer_topo.dat
src/dht/test_dht_multipeer.c

index a90477108db88818c2dbe5baa9f37a12117fac57..5a111433c692c13a19a21582759b4ed09d5fadaf 100644 (file)
@@ -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 = \
index 479c3527deed7c626c060926808cbfa24f89a052..2a67177889ddd9cc5e205ef7ed5c078c868917f8 100644 (file)
@@ -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
 
 
 /**
index 8a0e7943ca9a8a8df66bc41efa495e0abc0b6e4f..69d14ab78aca30f02e7ac3d91d93c99111c93527 100644 (file)
@@ -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;i<target_count;i++)
   {
     target = targets[i];
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Routing PUT for %s after %u hops to %s\n",
                GNUNET_h2s (key),
                (unsigned int) hop_count,
@@ -1344,10 +1362,14 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
   target_count = get_target_peers (key, peer_bf, hop_count,
                                   desired_replication_level,
                                   &targets);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Adding myself (%s) to GET bloomfilter for %s\n",
+             GNUNET_i2s (&my_identity),
+             GNUNET_h2s (key));
   GNUNET_CONTAINER_bloomfilter_add (peer_bf, &my_identity.hashPubKey);
   if (0 == target_count)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                  "Routing GET for %s terminates after %u hops at %s\n",
                  GNUNET_h2s (key),
                  (unsigned int) hop_count,
@@ -1368,7 +1390,7 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
   for (i=0;i<target_count;i++)
   {
     target = targets[i];
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Routing GET for %s after %u hops to %s\n",
                GNUNET_h2s (key),
                (unsigned int) hop_count,
@@ -1576,7 +1598,7 @@ handle_dht_p2p_put (void *cls,
     /* cannot verify, good luck */
     break;
   }
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "PUT for %s at %s\n",
              GNUNET_h2s (&put->key),
              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),
index cb950a611aefacb72e07238c7d062c73056915a6..1233e6b66e7d04564e57cd05781547aaa48c9344 100644 (file)
@@ -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
index 82d9aa55d7440a7b6ba88dee751e1ccb8f088f5f..76c10701d9d7928d722f5028a3f3b897ee2ed238 100644 (file)
 #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)
 
 #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; i<put_path_length; i++)
@@ -412,6 +413,8 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
   }
   if (get_path != NULL)
   {
+    unsigned int i;
+
     fprintf (stderr, "GET (%u) Path: ",
             test_get->uid);
     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
  */