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_1peer.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_1peer.c')
-rw-r--r-- | src/transport/test_transport_api_restart_1peer.c | 98 |
1 files changed, 61 insertions, 37 deletions
diff --git a/src/transport/test_transport_api_restart_1peer.c b/src/transport/test_transport_api_restart_1peer.c index fb06c26ab..67530f421 100644 --- a/src/transport/test_transport_api_restart_1peer.c +++ b/src/transport/test_transport_api_restart_1peer.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); |
@@ -118,10 +122,15 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
118 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer was 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, "Peer was NO 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,28 @@ 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 (p->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 | |||
168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
169 | "Restarted peer %u (`%4s'), issuing reconnect\n", | ||
170 | p->no, | ||
171 | GNUNET_i2s (&p->id)); | ||
172 | |||
173 | reconnect_task = GNUNET_SCHEDULER_add_now(&reconnect, p); | ||
174 | } | ||
175 | |||
145 | static | 176 | static |
146 | void restart (struct PeerContext *p , char * cfg_file) | 177 | void restart (struct PeerContext *p , char * cfg_file) |
147 | { | 178 | { |
@@ -150,7 +181,7 @@ void restart (struct PeerContext *p , char * cfg_file) | |||
150 | "Restarting peer %u (`%4s')\n", | 181 | "Restarting peer %u (`%4s')\n", |
151 | p->no, | 182 | p->no, |
152 | GNUNET_i2s (&p->id)); | 183 | GNUNET_i2s (&p->id)); |
153 | GNUNET_TRANSPORT_TESTING_restart_peer (tth, p1, cfg_file); | 184 | GNUNET_TRANSPORT_TESTING_restart_peer (tth, p, cfg_file, &restart_cb, p); |
154 | return; | 185 | return; |
155 | } | 186 | } |
156 | 187 | ||
@@ -169,17 +200,28 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
169 | GNUNET_assert (t != NULL); | 200 | GNUNET_assert (t != NULL); |
170 | 201 | ||
171 | char *ps = strdup (GNUNET_i2s (&p->id)); | 202 | char *ps = strdup (GNUNET_i2s (&p->id)); |
172 | |||
173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
174 | "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", | 204 | "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, | 205 | p->no, ps, ntohs (message->type), ntohs (message->size), t->no, |
176 | GNUNET_i2s (&t->id)); | 206 | GNUNET_i2s (&t->id)); |
207 | GNUNET_free (ps); | ||
177 | 208 | ||
178 | if ((MTYPE == ntohs (message->type)) && | 209 | if ((MTYPE == ntohs (message->type)) && |
179 | (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) | 210 | (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) |
180 | { | 211 | { |
181 | restarted = GNUNET_YES; | 212 | if (restarted == GNUNET_NO) |
182 | restart (p1, cfg_file_p1); | 213 | { |
214 | restarted = GNUNET_YES; | ||
215 | restart (p1, cfg_file_p1); | ||
216 | return; | ||
217 | } | ||
218 | else | ||
219 | { | ||
220 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
221 | "Restarted peers connected, stopping test...\n"); | ||
222 | ok = 0; | ||
223 | end (); | ||
224 | } | ||
183 | } | 225 | } |
184 | else | 226 | else |
185 | { | 227 | { |
@@ -268,13 +310,15 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
268 | 310 | ||
269 | char *ps = strdup (GNUNET_i2s (&p->id)); | 311 | char *ps = strdup (GNUNET_i2s (&p->id)); |
270 | 312 | ||
271 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 313 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
272 | "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps, | 314 | "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps, |
273 | t->no, GNUNET_i2s (peer)); | 315 | t->no, GNUNET_i2s (peer)); |
274 | GNUNET_free (ps); | 316 | GNUNET_free (ps); |
275 | 317 | ||
276 | if ((restarted == GNUNET_YES) && (c == 4)) | 318 | if ((restarted == GNUNET_YES) && (c == 4)) |
277 | end (); | 319 | { |
320 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); | ||
321 | } | ||
278 | } | 322 | } |
279 | 323 | ||
280 | 324 | ||
@@ -282,11 +326,13 @@ static void | |||
282 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | 326 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) |
283 | { | 327 | { |
284 | struct PeerContext *p = cls; | 328 | struct PeerContext *p = cls; |
285 | char *ps = strdup (GNUNET_i2s (&p->id)); | ||
286 | 329 | ||
330 | |||
331 | char *ps = strdup (GNUNET_i2s (&p->id)); | ||
287 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 332 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
288 | "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps, | 333 | "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps, |
289 | GNUNET_i2s (peer)); | 334 | GNUNET_i2s (peer)); |
335 | GNUNET_free (ps); | ||
290 | 336 | ||
291 | if (th != NULL) | 337 | if (th != NULL) |
292 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 338 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
@@ -322,10 +368,10 @@ start_cb (struct PeerContext *p, void *cls) | |||
322 | return; | 368 | return; |
323 | 369 | ||
324 | char *sender_c = strdup (GNUNET_i2s (&p1->id)); | 370 | char *sender_c = strdup (GNUNET_i2s (&p1->id)); |
325 | |||
326 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 371 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
327 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", | 372 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", |
328 | p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); | 373 | p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); |
374 | GNUNET_free (sender_c); | ||
329 | 375 | ||
330 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, | 376 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, |
331 | NULL); | 377 | NULL); |
@@ -390,12 +436,9 @@ int | |||
390 | main (int argc, char *argv[]) | 436 | main (int argc, char *argv[]) |
391 | { | 437 | { |
392 | int ret; | 438 | int ret; |
393 | int nat_res; | ||
394 | 439 | ||
395 | GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name); | 440 | GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name); |
396 | GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source); | 441 | |
397 | GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source, | ||
398 | &test_plugin); | ||
399 | 442 | ||
400 | GNUNET_log_setup (test_name, | 443 | GNUNET_log_setup (test_name, |
401 | #if VERBOSE | 444 | #if VERBOSE |
@@ -407,23 +450,6 @@ main (int argc, char *argv[]) | |||
407 | 450 | ||
408 | tth = GNUNET_TRANSPORT_TESTING_init (); | 451 | tth = GNUNET_TRANSPORT_TESTING_init (); |
409 | 452 | ||
410 | if ((strcmp (test_plugin, "tcp_nat") == 0) || | ||
411 | (strcmp (test_plugin, "udp_nat") == 0)) | ||
412 | { | ||
413 | nat_res = GNUNET_OS_check_helper_binary ("gnunet-nat-server"); | ||
414 | if (GNUNET_NO == nat_res) | ||
415 | { | ||
416 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Cannot run NAT test: `%s' %s \n", | ||
417 | "gnunet-nat-server", "SUID not set"); | ||
418 | return 0; | ||
419 | } | ||
420 | if (GNUNET_SYSERR == nat_res) | ||
421 | { | ||
422 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Cannot run NAT test: `%s' %s \n", | ||
423 | "gnunet-nat-server", "file not found"); | ||
424 | return 0; | ||
425 | } | ||
426 | } | ||
427 | 453 | ||
428 | GNUNET_asprintf(&cfg_file_p1,"test_transport_api_tcp_peer1.conf"); | 454 | GNUNET_asprintf(&cfg_file_p1,"test_transport_api_tcp_peer1.conf"); |
429 | GNUNET_asprintf(&cfg_file_p2,"test_transport_api_tcp_peer2.conf"); | 455 | GNUNET_asprintf(&cfg_file_p2,"test_transport_api_tcp_peer2.conf"); |
@@ -434,8 +460,6 @@ main (int argc, char *argv[]) | |||
434 | GNUNET_free (cfg_file_p1); | 460 | GNUNET_free (cfg_file_p1); |
435 | GNUNET_free (cfg_file_p2); | 461 | GNUNET_free (cfg_file_p2); |
436 | 462 | ||
437 | GNUNET_free (test_source); | ||
438 | GNUNET_free (test_plugin); | ||
439 | GNUNET_free (test_name); | 463 | GNUNET_free (test_name); |
440 | 464 | ||
441 | GNUNET_TRANSPORT_TESTING_done (tth); | 465 | GNUNET_TRANSPORT_TESTING_done (tth); |