aboutsummaryrefslogtreecommitdiff
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
parentf1d5be8c05ae4207596b9b8b6ef552b3df8dffc7 (diff)
downloadgnunet-78b04addaf643f8084df2f649f26dde01a1b5ddd.tar.gz
gnunet-78b04addaf643f8084df2f649f26dde01a1b5ddd.zip
rps service/profiler: count observed (unique) peers
-rw-r--r--src/rps/gnunet-service-rps.c69
-rw-r--r--src/rps/rps-test_util.c51
-rw-r--r--src/rps/rps-test_util.h4
-rw-r--r--src/rps/test_rps.c56
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;
1920/** 1920/**
1921 * Name to log view to 1921 * Name to log view to
1922 */ 1922 */
1923static char *file_name_view_log; 1923static const char *file_name_view_log;
1924
1925#ifdef TO_FILE
1926/**
1927 * Name to log number of observed peers to
1928 */
1929static const char *file_name_observed_log;
1930
1931/**
1932 * @brief Count the observed peers
1933 */
1934static uint32_t num_observed_peers;
1935
1936/**
1937 * @brief Multipeermap (ab-) used to count unique peer_ids
1938 */
1939static struct GNUNET_CONTAINER_MultiPeerMap *observed_unique_peers;
1940#endif /* TO_FILE */
1924 1941
1925/** 1942/**
1926 * The size of sampler we need to be able to satisfy the client's need 1943 * The size of sampler we need to be able to satisfy the client's need
@@ -2511,6 +2528,21 @@ insert_in_sampler (void *cls,
2511 * messages to it */ 2528 * messages to it */
2512 //Peers_indicate_sending_intention (peer); 2529 //Peers_indicate_sending_intention (peer);
2513 } 2530 }
2531 #ifdef TO_FILE
2532 num_observed_peers++;
2533 GNUNET_CONTAINER_multipeermap_put
2534 (observed_unique_peers,
2535 peer,
2536 NULL,
2537 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
2538 uint32_t num_observed_unique_peers = GNUNET_CONTAINER_multipeermap_size (
2539 observed_unique_peers);
2540 to_file (file_name_observed_log,
2541 "%" PRIu32 " %" PRIu32 " %f\n",
2542 num_observed_peers,
2543 num_observed_unique_peers,
2544 1.0*num_observed_unique_peers/num_observed_peers)
2545 #endif /* TO_FILE */
2514} 2546}
2515 2547
2516/** 2548/**
@@ -4126,7 +4158,12 @@ shutdown_task (void *cls)
4126 } 4158 }
4127 #ifdef ENABLE_MALICIOUS 4159 #ifdef ENABLE_MALICIOUS
4128 struct AttackedPeer *tmp_att_peer; 4160 struct AttackedPeer *tmp_att_peer;
4129 GNUNET_free (file_name_view_log); 4161 /* it is ok to free this const during shutdown: */
4162 GNUNET_free ((char *) file_name_view_log);
4163 #ifdef TO_FILE
4164 GNUNET_free ((char *) file_name_observed_log);
4165 GNUNET_CONTAINER_multipeermap_destroy (observed_unique_peers);
4166 #endif /* TO_FILE */
4130 GNUNET_array_grow (mal_peers, num_mal_peers, 0); 4167 GNUNET_array_grow (mal_peers, num_mal_peers, 0);
4131 if (NULL != mal_peer_set) 4168 if (NULL != mal_peer_set)
4132 GNUNET_CONTAINER_multipeermap_destroy (mal_peer_set); 4169 GNUNET_CONTAINER_multipeermap_destroy (mal_peer_set);
@@ -4211,8 +4248,6 @@ run (void *cls,
4211 const struct GNUNET_CONFIGURATION_Handle *c, 4248 const struct GNUNET_CONFIGURATION_Handle *c,
4212 struct GNUNET_SERVICE_Handle *service) 4249 struct GNUNET_SERVICE_Handle *service)
4213{ 4250{
4214 int size;
4215 int out_size;
4216 char* fn_valid_peers; 4251 char* fn_valid_peers;
4217 struct GNUNET_HashCode port; 4252 struct GNUNET_HashCode port;
4218 4253
@@ -4271,27 +4306,11 @@ run (void *cls,
4271 View_create (view_size_est_min); 4306 View_create (view_size_est_min);
4272 4307
4273 /* file_name_view_log */ 4308 /* file_name_view_log */
4274 if (GNUNET_OK != GNUNET_DISK_directory_create ("/tmp/rps/")) 4309 file_name_view_log = store_prefix_file_name (&own_identity, "view");
4275 { 4310 #ifdef TO_FILE
4276 LOG (GNUNET_ERROR_TYPE_WARNING, 4311 file_name_observed_log = store_prefix_file_name (&own_identity, "observed");
4277 "Failed to create directory /tmp/rps/\n"); 4312 observed_unique_peers = GNUNET_CONTAINER_multipeermap_create (1, GNUNET_NO);
4278 } 4313 #endif /* TO_FILE */
4279
4280 size = (14 + strlen (GNUNET_i2s_full (&own_identity)) + 1) * sizeof (char);
4281 file_name_view_log = GNUNET_malloc (size);
4282 out_size = GNUNET_snprintf (file_name_view_log,
4283 size,
4284 "/tmp/rps/view-%s",
4285 GNUNET_i2s_full (&own_identity));
4286 if (size < out_size ||
4287 0 > out_size)
4288 {
4289 LOG (GNUNET_ERROR_TYPE_WARNING,
4290 "Failed to write string to buffer (size: %i, out_size: %i)\n",
4291 size,
4292 out_size);
4293 }
4294
4295 4314
4296 /* connect to NSE */ 4315 /* connect to NSE */
4297 nse = GNUNET_NSE_connect (cfg, nse_callback, NULL); 4316 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)
208 208
209#endif /* TO_FILE */ 209#endif /* TO_FILE */
210 210
211/**
212 * @brief Try to ensure that `/tmp/rps` exists.
213 *
214 * @return #GNUNET_YES on success
215 * #GNUNET_SYSERR on failure
216 */
217static int ensure_folder_exist (void)
218{
219 if (GNUNET_NO == GNUNET_DISK_directory_test ("/tmp/rps/", GNUNET_NO))
220 {
221 GNUNET_DISK_directory_create ("/tmp/rps");
222 }
223 if (GNUNET_YES != GNUNET_DISK_directory_test ("/tmp/rps/", GNUNET_NO))
224 {
225 return GNUNET_SYSERR;
226 }
227 return GNUNET_YES;
228}
229
230const char *
231store_prefix_file_name (const struct GNUNET_PeerIdentity *peer,
232 const char *prefix)
233{
234 unsigned int len_file_name;
235 unsigned int out_size;
236 char *file_name;
237 const char *pid_long;
238
239 if (GNUNET_SYSERR == ensure_folder_exist()) return NULL;
240 pid_long = GNUNET_i2s_full (peer);
241 len_file_name = (strlen (prefix) +
242 strlen (pid_long) +
243 11)
244 * sizeof (char);
245 file_name = GNUNET_malloc (len_file_name);
246 out_size = GNUNET_snprintf (file_name,
247 len_file_name,
248 "/tmp/rps/%s-%s",
249 prefix,
250 pid_long);
251 if (len_file_name < out_size ||
252 0 > out_size)
253 {
254 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
255 "Failed to write string to buffer (size: %i, out_size: %i)\n",
256 len_file_name,
257 out_size);
258 }
259 return file_name;
260}
261
211/* end of gnunet-service-rps.c */ 262/* 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);
72# define to_file_w_len(file_name, len, ...) 72# define to_file_w_len(file_name, len, ...)
73#endif /* TO_FILE */ 73#endif /* TO_FILE */
74 74
75const char *
76store_prefix_file_name (const struct GNUNET_PeerIdentity *peer,
77 const char *prefix);
78
75#endif /* RPS_TEST_UTIL_H */ 79#endif /* RPS_TEST_UTIL_H */
76/* end of gnunet-service-rps.c */ 80/* 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)
1809 return evaluate (); 1809 return evaluate ();
1810} 1810}
1811 1811
1812/**
1813 * @brief Try to ensure that `/tmp/rps` exists.
1814 *
1815 * @return #GNUNET_YES on success
1816 * #GNUNET_SYSERR on failure
1817 */
1818static int ensure_folder_exist (void)
1819{
1820 if (GNUNET_NO == GNUNET_DISK_directory_test ("/tmp/rps/", GNUNET_NO))
1821 {
1822 GNUNET_DISK_directory_create ("/tmp/rps");
1823 }
1824 if (GNUNET_YES != GNUNET_DISK_directory_test ("/tmp/rps/", GNUNET_NO))
1825 {
1826 return GNUNET_SYSERR;
1827 }
1828 return GNUNET_YES;
1829}
1830
1831static const char *
1832store_prefix_file_name (struct RPSPeer *rps_peer, const char *prefix)
1833{
1834 unsigned int len_file_name;
1835 unsigned int out_size;
1836 char *file_name;
1837 const char *pid_long;
1838
1839 if (GNUNET_SYSERR == ensure_folder_exist()) return NULL;
1840 pid_long = GNUNET_i2s_full (rps_peer->peer_id);
1841 len_file_name = (strlen (prefix) +
1842 strlen (pid_long) +
1843 11)
1844 * sizeof (char);
1845 file_name = GNUNET_malloc (len_file_name);
1846 out_size = GNUNET_snprintf (file_name,
1847 len_file_name,
1848 "/tmp/rps/%s-%s",
1849 prefix,
1850 pid_long);
1851 if (len_file_name < out_size ||
1852 0 > out_size)
1853 {
1854 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1855 "Failed to write string to buffer (size: %i, out_size: %i)\n",
1856 len_file_name,
1857 out_size);
1858 }
1859 return file_name;
1860}
1861
1862static uint32_t fac (uint32_t x) 1812static uint32_t fac (uint32_t x)
1863{ 1813{
1864 if (1 >= x) 1814 if (1 >= x)
@@ -2253,7 +2203,8 @@ void view_update_cb (void *cls,
2253static void 2203static void
2254pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) 2204pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
2255{ 2205{
2256 rps_peer->file_name_probs = store_prefix_file_name (rps_peer, "probs"); 2206 rps_peer->file_name_probs =
2207 store_prefix_file_name (rps_peer->peer_id, "probs");
2257 GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer); 2208 GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer);
2258} 2209}
2259 2210
@@ -2576,7 +2527,8 @@ void post_profiler (struct RPSPeer *rps_peer)
2576 stat_cls = GNUNET_malloc (sizeof (struct STATcls)); 2527 stat_cls = GNUNET_malloc (sizeof (struct STATcls));
2577 stat_cls->rps_peer = rps_peer; 2528 stat_cls->rps_peer = rps_peer;
2578 stat_cls->stat_type = stat_type; 2529 stat_cls->stat_type = stat_type;
2579 rps_peer->file_name_stats = store_prefix_file_name (rps_peer, "stats"); 2530 rps_peer->file_name_stats =
2531 store_prefix_file_name (rps_peer->peer_id, "stats");
2580 GNUNET_STATISTICS_get (rps_peer->stats_h, 2532 GNUNET_STATISTICS_get (rps_peer->stats_h,
2581 "rps", 2533 "rps",
2582 stat_type_2_str (stat_type), 2534 stat_type_2_str (stat_type),