X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Frps%2Ftest_rps.c;h=92d8c12ea5a1ae46ccbe826d75542e01def01932;hb=7a5a724a6f96baf80d2226326124aa01c58ad3fe;hp=60a7431677598ff91b14bce6894af9c2b6a51910;hpb=7fe5d70497352ea453289fc582089ac1c352204a;p=oweals%2Fgnunet.git diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c index 60a743167..92d8c12ea 100644 --- a/src/rps/test_rps.c +++ b/src/rps/test_rps.c @@ -2,20 +2,18 @@ This file is part of GNUnet. Copyright (C) 2009, 2012 GNUnet e.V. - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . */ /** * @file rps/test_rps.c @@ -40,6 +38,12 @@ */ static uint32_t num_peers; +/** + * How long do we run the test? + * In seconds. + */ +static uint32_t timeout_s; + /** * How long do we run the test? */ @@ -368,6 +372,11 @@ static unsigned int view_sizes; */ static int ok; +/** + * Identifier for the churn task that runs periodically + */ +static struct GNUNET_SCHEDULER_Task *post_test_task; + /** * Identifier for the churn task that runs periodically */ @@ -555,6 +564,11 @@ struct SingleTestRun uint32_t stat_collect_flags; } cur_test_run; +/** + * Did we finish the test? + */ +static int post_test; + /** * Are we shutting down? */ @@ -755,6 +769,41 @@ shutdown_op (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Shutdown task scheduled, going down.\n"); in_shutdown = GNUNET_YES; + if (NULL != post_test_task) + { + GNUNET_SCHEDULER_cancel (post_test_task); + } + if (NULL != churn_task) + { + GNUNET_SCHEDULER_cancel (churn_task); + churn_task = NULL; + } + for (i = 0; i < num_peers; i++) + { + if (NULL != rps_peers[i].rps_handle) + { + GNUNET_RPS_disconnect (rps_peers[i].rps_handle); + } + if (NULL != rps_peers[i].op) + { + GNUNET_TESTBED_operation_done (rps_peers[i].op); + } + } +} + + +/** + * Task run on timeout to collect statistics and potentially shut down. + */ +static void +post_test_op (void *cls) +{ + unsigned int i; + + post_test_task = NULL; + post_test = GNUNET_YES; + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Post test task scheduled, going down.\n"); if (NULL != churn_task) { GNUNET_SCHEDULER_cancel (churn_task); @@ -763,7 +812,10 @@ shutdown_op (void *cls) for (i = 0; i < num_peers; i++) { if (NULL != rps_peers[i].op) + { GNUNET_TESTBED_operation_done (rps_peers[i].op); + rps_peers[i].op = NULL; + } if (NULL != cur_test_run.post_test) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i); @@ -789,6 +841,13 @@ seed_peers (void *cls) unsigned int amount; unsigned int i; + if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) + { + return; + } + + GNUNET_assert (NULL != peer->rps_handle); + // TODO if malicious don't seed mal peers amount = round (.5 * num_peers); @@ -847,7 +906,7 @@ info_cb (void *cb_cls, { struct OpListEntry *entry = (struct OpListEntry *) cb_cls; - if (GNUNET_YES == in_shutdown) + if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) { return; } @@ -901,7 +960,9 @@ rps_connect_complete_cb (void *cls, struct RPSPeer *rps_peer = cls; struct GNUNET_RPS_Handle *rps = ca_result; - if (GNUNET_YES == in_shutdown) + GNUNET_assert (NULL != ca_result); + + if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) { return; } @@ -944,9 +1005,11 @@ rps_connect_adapter (void *cls, struct GNUNET_RPS_Handle *h; h = GNUNET_RPS_connect (cfg); + GNUNET_assert (NULL != h); if (NULL != cur_test_run.pre_test) cur_test_run.pre_test (cls, h); + GNUNET_assert (NULL != h); return h; } @@ -1105,10 +1168,10 @@ default_reply_handle (void *cls, if (0 == evaluate () && HAVE_QUICK_QUIT == cur_test_run.have_quick_quit) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test succeeded before timeout\n"); - GNUNET_assert (NULL != shutdown_task); - GNUNET_SCHEDULER_cancel (shutdown_task); - shutdown_task = GNUNET_SCHEDULER_add_now (&shutdown_op, NULL); - GNUNET_assert (NULL!= shutdown_task); + GNUNET_assert (NULL != post_test_task); + GNUNET_SCHEDULER_cancel (post_test_task); + post_test_task = GNUNET_SCHEDULER_add_now (&post_test_op, NULL); + GNUNET_assert (NULL!= post_test_task); } } @@ -1122,7 +1185,7 @@ request_peers (void *cls) struct RPSPeer *rps_peer; struct PendingReply *pending_rep; - if (GNUNET_YES == in_shutdown) + if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) return; rps_peer = pending_req->rps_peer; GNUNET_assert (1 <= rps_peer->num_pending_reqs); @@ -1185,7 +1248,7 @@ cancel_request_cb (void *cls) struct RPSPeer *rps_peer = cls; struct PendingReply *pending_rep; - if (GNUNET_YES == in_shutdown) + if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) return; pending_rep = rps_peer->pending_rep_head; GNUNET_assert (1 <= rps_peer->num_pending_reps); @@ -1290,7 +1353,7 @@ mal_cb (struct RPSPeer *rps_peer) { uint32_t num_mal_peers; - if (GNUNET_YES == in_shutdown) + if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) { return; } @@ -1317,7 +1380,7 @@ mal_cb (struct RPSPeer *rps_peer) static void single_req_cb (struct RPSPeer *rps_peer) { - if (GNUNET_YES == in_shutdown) + if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) { return; } @@ -1331,7 +1394,7 @@ single_req_cb (struct RPSPeer *rps_peer) static void delay_req_cb (struct RPSPeer *rps_peer) { - if (GNUNET_YES == in_shutdown) + if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) { return; } @@ -1345,7 +1408,7 @@ delay_req_cb (struct RPSPeer *rps_peer) static void seed_cb (struct RPSPeer *rps_peer) { - if (GNUNET_YES == in_shutdown) + if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) { return; } @@ -1361,7 +1424,7 @@ seed_cb (struct RPSPeer *rps_peer) static void seed_big_cb (struct RPSPeer *rps_peer) { - if (GNUNET_YES == in_shutdown) + if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) { return; } @@ -1387,7 +1450,7 @@ single_peer_seed_cb (struct RPSPeer *rps_peer) static void seed_req_cb (struct RPSPeer *rps_peer) { - if (GNUNET_YES == in_shutdown) + if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) { return; } @@ -1406,7 +1469,7 @@ seed_req_cb (struct RPSPeer *rps_peer) static void req_cancel_cb (struct RPSPeer *rps_peer) { - if (GNUNET_YES == in_shutdown) + if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) { return; } @@ -1439,7 +1502,7 @@ churn (void *cls); static void churn_test_cb (struct RPSPeer *rps_peer) { - if (GNUNET_YES == in_shutdown) + if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) { return; } @@ -1480,7 +1543,7 @@ churn_cb (void *cls, // FIXME struct OpListEntry *entry = cls; - if (GNUNET_YES == in_shutdown) + if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) { return; } @@ -1615,7 +1678,7 @@ churn (void *cls) double portion_go_online; double portion_go_offline; - if (GNUNET_YES == in_shutdown) + if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) { return; } @@ -1731,7 +1794,7 @@ profiler_reply_handle (void *cls, static void profiler_cb (struct RPSPeer *rps_peer) { - if (GNUNET_YES == in_shutdown) + if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) { return; } @@ -1809,56 +1872,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) @@ -1886,7 +1899,7 @@ static uint32_t binom (uint32_t n, uint32_t k) * @param a * @param b * - * @return + * @return */ static int is_in_view (uint32_t a, uint32_t b) { @@ -1958,7 +1971,7 @@ static void compute_probabilities (uint32_t peer_idx) { //double probs[num_peers] = { 0 }; double probs[num_peers]; - size_t probs_as_str_size = (num_peers * 6 + 1) * sizeof (char); + size_t probs_as_str_size = (num_peers * 10 + 1) * sizeof (char); char *probs_as_str = GNUNET_malloc (probs_as_str_size); char *probs_as_str_cpy; uint32_t i; @@ -1998,6 +2011,10 @@ static void compute_probabilities (uint32_t peer_idx) peer_idx, i, prob_push); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "\t\tposs choices from view: %" PRIu32 ", containing i: %" PRIu32 "\n", + binom (view_size, 0.45 * view_size), + binom (0.45 * view_size, 1)); } else { prob_push = 0; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -2013,7 +2030,9 @@ static void compute_probabilities (uint32_t peer_idx) binom (view_size - cont_views, 0.45 * view_size)); if (0 != number_of_being_in_pull_events) { - prob_pull = 1.0 / number_of_being_in_pull_events; + prob_pull = number_of_being_in_pull_events + / + (1.0 * binom (view_size, 0.45 * view_size)); } else { prob_pull = 0; @@ -2062,7 +2081,7 @@ static void compute_probabilities (uint32_t peer_idx) probs_as_str_cpy = GNUNET_strndup (probs_as_str, probs_as_str_size); tmp = GNUNET_snprintf (probs_as_str, probs_as_str_size, - "%s %3.2f", probs_as_str_cpy, probs[i]); + "%s %7.6f", probs_as_str_cpy, probs[i]); GNUNET_free (probs_as_str_cpy); GNUNET_assert (0 <= tmp); } @@ -2216,30 +2235,33 @@ void view_update_cb (void *cls, rps_peer->cur_view_count, view_size); //*rps_peer->cur_view = *peers; - memcpy (rps_peer->cur_view, - peers, - view_size * sizeof (struct GNUNET_PeerIdentity)); + GNUNET_memcpy (rps_peer->cur_view, + peers, + view_size * sizeof (struct GNUNET_PeerIdentity)); to_file ("/tmp/rps/count_in_views.txt", "%" PRIu64 " %" PRIu32 "", rps_peer->index, count_peer_in_views_2 (rps_peer->index)); cumulated_view_sizes(); - to_file ("/tmp/rps/repr.txt", - "%" PRIu64 /* index */ - " %" PRIu32 /* occurrence in views */ - " %" PRIu32 /* view sizes */ - " %f" /* fraction of repr in views */ - " %f" /* average view size */ - " %f" /* prob of occurrence in view slot */ - " %f" "", /* exp frac of repr in views */ - rps_peer->index, - count_peer_in_views_2 (rps_peer->index), - view_sizes, - count_peer_in_views_2 (rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */ - view_sizes / (view_size * 1.0), /* average view size */ - 1.0 /view_size, /* prob of occurrence in view slot */ - (1.0/view_size) * (view_sizes/view_size) /* expected fraction of repr in views */ - ); + if (0 != view_size) + { + to_file ("/tmp/rps/repr.txt", + "%" PRIu64 /* index */ + " %" PRIu32 /* occurrence in views */ + " %" PRIu32 /* view sizes */ + " %f" /* fraction of repr in views */ + " %f" /* average view size */ + " %f" /* prob of occurrence in view slot */ + " %f" "", /* exp frac of repr in views */ + rps_peer->index, + count_peer_in_views_2 (rps_peer->index), + view_sizes, + count_peer_in_views_2 (rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */ + view_sizes / (view_size * 1.0), /* average view size */ + 1.0 /view_size, /* prob of occurrence in view slot */ + (1.0/view_size) * (view_sizes/view_size) /* expected fraction of repr in views */ + ); + } compute_probabilities (rps_peer->index); all_views_updated_cb(); } @@ -2247,7 +2269,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); } @@ -2570,7 +2593,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), @@ -2683,7 +2707,12 @@ run (void *cls, if (NULL != churn_task) GNUNET_SCHEDULER_cancel (churn_task); + post_test_task = GNUNET_SCHEDULER_add_delayed (timeout, &post_test_op, NULL); + timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, + (timeout_s * 1.2) + 0.1 * num_peers); shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL); + shutdown_task = GNUNET_SCHEDULER_add_shutdown (shutdown_op, NULL); + } @@ -2712,7 +2741,7 @@ main (int argc, char *argv[]) cur_test_run.stat_collect_flags = 0; cur_test_run.have_collect_view = NO_COLLECT_VIEW; churn_task = NULL; - timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); + timeout_s = 30; if (strstr (argv[0], "malicious") != NULL) { @@ -2764,7 +2793,7 @@ main (int argc, char *argv[]) cur_test_run.main_test = seed_big_cb; cur_test_run.eval_cb = no_eval; cur_test_run.have_churn = HAVE_NO_CHURN; - timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); + timeout_s = 10; } else if (strstr (argv[0], "_single_peer_seed") != NULL) @@ -2800,7 +2829,7 @@ main (int argc, char *argv[]) cur_test_run.main_test = req_cancel_cb; cur_test_run.eval_cb = no_eval; cur_test_run.have_churn = HAVE_NO_CHURN; - timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); + timeout_s = 10; } else if (strstr (argv[0], "_churn") != NULL) @@ -2812,16 +2841,16 @@ main (int argc, char *argv[]) cur_test_run.main_test = churn_test_cb; cur_test_run.reply_handle = default_reply_handle; cur_test_run.eval_cb = default_eval_cb; - cur_test_run.have_churn = HAVE_CHURN; + cur_test_run.have_churn = HAVE_NO_CHURN; cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT; - timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); + timeout_s = 10; } else if (strstr (argv[0], "profiler") != NULL) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n"); cur_test_run.name = "test-rps-profiler"; - num_peers = 10; + num_peers = 16; mal_type = 3; cur_test_run.init_peer = profiler_init_peer; //cur_test_run.pre_test = mal_pre; @@ -2832,7 +2861,8 @@ main (int argc, char *argv[]) cur_test_run.post_test = post_profiler; cur_test_run.request_interval = 2; cur_test_run.num_requests = 5; - cur_test_run.have_churn = HAVE_CHURN; + //cur_test_run.have_churn = HAVE_CHURN; + cur_test_run.have_churn = HAVE_NO_CHURN; cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT; cur_test_run.have_collect_statistics = COLLECT_STATISTICS; cur_test_run.stat_collect_flags = STAT_TYPE_ROUNDS | @@ -2852,12 +2882,13 @@ main (int argc, char *argv[]) STAT_TYPE_RECV_PULL_REQ | STAT_TYPE_RECV_PULL_REP; cur_test_run.have_collect_view = COLLECT_VIEW; - timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300); + timeout_s = 150; /* 'Clean' directory */ (void) GNUNET_DISK_directory_remove ("/tmp/rps/"); GNUNET_DISK_directory_create ("/tmp/rps/"); } + timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_s); rps_peers = GNUNET_new_array (num_peers, struct RPSPeer); peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO); @@ -2885,6 +2916,7 @@ main (int argc, char *argv[]) } ret_value = cur_test_run.eval_cb(); + if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) { GNUNET_array_grow (rps_peers->cur_view,