diff options
author | Julius Bünger <buenger@mytum.de> | 2015-06-10 11:01:49 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2015-06-10 11:01:49 +0000 |
commit | 33a96e5ef8b35e7e250f6e31175735ce863801e8 (patch) | |
tree | 56b3e6145806d0c90a5424241e032d33cadaad09 /src/rps/test_rps.c | |
parent | 11ca82f4300e03a0fd82e1507b3f1fc9aefbbabd (diff) | |
download | gnunet-33a96e5ef8b35e7e250f6e31175735ce863801e8.tar.gz gnunet-33a96e5ef8b35e7e250f6e31175735ce863801e8.zip |
restructured test
Diffstat (limited to 'src/rps/test_rps.c')
-rw-r--r-- | src/rps/test_rps.c | 297 |
1 files changed, 244 insertions, 53 deletions
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c index 9bf963a8a..4c0610751 100644 --- a/src/rps/test_rps.c +++ b/src/rps/test_rps.c | |||
@@ -189,6 +189,13 @@ typedef void (*PreTest) (void *cls, struct GNUNET_RPS_Handle *h); | |||
189 | typedef void (*MainTest) (struct RPSPeer *rps_peer); | 189 | typedef void (*MainTest) (struct RPSPeer *rps_peer); |
190 | 190 | ||
191 | /** | 191 | /** |
192 | * Callback called once the requested random peers are available | ||
193 | */ | ||
194 | typedef void (*ReplyHandle) (void *cls, | ||
195 | uint64_t n, | ||
196 | const struct GNUNET_PeerIdentity *recv_peers); | ||
197 | |||
198 | /** | ||
192 | * Called directly before disconnecting from the service | 199 | * Called directly before disconnecting from the service |
193 | */ | 200 | */ |
194 | typedef void (*PostTest) (void *cls, struct GNUNET_RPS_Handle *h); | 201 | typedef void (*PostTest) (void *cls, struct GNUNET_RPS_Handle *h); |
@@ -220,6 +227,11 @@ struct SingleTestRun | |||
220 | MainTest main_test; | 227 | MainTest main_test; |
221 | 228 | ||
222 | /** | 229 | /** |
230 | * Callback called once the requested peers are available | ||
231 | */ | ||
232 | ReplyHandle reply_handle; | ||
233 | |||
234 | /** | ||
223 | * Called directly before disconnecting from the service | 235 | * Called directly before disconnecting from the service |
224 | */ | 236 | */ |
225 | PostTest post_test; | 237 | PostTest post_test; |
@@ -228,10 +240,110 @@ struct SingleTestRun | |||
228 | * Function to evaluate the test results | 240 | * Function to evaluate the test results |
229 | */ | 241 | */ |
230 | EvaluationCallback eval_cb; | 242 | EvaluationCallback eval_cb; |
243 | |||
244 | /** | ||
245 | * Request interval | ||
246 | */ | ||
247 | uint32_t request_interval; | ||
248 | |||
249 | /** | ||
250 | * Number of Requests to make. | ||
251 | */ | ||
252 | uint32_t num_requests; | ||
231 | } cur_test_run; | 253 | } cur_test_run; |
232 | 254 | ||
233 | 255 | ||
234 | /** | 256 | /** |
257 | * Append arguments to file | ||
258 | */ | ||
259 | static void | ||
260 | to_file_ (char *file_name, char *line) | ||
261 | { | ||
262 | struct GNUNET_DISK_FileHandle *f; | ||
263 | /* char output_buffer[512]; */ | ||
264 | size_t size; | ||
265 | /* int size; */ | ||
266 | size_t size2; | ||
267 | |||
268 | if (NULL == (f = GNUNET_DISK_file_open (file_name, | ||
269 | GNUNET_DISK_OPEN_APPEND | | ||
270 | GNUNET_DISK_OPEN_WRITE | | ||
271 | GNUNET_DISK_OPEN_CREATE, | ||
272 | GNUNET_DISK_PERM_USER_READ | | ||
273 | GNUNET_DISK_PERM_USER_WRITE | | ||
274 | GNUNET_DISK_PERM_GROUP_READ | | ||
275 | GNUNET_DISK_PERM_OTHER_READ))) | ||
276 | { | ||
277 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
278 | "Not able to open file %s\n", | ||
279 | file_name); | ||
280 | return; | ||
281 | } | ||
282 | /* size = GNUNET_snprintf (output_buffer, | ||
283 | sizeof (output_buffer), | ||
284 | "%llu %s\n", | ||
285 | GNUNET_TIME_absolute_get ().abs_value_us, | ||
286 | line); | ||
287 | if (0 > size) | ||
288 | { | ||
289 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
290 | "Failed to write string to buffer (size: %i)\n", | ||
291 | size); | ||
292 | return; | ||
293 | } */ | ||
294 | |||
295 | size = strlen (line) * sizeof (char); | ||
296 | |||
297 | size2 = GNUNET_DISK_file_write (f, line, size); | ||
298 | if (size != size2) | ||
299 | { | ||
300 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
301 | "Unable to write to file! (Size: %u, size2: %u)\n", | ||
302 | size, | ||
303 | size2); | ||
304 | return; | ||
305 | } | ||
306 | |||
307 | if (GNUNET_YES != GNUNET_DISK_file_close (f)) | ||
308 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
309 | "Unable to close file\n"); | ||
310 | } | ||
311 | |||
312 | /** | ||
313 | * This function is used to facilitate writing important information to disk | ||
314 | */ | ||
315 | #define to_file(file_name, ...) do {\ | ||
316 | char tmp_buf[512];\ | ||
317 | int size;\ | ||
318 | size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ | ||
319 | if (0 > size)\ | ||
320 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\ | ||
321 | "Failed to create tmp_buf\n");\ | ||
322 | else\ | ||
323 | to_file_(file_name,tmp_buf);\ | ||
324 | } while (0); | ||
325 | |||
326 | /** | ||
327 | * Write the ids and their according index in the given array to a file | ||
328 | * Unused | ||
329 | */ | ||
330 | /* static void | ||
331 | ids_to_file (char *file_name, | ||
332 | struct GNUNET_PeerIdentity *peer_ids, | ||
333 | unsigned int num_peer_ids) | ||
334 | { | ||
335 | unsigned int i; | ||
336 | |||
337 | for (i=0 ; i < num_peer_ids ; i++) | ||
338 | { | ||
339 | to_file (file_name, | ||
340 | "%u\t%s", | ||
341 | i, | ||
342 | GNUNET_i2s_full (&peer_ids[i])); | ||
343 | } | ||
344 | } */ | ||
345 | |||
346 | /** | ||
235 | * Test the success of a single test | 347 | * Test the success of a single test |
236 | */ | 348 | */ |
237 | static int | 349 | static int |
@@ -360,53 +472,6 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
360 | 472 | ||
361 | 473 | ||
362 | /** | 474 | /** |
363 | * Callback to call on receipt of a reply | ||
364 | * | ||
365 | * @param cls closure | ||
366 | * @param n number of peers | ||
367 | * @param recv_peers the received peers | ||
368 | */ | ||
369 | static void | ||
370 | handle_reply (void *cls, uint64_t n, const struct GNUNET_PeerIdentity *recv_peers) | ||
371 | { | ||
372 | struct RPSPeer *rps_peer = (struct RPSPeer *) cls; | ||
373 | unsigned int i; | ||
374 | |||
375 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
376 | "[%s] got %" PRIu64 " peers:\n", | ||
377 | GNUNET_i2s (rps_peer->peer_id), | ||
378 | n); | ||
379 | |||
380 | for (i = 0 ; i < n ; i++) | ||
381 | { | ||
382 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
383 | "%u: %s\n", | ||
384 | i, | ||
385 | GNUNET_i2s (&recv_peers[i])); | ||
386 | |||
387 | GNUNET_array_append (rps_peer->rec_ids, rps_peer->num_rec_ids, recv_peers[i]); | ||
388 | } | ||
389 | } | ||
390 | |||
391 | |||
392 | /** | ||
393 | * Request random peers. | ||
394 | */ | ||
395 | void | ||
396 | request_peers (void *cls, | ||
397 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
398 | { | ||
399 | struct RPSPeer *rps_peer = (struct RPSPeer *) cls; | ||
400 | |||
401 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
402 | "Requesting one peer\n"); | ||
403 | |||
404 | (void) GNUNET_RPS_request_peers (rps_peer->rps_handle, 1, handle_reply, rps_peer); | ||
405 | //rps_peer->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle, 1, handle_reply, rps_peer); | ||
406 | } | ||
407 | |||
408 | |||
409 | /** | ||
410 | * Seed peers. | 475 | * Seed peers. |
411 | */ | 476 | */ |
412 | void | 477 | void |
@@ -456,6 +521,11 @@ info_cb (void *cb_cls, | |||
456 | rps_peers[entry->index].rec_ids = NULL; | 521 | rps_peers[entry->index].rec_ids = NULL; |
457 | rps_peers[entry->index].num_rec_ids = 0; | 522 | rps_peers[entry->index].num_rec_ids = 0; |
458 | 523 | ||
524 | to_file ("/tmp/rps/peer_ids", | ||
525 | "%u\t%s\n", | ||
526 | entry->index, | ||
527 | GNUNET_i2s_full (&rps_peer_ids[entry->index])); | ||
528 | |||
459 | GNUNET_TESTBED_operation_done (entry->op); | 529 | GNUNET_TESTBED_operation_done (entry->op); |
460 | 530 | ||
461 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); | 531 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); |
@@ -547,6 +617,7 @@ rps_disconnect_adapter (void *cls, | |||
547 | * Definition of tests | 617 | * Definition of tests |
548 | ***********************************************************************/ | 618 | ***********************************************************************/ |
549 | 619 | ||
620 | // TODO check whether tests can be stopped earlier | ||
550 | static int | 621 | static int |
551 | default_eval_cb (void) | 622 | default_eval_cb (void) |
552 | { | 623 | { |
@@ -559,6 +630,57 @@ no_eval (void) | |||
559 | return 1; | 630 | return 1; |
560 | } | 631 | } |
561 | 632 | ||
633 | /** | ||
634 | * Callback to call on receipt of a reply | ||
635 | * | ||
636 | * @param cls closure | ||
637 | * @param n number of peers | ||
638 | * @param recv_peers the received peers | ||
639 | */ | ||
640 | static void | ||
641 | default_reply_handle (void *cls, | ||
642 | uint64_t n, | ||
643 | const struct GNUNET_PeerIdentity *recv_peers) | ||
644 | { | ||
645 | struct RPSPeer *rps_peer = (struct RPSPeer *) cls; | ||
646 | unsigned int i; | ||
647 | |||
648 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
649 | "[%s] got %" PRIu64 " peers:\n", | ||
650 | GNUNET_i2s (rps_peer->peer_id), | ||
651 | n); | ||
652 | |||
653 | for (i = 0 ; i < n ; i++) | ||
654 | { | ||
655 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
656 | "%u: %s\n", | ||
657 | i, | ||
658 | GNUNET_i2s (&recv_peers[i])); | ||
659 | |||
660 | GNUNET_array_append (rps_peer->rec_ids, rps_peer->num_rec_ids, recv_peers[i]); | ||
661 | } | ||
662 | } | ||
663 | |||
664 | /** | ||
665 | * Request random peers. | ||
666 | */ | ||
667 | static void | ||
668 | request_peers (void *cls, | ||
669 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
670 | { | ||
671 | struct RPSPeer *rps_peer = (struct RPSPeer *) cls; | ||
672 | |||
673 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
674 | "Requesting one peer\n"); | ||
675 | |||
676 | GNUNET_free (GNUNET_RPS_request_peers (rps_peer->rps_handle, | ||
677 | 1, | ||
678 | cur_test_run.reply_handle, | ||
679 | rps_peer)); | ||
680 | //rps_peer->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle, 1, handle_reply, rps_peer); | ||
681 | } | ||
682 | |||
683 | |||
562 | /*********************************** | 684 | /*********************************** |
563 | * MALICIOUS | 685 | * MALICIOUS |
564 | ***********************************/ | 686 | ***********************************/ |
@@ -792,6 +914,8 @@ churn (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
792 | } | 914 | } |
793 | } | 915 | } |
794 | 916 | ||
917 | GNUNET_free (permut); | ||
918 | |||
795 | churn_task = GNUNET_SCHEDULER_add_delayed ( | 919 | churn_task = GNUNET_SCHEDULER_add_delayed ( |
796 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), | 920 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), |
797 | churn, | 921 | churn, |
@@ -807,20 +931,83 @@ profiler_pre (void *cls, struct GNUNET_RPS_Handle *h) | |||
807 | // churn, NULL); | 931 | // churn, NULL); |
808 | mal_pre (cls, h); | 932 | mal_pre (cls, h); |
809 | 933 | ||
810 | if (NULL == churn_task) | 934 | /* if (NULL == churn_task) |
811 | { | 935 | { |
812 | churn_task = GNUNET_SCHEDULER_add_delayed ( | 936 | churn_task = GNUNET_SCHEDULER_add_delayed ( |
813 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), | 937 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), |
814 | churn, | 938 | churn, |
815 | NULL); | 939 | NULL); |
940 | } */ | ||
941 | } | ||
942 | |||
943 | |||
944 | /** | ||
945 | * Callback to call on receipt of a reply | ||
946 | * | ||
947 | * @param cls closure | ||
948 | * @param n number of peers | ||
949 | * @param recv_peers the received peers | ||
950 | */ | ||
951 | static void | ||
952 | profiler_reply_handle (void *cls, | ||
953 | uint64_t n, | ||
954 | const struct GNUNET_PeerIdentity *recv_peers) | ||
955 | { | ||
956 | struct RPSPeer *rps_peer = (struct RPSPeer *) cls; | ||
957 | char *file_name; | ||
958 | unsigned int i; | ||
959 | |||
960 | file_name = "/tmp/rps/received_ids"; | ||
961 | |||
962 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
963 | "[%s] got %" PRIu64 " peers:\n", | ||
964 | GNUNET_i2s (rps_peer->peer_id), | ||
965 | n); | ||
966 | |||
967 | for (i = 0 ; i < n ; i++) | ||
968 | { | ||
969 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
970 | "%u: %s\n", | ||
971 | i, | ||
972 | GNUNET_i2s (&recv_peers[i])); | ||
973 | |||
974 | /* GNUNET_array_append (rps_peer->rec_ids, rps_peer->num_rec_ids, recv_peers[i]); */ | ||
975 | to_file (file_name, | ||
976 | "%s\n", | ||
977 | GNUNET_i2s_full (&recv_peers[i])); | ||
816 | } | 978 | } |
817 | } | 979 | } |
818 | 980 | ||
981 | |||
819 | static void | 982 | static void |
820 | profiler_cb (struct RPSPeer *rps_peer) | 983 | profiler_cb (struct RPSPeer *rps_peer) |
821 | { | 984 | { |
822 | // We're not requesting peers | 985 | uint32_t i; |
823 | // TODO maybe seed | 986 | |
987 | /* Churn only at peers that do not request peers for evaluation */ | ||
988 | if (NULL == churn_task && | ||
989 | rps_peer->index != num_peers - 2) | ||
990 | { | ||
991 | churn_task = GNUNET_SCHEDULER_add_delayed ( | ||
992 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), | ||
993 | churn, | ||
994 | NULL); | ||
995 | } | ||
996 | |||
997 | /* Only request peer ids at one peer. | ||
998 | * (It's the before-last because last one is target of the focussed attack.) | ||
999 | */ | ||
1000 | if (rps_peer->index == num_peers - 2) | ||
1001 | { | ||
1002 | for (i = 0 ; i < cur_test_run.num_requests ; i++) | ||
1003 | { | ||
1004 | GNUNET_SCHEDULER_add_delayed ( | ||
1005 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | ||
1006 | cur_test_run.request_interval * i), | ||
1007 | request_peers, | ||
1008 | rps_peer); | ||
1009 | } | ||
1010 | } | ||
824 | } | 1011 | } |
825 | 1012 | ||
826 | 1013 | ||
@@ -893,7 +1080,6 @@ run (void *cls, | |||
893 | if (NULL != churn_task) | 1080 | if (NULL != churn_task) |
894 | GNUNET_SCHEDULER_cancel (churn_task); | 1081 | GNUNET_SCHEDULER_cancel (churn_task); |
895 | 1082 | ||
896 | //GNUNET_SCHEDULER_add_delayed (TIMEOUT, &shutdown_task, NULL); | ||
897 | GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_task, NULL); | 1083 | GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_task, NULL); |
898 | } | 1084 | } |
899 | 1085 | ||
@@ -910,6 +1096,7 @@ main (int argc, char *argv[]) | |||
910 | { | 1096 | { |
911 | cur_test_run.name = "test-rps-default"; | 1097 | cur_test_run.name = "test-rps-default"; |
912 | cur_test_run.pre_test = NULL; | 1098 | cur_test_run.pre_test = NULL; |
1099 | cur_test_run.reply_handle = default_reply_handle; | ||
913 | cur_test_run.eval_cb = default_eval_cb; | 1100 | cur_test_run.eval_cb = default_eval_cb; |
914 | churn_task = NULL; | 1101 | churn_task = NULL; |
915 | 1102 | ||
@@ -999,9 +1186,14 @@ main (int argc, char *argv[]) | |||
999 | mal_type = 3; | 1186 | mal_type = 3; |
1000 | cur_test_run.pre_test = profiler_pre; | 1187 | cur_test_run.pre_test = profiler_pre; |
1001 | cur_test_run.main_test = profiler_cb; | 1188 | cur_test_run.main_test = profiler_cb; |
1189 | cur_test_run.reply_handle = profiler_reply_handle; | ||
1002 | cur_test_run.eval_cb = no_eval; | 1190 | cur_test_run.eval_cb = no_eval; |
1191 | cur_test_run.request_interval = 2; | ||
1192 | cur_test_run.num_requests = 50; | ||
1193 | |||
1194 | num_peers = 50; | ||
1003 | 1195 | ||
1004 | num_peers = 5; | 1196 | GNUNET_DISK_directory_create ("/tmp/rps/"); |
1005 | //timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90); | 1197 | //timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90); |
1006 | } | 1198 | } |
1007 | 1199 | ||
@@ -1009,7 +1201,6 @@ main (int argc, char *argv[]) | |||
1009 | rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity); | 1201 | rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity); |
1010 | 1202 | ||
1011 | ok = 1; | 1203 | ok = 1; |
1012 | //(void) GNUNET_TESTBED_test_run ("test-rps-multipeer", | ||
1013 | (void) GNUNET_TESTBED_test_run (cur_test_run.name, | 1204 | (void) GNUNET_TESTBED_test_run (cur_test_run.name, |
1014 | "test_rps.conf", | 1205 | "test_rps.conf", |
1015 | num_peers, | 1206 | num_peers, |