summaryrefslogtreecommitdiff
path: root/src/rps
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2019-02-25 19:41:04 +0100
committerJulius Bünger <buenger@mytum.de>2019-02-25 19:41:04 +0100
commit88aa8d7bb013d1b596a3da2c7162fa55e2fc03a4 (patch)
tree542721aa0c543309867157a107062d11f1313925 /src/rps
parent3d0971394f3d29518b8e78ea9968bc68535dae08 (diff)
downloadgnunet-88aa8d7bb013d1b596a3da2c7162fa55e2fc03a4.tar.gz
gnunet-88aa8d7bb013d1b596a3da2c7162fa55e2fc03a4.zip
RPS: Change way some numbers are written to files
Diffstat (limited to 'src/rps')
-rw-r--r--src/rps/gnunet-service-rps.c157
1 files changed, 92 insertions, 65 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 765c6e3be..a185645ef 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -283,6 +283,20 @@ struct AttackedPeer
283#endif /* ENABLE_MALICIOUS */ 283#endif /* ENABLE_MALICIOUS */
284 284
285/** 285/**
286 * @brief This number determines the number of slots for files that represent
287 * histograms
288 */
289#define HISTOGRAM_FILE_SLOTS 32
290
291/**
292 * @brief The size (in bytes) a file needs to store the histogram
293 *
294 * Per slot: 1 newline, up to 4 chars,
295 * Additionally: 1 null termination
296 */
297#define SIZE_DUMP_FILE (HISTOGRAM_FILE_SLOTS * 5) + 1
298
299/**
286 * @brief One Sub. 300 * @brief One Sub.
287 * 301 *
288 * Essentially one instance of brahms that only connects to other instances 302 * Essentially one instance of brahms that only connects to other instances
@@ -357,16 +371,6 @@ struct Sub
357 uint32_t num_observed_peers; 371 uint32_t num_observed_peers;
358 372
359 /** 373 /**
360 * @brief File name to log number of pushes per round to
361 */
362 char *file_name_push_recv;
363
364 /**
365 * @brief File name to log number of pushes per round to
366 */
367 char *file_name_pull_delays;
368
369 /**
370 * @brief Multipeermap (ab-) used to count unique peer_ids 374 * @brief Multipeermap (ab-) used to count unique peer_ids
371 */ 375 */
372 struct GNUNET_CONTAINER_MultiPeerMap *observed_unique_peers; 376 struct GNUNET_CONTAINER_MultiPeerMap *observed_unique_peers;
@@ -418,7 +422,16 @@ struct Sub
418 * 422 *
419 * Number at index i represents the number of rounds with i observed pushes. 423 * Number at index i represents the number of rounds with i observed pushes.
420 */ 424 */
421 uint32_t push_recv[256]; 425 uint32_t push_recv[HISTOGRAM_FILE_SLOTS];
426
427 /**
428 * @brief Histogram of deltas between the expected and actual number of
429 * received pushes.
430 *
431 * As half of the entries are expected to be negative, this is shifted by
432 * #HISTOGRAM_FILE_SLOTS/2.
433 */
434 uint32_t push_delta[HISTOGRAM_FILE_SLOTS];
422 435
423 /** 436 /**
424 * @brief Number of pull replies with this delay measured in rounds. 437 * @brief Number of pull replies with this delay measured in rounds.
@@ -426,7 +439,7 @@ struct Sub
426 * Number at index i represents the number of pull replies with a delay of i 439 * Number at index i represents the number of pull replies with a delay of i
427 * rounds. 440 * rounds.
428 */ 441 */
429 uint32_t pull_delays[256]; 442 uint32_t pull_delays[HISTOGRAM_FILE_SLOTS];
430}; 443};
431 444
432 445
@@ -2890,10 +2903,6 @@ new_sub (const struct GNUNET_HashCode *hash,
2890#ifdef TO_FILE 2903#ifdef TO_FILE
2891 sub->file_name_observed_log = store_prefix_file_name (&own_identity, 2904 sub->file_name_observed_log = store_prefix_file_name (&own_identity,
2892 "observed"); 2905 "observed");
2893 sub->file_name_push_recv = store_prefix_file_name (&own_identity,
2894 "push_recv");
2895 sub->file_name_pull_delays = store_prefix_file_name (&own_identity,
2896 "pull_delays");
2897 sub->num_observed_peers = 0; 2906 sub->num_observed_peers = 0;
2898 sub->observed_unique_peers = GNUNET_CONTAINER_multipeermap_create (1, 2907 sub->observed_unique_peers = GNUNET_CONTAINER_multipeermap_create (1,
2899 GNUNET_NO); 2908 GNUNET_NO);
@@ -2919,6 +2928,50 @@ new_sub (const struct GNUNET_HashCode *hash,
2919} 2928}
2920 2929
2921 2930
2931#ifdef TO_FILE
2932/**
2933 * @brief Write all numbers in the given array into the given file
2934 *
2935 * Single numbers devided by a newline
2936 *
2937 * @param hist_array[] the array to dump
2938 * @param file_name file to dump into
2939 */
2940static void
2941write_histogram_to_file (const uint32_t hist_array[],
2942 const char *file_name)
2943{
2944 char collect_str[SIZE_DUMP_FILE + 1] = "";
2945 char *recv_str_iter;
2946 char *file_name_full;
2947
2948 recv_str_iter = collect_str;
2949 file_name_full = store_prefix_file_name (&own_identity,
2950 file_name);
2951 for (uint32_t i = 0; i < HISTOGRAM_FILE_SLOTS; i++)
2952 {
2953 char collect_str_tmp[8];
2954
2955 GNUNET_snprintf (collect_str_tmp,
2956 sizeof (collect_str_tmp),
2957 "%" PRIu32 "\n",
2958 hist_array[i]);
2959 recv_str_iter = stpncpy (recv_str_iter,
2960 collect_str_tmp,
2961 6);
2962 }
2963 (void) stpcpy (recv_str_iter,
2964 "\n");
2965 LOG (GNUNET_ERROR_TYPE_DEBUG,
2966 "Writing push stats to disk\n");
2967 to_file_w_len (file_name_full,
2968 SIZE_DUMP_FILE,
2969 collect_str);
2970 GNUNET_free (file_name_full);
2971}
2972#endif /* TO_FILE */
2973
2974
2922/** 2975/**
2923 * @brief Destroy Sub. 2976 * @brief Destroy Sub.
2924 * 2977 *
@@ -2927,12 +2980,6 @@ new_sub (const struct GNUNET_HashCode *hash,
2927static void 2980static void
2928destroy_sub (struct Sub *sub) 2981destroy_sub (struct Sub *sub)
2929{ 2982{
2930#ifdef TO_FILE
2931#define SIZE_DUMP_FILE 1536 /* 256 * 6 (1 whitespace, 1 comma, up to 4 chars) */
2932 char push_recv_str[SIZE_DUMP_FILE + 1] = "";
2933 char pull_delays_str[SIZE_DUMP_FILE + 1] = "";
2934 char *recv_str_iter;
2935#endif /* TO_FILE */
2936 GNUNET_assert (NULL != sub); 2983 GNUNET_assert (NULL != sub);
2937 GNUNET_assert (NULL != sub->do_round_task); 2984 GNUNET_assert (NULL != sub->do_round_task);
2938 GNUNET_SCHEDULER_cancel (sub->do_round_task); 2985 GNUNET_SCHEDULER_cancel (sub->do_round_task);
@@ -2960,51 +3007,16 @@ destroy_sub (struct Sub *sub)
2960 sub->file_name_observed_log = NULL; 3007 sub->file_name_observed_log = NULL;
2961 3008
2962 /* Write push frequencies to disk */ 3009 /* Write push frequencies to disk */
2963 recv_str_iter = push_recv_str; 3010 write_histogram_to_file (sub->push_recv,
2964 for (uint32_t i = 0; i < 256; i++) 3011 "push_recv");
2965 {
2966 char push_recv_str_tmp[8];
2967 3012
2968 GNUNET_snprintf (push_recv_str_tmp, 3013 /* Write push deltas to disk */
2969 sizeof (push_recv_str_tmp), 3014 write_histogram_to_file (sub->push_delta,
2970 "%" PRIu32 "\n", 3015 "push_delta");
2971 sub->push_recv[i]);
2972 recv_str_iter = stpncpy (recv_str_iter,
2973 push_recv_str_tmp,
2974 6);
2975 }
2976 (void) stpcpy (recv_str_iter,
2977 "\n");
2978 LOG (GNUNET_ERROR_TYPE_DEBUG,
2979 "Writing push stats to disk\n");
2980 to_file_w_len (sub->file_name_push_recv,
2981 SIZE_DUMP_FILE,
2982 push_recv_str);
2983 GNUNET_free (sub->file_name_push_recv);
2984 sub->file_name_push_recv = NULL;
2985 3016
2986 /* Write pull delays to disk */ 3017 /* Write pull delays to disk */
2987 recv_str_iter = pull_delays_str; 3018 write_histogram_to_file (sub->pull_delays,
2988 for (uint32_t i = 0; i < 256; i++) 3019 "pull_delays");
2989 {
2990 char pull_delays_str_tmp[8];
2991
2992 GNUNET_snprintf (pull_delays_str_tmp,
2993 sizeof (pull_delays_str_tmp),
2994 "%" PRIu32 "\n",
2995 sub->pull_delays[i]);
2996 recv_str_iter = stpncpy (recv_str_iter,
2997 pull_delays_str_tmp,
2998 6);
2999 }
3000 (void) stpcpy (recv_str_iter,
3001 "\n");
3002 LOG (GNUNET_ERROR_TYPE_DEBUG, "Writing pull delays to disk\n");
3003 to_file_w_len (sub->file_name_pull_delays,
3004 SIZE_DUMP_FILE,
3005 pull_delays_str);
3006 GNUNET_free (sub->file_name_pull_delays);
3007 sub->file_name_pull_delays = NULL;
3008 3020
3009 GNUNET_CONTAINER_multipeermap_destroy (sub->observed_unique_peers); 3021 GNUNET_CONTAINER_multipeermap_destroy (sub->observed_unique_peers);
3010 sub->observed_unique_peers = NULL; 3022 sub->observed_unique_peers = NULL;
@@ -4357,7 +4369,22 @@ do_round (void *cls)
4357 } 4369 }
4358 } 4370 }
4359 // TODO independent of that also get some peers from CADET_get_peers()? 4371 // TODO independent of that also get some peers from CADET_get_peers()?
4360 sub->push_recv[CustomPeerMap_size (sub->push_map)]++; 4372 // TODO log/stat expected pushes/difference to received pushes
4373 if (CustomPeerMap_size (sub->push_map) < HISTOGRAM_FILE_SLOTS)
4374 {
4375 sub->push_recv[CustomPeerMap_size (sub->push_map)]++;
4376 }
4377 else
4378 {
4379 LOG (GNUNET_ERROR_TYPE_WARNING,
4380 "Push map size too big for histogram (%u, %u)\n",
4381 CustomPeerMap_size (sub->push_map),
4382 HISTOGRAM_FILE_SLOTS);
4383 }
4384 // FIXME check bounds of histogram
4385 sub->push_delta[(CustomPeerMap_size (sub->push_map) -
4386 sub->view_size_est_need) +
4387 (HISTOGRAM_FILE_SLOTS/2)]++;
4361 if (sub == msub) 4388 if (sub == msub)
4362 { 4389 {
4363 GNUNET_STATISTICS_set (stats, 4390 GNUNET_STATISTICS_set (stats,