Christian Grothoff 13 лет назад
Родитель
Сommit
f53e991a59
8 измененных файлов с 584 добавлено и 492 удалено
  1. 1 0
      configure.ac
  2. 1 0
      src/Makefile.am
  3. 16 40
      src/include/gnunet_nse_service.h
  4. 1 1
      src/nse/Makefile.am
  5. 499 355
      src/nse/gnunet-service-nse.c
  6. 7 47
      src/nse/nse.h
  7. 50 44
      src/nse/nse_api.c
  8. 9 5
      src/nse/test_nse_api.c

+ 1 - 0
configure.ac

@@ -755,6 +755,7 @@ src/include/gnunet_directories.h
 src/hostlist/Makefile
 src/mesh/Makefile
 src/nat/Makefile
+src/nse/Makefile
 src/peerinfo/Makefile
 src/peerinfo-tool/Makefile
 src/statistics/Makefile

+ 1 - 0
src/Makefile.am

@@ -23,6 +23,7 @@ SUBDIRS = \
   peerinfo-tool \
   core \
   testing \
+  nse \
   dv \
   dht \
   hostlist \

+ 16 - 40
src/include/gnunet_nse_service.h

@@ -1,6 +1,6 @@
 /*
       This file is part of GNUnet
-      (C) 2009, 2010 Christian Grothoff (and other contributing authors)
+      (C) 2011 Christian Grothoff (and other contributing authors)
 
       GNUnet is free software; you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published
@@ -47,56 +47,32 @@ extern "C"
  */
 #define GNUNET_NSE_VERSION 0x00000000
 
-/**
- * Interval for sending network size estimation flood requests.
- * Number is in milliseconds.
- * This needs to be a factor of the number milliseconds in
- * a day, as the base time used is midnight each day offset
- * by this amount.
- *
- * There are 86400000 milliseconds in a day.
- */
-#if 0
-#define GNUNET_NSE_INTERVAL 60000 /* Every minute */
-#define GNUNET_NSE_INTERVAL 180000 /* Every three minutes */
-#define GNUNET_NSE_INTERVAL 360000 /* Every six minutes */
-#define GNUNET_NSE_INTERVAL 600000 /* Every ten minutes */
-#define GNUNET_NSE_INTERVAL 1200000 /* Every twenty minutes */
-#endif
-#define GNUNET_NSE_INTERVAL 360000 /* Every ten minutes */
-/**
- * How much clock skew (in milliseconds) will we allow
- * for received messages.  We check our current time
- * with the timestamp received as part of the message
- * and if the difference is greater than this tolerance
- * we will discard the message as invalid.
- *
- * There are 86400000 milliseconds in a day.
- */
-#define GNUNET_NSE_DRIFT_TOLERANCE 600000 /* Ten minutes. */
-
-/**
- * Number of bits
- */
-#define GNUNET_NSE_BITS
-
 /**
  * Handle for the network size estimation service.
  */
 struct GNUNET_NSE_Handle;
 
-
 /**
  * Callback to call when network size estimate is updated.
  *
  * @param cls closure
- * @param estimate the value of the current network size estimate
- * @param std_dev standard deviation (rounded down to nearest integer)
- *                of the size estimation values seen
+ * @param logestimate the log(Base 2) value of the current network size estimate
+ * @param std_dev standard deviation for the estimate
+ *
+ */
+typedef void (*GNUNET_NSE_Callback) (void *cls,
+				     double logestimate, 
+				     double std_dev);
+
+
+/**
+ * Convert the logarithmic estimated returned to the 'GNUNET_NSE_Callback'
+ * into an absolute estimate in terms of the number of peers in the network.
  *
+ * @param loge logarithmic estimate 
+ * @return absolute number of peers in the network (estimated)
  */
-typedef void
-(*GNUNET_NSE_Callback) (void *cls, double estimate, double std_dev);
+#define GNUNET_NSE_log_estimate_to_n(loge) pow(2.0, (loge))
 
 /**
  * Connect to the network size estimation service.

+ 1 - 1
src/nse/Makefile.am

@@ -31,7 +31,7 @@ nse_profiler_SOURCES = \
 nse_profiler_LDADD = \
   $(top_builddir)/src/nse/libgnunetnse.la \
   $(top_builddir)/src/util/libgnunetutil.la \
-  $(top_builddir)/src/testing/libgnunettesting.la
+  $(top_builddir)/src/testing/libgnunettesting.la \
   $(GN_LIBINTL)
 nse_profiler_DEPENDENCIES = \
   libgnunetnse.la				 

Разница между файлами не показана из-за своего большого размера
+ 499 - 355
src/nse/gnunet-service-nse.c


+ 7 - 47
src/nse/nse.h

@@ -45,11 +45,16 @@
 struct GNUNET_NSE_ClientMessage
 {
   /**
-   * Type:  GNUNET_MESSAGE_TYPE_NSE_UPDATE
+   * Type: GNUNET_MESSAGE_TYPE_NSE_UPDATE
    */
   struct GNUNET_MessageHeader header;
 
-  /*
+  /**
+   * For alignment.
+   */
+  uint32_t reserved;
+
+  /**
    * The current estimated network size.
    */
   double size_estimate;
@@ -62,50 +67,5 @@ struct GNUNET_NSE_ClientMessage
   double std_deviation;
 };
 
-/**
- * Network size estimate reply; sent when "this"
- * peer's timer has run out before receiving a
- * valid reply from another peer.
- */
-struct GNUNET_NSE_FloodMessage
-{
-  /**
-   * Type: GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD
-   */
-  struct GNUNET_MessageHeader header;
-
-  /**
-   * Purpose.
-   */
-  struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
-
-  /**
-   * Number of matching bits between the hash
-   * of timestamp and the initiator's public
-   * key.
-   */
-  uint32_t distance;
-
-  /**
-   * The current timestamp value (which all
-   * peers should agree on).
-   */
-  struct GNUNET_TIME_AbsoluteNBO timestamp;
-
-  /**
-   * Public key of the originator.
-   */
-  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
-
-  /**
-   * FIXME: use, document.
-   */
-  uint32_t proof_of_work;
-
-  /**
-   * FIXME: use, document.
-   */
-  struct GNUNET_CRYPTO_RsaSignature signature;
-};
 
 #endif

+ 50 - 44
src/nse/nse_api.c

@@ -22,8 +22,6 @@
  * @file nse/nse_api.c
  * @brief api to get information from the network size estimation service
  * @author Nathan Evans
- *
- * TODO:
  */
 #include "platform.h"
 #include "gnunet_client_lib.h"
@@ -68,17 +66,6 @@ struct GNUNET_NSE_Handle
    */
   struct GNUNET_TIME_Relative reconnect_delay;
 
-  /**
-   * Should this handle auto-destruct once all actions have
-   * been processed?
-   */
-  int do_destroy;
-
-  /**
-   * Are we currently receiving from the service?
-   */
-  int receiving;
-
   /**
    * Callback function to call when message is received.
    */
@@ -92,6 +79,17 @@ struct GNUNET_NSE_Handle
 };
 
 
+/**
+ * Try again to connect to network size estimation service.
+ *
+ * @param cls the handle to the transport service
+ * @param tc scheduler context
+ */
+static void
+reconnect (void *cls,
+           const struct GNUNET_SCHEDULER_TaskContext *tc);
+
+
 /**
  * Type of a function to call when we receive a message
  * from the service.
@@ -99,39 +97,40 @@ struct GNUNET_NSE_Handle
  * @param cls closure
  * @param msg message received, NULL on timeout or fatal error
  */
-void message_handler (void *cls,
-                      const struct GNUNET_MessageHeader * msg)
+static void 
+message_handler (void *cls,
+		 const struct GNUNET_MessageHeader * msg)
 {
   struct GNUNET_NSE_Handle *h = cls;
-  struct GNUNET_NSE_ClientMessage *client_msg;
-
-  if (msg == NULL) /* Error, timeout, death */
-    return;
+  const struct GNUNET_NSE_ClientMessage *client_msg;
 
-  if ((ntohs (msg->size) < sizeof(struct GNUNET_NSE_ClientMessage))
-      || (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_NSE_ESTIMATE))
+  if (msg == NULL)
     {
-#if DEBUG_NSE
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "%s: received incorrect message (size %d < %d) from service!",
-                  "NSE API", ntohs (msg->size),
-                  sizeof(struct GNUNET_NSE_ClientMessage));
-#endif
+      /* Error, timeout, death */
+      GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
+      h->client = NULL;
+      h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->reconnect_delay,
+							&reconnect,
+							h);
       return;
     }
-
-  client_msg = (struct GNUNET_NSE_ClientMessage *)msg;
-
-  h->recv_cb (h->recv_cb_cls, client_msg->size_estimate,
+  if ( (ntohs (msg->size) != sizeof(struct GNUNET_NSE_ClientMessage)) || 
+       (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_NSE_ESTIMATE) )
+    {
+      GNUNET_break (0);
+      return;
+    }
+  client_msg = (const struct GNUNET_NSE_ClientMessage *)msg;
+  h->recv_cb (h->recv_cb_cls, 
+	      client_msg->size_estimate,
               client_msg->std_deviation);
-
   GNUNET_CLIENT_receive (h->client,
-                         &message_handler, h, GNUNET_TIME_UNIT_FOREVER_REL);
+                         &message_handler,
+			 h, 
+			 GNUNET_TIME_UNIT_FOREVER_REL);
 }
 
-static void
-reconnect (void *cls,
-           const struct GNUNET_SCHEDULER_TaskContext *tc);
+
 
 /**
  * Reschedule a connect attempt to the service.
@@ -174,6 +173,7 @@ reschedule_connect (struct GNUNET_NSE_Handle *h)
     }
 }
 
+
 /**
  * Transmit START message to service.
  *
@@ -214,6 +214,7 @@ send_start (void *cls, size_t size, void *buf)
   return sizeof (struct GNUNET_MessageHeader);
 }
 
+
 /**
  * Try again to connect to network size estimation service.
  *
@@ -250,6 +251,7 @@ reconnect (void *cls,
   GNUNET_assert(h->th != NULL);
 }
 
+
 /**
  * Connect to the network size estimation service.
  *
@@ -265,11 +267,8 @@ GNUNET_NSE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
 {
   struct GNUNET_NSE_Handle *ret;
 
+  GNUNET_assert (func != NULL);
   ret = GNUNET_malloc (sizeof (struct GNUNET_NSE_Handle));
-
-  if (func == NULL)
-    return NULL;
-
   ret->cfg = cfg;
   ret->recv_cb = func;
   ret->recv_cb_cls = func_cls;
@@ -278,11 +277,11 @@ GNUNET_NSE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
   return ret;
 }
 
+
 /**
  * Disconnect from network size estimation service
  *
  * @param h handle to destroy
- *
  */
 void
 GNUNET_NSE_disconnect (struct GNUNET_NSE_Handle *h)
@@ -294,9 +293,16 @@ GNUNET_NSE_disconnect (struct GNUNET_NSE_Handle *h)
       h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
     }
   if (h->th != NULL)
-    GNUNET_CLIENT_notify_transmit_ready_cancel(h->th);
+    {
+      GNUNET_CLIENT_notify_transmit_ready_cancel(h->th);
+      h->th = NULL;
+    }
   if (h->client != NULL)
-    GNUNET_CLIENT_disconnect(h->client, GNUNET_NO);
-
+    {
+      GNUNET_CLIENT_disconnect(h->client, GNUNET_NO);
+      h->client = NULL;
+    }
   GNUNET_free(h);
 }
+
+/* end of nse_api.c */

+ 9 - 5
src/nse/test_nse_api.c

@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2009 Christian Grothoff (and other contributing authors)
+     (C) 2011 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -35,7 +35,7 @@
 
 static struct GNUNET_NSE_Handle *h;
 
-GNUNET_SCHEDULER_TaskIdentifier die_task;
+static GNUNET_SCHEDULER_TaskIdentifier die_task;
 
 struct PeerContext
 {
@@ -83,18 +83,19 @@ check_nse_message (void *cls, double estimate, double std_dev)
   /* Fantastic check below. Expect NaN, the only thing not equal to itself. */
   if ((estimate != estimate) && (std_dev != std_dev))
     (*ok) = 0;
-
   if (die_task != GNUNET_SCHEDULER_NO_TASK)
     GNUNET_SCHEDULER_cancel(die_task);
-  GNUNET_SCHEDULER_add_now(&end_test, NULL);
+  die_task = GNUNET_SCHEDULER_add_now(&end_test, NULL);
 }
 
+
 static void
 setup_peer (struct PeerContext *p, const char *cfgname)
 {
   p->cfg = GNUNET_CONFIGURATION_create ();
 #if START_ARM
-  p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
+  p->arm_proc = GNUNET_OS_start_process (NULL, NULL,
+					 "gnunet-service-arm",
                                         "gnunet-service-arm",
 #if VERBOSE_ARM
                                         "-L", "DEBUG",
@@ -118,6 +119,7 @@ stop_arm (struct PeerContext *p)
   GNUNET_CONFIGURATION_destroy (p->cfg);
 }
 
+
 static void
 run (void *cls,
      char *const *args,
@@ -135,6 +137,7 @@ run (void *cls,
   GNUNET_assert (h != NULL);
 }
 
+
 static int
 check ()
 {
@@ -161,6 +164,7 @@ check ()
   return ok;
 }
 
+
 int
 main (int argc, char *argv[])
 {

Некоторые файлы не были показаны из-за большого количества измененных файлов