diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-11-14 12:18:55 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-11-14 12:18:55 +0000 |
commit | 3ef866edf0f125c2befa26863fa9fad1fd8febda (patch) | |
tree | e99fe8bd4a506f27940702a445a8833a7703543d | |
parent | 6884e874ab4d23f8a0d9b2cc1f3a1794e606cdeb (diff) | |
download | gnunet-3ef866edf0f125c2befa26863fa9fad1fd8febda.tar.gz gnunet-3ef866edf0f125c2befa26863fa9fad1fd8febda.zip |
- try connect as task
-rw-r--r-- | src/testbed/gnunet-service-testbed.c | 119 |
1 files changed, 88 insertions, 31 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index cf1e3ce48..18709b5db 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c | |||
@@ -495,6 +495,39 @@ struct Peer | |||
495 | 495 | ||
496 | 496 | ||
497 | /** | 497 | /** |
498 | * Context information for transport try connect | ||
499 | */ | ||
500 | struct TryConnectContext | ||
501 | { | ||
502 | /** | ||
503 | * The identity of the peer to which the transport has to attempt a connection | ||
504 | */ | ||
505 | struct GNUNET_PeerIdentity *pid; | ||
506 | |||
507 | /** | ||
508 | * The transport handle | ||
509 | */ | ||
510 | struct GNUNET_TRANSPORT_Handle *th; | ||
511 | |||
512 | /** | ||
513 | * the try connect handle | ||
514 | */ | ||
515 | struct GNUNET_TRANSPORT_TryConnectHandle *tch; | ||
516 | |||
517 | /** | ||
518 | * The task handle | ||
519 | */ | ||
520 | GNUNET_SCHEDULER_TaskIdentifier task; | ||
521 | |||
522 | /** | ||
523 | * The number of times we attempted to connect | ||
524 | */ | ||
525 | unsigned int retries; | ||
526 | |||
527 | }; | ||
528 | |||
529 | |||
530 | /** | ||
498 | * Context information for connecting 2 peers in overlay | 531 | * Context information for connecting 2 peers in overlay |
499 | */ | 532 | */ |
500 | struct OverlayConnectContext | 533 | struct OverlayConnectContext |
@@ -550,11 +583,6 @@ struct OverlayConnectContext | |||
550 | struct GNUNET_TRANSPORT_OfferHelloHandle *ohh; | 583 | struct GNUNET_TRANSPORT_OfferHelloHandle *ohh; |
551 | 584 | ||
552 | /** | 585 | /** |
553 | * The handle for transport try connect | ||
554 | */ | ||
555 | struct GNUNET_TRANSPORT_TryConnectHandle *tch; | ||
556 | |||
557 | /** | ||
558 | * The error message we send if this overlay connect operation has timed out | 586 | * The error message we send if this overlay connect operation has timed out |
559 | */ | 587 | */ |
560 | char *emsg; | 588 | char *emsg; |
@@ -570,6 +598,11 @@ struct OverlayConnectContext | |||
570 | struct GNUNET_TESTBED_Controller *peer2_controller; | 598 | struct GNUNET_TESTBED_Controller *peer2_controller; |
571 | 599 | ||
572 | /** | 600 | /** |
601 | * The transport try connect context | ||
602 | */ | ||
603 | struct TryConnectContext tcc; | ||
604 | |||
605 | /** | ||
573 | * The peer identity of the first peer | 606 | * The peer identity of the first peer |
574 | */ | 607 | */ |
575 | struct GNUNET_PeerIdentity peer_identity; | 608 | struct GNUNET_PeerIdentity peer_identity; |
@@ -2752,8 +2785,10 @@ cleanup_occ (struct OverlayConnectContext *occ) | |||
2752 | GNUNET_TRANSPORT_get_hello_cancel (occ->ghh); | 2785 | GNUNET_TRANSPORT_get_hello_cancel (occ->ghh); |
2753 | if (NULL != occ->ohh) | 2786 | if (NULL != occ->ohh) |
2754 | GNUNET_TRANSPORT_offer_hello_cancel (occ->ohh); | 2787 | GNUNET_TRANSPORT_offer_hello_cancel (occ->ohh); |
2755 | if (NULL != occ->tch) | 2788 | if (GNUNET_SCHEDULER_NO_TASK != occ->tcc.task) |
2756 | GNUNET_TRANSPORT_try_connect_cancel (occ->tch); | 2789 | GNUNET_SCHEDULER_cancel (occ->tcc.task); |
2790 | if (NULL != occ->tcc.tch) | ||
2791 | GNUNET_TRANSPORT_try_connect_cancel (occ->tcc.tch); | ||
2757 | if (NULL != occ->p1th) | 2792 | if (NULL != occ->p1th) |
2758 | { | 2793 | { |
2759 | GNUNET_TRANSPORT_disconnect (occ->p1th); | 2794 | GNUNET_TRANSPORT_disconnect (occ->p1th); |
@@ -2886,6 +2921,16 @@ overlay_connect_notify (void *cls, const struct GNUNET_PeerIdentity *new_peer, | |||
2886 | 2921 | ||
2887 | 2922 | ||
2888 | /** | 2923 | /** |
2924 | * Task to ask transport of a peer to connect to another peer | ||
2925 | * | ||
2926 | * @param cls the TryConnectContext | ||
2927 | * @param tc the scheduler task context | ||
2928 | */ | ||
2929 | static void | ||
2930 | try_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
2931 | |||
2932 | |||
2933 | /** | ||
2889 | * Callback to be called with result of the try connect request. | 2934 | * Callback to be called with result of the try connect request. |
2890 | * | 2935 | * |
2891 | * @param cls the overlay connect context | 2936 | * @param cls the overlay connect context |
@@ -2895,18 +2940,35 @@ overlay_connect_notify (void *cls, const struct GNUNET_PeerIdentity *new_peer, | |||
2895 | static void | 2940 | static void |
2896 | try_connect_cb (void *cls, const int result) | 2941 | try_connect_cb (void *cls, const int result) |
2897 | { | 2942 | { |
2898 | struct OverlayConnectContext *occ = cls; | 2943 | struct TryConnectContext *tcc = cls; |
2899 | 2944 | ||
2900 | occ->tch = NULL; | 2945 | tcc->tch = NULL; |
2901 | if (GNUNET_OK == result) | 2946 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == tcc->task); |
2902 | { | 2947 | tcc->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
2903 | GNUNET_free_non_null (occ->emsg); | 2948 | (GNUNET_TIME_UNIT_MILLISECONDS, |
2904 | occ->emsg = GNUNET_strdup ("Waiting for transport to connect"); | 2949 | pow (10, ++tcc->retries)), |
2905 | //return; FIXME: should return here | 2950 | &try_connect_task, tcc); |
2906 | } | 2951 | } |
2907 | // GNUNET_break (0); | 2952 | |
2908 | occ->tch = GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity, | 2953 | |
2909 | &try_connect_cb, occ); | 2954 | /** |
2955 | * Task to ask transport of a peer to connect to another peer | ||
2956 | * | ||
2957 | * @param cls the TryConnectContext | ||
2958 | * @param tc the scheduler task context | ||
2959 | */ | ||
2960 | static void | ||
2961 | try_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
2962 | { | ||
2963 | struct TryConnectContext *tcc = cls; | ||
2964 | |||
2965 | tcc->task = GNUNET_SCHEDULER_NO_TASK; | ||
2966 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) | ||
2967 | return; | ||
2968 | GNUNET_assert (NULL == tcc->tch); | ||
2969 | GNUNET_assert (NULL != tcc->pid); | ||
2970 | GNUNET_assert (NULL != tcc->th); | ||
2971 | tcc->tch = GNUNET_TRANSPORT_try_connect (tcc->th, tcc->pid, &try_connect_cb, tcc); | ||
2910 | } | 2972 | } |
2911 | 2973 | ||
2912 | 2974 | ||
@@ -2938,23 +3000,18 @@ occ_hello_sent_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2938 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == occ->send_hello_task); | 3000 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == occ->send_hello_task); |
2939 | if (GNUNET_SCHEDULER_REASON_TIMEOUT == tc->reason) | 3001 | if (GNUNET_SCHEDULER_REASON_TIMEOUT == tc->reason) |
2940 | { | 3002 | { |
2941 | //GNUNET_break (0); | 3003 | GNUNET_free_non_null (occ->emsg); |
2942 | goto schedule_send_hello; | 3004 | occ->emsg = GNUNET_strdup ("Timeout while offering HELLO to other peer"); |
3005 | occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ); | ||
3006 | return; | ||
2943 | } | 3007 | } |
2944 | if (GNUNET_SCHEDULER_REASON_READ_READY != tc->reason) | 3008 | if (GNUNET_SCHEDULER_REASON_READ_READY != tc->reason) |
2945 | return; | 3009 | return; |
2946 | GNUNET_free_non_null (occ->emsg); | 3010 | GNUNET_free_non_null (occ->emsg); |
2947 | occ->emsg = GNUNET_strdup ("Timeout while try connect\n"); | 3011 | occ->emsg = GNUNET_strdup ("Timeout while try connect\n"); |
2948 | occ->tch = GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity, | 3012 | occ->tcc.pid = &occ->peer_identity; |
2949 | &try_connect_cb, occ); | 3013 | occ->tcc.th = occ->p2th; |
2950 | if (NULL != occ->tch) | 3014 | occ->tcc.task = GNUNET_SCHEDULER_add_now (&try_connect_task, &occ->tcc); |
2951 | return; | ||
2952 | GNUNET_break (0); | ||
2953 | |||
2954 | schedule_send_hello: | ||
2955 | GNUNET_free_non_null (occ->emsg); | ||
2956 | occ->emsg = GNUNET_strdup ("Timeout while offering HELLO to other peer"); | ||
2957 | occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ); | ||
2958 | } | 3015 | } |
2959 | 3016 | ||
2960 | 3017 | ||