aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet_dht_profiler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/gnunet_dht_profiler.c')
-rw-r--r--src/dht/gnunet_dht_profiler.c760
1 files changed, 379 insertions, 381 deletions
diff --git a/src/dht/gnunet_dht_profiler.c b/src/dht/gnunet_dht_profiler.c
index a8f5a3aca..179f84a11 100644
--- a/src/dht/gnunet_dht_profiler.c
+++ b/src/dht/gnunet_dht_profiler.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file dht/gnunet_dht_profiler.c 22 * @file dht/gnunet_dht_profiler.c
@@ -32,10 +32,10 @@
32 32
33 33
34#define MESSAGE(...) \ 34#define MESSAGE(...) \
35 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, __VA_ARGS__) 35 GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE, __VA_ARGS__)
36 36
37#define DEBUG(...) \ 37#define DEBUG(...) \
38 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) 38 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
39 39
40/** 40/**
41 * Number of peers which should perform a PUT out of 100 peers 41 * Number of peers which should perform a PUT out of 100 peers
@@ -60,8 +60,7 @@ struct ActiveContext;
60/** 60/**
61 * Context to hold data of peer 61 * Context to hold data of peer
62 */ 62 */
63struct Context 63struct Context {
64{
65 /** 64 /**
66 * The testbed peer this context belongs to 65 * The testbed peer this context belongs to
67 */ 66 */
@@ -76,15 +75,13 @@ struct Context
76 * Active context; NULL if this peer is not an active peer 75 * Active context; NULL if this peer is not an active peer
77 */ 76 */
78 struct ActiveContext *ac; 77 struct ActiveContext *ac;
79
80}; 78};
81 79
82 80
83/** 81/**
84 * Context for a peer which actively does DHT PUT/GET 82 * Context for a peer which actively does DHT PUT/GET
85 */ 83 */
86struct ActiveContext 84struct ActiveContext {
87{
88 /** 85 /**
89 * The linked peer context 86 * The linked peer context
90 */ 87 */
@@ -261,8 +258,7 @@ static int peers_started = 0;
261/** 258/**
262 * Should we do a PUT (mode = 0) or GET (mode = 1); 259 * Should we do a PUT (mode = 0) or GET (mode = 1);
263 */ 260 */
264static enum 261static enum {
265{
266 MODE_PUT = 0, 262 MODE_PUT = 0,
267 263
268 MODE_GET = 1 264 MODE_GET = 1
@@ -279,7 +275,7 @@ static int in_shutdown = 0;
279 * Connect to DHT services of active peers 275 * Connect to DHT services of active peers
280 */ 276 */
281static void 277static void
282start_profiling (void); 278start_profiling(void);
283 279
284 280
285/** 281/**
@@ -288,43 +284,43 @@ start_profiling (void);
288 * @param cls NULL 284 * @param cls NULL
289 */ 285 */
290static void 286static void
291do_shutdown (void *cls) 287do_shutdown(void *cls)
292{ 288{
293 struct ActiveContext *ac; 289 struct ActiveContext *ac;
294 290
295 in_shutdown = GNUNET_YES; 291 in_shutdown = GNUNET_YES;
296 if (NULL != a_ctx) 292 if (NULL != a_ctx)
297 {
298 for (unsigned int cnt=0; cnt < num_peers; cnt++)
299 { 293 {
300 /* Cleanup active context if this peer is an active peer */ 294 for (unsigned int cnt = 0; cnt < num_peers; cnt++)
301 ac = a_ctx[cnt].ac; 295 {
302 if (NULL != ac) 296 /* Cleanup active context if this peer is an active peer */
303 { 297 ac = a_ctx[cnt].ac;
304 if (NULL != ac->delay_task) 298 if (NULL != ac)
305 GNUNET_SCHEDULER_cancel (ac->delay_task); 299 {
306 if (NULL != ac->hash) 300 if (NULL != ac->delay_task)
307 free (ac->hash); 301 GNUNET_SCHEDULER_cancel(ac->delay_task);
308 if (NULL != ac->dht_put) 302 if (NULL != ac->hash)
309 GNUNET_DHT_put_cancel (ac->dht_put); 303 free(ac->hash);
310 if (NULL != ac->dht_get) 304 if (NULL != ac->dht_put)
311 GNUNET_DHT_get_stop (ac->dht_get); 305 GNUNET_DHT_put_cancel(ac->dht_put);
312 } 306 if (NULL != ac->dht_get)
313 /* Cleanup testbed operation handle at the last as this operation may 307 GNUNET_DHT_get_stop(ac->dht_get);
314 contain service connection to DHT */ 308 }
315 if (NULL != a_ctx[cnt].op) 309 /* Cleanup testbed operation handle at the last as this operation may
316 GNUNET_TESTBED_operation_done (a_ctx[cnt].op); 310 contain service connection to DHT */
311 if (NULL != a_ctx[cnt].op)
312 GNUNET_TESTBED_operation_done(a_ctx[cnt].op);
313 }
314 GNUNET_free(a_ctx);
315 a_ctx = NULL;
317 } 316 }
318 GNUNET_free (a_ctx);
319 a_ctx = NULL;
320 }
321 //FIXME: Should we collect stats only for put/get not for other messages. 317 //FIXME: Should we collect stats only for put/get not for other messages.
322 if (NULL != bandwidth_stats_op) 318 if (NULL != bandwidth_stats_op)
323 { 319 {
324 GNUNET_TESTBED_operation_done (bandwidth_stats_op); 320 GNUNET_TESTBED_operation_done(bandwidth_stats_op);
325 bandwidth_stats_op = NULL; 321 bandwidth_stats_op = NULL;
326 } 322 }
327 GNUNET_free_non_null (a_ac); 323 GNUNET_free_non_null(a_ac);
328} 324}
329 325
330 326
@@ -338,18 +334,18 @@ do_shutdown (void *cls)
338 * operation has executed successfully. 334 * operation has executed successfully.
339 */ 335 */
340static void 336static void
341bandwidth_stats_cont (void *cls, 337bandwidth_stats_cont(void *cls,
342 struct GNUNET_TESTBED_Operation *op, 338 struct GNUNET_TESTBED_Operation *op,
343 const char *emsg) 339 const char *emsg)
344{ 340{
345 MESSAGE ("# Outgoing (core) bandwidth: %llu bytes\n", 341 MESSAGE("# Outgoing (core) bandwidth: %llu bytes\n",
346 (unsigned long long) outgoing_bandwidth); 342 (unsigned long long)outgoing_bandwidth);
347 MESSAGE ("# Incoming (core) bandwidth: %llu bytes\n", 343 MESSAGE("# Incoming (core) bandwidth: %llu bytes\n",
348 (unsigned long long) incoming_bandwidth); 344 (unsigned long long)incoming_bandwidth);
349 fprintf (stderr, 345 fprintf(stderr,
350 "Benchmark done. Collect data via gnunet-statistics, then press ENTER to exit.\n"); 346 "Benchmark done. Collect data via gnunet-statistics, then press ENTER to exit.\n");
351 (void) getchar (); 347 (void)getchar();
352 GNUNET_SCHEDULER_shutdown (); 348 GNUNET_SCHEDULER_shutdown();
353} 349}
354 350
355 351
@@ -365,55 +361,55 @@ bandwidth_stats_cont (void *cls,
365 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 361 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
366 */ 362 */
367static int 363static int
368bandwidth_stats_iterator (void *cls, 364bandwidth_stats_iterator(void *cls,
369 const struct GNUNET_TESTBED_Peer *peer, 365 const struct GNUNET_TESTBED_Peer *peer,
370 const char *subsystem, 366 const char *subsystem,
371 const char *name, 367 const char *name,
372 uint64_t value, 368 uint64_t value,
373 int is_persistent) 369 int is_persistent)
374{ 370{
375 static const char *s_sent = "# bytes encrypted"; 371 static const char *s_sent = "# bytes encrypted";
376 static const char *s_recv = "# bytes decrypted"; 372 static const char *s_recv = "# bytes decrypted";
377 373
378 if (0 == strncmp (s_sent, name, strlen (s_sent))) 374 if (0 == strncmp(s_sent, name, strlen(s_sent)))
379 outgoing_bandwidth = outgoing_bandwidth + value; 375 outgoing_bandwidth = outgoing_bandwidth + value;
380 else if (0 == strncmp(s_recv, name, strlen (s_recv))) 376 else if (0 == strncmp(s_recv, name, strlen(s_recv)))
381 incoming_bandwidth = incoming_bandwidth + value; 377 incoming_bandwidth = incoming_bandwidth + value;
382 return GNUNET_OK; 378 return GNUNET_OK;
383} 379}
384 380
385 381
386static void 382static void
387summarize () 383summarize()
388{ 384{
389 MESSAGE ("# PUTS started: %llu\n", 385 MESSAGE("# PUTS started: %llu\n",
390 n_puts); 386 n_puts);
391 MESSAGE ("# PUTS succeeded: %llu\n", 387 MESSAGE("# PUTS succeeded: %llu\n",
392 n_puts_ok); 388 n_puts_ok);
393 MESSAGE ("# GETS made: %u\n", 389 MESSAGE("# GETS made: %u\n",
394 n_gets); 390 n_gets);
395 MESSAGE ("# GETS succeeded: %u\n", 391 MESSAGE("# GETS succeeded: %u\n",
396 n_gets_ok); 392 n_gets_ok);
397 MESSAGE ("# GETS failed: %u\n", 393 MESSAGE("# GETS failed: %u\n",
398 n_gets_fail); 394 n_gets_fail);
399 MESSAGE ("# average_put_path_length: %f\n", 395 MESSAGE("# average_put_path_length: %f\n",
400 average_put_path_length); 396 average_put_path_length);
401 MESSAGE ("# average_get_path_length: %f\n", 397 MESSAGE("# average_get_path_length: %f\n",
402 average_get_path_length); 398 average_get_path_length);
403 399
404 if (NULL == testbed_handles) 400 if (NULL == testbed_handles)
405 { 401 {
406 MESSAGE ("No peers found\n"); 402 MESSAGE("No peers found\n");
407 return; 403 return;
408 } 404 }
409 /* Collect Stats*/ 405 /* Collect Stats*/
410 bandwidth_stats_op = GNUNET_TESTBED_get_statistics (n_active, 406 bandwidth_stats_op = GNUNET_TESTBED_get_statistics(n_active,
411 testbed_handles, 407 testbed_handles,
412 "core", 408 "core",
413 NULL, 409 NULL,
414 &bandwidth_stats_iterator, 410 &bandwidth_stats_iterator,
415 &bandwidth_stats_cont, 411 &bandwidth_stats_cont,
416 NULL); 412 NULL);
417} 413}
418 414
419 415
@@ -423,27 +419,27 @@ summarize ()
423 * @param cls NULL 419 * @param cls NULL
424 */ 420 */
425static void 421static void
426cancel_get (void *cls) 422cancel_get(void *cls)
427{ 423{
428 struct ActiveContext *ac = cls; 424 struct ActiveContext *ac = cls;
429 struct Context *ctx = ac->ctx; 425 struct Context *ctx = ac->ctx;
430 426
431 ac->delay_task = NULL; 427 ac->delay_task = NULL;
432 GNUNET_assert (NULL != ac->dht_get); 428 GNUNET_assert(NULL != ac->dht_get);
433 GNUNET_DHT_get_stop (ac->dht_get); 429 GNUNET_DHT_get_stop(ac->dht_get);
434 ac->dht_get = NULL; 430 ac->dht_get = NULL;
435 n_gets_fail++; 431 n_gets_fail++;
436 GNUNET_assert (NULL != ctx->op); 432 GNUNET_assert(NULL != ctx->op);
437 GNUNET_TESTBED_operation_done (ctx->op); 433 GNUNET_TESTBED_operation_done(ctx->op);
438 ctx->op = NULL; 434 ctx->op = NULL;
439 435
440 /* If profiling is complete, summarize */ 436 /* If profiling is complete, summarize */
441 if (n_active == n_gets_fail + n_gets_ok) 437 if (n_active == n_gets_fail + n_gets_ok)
442 { 438 {
443 average_put_path_length = (double)total_put_path_length/(double)n_active; 439 average_put_path_length = (double)total_put_path_length / (double)n_active;
444 average_get_path_length = (double)total_get_path_length/(double )n_gets_ok; 440 average_get_path_length = (double)total_get_path_length / (double )n_gets_ok;
445 summarize (); 441 summarize();
446 } 442 }
447} 443}
448 444
449 445
@@ -465,45 +461,45 @@ cancel_get (void *cls)
465 * @param data pointer to the result data 461 * @param data pointer to the result data
466 */ 462 */
467static void 463static void
468get_iter (void *cls, 464get_iter(void *cls,
469 struct GNUNET_TIME_Absolute exp, 465 struct GNUNET_TIME_Absolute exp,
470 const struct GNUNET_HashCode *key, 466 const struct GNUNET_HashCode *key,
471 const struct GNUNET_PeerIdentity *get_path, 467 const struct GNUNET_PeerIdentity *get_path,
472 unsigned int get_path_length, 468 unsigned int get_path_length,
473 const struct GNUNET_PeerIdentity *put_path, 469 const struct GNUNET_PeerIdentity *put_path,
474 unsigned int put_path_length, 470 unsigned int put_path_length,
475 enum GNUNET_BLOCK_Type type, 471 enum GNUNET_BLOCK_Type type,
476 size_t size, const void *data) 472 size_t size, const void *data)
477{ 473{
478 struct ActiveContext *ac = cls; 474 struct ActiveContext *ac = cls;
479 struct ActiveContext *get_ac = ac->get_ac; 475 struct ActiveContext *get_ac = ac->get_ac;
480 struct Context *ctx = ac->ctx; 476 struct Context *ctx = ac->ctx;
481 477
482 /* we found the data we are looking for */ 478 /* we found the data we are looking for */
483 DEBUG ("We found a GET request; %u remaining\n", 479 DEBUG("We found a GET request; %u remaining\n",
484 n_gets - (n_gets_fail + n_gets_ok)); //FIXME: It always prints 1. 480 n_gets - (n_gets_fail + n_gets_ok)); //FIXME: It always prints 1.
485 n_gets_ok++; 481 n_gets_ok++;
486 get_ac->nrefs--; 482 get_ac->nrefs--;
487 GNUNET_DHT_get_stop (ac->dht_get); 483 GNUNET_DHT_get_stop(ac->dht_get);
488 ac->dht_get = NULL; 484 ac->dht_get = NULL;
489 if (ac->delay_task != NULL) 485 if (ac->delay_task != NULL)
490 GNUNET_SCHEDULER_cancel (ac->delay_task); 486 GNUNET_SCHEDULER_cancel(ac->delay_task);
491 ac->delay_task = NULL; 487 ac->delay_task = NULL;
492 GNUNET_assert (NULL != ctx->op); 488 GNUNET_assert(NULL != ctx->op);
493 GNUNET_TESTBED_operation_done (ctx->op); 489 GNUNET_TESTBED_operation_done(ctx->op);
494 ctx->op = NULL; 490 ctx->op = NULL;
495 491
496 total_put_path_length = total_put_path_length + (double)put_path_length; 492 total_put_path_length = total_put_path_length + (double)put_path_length;
497 total_get_path_length = total_get_path_length + (double)get_path_length; 493 total_get_path_length = total_get_path_length + (double)get_path_length;
498 DEBUG ("total_put_path_length = %u,put_path \n", 494 DEBUG("total_put_path_length = %u,put_path \n",
499 total_put_path_length); 495 total_put_path_length);
500 /* Summarize if profiling is complete */ 496 /* Summarize if profiling is complete */
501 if (n_active == n_gets_fail + n_gets_ok) 497 if (n_active == n_gets_fail + n_gets_ok)
502 { 498 {
503 average_put_path_length = (double)total_put_path_length/(double)n_active; 499 average_put_path_length = (double)total_put_path_length / (double)n_active;
504 average_get_path_length = (double)total_get_path_length/(double )n_gets_ok; 500 average_get_path_length = (double)total_get_path_length / (double )n_gets_ok;
505 summarize (); 501 summarize();
506 } 502 }
507} 503}
508 504
509 505
@@ -513,7 +509,7 @@ get_iter (void *cls,
513 * @param cls the active context 509 * @param cls the active context
514 */ 510 */
515static void 511static void
516delayed_get (void *cls) 512delayed_get(void *cls)
517{ 513{
518 struct ActiveContext *ac = cls; 514 struct ActiveContext *ac = cls;
519 struct ActiveContext *get_ac; 515 struct ActiveContext *get_ac;
@@ -522,34 +518,34 @@ delayed_get (void *cls)
522 ac->delay_task = NULL; 518 ac->delay_task = NULL;
523 get_ac = NULL; 519 get_ac = NULL;
524 while (1) 520 while (1)
525 { 521 {
526 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 522 r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
527 n_active); 523 n_active);
528 get_ac = &a_ac[r]; 524 get_ac = &a_ac[r];
529 if (NULL != get_ac->hash) 525 if (NULL != get_ac->hash)
530 break; 526 break;
531 } 527 }
532 get_ac->nrefs++; 528 get_ac->nrefs++;
533 ac->get_ac = get_ac; 529 ac->get_ac = get_ac;
534 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 530 r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
535 num_puts_per_peer); 531 num_puts_per_peer);
536 DEBUG ("GET_REQUEST_START key %s \n", 532 DEBUG("GET_REQUEST_START key %s \n",
537 GNUNET_h2s(&get_ac->hash[r])); 533 GNUNET_h2s(&get_ac->hash[r]));
538 ac->dht_get = GNUNET_DHT_get_start (ac->dht, 534 ac->dht_get = GNUNET_DHT_get_start(ac->dht,
539 GNUNET_BLOCK_TYPE_TEST, 535 GNUNET_BLOCK_TYPE_TEST,
540 &get_ac->hash[r], 536 &get_ac->hash[r],
541 1, /* replication level */ 537 1, /* replication level */
542 GNUNET_DHT_RO_NONE, 538 GNUNET_DHT_RO_NONE,
543 NULL, 539 NULL,
544 0, /* extended query and size */ 540 0, /* extended query and size */
545 &get_iter, 541 &get_iter,
546 ac); /* GET iterator and closure */ 542 ac); /* GET iterator and closure */
547 n_gets++; 543 n_gets++;
548 544
549 /* schedule the timeout task for GET */ 545 /* schedule the timeout task for GET */
550 ac->delay_task = GNUNET_SCHEDULER_add_delayed (timeout, 546 ac->delay_task = GNUNET_SCHEDULER_add_delayed(timeout,
551 &cancel_get, 547 &cancel_get,
552 ac); 548 ac);
553} 549}
554 550
555 551
@@ -561,7 +557,7 @@ delayed_get (void *cls)
561 * @param cls the active context 557 * @param cls the active context
562 */ 558 */
563static void 559static void
564delayed_put (void *cls); 560delayed_put(void *cls);
565 561
566 562
567/** 563/**
@@ -571,14 +567,14 @@ delayed_put (void *cls);
571 * @param cls the active context 567 * @param cls the active context
572 */ 568 */
573static void 569static void
574put_cont (void *cls) 570put_cont(void *cls)
575{ 571{
576 struct ActiveContext *ac = cls; 572 struct ActiveContext *ac = cls;
577 573
578 ac->dht_put = NULL; 574 ac->dht_put = NULL;
579 n_puts_ok++; 575 n_puts_ok++;
580 ac->delay_task = GNUNET_SCHEDULER_add_now (&delayed_put, 576 ac->delay_task = GNUNET_SCHEDULER_add_now(&delayed_put,
581 ac); 577 ac);
582} 578}
583 579
584 580
@@ -590,7 +586,7 @@ put_cont (void *cls)
590 * @param cls the active context 586 * @param cls the active context
591 */ 587 */
592static void 588static void
593delayed_put (void *cls) 589delayed_put(void *cls)
594{ 590{
595 struct ActiveContext *ac = cls; 591 struct ActiveContext *ac = cls;
596 char block[65536]; 592 char block[65536];
@@ -598,42 +594,42 @@ delayed_put (void *cls)
598 594
599 ac->delay_task = NULL; 595 ac->delay_task = NULL;
600 if (0 == ac->put_count) 596 if (0 == ac->put_count)
601 { 597 {
602 struct Context *ctx = ac->ctx; 598 struct Context *ctx = ac->ctx;
603 struct GNUNET_TESTBED_Operation *op; 599 struct GNUNET_TESTBED_Operation *op;
604 600
605 GNUNET_assert (NULL != ctx); 601 GNUNET_assert(NULL != ctx);
606 op = ctx->op; 602 op = ctx->op;
607 ctx->op = NULL; 603 ctx->op = NULL;
608 GNUNET_TESTBED_operation_done (op); 604 GNUNET_TESTBED_operation_done(op);
609 return; 605 return;
610 } 606 }
611 607
612 608
613 /* Generate and DHT PUT some random data */ 609 /* Generate and DHT PUT some random data */
614 block_size = 16; /* minimum */ 610 block_size = 16; /* minimum */
615 /* make random payload, reserve 512 - 16 bytes for DHT headers */ 611 /* make random payload, reserve 512 - 16 bytes for DHT headers */
616 block_size += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 612 block_size += GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
617 GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE - 512); 613 GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE - 512);
618 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, 614 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK,
619 block, 615 block,
620 block_size); 616 block_size);
621 ac->put_count--; 617 ac->put_count--;
622 GNUNET_CRYPTO_hash (block, 618 GNUNET_CRYPTO_hash(block,
623 block_size, 619 block_size,
624 &ac->hash[ac->put_count]); 620 &ac->hash[ac->put_count]);
625 DEBUG ("PUT_REQUEST_START key %s\n", 621 DEBUG("PUT_REQUEST_START key %s\n",
626 GNUNET_h2s (&ac->hash[ac->put_count])); 622 GNUNET_h2s(&ac->hash[ac->put_count]));
627 ac->dht_put = GNUNET_DHT_put (ac->dht, 623 ac->dht_put = GNUNET_DHT_put(ac->dht,
628 &ac->hash[ac->put_count], 624 &ac->hash[ac->put_count],
629 replication, 625 replication,
630 GNUNET_DHT_RO_RECORD_ROUTE, 626 GNUNET_DHT_RO_RECORD_ROUTE,
631 GNUNET_BLOCK_TYPE_TEST, 627 GNUNET_BLOCK_TYPE_TEST,
632 block_size, 628 block_size,
633 block, 629 block,
634 GNUNET_TIME_UNIT_FOREVER_ABS, /* expiration time */ 630 GNUNET_TIME_UNIT_FOREVER_ABS, /* expiration time */
635 &put_cont, 631 &put_cont,
636 ac); /* continuation and its closure */ 632 ac); /* continuation and its closure */
637 n_puts++; 633 n_puts++;
638} 634}
639 635
@@ -648,65 +644,66 @@ delayed_put (void *cls)
648 * operation has executed successfully. 644 * operation has executed successfully.
649 */ 645 */
650static void 646static void
651dht_connected (void *cls, 647dht_connected(void *cls,
652 struct GNUNET_TESTBED_Operation *op, 648 struct GNUNET_TESTBED_Operation *op,
653 void *ca_result, 649 void *ca_result,
654 const char *emsg) 650 const char *emsg)
655{ 651{
656 struct ActiveContext *ac = cls; 652 struct ActiveContext *ac = cls;
657 struct Context *ctx = ac->ctx; 653 struct Context *ctx = ac->ctx;
658 654
659 GNUNET_assert (NULL != ctx); //FIXME: Fails 655 GNUNET_assert(NULL != ctx); //FIXME: Fails
660 GNUNET_assert (NULL != ctx->op); 656 GNUNET_assert(NULL != ctx->op);
661 GNUNET_assert (ctx->op == op); 657 GNUNET_assert(ctx->op == op);
662 ac->dht = (struct GNUNET_DHT_Handle *) ca_result; 658 ac->dht = (struct GNUNET_DHT_Handle *)ca_result;
663 if (NULL != emsg) 659 if (NULL != emsg)
664 { 660 {
665 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 661 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
666 "Connection to DHT service failed: %s\n", 662 "Connection to DHT service failed: %s\n",
667 emsg); 663 emsg);
668 GNUNET_TESTBED_operation_done (ctx->op); /* Calls dht_disconnect() */ 664 GNUNET_TESTBED_operation_done(ctx->op); /* Calls dht_disconnect() */
669 ctx->op = NULL; 665 ctx->op = NULL;
670 return; 666 return;
671 } 667 }
672 switch (mode) 668 switch (mode)
673 { 669 {
674 case MODE_PUT: 670 case MODE_PUT:
675 { 671 {
676 struct GNUNET_TIME_Relative peer_delay_put; 672 struct GNUNET_TIME_Relative peer_delay_put;
677 673
678 peer_delay_put.rel_value_us = 674 peer_delay_put.rel_value_us =
679 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 675 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
680 delay_put.rel_value_us); 676 delay_put.rel_value_us);
681 ac->put_count = num_puts_per_peer; 677 ac->put_count = num_puts_per_peer;
682 ac->hash = calloc (ac->put_count, 678 ac->hash = calloc(ac->put_count,
683 sizeof (struct GNUNET_HashCode)); 679 sizeof(struct GNUNET_HashCode));
684 if (NULL == ac->hash) 680 if (NULL == ac->hash)
685 { 681 {
686 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, 682 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR,
687 "calloc"); 683 "calloc");
688 GNUNET_SCHEDULER_shutdown (); 684 GNUNET_SCHEDULER_shutdown();
689 return; 685 return;
690 } 686 }
691 ac->delay_task = GNUNET_SCHEDULER_add_delayed (peer_delay_put, 687 ac->delay_task = GNUNET_SCHEDULER_add_delayed(peer_delay_put,
692 &delayed_put, 688 &delayed_put,
693 ac); 689 ac);
694 break; 690 break;
695 } 691 }
696 case MODE_GET: 692
693 case MODE_GET:
697 { 694 {
698 struct GNUNET_TIME_Relative peer_delay_get; 695 struct GNUNET_TIME_Relative peer_delay_get;
699 696
700 peer_delay_get.rel_value_us = 697 peer_delay_get.rel_value_us =
701 delay_get.rel_value_us + 698 delay_get.rel_value_us +
702 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 699 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
703 delay_get.rel_value_us); 700 delay_get.rel_value_us);
704 ac->delay_task = GNUNET_SCHEDULER_add_delayed (peer_delay_get, 701 ac->delay_task = GNUNET_SCHEDULER_add_delayed(peer_delay_get,
705 &delayed_get, 702 &delayed_get,
706 ac); 703 ac);
707 break; 704 break;
708 } 705 }
709 } 706 }
710} 707}
711 708
712 709
@@ -720,12 +717,12 @@ dht_connected (void *cls,
720 * @return service handle to return in 'op_result', NULL on error 717 * @return service handle to return in 'op_result', NULL on error
721 */ 718 */
722static void * 719static void *
723dht_connect (void *cls, 720dht_connect(void *cls,
724 const struct GNUNET_CONFIGURATION_Handle *cfg) 721 const struct GNUNET_CONFIGURATION_Handle *cfg)
725{ 722{
726 n_dht++; 723 n_dht++;
727 return GNUNET_DHT_connect (cfg, 724 return GNUNET_DHT_connect(cfg,
728 10); 725 10);
729} 726}
730 727
731 728
@@ -737,14 +734,14 @@ dht_connect (void *cls,
737 * @param op_result service handle returned from the connect adapter 734 * @param op_result service handle returned from the connect adapter
738 */ 735 */
739static void 736static void
740dht_disconnect (void *cls, 737dht_disconnect(void *cls,
741 void *op_result) 738 void *op_result)
742{ 739{
743 struct ActiveContext *ac = cls; 740 struct ActiveContext *ac = cls;
744 741
745 GNUNET_assert (NULL != ac->dht); 742 GNUNET_assert(NULL != ac->dht);
746 GNUNET_assert (ac->dht == op_result); 743 GNUNET_assert(ac->dht == op_result);
747 GNUNET_DHT_disconnect (ac->dht); 744 GNUNET_DHT_disconnect(ac->dht);
748 ac->dht = NULL; 745 ac->dht = NULL;
749 n_dht--; 746 n_dht--;
750 if (0 != n_dht) 747 if (0 != n_dht)
@@ -752,19 +749,20 @@ dht_disconnect (void *cls,
752 if (GNUNET_YES == in_shutdown) 749 if (GNUNET_YES == in_shutdown)
753 return; 750 return;
754 switch (mode) 751 switch (mode)
755 { 752 {
756 case MODE_PUT: 753 case MODE_PUT:
757 if (n_puts_ok != ((unsigned long long) n_active) * num_puts_per_peer) 754 if (n_puts_ok != ((unsigned long long)n_active) * num_puts_per_peer)
758 return; 755 return;
759 /* Start GETs if all PUTs have been made */ 756 /* Start GETs if all PUTs have been made */
760 mode = MODE_GET; 757 mode = MODE_GET;
761 start_profiling (); 758 start_profiling();
762 return;
763 case MODE_GET:
764 if ((n_gets_ok + n_gets_fail) != n_active)
765 return; 759 return;
766 break; 760
767 } 761 case MODE_GET:
762 if ((n_gets_ok + n_gets_fail) != n_active)
763 return;
764 break;
765 }
768} 766}
769 767
770 768
@@ -776,21 +774,21 @@ start_profiling()
776{ 774{
777 struct Context *ctx; 775 struct Context *ctx;
778 776
779 DEBUG ("GNUNET_TESTBED_service_connect\n"); 777 DEBUG("GNUNET_TESTBED_service_connect\n");
780 GNUNET_break (GNUNET_YES != in_shutdown); 778 GNUNET_break(GNUNET_YES != in_shutdown);
781 for (unsigned int i = 0; i < n_active; i++) 779 for (unsigned int i = 0; i < n_active; i++)
782 { 780 {
783 struct ActiveContext *ac = &a_ac[i]; 781 struct ActiveContext *ac = &a_ac[i];
784 GNUNET_assert (NULL != (ctx = ac->ctx)); 782 GNUNET_assert(NULL != (ctx = ac->ctx));
785 GNUNET_assert (NULL == ctx->op); 783 GNUNET_assert(NULL == ctx->op);
786 ctx->op = GNUNET_TESTBED_service_connect (ctx, 784 ctx->op = GNUNET_TESTBED_service_connect(ctx,
787 ctx->peer, 785 ctx->peer,
788 "dht", 786 "dht",
789 &dht_connected, ac, 787 &dht_connected, ac,
790 &dht_connect, 788 &dht_connect,
791 &dht_disconnect, 789 &dht_disconnect,
792 ac); 790 ac);
793 } 791 }
794} 792}
795 793
796 794
@@ -803,22 +801,22 @@ start_profiling()
803 * operation has executed successfully. 801 * operation has executed successfully.
804 */ 802 */
805static void 803static void
806service_started (void *cls, 804service_started(void *cls,
807 struct GNUNET_TESTBED_Operation *op, 805 struct GNUNET_TESTBED_Operation *op,
808 const char *emsg) 806 const char *emsg)
809{ 807{
810 struct Context *ctx = cls; 808 struct Context *ctx = cls;
811 809
812 GNUNET_assert (NULL != ctx); 810 GNUNET_assert(NULL != ctx);
813 GNUNET_assert (NULL != ctx->op); 811 GNUNET_assert(NULL != ctx->op);
814 GNUNET_TESTBED_operation_done (ctx->op); 812 GNUNET_TESTBED_operation_done(ctx->op);
815 ctx->op = NULL; 813 ctx->op = NULL;
816 peers_started++; 814 peers_started++;
817 DEBUG ("Peers Started = %d; num_peers = %d \n", 815 DEBUG("Peers Started = %d; num_peers = %d \n",
818 peers_started, 816 peers_started,
819 num_peers); 817 num_peers);
820 if (peers_started == num_peers) 818 if (peers_started == num_peers)
821 start_profiling (); 819 start_profiling();
822} 820}
823 821
824 822
@@ -834,63 +832,63 @@ service_started (void *cls,
834 * @param links_failed the number of overlay link 832 * @param links_failed the number of overlay link
835 */ 833 */
836static void 834static void
837test_run (void *cls, 835test_run(void *cls,
838 struct GNUNET_TESTBED_RunHandle *h, 836 struct GNUNET_TESTBED_RunHandle *h,
839 unsigned int num_peers, 837 unsigned int num_peers,
840 struct GNUNET_TESTBED_Peer **peers, 838 struct GNUNET_TESTBED_Peer **peers,
841 unsigned int links_succeeded, 839 unsigned int links_succeeded,
842 unsigned int links_failed) 840 unsigned int links_failed)
843{ 841{
844 unsigned int ac_cnt; 842 unsigned int ac_cnt;
845 843
846 testbed_handles = peers; 844 testbed_handles = peers;
847 if (NULL == peers) 845 if (NULL == peers)
848 { 846 {
849 /* exit */ 847 /* exit */
850 GNUNET_assert (0); 848 GNUNET_assert(0);
851 } 849 }
852 MESSAGE ("%u peers started, %u/%u links up\n", 850 MESSAGE("%u peers started, %u/%u links up\n",
853 num_peers, 851 num_peers,
854 links_succeeded, 852 links_succeeded,
855 links_succeeded + links_failed); 853 links_succeeded + links_failed);
856 a_ctx = GNUNET_new_array (num_peers, 854 a_ctx = GNUNET_new_array(num_peers,
857 struct Context); 855 struct Context);
858 /* select the peers which actively participate in profiling */ 856 /* select the peers which actively participate in profiling */
859 n_active = num_peers * put_probability / 100; 857 n_active = num_peers * put_probability / 100;
860 if (0 == n_active) 858 if (0 == n_active)
861 { 859 {
862 GNUNET_SCHEDULER_shutdown (); 860 GNUNET_SCHEDULER_shutdown();
863 GNUNET_free (a_ctx); 861 GNUNET_free(a_ctx);
864 a_ctx = NULL; 862 a_ctx = NULL;
865 return; 863 return;
866 } 864 }
867 865
868 a_ac = GNUNET_new_array (n_active, 866 a_ac = GNUNET_new_array(n_active,
869 struct ActiveContext); 867 struct ActiveContext);
870 ac_cnt = 0; 868 ac_cnt = 0;
871 for (unsigned int cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++) 869 for (unsigned int cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++)
872 { 870 {
873 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 871 if (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
874 100) >= put_probability) 872 100) >= put_probability)
875 continue; 873 continue;
876 874
877 a_ctx[cnt].ac = &a_ac[ac_cnt]; 875 a_ctx[cnt].ac = &a_ac[ac_cnt];
878 a_ac[ac_cnt].ctx = &a_ctx[cnt]; 876 a_ac[ac_cnt].ctx = &a_ctx[cnt];
879 ac_cnt++; 877 ac_cnt++;
880 } 878 }
881 n_active = ac_cnt; 879 n_active = ac_cnt;
882 880
883 /* start DHT service on all peers */ 881 /* start DHT service on all peers */
884 for (unsigned int cnt = 0; cnt < num_peers; cnt++) 882 for (unsigned int cnt = 0; cnt < num_peers; cnt++)
885 { 883 {
886 a_ctx[cnt].peer = peers[cnt]; 884 a_ctx[cnt].peer = peers[cnt];
887 a_ctx[cnt].op = GNUNET_TESTBED_peer_manage_service (&a_ctx[cnt], 885 a_ctx[cnt].op = GNUNET_TESTBED_peer_manage_service(&a_ctx[cnt],
888 peers[cnt], 886 peers[cnt],
889 "dht", 887 "dht",
890 &service_started, 888 &service_started,
891 &a_ctx[cnt], 889 &a_ctx[cnt],
892 1); 890 1);
893 } 891 }
894} 892}
895 893
896 894
@@ -903,32 +901,32 @@ test_run (void *cls,
903 * @param config configuration 901 * @param config configuration
904 */ 902 */
905static void 903static void
906run (void *cls, 904run(void *cls,
907 char *const *args, 905 char *const *args,
908 const char *cfgfile, 906 const char *cfgfile,
909 const struct GNUNET_CONFIGURATION_Handle *config) 907 const struct GNUNET_CONFIGURATION_Handle *config)
910{ 908{
911 uint64_t event_mask; 909 uint64_t event_mask;
912 910
913 if (0 == num_peers) 911 if (0 == num_peers)
914 { 912 {
915 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 913 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
916 _("Exiting as the number of peers is %u\n"), 914 _("Exiting as the number of peers is %u\n"),
917 num_peers); 915 num_peers);
918 return; 916 return;
919 } 917 }
920 cfg = config; 918 cfg = config;
921 event_mask = 0; 919 event_mask = 0;
922 GNUNET_TESTBED_run (hosts_file, 920 GNUNET_TESTBED_run(hosts_file,
923 cfg, 921 cfg,
924 num_peers, 922 num_peers,
925 event_mask, 923 event_mask,
926 NULL, 924 NULL,
927 NULL, 925 NULL,
928 &test_run, 926 &test_run,
929 NULL); 927 NULL);
930 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 928 GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
931 NULL); 929 NULL);
932} 930}
933 931
934 932
@@ -938,78 +936,78 @@ run (void *cls,
938 * @return 0 on success 936 * @return 0 on success
939 */ 937 */
940int 938int
941main (int argc, 939main(int argc,
942 char *const *argv) 940 char *const *argv)
943{ 941{
944 int rc; 942 int rc;
945 struct GNUNET_GETOPT_CommandLineOption options[] = { 943 struct GNUNET_GETOPT_CommandLineOption options[] = {
946 GNUNET_GETOPT_option_uint ('n', 944 GNUNET_GETOPT_option_uint('n',
947 "peers", 945 "peers",
948 "COUNT", 946 "COUNT",
949 gettext_noop ("number of peers to start"), 947 gettext_noop("number of peers to start"),
950 &num_peers), 948 &num_peers),
951 GNUNET_GETOPT_option_uint ('p', 949 GNUNET_GETOPT_option_uint('p',
952 "peer-put-count", 950 "peer-put-count",
953 "COUNT", 951 "COUNT",
954 gettext_noop ("number of PUTs to perform per peer"), 952 gettext_noop("number of PUTs to perform per peer"),
955 &num_puts_per_peer), 953 &num_puts_per_peer),
956 GNUNET_GETOPT_option_string ('H', 954 GNUNET_GETOPT_option_string('H',
957 "hosts", 955 "hosts",
958 "FILENAME", 956 "FILENAME",
959 gettext_noop ("name of the file with the login information for the testbed"), 957 gettext_noop("name of the file with the login information for the testbed"),
960 &hosts_file), 958 &hosts_file),
961 GNUNET_GETOPT_option_relative_time ('D', 959 GNUNET_GETOPT_option_relative_time('D',
962 "delay", 960 "delay",
963 "DELAY", 961 "DELAY",
964 gettext_noop ("delay between rounds for collecting statistics (default: 30 sec)"), 962 gettext_noop("delay between rounds for collecting statistics (default: 30 sec)"),
965 &delay_stats), 963 &delay_stats),
966 GNUNET_GETOPT_option_relative_time ('P', 964 GNUNET_GETOPT_option_relative_time('P',
967 "PUT-delay", 965 "PUT-delay",
968 "DELAY", 966 "DELAY",
969 gettext_noop ("delay to start doing PUTs (default: 1 sec)"), 967 gettext_noop("delay to start doing PUTs (default: 1 sec)"),
970 &delay_put), 968 &delay_put),
971 GNUNET_GETOPT_option_relative_time ('G', 969 GNUNET_GETOPT_option_relative_time('G',
972 "GET-delay", 970 "GET-delay",
973 "DELAY", 971 "DELAY",
974 gettext_noop ("delay to start doing GETs (default: 5 min)"), 972 gettext_noop("delay to start doing GETs (default: 5 min)"),
975 &delay_get), 973 &delay_get),
976 GNUNET_GETOPT_option_uint ('r', 974 GNUNET_GETOPT_option_uint('r',
977 "replication", 975 "replication",
978 "DEGREE", 976 "DEGREE",
979 gettext_noop ("replication degree for DHT PUTs"), 977 gettext_noop("replication degree for DHT PUTs"),
980 &replication), 978 &replication),
981 GNUNET_GETOPT_option_uint ('R', 979 GNUNET_GETOPT_option_uint('R',
982 "random-chance", 980 "random-chance",
983 "PROBABILITY", 981 "PROBABILITY",
984 gettext_noop ("chance that a peer is selected at random for PUTs"), 982 gettext_noop("chance that a peer is selected at random for PUTs"),
985 &put_probability), 983 &put_probability),
986 GNUNET_GETOPT_option_relative_time ('t', 984 GNUNET_GETOPT_option_relative_time('t',
987 "timeout", 985 "timeout",
988 "TIMEOUT", 986 "TIMEOUT",
989 gettext_noop ("timeout for DHT PUT and GET requests (default: 1 min)"), 987 gettext_noop("timeout for DHT PUT and GET requests (default: 1 min)"),
990 &timeout), 988 &timeout),
991 GNUNET_GETOPT_OPTION_END 989 GNUNET_GETOPT_OPTION_END
992 }; 990 };
993 991
994 if (GNUNET_OK != 992 if (GNUNET_OK !=
995 GNUNET_STRINGS_get_utf8_args (argc, argv, 993 GNUNET_STRINGS_get_utf8_args(argc, argv,
996 &argc, &argv)) 994 &argc, &argv))
997 return 2; 995 return 2;
998 /* set default delays */ 996 /* set default delays */
999 delay_stats = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); 997 delay_stats = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10);
1000 delay_put = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); 998 delay_put = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10);
1001 delay_get = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); 999 delay_get = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10);
1002 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); 1000 timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10);
1003 replication = 1; /* default replication */ 1001 replication = 1; /* default replication */
1004 rc = 0; 1002 rc = 0;
1005 if (GNUNET_OK != 1003 if (GNUNET_OK !=
1006 GNUNET_PROGRAM_run (argc, 1004 GNUNET_PROGRAM_run(argc,
1007 argv, 1005 argv,
1008 "gnunet-dht-profiler", 1006 "gnunet-dht-profiler",
1009 gettext_noop ("Measure quality and performance of the DHT service."), 1007 gettext_noop("Measure quality and performance of the DHT service."),
1010 options, 1008 options,
1011 &run, 1009 &run,
1012 NULL)) 1010 NULL))
1013 rc = 1; 1011 rc = 1;
1014 return rc; 1012 return rc;
1015} 1013}