- The next_message in the previous round should have the now current_timestamp.
[oweals/gnunet.git] / src / nse / gnunet-service-nse.c
index 30493851e653cb1ac609ecfe7f782578636fe418..bf78e23718ed609f5c785d7f432331078e542c9d 100644 (file)
@@ -385,11 +385,10 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em)
   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 - 0.332747;
+  double se = 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;
+  em->size_estimate = GNUNET_hton_double (GNUNET_MAX (se, nsize));
+  em->std_deviation = GNUNET_hton_double (std_dev);
   GNUNET_STATISTICS_set (stats, "# nodes in the network (estimate)",
                          (uint64_t) pow (2, mean - 1.0 / 3.0), GNUNET_NO);
 }
@@ -769,8 +768,10 @@ update_flood_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   estimate_index = (estimate_index + 1) % HISTORY_SIZE;
   if (estimate_count < HISTORY_SIZE)
     estimate_count++;
-  if (next_timestamp.abs_value ==
-      GNUNET_TIME_absolute_ntoh (next_message.timestamp).abs_value)
+  if ((current_timestamp.abs_value ==
+      GNUNET_TIME_absolute_ntoh (next_message.timestamp).abs_value) &&
+      (get_matching_bits (current_timestamp, &my_identity) >
+      ntohl(next_message.matching_bits)))
   {
     /* we received a message for this round way early, use it! */
     size_estimate_messages[estimate_index] = next_message;
@@ -911,7 +912,9 @@ find_proof (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     my_proof = counter;
   }
   proof_task =
-      GNUNET_SCHEDULER_add_delayed (proof_find_delay, &find_proof, NULL);
+      GNUNET_SCHEDULER_add_delayed_with_priority (proof_find_delay,
+                                                 GNUNET_SCHEDULER_PRIORITY_IDLE,
+                                                 &find_proof, NULL);
 }
 
 
@@ -1053,7 +1056,6 @@ handle_p2p_size_estimate (void *cls, const struct GNUNET_PeerIdentity *peer,
 #endif
 
   ts = GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp);
-
   if (ts.abs_value == current_timestamp.abs_value)
     idx = estimate_index;
   else if (ts.abs_value ==
@@ -1318,9 +1320,7 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server,
 
   if (server == NULL)
   {
-#if DEBUG_NSE
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connection to core FAILED!\n");
-#endif
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to core FAILED!\n");
     GNUNET_SCHEDULER_shutdown ();
     return;
   }