print stat
[oweals/gnunet.git] / src / dht / gnunet-service-dht_neighbours.c
index f9e31310eef7ea8374bc97b9e5d007886732a1b7..e1491a263d96742cabd9335ba7398969ec78c22e 100644 (file)
@@ -28,6 +28,7 @@
 #include "platform.h"
 #include "gnunet_block_lib.h"
 #include "gnunet_util_lib.h"
+#include "gnunet_hello_lib.h"
 #include "gnunet_constants.h"
 #include "gnunet_protocols.h"
 #include "gnunet_nse_service.h"
 #include "gnunet_hello_lib.h"
 #include "gnunet_dht_service.h"
 #include "gnunet_statistics_service.h"
-#include "dht.h"
 #include "gnunet-service-dht.h"
 #include "gnunet-service-dht_clients.h"
 #include "gnunet-service-dht_datacache.h"
+#include "gnunet-service-dht_hello.h"
+#include "gnunet-service-dht_neighbours.h"
 #include "gnunet-service-dht_nse.h"
 #include "gnunet-service-dht_routing.h"
 #include <fenv.h>
+#include "dht.h"
 
 /**
  * How many buckets will we allow total.
 /**
  * What is the maximum number of peers in a given bucket.
  */
-#define DEFAULT_BUCKET_SIZE 4
-
-/**
- * Size of the bloom filter the DHT uses to filter peers.
- */
-#define DHT_BLOOM_SIZE 128
+#define DEFAULT_BUCKET_SIZE 8
 
 /**
  * Desired replication level for FIND PEER requests
 /**
  * How long at least to wait before sending another find peer request.
  */
-#define DHT_MINIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2)
+#define DHT_MINIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)
 
 /**
  * How long at most to wait before sending another find peer request.
  */
-#define DHT_MAXIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 8)
+#define DHT_MAXIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 10)
 
 /**
  * How long at most to wait for transmission of a GET request to another peer?
@@ -325,11 +323,6 @@ struct PeerInfo
    */
   struct GNUNET_CORE_InformationRequestContext *info_ctx;
 
-  /**
-   * Task for scheduling message sends.
-   */
-  GNUNET_SCHEDULER_TaskIdentifier send_task;
-
   /**
    * Task for scheduling preference updates
    */
@@ -419,6 +412,7 @@ static struct GNUNET_PeerIdentity my_identity;
 static struct GNUNET_CORE_Handle *coreAPI;
 
 
+
 /**
  * Find the optimal bucket for this key.
  *
@@ -505,11 +499,14 @@ update_core_preference (void *cls,
                                      &peer->id.hashPubKey);
   if (matching >= 64)
     matching = 63;
-  bucket = find_bucket(&peer->id.hashPubKey);
+  bucket = find_bucket (&peer->id.hashPubKey);
   if (bucket == GNUNET_SYSERR)
     preference = 0;
   else
+  {
+    GNUNET_assert (k_buckets[bucket].peers_size != 0);
     preference = (1LL << matching) / k_buckets[bucket].peers_size;
+  }
   if (preference == 0)
     {
       peer->preference_task
@@ -517,6 +514,9 @@ update_core_preference (void *cls,
                                        &update_core_preference, peer);
       return;
     }
+  GNUNET_STATISTICS_update (GDS_stats,
+                           gettext_noop ("# Preference updates given to core"), 1,
+                           GNUNET_NO);
   peer->info_ctx =
     GNUNET_CORE_peer_change_preference (coreAPI, &peer->id,
                                        GNUNET_TIME_UNIT_FOREVER_REL,
@@ -526,6 +526,110 @@ update_core_preference (void *cls,
 }
 
 
+/**
+ * Closure for 'add_known_to_bloom'.
+ */
+struct BloomConstructorContext
+{
+  /**
+   * Bloom filter under construction.
+   */
+  struct GNUNET_CONTAINER_BloomFilter *bloom;
+
+  /**
+   * Mutator to use.
+   */
+  uint32_t bf_mutator;
+};
+
+
+/**
+ * Add each of the peers we already know to the bloom filter of
+ * the request so that we don't get duplicate HELLOs.
+ *
+ * @param cls the 'struct BloomConstructorContext'.
+ * @param key peer identity to add to the bloom filter
+ * @param value value the peer information (unused)
+ * @return GNUNET_YES (we should continue to iterate)
+ */
+static int
+add_known_to_bloom (void *cls, const GNUNET_HashCode * key, void *value)
+{
+  struct BloomConstructorContext *ctx = cls;
+  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;
+}
+
+
+/**
+ * Task to send a find peer message for our own peer identifier
+ * so that we can find the closest peers in the network to ourselves
+ * and attempt to connect to them.
+ *
+ * @param cls closure for this task
+ * @param tc the context under which the task is running
+ */
+static void
+send_find_peer_message (void *cls,
+                        const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  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)
+    return;
+  if (newly_found_peers > bucket_size) 
+  {
+    /* If we are finding many peers already, no need to send out our request right now! */
+    find_peer_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+                                                  &send_find_peer_message, NULL);
+    newly_found_peers = 0;
+    return;
+  }
+  bcc.bf_mutator = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
+  bcc.bloom =
+    GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, GNUNET_CONSTANTS_BLOOMFILTER_K);
+  GNUNET_CONTAINER_multihashmap_iterate (all_known_peers, 
+                                        &add_known_to_bloom,
+                                         &bcc);
+  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,
+                            FIND_PEER_REPLICATION_LEVEL,
+                            0,
+                            &my_identity.hashPubKey,
+                            NULL, 0,
+                            bcc.bloom, bcc.bf_mutator, 
+                            peer_bf);
+  GNUNET_CONTAINER_bloomfilter_free (peer_bf);
+  GNUNET_CONTAINER_bloomfilter_free (bcc.bloom);
+  /* schedule next round */
+  next_send_time.rel_value =
+    DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value +
+    GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+                             DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / (newly_found_peers+1));
+  newly_found_peers = 0;
+  find_peer_task = GNUNET_SCHEDULER_add_delayed (next_send_time, 
+                                                &send_find_peer_message,
+                                                NULL);  
+}
+
+
 /**
  * Method called whenever a peer connects.
  *
@@ -543,6 +647,10 @@ 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_DEBUG,
+             "Connected %s to %s\n",
+             GNUNET_i2s (&my_identity),
+             GNUNET_h2s (&peer->hashPubKey));
   if (GNUNET_YES ==
       GNUNET_CONTAINER_multihashmap_contains (all_known_peers,
                                               &peer->hashPubKey))
@@ -550,6 +658,9 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
     GNUNET_break (0);
     return;
   }
+  GNUNET_STATISTICS_update (GDS_stats,
+                           gettext_noop ("# Peers connected"), 1,
+                           GNUNET_NO);
   peer_bucket = find_bucket (&peer->hashPubKey);
   GNUNET_assert ( (peer_bucket >= 0) && (peer_bucket < MAX_BUCKETS) );
   ret = GNUNET_malloc (sizeof (struct PeerInfo));
@@ -565,12 +676,20 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
                               peer_bucket);
   if ( (peer_bucket > 0) &&
        (k_buckets[peer_bucket].peers_size <= bucket_size) )
+  {
     ret->preference_task = GNUNET_SCHEDULER_add_now (&update_core_preference, ret);
-  newly_found_peers++;
+    newly_found_peers++;
+  }
   GNUNET_assert (GNUNET_OK ==
                 GNUNET_CONTAINER_multihashmap_put (all_known_peers, 
                                                    &peer->hashPubKey, ret,
                                                    GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+  if (1 == GNUNET_CONTAINER_multihashmap_size (all_known_peers))
+  {
+    /* got a first connection, good time to start with FIND PEER requests... */
+    find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message,
+                                              NULL);    
+  }
 }
 
 
@@ -586,10 +705,15 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
   struct PeerInfo *to_remove;
   int current_bucket;
   struct P2PPendingMessage *pos;
+  unsigned int discarded;
 
   /* Check for disconnect from self message */
   if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
     return;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Disconnected %s from %s\n",
+             GNUNET_i2s (&my_identity),
+             GNUNET_h2s (&peer->hashPubKey));
   to_remove =
       GNUNET_CONTAINER_multihashmap_get (all_known_peers, &peer->hashPubKey);
   if (NULL == to_remove)
@@ -597,6 +721,9 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
       GNUNET_break (0);
       return;
     }
+  GNUNET_STATISTICS_update (GDS_stats,
+                           gettext_noop ("# Peers connected"), -1,
+                           GNUNET_NO);
   GNUNET_assert (GNUNET_YES ==
                  GNUNET_CONTAINER_multihashmap_remove (all_known_peers,
                                                        &peer->hashPubKey,
@@ -606,6 +733,11 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
     GNUNET_CORE_peer_change_preference_cancel (to_remove->info_ctx);
     to_remove->info_ctx = NULL;
   }
+  if (GNUNET_SCHEDULER_NO_TASK != to_remove->preference_task)
+  {
+    GNUNET_SCHEDULER_cancel (to_remove->preference_task);
+    to_remove->preference_task = GNUNET_SCHEDULER_NO_TASK;
+  }
   current_bucket = find_bucket (&to_remove->id.hashPubKey);
   GNUNET_CONTAINER_DLL_remove (k_buckets[current_bucket].head,
                               k_buckets[current_bucket].tail,
@@ -621,13 +753,19 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
     GNUNET_CORE_notify_transmit_ready_cancel (to_remove->th);
     to_remove->th = NULL;
   }
+  discarded = 0;
   while (NULL != (pos = to_remove->head))
   {
     GNUNET_CONTAINER_DLL_remove (to_remove->head,
                                 to_remove->tail,
                                 pos);
+    discarded++;
     GNUNET_free (pos);
   }
+  GNUNET_STATISTICS_update (GDS_stats,
+                           gettext_noop ("# Queued messages discarded (peer disconnected)"), discarded,
+                           GNUNET_NO);
+  GNUNET_free (to_remove);
 }
 
 
@@ -650,20 +788,36 @@ 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);
+    GNUNET_break (NULL != peer->th);
+    return 0;
+  }
   off = 0;
   while ( (NULL != (pending = peer->head)) &&
          (size - off >= (msize = ntohs (pending->msg->size))) )
   {
+    GNUNET_STATISTICS_update (GDS_stats,
+                             gettext_noop ("# Bytes transmitted to other peers"), msize,
+                             GNUNET_NO);
     memcpy (&cbuf[off], pending->msg, msize);
     off += msize;
     peer->pending_count--;
@@ -671,12 +825,15 @@ 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),
+                                          pending->importance,
+                                          GNUNET_TIME_absolute_get_remaining (pending->timeout),
                                           &peer->id, msize,
-                                           &core_transmit_notify, peer);
+                                          &core_transmit_notify, peer);
+    GNUNET_break (NULL != peer->th);
+  }
   return off;
 }
 
@@ -691,10 +848,14 @@ process_peer_queue (struct PeerInfo *peer)
 {
   struct P2PPendingMessage *pending;
 
-  if (NULL != (pending = peer->head))
+  if (NULL == (pending = peer->head))
     return;
   if (NULL != peer->th)
     return;
+  GNUNET_STATISTICS_update (GDS_stats,
+                           gettext_noop ("# Bytes of bandwdith requested from core"),
+                           ntohs (pending->msg->size),
+                           GNUNET_NO);
   peer->th 
     = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES,
                                         pending->importance,
@@ -702,6 +863,7 @@ process_peer_queue (struct PeerInfo *peer)
                                         &peer->id,
                                         ntohs (pending->msg->size),
                                         &core_transmit_notify, peer);
+  GNUNET_break (NULL != peer->th);
 }
 
 
@@ -721,12 +883,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;
@@ -743,7 +905,7 @@ get_forward_count (uint32_t hop_count,
   /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */
   target_value = target_value - forward_count;
   random_value =
-    GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, UINT32_MAX); 
+    GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); 
   if (random_value < (target_value * UINT32_MAX))
     forward_count++;
   return forward_count;
@@ -828,13 +990,11 @@ am_closest_peer (const GNUNET_HashCode *key,
   int bucket_num;
   int count;
   struct PeerInfo *pos;
-  unsigned int my_distance;
 
   if (0 == memcmp (&my_identity.hashPubKey, key, sizeof (GNUNET_HashCode)))
     return GNUNET_YES;
   bucket_num = find_bucket (key);
   bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, key);
-  my_distance = get_distance (&my_identity.hashPubKey, key);
   pos = k_buckets[bucket_num].head;
   count = 0;
   while ((pos != NULL) && (count < bucket_size))
@@ -893,15 +1053,16 @@ select_peer (const GNUNET_HashCode *key,
     /* greedy selection (closest peer that is not in bloomfilter) */
     smallest_distance = UINT_MAX;
     chosen = NULL;
-    for (bc = closest_bucket; bc < MAX_BUCKETS; bc++)
+    for (bc = 0; bc < closest_bucket; bc++)
     {
       pos = k_buckets[bc].head;
       count = 0;
       while ((pos != NULL) && (count < bucket_size))
       {
-        if (GNUNET_NO ==
-            GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
-        {
+        if ( (bloom == NULL) ||
+            (GNUNET_NO ==
+             GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) )
+       {
           dist = get_distance (key, &pos->id.hashPubKey);
           if (dist < smallest_distance)
           {
@@ -909,10 +1070,24 @@ select_peer (const GNUNET_HashCode *key,
             smallest_distance = dist;
           }
         }
+        else
+       {
+         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));
+         GNUNET_STATISTICS_update (GDS_stats,
+                                   gettext_noop ("# Peers excluded from routing due to Bloomfilter"), 1,
+                                   GNUNET_NO);
+       }
         count++;
         pos = pos->next;
       }
     }
+    if (NULL == chosen)
+      GNUNET_STATISTICS_update (GDS_stats,
+                               gettext_noop ("# Peer selection failed"), 1,
+                               GNUNET_NO);
     return chosen;
   }
 
@@ -924,9 +1099,17 @@ select_peer (const GNUNET_HashCode *key,
     pos = k_buckets[bc].head;
     while ((pos != NULL) && (count < bucket_size))
     {
-      if (GNUNET_YES ==
-          GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
+      if ( (bloom != NULL) &&
+          (GNUNET_YES ==
+           GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) )
       {
+       GNUNET_STATISTICS_update (GDS_stats,
+                                 gettext_noop ("# Peers excluded from routing due to Bloomfilter"), 1,
+                                 GNUNET_NO);
+       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));
         pos = pos->next;
         continue;               /* Ignore bloomfiltered peers */
       }
@@ -936,6 +1119,9 @@ select_peer (const GNUNET_HashCode *key,
   }
   if (count == 0)               /* No peers to select from! */
   {
+    GNUNET_STATISTICS_update (GDS_stats,
+                             gettext_noop ("# Peer selection failed"), 1,
+                             GNUNET_NO);
     return NULL;
   }
   /* Now actually choose a peer */
@@ -946,8 +1132,9 @@ select_peer (const GNUNET_HashCode *key,
     pos = k_buckets[bc].head;
     while ((pos != NULL) && (count < bucket_size))
     {
-      if (GNUNET_YES ==
-          GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
+      if ( (bloom != NULL) &&
+          (GNUNET_YES ==
+           GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) )
       {
         pos = pos->next;
         continue;               /* Ignore bloomfiltered peers */
@@ -987,6 +1174,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)
   {
@@ -994,15 +1182,23 @@ get_target_peers (const GNUNET_HashCode *key,
     return 0;
   }
   rtargets = GNUNET_malloc (sizeof (struct PeerInfo*) * ret);
-  off = 0;
-  while (ret-- > 0)
+  for (off = 0; off < ret; off++)
   {
     nxt = select_peer (key, bloom, hop_count);
     if (nxt == NULL)
-      break;
-    rtargets[off++] = nxt;
-    GNUNET_CONTAINER_bloomfilter_add (bloom, &nxt->id.hashPubKey);
+      break;      
+    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_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);
@@ -1055,11 +1251,27 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
   struct PeerPutMessage *ppm;
   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,
+                           GNUNET_NO);
   target_count = get_target_peers (key, bf, hop_count,
                                   desired_replication_level,
                                   &targets);
   if (0 == target_count)
-    return;
+    { 
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                 "Routing PUT for %s terminates after %u hops at %s\n",
+                 GNUNET_h2s (key),
+                 (unsigned int) hop_count,
+                 GNUNET_i2s (&my_identity));
+      return;
+    }
   msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + sizeof (struct PeerPutMessage);
   if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
   {
@@ -1071,9 +1283,17 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
     GNUNET_break (0);
     return;
   }
+  GNUNET_STATISTICS_update (GDS_stats,
+                           gettext_noop ("# PUT messages queued for transmission"), target_count,
+                           GNUNET_NO);
   for (i=0;i<target_count;i++)
   {
     target = targets[i];
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+               "Routing PUT for %s after %u hops to %s\n",
+               GNUNET_h2s (key),
+               (unsigned int) hop_count,
+               GNUNET_i2s (&target->id));
     pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
     pending->importance = 0; /* FIXME */
     pending->timeout = expiration_time;   
@@ -1087,6 +1307,7 @@ 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);
+    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,
@@ -1143,12 +1364,28 @@ 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_STATISTICS_update (GDS_stats,
+                           gettext_noop ("# GET requests routed"), 1,
+                           GNUNET_NO);
   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)
-    return;
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                 "Routing GET for %s terminates after %u hops at %s\n",
+                 GNUNET_h2s (key),
+                 (unsigned int) hop_count,
+                 GNUNET_i2s (&my_identity));
+      return;
+    }
   reply_bf_size = GNUNET_CONTAINER_bloomfilter_get_size (reply_bf);
   msize = xquery_size + sizeof (struct PeerGetMessage) + reply_bf_size;
   if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
@@ -1156,10 +1393,18 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
     GNUNET_break (0);
     return;
   }
+  GNUNET_STATISTICS_update (GDS_stats,
+                           gettext_noop ("# GET messages queued for transmission"), target_count,
+                           GNUNET_NO);
   /* forward request */
   for (i=0;i<target_count;i++)
   {
     target = targets[i];
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+               "Routing GET for %s after %u hops to %s\n",
+               GNUNET_h2s (key),
+               (unsigned int) hop_count,
+               GNUNET_i2s (&target->id));
     pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 
     pending->importance = 0; /* FIXME */
     pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT);
@@ -1173,6 +1418,7 @@ 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; 
+    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,
@@ -1180,10 +1426,11 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
     pgm->key = *key;
     xq = (char *) &pgm[1];
     memcpy (xq, xquery, xquery_size);
-    GNUNET_assert (GNUNET_OK ==
-                  GNUNET_CONTAINER_bloomfilter_get_raw_data (reply_bf,
-                                                             &xq[xquery_size],
-                                                             reply_bf_size));
+    if (NULL != reply_bf)
+      GNUNET_assert (GNUNET_OK ==
+                    GNUNET_CONTAINER_bloomfilter_get_raw_data (reply_bf,
+                                                               &xq[xquery_size],
+                                                               reply_bf_size));
     GNUNET_CONTAINER_DLL_insert_tail (target->head,
                                      target->tail,
                                      pending);
@@ -1216,9 +1463,9 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
                             struct GNUNET_TIME_Absolute expiration_time,
                             const GNUNET_HashCode *key,
                             unsigned int put_path_length,
-                            struct GNUNET_PeerIdentity *put_path,
+                            const struct GNUNET_PeerIdentity *put_path,
                             unsigned int get_path_length,
-                            struct GNUNET_PeerIdentity *get_path,
+                            const struct GNUNET_PeerIdentity *get_path,
                             const void *data,
                             size_t data_size)
 {
@@ -1245,6 +1492,9 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
     /* peer disconnected in the meantime, drop reply */
     return;
   }
+  GNUNET_STATISTICS_update (GDS_stats,
+                           gettext_noop ("# RESULT messages queued for transmission"), 1,
+                           GNUNET_NO);
   pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 
   pending->importance = 0; /* FIXME */
   pending->timeout = expiration_time;
@@ -1271,97 +1521,6 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
 }
 
 
-/**
- * Closure for 'add_known_to_bloom'.
- */
-struct BloomConstructorContext
-{
-  /**
-   * Bloom filter under construction.
-   */
-  struct GNUNET_CONTAINER_BloomFilter *bloom;
-
-  /**
-   * Mutator to use.
-   */
-  uint32_t bf_mutator;
-};
-
-
-/**
- * Add each of the peers we already know to the bloom filter of
- * the request so that we don't get duplicate HELLOs.
- *
- * @param cls the 'struct BloomConstructorContext'.
- * @param key peer identity to add to the bloom filter
- * @param value value the peer information (unused)
- * @return GNUNET_YES (we should continue to iterate)
- */
-static int
-add_known_to_bloom (void *cls, const GNUNET_HashCode * key, void *value)
-{
-  struct BloomConstructorContext *ctx = cls;
-  GNUNET_HashCode mh;
-
-  GNUNET_BLOCK_mingle_hash (key, ctx->bf_mutator, &mh);
-  GNUNET_CONTAINER_bloomfilter_add (ctx->bloom, &mh);
-  return GNUNET_YES;
-}
-
-
-/**
- * Task to send a find peer message for our own peer identifier
- * so that we can find the closest peers in the network to ourselves
- * and attempt to connect to them.
- *
- * @param cls closure for this task
- * @param tc the context under which the task is running
- */
-static void
-send_find_peer_message (void *cls,
-                        const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  struct GNUNET_TIME_Relative next_send_time;
-  struct BloomConstructorContext bcc;
-
-  find_peer_task = GNUNET_SCHEDULER_NO_TASK;
-  if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
-    return;
-  if (newly_found_peers > bucket_size) 
-  {
-    /* If we are finding many peers already, no need to send out our request right now! */
-    find_peer_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
-                                                  &send_find_peer_message, NULL);
-    newly_found_peers = 0;
-    return;
-  }
-  bcc.bf_mutator = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
-  bcc.bloom =
-    GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
-  GNUNET_CONTAINER_multihashmap_iterate (all_known_peers, 
-                                        &add_known_to_bloom,
-                                         &bcc);
-  // FIXME: pass priority!?
-  GDS_NEIGHBOURS_handle_get (GNUNET_BLOCK_TYPE_DHT_HELLO,
-                            GNUNET_DHT_RO_FIND_PEER,
-                            FIND_PEER_REPLICATION_LEVEL,
-                            0,
-                            &my_identity.hashPubKey,
-                            NULL, 0,
-                            bcc.bloom, bcc.bf_mutator, NULL);
-  GNUNET_CONTAINER_bloomfilter_free (bcc.bloom);
-  /* schedule next round */
-  newly_found_peers = 0;
-  next_send_time.rel_value =
-    (DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / 2) +
-    GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
-                             DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / 2);
-  find_peer_task = GNUNET_SCHEDULER_add_delayed (next_send_time, 
-                                                &send_find_peer_message,
-                                                NULL);  
-}
-
-
 /**
  * To be called on core init/fail.
  *
@@ -1375,20 +1534,8 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server,
            const struct GNUNET_PeerIdentity *identity,
            const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
 {
-  struct GNUNET_TIME_Relative next_send_time;
-
   GNUNET_assert (server != NULL);
   my_identity = *identity;
-  /* FIXME: do upon 1st connect instead! */
-  next_send_time.rel_value =
-    DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value +
-    GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
-                             (DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value /
-                              2) -
-                             DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value);
-  find_peer_task = GNUNET_SCHEDULER_add_delayed (next_send_time,
-                                                &send_find_peer_message,
-                                                NULL);
 }
 
 
@@ -1434,6 +1581,9 @@ handle_dht_p2p_put (void *cls,
       GNUNET_break_op (0);
       return GNUNET_YES;
     }
+  GNUNET_STATISTICS_update (GDS_stats,
+                           gettext_noop ("# P2P PUT requests received"), 1,
+                           GNUNET_NO);
   put_path = (const struct GNUNET_PeerIdentity*) &put[1];  
   payload = &put_path[putlen];
   options = ntohl (put->options);
@@ -1458,9 +1608,14 @@ handle_dht_p2p_put (void *cls,
     /* cannot verify, good luck */
     break;
   }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "PUT for %s at %s\n",
+             GNUNET_h2s (&put->key),
+             GNUNET_i2s (&my_identity));
   bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter,
                                          DHT_BLOOM_SIZE,
-                                         DHT_BLOOM_K);
+                                         GNUNET_CONSTANTS_BLOOMFILTER_K);
+  GNUNET_break_op (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &peer->hashPubKey));
   {
     struct GNUNET_PeerIdentity pp[putlen+1];
   
@@ -1475,7 +1630,7 @@ handle_dht_p2p_put (void *cls,
       putlen = 0;
     
     /* give to local clients */
-    GDS_CLIENT_handle_reply (GNUNET_TIME_absolute_ntoh (put->expiration_time),
+    GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (put->expiration_time),
                             &put->key,
                             0, NULL,
                             putlen,
@@ -1498,7 +1653,7 @@ handle_dht_p2p_put (void *cls,
                               options,
                               ntohl (put->desired_replication_level),
                               GNUNET_TIME_absolute_ntoh (put->expiration_time),
-                              ntohl (put->hop_count) + 1 /* who adds +1? */,
+                              ntohl (put->hop_count),
                               bf,
                               &put->key,
                               putlen, pp,
@@ -1510,6 +1665,101 @@ handle_dht_p2p_put (void *cls,
 }
 
 
+/**
+ * We have received a FIND PEER request.  Send matching
+ * HELLOs back.
+ *
+ * @param sender sender of the FIND PEER request
+ * @param key peers close to this key are desired
+ * @param bf peers matching this bf are excluded
+ * @param bf_mutator mutator for bf
+ */
+static void
+handle_find_peer (const struct GNUNET_PeerIdentity *sender,
+                 const GNUNET_HashCode *key,
+                 struct GNUNET_CONTAINER_BloomFilter *bf,
+                 uint32_t bf_mutator)
+{
+  int bucket_idx;
+  struct PeerBucket *bucket;
+  struct PeerInfo *peer;
+  unsigned int choice;
+  GNUNET_HashCode mhash;
+  const struct GNUNET_HELLO_Message *hello;
+
+  /* first, check about our own HELLO */
+  if (NULL != GDS_my_hello)
+  {
+    GNUNET_BLOCK_mingle_hash (&my_identity.hashPubKey, bf_mutator, &mhash);
+    if ( (NULL == bf) ||
+        (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)) )
+    {
+      GDS_NEIGHBOURS_handle_reply (sender,
+                                  GNUNET_BLOCK_TYPE_DHT_HELLO,
+                                  GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION),
+                                  key,
+                                  0, NULL,
+                                  0, NULL,
+                                  GDS_my_hello,
+                                  GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message*) GDS_my_hello));
+    }
+    else
+    {
+      GNUNET_STATISTICS_update (GDS_stats,
+                               gettext_noop ("# FIND PEER requests ignored due to Bloomfilter"), 1,
+                               GNUNET_NO);
+    }
+  }
+  else
+  {
+    GNUNET_STATISTICS_update (GDS_stats,
+                             gettext_noop ("# FIND PEER requests ignored due to lack of HELLO"), 1,
+                             GNUNET_NO);
+  }
+
+  /* then, also consider sending a random HELLO from the closest bucket */
+  if (0 == memcmp (&my_identity.hashPubKey, key, sizeof (GNUNET_HashCode)))
+    bucket_idx = closest_bucket;
+  else
+    bucket_idx = GNUNET_MIN (closest_bucket, find_bucket (key));
+  if (bucket_idx == GNUNET_SYSERR)
+    return;
+  bucket = &k_buckets[bucket_idx];
+  if (bucket->peers_size == 0)
+    return;
+  choice = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+                                    bucket->peers_size);
+  peer = bucket->head;
+  while (choice > 0)
+  {
+    GNUNET_assert (peer != NULL);
+    peer = peer->next;
+    choice--;
+  }
+  choice = bucket->peers_size;
+  do
+    {
+      peer = peer->next;
+      if (choice-- == 0)
+       return; /* no non-masked peer available */
+      if (peer == NULL)
+       peer = bucket->head;
+      GNUNET_BLOCK_mingle_hash (&peer->id.hashPubKey, bf_mutator, &mhash);
+      hello = GDS_HELLO_get (&peer->id);
+    }
+  while ( (hello == NULL) ||
+         (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)) );
+  GDS_NEIGHBOURS_handle_reply (sender,
+                              GNUNET_BLOCK_TYPE_DHT_HELLO,
+                              GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION),
+                              key,
+                              0, NULL,
+                              0, NULL,
+                              hello,
+                              GNUNET_HELLO_size (hello));    
+}
+
+
 /**
  * Core handler for p2p get requests.
  *
@@ -1537,7 +1787,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))
@@ -1552,6 +1803,9 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
     GNUNET_break_op (0);
     return GNUNET_YES;
   }
+  GNUNET_STATISTICS_update (GDS_stats,
+                           gettext_noop ("# P2P GET requests received"), 1,
+                           GNUNET_NO);
   reply_bf_size = msize - (sizeof (struct PeerGetMessage) + xquery_size);
   type = ntohl (get->type);
   options = ntohl (get->options);
@@ -1560,7 +1814,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
   if (reply_bf_size > 0)
     reply_bf = GNUNET_CONTAINER_bloomfilter_init (&xquery[xquery_size],
                                                  reply_bf_size,
-                                                 GNUNET_DHT_GET_BLOOMFILTER_K);
+                                                 GNUNET_CONSTANTS_BLOOMFILTER_K);
   eval = GNUNET_BLOCK_evaluate (GDS_block_context,
                                type,
                                &get->key,
@@ -1579,8 +1833,8 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
   peer_bf =
     GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, 
                                       DHT_BLOOM_SIZE,
-                                      DHT_BLOOM_K);
-
+                                      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,
@@ -1588,30 +1842,53 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
                   &get->key,
                   xquery, xquery_size,
                   reply_bf, get->bf_mutator);
-  /* FIXME: check options (find peer, local-processing-only-if-nearest, etc.!) */
-
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "GET for %s at %s after %u hops\n",
+             GNUNET_h2s (&get->key),
+             GNUNET_i2s (&my_identity),
+             (unsigned int) ntohl (get->hop_count));
   /* local lookup (this may update the reply_bf) */
   if ( (0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
        (am_closest_peer (&get->key,
                         peer_bf) ) )
-    GDS_DATACACHE_handle_get (&get->key,
-                             type,
-                             xquery, xquery_size,
-                             &reply_bf, 
-                             get->bf_mutator);
-  /* FIXME: should track if the local lookup resulted in a
-     definitive result and then NOT do P2P forwarding */
+    {
+    if ( (0 != (options & GNUNET_DHT_RO_FIND_PEER)))
+    {
+      GNUNET_STATISTICS_update (GDS_stats,
+                               gettext_noop ("# P2P FIND PEER requests processed"), 1,
+                               GNUNET_NO);
+      handle_find_peer (peer,
+                       &get->key,
+                       reply_bf,
+                       get->bf_mutator);
+    }
+    else
+    {
+      eval = GDS_DATACACHE_handle_get (&get->key,
+                                      type,
+                                      xquery, xquery_size,
+                                      &reply_bf, 
+                                      get->bf_mutator);
+    }
+  }
+  else
+  {
+    GNUNET_STATISTICS_update (GDS_stats,
+                             gettext_noop ("# P2P GET requests ONLY routed"), 1,
+                             GNUNET_NO);
+  }
   
-    /* P2P forwarding */
-  GDS_NEIGHBOURS_handle_get (type,
-                            options,
-                            ntohl (get->desired_replication_level),
-                            ntohl (get->hop_count) + 1, /* CHECK: where (else) do we do +1? */
-                            &get->key,
-                            xquery, xquery_size,
-                            reply_bf,
-                            get->bf_mutator,
-                            peer_bf);
+  /* P2P forwarding */
+  if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST)
+    GDS_NEIGHBOURS_handle_get (type,
+                              options,
+                              ntohl (get->desired_replication_level),
+                              ntohl (get->hop_count),
+                              &get->key,
+                              xquery, xquery_size,
+                              reply_bf,
+                              get->bf_mutator,
+                              peer_bf);
   /* clean up */
   if (NULL != reply_bf)
     GNUNET_CONTAINER_bloomfilter_free (reply_bf);
@@ -1663,12 +1940,58 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
     GNUNET_break_op (0);
     return GNUNET_YES;
   } 
+  GNUNET_STATISTICS_update (GDS_stats,
+                           gettext_noop ("# P2P RESULTS received"), 1,
+                           GNUNET_NO);
   put_path = (const struct GNUNET_PeerIdentity*) &prm[1];
   get_path = &put_path[put_path_length];
   type = ntohl (prm->type);
   data = (const void*) &get_path[get_path_length];
   data_size = msize - (sizeof (struct PeerResultMessage) + 
                       (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity));
+
+  /* if we got a HELLO, consider it for our own routing table */
+  if (type == GNUNET_BLOCK_TYPE_DHT_HELLO)
+  {
+    const struct GNUNET_MessageHeader *h;
+    struct GNUNET_PeerIdentity pid;
+    int bucket;
+
+    /* Should be a HELLO, validate and consider using it! */
+    if (data_size < sizeof (struct GNUNET_MessageHeader))
+    {
+      GNUNET_break_op (0);
+      return GNUNET_YES;
+    }
+    h = data;
+    if (data_size != ntohs (h->size))
+    {
+      GNUNET_break_op (0);
+      return GNUNET_YES;
+    }
+    if (GNUNET_OK !=
+       GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message*) h,
+                            &pid))
+    {
+      GNUNET_break_op (0);
+      return GNUNET_YES;
+    }
+    if (0 != memcmp (&my_identity, &pid, sizeof (struct GNUNET_PeerIdentity)))
+    {
+      bucket = find_bucket (&pid.hashPubKey);
+      if ( (bucket >= 0) &&
+          (k_buckets[bucket].peers_size < bucket_size) )
+       {    
+         if (NULL != GDS_transport_handle)
+           GNUNET_TRANSPORT_offer_hello (GDS_transport_handle,
+                                         h, NULL, NULL);
+         (void) GNUNET_CORE_peer_request_connect (coreAPI,
+                                                  &pid, 
+                                                  NULL, NULL);
+       }   
+    }
+  }
+
   /* append 'peer' to 'get_path' */
   {    
     struct GNUNET_PeerIdentity xget_path[get_path_length+1];
@@ -1678,7 +2001,7 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
     get_path_length++;
 
     /* forward to local clients */   
-    GDS_CLIENT_handle_reply (GNUNET_TIME_absolute_ntoh (prm->expiration_time),
+    GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (prm->expiration_time),
                             &prm->key,
                             get_path_length,
                             xget_path,
@@ -1736,20 +2059,6 @@ GDS_NEIGHBOURS_init ()
   if (coreAPI == NULL)
     return GNUNET_SYSERR;
   all_known_peers = GNUNET_CONTAINER_multihashmap_create (256);
-#if 0
-  struct GNUNET_TIME_Relative next_send_time;
-
-  // FIXME!
-  next_send_time.rel_value =
-    DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value +
-    GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
-                             (DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value /
-                              2) -
-                             DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value);
-  find_peer_task = GNUNET_SCHEDULER_add_delayed (next_send_time, 
-                                                &send_find_peer_message,
-                                                &find_peer_context);  
-#endif
   return GNUNET_OK;
 }
 
@@ -1776,10 +2085,3 @@ GDS_NEIGHBOURS_done ()
 
 
 /* end of gnunet-service-dht_neighbours.c */
-
-
-#if 0
-
-
-
-#endif