another core API simplification due to ATS introduction
[oweals/gnunet.git] / src / nse / gnunet-service-nse.c
index e70d6c29e82e3a0bc9992749f5a6fd3da71f2ce8..7000ec602da6289bf7d6ebe6a18c7c3723181d30 100644 (file)
@@ -36,6 +36,7 @@
  * this can calculate the expected number of peers in the network.
  */
 #include "platform.h"
+#include <math.h>
 #include "gnunet_util_lib.h"
 #include "gnunet_constants.h"
 #include "gnunet_protocols.h"
  */
 #define NSE_PRIORITY 5
 
+#if FREEBSD
+#define log2(a) (log(a)/log(2))
+#endif
+
 /**
  * Amount of work required (W-bit collisions) for NSE proofs, in collision-bits.
  */
@@ -308,6 +313,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 +339,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);
@@ -1202,12 +1211,10 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * @param cls service closure
  * @param server handle to the server for this service
  * @param identity the public identity of this peer
- * @param publicKey the public key of this peer
  */
 static void
 core_init (void *cls, struct GNUNET_CORE_Handle *server,
-           const struct GNUNET_PeerIdentity *identity,
-           const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
+           const struct GNUNET_PeerIdentity *identity)
 {
   struct GNUNET_TIME_Absolute now;
   struct GNUNET_TIME_Absolute prev_time;
@@ -1353,7 +1360,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
                                  &core_init,    /* Call core_init once connected */
                                  &handle_core_connect,  /* Handle connects */
                                  &handle_core_disconnect,       /* Handle disconnects */
-                                 NULL,  /* Do we care about "status" updates? */
                                  NULL,  /* Don't want notified about all incoming messages */
                                  GNUNET_NO,     /* For header only inbound notification */
                                  NULL,  /* Don't want notified about all outbound messages */