gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [gnunet] branch master updated: rps service/profiler: count


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated: rps service/profiler: count observed (unique) peers
Date: Thu, 12 Apr 2018 22:27:10 +0200

This is an automated email from the git hooks/post-receive script.

julius-buenger pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 78b04adda rps service/profiler: count observed (unique) peers
78b04adda is described below

commit 78b04addaf643f8084df2f649f26dde01a1b5ddd
Author: Julius Bünger <address@hidden>
AuthorDate: Thu Apr 12 12:06:46 2018 +0200

    rps service/profiler: count observed (unique) peers
---
 src/rps/gnunet-service-rps.c | 69 ++++++++++++++++++++++++++++----------------
 src/rps/rps-test_util.c      | 51 ++++++++++++++++++++++++++++++++
 src/rps/rps-test_util.h      |  4 +++
 src/rps/test_rps.c           | 56 +++--------------------------------
 4 files changed, 103 insertions(+), 77 deletions(-)

diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index c23a64285..eb47903e0 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -1920,7 +1920,24 @@ static struct RPS_Sampler *client_sampler;
 /**
  * Name to log view to
  */
-static char *file_name_view_log;
+static const char *file_name_view_log;
+
+#ifdef TO_FILE
+/**
+ * Name to log number of observed peers to
+ */
+static const char *file_name_observed_log;
+
+/**
+ * @brief Count the observed peers
+ */
+static uint32_t num_observed_peers;
+
+/**
+ * @brief Multipeermap (ab-) used to count unique peer_ids
+ */
+static struct GNUNET_CONTAINER_MultiPeerMap *observed_unique_peers;
+#endif /* TO_FILE */
 
 /**
  * The size of sampler we need to be able to satisfy the client's need
@@ -2511,6 +2528,21 @@ insert_in_sampler (void *cls,
      * messages to it */
     //Peers_indicate_sending_intention (peer);
   }
+  #ifdef TO_FILE
+  num_observed_peers++;
+  GNUNET_CONTAINER_multipeermap_put
+    (observed_unique_peers,
+     peer,
+     NULL,
+     GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+  uint32_t num_observed_unique_peers = GNUNET_CONTAINER_multipeermap_size (
+      observed_unique_peers);
+  to_file (file_name_observed_log,
+          "%" PRIu32 " %" PRIu32 " %f\n",
+          num_observed_peers,
+          num_observed_unique_peers,
+          1.0*num_observed_unique_peers/num_observed_peers)
+  #endif /* TO_FILE */
 }
 
 /**
@@ -4126,7 +4158,12 @@ shutdown_task (void *cls)
   }
   #ifdef ENABLE_MALICIOUS
   struct AttackedPeer *tmp_att_peer;
-  GNUNET_free (file_name_view_log);
+  /* it is ok to free this const during shutdown: */
+  GNUNET_free ((char *) file_name_view_log);
+  #ifdef TO_FILE
+  GNUNET_free ((char *) file_name_observed_log);
+  GNUNET_CONTAINER_multipeermap_destroy (observed_unique_peers);
+  #endif /* TO_FILE */
   GNUNET_array_grow (mal_peers, num_mal_peers, 0);
   if (NULL != mal_peer_set)
     GNUNET_CONTAINER_multipeermap_destroy (mal_peer_set);
@@ -4211,8 +4248,6 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *c,
      struct GNUNET_SERVICE_Handle *service)
 {
-  int size;
-  int out_size;
   char* fn_valid_peers;
   struct GNUNET_HashCode port;
 
@@ -4271,27 +4306,11 @@ run (void *cls,
   View_create (view_size_est_min);
 
   /* file_name_view_log */
-  if (GNUNET_OK != GNUNET_DISK_directory_create ("/tmp/rps/"))
-  {
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-         "Failed to create directory /tmp/rps/\n");
-  }
-
-  size = (14 + strlen (GNUNET_i2s_full (&own_identity)) + 1) * sizeof (char);
-  file_name_view_log = GNUNET_malloc (size);
-  out_size = GNUNET_snprintf (file_name_view_log,
-                              size,
-                              "/tmp/rps/view-%s",
-                              GNUNET_i2s_full (&own_identity));
-  if (size < out_size ||
-      0 > out_size)
-  {
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-         "Failed to write string to buffer (size: %i, out_size: %i)\n",
-         size,
-         out_size);
-  }
-
+  file_name_view_log = store_prefix_file_name (&own_identity, "view");
+  #ifdef TO_FILE
+  file_name_observed_log = store_prefix_file_name (&own_identity, "observed");
+  observed_unique_peers = GNUNET_CONTAINER_multipeermap_create (1, GNUNET_NO);
+  #endif /* TO_FILE */
 
   /* connect to NSE */
   nse = GNUNET_NSE_connect (cfg, nse_callback, NULL);
diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c
index 817967e0c..869170a8a 100644
--- a/src/rps/rps-test_util.c
+++ b/src/rps/rps-test_util.c
@@ -208,4 +208,55 @@ create_file (const char *name)
 
 #endif /* TO_FILE */
 
+/**
+ * @brief Try to ensure that `/tmp/rps` exists.
+ *
+ * @return #GNUNET_YES on success
+ *         #GNUNET_SYSERR on failure
+ */
+static int ensure_folder_exist (void)
+{
+  if (GNUNET_NO == GNUNET_DISK_directory_test ("/tmp/rps/", GNUNET_NO))
+  {
+    GNUNET_DISK_directory_create ("/tmp/rps");
+  }
+  if (GNUNET_YES != GNUNET_DISK_directory_test ("/tmp/rps/", GNUNET_NO))
+  {
+    return GNUNET_SYSERR;
+  }
+  return GNUNET_YES;
+}
+
+const char *
+store_prefix_file_name (const struct GNUNET_PeerIdentity *peer,
+    const char *prefix)
+{
+  unsigned int len_file_name;
+  unsigned int out_size;
+  char *file_name;
+  const char *pid_long;
+
+  if (GNUNET_SYSERR == ensure_folder_exist()) return NULL;
+  pid_long = GNUNET_i2s_full (peer);
+  len_file_name = (strlen (prefix) +
+                   strlen (pid_long) +
+                   11)
+                     * sizeof (char);
+  file_name = GNUNET_malloc (len_file_name);
+  out_size = GNUNET_snprintf (file_name,
+                              len_file_name,
+                              "/tmp/rps/%s-%s",
+                              prefix,
+                              pid_long);
+  if (len_file_name < out_size ||
+      0 > out_size)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+               "Failed to write string to buffer (size: %i, out_size: %i)\n",
+               len_file_name,
+               out_size);
+  }
+  return file_name;
+}
+
 /* end of gnunet-service-rps.c */
diff --git a/src/rps/rps-test_util.h b/src/rps/rps-test_util.h
index 725be815c..59f062331 100644
--- a/src/rps/rps-test_util.h
+++ b/src/rps/rps-test_util.h
@@ -72,5 +72,9 @@ create_file (const char *name);
 #  define to_file_w_len(file_name, len, ...)
 #endif /* TO_FILE */
 
+const char *
+store_prefix_file_name (const struct GNUNET_PeerIdentity *peer,
+    const char *prefix);
+
 #endif /* RPS_TEST_UTIL_H */
 /* end of gnunet-service-rps.c */
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c
index 9ccf3e61c..8d31bf50d 100644
--- a/src/rps/test_rps.c
+++ b/src/rps/test_rps.c
@@ -1809,56 +1809,6 @@ profiler_eval (void)
   return evaluate ();
 }
 
-/**
- * @brief Try to ensure that `/tmp/rps` exists.
- *
- * @return #GNUNET_YES on success
- *         #GNUNET_SYSERR on failure
- */
-static int ensure_folder_exist (void)
-{
-  if (GNUNET_NO == GNUNET_DISK_directory_test ("/tmp/rps/", GNUNET_NO))
-  {
-    GNUNET_DISK_directory_create ("/tmp/rps");
-  }
-  if (GNUNET_YES != GNUNET_DISK_directory_test ("/tmp/rps/", GNUNET_NO))
-  {
-    return GNUNET_SYSERR;
-  }
-  return GNUNET_YES;
-}
-
-static const char *
-store_prefix_file_name (struct RPSPeer *rps_peer, const char *prefix)
-{
-  unsigned int len_file_name;
-  unsigned int out_size;
-  char *file_name;
-  const char *pid_long;
-
-  if (GNUNET_SYSERR == ensure_folder_exist()) return NULL;
-  pid_long = GNUNET_i2s_full (rps_peer->peer_id);
-  len_file_name = (strlen (prefix) +
-                   strlen (pid_long) +
-                   11)
-                     * sizeof (char);
-  file_name = GNUNET_malloc (len_file_name);
-  out_size = GNUNET_snprintf (file_name,
-                              len_file_name,
-                              "/tmp/rps/%s-%s",
-                              prefix,
-                              pid_long);
-  if (len_file_name < out_size ||
-      0 > out_size)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-               "Failed to write string to buffer (size: %i, out_size: %i)\n",
-               len_file_name,
-               out_size);
-  }
-  return file_name;
-}
-
 static uint32_t fac (uint32_t x)
 {
   if (1 >= x)
@@ -2253,7 +2203,8 @@ void view_update_cb (void *cls,
 static void
 pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
 {
-  rps_peer->file_name_probs = store_prefix_file_name (rps_peer, "probs");
+  rps_peer->file_name_probs =
+    store_prefix_file_name (rps_peer->peer_id, "probs");
   GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer);
 }
 
@@ -2576,7 +2527,8 @@ void post_profiler (struct RPSPeer *rps_peer)
       stat_cls = GNUNET_malloc (sizeof (struct STATcls));
       stat_cls->rps_peer = rps_peer;
       stat_cls->stat_type = stat_type;
-      rps_peer->file_name_stats = store_prefix_file_name (rps_peer, "stats");
+      rps_peer->file_name_stats =
+        store_prefix_file_name (rps_peer->peer_id, "stats");
       GNUNET_STATISTICS_get (rps_peer->stats_h,
                              "rps",
                              stat_type_2_str (stat_type),

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]