diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-11-21 22:02:20 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-11-21 22:02:20 +0000 |
commit | ffabb052fa64eded69dffa1387b72df0ad1b0211 (patch) | |
tree | fb5fb6a36a0f885adcc7c44e84347a1cfa7e75b8 /src/transport/transport-testing.c | |
parent | d3871e80fec5e7fcd5ff7cc7ff64284bb7051b38 (diff) | |
download | gnunet-ffabb052fa64eded69dffa1387b72df0ad1b0211.tar.gz gnunet-ffabb052fa64eded69dffa1387b72df0ad1b0211.zip |
transport testing:
peer restart functionality
+ testcases if peers reconnect when restarted
Diffstat (limited to 'src/transport/transport-testing.c')
-rw-r--r-- | src/transport/transport-testing.c | 101 |
1 files changed, 98 insertions, 3 deletions
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c index 6892b2556..28d0db256 100644 --- a/src/transport/transport-testing.c +++ b/src/transport/transport-testing.c | |||
@@ -283,11 +283,10 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle | |||
283 | struct PeerContext *p = GNUNET_malloc (sizeof (struct PeerContext)); | 283 | struct PeerContext *p = GNUNET_malloc (sizeof (struct PeerContext)); |
284 | 284 | ||
285 | p->cfg = GNUNET_CONFIGURATION_create (); | 285 | p->cfg = GNUNET_CONFIGURATION_create (); |
286 | |||
287 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 286 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
288 | 287 | ||
289 | 288 | if (GNUNET_CONFIGURATION_have_value (p-> | |
290 | if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME")) | 289 | cfg, "PATHS", "SERVICEHOME")) |
291 | GNUNET_assert (GNUNET_OK == | 290 | GNUNET_assert (GNUNET_OK == |
292 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", | 291 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", |
293 | "SERVICEHOME", | 292 | "SERVICEHOME", |
@@ -350,6 +349,100 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle | |||
350 | } | 349 | } |
351 | 350 | ||
352 | /** | 351 | /** |
352 | * Restart the given peer | ||
353 | * @param tth testing handle | ||
354 | * @param p the peer | ||
355 | */ | ||
356 | void | ||
357 | GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, | ||
358 | struct PeerContext *p, | ||
359 | const char *cfgname) | ||
360 | { | ||
361 | GNUNET_assert (p != NULL); | ||
362 | /* shutdown */ | ||
363 | #if VERBOSE | ||
364 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | ||
365 | "Stopping peer %u (`%s')\n", p->no, | ||
366 | GNUNET_i2s (&p->id)); | ||
367 | #endif | ||
368 | if (p->ghh != NULL) | ||
369 | GNUNET_TRANSPORT_get_hello_cancel (p->ghh); | ||
370 | p->ghh = NULL; | ||
371 | |||
372 | if (p->th != NULL) | ||
373 | GNUNET_TRANSPORT_disconnect (p->th); | ||
374 | |||
375 | if (NULL != p->arm_proc) | ||
376 | { | ||
377 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | ||
378 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
379 | GNUNET_OS_process_wait (p->arm_proc); | ||
380 | GNUNET_OS_process_close (p->arm_proc); | ||
381 | p->arm_proc = NULL; | ||
382 | } | ||
383 | if (p->hello != NULL) | ||
384 | GNUNET_free (p->hello); | ||
385 | p->hello = NULL; | ||
386 | |||
387 | if (p->cfg != NULL) | ||
388 | GNUNET_CONFIGURATION_destroy (p->cfg); | ||
389 | p->cfg = NULL; | ||
390 | |||
391 | /* start */ | ||
392 | #if VERBOSE | ||
393 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | ||
394 | "Restarting peer %u (`%s')\n", p->no, | ||
395 | GNUNET_i2s (&p->id)); | ||
396 | #endif | ||
397 | struct GNUNET_DISK_FileHandle *fn; | ||
398 | |||
399 | GNUNET_assert (tth != NULL); | ||
400 | if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO) | ||
401 | { | ||
402 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", | ||
403 | "File not found: `%s' \n", cfgname); | ||
404 | return; | ||
405 | } | ||
406 | |||
407 | p->cfg = GNUNET_CONFIGURATION_create (); | ||
408 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | ||
409 | if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME")) | ||
410 | GNUNET_assert (GNUNET_OK == | ||
411 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", | ||
412 | "SERVICEHOME", | ||
413 | &p->servicehome)); | ||
414 | |||
415 | GNUNET_assert (p->hostkeyfile != NULL); | ||
416 | GNUNET_asprintf (&p->hostkeyfile, "%s/.hostkey", p->servicehome); | ||
417 | fn = GNUNET_DISK_file_open (p->hostkeyfile, | ||
418 | GNUNET_DISK_OPEN_READWRITE | | ||
419 | GNUNET_DISK_OPEN_CREATE, | ||
420 | GNUNET_DISK_PERM_USER_READ | | ||
421 | GNUNET_DISK_PERM_USER_WRITE); | ||
422 | GNUNET_assert (fn != NULL); | ||
423 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fn)); | ||
424 | |||
425 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | ||
426 | "gnunet-service-arm", "-c", cfgname, | ||
427 | #if VERBOSE_PEERS | ||
428 | "-L", "DEBUG", | ||
429 | #else | ||
430 | "-L", "ERROR", | ||
431 | #endif | ||
432 | NULL); | ||
433 | |||
434 | p->th = | ||
435 | GNUNET_TRANSPORT_connect (p->cfg, NULL, p, ¬ify_receive, | ||
436 | ¬ify_connect, ¬ify_disconnect); | ||
437 | GNUNET_assert (p->th != NULL); | ||
438 | |||
439 | p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &get_hello, p); | ||
440 | GNUNET_assert (p->ghh != NULL); | ||
441 | |||
442 | return ; | ||
443 | } | ||
444 | |||
445 | /** | ||
353 | * shutdown the given peer | 446 | * shutdown the given peer |
354 | * @param p the peer | 447 | * @param p the peer |
355 | */ | 448 | */ |
@@ -389,9 +482,11 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, | |||
389 | 482 | ||
390 | if (p->hello != NULL) | 483 | if (p->hello != NULL) |
391 | GNUNET_free (p->hello); | 484 | GNUNET_free (p->hello); |
485 | p->hello = NULL; | ||
392 | 486 | ||
393 | if (p->cfg != NULL) | 487 | if (p->cfg != NULL) |
394 | GNUNET_CONFIGURATION_destroy (p->cfg); | 488 | GNUNET_CONFIGURATION_destroy (p->cfg); |
489 | p->cfg = NULL; | ||
395 | 490 | ||
396 | GNUNET_CONTAINER_DLL_remove (tth->p_head, tth->p_tail, p); | 491 | GNUNET_CONTAINER_DLL_remove (tth->p_head, tth->p_tail, p); |
397 | 492 | ||