diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-11-08 14:09:51 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-11-08 14:09:51 +0000 |
commit | d2c8b3d900d2feccf8efb752ea3c50e0091d0cd5 (patch) | |
tree | 00e3c96a5a172094d1af41108a01485f3585f948 /src/transport/gnunet-transport.c | |
parent | ace4b0ed0bc524f36bf8e74a56145e0e8f59f6eb (diff) | |
download | gnunet-d2c8b3d900d2feccf8efb752ea3c50e0091d0cd5.tar.gz gnunet-d2c8b3d900d2feccf8efb752ea3c50e0091d0cd5.zip |
changes
Diffstat (limited to 'src/transport/gnunet-transport.c')
-rw-r--r-- | src/transport/gnunet-transport.c | 140 |
1 files changed, 79 insertions, 61 deletions
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index 42ca26b74..e125c5e56 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c | |||
@@ -44,6 +44,12 @@ | |||
44 | #define OP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 44 | #define OP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) |
45 | 45 | ||
46 | /** | 46 | /** |
47 | * Benchmarking block size in KB | ||
48 | */ | ||
49 | #define BLOCKSIZE 4 | ||
50 | |||
51 | |||
52 | /** | ||
47 | * Which peer should we connect to? | 53 | * Which peer should we connect to? |
48 | */ | 54 | */ |
49 | static char *cpid; | 55 | static char *cpid; |
@@ -212,6 +218,8 @@ static void | |||
212 | shutdown_task (void *cls, | 218 | shutdown_task (void *cls, |
213 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 219 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
214 | { | 220 | { |
221 | struct GNUNET_TIME_Relative duration; | ||
222 | end = GNUNET_SCHEDULER_NO_TASK; | ||
215 | if (GNUNET_SCHEDULER_NO_TASK != op_timeout) | 223 | if (GNUNET_SCHEDULER_NO_TASK != op_timeout) |
216 | { | 224 | { |
217 | GNUNET_SCHEDULER_cancel (op_timeout); | 225 | GNUNET_SCHEDULER_cancel (op_timeout); |
@@ -237,6 +245,21 @@ shutdown_task (void *cls, | |||
237 | GNUNET_CONTAINER_multihashmap_destroy (peers); | 245 | GNUNET_CONTAINER_multihashmap_destroy (peers); |
238 | peers = NULL; | 246 | peers = NULL; |
239 | } | 247 | } |
248 | if (benchmark_send) | ||
249 | { | ||
250 | duration = GNUNET_TIME_absolute_get_duration (start_time); | ||
251 | FPRINTF (stdout, _("Transmitted %llu bytes/s (%llu bytes in %s)\n"), | ||
252 | 1000 * traffic_sent / (1 + duration.rel_value), traffic_sent, | ||
253 | GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); | ||
254 | } | ||
255 | if (benchmark_receive) | ||
256 | { | ||
257 | duration = GNUNET_TIME_absolute_get_duration (start_time); | ||
258 | FPRINTF (stdout, _("Received %llu bytes/s (%llu bytes in %s)\n"), | ||
259 | 1000 * traffic_received / (1 + duration.rel_value), | ||
260 | traffic_received, | ||
261 | GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); | ||
262 | } | ||
240 | } | 263 | } |
241 | 264 | ||
242 | 265 | ||
@@ -246,7 +269,7 @@ operation_timeout (void *cls, | |||
246 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 269 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
247 | { | 270 | { |
248 | op_timeout = GNUNET_SCHEDULER_NO_TASK; | 271 | op_timeout = GNUNET_SCHEDULER_NO_TASK; |
249 | if (try_connect) | 272 | if ((try_connect) || (benchmark_send) || (benchmark_receive)) |
250 | { | 273 | { |
251 | FPRINTF (stdout, _("Failed to connect to `%s'\n"), GNUNET_h2s_full (&pid.hashPubKey)); | 274 | FPRINTF (stdout, _("Failed to connect to `%s'\n"), GNUNET_h2s_full (&pid.hashPubKey)); |
252 | if (GNUNET_SCHEDULER_NO_TASK != end) | 275 | if (GNUNET_SCHEDULER_NO_TASK != end) |
@@ -396,39 +419,6 @@ do_test_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
396 | GNUNET_free (plugins); | 419 | GNUNET_free (plugins); |
397 | } | 420 | } |
398 | 421 | ||
399 | |||
400 | /** | ||
401 | * Shutdown, print statistics. | ||
402 | */ | ||
403 | static void | ||
404 | do_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
405 | { | ||
406 | struct GNUNET_TIME_Relative duration; | ||
407 | |||
408 | if (NULL != th) | ||
409 | { | ||
410 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
411 | th = NULL; | ||
412 | } | ||
413 | GNUNET_TRANSPORT_disconnect (handle); | ||
414 | if (benchmark_receive) | ||
415 | { | ||
416 | duration = GNUNET_TIME_absolute_get_duration (start_time); | ||
417 | FPRINTF (stdout, _("Received %llu bytes/s (%llu bytes in %s)\n"), | ||
418 | 1000 * traffic_received / (1 + duration.rel_value), | ||
419 | traffic_received, | ||
420 | GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); | ||
421 | } | ||
422 | if (benchmark_send) | ||
423 | { | ||
424 | duration = GNUNET_TIME_absolute_get_duration (start_time); | ||
425 | FPRINTF (stdout, _("Transmitted %llu bytes/s (%llu bytes in %s)\n"), | ||
426 | 1000 * traffic_sent / (1 + duration.rel_value), traffic_sent, | ||
427 | GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); | ||
428 | } | ||
429 | } | ||
430 | |||
431 | |||
432 | /** | 422 | /** |
433 | * Function called to notify a client about the socket | 423 | * Function called to notify a client about the socket |
434 | * begin ready to queue more data. "buf" will be | 424 | * begin ready to queue more data. "buf" will be |
@@ -457,7 +447,7 @@ transmit_data (void *cls, size_t size, void *buf) | |||
457 | m->type = ntohs (GNUNET_MESSAGE_TYPE_DUMMY); | 447 | m->type = ntohs (GNUNET_MESSAGE_TYPE_DUMMY); |
458 | memset (&m[1], 52, size - sizeof (struct GNUNET_MessageHeader)); | 448 | memset (&m[1], 52, size - sizeof (struct GNUNET_MessageHeader)); |
459 | traffic_sent += size; | 449 | traffic_sent += size; |
460 | th = GNUNET_TRANSPORT_notify_transmit_ready (handle, &pid, 32 * 1024, 0, | 450 | th = GNUNET_TRANSPORT_notify_transmit_ready (handle, &pid, BLOCKSIZE * 1024, 0, |
461 | GNUNET_TIME_UNIT_FOREVER_REL, | 451 | GNUNET_TIME_UNIT_FOREVER_REL, |
462 | &transmit_data, NULL); | 452 | &transmit_data, NULL); |
463 | if (verbosity > 0) | 453 | if (verbosity > 0) |
@@ -480,34 +470,54 @@ static void | |||
480 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | 470 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, |
481 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) | 471 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) |
482 | { | 472 | { |
483 | if (verbosity > 0) | ||
484 | FPRINTF (stdout, _("Connected to %s\n"), GNUNET_i2s (peer)); | ||
485 | if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) | 473 | if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) |
486 | return; | 474 | return; |
487 | ret = 0; | 475 | ret = 0; |
488 | if (try_connect) | 476 | if (try_connect) |
489 | { | 477 | { |
490 | /* all done, terminate instantly */ | 478 | /* all done, terminate instantly */ |
491 | FPRINTF (stdout, _("Successfully connected to %s\n"), GNUNET_h2s_full (&peer->hashPubKey)); | 479 | FPRINTF (stdout, _("Successfully connected to `%s'\n"), GNUNET_h2s_full (&peer->hashPubKey)); |
492 | ret = 0; | 480 | ret = 0; |
493 | 481 | ||
494 | if (GNUNET_SCHEDULER_NO_TASK != op_timeout) | 482 | if (GNUNET_SCHEDULER_NO_TASK != op_timeout) |
483 | { | ||
495 | GNUNET_SCHEDULER_cancel (op_timeout); | 484 | GNUNET_SCHEDULER_cancel (op_timeout); |
485 | op_timeout = GNUNET_SCHEDULER_NO_TASK; | ||
486 | } | ||
496 | 487 | ||
497 | if (GNUNET_SCHEDULER_NO_TASK != end) | 488 | if (GNUNET_SCHEDULER_NO_TASK != end) |
498 | GNUNET_SCHEDULER_cancel (end); | 489 | GNUNET_SCHEDULER_cancel (end); |
499 | end = GNUNET_SCHEDULER_add_now (&do_disconnect, NULL); | 490 | end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); |
500 | return; | 491 | return; |
501 | } | 492 | } |
502 | if (benchmark_send) | 493 | if (benchmark_send) |
503 | { | 494 | { |
495 | if (GNUNET_SCHEDULER_NO_TASK != op_timeout) | ||
496 | { | ||
497 | GNUNET_SCHEDULER_cancel (op_timeout); | ||
498 | op_timeout = GNUNET_SCHEDULER_NO_TASK; | ||
499 | } | ||
500 | if (verbosity > 0) | ||
501 | FPRINTF (stdout, _("Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"), | ||
502 | GNUNET_i2s (&pid), BLOCKSIZE); | ||
504 | start_time = GNUNET_TIME_absolute_get (); | 503 | start_time = GNUNET_TIME_absolute_get (); |
505 | if (NULL == th) | 504 | if (NULL == th) |
506 | th = GNUNET_TRANSPORT_notify_transmit_ready (handle, peer, 32 * 1024, 0, | 505 | th = GNUNET_TRANSPORT_notify_transmit_ready (handle, peer, |
507 | GNUNET_TIME_UNIT_FOREVER_REL, | 506 | BLOCKSIZE * 1024, 0, |
508 | &transmit_data, NULL); | 507 | GNUNET_TIME_UNIT_FOREVER_REL, |
508 | &transmit_data, NULL); | ||
509 | else | ||
510 | GNUNET_break (0); | ||
509 | return; | 511 | return; |
510 | } | 512 | } |
513 | if (benchmark_receive) | ||
514 | { | ||
515 | if (verbosity > 0) | ||
516 | FPRINTF (stdout, _("Successfully connected to `%s', starting to receive benchmark data\n"), | ||
517 | GNUNET_i2s (&pid)); | ||
518 | start_time = GNUNET_TIME_absolute_get (); | ||
519 | return; | ||
520 | } | ||
511 | } | 521 | } |
512 | 522 | ||
513 | 523 | ||
@@ -521,14 +531,21 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
521 | static void | 531 | static void |
522 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | 532 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) |
523 | { | 533 | { |
524 | if (verbosity > 0) | 534 | if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) |
525 | FPRINTF (stdout, _("Disconnected from %s\n"), GNUNET_i2s (peer)); | 535 | return; |
536 | |||
526 | if (NULL != th) | 537 | if (NULL != th) |
527 | { | 538 | { |
528 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 539 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
529 | th = NULL; | 540 | th = NULL; |
530 | } | 541 | } |
531 | 542 | if (benchmark_send) | |
543 | { | ||
544 | FPRINTF (stdout, _("Disconnected from peer `%s' while benchmarking\n"), GNUNET_i2s (&pid)); | ||
545 | if (GNUNET_SCHEDULER_NO_TASK != end) | ||
546 | GNUNET_SCHEDULER_cancel (end); | ||
547 | return; | ||
548 | } | ||
532 | } | 549 | } |
533 | 550 | ||
534 | /** | 551 | /** |
@@ -595,16 +612,18 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
595 | const struct GNUNET_MessageHeader *message, | 612 | const struct GNUNET_MessageHeader *message, |
596 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) | 613 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) |
597 | { | 614 | { |
598 | if (!benchmark_receive) | 615 | if (benchmark_receive) |
599 | return; | 616 | { |
600 | if (GNUNET_MESSAGE_TYPE_DUMMY != ntohs (message->type)) | 617 | if (GNUNET_MESSAGE_TYPE_DUMMY != ntohs (message->type)) |
618 | return; | ||
619 | if (verbosity > 0) | ||
620 | FPRINTF (stdout, _("Received %u bytes from %s\n"), | ||
621 | (unsigned int) ntohs (message->size), GNUNET_i2s (peer)); | ||
622 | if (traffic_received == 0) | ||
623 | start_time = GNUNET_TIME_absolute_get (); | ||
624 | traffic_received += ntohs (message->size); | ||
601 | return; | 625 | return; |
602 | if (verbosity > 0) | 626 | } |
603 | FPRINTF (stdout, _("Received %u bytes from %s\n"), | ||
604 | (unsigned int) ntohs (message->size), GNUNET_i2s (peer)); | ||
605 | if (traffic_received == 0) | ||
606 | start_time = GNUNET_TIME_absolute_get (); | ||
607 | traffic_received += ntohs (message->size); | ||
608 | } | 627 | } |
609 | 628 | ||
610 | struct ResolutionContext | 629 | struct ResolutionContext |
@@ -635,7 +654,7 @@ process_string (void *cls, const char *address) | |||
635 | FPRINTF (stdout, _("Peer `%s': %s <unable to resolve address>\n"), GNUNET_i2s (&addrcp->peer), addrcp->transport_name); | 654 | FPRINTF (stdout, _("Peer `%s': %s <unable to resolve address>\n"), GNUNET_i2s (&addrcp->peer), addrcp->transport_name); |
636 | GNUNET_free (rc->addrcp); | 655 | GNUNET_free (rc->addrcp); |
637 | GNUNET_free (rc); | 656 | GNUNET_free (rc); |
638 | if (0 == address_resolutions) | 657 | if ((0 == address_resolutions) && (iterate_connections)) |
639 | { | 658 | { |
640 | if (GNUNET_SCHEDULER_NO_TASK != end) | 659 | if (GNUNET_SCHEDULER_NO_TASK != end) |
641 | GNUNET_SCHEDULER_cancel (end); | 660 | GNUNET_SCHEDULER_cancel (end); |
@@ -768,10 +787,9 @@ testservice_task (void *cls, | |||
768 | return; | 787 | return; |
769 | } | 788 | } |
770 | GNUNET_TRANSPORT_try_connect (handle, &pid); | 789 | GNUNET_TRANSPORT_try_connect (handle, &pid); |
771 | 790 | start_time = GNUNET_TIME_absolute_get (); | |
772 | op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, | 791 | op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, |
773 | &operation_timeout, | 792 | &operation_timeout, NULL); |
774 | NULL); | ||
775 | } | 793 | } |
776 | else if (benchmark_receive) /* Benchmark receiving */ | 794 | else if (benchmark_receive) /* Benchmark receiving */ |
777 | { | 795 | { |
@@ -786,9 +804,8 @@ testservice_task (void *cls, | |||
786 | } | 804 | } |
787 | GNUNET_TRANSPORT_try_connect (handle, &pid); | 805 | GNUNET_TRANSPORT_try_connect (handle, &pid); |
788 | start_time = GNUNET_TIME_absolute_get (); | 806 | start_time = GNUNET_TIME_absolute_get (); |
789 | /* | 807 | op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, |
790 | end = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 808 | &operation_timeout, NULL); |
791 | &do_disconnect, NULL);*/ | ||
792 | } | 809 | } |
793 | else if (iterate_connections) /* -i: List all active addresses once */ | 810 | else if (iterate_connections) /* -i: List all active addresses once */ |
794 | { | 811 | { |
@@ -845,6 +862,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
845 | if (test_configuration) | 862 | if (test_configuration) |
846 | { | 863 | { |
847 | do_test_configuration (cfg); | 864 | do_test_configuration (cfg); |
865 | return; | ||
848 | } | 866 | } |
849 | 867 | ||
850 | GNUNET_CLIENT_service_test ("transport", cfg, | 868 | GNUNET_CLIENT_service_test ("transport", cfg, |