diff options
-rw-r--r-- | src/include/gnunet_testbed_service.h | 1 | ||||
-rw-r--r-- | src/testbed/Makefile.am | 1 | ||||
-rw-r--r-- | src/testbed/gnunet-service-testbed.c | 34 | ||||
-rw-r--r-- | src/testbed/test_testbed_api.c | 19 | ||||
-rw-r--r-- | src/testbed/test_testbed_api_hosts.c | 5 | ||||
-rw-r--r-- | src/testbed/testbed_api.c | 83 |
6 files changed, 122 insertions, 21 deletions
diff --git a/src/include/gnunet_testbed_service.h b/src/include/gnunet_testbed_service.h index 46be98b79..736a0c03c 100644 --- a/src/include/gnunet_testbed_service.h +++ b/src/include/gnunet_testbed_service.h | |||
@@ -29,6 +29,7 @@ | |||
29 | #define GNUNET_TESTBED_SERVICE_H | 29 | #define GNUNET_TESTBED_SERVICE_H |
30 | 30 | ||
31 | #include "gnunet_util_lib.h" | 31 | #include "gnunet_util_lib.h" |
32 | #include "gnunet_testing_lib-new.h" | ||
32 | 33 | ||
33 | #ifdef __cplusplus | 34 | #ifdef __cplusplus |
34 | extern "C" | 35 | extern "C" |
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am index a4e1b2a01..b6e42276e 100644 --- a/src/testbed/Makefile.am +++ b/src/testbed/Makefile.am | |||
@@ -46,6 +46,7 @@ libgnunettestbed_la_LIBADD = $(XLIB) \ | |||
46 | $(top_builddir)/src/hello/libgnunethello.la \ | 46 | $(top_builddir)/src/hello/libgnunethello.la \ |
47 | -lm \ | 47 | -lm \ |
48 | $(top_builddir)/src/util/libgnunetutil.la \ | 48 | $(top_builddir)/src/util/libgnunetutil.la \ |
49 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
49 | $(LTLIBINTL) | 50 | $(LTLIBINTL) |
50 | libgnunettestbed_la_LDFLAGS = \ | 51 | libgnunettestbed_la_LDFLAGS = \ |
51 | $(GN_LIB_LDFLAGS) \ | 52 | $(GN_LIB_LDFLAGS) \ |
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index 9ba145abe..0619a67cb 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c | |||
@@ -385,6 +385,11 @@ static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id; | |||
385 | */ | 385 | */ |
386 | static struct GNUNET_TESTING_System *test_system; | 386 | static struct GNUNET_TESTING_System *test_system; |
387 | 387 | ||
388 | /** | ||
389 | * Our configuration; we also use this as template for starting other controllers | ||
390 | */ | ||
391 | static struct GNUNET_CONFIGURATION_Handle *config; | ||
392 | |||
388 | 393 | ||
389 | /** | 394 | /** |
390 | * Function called to notify a client about the connection begin ready to queue | 395 | * Function called to notify a client about the connection begin ready to queue |
@@ -692,6 +697,27 @@ slave_event_callback(void *cls, | |||
692 | } | 697 | } |
693 | 698 | ||
694 | 699 | ||
700 | /** | ||
701 | * Callback for unexpected slave shutdowns | ||
702 | * | ||
703 | * @param cls closure | ||
704 | * @param emsg error message if available; can be NULL, which does NOT mean | ||
705 | * that there was no error | ||
706 | */ | ||
707 | static void | ||
708 | slave_shutdown_handler (void *cls, const char *emsg) | ||
709 | { | ||
710 | struct Slave *slave; | ||
711 | |||
712 | slave = (struct Slave *) cls; | ||
713 | slave->controller_proc = NULL; | ||
714 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
715 | "Unexpected slave shutdown\n"); | ||
716 | if (NULL != emsg) | ||
717 | LOG (GNUNET_ERROR_TYPE_WARNING, "Error: %s\n", emsg); | ||
718 | GNUNET_SCHEDULER_shutdown (); /* We too shutdown */ | ||
719 | } | ||
720 | |||
695 | 721 | ||
696 | /** | 722 | /** |
697 | * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages | 723 | * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages |
@@ -1011,7 +1037,10 @@ handle_link_controllers (void *cls, | |||
1011 | if (1 == msg->is_subordinate) | 1037 | if (1 == msg->is_subordinate) |
1012 | { | 1038 | { |
1013 | slave->controller_proc = | 1039 | slave->controller_proc = |
1014 | GNUNET_TESTBED_controller_start (host_list[delegated_host_id]); | 1040 | GNUNET_TESTBED_controller_start (test_system, |
1041 | host_list[delegated_host_id], | ||
1042 | cfg, &slave_shutdown_handler, | ||
1043 | slave); | ||
1015 | } | 1044 | } |
1016 | slave->controller = | 1045 | slave->controller = |
1017 | GNUNET_TESTBED_controller_connect (cfg, host_list[delegated_host_id], | 1046 | GNUNET_TESTBED_controller_connect (cfg, host_list[delegated_host_id], |
@@ -1378,13 +1407,14 @@ testbed_run (void *cls, | |||
1378 | {NULL} | 1407 | {NULL} |
1379 | }; | 1408 | }; |
1380 | 1409 | ||
1410 | config = GNUNET_CONFIGURATION_dup (cfg); | ||
1381 | GNUNET_SERVER_add_handlers (server, | 1411 | GNUNET_SERVER_add_handlers (server, |
1382 | message_handlers); | 1412 | message_handlers); |
1383 | GNUNET_SERVER_disconnect_notify (server, | 1413 | GNUNET_SERVER_disconnect_notify (server, |
1384 | &client_disconnect_cb, | 1414 | &client_disconnect_cb, |
1385 | NULL); | 1415 | NULL); |
1386 | ss_map = GNUNET_CONTAINER_multihashmap_create (5); | 1416 | ss_map = GNUNET_CONTAINER_multihashmap_create (5); |
1387 | test_system = GNUNET_TESTING_system_create ("testbed_peers", NULL); | 1417 | test_system = GNUNET_TESTING_system_create ("testbed", NULL); |
1388 | 1418 | ||
1389 | fh = GNUNET_DISK_get_handle_from_native (stdin); | 1419 | fh = GNUNET_DISK_get_handle_from_native (stdin); |
1390 | if (NULL == fh) | 1420 | if (NULL == fh) |
diff --git a/src/testbed/test_testbed_api.c b/src/testbed/test_testbed_api.c index 1fdb7169a..849f5ddd4 100644 --- a/src/testbed/test_testbed_api.c +++ b/src/testbed/test_testbed_api.c | |||
@@ -43,6 +43,11 @@ | |||
43 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) | 43 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * The testing system we work with | ||
47 | */ | ||
48 | struct GNUNET_TESTING_System *test_system; | ||
49 | |||
50 | /** | ||
46 | * Our localhost | 51 | * Our localhost |
47 | */ | 52 | */ |
48 | static struct GNUNET_TESTBED_Host *host; | 53 | static struct GNUNET_TESTBED_Host *host; |
@@ -75,7 +80,7 @@ static struct GNUNET_TESTBED_Peer *peer; | |||
75 | /** | 80 | /** |
76 | * Handle to configuration | 81 | * Handle to configuration |
77 | */ | 82 | */ |
78 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 83 | static struct GNUNET_CONFIGURATION_Handle *cfg; |
79 | 84 | ||
80 | /** | 85 | /** |
81 | * Handle to operation | 86 | * Handle to operation |
@@ -107,10 +112,12 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
107 | if (NULL != reg_handle) | 112 | if (NULL != reg_handle) |
108 | GNUNET_TESTBED_cancel_registration (reg_handle); | 113 | GNUNET_TESTBED_cancel_registration (reg_handle); |
109 | GNUNET_TESTBED_controller_disconnect (controller); | 114 | GNUNET_TESTBED_controller_disconnect (controller); |
115 | GNUNET_CONFIGURATION_destroy (cfg); | ||
110 | if (NULL != cp) | 116 | if (NULL != cp) |
111 | GNUNET_TESTBED_controller_stop (cp); | 117 | GNUNET_TESTBED_controller_stop (cp); |
112 | GNUNET_TESTBED_host_destroy (neighbour); | 118 | GNUNET_TESTBED_host_destroy (neighbour); |
113 | GNUNET_TESTBED_host_destroy (host); | 119 | GNUNET_TESTBED_host_destroy (host); |
120 | GNUNET_TESTING_system_destroy (test_system, GNUNET_YES); | ||
114 | } | 121 | } |
115 | 122 | ||
116 | 123 | ||
@@ -182,19 +189,19 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
182 | const struct GNUNET_CONFIGURATION_Handle *config) | 189 | const struct GNUNET_CONFIGURATION_Handle *config) |
183 | { | 190 | { |
184 | uint64_t event_mask; | 191 | uint64_t event_mask; |
185 | struct GNUNET_CONFIGURATION_Handle *cdup; | ||
186 | 192 | ||
187 | cfg = config; | 193 | test_system = GNUNET_TESTING_system_create ("test_testbed", |
194 | "127.0.0.1"); | ||
188 | host = GNUNET_TESTBED_host_create (NULL, NULL, 0); | 195 | host = GNUNET_TESTBED_host_create (NULL, NULL, 0); |
189 | GNUNET_assert (NULL != host); | 196 | GNUNET_assert (NULL != host); |
190 | cdup = GNUNET_CONFIGURATION_dup (config); | 197 | cfg = GNUNET_CONFIGURATION_dup (config); |
191 | cp = GNUNET_TESTBED_controller_start (system, host, cdup, NULL, NULL); | 198 | cp = GNUNET_TESTBED_controller_start (test_system, host, cfg, NULL, NULL); |
192 | event_mask = 0; | 199 | event_mask = 0; |
193 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); | 200 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); |
194 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); | 201 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); |
195 | event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); | 202 | event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); |
196 | event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); | 203 | event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); |
197 | controller = GNUNET_TESTBED_controller_connect (config, host, event_mask, | 204 | controller = GNUNET_TESTBED_controller_connect (cfg, host, event_mask, |
198 | &controller_cb, NULL); | 205 | &controller_cb, NULL); |
199 | GNUNET_assert (NULL != controller); | 206 | GNUNET_assert (NULL != controller); |
200 | neighbour = GNUNET_TESTBED_host_create ("localhost", NULL, 0); | 207 | neighbour = GNUNET_TESTBED_host_create ("localhost", NULL, 0); |
diff --git a/src/testbed/test_testbed_api_hosts.c b/src/testbed/test_testbed_api_hosts.c index 2528e7aff..340e2491a 100644 --- a/src/testbed/test_testbed_api_hosts.c +++ b/src/testbed/test_testbed_api_hosts.c | |||
@@ -70,7 +70,8 @@ static void | |||
70 | run (void *cls, char *const *args, const char *cfgfile, | 70 | run (void *cls, char *const *args, const char *cfgfile, |
71 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 71 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
72 | { | 72 | { |
73 | char *const binary_args[] = {NULL}; | 73 | char *const binary_args[] = {"gnunet-service-testbed", |
74 | NULL}; | ||
74 | 75 | ||
75 | host = GNUNET_TESTBED_host_create ("localhost", NULL, 0); | 76 | host = GNUNET_TESTBED_host_create ("localhost", NULL, 0); |
76 | GNUNET_assert (NULL != host); | 77 | GNUNET_assert (NULL != host); |
@@ -82,7 +83,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
82 | GNUNET_assert (host == GNUNET_TESTBED_host_lookup_by_id_ (0)); | 83 | GNUNET_assert (host == GNUNET_TESTBED_host_lookup_by_id_ (0)); |
83 | helper_handle = GNUNET_TESTBED_host_run_ (host, binary_args); | 84 | helper_handle = GNUNET_TESTBED_host_run_ (host, binary_args); |
84 | GNUNET_assert (NULL != helper_handle); | 85 | GNUNET_assert (NULL != helper_handle); |
85 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (2), &do_shutdown, NULL); | 86 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (1), &do_shutdown, NULL); |
86 | } | 87 | } |
87 | 88 | ||
88 | 89 | ||
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index dfec11f94..5070d4f29 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -329,6 +329,7 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
329 | } | 329 | } |
330 | } | 330 | } |
331 | 331 | ||
332 | |||
332 | /** | 333 | /** |
333 | * Function called to notify a client about the connection begin ready to queue | 334 | * Function called to notify a client about the connection begin ready to queue |
334 | * more data. "buf" will be NULL and "size" zero if the connection was closed | 335 | * more data. "buf" will be NULL and "size" zero if the connection was closed |
@@ -433,25 +434,85 @@ struct GNUNET_TESTBED_ControllerProc | |||
433 | 434 | ||
434 | 435 | ||
435 | /** | 436 | /** |
437 | * Context to use while starting a controller | ||
438 | */ | ||
439 | struct ControllerStartContext | ||
440 | { | ||
441 | /** | ||
442 | * The error callback | ||
443 | */ | ||
444 | GNUNET_TESTBED_ControllerErrorCallback cec; | ||
445 | |||
446 | /** | ||
447 | * Closure for the above callback | ||
448 | */ | ||
449 | void *cec_cls; | ||
450 | |||
451 | /** | ||
452 | * error message if any | ||
453 | */ | ||
454 | char *emsg; | ||
455 | }; | ||
456 | |||
457 | |||
458 | /** | ||
436 | * Starts a controller process at the host | 459 | * Starts a controller process at the host |
437 | * | 460 | * |
461 | * @param system used for reserving ports if host is NULL and to determine | ||
462 | * which 'host' to set as TRUSTED ('controller') when starting testbed remotely | ||
438 | * @param host the host where the controller has to be started; NULL for localhost | 463 | * @param host the host where the controller has to be started; NULL for localhost |
439 | * @return the controller process handle | 464 | * @param cfg template configuration to use for the remote controller; will |
465 | * be modified to contain the actual host/port/unixpath used for | ||
466 | * the testbed service | ||
467 | * @param cec function called if the contoller dies unexpectedly; will not be | ||
468 | * invoked after GNUNET_TESTBED_controller_stop, if 'cec' was called, | ||
469 | * GNUNET_TESTBED_controller_stop must no longer be called; will | ||
470 | * never be called in the same task as 'GNUNET_TESTBED_controller_start' | ||
471 | * (synchronous errors will be signalled by returning NULL) | ||
472 | * @param cec_cls closure for 'cec' | ||
473 | * @return the controller process handle, NULL on errors | ||
440 | */ | 474 | */ |
441 | struct GNUNET_TESTBED_ControllerProc * | 475 | struct GNUNET_TESTBED_ControllerProc * |
442 | GNUNET_TESTBED_controller_start (struct GNUNET_TESTBED_Host *host) | 476 | GNUNET_TESTBED_controller_start (struct GNUNET_TESTING_System *system, |
477 | struct GNUNET_TESTBED_Host *host, | ||
478 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
479 | GNUNET_TESTBED_ControllerErrorCallback cec, | ||
480 | void *cec_cls) | ||
443 | { | 481 | { |
444 | struct GNUNET_TESTBED_ControllerProc *cproc; | 482 | struct GNUNET_TESTBED_ControllerProc *cproc; |
445 | char * const binary_argv[] = { | 483 | //struct ControllerStartContext *csc; |
446 | "gnunet-service-testbed", | 484 | char *cfg_filename; |
447 | NULL | 485 | |
448 | }; | 486 | if ((NULL == host) || (0 == GNUNET_TESTBED_host_get_id_ (host))) |
449 | 487 | { | |
450 | cproc = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ControllerProc)); | 488 | if (GNUNET_OK != GNUNET_TESTING_configuration_create (system, cfg)) |
451 | cproc->helper = GNUNET_TESTBED_host_run_ (host, binary_argv); | 489 | return NULL; |
452 | if (NULL == cproc->helper) | 490 | GNUNET_assert |
491 | (GNUNET_OK == | ||
492 | GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "DEFAULTCONFIG", | ||
493 | &cfg_filename)); | ||
494 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, cfg_filename)) | ||
495 | { | ||
496 | GNUNET_break (0); | ||
497 | return NULL; | ||
498 | } | ||
499 | char * const binary_argv[] = { | ||
500 | "gnunet-service-testbed", | ||
501 | "-c", cfg_filename, | ||
502 | NULL | ||
503 | }; | ||
504 | cproc = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ControllerProc)); | ||
505 | cproc->helper = GNUNET_TESTBED_host_run_ (host, binary_argv); | ||
506 | GNUNET_free (cfg_filename); | ||
507 | if (NULL == cproc->helper) | ||
508 | { | ||
509 | GNUNET_free (cproc); | ||
510 | return NULL; | ||
511 | } | ||
512 | } | ||
513 | else | ||
453 | { | 514 | { |
454 | GNUNET_free (cproc); | 515 | GNUNET_break (0); |
455 | return NULL; | 516 | return NULL; |
456 | } | 517 | } |
457 | return cproc; | 518 | return cproc; |