diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-11-09 16:14:20 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-11-09 16:14:20 +0000 |
commit | 7dcb3d8558f23a197b357874917c66cfe9d9cca4 (patch) | |
tree | ef7032550d6df86bd9396d57ec990cfd1ef9c8a7 /src/testbed | |
parent | f9a99e68470c769411a1e3851838b4b18a6ce5f8 (diff) | |
download | gnunet-7dcb3d8558f23a197b357874917c66cfe9d9cca4.tar.gz gnunet-7dcb3d8558f23a197b357874917c66cfe9d9cca4.zip |
-fixes
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/gnunet-service-testbed.c | 99 | ||||
-rw-r--r-- | src/testbed/test_testbed_api_test.c | 97 |
2 files changed, 150 insertions, 46 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index 452fb764c..cab910a37 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c | |||
@@ -545,6 +545,16 @@ struct OverlayConnectContext | |||
545 | struct GNUNET_TRANSPORT_GetHelloHandle *ghh; | 545 | struct GNUNET_TRANSPORT_GetHelloHandle *ghh; |
546 | 546 | ||
547 | /** | 547 | /** |
548 | * The handle for offering HELLO | ||
549 | */ | ||
550 | struct GNUNET_TRANSPORT_OfferHelloHandle *ohh; | ||
551 | |||
552 | /** | ||
553 | * The handle for transport try connect | ||
554 | */ | ||
555 | struct GNUNET_TRANSPORT_TryConnectHandle *tch; | ||
556 | |||
557 | /** | ||
548 | * The error message we send if this overlay connect operation has timed out | 558 | * The error message we send if this overlay connect operation has timed out |
549 | */ | 559 | */ |
550 | char *emsg; | 560 | char *emsg; |
@@ -2730,6 +2740,10 @@ cleanup_occ (struct OverlayConnectContext *occ) | |||
2730 | } | 2740 | } |
2731 | if (NULL != occ->ghh) | 2741 | if (NULL != occ->ghh) |
2732 | GNUNET_TRANSPORT_get_hello_cancel (occ->ghh); | 2742 | GNUNET_TRANSPORT_get_hello_cancel (occ->ghh); |
2743 | if (NULL != occ->ohh) | ||
2744 | GNUNET_TRANSPORT_offer_hello_cancel (occ->ohh); | ||
2745 | if (NULL != occ->tch) | ||
2746 | GNUNET_TRANSPORT_try_connect_cancel (occ->tch); | ||
2733 | if (NULL != occ->p1th) | 2747 | if (NULL != occ->p1th) |
2734 | { | 2748 | { |
2735 | GNUNET_TRANSPORT_disconnect (occ->p1th); | 2749 | GNUNET_TRANSPORT_disconnect (occ->p1th); |
@@ -2862,6 +2876,31 @@ overlay_connect_notify (void *cls, const struct GNUNET_PeerIdentity *new_peer, | |||
2862 | 2876 | ||
2863 | 2877 | ||
2864 | /** | 2878 | /** |
2879 | * Callback to be called with result of the try connect request. | ||
2880 | * | ||
2881 | * @param cls the overlay connect context | ||
2882 | * @param result GNUNET_OK if message was transmitted to transport service | ||
2883 | * GNUNET_SYSERR if message was not transmitted to transport service | ||
2884 | */ | ||
2885 | static void | ||
2886 | try_connect_cb (void *cls, const int result) | ||
2887 | { | ||
2888 | struct OverlayConnectContext *occ = cls; | ||
2889 | |||
2890 | occ->tch = NULL; | ||
2891 | if (GNUNET_OK == result) | ||
2892 | { | ||
2893 | GNUNET_free_non_null (occ->emsg); | ||
2894 | occ->emsg = GNUNET_strdup ("Waiting for transport to connect"); | ||
2895 | //return; FIXME: should return here | ||
2896 | } | ||
2897 | // GNUNET_break (0); | ||
2898 | occ->tch = GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity, | ||
2899 | &try_connect_cb, occ); | ||
2900 | } | ||
2901 | |||
2902 | |||
2903 | /** | ||
2865 | * Task to offer HELLO of peer 1 to peer 2 and try to make peer 2 to connect to | 2904 | * Task to offer HELLO of peer 1 to peer 2 and try to make peer 2 to connect to |
2866 | * peer 1. | 2905 | * peer 1. |
2867 | * | 2906 | * |
@@ -2880,31 +2919,34 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | |||
2880 | * GNUNET_SCHEDULER_REASON_TIMEOUT then sending HELLO failed; if | 2919 | * GNUNET_SCHEDULER_REASON_TIMEOUT then sending HELLO failed; if |
2881 | * GNUNET_SCHEDULER_REASON_READ_READY is succeeded | 2920 | * GNUNET_SCHEDULER_REASON_READ_READY is succeeded |
2882 | */ | 2921 | */ |
2883 | //static FIXME: uncomment when using | 2922 | static void |
2884 | void | ||
2885 | occ_hello_sent_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 2923 | occ_hello_sent_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
2886 | { | 2924 | { |
2887 | struct OverlayConnectContext *occ = cls; | 2925 | struct OverlayConnectContext *occ = cls; |
2888 | int ret; | ||
2889 | 2926 | ||
2927 | occ->ohh = NULL; | ||
2890 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == occ->send_hello_task); | 2928 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == occ->send_hello_task); |
2891 | if (GNUNET_SCHEDULER_REASON_TIMEOUT == tc->reason) | 2929 | if (GNUNET_SCHEDULER_REASON_TIMEOUT == tc->reason) |
2892 | { | 2930 | { |
2893 | occ->send_hello_task = | 2931 | GNUNET_break (0); |
2894 | GNUNET_SCHEDULER_add_delayed | 2932 | goto schedule_send_hello; |
2895 | (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | ||
2896 | 100 + GNUNET_CRYPTO_random_u32 | ||
2897 | (GNUNET_CRYPTO_QUALITY_WEAK, 500)), | ||
2898 | &send_hello, occ); | ||
2899 | return; | ||
2900 | } | 2933 | } |
2901 | if (GNUNET_SCHEDULER_REASON_READ_READY != tc->reason) | 2934 | if (GNUNET_SCHEDULER_REASON_READ_READY != tc->reason) |
2935 | { | ||
2936 | GNUNET_break (0); | ||
2902 | return; | 2937 | return; |
2903 | ret = GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity, NULL, NULL); /*FIXME TRY_CONNECT change */ | 2938 | } |
2904 | if (GNUNET_OK == ret) | 2939 | GNUNET_free_non_null (occ->emsg); |
2940 | occ->emsg = GNUNET_strdup ("Timeout while try connect\n"); | ||
2941 | occ->tch = GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity, | ||
2942 | &try_connect_cb, occ); | ||
2943 | if (NULL != occ->tch) | ||
2905 | return; | 2944 | return; |
2906 | if (GNUNET_SYSERR == ret) | 2945 | GNUNET_break (0); |
2907 | GNUNET_break (0); | 2946 | |
2947 | schedule_send_hello: | ||
2948 | GNUNET_free_non_null (occ->emsg); | ||
2949 | occ->emsg = GNUNET_strdup ("Timeout while offering HELLO to other peer"); | ||
2908 | occ->send_hello_task = | 2950 | occ->send_hello_task = |
2909 | GNUNET_SCHEDULER_add_delayed | 2951 | GNUNET_SCHEDULER_add_delayed |
2910 | (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 2952 | (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, |
@@ -2956,21 +2998,20 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2956 | { | 2998 | { |
2957 | LOG_DEBUG ("Offering HELLO of %s to %s\n", | 2999 | LOG_DEBUG ("Offering HELLO of %s to %s\n", |
2958 | GNUNET_i2s (&occ->peer_identity), other_peer_str); | 3000 | GNUNET_i2s (&occ->peer_identity), other_peer_str); |
2959 | /* FIXME: To be replaced by */ | 3001 | occ->ohh = GNUNET_TRANSPORT_offer_hello (occ->p2th, |
2960 | /* occ->offer_hello_handle = GNUNET_TRANSPORT_offer_hello (occ->p2th, */ | 3002 | occ->hello, |
2961 | /* occ->hello, */ | 3003 | occ_hello_sent_cb, |
2962 | /* occ_hello_sent_cb, */ | 3004 | occ); |
2963 | /* occ); */ | 3005 | if (NULL == occ->ohh) |
2964 | 3006 | { | |
2965 | /* FIXME: once offer_hello offers a handle to cancel remove the following lines */ | 3007 | GNUNET_break (0); |
2966 | GNUNET_TRANSPORT_offer_hello (occ->p2th, occ->hello, NULL, NULL); | 3008 | occ->send_hello_task = |
2967 | GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity, NULL, NULL); /*FIXME TRY_CONNECT change */ | 3009 | GNUNET_SCHEDULER_add_delayed |
2968 | occ->send_hello_task = | 3010 | (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, |
2969 | GNUNET_SCHEDULER_add_delayed | 3011 | 100 + GNUNET_CRYPTO_random_u32 |
2970 | (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 3012 | (GNUNET_CRYPTO_QUALITY_WEAK, 500)), |
2971 | 100 + GNUNET_CRYPTO_random_u32 | 3013 | &send_hello, occ); |
2972 | (GNUNET_CRYPTO_QUALITY_WEAK, 500)), | 3014 | } |
2973 | &send_hello, occ); | ||
2974 | } | 3015 | } |
2975 | GNUNET_free (other_peer_str); | 3016 | GNUNET_free (other_peer_str); |
2976 | } | 3017 | } |
diff --git a/src/testbed/test_testbed_api_test.c b/src/testbed/test_testbed_api_test.c index e93c5872a..1738c0a98 100644 --- a/src/testbed/test_testbed_api_test.c +++ b/src/testbed/test_testbed_api_test.c | |||
@@ -28,6 +28,13 @@ | |||
28 | #include "gnunet_common.h" | 28 | #include "gnunet_common.h" |
29 | #include "gnunet_testbed_service.h" | 29 | #include "gnunet_testbed_service.h" |
30 | 30 | ||
31 | |||
32 | /** | ||
33 | * Generic logging shortcut | ||
34 | */ | ||
35 | #define LOG(kind,...) \ | ||
36 | GNUNET_log (kind, __VA_ARGS__) | ||
37 | |||
31 | /** | 38 | /** |
32 | * Number of peers we want to start | 39 | * Number of peers we want to start |
33 | */ | 40 | */ |
@@ -44,6 +51,16 @@ static struct GNUNET_TESTBED_Peer **peers; | |||
44 | static struct GNUNET_TESTBED_Operation *op; | 51 | static struct GNUNET_TESTBED_Operation *op; |
45 | 52 | ||
46 | /** | 53 | /** |
54 | * Abort task identifier | ||
55 | */ | ||
56 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; | ||
57 | |||
58 | /** | ||
59 | * shutdown task identifier | ||
60 | */ | ||
61 | static GNUNET_SCHEDULER_TaskIdentifier shutdown_task; | ||
62 | |||
63 | /** | ||
47 | * Testing result | 64 | * Testing result |
48 | */ | 65 | */ |
49 | static int result; | 66 | static int result; |
@@ -57,10 +74,47 @@ static int result; | |||
57 | */ | 74 | */ |
58 | static void | 75 | static void |
59 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 76 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
60 | { | 77 | { |
78 | shutdown_task = GNUNET_SCHEDULER_NO_TASK; | ||
79 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) | ||
80 | GNUNET_SCHEDULER_cancel (abort_task); | ||
81 | if (NULL != op) | ||
82 | GNUNET_TESTBED_operation_done (op); | ||
61 | GNUNET_SCHEDULER_shutdown (); | 83 | GNUNET_SCHEDULER_shutdown (); |
62 | } | 84 | } |
63 | 85 | ||
86 | /** | ||
87 | * shortcut to exit during failure | ||
88 | */ | ||
89 | #define FAIL_TEST(cond) do { \ | ||
90 | if (!(cond)) { \ | ||
91 | GNUNET_break(0); \ | ||
92 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) \ | ||
93 | GNUNET_SCHEDULER_cancel (abort_task); \ | ||
94 | abort_task = GNUNET_SCHEDULER_NO_TASK; \ | ||
95 | if (GNUNET_SCHEDULER_NO_TASK == shutdown_task) \ | ||
96 | shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL); \ | ||
97 | return; \ | ||
98 | } \ | ||
99 | } while (0) | ||
100 | |||
101 | |||
102 | /** | ||
103 | * abort task to run on test timed out | ||
104 | * | ||
105 | * @param cls NULL | ||
106 | * @param tc the task context | ||
107 | */ | ||
108 | static void | ||
109 | do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
110 | { | ||
111 | LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); | ||
112 | abort_task = GNUNET_SCHEDULER_NO_TASK; | ||
113 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) | ||
114 | GNUNET_SCHEDULER_cancel (shutdown_task); | ||
115 | shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL); | ||
116 | } | ||
117 | |||
64 | 118 | ||
65 | /** | 119 | /** |
66 | * Callback to be called when the requested peer information is available | 120 | * Callback to be called when the requested peer information is available |
@@ -76,14 +130,15 @@ peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_, | |||
76 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | 130 | const struct GNUNET_TESTBED_PeerInformation *pinfo, |
77 | const char *emsg) | 131 | const char *emsg) |
78 | { | 132 | { |
79 | GNUNET_assert (op == op_); | 133 | FAIL_TEST (op == op_); |
80 | GNUNET_assert (NULL == cb_cls); | 134 | FAIL_TEST (NULL == cb_cls); |
81 | GNUNET_assert (NULL == emsg); | 135 | FAIL_TEST (NULL == emsg); |
82 | GNUNET_assert (GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit); | 136 | FAIL_TEST (GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit); |
83 | GNUNET_assert (NULL != pinfo->result.id); | 137 | FAIL_TEST (NULL != pinfo->result.id); |
84 | GNUNET_TESTBED_operation_done (op); | 138 | GNUNET_TESTBED_operation_done (op); |
139 | op = NULL; | ||
85 | result = GNUNET_OK; | 140 | result = GNUNET_OK; |
86 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 141 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
87 | } | 142 | } |
88 | 143 | ||
89 | 144 | ||
@@ -98,9 +153,13 @@ peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_, | |||
98 | static void | 153 | static void |
99 | op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg) | 154 | op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg) |
100 | { | 155 | { |
101 | GNUNET_assert (NULL == cls); | 156 | FAIL_TEST (NULL == cls); |
102 | GNUNET_assert (op == op_); | 157 | FAIL_TEST (op == op_); |
103 | GNUNET_assert (NULL == emsg); | 158 | if (NULL != emsg) |
159 | { | ||
160 | LOG (GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg); | ||
161 | FAIL_TEST (0); | ||
162 | } | ||
104 | GNUNET_TESTBED_operation_done (op); | 163 | GNUNET_TESTBED_operation_done (op); |
105 | op = GNUNET_TESTBED_peer_get_information (peers[0], | 164 | op = GNUNET_TESTBED_peer_get_information (peers[0], |
106 | GNUNET_TESTBED_PIT_IDENTITY, | 165 | GNUNET_TESTBED_PIT_IDENTITY, |
@@ -121,11 +180,11 @@ controller_event_cb (void *cls, | |||
121 | switch (event->type) | 180 | switch (event->type) |
122 | { | 181 | { |
123 | case GNUNET_TESTBED_ET_CONNECT: | 182 | case GNUNET_TESTBED_ET_CONNECT: |
124 | GNUNET_assert (event->details.peer_connect.peer1 == peers[0]); | 183 | FAIL_TEST (event->details.peer_connect.peer1 == peers[0]); |
125 | GNUNET_assert (event->details.peer_connect.peer2 == peers[1]); | 184 | FAIL_TEST (event->details.peer_connect.peer2 == peers[1]); |
126 | break; | 185 | break; |
127 | default: | 186 | default: |
128 | GNUNET_assert (0); | 187 | FAIL_TEST (0); |
129 | } | 188 | } |
130 | } | 189 | } |
131 | 190 | ||
@@ -143,13 +202,17 @@ test_master (void *cls, unsigned int num_peers, | |||
143 | { | 202 | { |
144 | unsigned int peer; | 203 | unsigned int peer; |
145 | 204 | ||
146 | GNUNET_assert (NULL == cls); | 205 | FAIL_TEST (NULL == cls); |
147 | GNUNET_assert (NUM_PEERS == num_peers); | 206 | FAIL_TEST (NUM_PEERS == num_peers); |
148 | GNUNET_assert (NULL != peers_); | 207 | FAIL_TEST (NULL != peers_); |
149 | for (peer = 0; peer < num_peers; peer++) | 208 | for (peer = 0; peer < num_peers; peer++) |
150 | GNUNET_assert (NULL != peers_[peer]); | 209 | FAIL_TEST (NULL != peers_[peer]); |
151 | peers = peers_; | 210 | peers = peers_; |
152 | op = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peers[0], peers[1]); | 211 | op = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peers[0], peers[1]); |
212 | abort_task = | ||
213 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
214 | (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort, | ||
215 | NULL); | ||
153 | } | 216 | } |
154 | 217 | ||
155 | 218 | ||