diff options
-rw-r--r-- | src/transport/test_transport_api_restart_1peer.c | 98 | ||||
-rw-r--r-- | src/transport/test_transport_api_restart_2peers.c | 108 | ||||
-rw-r--r-- | src/transport/transport-testing.c | 12 | ||||
-rw-r--r-- | src/transport/transport-testing.h | 5 |
4 files changed, 142 insertions, 81 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); |
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 */ |
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c index d11c885f8..a8f034c9c 100644 --- a/src/transport/transport-testing.c +++ b/src/transport/transport-testing.c | |||
@@ -27,7 +27,6 @@ | |||
27 | 27 | ||
28 | #include "transport-testing.h" | 28 | #include "transport-testing.h" |
29 | 29 | ||
30 | #define VERBOSE GNUNET_YES | ||
31 | #define HOSTKEYFILESIZE 914 | 30 | #define HOSTKEYFILESIZE 914 |
32 | 31 | ||
33 | static const char * | 32 | static const char * |
@@ -358,11 +357,14 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle | |||
358 | int | 357 | int |
359 | GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, | 358 | GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, |
360 | struct PeerContext *p, | 359 | struct PeerContext *p, |
361 | const char *cfgname) | 360 | const char *cfgname, |
361 | GNUNET_TRANSPORT_TESTING_start_cb restart_cb, | ||
362 | void *cb_cls) | ||
362 | { | 363 | { |
363 | struct GNUNET_DISK_FileHandle *fn; | 364 | struct GNUNET_DISK_FileHandle *fn; |
364 | int success = GNUNET_OK; | 365 | int success = GNUNET_OK; |
365 | 366 | ||
367 | GNUNET_assert (tth != NULL); | ||
366 | GNUNET_assert (p != NULL); | 368 | GNUNET_assert (p != NULL); |
367 | GNUNET_assert (p->hostkeyfile != NULL); | 369 | GNUNET_assert (p->hostkeyfile != NULL); |
368 | GNUNET_assert (p->servicehome != NULL); | 370 | GNUNET_assert (p->servicehome != NULL); |
@@ -396,6 +398,7 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle *t | |||
396 | GNUNET_CONFIGURATION_destroy (p->cfg); | 398 | GNUNET_CONFIGURATION_destroy (p->cfg); |
397 | p->cfg = NULL; | 399 | p->cfg = NULL; |
398 | 400 | ||
401 | |||
399 | /* start */ | 402 | /* start */ |
400 | #if VERBOSE | 403 | #if VERBOSE |
401 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | 404 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", |
@@ -403,8 +406,8 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle *t | |||
403 | GNUNET_i2s (&p->id)); | 406 | GNUNET_i2s (&p->id)); |
404 | #endif | 407 | #endif |
405 | 408 | ||
409 | sleep (5); | ||
406 | 410 | ||
407 | GNUNET_assert (tth != NULL); | ||
408 | if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO) | 411 | if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO) |
409 | { | 412 | { |
410 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", | 413 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", |
@@ -447,6 +450,9 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle *t | |||
447 | ¬ify_connect, ¬ify_disconnect); | 450 | ¬ify_connect, ¬ify_disconnect); |
448 | GNUNET_assert (p->th != NULL); | 451 | GNUNET_assert (p->th != NULL); |
449 | 452 | ||
453 | p->start_cb = restart_cb; | ||
454 | p->cb_cls = cb_cls; | ||
455 | |||
450 | p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &get_hello, p); | 456 | p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &get_hello, p); |
451 | GNUNET_assert (p->ghh != NULL); | 457 | GNUNET_assert (p->ghh != NULL); |
452 | 458 | ||
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h index 6af2d68f5..883c68837 100644 --- a/src/transport/transport-testing.h +++ b/src/transport/transport-testing.h | |||
@@ -34,6 +34,7 @@ | |||
34 | #include "gnunet_container_lib.h" | 34 | #include "gnunet_container_lib.h" |
35 | #include "gnunet_transport_service.h" | 35 | #include "gnunet_transport_service.h" |
36 | 36 | ||
37 | |||
37 | #define GNUNET_TRANSPORT_TESTING_ConnectRequest void * | 38 | #define GNUNET_TRANSPORT_TESTING_ConnectRequest void * |
38 | 39 | ||
39 | 40 | ||
@@ -170,7 +171,9 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, | |||
170 | int | 171 | int |
171 | GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, | 172 | GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, |
172 | struct PeerContext *p, | 173 | struct PeerContext *p, |
173 | const char *cfgname); | 174 | const char *cfgname, |
175 | GNUNET_TRANSPORT_TESTING_start_cb start_cb, | ||
176 | void *cb_cls); | ||
174 | 177 | ||
175 | /** | 178 | /** |
176 | * Connect the given peers and call the callback when both peers report the | 179 | * Connect the given peers and call the callback when both peers report the |