diff options
Diffstat (limited to 'src/transport/test_transport_api_reliability.c')
-rw-r--r-- | src/transport/test_transport_api_reliability.c | 718 |
1 files changed, 203 insertions, 515 deletions
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c index 32697e52c..273a69526 100644 --- a/src/transport/test_transport_api_reliability.c +++ b/src/transport/test_transport_api_reliability.c | |||
@@ -58,27 +58,34 @@ | |||
58 | 58 | ||
59 | #define MTYPE 12345 | 59 | #define MTYPE 12345 |
60 | 60 | ||
61 | static struct PeerContext p1; | ||
62 | |||
63 | static struct PeerContext p2; | ||
64 | |||
65 | static int ok; | 61 | static int ok; |
66 | 62 | ||
67 | static int is_tcp; | 63 | static GNUNET_SCHEDULER_TaskIdentifier die_task; |
68 | 64 | ||
69 | static int is_tcp_nat; | 65 | struct PeerContext * p1; |
70 | 66 | ||
71 | static int is_http; | 67 | struct PeerContext * p2; |
72 | 68 | ||
73 | static int is_https; | 69 | struct GNUNET_TRANSPORT_TransmitHandle * th; |
74 | 70 | ||
75 | static int is_udp; | 71 | char * cfg_file_p1; |
76 | 72 | ||
77 | static int is_unix; | 73 | char * cfg_file_p2; |
78 | 74 | ||
79 | static int is_wlan; | 75 | /* |
76 | * Testcase specific declarations | ||
77 | */ | ||
78 | |||
79 | struct TestMessage | ||
80 | { | ||
81 | struct GNUNET_MessageHeader header; | ||
82 | uint32_t num; | ||
83 | }; | ||
80 | 84 | ||
81 | static int connected; | 85 | static int msg_scheduled; |
86 | static int msg_sent; | ||
87 | static int msg_recv_expected; | ||
88 | static int msg_recv; | ||
82 | 89 | ||
83 | static int test_failed; | 90 | static int test_failed; |
84 | 91 | ||
@@ -86,25 +93,9 @@ static unsigned long long total_bytes; | |||
86 | 93 | ||
87 | static struct GNUNET_TIME_Absolute start_time; | 94 | static struct GNUNET_TIME_Absolute start_time; |
88 | 95 | ||
89 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | 96 | /* |
90 | 97 | * END Testcase specific declarations | |
91 | static GNUNET_SCHEDULER_TaskIdentifier tct; | 98 | */ |
92 | |||
93 | struct GNUNET_TRANSPORT_TransmitHandle * th_p2; | ||
94 | |||
95 | static char * key_file_p1; | ||
96 | static char * cert_file_p1; | ||
97 | |||
98 | static char * key_file_p2; | ||
99 | static char * cert_file_p2; | ||
100 | static char *test_name; | ||
101 | static int msg_scheduled; | ||
102 | static int msg_sent; | ||
103 | static int msg_recv_expected; | ||
104 | static int msg_recv; | ||
105 | |||
106 | static int p1_hello_canceled; | ||
107 | static int p2_hello_canceled; | ||
108 | 99 | ||
109 | #if VERBOSE | 100 | #if VERBOSE |
110 | #define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) | 101 | #define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) |
@@ -117,88 +108,46 @@ static void | |||
117 | end () | 108 | end () |
118 | { | 109 | { |
119 | unsigned long long delta; | 110 | unsigned long long delta; |
120 | char *value_name; | 111 | //char *value_name; |
121 | 112 | ||
122 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | 113 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); |
123 | GNUNET_SCHEDULER_cancel (die_task); | ||
124 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
125 | #if VERBOSE | ||
126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); | ||
127 | #endif | ||
128 | |||
129 | if (th_p2 != NULL) | ||
130 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(th_p2); | ||
131 | th_p2 = NULL; | ||
132 | 114 | ||
133 | GNUNET_TRANSPORT_disconnect (p1.th); | ||
134 | GNUNET_TRANSPORT_disconnect (p2.th); | ||
135 | #if VERBOSE | ||
136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
137 | "Transports disconnected, returning success!\n"); | ||
138 | #endif | ||
139 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; | 115 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; |
140 | fprintf (stderr, | 116 | fprintf (stderr, |
141 | "\nThroughput was %llu kb/s\n", | 117 | "\nThroughput was %llu kb/s\n", |
142 | total_bytes * 1000 / 1024 / delta); | 118 | total_bytes * 1000 / 1024 / delta); |
143 | GNUNET_asprintf(&value_name, "reliable_%s", test_name); | 119 | //GNUNET_asprintf(&value_name, "reliable_%s", test_name); |
144 | GAUGER ("TRANSPORT", value_name, (int)(total_bytes * 1000 / 1024 /delta), "kb/s"); | 120 | //GAUGER ("TRANSPORT", value_name, (int)(total_bytes * 1000 / 1024 /delta), "kb/s"); |
145 | GNUNET_free(value_name); | 121 | //GNUNET_free(value_name); |
146 | ok = 0; | ||
147 | |||
148 | } | ||
149 | 122 | ||
123 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | ||
124 | GNUNET_SCHEDULER_cancel(die_task); | ||
150 | 125 | ||
126 | if (th != NULL) | ||
127 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(th); | ||
128 | th = NULL; | ||
151 | 129 | ||
152 | static void | 130 | GNUNET_TRANSPORT_TESTING_stop_peer(p1); |
153 | stop_arm (struct PeerContext *p) | 131 | GNUNET_TRANSPORT_TESTING_stop_peer(p2); |
154 | { | ||
155 | #if START_ARM | ||
156 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | ||
157 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
158 | GNUNET_OS_process_wait (p->arm_proc); | ||
159 | GNUNET_OS_process_close (p->arm_proc); | ||
160 | p->arm_proc = NULL; | ||
161 | #endif | ||
162 | GNUNET_CONFIGURATION_destroy (p->cfg); | ||
163 | } | 132 | } |
164 | 133 | ||
165 | |||
166 | static void | 134 | static void |
167 | end_badly (void *cls, | 135 | end_badly () |
168 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
169 | { | 136 | { |
170 | if (test_failed == GNUNET_NO) | 137 | die_task = GNUNET_SCHEDULER_NO_TASK; |
171 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); |
172 | "Testcase timeout\n"); | ||
173 | else | ||
174 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
175 | "Reliability failed: Last message sent %u, Next message scheduled %u, Last message received %u, Message expected %u\n", | ||
176 | msg_sent, | ||
177 | msg_scheduled, | ||
178 | msg_recv, | ||
179 | msg_recv_expected); | ||
180 | if (th_p2 != NULL) | ||
181 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(th_p2); | ||
182 | th_p2 = NULL; | ||
183 | |||
184 | GNUNET_break (0); | ||
185 | GNUNET_TRANSPORT_disconnect (p1.th); | ||
186 | GNUNET_TRANSPORT_disconnect (p2.th); | ||
187 | if (GNUNET_SCHEDULER_NO_TASK != tct) | ||
188 | { | ||
189 | GNUNET_SCHEDULER_cancel (tct); | ||
190 | tct = GNUNET_SCHEDULER_NO_TASK; | ||
191 | } | ||
192 | ok = 1; | ||
193 | } | ||
194 | 139 | ||
140 | if (th != NULL) | ||
141 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(th); | ||
142 | th = NULL; | ||
195 | 143 | ||
144 | if (p1 != NULL) | ||
145 | GNUNET_TRANSPORT_TESTING_stop_peer(p1); | ||
146 | if (p2 != NULL) | ||
147 | GNUNET_TRANSPORT_TESTING_stop_peer(p2); | ||
196 | 148 | ||
197 | struct TestMessage | 149 | ok = GNUNET_SYSERR; |
198 | { | 150 | } |
199 | struct GNUNET_MessageHeader header; | ||
200 | uint32_t num; | ||
201 | }; | ||
202 | 151 | ||
203 | 152 | ||
204 | static unsigned int | 153 | static unsigned int |
@@ -229,13 +178,13 @@ notify_receive (void *cls, | |||
229 | return; | 178 | return; |
230 | msg_recv_expected = n; | 179 | msg_recv_expected = n; |
231 | msg_recv = ntohl(hdr->num); | 180 | msg_recv = ntohl(hdr->num); |
232 | if (ntohs (message->size) != s) | 181 | if (ntohs (message->size) != (s)) |
233 | { | 182 | { |
234 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 183 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
235 | "Expected message %u of size %u, got %u bytes of message %u\n", | 184 | "Expected message %u of size %u, got %u bytes of message %u\n", |
236 | n, s, | 185 | n, s, |
237 | ntohs (message->size), | 186 | ntohs (message->size), |
238 | ntohl (hdr->num)); | 187 | ntohl (hdr->num)); |
239 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | 188 | if (die_task != GNUNET_SCHEDULER_NO_TASK) |
240 | GNUNET_SCHEDULER_cancel (die_task); | 189 | GNUNET_SCHEDULER_cancel (die_task); |
241 | test_failed = GNUNET_YES; | 190 | test_failed = GNUNET_YES; |
@@ -245,10 +194,10 @@ notify_receive (void *cls, | |||
245 | if (ntohl (hdr->num) != n) | 194 | if (ntohl (hdr->num) != n) |
246 | { | 195 | { |
247 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 196 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
248 | "Expected message %u of size %u, got %u bytes of message %u\n", | 197 | "Expected message %u of size %u, got %u bytes of message %u\n", |
249 | n, s, | 198 | n, s, |
250 | ntohs (message->size), | 199 | ntohs (message->size), |
251 | ntohl (hdr->num)); | 200 | ntohl (hdr->num)); |
252 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | 201 | if (die_task != GNUNET_SCHEDULER_NO_TASK) |
253 | GNUNET_SCHEDULER_cancel (die_task); | 202 | GNUNET_SCHEDULER_cancel (die_task); |
254 | test_failed = GNUNET_YES; | 203 | test_failed = GNUNET_YES; |
@@ -257,12 +206,12 @@ notify_receive (void *cls, | |||
257 | } | 206 | } |
258 | memset (cbuf, n, s - sizeof (struct TestMessage)); | 207 | memset (cbuf, n, s - sizeof (struct TestMessage)); |
259 | if (0 != memcmp (cbuf, | 208 | if (0 != memcmp (cbuf, |
260 | &hdr[1], | 209 | &hdr[1], |
261 | s - sizeof (struct TestMessage))) | 210 | s - sizeof (struct TestMessage))) |
262 | { | 211 | { |
263 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 212 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
264 | "Expected message %u with bits %u, but body did not match\n", | 213 | "Expected message %u with bits %u, but body did not match\n", |
265 | n, (unsigned char) n); | 214 | n, (unsigned char) n); |
266 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | 215 | if (die_task != GNUNET_SCHEDULER_NO_TASK) |
267 | GNUNET_SCHEDULER_cancel (die_task); | 216 | GNUNET_SCHEDULER_cancel (die_task); |
268 | test_failed = GNUNET_YES; | 217 | test_failed = GNUNET_YES; |
@@ -285,11 +234,15 @@ notify_receive (void *cls, | |||
285 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | 234 | if (die_task != GNUNET_SCHEDULER_NO_TASK) |
286 | GNUNET_SCHEDULER_cancel (die_task); | 235 | GNUNET_SCHEDULER_cancel (die_task); |
287 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 236 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
288 | &end_badly, | 237 | &end_badly, |
289 | NULL); | 238 | NULL); |
290 | } | 239 | } |
291 | if (n == TOTAL_MSGS) | 240 | if (n == TOTAL_MSGS) |
241 | { | ||
242 | ok = 0; | ||
243 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"All messages received\n"); | ||
292 | end (); | 244 | end (); |
245 | } | ||
293 | } | 246 | } |
294 | 247 | ||
295 | 248 | ||
@@ -308,7 +261,7 @@ notify_ready (void *cls, size_t size, void *buf) | |||
308 | ok = 42; | 261 | ok = 42; |
309 | return 0; | 262 | return 0; |
310 | } | 263 | } |
311 | th_p2 = NULL; | 264 | th = NULL; |
312 | ret = 0; | 265 | ret = 0; |
313 | s = get_size (n); | 266 | s = get_size (n); |
314 | GNUNET_assert (size >= s); | 267 | GNUNET_assert (size >= s); |
@@ -336,17 +289,17 @@ notify_ready (void *cls, size_t size, void *buf) | |||
336 | n++; | 289 | n++; |
337 | s = get_size (n); | 290 | s = get_size (n); |
338 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) | 291 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) |
339 | break; /* sometimes pack buffer full, sometimes not */ | 292 | break; /* sometimes pack buffer full, sometimes not */ |
340 | } | 293 | } |
341 | while (size - ret >= s); | 294 | while (size - ret >= s); |
342 | if (n < TOTAL_MSGS) | 295 | if (n < TOTAL_MSGS) |
343 | { | 296 | { |
344 | if (th_p2 == NULL) | 297 | if (th == NULL) |
345 | th_p2 = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, | 298 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, |
346 | &p1.id, | 299 | &p1->id, |
347 | s, 0, TIMEOUT, | 300 | s, 0, TIMEOUT, |
348 | ¬ify_ready, | 301 | ¬ify_ready, |
349 | NULL); | 302 | NULL); |
350 | msg_scheduled = n; | 303 | msg_scheduled = n; |
351 | } | 304 | } |
352 | if (n % 5000 == 0) | 305 | if (n % 5000 == 0) |
@@ -361,219 +314,115 @@ notify_ready (void *cls, size_t size, void *buf) | |||
361 | 314 | ||
362 | 315 | ||
363 | static void | 316 | static void |
364 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | 317 | notify_connect (void *cls, |
318 | const struct GNUNET_PeerIdentity *peer, | ||
319 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | ||
320 | uint32_t ats_count) | ||
365 | { | 321 | { |
366 | connected--; | 322 | |
367 | #if VERBOSE | ||
368 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 323 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
369 | "Peer `%4s' disconnected (%p)!\n", | 324 | "Peer `%4s' connected to us (%p)!\n", |
370 | GNUNET_i2s (peer), cls); | 325 | GNUNET_i2s (peer), |
371 | #endif | 326 | cls); |
372 | if (th_p2 != NULL) | 327 | |
328 | if (cls == p1) | ||
329 | { | ||
330 | GNUNET_TRANSPORT_set_quota (p1->th, | ||
331 | &p2->id, | ||
332 | GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024), | ||
333 | GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024)); | ||
334 | } | ||
335 | else if (cls == p2) | ||
373 | { | 336 | { |
374 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(th_p2); | 337 | GNUNET_TRANSPORT_set_quota (p2->th, |
375 | th_p2 = NULL; | 338 | &p1->id, |
339 | GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024), | ||
340 | GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024)); | ||
376 | } | 341 | } |
377 | } | 342 | } |
378 | 343 | ||
379 | 344 | ||
380 | static void | 345 | static void |
381 | exchange_hello_last (void *cls, | 346 | notify_disconnect (void *cls, |
382 | const struct GNUNET_MessageHeader *message) | 347 | const struct GNUNET_PeerIdentity *peer) |
383 | { | 348 | { |
384 | struct PeerContext *me = cls; | ||
385 | |||
386 | GNUNET_assert (message != NULL); | ||
387 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
388 | "Exchanging HELLO of size %d with peer (%s)!\n", | 350 | "Peer `%4s' disconnected (%p)!\n", |
389 | (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), | 351 | GNUNET_i2s (peer), cls); |
390 | GNUNET_i2s (&me->id)); | ||
391 | GNUNET_assert (GNUNET_OK == | ||
392 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) | ||
393 | message, &me->id)); | ||
394 | GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL); | ||
395 | } | 352 | } |
396 | 353 | ||
397 | |||
398 | |||
399 | static void | 354 | static void |
400 | exchange_hello (void *cls, | 355 | sendtask () |
401 | const struct GNUNET_MessageHeader *message) | ||
402 | { | 356 | { |
403 | struct PeerContext *me = cls; | 357 | start_time = GNUNET_TIME_absolute_get (); |
404 | 358 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, | |
405 | GNUNET_assert (message != NULL); | 359 | &p1->id, |
406 | GNUNET_assert (GNUNET_OK == | 360 | get_size (0), 0, TIMEOUT, |
407 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) | 361 | ¬ify_ready, |
408 | message, &me->id)); | 362 | NULL); |
409 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
410 | "Exchanging HELLO of size %d from peer %s!\n", | ||
411 | (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), | ||
412 | GNUNET_i2s (&me->id)); | ||
413 | GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); | ||
414 | } | 363 | } |
415 | 364 | ||
416 | |||
417 | static void | 365 | static void |
418 | notify_connect (void *cls, | 366 | testing_connect_cb (struct PeerContext * p1, struct PeerContext * p2, void *cls) |
419 | const struct GNUNET_PeerIdentity *peer, | ||
420 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | ||
421 | uint32_t ats_count) | ||
422 | { | 367 | { |
423 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 368 | char * p1_c = strdup (GNUNET_i2s(&p1->id)); |
424 | "Peer `%4s' connected to us (%p)!\n", | 369 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", |
425 | GNUNET_i2s (peer), | 370 | p1_c, |
426 | cls); | 371 | GNUNET_i2s (&p2->id)); |
427 | connected++; | 372 | GNUNET_free (p1_c); |
428 | if (cls == &p1) | 373 | |
429 | { | 374 | // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG! |
430 | GNUNET_TRANSPORT_set_quota (p1.th, | 375 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL); |
431 | &p2.id, | ||
432 | GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024), | ||
433 | GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024)); | ||
434 | start_time = GNUNET_TIME_absolute_get (); | ||
435 | } | ||
436 | else | ||
437 | { | ||
438 | GNUNET_TRANSPORT_set_quota (p2.th, | ||
439 | &p1.id, | ||
440 | GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024), | ||
441 | GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024)); | ||
442 | } | ||
443 | if (2 == connected) | ||
444 | { | ||
445 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | ||
446 | GNUNET_SCHEDULER_cancel (die_task); | ||
447 | if (tct != GNUNET_SCHEDULER_NO_TASK) | ||
448 | GNUNET_SCHEDULER_cancel (tct); | ||
449 | tct = GNUNET_SCHEDULER_NO_TASK; | ||
450 | if (p2_hello_canceled == GNUNET_NO) | ||
451 | { | ||
452 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2); | ||
453 | p2_hello_canceled = GNUNET_YES; | ||
454 | } | ||
455 | if (p1_hello_canceled == GNUNET_NO) | ||
456 | { | ||
457 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1); | ||
458 | p1_hello_canceled = GNUNET_YES; | ||
459 | } | ||
460 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
461 | &end_badly, NULL); | ||
462 | th_p2 = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, | ||
463 | &p1.id, | ||
464 | get_size (0), 0, TIMEOUT, | ||
465 | ¬ify_ready, | ||
466 | NULL); | ||
467 | |||
468 | } | ||
469 | } | 376 | } |
470 | 377 | ||
471 | |||
472 | static void | 378 | static void |
473 | setup_peer (struct PeerContext *p, const char *cfgname) | 379 | run (void *cls, |
380 | char *const *args, | ||
381 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
474 | { | 382 | { |
475 | p->cfg = GNUNET_CONFIGURATION_create (); | 383 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
476 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 384 | &end_badly, NULL); |
477 | if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME")) | 385 | |
478 | { | 386 | p1 = GNUNET_TRANSPORT_TESTING_start_peer(cfg_file_p1, |
479 | GNUNET_assert (GNUNET_OK == | 387 | ¬ify_receive, |
480 | GNUNET_CONFIGURATION_get_value_string (p->cfg, | 388 | ¬ify_connect, |
481 | "PATHS", "SERVICEHOME", | 389 | ¬ify_disconnect, |
482 | &p->servicehome)); | 390 | NULL); |
483 | GNUNET_DISK_directory_remove (p->servicehome); | 391 | p2 = GNUNET_TRANSPORT_TESTING_start_peer(cfg_file_p2, |
484 | } | 392 | ¬ify_receive, |
393 | ¬ify_connect, | ||
394 | ¬ify_disconnect, | ||
395 | NULL); | ||
396 | |||
397 | GNUNET_TRANSPORT_TESTING_connect_peers(p1, p2, &testing_connect_cb, NULL); | ||
398 | } | ||
485 | 399 | ||
486 | #if START_ARM | 400 | static int |
487 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, | 401 | check () |
488 | "gnunet-service-arm", | 402 | { |
489 | "gnunet-service-arm", | 403 | static char *const argv[] = { "test-transport-api", |
490 | #if VERBOSE_ARM | 404 | "-c", |
491 | "-L", "DEBUG", | 405 | "test_transport_api_data.conf", |
406 | #if VERBOSE | ||
407 | "-L", "DEBUG", | ||
492 | #endif | 408 | #endif |
493 | "-c", cfgname, NULL); | 409 | NULL |
410 | }; | ||
411 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
412 | GNUNET_GETOPT_OPTION_END | ||
413 | }; | ||
414 | |||
415 | #if WRITECONFIG | ||
416 | setTransportOptions("test_transport_api_data.conf"); | ||
494 | #endif | 417 | #endif |
418 | ok = 1; | ||
419 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | ||
420 | argv, "test-transport-api", "nohelp", | ||
421 | options, &run, &ok); | ||
495 | 422 | ||
496 | if (is_https) | 423 | return ok; |
497 | { | ||
498 | struct stat sbuf; | ||
499 | if (p==&p1) | ||
500 | { | ||
501 | if (GNUNET_CONFIGURATION_have_value (p->cfg, | ||
502 | "transport-https", "KEY_FILE")) | ||
503 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "KEY_FILE", &key_file_p1); | ||
504 | if (key_file_p1 == NULL) | ||
505 | GNUNET_asprintf(&key_file_p1,"https_p1.key"); | ||
506 | if (0 == stat (key_file_p1, &sbuf )) | ||
507 | { | ||
508 | if (0 == remove(key_file_p1)) | ||
509 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
510 | "Successfully removed existing private key file `%s'\n", | ||
511 | key_file_p1); | ||
512 | else | ||
513 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
514 | "Failed to remove private key file `%s'\n", | ||
515 | key_file_p1); | ||
516 | } | ||
517 | if (GNUNET_CONFIGURATION_have_value (p->cfg,"transport-https", "CERT_FILE")) | ||
518 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "CERT_FILE", &cert_file_p1); | ||
519 | if (cert_file_p1 == NULL) | ||
520 | GNUNET_asprintf(&cert_file_p1,"https_p1.cert"); | ||
521 | if (0 == stat (cert_file_p1, &sbuf )) | ||
522 | { | ||
523 | if (0 == remove(cert_file_p1)) | ||
524 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
525 | "Successfully removed existing certificate file `%s'\n", | ||
526 | cert_file_p1); | ||
527 | else | ||
528 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
529 | "Failed to remove existing certificate file `%s'\n", | ||
530 | cert_file_p1); | ||
531 | } | ||
532 | } | ||
533 | else if (p==&p2) | ||
534 | { | ||
535 | if (GNUNET_CONFIGURATION_have_value (p->cfg, | ||
536 | "transport-https", "KEY_FILE")) | ||
537 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "KEY_FILE", &key_file_p2); | ||
538 | if (key_file_p2 == NULL) | ||
539 | GNUNET_asprintf(&key_file_p2,"https_p2.key"); | ||
540 | if (0 == stat (key_file_p2, &sbuf )) | ||
541 | { | ||
542 | if (0 == remove(key_file_p2)) | ||
543 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
544 | "Successfully removed existing private key file `%s'\n", | ||
545 | key_file_p2); | ||
546 | else | ||
547 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
548 | "Failed to remove private key file `%s'\n", | ||
549 | key_file_p2); | ||
550 | } | ||
551 | if (GNUNET_CONFIGURATION_have_value (p->cfg,"transport-https", "CERT_FILE")) | ||
552 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "CERT_FILE", &cert_file_p2); | ||
553 | if (cert_file_p2 == NULL) | ||
554 | GNUNET_asprintf(&cert_file_p2,"https_p2.cert"); | ||
555 | if (0 == stat (cert_file_p2, &sbuf )) | ||
556 | { | ||
557 | if (0 == remove(cert_file_p2)) | ||
558 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
559 | "Successfully removed existing certificate file `%s'\n", | ||
560 | cert_file_p2); | ||
561 | else | ||
562 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
563 | "Failed to remove existing certificate file `%s'\n", | ||
564 | cert_file_p2); | ||
565 | } | ||
566 | } | ||
567 | } | ||
568 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, | ||
569 | p, | ||
570 | ¬ify_receive, | ||
571 | ¬ify_connect, | ||
572 | ¬ify_disconnect); | ||
573 | GNUNET_assert (p->th != NULL); | ||
574 | } | 424 | } |
575 | 425 | ||
576 | |||
577 | /** | 426 | /** |
578 | * Return the actual path to a file found in the current | 427 | * Return the actual path to a file found in the current |
579 | * PATH environment variable. | 428 | * PATH environment variable. |
@@ -685,231 +534,70 @@ check_gnunet_nat_binary(char *binary) | |||
685 | #endif | 534 | #endif |
686 | } | 535 | } |
687 | 536 | ||
688 | 537 | int | |
689 | static void | 538 | main (int argc, char *argv[]) |
690 | try_connect (void *cls, | ||
691 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
692 | { | ||
693 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
694 | "Asking peers to connect...\n"); | ||
695 | GNUNET_TRANSPORT_try_connect (p2.th, | ||
696 | &p1.id); | ||
697 | GNUNET_TRANSPORT_try_connect (p1.th, | ||
698 | &p2.id); | ||
699 | tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
700 | &try_connect, | ||
701 | NULL); | ||
702 | } | ||
703 | |||
704 | |||
705 | static void | ||
706 | run (void *cls, | ||
707 | char *const *args, | ||
708 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
709 | { | 539 | { |
710 | GNUNET_assert (ok == 1); | 540 | int ret; |
711 | OKPP; | ||
712 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
713 | &end_badly, | ||
714 | NULL); | ||
715 | if (is_tcp) | ||
716 | { | ||
717 | setup_peer (&p1, "test_transport_api_tcp_peer1.conf"); | ||
718 | setup_peer (&p2, "test_transport_api_tcp_peer2.conf"); | ||
719 | } | ||
720 | else if (is_http) | ||
721 | { | ||
722 | setup_peer (&p1, "test_transport_api_rel_http_peer1.conf"); | ||
723 | setup_peer (&p2, "test_transport_api_rel_http_peer2.conf"); | ||
724 | } | ||
725 | else if (is_https) | ||
726 | { | ||
727 | setup_peer (&p1, "test_transport_api_rel_https_peer1.conf"); | ||
728 | setup_peer (&p2, "test_transport_api_rel_https_peer2.conf"); | ||
729 | } | ||
730 | else if (is_udp) | ||
731 | { | ||
732 | setup_peer (&p1, "test_transport_api_udp_peer1.conf"); | ||
733 | setup_peer (&p2, "test_transport_api_udp_peer2.conf"); | ||
734 | } | ||
735 | else if (is_unix) | ||
736 | { | ||
737 | setup_peer (&p1, "test_transport_api_unix_peer1.conf"); | ||
738 | setup_peer (&p2, "test_transport_api_unix_peer2.conf"); | ||
739 | } | ||
740 | else if (is_tcp_nat) | ||
741 | { | ||
742 | setup_peer (&p1, "test_transport_api_tcp_nat_peer1.conf"); | ||
743 | setup_peer (&p2, "test_transport_api_tcp_nat_peer2.conf"); | ||
744 | } | ||
745 | else if (is_wlan) | ||
746 | { | ||
747 | setup_peer (&p1, "test_transport_api_wlan_peer1.conf"); | ||
748 | setup_peer (&p2, "test_transport_api_wlan_peer2.conf"); | ||
749 | } | ||
750 | else | ||
751 | GNUNET_assert (0); | ||
752 | GNUNET_assert(p1.th != NULL); | ||
753 | GNUNET_assert(p2.th != NULL); | ||
754 | GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); | ||
755 | p1_hello_canceled = GNUNET_NO; | ||
756 | GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2); | ||
757 | p2_hello_canceled = GNUNET_NO; | ||
758 | tct = GNUNET_SCHEDULER_add_now (&try_connect, NULL); | ||
759 | } | ||
760 | |||
761 | 541 | ||
762 | static int | 542 | GNUNET_log_setup ("test-transport-api", |
763 | check () | ||
764 | { | ||
765 | char *const argv[] = { "test-transport-api-reliability", | ||
766 | "-c", | ||
767 | "test_transport_api_data.conf", | ||
768 | #if VERBOSE | 543 | #if VERBOSE |
769 | "-L", "DEBUG", | 544 | "DEBUG", |
770 | #endif | 545 | #else |
771 | NULL | 546 | "WARNING", |
772 | }; | ||
773 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
774 | GNUNET_GETOPT_OPTION_END | ||
775 | }; | ||
776 | |||
777 | #if WRITECONFIG | ||
778 | setTransportOptions("test_transport_api_data.conf"); | ||
779 | #endif | 547 | #endif |
780 | ok = 1; | 548 | NULL); |
781 | |||
782 | if ((GNUNET_YES == is_tcp_nat) && (check_gnunet_nat_binary("gnunet-nat-server") != GNUNET_YES)) | ||
783 | { | ||
784 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
785 | "Not running NAT test case, binaries not properly installed.\n"); | ||
786 | return 0; | ||
787 | } | ||
788 | 549 | ||
789 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 550 | char * pch = strdup(argv[0]); |
790 | argv, "test-transport-api-reliability", "nohelp", | 551 | char * backup = pch; |
791 | options, &run, &ok); | 552 | char * filename = NULL; |
792 | stop_arm (&p1); | 553 | char *dotexe; |
793 | stop_arm (&p2); | ||
794 | 554 | ||
795 | if (is_https) | 555 | /* get executable filename */ |
556 | pch = strtok (pch,"/"); | ||
557 | while (pch != NULL) | ||
796 | { | 558 | { |
797 | struct stat sbuf; | 559 | pch = strtok (NULL, "/"); |
798 | if (0 == stat (cert_file_p1, &sbuf )) | 560 | if (pch != NULL) |
799 | { | 561 | filename = pch; |
800 | if (0 == remove(cert_file_p1)) | ||
801 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
802 | "Successfully removed existing certificate file `%s'\n", | ||
803 | cert_file_p1); | ||
804 | else | ||
805 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
806 | "Failed to remove certfile `%s'\n", | ||
807 | cert_file_p1); | ||
808 | } | ||
809 | |||
810 | if (0 == stat (key_file_p1, &sbuf )) | ||
811 | { | ||
812 | if (0 == remove(key_file_p1)) | ||
813 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
814 | "Successfully removed private key file `%s'\n", | ||
815 | key_file_p1); | ||
816 | else | ||
817 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
818 | "Failed to private key file `%s'\n",key_file_p1); | ||
819 | } | ||
820 | |||
821 | if (0 == stat (cert_file_p2, &sbuf )) | ||
822 | { | ||
823 | if (0 == remove(cert_file_p2)) | ||
824 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
825 | "Successfully removed existing certificate file `%s'\n", | ||
826 | cert_file_p2); | ||
827 | else | ||
828 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
829 | "Failed to remove certfile `%s'\n",cert_file_p2); | ||
830 | } | ||
831 | |||
832 | if (0 == stat (key_file_p2, &sbuf )) | ||
833 | { | ||
834 | if (0 == remove(key_file_p2)) | ||
835 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
836 | "Successfully removed private key file `%s'\n", | ||
837 | key_file_p2); | ||
838 | else | ||
839 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
840 | "Failed to private key file `%s'\n", | ||
841 | key_file_p2); | ||
842 | } | ||
843 | GNUNET_free(key_file_p1); | ||
844 | GNUNET_free(key_file_p2); | ||
845 | GNUNET_free(cert_file_p1); | ||
846 | GNUNET_free(cert_file_p2); | ||
847 | } | 562 | } |
563 | /* remove "lt-" */ | ||
564 | filename = strstr(filename, "tes"); | ||
565 | if (NULL != (dotexe = strstr (filename, ".exe"))) | ||
566 | dotexe[0] = '\0'; | ||
848 | 567 | ||
849 | return ok; | 568 | /* create cfg filename */ |
850 | } | 569 | GNUNET_asprintf(&cfg_file_p1, "%s_peer1.conf",filename); |
851 | 570 | GNUNET_asprintf(&cfg_file_p2, "%s_peer2.conf", filename); | |
852 | 571 | GNUNET_free (backup); | |
853 | int | ||
854 | main (int argc, char *argv[]) | ||
855 | { | ||
856 | int ret; | ||
857 | |||
858 | test_failed = GNUNET_NO; | ||
859 | 572 | ||
860 | if (strstr(argv[0], "tcp_nat") != NULL) | 573 | if (strstr(argv[0], "tcp_nat") != NULL) |
861 | { | 574 | { |
862 | is_tcp_nat = GNUNET_YES; | 575 | if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server")) |
863 | GNUNET_asprintf(&test_name, "tcp_nat"); | 576 | { |
864 | } | 577 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
865 | else if (strstr(argv[0], "tcp") != NULL) | 578 | "`%s' not properly installed, cannot run NAT test!\n", |
866 | { | 579 | "gnunet-nat-server"); |
867 | is_tcp = GNUNET_YES; | 580 | return 0; |
868 | GNUNET_asprintf(&test_name, "tcp"); | 581 | } |
869 | } | ||
870 | else if (strstr(argv[0], "https") != NULL) | ||
871 | { | ||
872 | is_https = GNUNET_YES; | ||
873 | GNUNET_asprintf(&test_name, "https"); | ||
874 | } | ||
875 | else if (strstr(argv[0], "http") != NULL) | ||
876 | { | ||
877 | is_http = GNUNET_YES; | ||
878 | GNUNET_asprintf(&test_name, "http"); | ||
879 | } | ||
880 | else if (strstr(argv[0], "udp") != NULL) | ||
881 | { | ||
882 | is_udp = GNUNET_YES; | ||
883 | GNUNET_asprintf(&test_name, "udp"); | ||
884 | } | ||
885 | else if (strstr(argv[0], "unix") != NULL) | ||
886 | { | ||
887 | is_unix = GNUNET_YES; | ||
888 | GNUNET_asprintf(&test_name, "unix"); | ||
889 | } | 582 | } |
890 | else if (strstr(argv[0], "wlan") != NULL) | 583 | else if (strstr(argv[0], "udp_nat") != NULL) |
891 | { | 584 | { |
892 | is_wlan = GNUNET_YES; | 585 | if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server")) |
586 | { | ||
587 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
588 | "`%s' not properly installed, cannot run NAT test!\n", | ||
589 | "gnunet-nat-server"); | ||
590 | return 0; | ||
591 | } | ||
893 | } | 592 | } |
894 | GNUNET_log_setup ("test-transport-api-reliability", | 593 | |
895 | #if VERBOSE | ||
896 | "DEBUG", | ||
897 | #else | ||
898 | "WARNING", | ||
899 | #endif | ||
900 | NULL); | ||
901 | ret = check (); | 594 | ret = check (); |
902 | if (p1.servicehome != NULL) | 595 | |
903 | { | 596 | GNUNET_free (cfg_file_p1); |
904 | GNUNET_DISK_directory_remove (p1.servicehome); | 597 | GNUNET_free (cfg_file_p2); |
905 | GNUNET_free (p1.servicehome); | 598 | |
906 | } | ||
907 | if (p2.servicehome != NULL) | ||
908 | { | ||
909 | GNUNET_DISK_directory_remove (p2.servicehome); | ||
910 | GNUNET_free (p2.servicehome); | ||
911 | } | ||
912 | return ret; | 599 | return ret; |
913 | } | 600 | } |
914 | 601 | ||
602 | |||
915 | /* end of test_transport_api_reliability.c */ | 603 | /* end of test_transport_api_reliability.c */ |