fix correction according to paper, minimum NSE should be our neighour set
[oweals/gnunet.git] / src / nse / gnunet-service-nse.c
index f8d5f76f1bee074f7526dd89e468b9120b556e75..bc46a537cdd3b2f5b614740c3b4dd07f4c433d75 100644 (file)
@@ -148,7 +148,7 @@ struct GNUNET_NSE_FloodMessage
   /**
    * Number of hops this message has taken so far.
    */
-  uint32_t hop_count;
+  uint32_t hop_count GNUNET_PACKED;
 
   /**
    * Purpose.
@@ -166,7 +166,7 @@ struct GNUNET_NSE_FloodMessage
    * of timestamp and the initiator's public
    * key.
    */
-  uint32_t matching_bits;
+  uint32_t matching_bits GNUNET_PACKED;
 
   /**
    * Public key of the originator.
@@ -176,7 +176,7 @@ struct GNUNET_NSE_FloodMessage
   /**
    * Proof of work, causing leading zeros when hashed with pkey.
    */
-  uint64_t proof_of_work;
+  uint64_t proof_of_work GNUNET_PACKED;
 
   /**
    * Signature (over range specified in purpose).
@@ -308,6 +308,7 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em)
   double q;
   double r;
   double temp;
+  double nsize;
 
   /* Weighted incremental algorithm for stddev according to West (1979) */
   mean = 0.0;
@@ -333,12 +334,15 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em)
   std_dev = sqrt (variance);
   current_std_dev = std_dev;
   current_size_estimate = mean;
-
+  
   em->header.size = htons (sizeof (struct GNUNET_NSE_ClientMessage));
   em->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_ESTIMATE);
   em->reserved = htonl (0);
   em->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
-  em->size_estimate = mean - 1.0 / 3.0;
+  em->size_estimate = mean - 0.332747;
+  nsize = log2 (GNUNET_CONTAINER_multihashmap_size (peers) + 1);
+  if (em->size_estimate < nsize)
+    em->size_estimate = nsize;
   em->std_deviation = std_dev;
   GNUNET_STATISTICS_set (stats, "# nodes in the network (estimate)",
                          (uint64_t) pow (2, mean - 1.0 / 3.0), GNUNET_NO);
@@ -627,7 +631,8 @@ setup_flood_message (unsigned int slot, struct GNUNET_TIME_Absolute ts)
   fm->timestamp = GNUNET_TIME_absolute_hton (ts);
   fm->pkey = my_public_key;
   fm->proof_of_work = my_proof;
-  GNUNET_CRYPTO_rsa_sign (my_private_key, &fm->purpose, &fm->signature);
+  GNUNET_assert (GNUNET_OK ==
+                GNUNET_CRYPTO_rsa_sign (my_private_key, &fm->purpose, &fm->signature));
 }
 
 
@@ -815,9 +820,10 @@ find_proof (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
         if (ntohl (size_estimate_messages[i].hop_count) == 0)
         {
           size_estimate_messages[i].proof_of_work = my_proof;
-          GNUNET_CRYPTO_rsa_sign (my_private_key,
-                                  &size_estimate_messages[i].purpose,
-                                  &size_estimate_messages[i].signature);
+          GNUNET_assert (GNUNET_OK ==
+                        GNUNET_CRYPTO_rsa_sign (my_private_key,
+                                                &size_estimate_messages[i].purpose,
+                                                &size_estimate_messages[i].signature));
         }
       write_proof ();
       return;