summaryrefslogtreecommitdiff
path: root/src/rps/rps-test_util.c
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2018-04-12 12:06:46 +0200
committerJulius Bünger <buenger@mytum.de>2018-04-12 22:25:42 +0200
commit78b04addaf643f8084df2f649f26dde01a1b5ddd (patch)
treea86819060941478ee5d20f4c430934d891911de2 /src/rps/rps-test_util.c
parentf1d5be8c05ae4207596b9b8b6ef552b3df8dffc7 (diff)
rps service/profiler: count observed (unique) peers
Diffstat (limited to 'src/rps/rps-test_util.c')
-rw-r--r--src/rps/rps-test_util.c51
1 files changed, 51 insertions, 0 deletions
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 */