aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_testing_lib.h34
-rw-r--r--src/testbed/gnunet-helper-testbed.c2
-rw-r--r--src/testbed/gnunet-service-testbed.c2
-rw-r--r--src/testing/gnunet-testing.c5
-rw-r--r--src/testing/test_testing_peerstartup.c2
-rw-r--r--src/testing/test_testing_peerstartup2.c2
-rw-r--r--src/testing/test_testing_portreservation.c2
-rw-r--r--src/testing/testing.c273
-rw-r--r--src/transport/transport-testing.c3
9 files changed, 309 insertions, 16 deletions
diff --git a/src/include/gnunet_testing_lib.h b/src/include/gnunet_testing_lib.h
index d96743615..d4c5b5b37 100644
--- a/src/include/gnunet_testing_lib.h
+++ b/src/include/gnunet_testing_lib.h
@@ -67,6 +67,29 @@ struct GNUNET_TESTING_Peer;
67 67
68 68
69/** 69/**
70 * Specification of a service that is to be shared among peers
71 */
72struct GNUNET_TESTING_SharedService
73{
74 /**
75 * The name of the service.
76 */
77 const char *service;
78
79 /**
80 * The configuration template for the service. Cannot be NULL
81 */
82 const struct GNUNET_CONFIGURATION_Handle *cfg;
83
84 /**
85 * The number of peers which share an instance of the service. 0 for sharing
86 * among all peers
87 */
88 unsigned int share;
89};
90
91
92/**
70 * Create a system handle. There must only be one system handle per operating 93 * Create a system handle. There must only be one system handle per operating
71 * system. Uses a default range for allowed ports. Ports are still tested for 94 * system. Uses a default range for allowed ports. Ports are still tested for
72 * availability. 95 * availability.
@@ -80,12 +103,16 @@ struct GNUNET_TESTING_Peer;
80 * in CIDR notation. 103 * in CIDR notation.
81 * @param hostname the hostname of the system we are using for testing; NULL for 104 * @param hostname the hostname of the system we are using for testing; NULL for
82 * localhost 105 * localhost
106 * @param shared_services NULL terminated array describing services that are to
107 * be shared among peers
83 * @return handle to this system, NULL on error 108 * @return handle to this system, NULL on error
84 */ 109 */
85struct GNUNET_TESTING_System * 110struct GNUNET_TESTING_System *
86GNUNET_TESTING_system_create (const char *testdir, 111GNUNET_TESTING_system_create (const char *testdir,
87 const char *trusted_ip, 112 const char *trusted_ip,
88 const char *hostname); 113 const char *hostname,
114 const struct GNUNET_TESTING_SharedService **
115 shared_services);
89 116
90 117
91/** 118/**
@@ -104,6 +131,8 @@ GNUNET_TESTING_system_create (const char *testdir,
104 * in CIDR notation. 131 * in CIDR notation.
105 * @param hostname the hostname of the system we are using for testing; NULL for 132 * @param hostname the hostname of the system we are using for testing; NULL for
106 * localhost 133 * localhost
134 * @param shared_services NULL terminated array describing services that are to
135 * be shared among peers
107 * @param lowport lowest port number this system is allowed to allocate (inclusive) 136 * @param lowport lowest port number this system is allowed to allocate (inclusive)
108 * @param highport highest port number this system is allowed to allocate (exclusive) 137 * @param highport highest port number this system is allowed to allocate (exclusive)
109 * @return handle to this system, NULL on error 138 * @return handle to this system, NULL on error
@@ -112,6 +141,9 @@ struct GNUNET_TESTING_System *
112GNUNET_TESTING_system_create_with_portrange (const char *testdir, 141GNUNET_TESTING_system_create_with_portrange (const char *testdir,
113 const char *trusted_ip, 142 const char *trusted_ip,
114 const char *hostname, 143 const char *hostname,
144 const struct
145 GNUNET_TESTING_SharedService **
146 shared_services,
115 uint16_t lowport, 147 uint16_t lowport,
116 uint16_t highport); 148 uint16_t highport);
117 149
diff --git a/src/testbed/gnunet-helper-testbed.c b/src/testbed/gnunet-helper-testbed.c
index ab0a595d2..bdd8911de 100644
--- a/src/testbed/gnunet-helper-testbed.c
+++ b/src/testbed/gnunet-helper-testbed.c
@@ -393,7 +393,7 @@ tokenizer_cb (void *cls, void *client,
393 hostname[hostname_size] = '\0'; 393 hostname[hostname_size] = '\0';
394 } 394 }
395 test_system = 395 test_system =
396 GNUNET_TESTING_system_create ("testbed-helper", trusted_ip, hostname); 396 GNUNET_TESTING_system_create ("testbed-helper", trusted_ip, hostname, NULL);
397 GNUNET_free_non_null (hostname); 397 GNUNET_free_non_null (hostname);
398 hostname = NULL; 398 hostname = NULL;
399 GNUNET_assert (NULL != test_system); 399 GNUNET_assert (NULL != test_system);
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index 3d4a54db3..9a0084efa 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -485,7 +485,7 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client,
485 LOG_DEBUG ("Our IP: %s\n", GST_context->master_ip); 485 LOG_DEBUG ("Our IP: %s\n", GST_context->master_ip);
486 GST_context->system = 486 GST_context->system =
487 GNUNET_TESTING_system_create ("testbed", GST_context->master_ip, 487 GNUNET_TESTING_system_create ("testbed", GST_context->master_ip,
488 hostname); 488 hostname, NULL);
489 host = 489 host =
490 GNUNET_TESTBED_host_create_with_id (GST_context->host_id, 490 GNUNET_TESTBED_host_create_with_id (GST_context->host_id,
491 GST_context->master_ip, NULL, 491 GST_context->master_ip, NULL,
diff --git a/src/testing/gnunet-testing.c b/src/testing/gnunet-testing.c
index 8c92068ab..574b585fc 100644
--- a/src/testing/gnunet-testing.c
+++ b/src/testing/gnunet-testing.c
@@ -76,7 +76,8 @@ create_unique_cfgs (const char * template, const unsigned int no)
76 } 76 }
77 77
78 fail = GNUNET_NO; 78 fail = GNUNET_NO;
79 system = GNUNET_TESTING_system_create ("testing", NULL /* controller */, NULL); 79 system = GNUNET_TESTING_system_create ("testing", NULL /* controller */,
80 NULL, NULL);
80 for (cur = 0; cur < no; cur++) 81 for (cur = 0; cur < no; cur++)
81 { 82 {
82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating configuration no. %u \n", cur); 83 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating configuration no. %u \n", cur);
@@ -125,7 +126,7 @@ create_hostkeys (const unsigned int no)
125 struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *pkb; 126 struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *pkb;
126 ssize_t ret; 127 ssize_t ret;
127 128
128 system = GNUNET_TESTING_system_create ("testing", NULL, NULL); 129 system = GNUNET_TESTING_system_create ("testing", NULL, NULL, NULL);
129 pk = GNUNET_TESTING_hostkey_get (system, create_no, &id); 130 pk = GNUNET_TESTING_hostkey_get (system, create_no, &id);
130 if (NULL == pk) 131 if (NULL == pk)
131 { 132 {
diff --git a/src/testing/test_testing_peerstartup.c b/src/testing/test_testing_peerstartup.c
index fb3967ce0..d32a341b5 100644
--- a/src/testing/test_testing_peerstartup.c
+++ b/src/testing/test_testing_peerstartup.c
@@ -99,7 +99,7 @@ run (void *cls, char *const *args, const char *cfgfile,
99 test_ctx = GNUNET_malloc (sizeof (struct TestingContext)); 99 test_ctx = GNUNET_malloc (sizeof (struct TestingContext));
100 test_ctx->system = 100 test_ctx->system =
101 GNUNET_TESTING_system_create ("test-gnunet-testing", 101 GNUNET_TESTING_system_create ("test-gnunet-testing",
102 "127.0.0.1", NULL); 102 "127.0.0.1", NULL, NULL);
103 emsg = NULL; 103 emsg = NULL;
104 if (NULL == test_ctx->system) 104 if (NULL == test_ctx->system)
105 goto end; 105 goto end;
diff --git a/src/testing/test_testing_peerstartup2.c b/src/testing/test_testing_peerstartup2.c
index d290aff16..cd8141b40 100644
--- a/src/testing/test_testing_peerstartup2.c
+++ b/src/testing/test_testing_peerstartup2.c
@@ -169,7 +169,7 @@ run (void *cls, char *const *args, const char *cfgfile,
169 test_ctx = GNUNET_malloc (sizeof (struct TestingContext)); 169 test_ctx = GNUNET_malloc (sizeof (struct TestingContext));
170 test_ctx->system = 170 test_ctx->system =
171 GNUNET_TESTING_system_create ("test-gnunet-testing", 171 GNUNET_TESTING_system_create ("test-gnunet-testing",
172 "127.0.0.1", NULL); 172 "127.0.0.1", NULL, NULL);
173 emsg = NULL; 173 emsg = NULL;
174 if (NULL == test_ctx->system) 174 if (NULL == test_ctx->system)
175 goto end; 175 goto end;
diff --git a/src/testing/test_testing_portreservation.c b/src/testing/test_testing_portreservation.c
index 21ef51ffd..81ba67e96 100644
--- a/src/testing/test_testing_portreservation.c
+++ b/src/testing/test_testing_portreservation.c
@@ -50,7 +50,7 @@ run (void *cls, char *const *args, const char *cfgfile,
50 uint16_t old_port1; 50 uint16_t old_port1;
51 51
52 system = GNUNET_TESTING_system_create ("/tmp/gnunet-testing-new", 52 system = GNUNET_TESTING_system_create ("/tmp/gnunet-testing-new",
53 "localhost", NULL); 53 "localhost", NULL, NULL);
54 GNUNET_assert (NULL != system); 54 GNUNET_assert (NULL != system);
55 new_port1 = GNUNET_TESTING_reserve_port (system, GNUNET_YES); 55 new_port1 = GNUNET_TESTING_reserve_port (system, GNUNET_YES);
56 LOG (GNUNET_ERROR_TYPE_DEBUG, 56 LOG (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/testing/testing.c b/src/testing/testing.c
index a1a2fdc06..23cd7ddc7 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -64,6 +64,37 @@
64#define HIGH_PORT 56000 64#define HIGH_PORT 56000
65 65
66 66
67struct SharedServiceInstance
68{
69 struct SharedService *ss;
70
71 char *cfg_fn;
72
73 struct GNUNET_OS_Process *proc;
74
75 char *unix_sock;
76
77 char *port_str;
78
79 unsigned int n_refs;
80};
81
82struct SharedService
83{
84 char *sname;
85
86 struct SharedServiceInstance **instances;
87
88 struct GNUNET_CONFIGURATION_Handle *cfg;
89
90 unsigned int n_peers;
91
92 unsigned int share;
93
94 unsigned int n_instances;
95};
96
97
67/** 98/**
68 * Handle for a system on which GNUnet peers are executed; 99 * Handle for a system on which GNUnet peers are executed;
69 * a system is used for reserving unique paths and ports. 100 * a system is used for reserving unique paths and ports.
@@ -96,6 +127,10 @@ struct GNUNET_TESTING_System
96 */ 127 */
97 struct GNUNET_DISK_MapHandle *map; 128 struct GNUNET_DISK_MapHandle *map;
98 129
130 struct SharedService **shared_services;
131
132 unsigned int n_shared_services;
133
99 /** 134 /**
100 * Bitmap where each TCP port that has already been reserved for 135 * Bitmap where each TCP port that has already been reserved for
101 * some GNUnet peer is recorded. Note that we additionally need to 136 * some GNUnet peer is recorded. Note that we additionally need to
@@ -206,6 +241,8 @@ struct GNUNET_TESTING_Peer
206 */ 241 */
207 struct GNUNET_PeerIdentity *id; 242 struct GNUNET_PeerIdentity *id;
208 243
244 struct SharedServiceInstance **ss_instances;
245
209 /** 246 /**
210 * Array of ports currently allocated to this peer. These ports will be 247 * Array of ports currently allocated to this peer. These ports will be
211 * released upon peer destroy and can be used by other peers which are 248 * released upon peer destroy and can be used by other peers which are
@@ -307,6 +344,24 @@ hostkeys_unload (struct GNUNET_TESTING_System *system)
307 344
308 345
309/** 346/**
347 * Function to iterate over options.
348 *
349 * @param cls closure
350 * @param section name of the section
351 * @param option name of the option
352 * @param value value of the option
353 */
354static void
355cfg_copy_iterator (void *cls, const char *section,
356 const char *option, const char *value)
357{
358 struct GNUNET_CONFIGURATION_Handle *cfg2 = cls;
359
360 GNUNET_CONFIGURATION_set_value_string (cfg2, section, option, value);
361}
362
363
364/**
310 * Create a system handle. There must only be one system 365 * Create a system handle. There must only be one system
311 * handle per operating system. 366 * handle per operating system.
312 * 367 *
@@ -319,6 +374,8 @@ hostkeys_unload (struct GNUNET_TESTING_System *system)
319 * in CIDR notation. 374 * in CIDR notation.
320 * @param hostname the hostname of the system we are using for testing; NULL for 375 * @param hostname the hostname of the system we are using for testing; NULL for
321 * localhost 376 * localhost
377 * @param shared_services NULL terminated array describing services that are to
378 * be shared among peers
322 * @param lowport lowest port number this system is allowed to allocate (inclusive) 379 * @param lowport lowest port number this system is allowed to allocate (inclusive)
323 * @param highport highest port number this system is allowed to allocate (exclusive) 380 * @param highport highest port number this system is allowed to allocate (exclusive)
324 * @return handle to this system, NULL on error 381 * @return handle to this system, NULL on error
@@ -327,10 +384,16 @@ struct GNUNET_TESTING_System *
327GNUNET_TESTING_system_create_with_portrange (const char *testdir, 384GNUNET_TESTING_system_create_with_portrange (const char *testdir,
328 const char *trusted_ip, 385 const char *trusted_ip,
329 const char *hostname, 386 const char *hostname,
387 const struct
388 GNUNET_TESTING_SharedService **
389 shared_services,
330 uint16_t lowport, 390 uint16_t lowport,
331 uint16_t highport) 391 uint16_t highport)
332{ 392{
333 struct GNUNET_TESTING_System *system; 393 struct GNUNET_TESTING_System *system;
394 const struct GNUNET_TESTING_SharedService *tss;
395 struct SharedService *ss;
396 unsigned int cnt;
334 397
335 GNUNET_assert (NULL != testdir); 398 GNUNET_assert (NULL != testdir);
336 system = GNUNET_malloc (sizeof (struct GNUNET_TESTING_System)); 399 system = GNUNET_malloc (sizeof (struct GNUNET_TESTING_System));
@@ -351,6 +414,22 @@ GNUNET_TESTING_system_create_with_portrange (const char *testdir,
351 GNUNET_TESTING_system_destroy (system, GNUNET_YES); 414 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
352 return NULL; 415 return NULL;
353 } 416 }
417 if (NULL == shared_services)
418 return system;
419 for (cnt = 0; NULL != (tss = shared_services[cnt]); cnt++)
420 {
421 ss = GNUNET_malloc (sizeof (struct SharedService));
422 ss->sname = GNUNET_strdup (tss->service);
423 ss->cfg = GNUNET_CONFIGURATION_dup (tss->cfg);
424 ss->cfg = GNUNET_CONFIGURATION_create ();
425 GNUNET_CONFIGURATION_iterate_section_values (tss->cfg, ss->sname,
426 &cfg_copy_iterator, ss->cfg);
427 GNUNET_CONFIGURATION_iterate_section_values (tss->cfg, "TESTING",
428 &cfg_copy_iterator, ss->cfg);
429 ss->share = tss->share;
430 GNUNET_array_append (system->shared_services, system->n_shared_services,
431 ss);
432 }
354 return system; 433 return system;
355} 434}
356 435
@@ -369,20 +448,72 @@ GNUNET_TESTING_system_create_with_portrange (const char *testdir,
369 * in CIDR notation. 448 * in CIDR notation.
370 * @param hostname the hostname of the system we are using for testing; NULL for 449 * @param hostname the hostname of the system we are using for testing; NULL for
371 * localhost 450 * localhost
451 * @param shared_services NULL terminated array describing services that are to
452 * be shared among peers
372 * @return handle to this system, NULL on error 453 * @return handle to this system, NULL on error
373 */ 454 */
374struct GNUNET_TESTING_System * 455struct GNUNET_TESTING_System *
375GNUNET_TESTING_system_create (const char *testdir, 456GNUNET_TESTING_system_create (const char *testdir,
376 const char *trusted_ip, 457 const char *trusted_ip,
377 const char *hostname) 458 const char *hostname,
459 const struct GNUNET_TESTING_SharedService **
460 shared_services)
378{ 461{
379 return GNUNET_TESTING_system_create_with_portrange (testdir, 462 return GNUNET_TESTING_system_create_with_portrange (testdir,
380 trusted_ip, 463 trusted_ip,
381 hostname, 464 hostname,
465 shared_services,
382 LOW_PORT, 466 LOW_PORT,
383 HIGH_PORT); 467 HIGH_PORT);
384} 468}
385 469
470static void
471cleanup_shared_service_instance (struct SharedServiceInstance *i)
472{
473 if (NULL != i->cfg_fn)
474 {
475 (void) unlink (i->cfg_fn);
476 GNUNET_free (i->cfg_fn);
477 }
478 GNUNET_free_non_null (i->unix_sock);
479 GNUNET_free_non_null (i->port_str);
480 GNUNET_break (NULL == i->proc);
481 GNUNET_break (0 == i->n_refs);
482 GNUNET_free (i);
483}
484
485static int
486start_shared_service_instance (struct SharedServiceInstance *i)
487{
488 char *binary;
489
490 GNUNET_assert (NULL == i->proc);
491 GNUNET_assert (NULL != i->cfg_fn);
492 (void) GNUNET_asprintf (&binary, "gnunet-service-%s", i->ss->sname);
493 i->proc = GNUNET_OS_start_process (PIPE_CONTROL,
494 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
495 NULL, NULL,
496 binary,
497 binary,
498 "-c",
499 i->cfg_fn,
500 NULL);
501 if (NULL == i->proc)
502 return GNUNET_SYSERR;
503 return GNUNET_OK;
504}
505
506
507static void
508stop_shared_service_instance (struct SharedServiceInstance *i)
509{
510 GNUNET_break (0 == i->n_refs);
511 GNUNET_OS_process_kill (i->proc, SIGTERM);
512 (void) GNUNET_OS_process_wait (i->proc);
513 GNUNET_OS_process_destroy (i->proc);
514 i->proc = NULL;
515}
516
386 517
387/** 518/**
388 * Free system resources. 519 * Free system resources.
@@ -395,8 +526,29 @@ void
395GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, 526GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system,
396 int remove_paths) 527 int remove_paths)
397{ 528{
529 struct SharedService *ss;
530 struct SharedServiceInstance *i;
531 unsigned int ss_cnt;
532 unsigned int i_cnt;
533
398 if (NULL != system->hostkeys_data) 534 if (NULL != system->hostkeys_data)
399 hostkeys_unload (system); 535 hostkeys_unload (system);
536 for (ss_cnt = 0; ss_cnt < system->n_shared_services; ss_cnt++)
537 {
538 ss = system->shared_services[ss_cnt];
539 for (i_cnt = 0; i_cnt < ss->n_instances; i_cnt++)
540 {
541 i = ss->instances[i_cnt];
542 if (NULL != i->proc)
543 stop_shared_service_instance (i);
544 cleanup_shared_service_instance (i);
545 }
546 GNUNET_free_non_null (ss->instances);
547 GNUNET_CONFIGURATION_destroy (ss->cfg);
548 GNUNET_free (ss->sname);
549 GNUNET_free (ss);
550 }
551 GNUNET_free_non_null (system->shared_services);
400 if (GNUNET_YES == remove_paths) 552 if (GNUNET_YES == remove_paths)
401 GNUNET_DISK_directory_remove (system->tmppath); 553 GNUNET_DISK_directory_remove (system->tmppath);
402 GNUNET_free (system->tmppath); 554 GNUNET_free (system->tmppath);
@@ -739,6 +891,8 @@ update_config_sections (void *cls,
739 891
740 ikeys_cnt = 0; 892 ikeys_cnt = 0;
741 val = NULL; 893 val = NULL;
894 /* Ignore certain options from sections. See
895 https://gnunet.org/bugs/view.php?id=2476 */
742 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (uc->cfg, section, 896 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (uc->cfg, section,
743 "TESTING_IGNORE_KEYS")) 897 "TESTING_IGNORE_KEYS"))
744 { 898 {
@@ -816,6 +970,66 @@ update_config_sections (void *cls,
816 GNUNET_free (allowed_hosts); 970 GNUNET_free (allowed_hosts);
817} 971}
818 972
973static struct SharedServiceInstance *
974associate_shared_service (struct GNUNET_TESTING_System *system,
975 struct SharedService *ss,
976 struct GNUNET_CONFIGURATION_Handle *cfg)
977{
978 struct SharedServiceInstance *i;
979 struct GNUNET_CONFIGURATION_Handle *temp;
980 char *service_home;
981 uint32_t port;
982
983 ss->n_peers++;
984 if ( ((0 == ss->share) && (NULL == ss->instances))
985 ||
986 ( (0 != ss->share)
987 && (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share)) ) )
988 {
989 i = GNUNET_malloc (sizeof (struct SharedServiceInstance));
990 i->ss = ss;
991 (void) GNUNET_asprintf (&service_home, "%s/shared/%s/%u",
992 system->tmppath, ss->sname, ss->n_instances);
993 (void) GNUNET_asprintf (&i->unix_sock, "%s/sock", service_home);
994 port = GNUNET_TESTING_reserve_port (system, GNUNET_YES);
995 if (0 == port)
996 {
997 GNUNET_free (service_home);
998 cleanup_shared_service_instance (i);
999 return NULL;
1000 }
1001 GNUNET_array_append (ss->instances, ss->n_instances, i);
1002 temp = GNUNET_CONFIGURATION_dup (ss->cfg);
1003 (void) GNUNET_asprintf (&i->port_str, "%u", port);
1004 (void) GNUNET_asprintf (&i->cfg_fn, "%s/config", service_home);
1005 GNUNET_CONFIGURATION_set_value_string (temp, "PATHS", "SERVICEHOME",
1006 service_home);
1007 GNUNET_CONFIGURATION_set_value_string (temp, ss->sname, "UNIXPATH",
1008 i->unix_sock);
1009 GNUNET_CONFIGURATION_set_value_string (temp, ss->sname, "PORT",
1010 i->port_str);
1011 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_write (temp, i->cfg_fn))
1012 {
1013 GNUNET_CONFIGURATION_destroy (temp);
1014 cleanup_shared_service_instance (i);
1015 return NULL;
1016 }
1017 GNUNET_CONFIGURATION_destroy (temp);
1018 }
1019 else
1020 {
1021 GNUNET_assert (NULL != ss->instances);
1022 GNUNET_assert (0 < ss->n_instances);
1023 i = ss->instances[ss->n_instances - 1];
1024 }
1025 GNUNET_CONFIGURATION_iterate_section_values(ss->cfg, ss->sname,
1026 &cfg_copy_iterator, cfg);
1027 GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "UNIXPATH",
1028 i->unix_sock);
1029 GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "PORT", i->port_str);
1030 return i;
1031}
1032
819 1033
820/** 1034/**
821 * Create a new configuration using the given configuration as a template; 1035 * Create a new configuration using the given configuration as a template;
@@ -843,8 +1057,8 @@ GNUNET_TESTING_configuration_create_ (struct GNUNET_TESTING_System *system,
843 unsigned int *nports) 1057 unsigned int *nports)
844{ 1058{
845 struct UpdateContext uc; 1059 struct UpdateContext uc;
846 char *default_config; 1060 char *default_config;
847 1061
848 uc.system = system; 1062 uc.system = system;
849 uc.cfg = cfg; 1063 uc.cfg = cfg;
850 uc.status = GNUNET_OK; 1064 uc.status = GNUNET_OK;
@@ -933,12 +1147,22 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
933 char *emsg_; 1147 char *emsg_;
934 struct GNUNET_CRYPTO_EccPrivateKey *pk; 1148 struct GNUNET_CRYPTO_EccPrivateKey *pk;
935 uint16_t *ports; 1149 uint16_t *ports;
1150 struct SharedService *ss;
1151 struct SharedServiceInstance **ss_instances;
1152 unsigned int cnt;
936 unsigned int nports; 1153 unsigned int nports;
937 1154
938 ports = NULL; 1155 ports = NULL;
939 nports = 0; 1156 nports = 0;
1157 ss_instances = NULL;
940 if (NULL != emsg) 1158 if (NULL != emsg)
941 *emsg = NULL; 1159 *emsg = NULL;
1160 /* Remove sections for shared services */
1161 for (cnt = 0; cnt < system->n_shared_services; cnt++)
1162 {
1163 ss = system->shared_services[cnt];
1164 GNUNET_CONFIGURATION_remove_section (cfg, ss->sname);
1165 }
942 if (GNUNET_OK != GNUNET_TESTING_configuration_create_ (system, cfg, 1166 if (GNUNET_OK != GNUNET_TESTING_configuration_create_ (system, cfg,
943 &ports, &nports)) 1167 &ports, &nports))
944 { 1168 {
@@ -996,6 +1220,15 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
996 goto err_ret; 1220 goto err_ret;
997 } 1221 }
998 GNUNET_DISK_file_close (fd); 1222 GNUNET_DISK_file_close (fd);
1223 ss_instances = GNUNET_malloc (sizeof (struct SharedServiceInstance *)
1224 * system->n_shared_services);
1225 for (cnt=0; cnt < system->n_shared_services; cnt++)
1226 {
1227 ss = system->shared_services[cnt];
1228 ss_instances[cnt] = associate_shared_service (system, ss, cfg);
1229 if (NULL == ss_instances[cnt])
1230 goto err_ret;
1231 }
999 GNUNET_assert (GNUNET_OK == 1232 GNUNET_assert (GNUNET_OK ==
1000 GNUNET_CONFIGURATION_get_value_string 1233 GNUNET_CONFIGURATION_get_value_string
1001 (cfg, "PATHS", "DEFAULTCONFIG", &config_filename)); 1234 (cfg, "PATHS", "DEFAULTCONFIG", &config_filename));
@@ -1010,6 +1243,7 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1010 goto err_ret; 1243 goto err_ret;
1011 } 1244 }
1012 peer = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Peer)); 1245 peer = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Peer));
1246 peer->ss_instances = ss_instances;
1013 peer->cfgfile = config_filename; /* Free in peer_destroy */ 1247 peer->cfgfile = config_filename; /* Free in peer_destroy */
1014 peer->cfg = GNUNET_CONFIGURATION_dup (cfg); 1248 peer->cfg = GNUNET_CONFIGURATION_dup (cfg);
1015 libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); 1249 libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
@@ -1029,6 +1263,7 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1029 return peer; 1263 return peer;
1030 1264
1031 err_ret: 1265 err_ret:
1266 GNUNET_free_non_null (ss_instances);
1032 GNUNET_free_non_null (ports); 1267 GNUNET_free_non_null (ports);
1033 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_); 1268 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_);
1034 if (NULL != emsg) 1269 if (NULL != emsg)
@@ -1071,12 +1306,23 @@ GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer,
1071int 1306int
1072GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer) 1307GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer)
1073{ 1308{
1309 struct SharedServiceInstance *i;
1310 unsigned int cnt;
1311
1074 if (NULL != peer->main_process) 1312 if (NULL != peer->main_process)
1075 { 1313 {
1076 GNUNET_break (0); 1314 GNUNET_break (0);
1077 return GNUNET_SYSERR; 1315 return GNUNET_SYSERR;
1078 } 1316 }
1079 GNUNET_assert (NULL != peer->cfgfile); 1317 GNUNET_assert (NULL != peer->cfgfile);
1318 for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1319 {
1320 i = peer->ss_instances[cnt];
1321 if ((0 == i->n_refs)
1322 && (GNUNET_SYSERR == start_shared_service_instance (i)) )
1323 return GNUNET_SYSERR;
1324 i->n_refs++;
1325 }
1080 peer->main_process = GNUNET_OS_start_process (PIPE_CONTROL, 1326 peer->main_process = GNUNET_OS_start_process (PIPE_CONTROL,
1081 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 1327 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
1082 NULL, NULL, 1328 NULL, NULL,
@@ -1167,13 +1413,25 @@ GNUNET_TESTING_peer_service_stop (struct GNUNET_TESTING_Peer *peer,
1167int 1413int
1168GNUNET_TESTING_peer_kill (struct GNUNET_TESTING_Peer *peer) 1414GNUNET_TESTING_peer_kill (struct GNUNET_TESTING_Peer *peer)
1169{ 1415{
1416 struct SharedServiceInstance *i;
1417 unsigned int cnt;
1418
1170 if (NULL == peer->main_process) 1419 if (NULL == peer->main_process)
1171 { 1420 {
1172 GNUNET_break (0); 1421 GNUNET_break (0);
1173 return GNUNET_SYSERR; 1422 return GNUNET_SYSERR;
1174 } 1423 }
1175 return (0 == GNUNET_OS_process_kill (peer->main_process, SIGTERM)) ? 1424 if (0 != GNUNET_OS_process_kill (peer->main_process, SIGTERM))
1176 GNUNET_OK : GNUNET_SYSERR; 1425 return GNUNET_SYSERR;
1426 for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1427 {
1428 i = peer->ss_instances[cnt];
1429 GNUNET_assert (0 != i->n_refs);
1430 i->n_refs--;
1431 if (0 == i->n_refs)
1432 stop_shared_service_instance (i);
1433 }
1434 return GNUNET_OK;
1177} 1435}
1178 1436
1179 1437
@@ -1299,6 +1557,7 @@ GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer)
1299 GNUNET_free (peer->main_binary); 1557 GNUNET_free (peer->main_binary);
1300 GNUNET_free (peer->args); 1558 GNUNET_free (peer->args);
1301 GNUNET_free_non_null (peer->id); 1559 GNUNET_free_non_null (peer->id);
1560 GNUNET_free_non_null (peer->ss_instances);
1302 if (NULL != peer->ports) 1561 if (NULL != peer->ports)
1303 { 1562 {
1304 for (cnt = 0; cnt < peer->nports; cnt++) 1563 for (cnt = 0; cnt < peer->nports; cnt++)
@@ -1417,7 +1676,7 @@ GNUNET_TESTING_service_run (const char *testdir,
1417 char *libexec_binary; 1676 char *libexec_binary;
1418 1677
1419 GNUNET_log_setup (testdir, "WARNING", NULL); 1678 GNUNET_log_setup (testdir, "WARNING", NULL);
1420 system = GNUNET_TESTING_system_create (testdir, "127.0.0.1", NULL); 1679 system = GNUNET_TESTING_system_create (testdir, "127.0.0.1", NULL, NULL);
1421 if (NULL == system) 1680 if (NULL == system)
1422 return 1; 1681 return 1;
1423 cfg = GNUNET_CONFIGURATION_create (); 1682 cfg = GNUNET_CONFIGURATION_create ();
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c
index 8875afb8e..11344b125 100644
--- a/src/transport/transport-testing.c
+++ b/src/transport/transport-testing.c
@@ -578,7 +578,8 @@ GNUNET_TRANSPORT_TESTING_init ()
578 tth = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TESTING_handle)); 578 tth = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TESTING_handle));
579 579
580 /* Init testing the testing lib */ 580 /* Init testing the testing lib */
581 tth->tl_system = GNUNET_TESTING_system_create ("transport-testing", NULL, NULL); 581 tth->tl_system = GNUNET_TESTING_system_create ("transport-testing", NULL,
582 NULL, NULL);
582 if (NULL == tth->tl_system) 583 if (NULL == tth->tl_system)
583 { 584 {
584 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize testing library!\n")); 585 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize testing library!\n"));