aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-11-08 10:29:44 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-11-08 10:29:44 +0000
commit573b78a4733ff0e7be46de19328d2b9049ae896b (patch)
treeddbba35fb3f3164863486a87e24aaff5ae6328a4 /src
parentddd5cddf5fcecccbadb3430896ffa2a46f679780 (diff)
downloadgnunet-573b78a4733ff0e7be46de19328d2b9049ae896b.tar.gz
gnunet-573b78a4733ff0e7be46de19328d2b9049ae896b.zip
- clean up gnunet-transport (not finished)
Diffstat (limited to 'src')
-rw-r--r--src/transport/gnunet-transport.c193
1 files changed, 132 insertions, 61 deletions
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index 18b1b9839..6d14d51aa 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -78,6 +78,11 @@ static int iterate_connections;
78static int test_configuration; 78static int test_configuration;
79 79
80/** 80/**
81 * Option -c.
82 */
83static int monitor_connects;
84
85/**
81 * Option -m. 86 * Option -m.
82 */ 87 */
83static int monitor_connections; 88static int monitor_connections;
@@ -95,7 +100,7 @@ static int ret;
95/** 100/**
96 * Current number of connections in monitor mode 101 * Current number of connections in monitor mode
97 */ 102 */
98static int monitor_connections_counter; 103static int monitor_connect_counter;
99 104
100/** 105/**
101 * Number of bytes of traffic we received so far. 106 * Number of bytes of traffic we received so far.
@@ -118,6 +123,11 @@ static struct GNUNET_TIME_Absolute start_time;
118static struct GNUNET_TRANSPORT_TransmitHandle *th; 123static struct GNUNET_TRANSPORT_TransmitHandle *th;
119 124
120/** 125/**
126 *
127 */
128struct GNUNET_TRANSPORT_PeerIterateContext *pic;
129
130/**
121 * Identity of the peer we transmit to / connect to. 131 * Identity of the peer we transmit to / connect to.
122 * (equivalent to 'cpid' string). 132 * (equivalent to 'cpid' string).
123 */ 133 */
@@ -145,6 +155,15 @@ struct GNUNET_OS_Process *resolver;
145 */ 155 */
146static unsigned int resolver_users; 156static unsigned int resolver_users;
147 157
158/**
159 * Number of address resolutions pending
160 */
161static unsigned int address_resolutions;
162
163/**
164 * Address resolutions pending in progress
165 */
166static unsigned int address_resolution_in_progress;
148 167
149/** 168/**
150 * Context for a plugin test. 169 * Context for a plugin test.
@@ -171,6 +190,40 @@ struct TestContext
171 190
172 191
173/** 192/**
193 * Task run in monitor mode when the user presses CTRL-C to abort.
194 * Stops monitoring activity.
195 *
196 * @param cls the 'struct GNUNET_TRANSPORT_PeerIterateContext *'
197 * @param tc scheduler context
198 */
199static void
200shutdown_task (void *cls,
201 const struct GNUNET_SCHEDULER_TaskContext *tc)
202{
203 if (NULL != pic)
204 {
205 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pic);
206 pic = NULL;
207 }
208 if (NULL != th)
209 {
210 GNUNET_TRANSPORT_notify_transmit_ready_cancel(th);
211 th = NULL;
212 }
213 if (NULL != handle)
214 {
215 GNUNET_TRANSPORT_disconnect(handle);
216 handle = NULL;
217 }
218
219 if (NULL != peers)
220 {
221 GNUNET_CONTAINER_multihashmap_destroy (peers);
222 peers = NULL;
223 }
224}
225
226/**
174 * Display the result of the test. 227 * Display the result of the test.
175 * 228 *
176 * @param tc test context 229 * @param tc test context
@@ -446,7 +499,7 @@ static void
446monitor_notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 499monitor_notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
447 const struct GNUNET_ATS_Information *ats, uint32_t ats_count) 500 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
448{ 501{
449 monitor_connections_counter ++; 502 monitor_connect_counter ++;
450 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); 503 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
451 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); 504 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
452 505
@@ -454,7 +507,7 @@ monitor_notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
454 now_str, 507 now_str,
455 _("Connected to"), 508 _("Connected to"),
456 GNUNET_i2s (peer), 509 GNUNET_i2s (peer),
457 monitor_connections_counter); 510 monitor_connect_counter);
458} 511}
459 512
460 513
@@ -471,14 +524,14 @@ monitor_notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
471 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); 524 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
472 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); 525 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
473 526
474 GNUNET_assert (monitor_connections_counter > 0); 527 GNUNET_assert (monitor_connect_counter > 0);
475 monitor_connections_counter --; 528 monitor_connect_counter --;
476 529
477 FPRINTF (stdout, _("%24s: %-17s %4s (%u connections in total)\n"), 530 FPRINTF (stdout, _("%24s: %-17s %4s (%u connections in total)\n"),
478 now_str, 531 now_str,
479 _("Disconnected from"), 532 _("Disconnected from"),
480 GNUNET_i2s (peer), 533 GNUNET_i2s (peer),
481 monitor_connections_counter); 534 monitor_connect_counter);
482} 535}
483 536
484 537
@@ -531,10 +584,20 @@ process_string (void *cls, const char *address)
531 else 584 else
532 { 585 {
533 /* done */ 586 /* done */
587 GNUNET_assert (address_resolutions > 0);
588 address_resolutions --;
534 if (GNUNET_NO == rc->printed) 589 if (GNUNET_NO == rc->printed)
535 FPRINTF (stdout, _("Peer `%s': %s <unable to resolve address>\n"), GNUNET_i2s (&addrcp->peer), addrcp->transport_name); 590 FPRINTF (stdout, _("Peer `%s': %s <unable to resolve address>\n"), GNUNET_i2s (&addrcp->peer), addrcp->transport_name);
536 GNUNET_free (rc->addrcp); 591 GNUNET_free (rc->addrcp);
537 GNUNET_free (rc); 592 GNUNET_free (rc);
593 FPRINTF (stdout, _("Peer --: %u\n"), address_resolutions);
594 if (0 == address_resolutions)
595 {
596 if (GNUNET_SCHEDULER_NO_TASK == end)
597 GNUNET_SCHEDULER_cancel (end);
598 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
599 GNUNET_break (0);
600 }
538 } 601 }
539} 602}
540 603
@@ -555,9 +618,10 @@ process_address (void *cls, const struct GNUNET_PeerIdentity *peer,
555 if (peer == NULL) 618 if (peer == NULL)
556 { 619 {
557 /* done */ 620 /* done */
621 address_resolution_in_progress = GNUNET_NO;
622 pic = NULL;
558 return; 623 return;
559 } 624 }
560
561 if (address == NULL) 625 if (address == NULL)
562 { 626 {
563 FPRINTF (stdout, _("Peer `%s' disconnected\n"), GNUNET_i2s (peer)); 627 FPRINTF (stdout, _("Peer `%s' disconnected\n"), GNUNET_i2s (peer));
@@ -569,7 +633,8 @@ process_address (void *cls, const struct GNUNET_PeerIdentity *peer,
569 rc->printed = GNUNET_NO; 633 rc->printed = GNUNET_NO;
570 634
571 GNUNET_assert (NULL != rc); 635 GNUNET_assert (NULL != rc);
572 636 address_resolutions ++;
637 FPRINTF (stdout, _("Peer `%s' ++: %u\n"), GNUNET_i2s (peer), address_resolutions);
573 /* Resolve address to string */ 638 /* Resolve address to string */
574 GNUNET_TRANSPORT_address_to_string (cfg, address, numeric, 639 GNUNET_TRANSPORT_address_to_string (cfg, address, numeric,
575 RESOLUTION_TIMEOUT, &process_string, 640 RESOLUTION_TIMEOUT, &process_string,
@@ -577,40 +642,12 @@ process_address (void *cls, const struct GNUNET_PeerIdentity *peer,
577} 642}
578 643
579 644
580/**
581 * Task run in monitor mode when the user presses CTRL-C to abort.
582 * Stops monitoring activity.
583 *
584 * @param cls the 'struct GNUNET_TRANSPORT_PeerIterateContext *'
585 * @param tc scheduler context
586 */
587static void
588shutdown_task (void *cls,
589 const struct GNUNET_SCHEDULER_TaskContext *tc)
590{
591 if (NULL != th)
592 {
593 GNUNET_TRANSPORT_notify_transmit_ready_cancel(th);
594 th = NULL;
595 }
596 if (NULL != handle)
597 {
598 GNUNET_TRANSPORT_disconnect(handle);
599 handle = NULL;
600 }
601
602 if (NULL != peers)
603 {
604 GNUNET_CONTAINER_multihashmap_destroy (peers);
605 peers = NULL;
606 }
607}
608
609static void 645static void
610testservice_task (void *cls, 646testservice_task (void *cls,
611 const struct GNUNET_SCHEDULER_TaskContext *tc) 647 const struct GNUNET_SCHEDULER_TaskContext *tc)
612{ 648{
613 struct GNUNET_CONFIGURATION_Handle *cfg = cls; 649 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
650 int counter = 0;
614 651
615 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) 652 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
616 { 653 {
@@ -618,31 +655,49 @@ testservice_task (void *cls,
618 return; 655 return;
619 } 656 }
620 657
621 if (benchmark_send && (NULL == cpid)) 658 counter = benchmark_send + benchmark_receive + iterate_connections +
659 monitor_connections + monitor_connects;
660
661 if (1 < counter)
622 { 662 {
623 FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"), 663 FPRINTF (stderr, _("Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s\n"),
624 "-s", "-C"); 664 "benchmark send", "benchmark receive", "information", "monitor", "events");
625 return; 665 return;
626 } 666 }
627 if (NULL != cpid) 667 if (0 == counter)
628 { 668 {
669 FPRINTF (stderr, _("No operation given. Please choose one operation: %s, %s, %s, %s, %s\n"),
670 "benchmark send", "benchmark receive", "information", "monitor", "events");
671 return;
672 }
673
674
675 if (benchmark_send) /* Benchmark sending */
676 {
677 if (NULL == cpid)
678 {
679 FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
680 "-s", "-C");
681 return;
682 }
629 ret = 1; 683 ret = 1;
630 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (cpid, &pid.hashPubKey)) 684 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (cpid, &pid.hashPubKey))
631 { 685 {
632 FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), cpid); 686 FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), cpid);
633 return; 687 return;
634 } 688 }
635 handle = 689 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL,
636 GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive, 690 &notify_receive,
637 &notify_connect, &notify_disconnect); 691 &notify_connect,
692 &notify_disconnect);
638 GNUNET_TRANSPORT_try_connect (handle, &pid); 693 GNUNET_TRANSPORT_try_connect (handle, &pid);
639 end = 694 end = GNUNET_SCHEDULER_add_delayed (benchmark_send ?
640 GNUNET_SCHEDULER_add_delayed (benchmark_send ? 695 GNUNET_TIME_UNIT_FOREVER_REL :
641 GNUNET_TIME_UNIT_FOREVER_REL : 696 GNUNET_TIME_UNIT_SECONDS,
642 GNUNET_TIME_UNIT_SECONDS, &do_disconnect, 697 &do_disconnect,
643 NULL); 698 NULL);
644 } 699 }
645 else if (benchmark_receive) 700 else if (benchmark_receive) /* Benchmark receiving */
646 { 701 {
647 handle = 702 handle =
648 GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive, 703 GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive,
@@ -653,32 +708,45 @@ testservice_task (void *cls,
653 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 708 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
654 &do_disconnect, NULL); 709 &do_disconnect, NULL);
655 } 710 }
656 if (iterate_connections) 711 else if (iterate_connections) /* List all active addresses once */
712 {
713 peers = GNUNET_CONTAINER_multihashmap_create (20, GNUNET_NO);
714 address_resolution_in_progress = GNUNET_YES;
715 pic = GNUNET_TRANSPORT_peer_get_active_addresses (cfg, NULL,
716 GNUNET_NO,
717 TIMEOUT,
718 &process_address, (void *) cfg);
719 }
720 else if (monitor_connections) /* List all active addresses continously */
657 { 721 {
658 peers = GNUNET_CONTAINER_multihashmap_create (20, GNUNET_NO); 722 peers = GNUNET_CONTAINER_multihashmap_create (20, GNUNET_NO);
659 GNUNET_TRANSPORT_peer_get_active_addresses (cfg, NULL, GNUNET_YES, 723 address_resolution_in_progress = GNUNET_YES;
724 pic = GNUNET_TRANSPORT_peer_get_active_addresses (cfg, NULL,
725 GNUNET_YES,
660 TIMEOUT, 726 TIMEOUT,
661 &process_address, (void *) cfg); 727 &process_address, (void *) cfg);
662 } 728 }
663 if (monitor_connections) 729 else if (monitor_connects) /* Monitor (dis)connect events continously */
664 { 730 {
665 monitor_connections_counter = 0; 731 monitor_connect_counter = 0;
666 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, 732 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL,
667 &monitor_notify_connect, 733 &monitor_notify_connect,
668 &monitor_notify_disconnect); 734 &monitor_notify_disconnect);
669 if (NULL == handle) 735 if (NULL == handle)
670 { 736 {
671 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 737 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
672 } 738 return;
673 else
674 {
675 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
676 &shutdown_task,
677 NULL);
678 } 739 }
679 } 740 }
741 else
742 {
743 GNUNET_break (0)
744 return;
745 }
680 746
681 747 end = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
748 &shutdown_task,
749 NULL);
682} 750}
683 751
684 752
@@ -723,6 +791,9 @@ main (int argc, char *const *argv)
723 {'m', "monitor", NULL, 791 {'m', "monitor", NULL,
724 gettext_noop ("provide information about all current connections (continuously)"), 792 gettext_noop ("provide information about all current connections (continuously)"),
725 0, &GNUNET_GETOPT_set_one, &monitor_connections}, 793 0, &GNUNET_GETOPT_set_one, &monitor_connections},
794 {'e', "events", NULL,
795 gettext_noop ("provide information about all connects and disconnect events (continuously)"),
796 0, &GNUNET_GETOPT_set_one, &monitor_connects},
726 {'n', "numeric", NULL, 797 {'n', "numeric", NULL,
727 gettext_noop ("do not resolve hostnames"), 798 gettext_noop ("do not resolve hostnames"),
728 0, &GNUNET_GETOPT_set_one, &numeric}, 799 0, &GNUNET_GETOPT_set_one, &numeric},