/**
* 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
* 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 */
}
/**
}
#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);
const struct GNUNET_CONFIGURATION_Handle *c,
struct GNUNET_SERVICE_Handle *service)
{
- int size;
- int out_size;
char* fn_valid_peers;
struct GNUNET_HashCode port;
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);
#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 */
# 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 */
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)
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);
}
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),