diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-11-22 14:22:28 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-11-22 14:22:28 +0000 |
commit | a0e99f40994a4f620dd5c9b51f84ea5f9268fd1f (patch) | |
tree | 535003777bc0396f0a5897d9720be6a10c884887 /src/transport/test_transport_api_restart_2peers.c | |
parent | d778dbc46a3186140b8947d8614f6e6df9de7718 (diff) | |
download | gnunet-a0e99f40994a4f620dd5c9b51f84ea5f9268fd1f.tar.gz gnunet-a0e99f40994a4f620dd5c9b51f84ea5f9268fd1f.zip |
tests for mantis #1028
Diffstat (limited to 'src/transport/test_transport_api_restart_2peers.c')
-rw-r--r-- | src/transport/test_transport_api_restart_2peers.c | 108 |
1 files changed, 68 insertions, 40 deletions
diff --git a/src/transport/test_transport_api_restart_2peers.c b/src/transport/test_transport_api_restart_2peers.c index af9b46385..dab8f39a6 100644 --- a/src/transport/test_transport_api_restart_2peers.c +++ b/src/transport/test_transport_api_restart_2peers.c | |||
@@ -44,7 +44,7 @@ | |||
44 | /** | 44 | /** |
45 | * How long until we give up on transmitting the message? | 45 | * How long until we give up on transmitting the message? |
46 | */ | 46 | */ |
47 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) | 47 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
48 | 48 | ||
49 | /** | 49 | /** |
50 | * How long until we give up on transmitting the message? | 50 | * How long until we give up on transmitting the message? |
@@ -53,10 +53,6 @@ | |||
53 | 53 | ||
54 | #define MTYPE 12345 | 54 | #define MTYPE 12345 |
55 | 55 | ||
56 | static char *test_source; | ||
57 | |||
58 | static char *test_plugin; | ||
59 | |||
60 | static char *test_name; | 56 | static char *test_name; |
61 | 57 | ||
62 | static int ok; | 58 | static int ok; |
@@ -65,6 +61,8 @@ static GNUNET_SCHEDULER_TaskIdentifier die_task; | |||
65 | 61 | ||
66 | static GNUNET_SCHEDULER_TaskIdentifier send_task; | 62 | static GNUNET_SCHEDULER_TaskIdentifier send_task; |
67 | 63 | ||
64 | static GNUNET_SCHEDULER_TaskIdentifier reconnect_task; | ||
65 | |||
68 | struct PeerContext *p1; | 66 | struct PeerContext *p1; |
69 | 67 | ||
70 | struct PeerContext *p2; | 68 | struct PeerContext *p2; |
@@ -95,9 +93,15 @@ end () | |||
95 | 93 | ||
96 | if (send_task != GNUNET_SCHEDULER_NO_TASK) | 94 | if (send_task != GNUNET_SCHEDULER_NO_TASK) |
97 | GNUNET_SCHEDULER_cancel (send_task); | 95 | GNUNET_SCHEDULER_cancel (send_task); |
96 | send_task = GNUNET_SCHEDULER_NO_TASK; | ||
97 | |||
98 | if (reconnect_task != GNUNET_SCHEDULER_NO_TASK) | ||
99 | GNUNET_SCHEDULER_cancel (reconnect_task); | ||
100 | reconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
98 | 101 | ||
99 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | 102 | if (die_task != GNUNET_SCHEDULER_NO_TASK) |
100 | GNUNET_SCHEDULER_cancel (die_task); | 103 | GNUNET_SCHEDULER_cancel (die_task); |
104 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
101 | 105 | ||
102 | if (th != NULL) | 106 | if (th != NULL) |
103 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 107 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
@@ -115,13 +119,18 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); | 119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); |
116 | 120 | ||
117 | if (restarted == GNUNET_YES) | 121 | if (restarted == GNUNET_YES) |
118 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers were restarted\n"); | 122 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer was restarted\n"); |
119 | 123 | ||
120 | if (restarted == GNUNET_NO) | 124 | if (restarted == GNUNET_NO) |
121 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers were NOT restarted\n"); | 125 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer was NOT restarted\n"); |
126 | |||
127 | if (reconnect_task != GNUNET_SCHEDULER_NO_TASK) | ||
128 | GNUNET_SCHEDULER_cancel (reconnect_task); | ||
129 | reconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
122 | 130 | ||
123 | if (send_task != GNUNET_SCHEDULER_NO_TASK) | 131 | if (send_task != GNUNET_SCHEDULER_NO_TASK) |
124 | GNUNET_SCHEDULER_cancel (send_task); | 132 | GNUNET_SCHEDULER_cancel (send_task); |
133 | send_task = GNUNET_SCHEDULER_NO_TASK; | ||
125 | 134 | ||
126 | if (cc != NULL) | 135 | if (cc != NULL) |
127 | { | 136 | { |
@@ -142,6 +151,33 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
142 | ok = GNUNET_SYSERR; | 151 | ok = GNUNET_SYSERR; |
143 | } | 152 | } |
144 | 153 | ||
154 | static void | ||
155 | reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
156 | { | ||
157 | struct PeerContext *p = cls; | ||
158 | reconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
159 | |||
160 | GNUNET_TRANSPORT_try_connect (p1->th, &p2->id); | ||
161 | reconnect_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &reconnect, p); | ||
162 | } | ||
163 | |||
164 | static void | ||
165 | restart_cb (struct PeerContext *p, void *cls) | ||
166 | { | ||
167 | static int c; | ||
168 | c++; | ||
169 | |||
170 | if (c != 2) | ||
171 | return; | ||
172 | |||
173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
174 | "Restarted peer %u (`%4s'), issuing reconnect\n", | ||
175 | p->no, | ||
176 | GNUNET_i2s (&p->id)); | ||
177 | |||
178 | reconnect_task = GNUNET_SCHEDULER_add_now(&reconnect, p); | ||
179 | } | ||
180 | |||
145 | static | 181 | static |
146 | void restart (struct PeerContext *p , char * cfg_file) | 182 | void restart (struct PeerContext *p , char * cfg_file) |
147 | { | 183 | { |
@@ -150,7 +186,7 @@ void restart (struct PeerContext *p , char * cfg_file) | |||
150 | "Restarting peer %u (`%4s')\n", | 186 | "Restarting peer %u (`%4s')\n", |
151 | p->no, | 187 | p->no, |
152 | GNUNET_i2s (&p->id)); | 188 | GNUNET_i2s (&p->id)); |
153 | GNUNET_TRANSPORT_TESTING_restart_peer (tth, p, cfg_file); | 189 | GNUNET_TRANSPORT_TESTING_restart_peer (tth, p, cfg_file, &restart_cb, p); |
154 | return; | 190 | return; |
155 | } | 191 | } |
156 | 192 | ||
@@ -169,18 +205,29 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
169 | GNUNET_assert (t != NULL); | 205 | GNUNET_assert (t != NULL); |
170 | 206 | ||
171 | char *ps = strdup (GNUNET_i2s (&p->id)); | 207 | char *ps = strdup (GNUNET_i2s (&p->id)); |
172 | |||
173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
174 | "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", | 209 | "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", |
175 | p->no, ps, ntohs (message->type), ntohs (message->size), t->no, | 210 | p->no, ps, ntohs (message->type), ntohs (message->size), t->no, |
176 | GNUNET_i2s (&t->id)); | 211 | GNUNET_i2s (&t->id)); |
212 | GNUNET_free (ps); | ||
177 | 213 | ||
178 | if ((MTYPE == ntohs (message->type)) && | 214 | if ((MTYPE == ntohs (message->type)) && |
179 | (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) | 215 | (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) |
180 | { | 216 | { |
181 | restarted = GNUNET_YES; | 217 | if (restarted == GNUNET_NO) |
182 | restart (p1, cfg_file_p1); | 218 | { |
183 | restart (p2, cfg_file_p2); | 219 | restarted = GNUNET_YES; |
220 | restart (p1, cfg_file_p1); | ||
221 | restart (p2, cfg_file_p2); | ||
222 | return; | ||
223 | } | ||
224 | else | ||
225 | { | ||
226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
227 | "Restarted peers connected, stopping test...\n"); | ||
228 | ok = 0; | ||
229 | end (); | ||
230 | } | ||
184 | } | 231 | } |
185 | else | 232 | else |
186 | { | 233 | { |
@@ -269,13 +316,15 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
269 | 316 | ||
270 | char *ps = strdup (GNUNET_i2s (&p->id)); | 317 | char *ps = strdup (GNUNET_i2s (&p->id)); |
271 | 318 | ||
272 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
273 | "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps, | 320 | "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps, |
274 | t->no, GNUNET_i2s (peer)); | 321 | t->no, GNUNET_i2s (peer)); |
275 | GNUNET_free (ps); | 322 | GNUNET_free (ps); |
276 | 323 | ||
277 | if ((restarted == GNUNET_YES) && (c == 4)) | 324 | if ((restarted == GNUNET_YES) && (c == 4)) |
278 | end (); | 325 | { |
326 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); | ||
327 | } | ||
279 | } | 328 | } |
280 | 329 | ||
281 | 330 | ||
@@ -283,11 +332,13 @@ static void | |||
283 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | 332 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) |
284 | { | 333 | { |
285 | struct PeerContext *p = cls; | 334 | struct PeerContext *p = cls; |
286 | char *ps = strdup (GNUNET_i2s (&p->id)); | ||
287 | 335 | ||
336 | |||
337 | char *ps = strdup (GNUNET_i2s (&p->id)); | ||
288 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 338 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
289 | "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps, | 339 | "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps, |
290 | GNUNET_i2s (peer)); | 340 | GNUNET_i2s (peer)); |
341 | GNUNET_free (ps); | ||
291 | 342 | ||
292 | if (th != NULL) | 343 | if (th != NULL) |
293 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 344 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
@@ -323,10 +374,10 @@ start_cb (struct PeerContext *p, void *cls) | |||
323 | return; | 374 | return; |
324 | 375 | ||
325 | char *sender_c = strdup (GNUNET_i2s (&p1->id)); | 376 | char *sender_c = strdup (GNUNET_i2s (&p1->id)); |
326 | |||
327 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 377 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
328 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", | 378 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", |
329 | p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); | 379 | p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); |
380 | GNUNET_free (sender_c); | ||
330 | 381 | ||
331 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, | 382 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, |
332 | NULL); | 383 | NULL); |
@@ -391,12 +442,9 @@ int | |||
391 | main (int argc, char *argv[]) | 442 | main (int argc, char *argv[]) |
392 | { | 443 | { |
393 | int ret; | 444 | int ret; |
394 | int nat_res; | ||
395 | 445 | ||
396 | GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name); | 446 | GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name); |
397 | GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source); | 447 | |
398 | GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source, | ||
399 | &test_plugin); | ||
400 | 448 | ||
401 | GNUNET_log_setup (test_name, | 449 | GNUNET_log_setup (test_name, |
402 | #if VERBOSE | 450 | #if VERBOSE |
@@ -408,23 +456,6 @@ main (int argc, char *argv[]) | |||
408 | 456 | ||
409 | tth = GNUNET_TRANSPORT_TESTING_init (); | 457 | tth = GNUNET_TRANSPORT_TESTING_init (); |
410 | 458 | ||
411 | if ((strcmp (test_plugin, "tcp_nat") == 0) || | ||
412 | (strcmp (test_plugin, "udp_nat") == 0)) | ||
413 | { | ||
414 | nat_res = GNUNET_OS_check_helper_binary ("gnunet-nat-server"); | ||
415 | if (GNUNET_NO == nat_res) | ||
416 | { | ||
417 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Cannot run NAT test: `%s' %s \n", | ||
418 | "gnunet-nat-server", "SUID not set"); | ||
419 | return 0; | ||
420 | } | ||
421 | if (GNUNET_SYSERR == nat_res) | ||
422 | { | ||
423 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Cannot run NAT test: `%s' %s \n", | ||
424 | "gnunet-nat-server", "file not found"); | ||
425 | return 0; | ||
426 | } | ||
427 | } | ||
428 | 459 | ||
429 | GNUNET_asprintf(&cfg_file_p1,"test_transport_api_tcp_peer1.conf"); | 460 | GNUNET_asprintf(&cfg_file_p1,"test_transport_api_tcp_peer1.conf"); |
430 | GNUNET_asprintf(&cfg_file_p2,"test_transport_api_tcp_peer2.conf"); | 461 | GNUNET_asprintf(&cfg_file_p2,"test_transport_api_tcp_peer2.conf"); |
@@ -435,13 +466,10 @@ main (int argc, char *argv[]) | |||
435 | GNUNET_free (cfg_file_p1); | 466 | GNUNET_free (cfg_file_p1); |
436 | GNUNET_free (cfg_file_p2); | 467 | GNUNET_free (cfg_file_p2); |
437 | 468 | ||
438 | GNUNET_free (test_source); | ||
439 | GNUNET_free (test_plugin); | ||
440 | GNUNET_free (test_name); | 469 | GNUNET_free (test_name); |
441 | 470 | ||
442 | GNUNET_TRANSPORT_TESTING_done (tth); | 471 | GNUNET_TRANSPORT_TESTING_done (tth); |
443 | 472 | ||
444 | return ret; | 473 | return ret; |
445 | } | 474 | } |
446 | |||
447 | /* end of test_transport_api_restart_2peers.c */ | 475 | /* end of test_transport_api_restart_2peers.c */ |