diff options
Diffstat (limited to 'src/transport/test_transport_api.c')
-rw-r--r-- | src/transport/test_transport_api.c | 190 |
1 files changed, 140 insertions, 50 deletions
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c index c9068c47a..49e160ddb 100644 --- a/src/transport/test_transport_api.c +++ b/src/transport/test_transport_api.c | |||
@@ -75,6 +75,8 @@ static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; | |||
75 | 75 | ||
76 | struct GNUNET_TRANSPORT_TransmitHandle *th; | 76 | struct GNUNET_TRANSPORT_TransmitHandle *th; |
77 | 77 | ||
78 | struct TransportTestingHandle * tth; | ||
79 | |||
78 | char *cfg_file_p1; | 80 | char *cfg_file_p1; |
79 | 81 | ||
80 | char *cfg_file_p2; | 82 | char *cfg_file_p2; |
@@ -90,7 +92,55 @@ static void | |||
90 | end () | 92 | end () |
91 | { | 93 | { |
92 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); | 94 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); |
95 | #if 0 | ||
96 | static void | ||
97 | get_hello_p2 (void *cb_cls, const struct GNUNET_MessageHeader *message); | ||
98 | |||
99 | static void | ||
100 | get_hello_p1 (void *cb_cls, const struct GNUNET_MessageHeader *message); | ||
101 | |||
102 | static void | ||
103 | notify_connect_internal (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
104 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | ||
105 | uint32_t ats_count) | ||
106 | { | ||
107 | struct ConnectingContext *cc = cls; | ||
108 | |||
109 | GNUNET_assert (cc != NULL); | ||
110 | |||
111 | if (0 == | ||
112 | memcmp (&(*peer).hashPubKey, &cc->p1->id.hashPubKey, | ||
113 | sizeof (GNUNET_HashCode))) | ||
114 | { | ||
115 | if (cc->p1_c == GNUNET_NO) | ||
116 | cc->p1_c = GNUNET_YES; | ||
117 | } | ||
118 | if (0 == | ||
119 | memcmp (&(*peer).hashPubKey, &cc->p2->id.hashPubKey, | ||
120 | sizeof (GNUNET_HashCode))) | ||
121 | { | ||
122 | if (cc->p2_c == GNUNET_NO) | ||
123 | cc->p2_c = GNUNET_YES; | ||
124 | } | ||
93 | 125 | ||
126 | if ((cc->p2_c == GNUNET_YES) && (cc->p2_c == GNUNET_YES)) | ||
127 | { | ||
128 | /* clean up */ | ||
129 | if (cc->tct != GNUNET_SCHEDULER_NO_TASK) | ||
130 | GNUNET_SCHEDULER_cancel (cc->tct); | ||
131 | |||
132 | cc->tct = GNUNET_SCHEDULER_NO_TASK; | ||
133 | |||
134 | GNUNET_TRANSPORT_disconnect (cc->th_p1); | ||
135 | GNUNET_TRANSPORT_disconnect (cc->th_p2); | ||
136 | |||
137 | if (cc->cb != NULL) | ||
138 | cc->cb (cc->p1, cc->p2, cc->cb_cls); | ||
139 | |||
140 | GNUNET_free (cc); | ||
141 | } | ||
142 | } | ||
143 | #endif | ||
94 | if (send_task != GNUNET_SCHEDULER_NO_TASK) | 144 | if (send_task != GNUNET_SCHEDULER_NO_TASK) |
95 | GNUNET_SCHEDULER_cancel (send_task); | 145 | GNUNET_SCHEDULER_cancel (send_task); |
96 | 146 | ||
@@ -101,8 +151,8 @@ end () | |||
101 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 151 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
102 | th = NULL; | 152 | th = NULL; |
103 | 153 | ||
104 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | 154 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); |
105 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | 155 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); |
106 | } | 156 | } |
107 | 157 | ||
108 | static void | 158 | static void |
@@ -112,13 +162,14 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
112 | 162 | ||
113 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); | 163 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); |
114 | 164 | ||
165 | |||
115 | if (send_task != GNUNET_SCHEDULER_NO_TASK) | 166 | if (send_task != GNUNET_SCHEDULER_NO_TASK) |
116 | GNUNET_SCHEDULER_cancel (send_task); | 167 | GNUNET_SCHEDULER_cancel (send_task); |
117 | 168 | ||
118 | if (cc != NULL) | 169 | if (cc != NULL) |
119 | { | 170 | { |
120 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n")); | 171 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n")); |
121 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); | 172 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); |
122 | } | 173 | } |
123 | 174 | ||
124 | if (th != NULL) | 175 | if (th != NULL) |
@@ -126,9 +177,11 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
126 | th = NULL; | 177 | th = NULL; |
127 | 178 | ||
128 | if (p1 != NULL) | 179 | if (p1 != NULL) |
129 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | 180 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); |
130 | if (p2 != NULL) | 181 | if (p2 != NULL) |
131 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | 182 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); |
183 | |||
184 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
132 | 185 | ||
133 | ok = GNUNET_SYSERR; | 186 | ok = GNUNET_SYSERR; |
134 | } | 187 | } |
@@ -141,10 +194,18 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
141 | uint32_t ats_count) | 194 | uint32_t ats_count) |
142 | { | 195 | { |
143 | struct PeerContext * p = cls; | 196 | struct PeerContext * p = cls; |
197 | struct PeerContext *t = NULL; | ||
198 | |||
199 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) | ||
200 | t = p1; | ||
201 | if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) | ||
202 | t = p2; | ||
203 | |||
204 | char * ps = strdup (GNUNET_i2s(&p->id)); | ||
144 | 205 | ||
145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
146 | "Received message of type %d from peer %u (`%4s')!\n", | 207 | "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", |
147 | ntohs (message->type), p->no, GNUNET_i2s (peer)); | 208 | p->no, ps, ntohs (message->type), ntohs (message->size), t->no, GNUNET_i2s (&t->id)); |
148 | 209 | ||
149 | if ((MTYPE == ntohs (message->type)) && | 210 | if ((MTYPE == ntohs (message->type)) && |
150 | (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) | 211 | (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) |
@@ -180,9 +241,6 @@ notify_ready (void *cls, size_t size, void *buf) | |||
180 | return 0; | 241 | return 0; |
181 | } | 242 | } |
182 | 243 | ||
183 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
184 | "Transmitting message with %u bytes to peer %u (%4s)\n", | ||
185 | sizeof (struct GNUNET_MessageHeader), p->no, GNUNET_i2s (&p->id)); | ||
186 | GNUNET_assert (size >= 256); | 244 | GNUNET_assert (size >= 256); |
187 | 245 | ||
188 | if (buf != NULL) | 246 | if (buf != NULL) |
@@ -191,11 +249,17 @@ notify_ready (void *cls, size_t size, void *buf) | |||
191 | hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); | 249 | hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); |
192 | hdr->type = htons (MTYPE); | 250 | hdr->type = htons (MTYPE); |
193 | } | 251 | } |
252 | char * ps = strdup (GNUNET_i2s(&p2->id)); | ||
253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
254 | "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n", | ||
255 | p2->no, | ||
256 | ps, | ||
257 | ntohs (hdr->type), | ||
258 | ntohs (hdr->size), p->no, GNUNET_i2s (&p->id)); | ||
259 | GNUNET_free (ps); | ||
194 | return sizeof (struct GNUNET_MessageHeader); | 260 | return sizeof (struct GNUNET_MessageHeader); |
195 | } | 261 | } |
196 | 262 | ||
197 | struct PeerContext * sender; | ||
198 | struct PeerContext * receiver; | ||
199 | 263 | ||
200 | static void | 264 | static void |
201 | sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 265 | sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
@@ -204,16 +268,16 @@ sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
204 | 268 | ||
205 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 269 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
206 | return; | 270 | return; |
207 | char * receiver_s = strdup(GNUNET_i2s (&receiver->id)); | 271 | char * receiver_s = strdup(GNUNET_i2s (&p1->id)); |
208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
209 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", | 273 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", |
210 | sender->no, | 274 | p2->no, |
211 | GNUNET_i2s (&sender->id), receiver->no, receiver_s); | 275 | GNUNET_i2s (&p2->id), p1->no, receiver_s); |
212 | GNUNET_free (receiver_s); | 276 | GNUNET_free (receiver_s); |
213 | 277 | ||
214 | th = GNUNET_TRANSPORT_notify_transmit_ready (sender->th, &receiver->id, 256, 0, | 278 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256, 0, |
215 | TIMEOUT_TRANSMIT, ¬ify_ready, | 279 | TIMEOUT_TRANSMIT, ¬ify_ready, |
216 | receiver); | 280 | p1); |
217 | } | 281 | } |
218 | 282 | ||
219 | 283 | ||
@@ -225,10 +289,18 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
225 | static int c; | 289 | static int c; |
226 | c++; | 290 | c++; |
227 | struct PeerContext *p = cls; | 291 | struct PeerContext *p = cls; |
228 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') connected to us!\n", | 292 | struct PeerContext *t = NULL; |
229 | p->no, GNUNET_i2s (peer)); | 293 | |
230 | if (c == 2) | 294 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) |
231 | send_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL); | 295 | t = p1; |
296 | if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) | ||
297 | t = p2; | ||
298 | |||
299 | char * ps = strdup (GNUNET_i2s(&p->id)); | ||
300 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", | ||
301 | p->no, ps, | ||
302 | t->no, GNUNET_i2s (peer)); | ||
303 | GNUNET_free (ps); | ||
232 | } | 304 | } |
233 | 305 | ||
234 | 306 | ||
@@ -236,14 +308,15 @@ static void | |||
236 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | 308 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) |
237 | { | 309 | { |
238 | struct PeerContext *p = cls; | 310 | struct PeerContext *p = cls; |
239 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') disconnected!\n", | 311 | char * ps = strdup (GNUNET_i2s(&p->id)); |
240 | p->no, GNUNET_i2s (peer)); | 312 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", |
313 | p->no, ps, GNUNET_i2s (peer)); | ||
314 | |||
241 | if (th != NULL) | 315 | if (th != NULL) |
242 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 316 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
243 | th = NULL; | 317 | th = NULL; |
244 | } | 318 | } |
245 | 319 | ||
246 | |||
247 | static void | 320 | static void |
248 | testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) | 321 | testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) |
249 | { | 322 | { |
@@ -254,6 +327,33 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) | |||
254 | p1->no, p1_c, | 327 | p1->no, p1_c, |
255 | p2->no, GNUNET_i2s (&p2->id)); | 328 | p2->no, GNUNET_i2s (&p2->id)); |
256 | GNUNET_free (p1_c); | 329 | GNUNET_free (p1_c); |
330 | |||
331 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); | ||
332 | } | ||
333 | |||
334 | |||
335 | |||
336 | void start_cb (struct PeerContext * p, | ||
337 | void *cls) | ||
338 | { | ||
339 | static int started; | ||
340 | started++; | ||
341 | |||
342 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", | ||
343 | p->no, | ||
344 | GNUNET_i2s (&p->id)); | ||
345 | |||
346 | if (started != 2) | ||
347 | return; | ||
348 | |||
349 | char *sender_c = strdup (GNUNET_i2s (&p1->id)); | ||
350 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", | ||
351 | p1->no, sender_c, | ||
352 | p2->no, GNUNET_i2s (&p2->id)); | ||
353 | |||
354 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, | ||
355 | NULL); | ||
356 | |||
257 | } | 357 | } |
258 | 358 | ||
259 | static void | 359 | static void |
@@ -262,14 +362,20 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
262 | { | 362 | { |
263 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 363 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
264 | 364 | ||
265 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1, ¬ify_receive, | 365 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, |
266 | ¬ify_connect, ¬ify_disconnect, | 366 | ¬ify_receive, |
367 | ¬ify_connect, | ||
368 | ¬ify_disconnect, | ||
369 | &start_cb, | ||
370 | NULL); | ||
371 | |||
372 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, | ||
373 | ¬ify_receive, | ||
374 | ¬ify_connect, | ||
375 | ¬ify_disconnect, | ||
376 | &start_cb, | ||
267 | NULL); | 377 | NULL); |
268 | p1->no = 1; | 378 | |
269 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2, ¬ify_receive, | ||
270 | ¬ify_connect, ¬ify_disconnect, | ||
271 | NULL); | ||
272 | p2->no = 2; | ||
273 | if ((p1 == NULL) || (p2 == NULL)) | 379 | if ((p1 == NULL) || (p2 == NULL)) |
274 | { | 380 | { |
275 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); | 381 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); |
@@ -278,25 +384,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
278 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 384 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); |
279 | return; | 385 | return; |
280 | } | 386 | } |
281 | |||
282 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u: `%s' using configuration file `%s'\n", | ||
283 | p1->no, | ||
284 | GNUNET_i2s (&p1->id), cfg_file_p1); | ||
285 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u: `%s' using configuration file `%s'\n", | ||
286 | p2->no, | ||
287 | GNUNET_i2s (&p2->id), cfg_file_p2); | ||
288 | |||
289 | sender = p2; | ||
290 | receiver = p1; | ||
291 | |||
292 | char *sender_c = strdup (GNUNET_i2s (&sender->id)); | ||
293 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test triest to send from %u (%s) -> peer %u (%s)\n", | ||
294 | sender->no, sender_c, | ||
295 | receiver->no, GNUNET_i2s (&receiver->id)); | ||
296 | |||
297 | |||
298 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, | ||
299 | NULL); | ||
300 | } | 387 | } |
301 | 388 | ||
302 | 389 | ||
@@ -333,6 +420,8 @@ main (int argc, char *argv[]) | |||
333 | int ret; | 420 | int ret; |
334 | int nat_res; | 421 | int nat_res; |
335 | 422 | ||
423 | tth = GNUNET_TRANSPORT_TESTING_init (); | ||
424 | |||
336 | GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source); | 425 | GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source); |
337 | GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source, | 426 | GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source, |
338 | &test_plugin); | 427 | &test_plugin); |
@@ -376,6 +465,7 @@ main (int argc, char *argv[]) | |||
376 | GNUNET_free (test_plugin); | 465 | GNUNET_free (test_plugin); |
377 | GNUNET_free (test_name); | 466 | GNUNET_free (test_name); |
378 | 467 | ||
468 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
379 | 469 | ||
380 | return ret; | 470 | return ret; |
381 | } | 471 | } |