aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
authorNils Gillmann <ng0@n0.is>2018-05-06 19:01:52 +0000
committerNils Gillmann <ng0@n0.is>2018-05-06 19:01:52 +0000
commitf13af7e7281064380def70d0b4392b4351211655 (patch)
treeb167e9cf852f56fa0272c0eee1a311599320d469 /src/dht
parent9fbda6db66bf8dc074de6c8792f369801e4e5999 (diff)
parent4c72bbbf38d25ac5a2301315f5028fceb2893b7e (diff)
downloadgnunet-f13af7e7281064380def70d0b4392b4351211655.tar.gz
gnunet-f13af7e7281064380def70d0b4392b4351211655.zip
Merge branch 'master' of gnunet.org:gnunet
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/gnunet_dht_profiler.c681
1 files changed, 229 insertions, 452 deletions
diff --git a/src/dht/gnunet_dht_profiler.c b/src/dht/gnunet_dht_profiler.c
index a8807bea8..12e99f65d 100644
--- a/src/dht/gnunet_dht_profiler.c
+++ b/src/dht/gnunet_dht_profiler.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2014 GNUnet e.V. 3 Copyright (C) 2014, 2018 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -29,8 +29,8 @@
29#include "gnunet_testbed_service.h" 29#include "gnunet_testbed_service.h"
30#include "gnunet_dht_service.h" 30#include "gnunet_dht_service.h"
31 31
32#define INFO(...) \ 32#define MESSAGE(...) \
33 GNUNET_log (GNUNET_ERROR_TYPE_INFO, __VA_ARGS__) 33 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, __VA_ARGS__)
34 34
35#define DEBUG(...) \ 35#define DEBUG(...) \
36 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) 36 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
@@ -38,7 +38,7 @@
38/** 38/**
39 * Number of peers which should perform a PUT out of 100 peers 39 * Number of peers which should perform a PUT out of 100 peers
40 */ 40 */
41#define PUT_PROBABILITY 50 41static unsigned int put_probability = 100;
42 42
43/** 43/**
44 * Configuration 44 * Configuration
@@ -121,7 +121,12 @@ struct ActiveContext
121 /** 121 /**
122 * Delay task 122 * Delay task
123 */ 123 */
124 struct GNUNET_SCHEDULER_Task * delay_task; 124 struct GNUNET_SCHEDULER_Task *delay_task;
125
126 /**
127 * How many puts should we still issue?
128 */
129 unsigned int put_count;
125 130
126 /** 131 /**
127 * The size of the @e put_data 132 * The size of the @e put_data
@@ -183,17 +188,17 @@ static unsigned int n_dht;
183/** 188/**
184 * Number of DHT PUTs made 189 * Number of DHT PUTs made
185 */ 190 */
186static unsigned int n_puts; 191static unsigned long long n_puts;
187 192
188/** 193/**
189 * Number of DHT PUTs succeeded 194 * Number of DHT PUTs to be made per peer.
190 */ 195 */
191static unsigned int n_puts_ok; 196static unsigned int num_puts_per_peer = 1;
192 197
193/** 198/**
194 * Number of DHT PUTs failed 199 * Number of DHT PUTs succeeded
195 */ 200 */
196static unsigned int n_puts_fail; 201static unsigned long long n_puts_ok;
197 202
198/** 203/**
199 * Number of DHT GETs made 204 * Number of DHT GETs made
@@ -226,11 +231,6 @@ static unsigned int max_searches;
226static struct GNUNET_TESTBED_Operation *bandwidth_stats_op; 231static struct GNUNET_TESTBED_Operation *bandwidth_stats_op;
227 232
228/** 233/**
229 * To get successor stats.
230 */
231static struct GNUNET_TESTBED_Operation *successor_stats_op;
232
233/**
234 * Testbed peer handles. 234 * Testbed peer handles.
235 */ 235 */
236static struct GNUNET_TESTBED_Peer **testbed_handles; 236static struct GNUNET_TESTBED_Peer **testbed_handles;
@@ -266,42 +266,6 @@ static unsigned int total_put_path_length;
266static unsigned int total_get_path_length; 266static unsigned int total_get_path_length;
267 267
268/** 268/**
269 * Hashmap to store pair of peer and its corresponding successor.
270 */
271static struct GNUNET_CONTAINER_MultiHashMap *successor_peer_hashmap;
272
273/**
274 * Key to start the lookup on successor_peer_hashmap.
275 */
276static struct GNUNET_HashCode *start_key;
277
278/**
279 * Flag used to get the start_key.
280 */
281static int flag = 0;
282
283/**
284 * Task to collect peer and its current successor statistics.
285 */
286static struct GNUNET_SCHEDULER_Task * successor_stats_task;
287
288/**
289 * Closure for successor_stats_task.
290 */
291struct Collect_Stat_Context
292{
293 /**
294 * Current Peer Context.
295 */
296 struct Context *service_connect_ctx;
297
298 /**
299 * Testbed operation acting on this peer
300 */
301 struct GNUNET_TESTBED_Operation *op;
302};
303
304/**
305 * List of all the peers contexts. 269 * List of all the peers contexts.
306 */ 270 */
307struct Context **peer_contexts = NULL; 271struct Context **peer_contexts = NULL;
@@ -327,20 +291,6 @@ static enum
327 */ 291 */
328static int in_shutdown = 0; 292static int in_shutdown = 0;
329 293
330/**
331 * Total number of times to check if circle is formed or not.
332 */
333static unsigned int tries;
334
335
336/**
337 * Task that collects successor statistics from all the peers.
338 *
339 * @param cls
340 */
341static void
342collect_stats (void *cls);
343
344 294
345/** 295/**
346 * Connect to DHT services of active peers 296 * Connect to DHT services of active peers
@@ -358,12 +308,11 @@ static void
358do_shutdown (void *cls) 308do_shutdown (void *cls)
359{ 309{
360 struct ActiveContext *ac; 310 struct ActiveContext *ac;
361 unsigned int cnt;
362 311
363 in_shutdown = GNUNET_YES; 312 in_shutdown = GNUNET_YES;
364 if (NULL != a_ctx) 313 if (NULL != a_ctx)
365 { 314 {
366 for (cnt=0; cnt < num_peers; cnt++) 315 for (unsigned int cnt=0; cnt < num_peers; cnt++)
367 { 316 {
368 /* Cleanup active context if this peer is an active peer */ 317 /* Cleanup active context if this peer is an active peer */
369 ac = a_ctx[cnt].ac; 318 ac = a_ctx[cnt].ac;
@@ -392,16 +341,6 @@ do_shutdown (void *cls)
392 GNUNET_TESTBED_operation_done (bandwidth_stats_op); 341 GNUNET_TESTBED_operation_done (bandwidth_stats_op);
393 bandwidth_stats_op = NULL; 342 bandwidth_stats_op = NULL;
394 } 343 }
395 if (NULL != successor_stats_op)
396 {
397 GNUNET_TESTBED_operation_done (successor_stats_op);
398 successor_stats_op = NULL;
399 }
400 if (NULL != successor_stats_task)
401 {
402 GNUNET_SCHEDULER_cancel (successor_stats_task);
403 successor_stats_task = NULL;
404 }
405 GNUNET_free_non_null (a_ac); 344 GNUNET_free_non_null (a_ac);
406} 345}
407 346
@@ -420,10 +359,13 @@ bandwidth_stats_cont (void *cls,
420 struct GNUNET_TESTBED_Operation *op, 359 struct GNUNET_TESTBED_Operation *op,
421 const char *emsg) 360 const char *emsg)
422{ 361{
423 INFO ("# Outgoing bandwidth: %llu\n", 362 MESSAGE ("# Outgoing bandwidth: %llu\n",
424 (unsigned long long) outgoing_bandwidth); 363 (unsigned long long) outgoing_bandwidth);
425 INFO ("# Incoming bandwidth: %llu\n", 364 MESSAGE ("# Incoming bandwidth: %llu\n",
426 (unsigned long long) incoming_bandwidth); 365 (unsigned long long) incoming_bandwidth);
366 fprintf (stderr,
367 "Benchmark done. Collect data via gnunet-statisics, then press ENTER to exit.\n");
368 getchar ();
427 GNUNET_SCHEDULER_shutdown (); 369 GNUNET_SCHEDULER_shutdown ();
428} 370}
429 371
@@ -447,40 +389,48 @@ bandwidth_stats_iterator (void *cls,
447 uint64_t value, 389 uint64_t value,
448 int is_persistent) 390 int is_persistent)
449{ 391{
450 static const char *s_sent = "# Bytes transmitted to other peers"; 392 static const char *s_sent = "# Bytes transmitted to other peers";
451 static const char *s_recv = "# Bytes received from other peers"; 393 static const char *s_recv = "# Bytes received from other peers";
452
453 if (0 == strncmp (s_sent, name, strlen (s_sent)))
454 outgoing_bandwidth = outgoing_bandwidth + value;
455 else if (0 == strncmp(s_recv, name, strlen (s_recv)))
456 incoming_bandwidth = incoming_bandwidth + value;
457 394
458 return GNUNET_OK; 395 if (0 == strncmp (s_sent, name, strlen (s_sent)))
396 outgoing_bandwidth = outgoing_bandwidth + value;
397 else if (0 == strncmp(s_recv, name, strlen (s_recv)))
398 incoming_bandwidth = incoming_bandwidth + value;
399 return GNUNET_OK;
459} 400}
460 401
461 402
462static void 403static void
463summarize () 404summarize ()
464{ 405{
465 INFO ("# PUTS made: %u\n", n_puts); 406 MESSAGE ("# PUTS started: %llu\n",
466 INFO ("# PUTS succeeded: %u\n", n_puts_ok); 407 n_puts);
467 INFO ("# PUTS failed: %u\n", n_puts_fail); 408 MESSAGE ("# PUTS succeeded: %llu\n",
468 INFO ("# GETS made: %u\n", n_gets); 409 n_puts_ok);
469 INFO ("# GETS succeeded: %u\n", n_gets_ok); 410 MESSAGE ("# GETS made: %u\n",
470 INFO ("# GETS failed: %u\n", n_gets_fail); 411 n_gets);
471 INFO ("# average_put_path_length: %f\n", average_put_path_length); 412 MESSAGE ("# GETS succeeded: %u\n",
472 INFO ("# average_get_path_length: %f\n", average_get_path_length); 413 n_gets_ok);
414 MESSAGE ("# GETS failed: %u\n",
415 n_gets_fail);
416 MESSAGE ("# average_put_path_length: %f\n",
417 average_put_path_length);
418 MESSAGE ("# average_get_path_length: %f\n",
419 average_get_path_length);
473 420
474 if (NULL == testbed_handles) 421 if (NULL == testbed_handles)
475 { 422 {
476 INFO ("No peers found\n"); 423 MESSAGE ("No peers found\n");
477 return; 424 return;
478 } 425 }
479 /* Collect Stats*/ 426 /* Collect Stats*/
480 bandwidth_stats_op = GNUNET_TESTBED_get_statistics (n_active, testbed_handles, 427 bandwidth_stats_op = GNUNET_TESTBED_get_statistics (n_active,
481 "dht", NULL, 428 testbed_handles,
482 bandwidth_stats_iterator, 429 "dht",
483 bandwidth_stats_cont, NULL); 430 NULL,
431 bandwidth_stats_iterator,
432 bandwidth_stats_cont,
433 NULL);
484} 434}
485 435
486 436
@@ -547,9 +497,12 @@ get_iter (void *cls,
547 struct Context *ctx = ac->ctx; 497 struct Context *ctx = ac->ctx;
548 498
549 /* Check the keys of put and get match or not. */ 499 /* Check the keys of put and get match or not. */
550 GNUNET_assert (0 == memcmp (key, &get_ac->hash, sizeof (struct GNUNET_HashCode))); 500 GNUNET_assert (0 == memcmp (key,
501 &get_ac->hash,
502 sizeof (struct GNUNET_HashCode)));
551 /* we found the data we are looking for */ 503 /* we found the data we are looking for */
552 DEBUG ("We found a GET request; %u remaining\n", n_gets - (n_gets_fail + n_gets_ok)); //FIXME: It always prints 1. 504 DEBUG ("We found a GET request; %u remaining\n",
505 n_gets - (n_gets_fail + n_gets_ok)); //FIXME: It always prints 1.
553 n_gets_ok++; 506 n_gets_ok++;
554 get_ac->nrefs--; 507 get_ac->nrefs--;
555 GNUNET_DHT_get_stop (ac->dht_get); 508 GNUNET_DHT_get_stop (ac->dht_get);
@@ -591,79 +544,67 @@ delayed_get (void *cls)
591 get_ac = NULL; 544 get_ac = NULL;
592 while (1) 545 while (1)
593 { 546 {
594 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, n_active); 547 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
548 n_active);
595 get_ac = &a_ac[r]; 549 get_ac = &a_ac[r];
596 if (NULL != get_ac->put_data) 550 if (NULL != get_ac->put_data)
597 break; 551 break;
598 } 552 }
599 get_ac->nrefs++; 553 get_ac->nrefs++;
600 ac->get_ac = get_ac; 554 ac->get_ac = get_ac;
601 DEBUG ("GET_REQUEST_START key %s \n", GNUNET_h2s((struct GNUNET_HashCode *)ac->put_data)); 555 DEBUG ("GET_REQUEST_START key %s \n",
556 GNUNET_h2s((struct GNUNET_HashCode *) ac->put_data));
602 ac->dht_get = GNUNET_DHT_get_start (ac->dht, 557 ac->dht_get = GNUNET_DHT_get_start (ac->dht,
603 GNUNET_BLOCK_TYPE_TEST, 558 GNUNET_BLOCK_TYPE_TEST,
604 &get_ac->hash, 559 &get_ac->hash,
605 1, /* replication level */ 560 1, /* replication level */
606 GNUNET_DHT_RO_NONE, 561 GNUNET_DHT_RO_NONE,
607 NULL, 0, /* extended query and size */ 562 NULL,
608 get_iter, ac); /* GET iterator and closure 563 0, /* extended query and size */
609 */ 564 get_iter,
565 ac); /* GET iterator and closure */
610 n_gets++; 566 n_gets++;
611 567
612 /* schedule the timeout task for GET */ 568 /* schedule the timeout task for GET */
613 ac->delay_task = GNUNET_SCHEDULER_add_delayed (timeout, &cancel_get, ac); 569 ac->delay_task = GNUNET_SCHEDULER_add_delayed (timeout,
570 &cancel_get,
571 ac);
614} 572}
615 573
616 574
617/** 575/**
618 * Task to teardown the dht connection. We do it as a task because calling 576 * Task to do DHT PUTs. If the "put_count" hits zero,
619 * GNUNET_DHT_disconnect() from put_continutation_callback seems illegal (the 577 * we stop the TESTBED operation (connection to DHT)
620 * put_continuation_callback() is getting called again synchronously). Also, 578 * so that others PUTs have a chance.
621 * only free the operation when we are not shutting down; the shutdown task will
622 * clear the operation during shutdown.
623 * 579 *
624 * @param cls the context 580 * @param cls the active context
625 */ 581 */
626static void 582static void
627teardown_dht_connection (void *cls) 583delayed_put (void *cls);
628{
629 struct Context *ctx = cls;
630 struct GNUNET_TESTBED_Operation *op;
631
632 GNUNET_assert (NULL != ctx);
633 GNUNET_assert (NULL != (op = ctx->op));
634 ctx->op = NULL;
635 GNUNET_TESTBED_operation_done (op);
636}
637 584
638 585
639/** 586/**
640 * Queue up a delayed task for doing DHT GET 587 * Conclude individual PUT operation, schedule the
588 * next one.
641 * 589 *
642 * @param cls the active context 590 * @param cls the active context
643 * @param success #GNUNET_OK if the PUT was transmitted,
644 * #GNUNET_NO on timeout,
645 * #GNUNET_SYSERR on disconnect from service
646 * after the PUT message was transmitted
647 * (so we don't know if it was received or not)
648 */ 591 */
649static void 592static void
650put_cont (void *cls, int success) 593put_cont (void *cls)
651{ 594{
652 struct ActiveContext *ac = cls; 595 struct ActiveContext *ac = cls;
653 struct Context *ctx = ac->ctx;
654 596
655 ac->dht_put = NULL; 597 ac->dht_put = NULL;
656 if (success) 598 n_puts_ok++;
657 n_puts_ok++; 599 ac->delay_task = GNUNET_SCHEDULER_add_now (&delayed_put,
658 else 600 ac);
659 n_puts_fail++;
660 GNUNET_assert (NULL != ctx);
661 (void) GNUNET_SCHEDULER_add_now (&teardown_dht_connection, ctx);
662} 601}
663 602
664 603
665/** 604/**
666 * Task to do DHT PUTs 605 * Task to do DHT PUTs. If the "put_count" hits zero,
606 * we stop the TESTBED operation (connection to DHT)
607 * so that others PUTs have a chance.
667 * 608 *
668 * @param cls the active context 609 * @param cls the active context
669 */ 610 */
@@ -673,16 +614,33 @@ delayed_put (void *cls)
673 struct ActiveContext *ac = cls; 614 struct ActiveContext *ac = cls;
674 615
675 ac->delay_task = NULL; 616 ac->delay_task = NULL;
617 if (0 == ac->put_count)
618 {
619 struct Context *ctx = ac->ctx;
620 struct GNUNET_TESTBED_Operation *op;
621
622 GNUNET_assert (NULL != ctx);
623 op = ctx->op;
624 ctx->op = NULL;
625 GNUNET_TESTBED_operation_done (op);
626 return;
627 }
628
629
676 /* Generate and DHT PUT some random data */ 630 /* Generate and DHT PUT some random data */
677 ac->put_data_size = 16; /* minimum */ 631 ac->put_data_size = 16; /* minimum */
678 ac->put_data_size += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 632 ac->put_data_size += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
679 (63*1024)); 633 (63*1024));
680 ac->put_data = GNUNET_malloc (ac->put_data_size); 634 ac->put_data = GNUNET_malloc (ac->put_data_size);
681 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, 635 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
682 ac->put_data, ac->put_data_size); 636 ac->put_data,
683 GNUNET_CRYPTO_hash (ac->put_data, ac->put_data_size, &ac->hash); 637 ac->put_data_size);
638 GNUNET_CRYPTO_hash (ac->put_data,
639 ac->put_data_size,
640 &ac->hash);
684 DEBUG ("PUT_REQUEST_START key %s\n", 641 DEBUG ("PUT_REQUEST_START key %s\n",
685 GNUNET_h2s((struct GNUNET_HashCode *)ac->put_data)); 642 GNUNET_h2s ((struct GNUNET_HashCode *)ac->put_data));
643 ac->put_count--;
686 ac->dht_put = GNUNET_DHT_put (ac->dht, 644 ac->dht_put = GNUNET_DHT_put (ac->dht,
687 &ac->hash, 645 &ac->hash,
688 replication, 646 replication,
@@ -691,7 +649,8 @@ delayed_put (void *cls)
691 ac->put_data_size, 649 ac->put_data_size,
692 ac->put_data, 650 ac->put_data,
693 GNUNET_TIME_UNIT_FOREVER_ABS, /* expiration time */ 651 GNUNET_TIME_UNIT_FOREVER_ABS, /* expiration time */
694 &put_cont, ac); /* continuation and its closure */ 652 &put_cont,
653 ac); /* continuation and its closure */
695 n_puts++; 654 n_puts++;
696} 655}
697 656
@@ -720,7 +679,9 @@ dht_connected (void *cls,
720 ac->dht = (struct GNUNET_DHT_Handle *) ca_result; 679 ac->dht = (struct GNUNET_DHT_Handle *) ca_result;
721 if (NULL != emsg) 680 if (NULL != emsg)
722 { 681 {
723 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to DHT service failed: %s\n", emsg); 682 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
683 "Connection to DHT service failed: %s\n",
684 emsg);
724 GNUNET_TESTBED_operation_done (ctx->op); /* Calls dht_disconnect() */ 685 GNUNET_TESTBED_operation_done (ctx->op); /* Calls dht_disconnect() */
725 ctx->op = NULL; 686 ctx->op = NULL;
726 return; 687 return;
@@ -728,24 +689,31 @@ dht_connected (void *cls,
728 switch (mode) 689 switch (mode)
729 { 690 {
730 case MODE_PUT: 691 case MODE_PUT:
731 { 692 {
732 struct GNUNET_TIME_Relative peer_delay_put; 693 struct GNUNET_TIME_Relative peer_delay_put;
733 peer_delay_put.rel_value_us = 694
734 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 695 peer_delay_put.rel_value_us =
735 delay_put.rel_value_us); 696 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
736 ac->delay_task = GNUNET_SCHEDULER_add_delayed (peer_delay_put, &delayed_put, ac); 697 delay_put.rel_value_us);
737 break; 698 ac->put_count = num_puts_per_peer;
738 } 699 ac->delay_task = GNUNET_SCHEDULER_add_delayed (peer_delay_put,
700 &delayed_put,
701 ac);
702 break;
703 }
739 case MODE_GET: 704 case MODE_GET:
740 { 705 {
741 struct GNUNET_TIME_Relative peer_delay_get; 706 struct GNUNET_TIME_Relative peer_delay_get;
742 peer_delay_get.rel_value_us = 707
743 delay_get.rel_value_us + 708 peer_delay_get.rel_value_us =
744 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 709 delay_get.rel_value_us +
745 delay_get.rel_value_us); 710 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
746 ac->delay_task = GNUNET_SCHEDULER_add_delayed (peer_delay_get, &delayed_get, ac); 711 delay_get.rel_value_us);
747 break; 712 ac->delay_task = GNUNET_SCHEDULER_add_delayed (peer_delay_get,
748 } 713 &delayed_get,
714 ac);
715 break;
716 }
749 } 717 }
750} 718}
751 719
@@ -760,10 +728,12 @@ dht_connected (void *cls,
760 * @return service handle to return in 'op_result', NULL on error 728 * @return service handle to return in 'op_result', NULL on error
761 */ 729 */
762static void * 730static void *
763dht_connect (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) 731dht_connect (void *cls,
732 const struct GNUNET_CONFIGURATION_Handle *cfg)
764{ 733{
765 n_dht++; 734 n_dht++;
766 return GNUNET_DHT_connect (cfg, 10); 735 return GNUNET_DHT_connect (cfg,
736 10);
767} 737}
768 738
769 739
@@ -775,7 +745,8 @@ dht_connect (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
775 * @param op_result service handle returned from the connect adapter 745 * @param op_result service handle returned from the connect adapter
776 */ 746 */
777static void 747static void
778dht_disconnect (void *cls, void *op_result) 748dht_disconnect (void *cls,
749 void *op_result)
779{ 750{
780 struct ActiveContext *ac = cls; 751 struct ActiveContext *ac = cls;
781 752
@@ -791,11 +762,10 @@ dht_disconnect (void *cls, void *op_result)
791 switch (mode) 762 switch (mode)
792 { 763 {
793 case MODE_PUT: 764 case MODE_PUT:
794 if ((n_puts_ok + n_puts_fail) != n_active) 765 if (n_puts_ok != n_active * num_puts_per_peer)
795 return; 766 return;
796 /* Start GETs if all PUTs have been made */ 767 /* Start GETs if all PUTs have been made */
797 mode = MODE_GET; 768 mode = MODE_GET;
798 //(void) GNUNET_SCHEDULER_add_now (&call_start_profiling, NULL);
799 start_profiling (); 769 start_profiling ();
800 return; 770 return;
801 case MODE_GET: 771 case MODE_GET:
@@ -805,6 +775,7 @@ dht_disconnect (void *cls, void *op_result)
805 } 775 }
806} 776}
807 777
778
808/** 779/**
809 * Connect to DHT services of active peers 780 * Connect to DHT services of active peers
810 */ 781 */
@@ -812,229 +783,22 @@ static void
812start_profiling() 783start_profiling()
813{ 784{
814 struct Context *ctx; 785 struct Context *ctx;
815 unsigned int i;
816 786
817 DEBUG("GNUNET_TESTBED_service_connect \n"); 787 DEBUG ("GNUNET_TESTBED_service_connect\n");
818 GNUNET_break (GNUNET_YES != in_shutdown); 788 GNUNET_break (GNUNET_YES != in_shutdown);
819 for(i = 0; i < n_active; i++) 789 for (unsigned int i = 0; i < n_active; i++)
820 { 790 {
821 struct ActiveContext *ac = &a_ac[i]; 791 struct ActiveContext *ac = &a_ac[i];
822 GNUNET_assert (NULL != (ctx = ac->ctx)); 792 GNUNET_assert (NULL != (ctx = ac->ctx));
823 GNUNET_assert (NULL == ctx->op); 793 GNUNET_assert (NULL == ctx->op);
824 ctx->op = 794 ctx->op = GNUNET_TESTBED_service_connect (ctx,
825 GNUNET_TESTBED_service_connect (ctx, 795 ctx->peer,
826 ctx->peer, 796 "dht",
827 "dht", 797 &dht_connected, ac,
828 &dht_connected, ac, 798 &dht_connect,
829 &dht_connect, 799 &dht_disconnect,
830 &dht_disconnect, 800 ac);
831 ac);
832 }
833}
834
835/**
836 * Start collecting relevant statistics. If ENABLE_MALICIOUS set, first
837 * set the malicious peers. If not, then start with PUT operation on active
838 * peers.
839 */
840static void
841start_func()
842{
843 start_profiling();
844}
845
846
847/**
848 * Remove entry from successor peer hashmap.
849 * @param cls closure
850 * @param key current public key
851 * @param value value in the hash map
852 * @return #GNUNET_YES if we should continue to iterate,
853 * #GNUNET_NO if not.
854 */
855static int
856hashmap_iterate_remove(void *cls,
857 const struct GNUNET_HashCode *key,
858 void *value)
859{
860 GNUNET_assert (GNUNET_YES ==
861 GNUNET_CONTAINER_multihashmap_remove(successor_peer_hashmap, key, value));
862 return GNUNET_YES;
863}
864
865
866/**
867 * Stats callback. Iterate over the hashmap and check if all th peers form
868 * a virtual ring topology.
869 *
870 * @param cls closure
871 * @param op the operation that has been finished
872 * @param emsg error message in case the operation has failed; will be NULL if
873 * operation has executed successfully.
874 */
875static void
876successor_stats_cont (void *cls,
877 struct GNUNET_TESTBED_Operation *op,
878 const char *emsg)
879{
880 struct GNUNET_HashCode *val;
881 struct GNUNET_HashCode *start_val;
882 struct GNUNET_HashCode *key;
883 int count;
884
885 /* Don't schedule the task till we are looking for circle here. */
886 successor_stats_task = NULL;
887 GNUNET_TESTBED_operation_done (successor_stats_op);
888 successor_stats_op = NULL;
889 if (0 == max_searches)
890 {
891 start_func ();
892 return;
893 }
894
895 GNUNET_assert (NULL != start_key);
896 start_val = GNUNET_CONTAINER_multihashmap_get (successor_peer_hashmap,
897 start_key);
898 GNUNET_assert (NULL != start_val);
899 val = start_val;
900 for (count = 0; count < num_peers; count++)
901 {
902 key = val;
903 val = GNUNET_CONTAINER_multihashmap_get (successor_peer_hashmap,
904 key);
905 if (NULL == val)
906 break;
907 /* Remove the entry from hashmap. This is done to take care of loop. */
908 if (GNUNET_NO ==
909 GNUNET_CONTAINER_multihashmap_remove (successor_peer_hashmap,
910 key, val))
911 {
912 DEBUG ("Failed to remove entry from hashmap\n");
913 break;
914 }
915 /* If a peer has its own identity as its successor. */
916 if (0 == memcmp(key, val, sizeof (struct GNUNET_HashCode)))
917 break;
918 }
919
920 GNUNET_assert (GNUNET_SYSERR !=
921 GNUNET_CONTAINER_multihashmap_iterate (successor_peer_hashmap,
922 &hashmap_iterate_remove,
923 NULL));
924
925 successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (num_peers,
926 GNUNET_NO);
927 if ((start_val == val) && (count == num_peers))
928 {
929 DEBUG ("CIRCLE COMPLETED after %u tries", tries);
930 if(NULL == successor_stats_task)
931 {
932 start_func();
933 }
934 return;
935 }
936 if (max_searches == ++tries)
937 {
938 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
939 "Maximum tries %u exceeded while checking successor TOTAL TRIES %u"
940 " circle formation. Exiting\n",
941 max_searches,tries);
942 start_func();
943 return;
944 }
945 flag = 0;
946 successor_stats_task
947 = GNUNET_SCHEDULER_add_delayed (delay_stats,
948 &collect_stats,
949 cls);
950}
951
952
953/**
954 * Process successor statistic values.
955 *
956 * @param cls closure
957 * @param peer the peer the statistic belong to
958 * @param subsystem name of subsystem that created the statistic
959 * @param name the name of the datum
960 * @param value the current value
961 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
962 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
963 */
964static int
965successor_stats_iterator (void *cls,
966 const struct GNUNET_TESTBED_Peer *peer,
967 const char *subsystem,
968 const char *name,
969 uint64_t value,
970 int is_persistent)
971{
972 static const char *key_string = "XDHT";
973 if (0 == max_searches)
974 return GNUNET_OK;
975
976 if (0 == strncmp (key_string, name, strlen (key_string)))
977 {
978 char *my_id_str;
979 char successor_str[13];
980 char truncated_my_id_str[13];
981 char truncated_successor_str[13];
982 struct GNUNET_HashCode *my_id_key;
983 struct GNUNET_HashCode *succ_key;
984
985 strtok((char *)name,":");
986 my_id_str = strtok(NULL,":");
987
988 strncpy(truncated_my_id_str, my_id_str, 12);
989 truncated_my_id_str[12] = '\0';
990 my_id_key = GNUNET_new(struct GNUNET_HashCode);
991 GNUNET_CRYPTO_hash (truncated_my_id_str, sizeof(truncated_my_id_str),my_id_key);
992 GNUNET_STRINGS_data_to_string(&value, sizeof(uint64_t), successor_str, 13);
993 strncpy(truncated_successor_str, successor_str, 12);
994 truncated_successor_str[12] ='\0';
995
996 succ_key = GNUNET_new(struct GNUNET_HashCode);
997 GNUNET_CRYPTO_hash (truncated_successor_str, sizeof(truncated_successor_str),succ_key);
998
999 if (0 == flag)
1000 {
1001 GNUNET_assert(NULL != my_id_key);
1002 start_key = my_id_key;
1003 GNUNET_assert(NULL != start_key);
1004 flag = 1;
1005 }
1006 GNUNET_CONTAINER_multihashmap_put (successor_peer_hashmap,
1007 my_id_key, (void *)succ_key,
1008 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
1009 } 801 }
1010
1011 return GNUNET_OK;
1012}
1013
1014
1015/*
1016 * Task that collects peer and its corresponding successors.
1017 *
1018 * @param cls Closure (NULL).
1019 */
1020static void
1021collect_stats (void *cls)
1022{
1023 successor_stats_task = NULL;
1024 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1025 "Start collecting statistics...\n");
1026 GNUNET_assert(NULL != testbed_handles);
1027
1028 if (0 != max_searches)
1029 successor_peer_hashmap
1030 = GNUNET_CONTAINER_multihashmap_create (num_peers,
1031 GNUNET_NO);
1032 successor_stats_op
1033 = GNUNET_TESTBED_get_statistics (num_peers, testbed_handles,
1034 "dht", NULL,
1035 successor_stats_iterator,
1036 successor_stats_cont, cls);
1037 GNUNET_assert (NULL != successor_stats_op);
1038} 802}
1039 803
1040 804
@@ -1058,19 +822,11 @@ service_started (void *cls,
1058 GNUNET_TESTBED_operation_done (ctx->op); 822 GNUNET_TESTBED_operation_done (ctx->op);
1059 ctx->op = NULL; 823 ctx->op = NULL;
1060 peers_started++; 824 peers_started++;
1061 DEBUG("Peers Started = %d; num_peers = %d \n", peers_started, num_peers); 825 DEBUG ("Peers Started = %d; num_peers = %d \n",
1062 if (NULL == successor_stats_task && peers_started == num_peers) 826 peers_started,
1063 { 827 num_peers);
1064 DEBUG("successor_stats_task \n"); 828 if (peers_started == num_peers)
1065 struct Collect_Stat_Context *collect_stat_cls = GNUNET_new(struct Collect_Stat_Context); 829 start_profiling ();
1066 collect_stat_cls->service_connect_ctx = cls;
1067 collect_stat_cls->op = op;
1068
1069 successor_stats_task
1070 = GNUNET_SCHEDULER_add_delayed (delay_stats,
1071 &collect_stats,
1072 collect_stat_cls);
1073 }
1074} 830}
1075 831
1076 832
@@ -1088,36 +844,40 @@ service_started (void *cls,
1088static void 844static void
1089test_run (void *cls, 845test_run (void *cls,
1090 struct GNUNET_TESTBED_RunHandle *h, 846 struct GNUNET_TESTBED_RunHandle *h,
1091 unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, 847 unsigned int num_peers,
848 struct GNUNET_TESTBED_Peer **peers,
1092 unsigned int links_succeeded, 849 unsigned int links_succeeded,
1093 unsigned int links_failed) 850 unsigned int links_failed)
1094{ 851{
1095 unsigned int cnt;
1096 unsigned int ac_cnt; 852 unsigned int ac_cnt;
853
1097 testbed_handles = peers; 854 testbed_handles = peers;
1098 if (NULL == peers) 855 if (NULL == peers)
1099 { 856 {
1100 /* exit */ 857 /* exit */
1101 GNUNET_assert (0); 858 GNUNET_assert (0);
1102 } 859 }
1103 INFO ("%u peers started\n", num_peers); 860 MESSAGE ("%u peers started\n",
1104 a_ctx = GNUNET_malloc (sizeof (struct Context) * num_peers); 861 num_peers);
1105 862 a_ctx = GNUNET_new_array (num_peers,
863 struct Context);
1106 /* select the peers which actively participate in profiling */ 864 /* select the peers which actively participate in profiling */
1107 n_active = num_peers * PUT_PROBABILITY / 100; 865 n_active = num_peers * put_probability / 100;
1108 if (0 == n_active) 866 if (0 == n_active)
1109 { 867 {
1110 GNUNET_SCHEDULER_shutdown (); 868 GNUNET_SCHEDULER_shutdown ();
1111 GNUNET_free (a_ctx); 869 GNUNET_free (a_ctx);
870 a_ctx = NULL;
1112 return; 871 return;
1113 } 872 }
1114 873
1115 a_ac = GNUNET_malloc (n_active * sizeof (struct ActiveContext)); 874 a_ac = GNUNET_new_array (n_active,
875 struct ActiveContext);
1116 ac_cnt = 0; 876 ac_cnt = 0;
1117 for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++) 877 for (unsigned int cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++)
1118 { 878 {
1119 if ((GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >= 879 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1120 PUT_PROBABILITY)) 880 100) >= put_probability)
1121 continue; 881 continue;
1122 882
1123 a_ctx[cnt].ac = &a_ac[ac_cnt]; 883 a_ctx[cnt].ac = &a_ac[ac_cnt];
@@ -1125,10 +885,11 @@ test_run (void *cls,
1125 ac_cnt++; 885 ac_cnt++;
1126 } 886 }
1127 n_active = ac_cnt; 887 n_active = ac_cnt;
1128 INFO ("Active peers: %u\n", n_active); 888 MESSAGE ("Active peers: %u\n",
889 n_active);
1129 890
1130 /* start DHT service on all peers */ 891 /* start DHT service on all peers */
1131 for (cnt = 0; cnt < num_peers; cnt++) 892 for (unsigned int cnt = 0; cnt < num_peers; cnt++)
1132 { 893 {
1133 a_ctx[cnt].peer = peers[cnt]; 894 a_ctx[cnt].peer = peers[cnt];
1134 a_ctx[cnt].op = GNUNET_TESTBED_peer_manage_service (&a_ctx[cnt], 895 a_ctx[cnt].op = GNUNET_TESTBED_peer_manage_service (&a_ctx[cnt],
@@ -1150,7 +911,9 @@ test_run (void *cls,
1150 * @param config configuration 911 * @param config configuration
1151 */ 912 */
1152static void 913static void
1153run (void *cls, char *const *args, const char *cfgfile, 914run (void *cls,
915 char *const *args,
916 const char *cfgfile,
1154 const struct GNUNET_CONFIGURATION_Handle *config) 917 const struct GNUNET_CONFIGURATION_Handle *config)
1155{ 918{
1156 uint64_t event_mask; 919 uint64_t event_mask;
@@ -1164,8 +927,14 @@ run (void *cls, char *const *args, const char *cfgfile,
1164 } 927 }
1165 cfg = GNUNET_CONFIGURATION_dup (config); 928 cfg = GNUNET_CONFIGURATION_dup (config);
1166 event_mask = 0; 929 event_mask = 0;
1167 GNUNET_TESTBED_run (hosts_file, cfg, num_peers, event_mask, NULL, 930 GNUNET_TESTBED_run (hosts_file,
1168 NULL, &test_run, NULL); 931 cfg,
932 num_peers,
933 event_mask,
934 NULL,
935 NULL,
936 &test_run,
937 NULL);
1169 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 938 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
1170 NULL); 939 NULL);
1171} 940}
@@ -1177,63 +946,68 @@ run (void *cls, char *const *args, const char *cfgfile,
1177 * @return 0 on success 946 * @return 0 on success
1178 */ 947 */
1179int 948int
1180main (int argc, char *const *argv) 949main (int argc,
950 char *const *argv)
1181{ 951{
1182 int rc; 952 int rc;
1183
1184 struct GNUNET_GETOPT_CommandLineOption options[] = { 953 struct GNUNET_GETOPT_CommandLineOption options[] = {
1185 GNUNET_GETOPT_option_uint ('n', 954 GNUNET_GETOPT_option_uint ('n',
1186 "peers", 955 "peers",
1187 "COUNT", 956 "COUNT",
1188 gettext_noop ("number of peers to start"), 957 gettext_noop ("number of peers to start"),
1189 &num_peers), 958 &num_peers),
1190 959 GNUNET_GETOPT_option_uint ('p',
960 "peer-put-count",
961 "COUNT",
962 gettext_noop ("number of PUTs to perform per peer"),
963 &num_puts_per_peer),
1191 GNUNET_GETOPT_option_uint ('s', 964 GNUNET_GETOPT_option_uint ('s',
1192 "searches", 965 "searches",
1193 "COUNT", 966 "COUNT",
1194 gettext_noop ("maximum number of times we try to search for successor circle formation (0 for R5N)"), 967 gettext_noop ("maximum number of times we try to search for successor circle formation (0 for R5N)"),
1195 &max_searches), 968 &max_searches),
1196
1197 GNUNET_GETOPT_option_string ('H', 969 GNUNET_GETOPT_option_string ('H',
1198 "hosts", 970 "hosts",
1199 "FILENAME", 971 "FILENAME",
1200 gettext_noop ("name of the file with the login information for the testbed"), 972 gettext_noop ("name of the file with the login information for the testbed"),
1201 &hosts_file), 973 &hosts_file),
1202
1203 GNUNET_GETOPT_option_relative_time ('D', 974 GNUNET_GETOPT_option_relative_time ('D',
1204 "delay", 975 "delay",
1205 "DELAY", 976 "DELAY",
1206 gettext_noop ("delay between rounds for collecting statistics (default: 30 sec)"), 977 gettext_noop ("delay between rounds for collecting statistics (default: 30 sec)"),
1207 &delay_stats), 978 &delay_stats),
1208
1209 GNUNET_GETOPT_option_relative_time ('P', 979 GNUNET_GETOPT_option_relative_time ('P',
1210 "PUT-delay", 980 "PUT-delay",
1211 "DELAY", 981 "DELAY",
1212 gettext_noop ("delay to start doing PUTs (default: 1 sec)"), 982 gettext_noop ("delay to start doing PUTs (default: 1 sec)"),
1213 &delay_put), 983 &delay_put),
1214
1215 GNUNET_GETOPT_option_relative_time ('G', 984 GNUNET_GETOPT_option_relative_time ('G',
1216 "GET-delay", 985 "GET-delay",
1217 "DELAY", 986 "DELAY",
1218 gettext_noop ("delay to start doing GETs (default: 5 min)"), 987 gettext_noop ("delay to start doing GETs (default: 5 min)"),
1219 &delay_get), 988 &delay_get),
1220 GNUNET_GETOPT_option_uint ('r', 989 GNUNET_GETOPT_option_uint ('r',
1221 "replication", 990 "replication",
1222 "DEGREE", 991 "DEGREE",
1223 gettext_noop ("replication degree for DHT PUTs"), 992 gettext_noop ("replication degree for DHT PUTs"),
1224 &replication), 993 &replication),
1225 994 GNUNET_GETOPT_option_uint ('R',
1226 995 "random-chance",
996 "PROBABILITY",
997 gettext_noop ("chance that a peer is selected at random for PUTs"),
998 &put_probability),
1227 GNUNET_GETOPT_option_relative_time ('t', 999 GNUNET_GETOPT_option_relative_time ('t',
1228 "timeout", 1000 "timeout",
1229 "TIMEOUT", 1001 "TIMEOUT",
1230 gettext_noop ("timeout for DHT PUT and GET requests (default: 1 min)"), 1002 gettext_noop ("timeout for DHT PUT and GET requests (default: 1 min)"),
1231 &timeout), 1003 &timeout),
1232 GNUNET_GETOPT_OPTION_END 1004 GNUNET_GETOPT_OPTION_END
1233 }; 1005 };
1234 1006
1235 max_searches = 5; 1007 max_searches = 5;
1236 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 1008 if (GNUNET_OK !=
1009 GNUNET_STRINGS_get_utf8_args (argc, argv,
1010 &argc, &argv))
1237 return 2; 1011 return 2;
1238 /* set default delays */ 1012 /* set default delays */
1239 delay_stats = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); 1013 delay_stats = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
@@ -1243,10 +1017,13 @@ main (int argc, char *const *argv)
1243 replication = 1; /* default replication */ 1017 replication = 1; /* default replication */
1244 rc = 0; 1018 rc = 0;
1245 if (GNUNET_OK != 1019 if (GNUNET_OK !=
1246 GNUNET_PROGRAM_run (argc, argv, "dht-profiler", 1020 GNUNET_PROGRAM_run (argc,
1247 gettext_noop 1021 argv,
1248 ("Measure quality and performance of the DHT service."), 1022 "gnunet-dht-profiler",
1249 options, &run, NULL)) 1023 gettext_noop ("Measure quality and performance of the DHT service."),
1024 options,
1025 &run,
1026 NULL))
1250 rc = 1; 1027 rc = 1;
1251 return rc; 1028 return rc;
1252} 1029}