print stat
[oweals/gnunet.git] / src / dht / gnunet-service-dht_neighbours.c
index e5f9d0d2351053ceeea9a7e374305ad90643ac0a..e1491a263d96742cabd9335ba7398969ec78c22e 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
@@ -503,7 +503,10 @@ update_core_preference (void *cls,
   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
@@ -556,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;
 }
@@ -640,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));
@@ -698,11 +705,12 @@ 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_ERROR,
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Disconnected %s from %s\n",
              GNUNET_i2s (&my_identity),
              GNUNET_h2s (&peer->hashPubKey));
@@ -745,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);
 }
 
 
@@ -774,16 +788,29 @@ 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))) )
@@ -798,14 +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),
-                                            &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);
+    GNUNET_break (NULL != peer->th);
+  }
   return off;
 }
 
@@ -835,6 +863,7 @@ process_peer_queue (struct PeerInfo *peer)
                                         &peer->id,
                                         ntohs (pending->msg->size),
                                         &core_transmit_notify, peer);
+  GNUNET_break (NULL != peer->th);
 }
 
 
@@ -854,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;
@@ -1043,7 +1072,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));
@@ -1077,7 +1106,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));
@@ -1161,15 +1190,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);
@@ -1177,8 +1206,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;
 }
 
@@ -1225,6 +1252,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,
@@ -1234,7 +1265,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,
@@ -1253,12 +1284,12 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
     return;
   }
   GNUNET_STATISTICS_update (GDS_stats,
-                           gettext_noop ("# Peers selected as targets for PUT requests"), target_count,
+                           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_ERROR,
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Routing PUT for %s after %u hops to %s\n",
                GNUNET_h2s (key),
                (unsigned int) hop_count,
@@ -1341,10 +1372,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,
@@ -1359,13 +1394,13 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
     return;
   }
   GNUNET_STATISTICS_update (GDS_stats,
-                           gettext_noop ("# Peers selected as targets for GET requests"), target_count,
+                           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_ERROR,
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Routing GET for %s after %u hops to %s\n",
                GNUNET_h2s (key),
                (unsigned int) hop_count,
@@ -1458,7 +1493,7 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
     return;
   }
   GNUNET_STATISTICS_update (GDS_stats,
-                           gettext_noop ("# REPLIES routed"), 1,
+                           gettext_noop ("# RESULT messages queued for transmission"), 1,
                            GNUNET_NO);
   pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 
   pending->importance = 0; /* FIXME */
@@ -1573,7 +1608,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));
@@ -1807,7 +1842,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),