aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-transport.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-11-08 13:07:53 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-11-08 13:07:53 +0000
commit845e5322aa6b47f9b48fb97964afc43d36701fda (patch)
treeb246134be1ec56958b32d00f890f4c19b699d697 /src/transport/gnunet-transport.c
parentc5b4eaa5e50c1c34f74852ff001772663b0b586a (diff)
downloadgnunet-845e5322aa6b47f9b48fb97964afc43d36701fda.tar.gz
gnunet-845e5322aa6b47f9b48fb97964afc43d36701fda.zip
- working: -i -e -C , todo: -m -s -b
Diffstat (limited to 'src/transport/gnunet-transport.c')
-rw-r--r--src/transport/gnunet-transport.c77
1 files changed, 57 insertions, 20 deletions
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index 312859695..42ca26b74 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -41,6 +41,7 @@
41 */ 41 */
42#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 42#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
43#define RESOLUTION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) 43#define RESOLUTION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
44#define OP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
44 45
45/** 46/**
46 * Which peer should we connect to? 47 * Which peer should we connect to?
@@ -143,6 +144,12 @@ static struct GNUNET_PeerIdentity pid;
143 */ 144 */
144static GNUNET_SCHEDULER_TaskIdentifier end; 145static GNUNET_SCHEDULER_TaskIdentifier end;
145 146
147/**
148 * Task for operation timeout
149 */
150static GNUNET_SCHEDULER_TaskIdentifier op_timeout;
151
152
146static struct GNUNET_CONTAINER_MultiHashMap *peers; 153static struct GNUNET_CONTAINER_MultiHashMap *peers;
147 154
148/** 155/**
@@ -205,6 +212,11 @@ static void
205shutdown_task (void *cls, 212shutdown_task (void *cls,
206 const struct GNUNET_SCHEDULER_TaskContext *tc) 213 const struct GNUNET_SCHEDULER_TaskContext *tc)
207{ 214{
215 if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
216 {
217 GNUNET_SCHEDULER_cancel (op_timeout);
218 op_timeout = GNUNET_SCHEDULER_NO_TASK;
219 }
208 if (NULL != pic) 220 if (NULL != pic)
209 { 221 {
210 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pic); 222 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pic);
@@ -227,6 +239,26 @@ shutdown_task (void *cls,
227 } 239 }
228} 240}
229 241
242
243
244static void
245operation_timeout (void *cls,
246 const struct GNUNET_SCHEDULER_TaskContext *tc)
247{
248 op_timeout = GNUNET_SCHEDULER_NO_TASK;
249 if (try_connect)
250 {
251 FPRINTF (stdout, _("Failed to connect to `%s'\n"), GNUNET_h2s_full (&pid.hashPubKey));
252 if (GNUNET_SCHEDULER_NO_TASK != end)
253 GNUNET_SCHEDULER_cancel (end);
254 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
255 ret = 1;
256 return;
257 }
258}
259
260
261
230/** 262/**
231 * Display the result of the test. 263 * Display the result of the test.
232 * 264 *
@@ -456,24 +488,25 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
456 if (try_connect) 488 if (try_connect)
457 { 489 {
458 /* all done, terminate instantly */ 490 /* all done, terminate instantly */
459 if (verbosity > 0) 491 FPRINTF (stdout, _("Successfully connected to %s\n"), GNUNET_h2s_full (&peer->hashPubKey));
460 FPRINTF (stdout, _("Successfully connected to %s\n"), GNUNET_i2s (peer)); 492 ret = 0;
461 GNUNET_SCHEDULER_cancel (end); 493
494 if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
495 GNUNET_SCHEDULER_cancel (op_timeout);
496
497 if (GNUNET_SCHEDULER_NO_TASK != end)
498 GNUNET_SCHEDULER_cancel (end);
462 end = GNUNET_SCHEDULER_add_now (&do_disconnect, NULL); 499 end = GNUNET_SCHEDULER_add_now (&do_disconnect, NULL);
500 return;
463 } 501 }
464 else if (benchmark_send) 502 if (benchmark_send)
465 { 503 {
466 start_time = GNUNET_TIME_absolute_get (); 504 start_time = GNUNET_TIME_absolute_get ();
467 if (NULL == th) 505 if (NULL == th)
468 th = GNUNET_TRANSPORT_notify_transmit_ready (handle, peer, 32 * 1024, 0, 506 th = GNUNET_TRANSPORT_notify_transmit_ready (handle, peer, 32 * 1024, 0,
469 GNUNET_TIME_UNIT_FOREVER_REL, 507 GNUNET_TIME_UNIT_FOREVER_REL,
470 &transmit_data, NULL); 508 &transmit_data, NULL);
471 } 509 return;
472 else
473 {
474 /* all done, terminate instantly */
475 GNUNET_SCHEDULER_cancel (end);
476 end = GNUNET_SCHEDULER_add_now (&do_disconnect, NULL);
477 } 510 }
478} 511}
479 512
@@ -606,6 +639,7 @@ process_string (void *cls, const char *address)
606 { 639 {
607 if (GNUNET_SCHEDULER_NO_TASK != end) 640 if (GNUNET_SCHEDULER_NO_TASK != end)
608 GNUNET_SCHEDULER_cancel (end); 641 GNUNET_SCHEDULER_cancel (end);
642 ret = 0;
609 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 643 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
610 } 644 }
611 } 645 }
@@ -657,8 +691,7 @@ testservice_task (void *cls,
657{ 691{
658 struct GNUNET_CONFIGURATION_Handle *cfg = cls; 692 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
659 int counter = 0; 693 int counter = 0;
660 int try_connect = 0; 694 ret = 1;
661
662 695
663 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) 696 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
664 { 697 {
@@ -707,10 +740,12 @@ testservice_task (void *cls,
707 if (NULL == handle) 740 if (NULL == handle)
708 { 741 {
709 FPRINTF (stderr, _("Failed to connect to transport service\n")); 742 FPRINTF (stderr, _("Failed to connect to transport service\n"));
743 ret = 1;
710 return; 744 return;
711 } 745 }
712
713 GNUNET_TRANSPORT_try_connect (handle, &pid); 746 GNUNET_TRANSPORT_try_connect (handle, &pid);
747 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
748 &operation_timeout, NULL);
714 749
715 } 750 }
716 else if (benchmark_send) /* Benchmark sending */ 751 else if (benchmark_send) /* Benchmark sending */
@@ -719,9 +754,9 @@ testservice_task (void *cls,
719 { 754 {
720 FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"), 755 FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
721 "-s", "-p"); 756 "-s", "-p");
757 ret = 1;
722 return; 758 return;
723 } 759 }
724 ret = 1;
725 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, 760 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL,
726 &notify_receive, 761 &notify_receive,
727 &notify_connect, 762 &notify_connect,
@@ -729,15 +764,14 @@ testservice_task (void *cls,
729 if (NULL == handle) 764 if (NULL == handle)
730 { 765 {
731 FPRINTF (stderr, _("Failed to connect to transport service\n")); 766 FPRINTF (stderr, _("Failed to connect to transport service\n"));
767 ret = 1;
732 return; 768 return;
733 } 769 }
734 GNUNET_TRANSPORT_try_connect (handle, &pid); 770 GNUNET_TRANSPORT_try_connect (handle, &pid);
735 /* 771
736 end = GNUNET_SCHEDULER_add_delayed (benchmark_send ? 772 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
737 GNUNET_TIME_UNIT_FOREVER_REL : 773 &operation_timeout,
738 GNUNET_TIME_UNIT_SECONDS, 774 NULL);
739 &do_disconnect,
740 NULL);*/
741 } 775 }
742 else if (benchmark_receive) /* Benchmark receiving */ 776 else if (benchmark_receive) /* Benchmark receiving */
743 { 777 {
@@ -747,6 +781,7 @@ testservice_task (void *cls,
747 if (NULL == handle) 781 if (NULL == handle)
748 { 782 {
749 FPRINTF (stderr, _("Failed to connect to transport service\n")); 783 FPRINTF (stderr, _("Failed to connect to transport service\n"));
784 ret = 1;
750 return; 785 return;
751 } 786 }
752 GNUNET_TRANSPORT_try_connect (handle, &pid); 787 GNUNET_TRANSPORT_try_connect (handle, &pid);
@@ -782,8 +817,10 @@ testservice_task (void *cls,
782 if (NULL == handle) 817 if (NULL == handle)
783 { 818 {
784 FPRINTF (stderr, _("Failed to connect to transport service\n")); 819 FPRINTF (stderr, _("Failed to connect to transport service\n"));
820 ret = 1;
785 return; 821 return;
786 } 822 }
823 ret = 0;
787 } 824 }
788 else 825 else
789 { 826 {