increase
[oweals/gnunet.git] / src / nse / gnunet-service-nse.c
index 61ab7e57ab60d3077295ad38b5fe5ef37e52ad58..32b81b080b3ae867a75587e17ba1868a023ce82d 100644 (file)
  */
 #define HISTORY_SIZE 64
 
-/**
- * Size of the queue to core.
- */
-#define CORE_QUEUE_SIZE 2
-
 /**
  * Message priority to use.
  */
@@ -303,6 +298,7 @@ static void
 setup_estimate_message (struct GNUNET_NSE_ClientMessage *em)
 {
   unsigned int i;
+  unsigned int j;
   double mean;
   double sum;
   double std_dev;
@@ -323,20 +319,19 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em)
   sumweight = 0.0;
   for (i = 0; i < estimate_count; i++)
   {
-    val =
-        htonl (size_estimate_messages
-               [(estimate_index - i +
-                 HISTORY_SIZE) % HISTORY_SIZE].matching_bits);
-    weight = 1;                 /* was: estimate_count + 1 - i; */
+    j = (estimate_index - i + HISTORY_SIZE) % HISTORY_SIZE;
+    val = htonl (size_estimate_messages[j].matching_bits);
+    weight = 1.0;              /* was: estimate_count + 1 - i; */
 
     temp = weight + sumweight;
     q = val - mean;
     r = q * weight / temp;
-    sum += sumweight * q * r;
     mean += r;
+    sum += sumweight * q * r;
     sumweight = temp;
   }
-  variance = sum / (sumweight - 1.0);
+  if (estimate_count > 0)
+    variance = (sum / sumweight) * estimate_count / (estimate_count - 1.0);
 #else
   /* trivial version for debugging */
   double vsq;
@@ -349,8 +344,6 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em)
 
   for (i = 0; i < estimate_count; i++)
   {
-    int j;
-
     j = (estimate_index - i + HISTORY_SIZE) % HISTORY_SIZE;
     val = htonl (size_estimate_messages[j].matching_bits);
     sum += val;
@@ -359,9 +352,10 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em)
   if (0 != estimate_count)
   {
     mean = sum / estimate_count;
-    variance = (vsq - mean * sum) / estimate_count; // terrible for numerical stability...
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(%f - %f) / %u = %f\n", 
-      vsq, mean * sum, estimate_count, variance);
+    variance = (vsq - mean * sum) / (estimate_count - 1.0); // terrible for numerical stability...
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
+               "(%f - %f) / %u = %f\n", 
+               vsq, mean * sum, estimate_count - 1, variance);
 
   }
 #endif
@@ -1143,8 +1137,9 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
 #endif
   peer_entry = GNUNET_malloc (sizeof (struct NSEPeerEntry));
   peer_entry->id = *peer;
-  GNUNET_CONTAINER_multihashmap_put (peers, &peer->hashPubKey, peer_entry,
-                                     GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+  GNUNET_assert (GNUNET_OK ==
+                GNUNET_CONTAINER_multihashmap_put (peers, &peer->hashPubKey, peer_entry,
+                                                   GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
   peer_entry->transmit_task =
       GNUNET_SCHEDULER_add_delayed (get_transmit_delay (-1), &transmit_task,
                                     peer_entry);
@@ -1391,7 +1386,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
   nc = GNUNET_SERVER_notification_context_create (server, 1);
   /* Connect to core service and register core handlers */
   coreAPI = GNUNET_CORE_connect (cfg,   /* Main configuration */
-                                 CORE_QUEUE_SIZE,       /* queue size */
+                                 1,
                                  NULL,  /* Closure passed to functions */
                                  &core_init,    /* Call core_init once connected */
                                  &handle_core_connect,  /* Handle connects */