aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/testing/test_testing_connect.c2
-rw-r--r--src/testing/test_testing_topology.c360
-rw-r--r--src/testing/testing.c63
-rw-r--r--src/testing/testing_group.c7
4 files changed, 235 insertions, 197 deletions
diff --git a/src/testing/test_testing_connect.c b/src/testing/test_testing_connect.c
index 9dd07f993..60721298e 100644
--- a/src/testing/test_testing_connect.c
+++ b/src/testing/test_testing_connect.c
@@ -24,7 +24,7 @@
24#include "platform.h" 24#include "platform.h"
25#include "gnunet_testing_lib.h" 25#include "gnunet_testing_lib.h"
26 26
27#define VERBOSE GNUNET_YES 27#define VERBOSE GNUNET_NO
28 28
29 29
30/** 30/**
diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c
index eae59913c..6961f0418 100644
--- a/src/testing/test_testing_topology.c
+++ b/src/testing/test_testing_topology.c
@@ -25,7 +25,7 @@
25#include "gnunet_testing_lib.h" 25#include "gnunet_testing_lib.h"
26#include "gnunet_core_service.h" 26#include "gnunet_core_service.h"
27 27
28#define VERBOSE GNUNET_NO 28#define VERBOSE GNUNET_YES
29 29
30/** 30/**
31 * How long until we fail the whole testcase? 31 * How long until we fail the whole testcase?
@@ -37,7 +37,9 @@
37 */ 37 */
38#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) 38#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
39 39
40#define DEFAULT_NUM_PEERS 4; 40#define DEFAULT_NUM_PEERS 4
41
42#define MAX_OUTSTANDING_CONNECTIONS 300
41 43
42static float fail_percentage = 0.05; 44static float fail_percentage = 0.05;
43 45
@@ -75,12 +77,25 @@ static char *topology_string;
75 77
76static int transmit_ready_scheduled; 78static int transmit_ready_scheduled;
77 79
78static int transmit_ready_called; 80static int transmit_ready_failed;
79 81
80struct TestMessageContext *global_pos; 82static int transmit_ready_called;
81 83
82#define MTYPE 12345 84#define MTYPE 12345
83 85
86struct GNUNET_TestMessage
87{
88 /**
89 * Header of the message
90 */
91 struct GNUNET_MessageHeader header;
92
93 /**
94 * Unique identifier for this message.
95 */
96 uint32_t uid;
97};
98
84struct TestMessageContext 99struct TestMessageContext
85{ 100{
86 /* This is a linked list */ 101 /* This is a linked list */
@@ -98,46 +113,45 @@ struct TestMessageContext
98 /* Handle to the receiving peer daemon */ 113 /* Handle to the receiving peer daemon */
99 struct GNUNET_TESTING_Daemon *peer2; 114 struct GNUNET_TESTING_Daemon *peer2;
100 115
101 /* Maintain some state */ 116 /* Identifier for this message, so we don't disconnect other peers! */
102 int first_step_done; 117 uint32_t uid;
103 118
104}; 119};
105 120
106struct Connection
107{
108 struct Connection *next;
109 struct GNUNET_TESTING_Daemon *peer;
110 struct GNUNET_CORE_Handle *server;
111};
112
113static struct Connection *global_connections;
114
115static struct TestMessageContext *test_messages; 121static struct TestMessageContext *test_messages;
116 122
117static void 123static void
118finish_testing () 124finish_testing ()
119{ 125{
120 GNUNET_assert (pg != NULL); 126 GNUNET_assert (pg != NULL);
121 struct Connection *pos; 127 struct TestMessageContext *pos;
128 struct TestMessageContext *free_pos;
122#if VERBOSE 129#if VERBOSE
123 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
124 "Called finish testing, stopping daemons.\n"); 131 "Called finish testing, stopping daemons.\n");
125#endif 132#endif
126 int count; 133 int count;
127 count = 0; 134 count = 0;
128 pos = global_connections; 135 pos = test_messages;
129 while (pos != NULL) 136 while (pos != NULL)
130 { 137 {
131 if (pos->server != NULL) 138 if (pos->peer1handle != NULL)
139 {
140 GNUNET_CORE_disconnect(pos->peer1handle);
141 pos->peer1handle = NULL;
142 }
143 if (pos->peer2handle != NULL)
132 { 144 {
133 GNUNET_CORE_disconnect(pos->server); 145 GNUNET_CORE_disconnect(pos->peer2handle);
134 pos->server = NULL; 146 pos->peer2handle = NULL;
135 } 147 }
148 free_pos = pos;
136 pos = pos->next; 149 pos = pos->next;
150 GNUNET_free(free_pos);
137 } 151 }
138#if VERBOSE 152#if VERBOSE
139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
140 "transmit_ready's scheduled %d, transmit_ready's called %d\n", transmit_ready_scheduled, transmit_ready_called); 154 "transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", transmit_ready_scheduled, transmit_ready_failed, transmit_ready_called);
141#endif 155#endif
142 sleep(1); 156 sleep(1);
143#if VERBOSE 157#if VERBOSE
@@ -158,6 +172,32 @@ finish_testing ()
158 ok = 0; 172 ok = 0;
159} 173}
160 174
175
176static void
177disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
178{
179 struct TestMessageContext *pos = cls;
180
181 /* Disconnect from the respective cores */
182#if VERBOSE
183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
184 "Disconnecting from peer 1 `%4s'\n", GNUNET_i2s (&pos->peer1->id));
185#endif
186 if (pos->peer1handle != NULL)
187 GNUNET_CORE_disconnect(pos->peer1handle);
188#if VERBOSE
189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
190 "Disconnecting from peer 2 `%4s'\n", GNUNET_i2s (&pos->peer2->id));
191#endif
192 if (pos->peer2handle != NULL)
193 GNUNET_CORE_disconnect(pos->peer2handle);
194 /* Set handles to NULL so test case can be ended properly */
195 pos->peer1handle = NULL;
196 pos->peer2handle = NULL;
197 /* Decrement total connections so new can be established */
198 total_server_connections -= 2;
199}
200
161static int 201static int
162process_mtype (void *cls, 202process_mtype (void *cls,
163 const struct GNUNET_PeerIdentity *peer, 203 const struct GNUNET_PeerIdentity *peer,
@@ -165,6 +205,11 @@ process_mtype (void *cls,
165 struct GNUNET_TIME_Relative latency, 205 struct GNUNET_TIME_Relative latency,
166 uint32_t distance) 206 uint32_t distance)
167{ 207{
208 struct TestMessageContext *pos = cls;
209 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message;
210 if (pos->uid != ntohl(msg->uid))
211 return GNUNET_OK;
212
168 total_messages_received++; 213 total_messages_received++;
169#if VERBOSE 214#if VERBOSE
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -178,6 +223,11 @@ process_mtype (void *cls,
178 GNUNET_SCHEDULER_cancel (sched, die_task); 223 GNUNET_SCHEDULER_cancel (sched, die_task);
179 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL); 224 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
180 } 225 }
226 else
227 {
228 GNUNET_SCHEDULER_add_now(sched, &disconnect_cores, pos);
229 }
230
181 return GNUNET_OK; 231 return GNUNET_OK;
182} 232}
183 233
@@ -187,17 +237,25 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
187 char *msg = cls; 237 char *msg = cls;
188 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 238 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
189 "End badly was called (%s)... stopping daemons.\n", msg); 239 "End badly was called (%s)... stopping daemons.\n", msg);
190 struct Connection *pos; 240 struct TestMessageContext *pos;
241 struct TestMessageContext *free_pos;
191 242
192 pos = global_connections; 243 pos = test_messages;
193 while (pos != NULL) 244 while (pos != NULL)
194 { 245 {
195 if (pos->server != NULL) 246 if (pos->peer1handle != NULL)
247 {
248 GNUNET_CORE_disconnect(pos->peer1handle);
249 pos->peer1handle = NULL;
250 }
251 if (pos->peer2handle != NULL)
196 { 252 {
197 GNUNET_CORE_disconnect(pos->server); 253 GNUNET_CORE_disconnect(pos->peer2handle);
198 pos->server = NULL; 254 pos->peer2handle = NULL;
199 } 255 }
256 free_pos = pos;
200 pos = pos->next; 257 pos = pos->next;
258 GNUNET_free(free_pos);
201 } 259 }
202 260
203 if (pg != NULL) 261 if (pg != NULL)
@@ -216,195 +274,151 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
216} 274}
217 275
218 276
219/**
220 * Forward declaration.
221 */
222static size_t
223transmit_ready (void *cls, size_t size, void *buf);
224
225static void
226schedule_transmission (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
227{
228
229 if (global_pos != NULL)
230 {
231 if (NULL == GNUNET_CORE_notify_transmit_ready (global_pos->peer1handle,
232 0,
233 TIMEOUT,
234 &global_pos->peer2->id,
235 sizeof (struct GNUNET_MessageHeader),
236 &transmit_ready, &global_pos->peer1->id))
237 {
238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
239 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
240 GNUNET_i2s (&global_pos->peer2->id));
241 }
242 else
243 {
244 transmit_ready_scheduled++;
245 }
246 global_pos = global_pos->next;
247 }
248 else
249 {
250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
251 "Transmit ready scheduled on %d messages\n",
252 transmit_ready_scheduled);
253 }
254
255}
256 277
257static size_t 278static size_t
258transmit_ready (void *cls, size_t size, void *buf) 279transmit_ready (void *cls, size_t size, void *buf)
259{ 280{
260 struct GNUNET_MessageHeader *m; 281 struct GNUNET_TestMessage *m;
261#if VERBOSE 282 struct TestMessageContext *pos = cls;
262 struct GNUNET_PeerIdentity *peer = cls;
263#endif
264 GNUNET_assert (buf != NULL);
265 m = (struct GNUNET_MessageHeader *) buf;
266 m->type = htons (MTYPE);
267 m->size = htons (sizeof (struct GNUNET_MessageHeader));
268 283
284 GNUNET_assert (buf != NULL);
285 m = (struct GNUNET_TestMessage *) buf;
286 m->header.type = htons (MTYPE);
287 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
288 m->uid = htonl(pos->uid);
269 transmit_ready_called++; 289 transmit_ready_called++;
270#if VERBOSE 290#if VERBOSE
271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
272 "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n", GNUNET_i2s(peer), transmit_ready_scheduled, transmit_ready_called); 292 "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n", GNUNET_i2s(&pos->peer1->id), transmit_ready_scheduled, transmit_ready_called);
273#endif 293#endif
274 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 50), &schedule_transmission, NULL); 294 return sizeof (struct GNUNET_TestMessage);
275 return sizeof (struct GNUNET_MessageHeader);
276} 295}
277 296
278 297
279static struct GNUNET_CORE_MessageHandler handlers[] = { 298static struct GNUNET_CORE_MessageHandler no_handlers[] = {
280 {&process_mtype, MTYPE, sizeof (struct GNUNET_MessageHeader)},
281 {NULL, 0, 0} 299 {NULL, 0, 0}
282}; 300};
283 301
284 302static struct GNUNET_CORE_MessageHandler handlers[] = {
303 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
304 {NULL, 0, 0}
305};
285 306
286static void 307static void
287send_test_messages () 308init_notify_peer2 (void *cls,
309 struct GNUNET_CORE_Handle *server,
310 const struct GNUNET_PeerIdentity *my_identity,
311 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
288{ 312{
289 struct TestMessageContext *pos; 313 struct TestMessageContext *pos = cls;
290 struct Connection *conn_pos;
291 die_task = GNUNET_SCHEDULER_add_delayed (sched,
292 TEST_TIMEOUT,
293 &end_badly, "from send test messages");
294
295 int count = 0;
296 int conn_count = 0;
297 pos = test_messages;
298 while (pos != NULL)
299 {
300 conn_pos = global_connections;
301 conn_count = 0;
302 while (conn_pos != NULL)
303 {
304 if (conn_pos->peer == pos->peer1)
305 {
306 pos->peer1handle = conn_pos->server;
307 break;
308 }
309 conn_count++;
310 conn_pos = conn_pos->next;
311 }
312 GNUNET_assert(pos->peer1handle != NULL);
313
314 /*
315 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
316 0,
317 TIMEOUT,
318 &pos->peer2->id,
319 sizeof (struct GNUNET_MessageHeader),
320 &transmit_ready, &pos->peer1->id))
321 {
322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
323 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
324 GNUNET_i2s (&pos->peer2->id));
325 }
326 else
327 {
328 transmit_ready_scheduled++;
329 }
330 */
331 pos = pos->next;
332 count++;
333
334 }
335 314
315#if VERBOSE
336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 316 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
337 "Prepared %d messages\n", 317 "Core connection to `%4s' established, scheduling message send\n",
338 count); 318 GNUNET_i2s (my_identity));
339 global_pos = test_messages; 319#endif
320 total_server_connections++;
340 321
341 GNUNET_SCHEDULER_add_now(sched, &schedule_transmission, NULL); 322 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
323 0,
324 TIMEOUT,
325 &pos->peer2->id,
326 sizeof (struct GNUNET_TestMessage),
327 &transmit_ready, pos))
328 {
329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
330 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
331 GNUNET_i2s (&pos->peer2->id));
332 transmit_ready_failed++;
333 }
334 else
335 {
336 transmit_ready_scheduled++;
337 }
342} 338}
343 339
344 340
345
346static void 341static void
347init_notify (void *cls, 342init_notify_peer1 (void *cls,
348 struct GNUNET_CORE_Handle *server, 343 struct GNUNET_CORE_Handle *server,
349 const struct GNUNET_PeerIdentity *my_identity, 344 const struct GNUNET_PeerIdentity *my_identity,
350 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 345 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
351{ 346{
352 struct Connection *connection = cls; 347 struct TestMessageContext *pos = cls;
348 total_server_connections++;
353 349
354#if VERBOSE 350#if VERBOSE
355 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
356 "Core connection to `%4s' established, setting up handles\n", 352 "Core connection to `%4s' established, setting up handles\n",
357 GNUNET_i2s (my_identity)); 353 GNUNET_i2s (my_identity));
358#endif 354#endif
359 connection->server = server;
360 total_server_connections++;
361 355
362 if (total_server_connections == num_peers) 356 /*
363 { 357 * Connect to the receiving peer
364 GNUNET_SCHEDULER_cancel(sched, die_task); 358 */
365 GNUNET_SCHEDULER_add_now(sched, &send_test_messages, NULL); 359 pos->peer2handle = GNUNET_CORE_connect (sched,
366 } 360 pos->peer2->cfg,
361 TIMEOUT,
362 pos,
363 &init_notify_peer2,
364 NULL,
365 NULL,
366 NULL,
367 GNUNET_YES, NULL, GNUNET_YES, handlers);
368
367} 369}
368 370
369 371
370static void 372static void
371setup_handlers () 373send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
372{ 374{
373 int i; 375 struct TestMessageContext *pos = cls;
374 struct Connection *new_connection;
375 376
376 struct GNUNET_TESTING_Daemon *temp_daemon; 377 if ((tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) || (cls == NULL))
377 die_task = GNUNET_SCHEDULER_add_delayed (sched, 378 return;
378 TEST_TIMEOUT,
379 &end_badly, "from setup_handlers");
380 379
380 if (die_task == GNUNET_SCHEDULER_NO_TASK)
381 {
382 die_task = GNUNET_SCHEDULER_add_delayed (sched,
383 TEST_TIMEOUT,
384 &end_badly, "from create topology (timeout)");
385 }
381 386
382 /** 387 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
383 * Set up a single handler for each peer 388 {
389 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
390 &send_test_messages, pos);
391 return; /* Otherwise we'll double schedule messages here! */
392 }
393
394 /*
395 * Connect to the sending peer
384 */ 396 */
385 for (i = 0; i < num_peers; i++) 397 pos->peer1handle = GNUNET_CORE_connect (sched,
398 pos->peer1->cfg,
399 TIMEOUT,
400 pos,
401 &init_notify_peer1,
402 NULL,
403 NULL,
404 NULL,
405 GNUNET_NO, NULL, GNUNET_NO, no_handlers);
406
407 GNUNET_assert(pos->peer1handle != NULL);
408
409 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
386 { 410 {
387 new_connection = GNUNET_malloc(sizeof(struct Connection)); 411 GNUNET_SCHEDULER_add_now (sched,
388 temp_daemon = GNUNET_TESTING_daemon_get(pg, i); 412 &send_test_messages, pos->next);
389 new_connection->peer = temp_daemon; 413 }
390 new_connection->server = NULL; 414 else
391 new_connection->next = global_connections; 415 {
392 global_connections = new_connection; 416 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
393 417 &send_test_messages, pos->next);
394 GNUNET_CORE_connect (sched,
395 temp_daemon->cfg,
396 TIMEOUT,
397 new_connection,
398 &init_notify,
399 NULL,
400 NULL,
401 NULL,
402 GNUNET_YES, NULL, GNUNET_YES, handlers);
403 } 418 }
404} 419}
405 420
406 421
407
408void 422void
409topology_callback (void *cls, 423topology_callback (void *cls,
410 const struct GNUNET_PeerIdentity *first, 424 const struct GNUNET_PeerIdentity *first,
@@ -425,12 +439,10 @@ topology_callback (void *cls,
425 second_daemon->shortname); 439 second_daemon->shortname);
426#endif 440#endif
427 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext)); 441 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
428 temp_context->first_step_done = 0;
429 temp_context->peer1handle = NULL;
430 temp_context->peer1 = first_daemon; 442 temp_context->peer1 = first_daemon;
431 temp_context->peer2 = second_daemon; 443 temp_context->peer2 = second_daemon;
432 temp_context->peer2handle = NULL;
433 temp_context->next = test_messages; 444 temp_context->next = test_messages;
445 temp_context->uid = total_connections;
434 test_messages = temp_context; 446 test_messages = temp_context;
435 447
436 expected_messages++; 448 expected_messages++;
@@ -456,16 +468,16 @@ topology_callback (void *cls,
456#endif 468#endif
457 469
458 GNUNET_SCHEDULER_cancel (sched, die_task); 470 GNUNET_SCHEDULER_cancel (sched, die_task);
459 /* die_task = GNUNET_SCHEDULER_add_now (sched, &setup_handlers, NULL); */ 471 die_task = GNUNET_SCHEDULER_NO_TASK;
460 die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &setup_handlers, NULL); 472 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &send_test_messages, test_messages);
461 } 473 }
462 else if (total_connections + failed_connections == expected_connections) 474 else if (total_connections + failed_connections == expected_connections)
463 { 475 {
464 if (failed_connections < (unsigned int)(fail_percentage * total_connections)) 476 if (failed_connections < (unsigned int)(fail_percentage * total_connections))
465 { 477 {
466 GNUNET_SCHEDULER_cancel (sched, die_task); 478 GNUNET_SCHEDULER_cancel (sched, die_task);
467 /* die_task = GNUNET_SCHEDULER_add_now (sched, &setup_handlers, NULL); */ 479 die_task = GNUNET_SCHEDULER_NO_TASK;
468 die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &setup_handlers, NULL); 480 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &send_test_messages, test_messages);
469 } 481 }
470 else 482 else
471 { 483 {
@@ -541,7 +553,7 @@ my_cb (void *cls,
541 die_task = GNUNET_SCHEDULER_add_delayed (sched, 553 die_task = GNUNET_SCHEDULER_add_delayed (sched,
542 GNUNET_TIME_relative_multiply 554 GNUNET_TIME_relative_multiply
543 (GNUNET_TIME_UNIT_MINUTES, 5), 555 (GNUNET_TIME_UNIT_MINUTES, 5),
544 &end_badly, NULL); 556 &end_badly, "from my_cb");
545 create_topology (); 557 create_topology ();
546 ok = 0; 558 ok = 0;
547 } 559 }
@@ -580,7 +592,7 @@ run (void *cls,
580 die_task = GNUNET_SCHEDULER_add_delayed (sched, 592 die_task = GNUNET_SCHEDULER_add_delayed (sched,
581 GNUNET_TIME_relative_multiply 593 GNUNET_TIME_relative_multiply
582 (GNUNET_TIME_UNIT_MINUTES, 5), 594 (GNUNET_TIME_UNIT_MINUTES, 5),
583 &end_badly, NULL); 595 &end_badly, "didn't start all daemons in reasonable amount of time!!!");
584 596
585 pg = GNUNET_TESTING_daemons_start (sched, cfg, 597 pg = GNUNET_TESTING_daemons_start (sched, cfg,
586 peers_left, &my_cb, NULL, 598 peers_left, &my_cb, NULL,
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 1df3ad68c..fcc8c9767 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -38,6 +38,7 @@
38#include "gnunet_hello_lib.h" 38#include "gnunet_hello_lib.h"
39 39
40#define DEBUG_TESTING GNUNET_NO 40#define DEBUG_TESTING GNUNET_NO
41#define DEBUG_TESTING_RECONNECT GNUNET_YES
41 42
42/** 43/**
43 * How long do we wait after starting gnunet-service-arm 44 * How long do we wait after starting gnunet-service-arm
@@ -64,14 +65,26 @@ static void
64process_hello (void *cls, const struct GNUNET_MessageHeader *message) 65process_hello (void *cls, const struct GNUNET_MessageHeader *message)
65{ 66{
66 struct GNUNET_TESTING_Daemon *daemon = cls; 67 struct GNUNET_TESTING_Daemon *daemon = cls;
67 GNUNET_TRANSPORT_get_hello_cancel(daemon->th, &process_hello, daemon); 68 if (daemon == NULL)
69 return;
70
71 if (daemon->server != NULL)
72 {
73 GNUNET_CORE_disconnect(daemon->server);
74 daemon->server = NULL;
75 }
76
77 GNUNET_assert (message != NULL);
78 if (daemon->th != NULL)
79 {
80 GNUNET_TRANSPORT_get_hello_cancel(daemon->th, &process_hello, daemon);
81 }
68#if DEBUG_TESTING 82#if DEBUG_TESTING
69 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 83 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
70 "Received `%s' from transport service of `%4s'\n", 84 "Received `%s' from transport service of `%4s'\n",
71 "HELLO", GNUNET_i2s (&daemon->id)); 85 "HELLO", GNUNET_i2s (&daemon->id));
72#endif 86#endif
73 87
74 GNUNET_assert (message != NULL);
75 GNUNET_free_non_null(daemon->hello); 88 GNUNET_free_non_null(daemon->hello);
76 daemon->hello = GNUNET_malloc(ntohs(message->size)); 89 daemon->hello = GNUNET_malloc(ntohs(message->size));
77 memcpy(daemon->hello, message, ntohs(message->size)); 90 memcpy(daemon->hello, message, ntohs(message->size));
@@ -126,6 +139,7 @@ testing_init (void *cls,
126 d->id = *my_identity; 139 d->id = *my_identity;
127 d->shortname = strdup (GNUNET_i2s (my_identity)); 140 d->shortname = strdup (GNUNET_i2s (my_identity));
128 d->server = server; 141 d->server = server;
142 d->running = GNUNET_YES;
129 if (GNUNET_YES == d->dead) 143 if (GNUNET_YES == d->dead)
130 GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls); 144 GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls);
131 else if (NULL != cb) 145 else if (NULL != cb)
@@ -344,6 +358,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
344 } 358 }
345 GNUNET_CONFIGURATION_destroy (d->cfg); 359 GNUNET_CONFIGURATION_destroy (d->cfg);
346 GNUNET_free (d->cfgfile); 360 GNUNET_free (d->cfgfile);
361 GNUNET_free_non_null(d->hello);
347 GNUNET_free_non_null (d->hostname); 362 GNUNET_free_non_null (d->hostname);
348 GNUNET_free_non_null (d->username); 363 GNUNET_free_non_null (d->username);
349 GNUNET_free_non_null (d->shortname); 364 GNUNET_free_non_null (d->shortname);
@@ -370,6 +385,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
370 } 385 }
371 GNUNET_CONFIGURATION_destroy (d->cfg); 386 GNUNET_CONFIGURATION_destroy (d->cfg);
372 GNUNET_free (d->cfgfile); 387 GNUNET_free (d->cfgfile);
388 GNUNET_free_non_null(d->hello);
373 GNUNET_free_non_null (d->hostname); 389 GNUNET_free_non_null (d->hostname);
374 GNUNET_free_non_null (d->username); 390 GNUNET_free_non_null (d->username);
375 GNUNET_free_non_null (d->shortname); 391 GNUNET_free_non_null (d->shortname);
@@ -388,6 +404,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
388 /* state clean up and notifications */ 404 /* state clean up and notifications */
389 GNUNET_CONFIGURATION_destroy (d->cfg); 405 GNUNET_CONFIGURATION_destroy (d->cfg);
390 GNUNET_free (d->cfgfile); 406 GNUNET_free (d->cfgfile);
407 GNUNET_free_non_null(d->hello);
391 GNUNET_free_non_null (d->hostname); 408 GNUNET_free_non_null (d->hostname);
392 GNUNET_free_non_null (d->username); 409 GNUNET_free_non_null (d->username);
393 GNUNET_free_non_null (d->shortname); 410 GNUNET_free_non_null (d->shortname);
@@ -633,14 +650,11 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
633 "-c", d->cfgfile, "-e", "-d", "-q", NULL); 650 "-c", d->cfgfile, "-e", "-d", "-q", NULL);
634 } 651 }
635 652
636 GNUNET_free_non_null(d->hello);
637
638 d->wait_runs = 0; 653 d->wait_runs = 0;
639 d->task 654 d->task
640 = GNUNET_SCHEDULER_add_delayed (d->sched, 655 = GNUNET_SCHEDULER_add_delayed (d->sched,
641 GNUNET_CONSTANTS_EXEC_WAIT, 656 GNUNET_CONSTANTS_EXEC_WAIT,
642 &start_fsm, d); 657 &start_fsm, d);
643 return;
644} 658}
645 659
646 660
@@ -820,6 +834,12 @@ notify_connect_result (void *cls,
820 ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; 834 ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
821 } 835 }
822 836
837 if ((ctx->timeout_task != GNUNET_SCHEDULER_NO_TASK) && (tc->reason != GNUNET_SCHEDULER_REASON_TIMEOUT))
838 {
839 GNUNET_SCHEDULER_cancel(ctx->d1->sched, ctx->timeout_task);
840 ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK;
841 }
842
823 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) 843 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
824 { 844 {
825 if (ctx->d2th != NULL) 845 if (ctx->d2th != NULL)
@@ -842,10 +862,20 @@ notify_connect_result (void *cls,
842 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg, 862 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg,
843 ctx->d2->cfg, ctx->d1, ctx->d2, NULL); 863 ctx->d2->cfg, ctx->d1, ctx->d2, NULL);
844 } 864 }
845 GNUNET_SCHEDULER_cancel(ctx->d1->sched, ctx->timeout_task);
846 } 865 }
847 else if (remaining.value > 0) 866 else if (remaining.value > 0)
848 { 867 {
868 if (ctx->d1core != NULL)
869 {
870 GNUNET_CORE_disconnect(ctx->d1core);
871 ctx->d1core = NULL;
872 }
873
874 if (ctx->d2th != NULL)
875 {
876 GNUNET_TRANSPORT_disconnect(ctx->d2th);
877 ctx->d2th = NULL;
878 }
849 GNUNET_SCHEDULER_add_now(ctx->d1->sched, &reattempt_daemons_connect, ctx); 879 GNUNET_SCHEDULER_add_now(ctx->d1->sched, &reattempt_daemons_connect, ctx);
850 return; 880 return;
851 } 881 }
@@ -859,7 +889,6 @@ notify_connect_result (void *cls,
859 } 889 }
860 } 890 }
861 891
862
863 GNUNET_TRANSPORT_disconnect (ctx->d2th); 892 GNUNET_TRANSPORT_disconnect (ctx->d2th);
864 ctx->d2th = NULL; 893 ctx->d2th = NULL;
865 GNUNET_CORE_disconnect (ctx->d1core); 894 GNUNET_CORE_disconnect (ctx->d1core);
@@ -886,6 +915,8 @@ connect_notify (void *cls, const struct GNUNET_PeerIdentity * peer, struct GNUNE
886 if (memcmp(&ctx->d2->id, peer, sizeof(struct GNUNET_PeerIdentity)) == 0) 915 if (memcmp(&ctx->d2->id, peer, sizeof(struct GNUNET_PeerIdentity)) == 0)
887 { 916 {
888 ctx->connected = GNUNET_YES; 917 ctx->connected = GNUNET_YES;
918 GNUNET_SCHEDULER_cancel(ctx->d1->sched, ctx->timeout_task);
919 ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK;
889 GNUNET_SCHEDULER_add_now (ctx->d1->sched, 920 GNUNET_SCHEDULER_add_now (ctx->d1->sched,
890 &notify_connect_result, 921 &notify_connect_result,
891 ctx); 922 ctx);
@@ -935,7 +966,7 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
935{ 966{
936 struct ConnectContext *ctx; 967 struct ConnectContext *ctx;
937 968
938 if ((d1->server == NULL) || (d2->server == NULL)) 969 if ((d1->running == GNUNET_NO) || (d2->running == GNUNET_NO))
939 { 970 {
940 if (NULL != cb) 971 if (NULL != cb)
941 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2, 972 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
@@ -988,6 +1019,7 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
988 d2->cfg, d2, NULL, NULL, NULL); 1019 d2->cfg, d2, NULL, NULL, NULL);
989 if (ctx->d2th == NULL) 1020 if (ctx->d2th == NULL)
990 { 1021 {
1022 GNUNET_CORE_disconnect(ctx->d1core);
991 GNUNET_free (ctx); 1023 GNUNET_free (ctx);
992 if (NULL != cb) 1024 if (NULL != cb)
993 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2, 1025 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
@@ -1011,22 +1043,12 @@ reattempt_daemons_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext
1011 { 1043 {
1012 return; 1044 return;
1013 } 1045 }
1014#if DEBUG_TESTING 1046#if DEBUG_TESTING_RECONNECT
1015 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "re-attempting connect of peer %s to peer %s\n", 1047 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "re-attempting connect of peer %s to peer %s\n",
1016 ctx->d1->shortname, ctx->d2->shortname); 1048 ctx->d1->shortname, ctx->d2->shortname);
1017#endif 1049#endif
1018 1050
1019 if (ctx->d1core != NULL) 1051 GNUNET_assert(ctx->d1core == NULL);
1020 {
1021 GNUNET_CORE_disconnect(ctx->d1core);
1022 ctx->d1core = NULL;
1023 }
1024
1025 if (ctx->d2th != NULL)
1026 {
1027 GNUNET_TRANSPORT_disconnect(ctx->d2th);
1028 ctx->d2th = NULL;
1029 }
1030 1052
1031 ctx->d1core = GNUNET_CORE_connect (ctx->d1->sched, 1053 ctx->d1core = GNUNET_CORE_connect (ctx->d1->sched,
1032 ctx->d1->cfg, 1054 ctx->d1->cfg,
@@ -1049,6 +1071,7 @@ reattempt_daemons_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext
1049 ctx->d2->cfg, ctx->d2, NULL, NULL, NULL); 1071 ctx->d2->cfg, ctx->d2, NULL, NULL, NULL);
1050 if (ctx->d2th == NULL) 1072 if (ctx->d2th == NULL)
1051 { 1073 {
1074 GNUNET_CORE_disconnect(ctx->d1core);
1052 GNUNET_free (ctx); 1075 GNUNET_free (ctx);
1053 if (NULL != ctx->cb) 1076 if (NULL != ctx->cb)
1054 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, 1077 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2,
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c
index 49ab8a349..136b167fb 100644
--- a/src/testing/testing_group.c
+++ b/src/testing/testing_group.c
@@ -84,7 +84,6 @@ struct PeerData
84 84
85 /* 85 /*
86 * Linked list of peer connections (simply indexes of PeerGroup) 86 * Linked list of peer connections (simply indexes of PeerGroup)
87 * FIXME: Question, store pointer or integer? Pointer for now...
88 */ 87 */
89 struct PeerConnection *connected_peers; 88 struct PeerConnection *connected_peers;
90}; 89};
@@ -255,7 +254,7 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, uint16_t * port, con
255 254
256 if (GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "control_host", &control_host) == GNUNET_OK) 255 if (GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "control_host", &control_host) == GNUNET_OK)
257 { 256 {
258 GNUNET_asprintf(&allowed_hosts, "%s 127.0.0.1;", control_host); 257 GNUNET_asprintf(&allowed_hosts, "%s; 127.0.0.1;", control_host);
259 GNUNET_CONFIGURATION_set_value_string(uc.ret, "core", "ACCEPT_FROM", allowed_hosts); 258 GNUNET_CONFIGURATION_set_value_string(uc.ret, "core", "ACCEPT_FROM", allowed_hosts);
260 GNUNET_free_non_null(control_host); 259 GNUNET_free_non_null(control_host);
261 GNUNET_free(allowed_hosts); 260 GNUNET_free(allowed_hosts);
@@ -957,6 +956,10 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg)
957 } 956 }
958 } 957 }
959 958
959#if VERBOSE_TESTING
960 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
961 _("Finished copying all friend files!\n"));
962#endif
960 GNUNET_free(pidarr); 963 GNUNET_free(pidarr);
961 return ret; 964 return ret;
962} 965}