aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-06 22:46:29 +0000
committerng0 <ng0@n0.is>2019-09-06 22:46:29 +0000
commit6e599264ad13e8fc105493d74d7c11d46f8739ed (patch)
tree169bef1ecbade5a659831fb169f3ae6943af127f /src/testing
parent4f13bc15113021ebf71d5d81e99bc29f8a07fc9c (diff)
downloadgnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.tar.gz
gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.zip
first step to remove plibc
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/gnunet-testing.c212
-rw-r--r--src/testing/list-keys.c43
-rw-r--r--src/testing/testing.c450
3 files changed, 403 insertions, 302 deletions
diff --git a/src/testing/gnunet-testing.c b/src/testing/gnunet-testing.c
index ec611ba4c..bc402227c 100644
--- a/src/testing/gnunet-testing.c
+++ b/src/testing/gnunet-testing.c
@@ -28,8 +28,7 @@
28#include "gnunet_testing_lib.h" 28#include "gnunet_testing_lib.h"
29 29
30 30
31#define LOG(kind,...) \ 31#define LOG(kind, ...) GNUNET_log_from (kind, "gnunet-testing", __VA_ARGS__)
32 GNUNET_log_from (kind, "gnunet-testing", __VA_ARGS__)
33 32
34 33
35/** 34/**
@@ -84,9 +83,8 @@ static struct GNUNET_SCHEDULER_Task *tid;
84static struct GNUNET_TESTING_Peer *my_peer; 83static struct GNUNET_TESTING_Peer *my_peer;
85 84
86 85
87
88static int 86static int
89create_unique_cfgs (const char * template, const unsigned int no) 87create_unique_cfgs (const char *template, const unsigned int no)
90{ 88{
91 struct GNUNET_TESTING_System *system; 89 struct GNUNET_TESTING_System *system;
92 int fail; 90 int fail;
@@ -95,54 +93,67 @@ create_unique_cfgs (const char * template, const unsigned int no)
95 struct GNUNET_CONFIGURATION_Handle *cfg_new; 93 struct GNUNET_CONFIGURATION_Handle *cfg_new;
96 struct GNUNET_CONFIGURATION_Handle *cfg_tmpl; 94 struct GNUNET_CONFIGURATION_Handle *cfg_tmpl;
97 95
98 if (GNUNET_NO == GNUNET_DISK_file_test(template)) 96 if (GNUNET_NO == GNUNET_DISK_file_test (template))
99 { 97 {
100 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Configuration template `%s': file not found\n", create_cfg_template); 98 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
99 "Configuration template `%s': file not found\n",
100 create_cfg_template);
101 return 1; 101 return 1;
102 } 102 }
103 cfg_tmpl = GNUNET_CONFIGURATION_create(); 103 cfg_tmpl = GNUNET_CONFIGURATION_create ();
104 104
105 /* load template */ 105 /* load template */
106 if ((create_cfg_template != NULL) && (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg_tmpl, create_cfg_template))) 106 if ((create_cfg_template != NULL) &&
107 (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg_tmpl, create_cfg_template)))
107 { 108 {
108 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not load template `%s'\n", create_cfg_template); 109 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
110 "Could not load template `%s'\n",
111 create_cfg_template);
109 GNUNET_CONFIGURATION_destroy (cfg_tmpl); 112 GNUNET_CONFIGURATION_destroy (cfg_tmpl);
110 113
111 return 1; 114 return 1;
112 } 115 }
113 /* load defaults */ 116 /* load defaults */
114 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg_tmpl, NULL)) 117 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg_tmpl, NULL))
115 { 118 {
116 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not load template `%s'\n", create_cfg_template); 119 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
120 "Could not load template `%s'\n",
121 create_cfg_template);
117 GNUNET_CONFIGURATION_destroy (cfg_tmpl); 122 GNUNET_CONFIGURATION_destroy (cfg_tmpl);
118 return 1; 123 return 1;
119 } 124 }
120 125
121 fail = GNUNET_NO; 126 fail = GNUNET_NO;
122 system = GNUNET_TESTING_system_create ("testing", NULL /* controller */, 127 system =
123 NULL, NULL); 128 GNUNET_TESTING_system_create ("testing", NULL /* controller */, NULL, NULL);
124 for (cur = 0; cur < no; cur++) 129 for (cur = 0; cur < no; cur++)
125 { 130 {
126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating configuration no. %u \n", cur); 131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
132 "Creating configuration no. %u \n",
133 cur);
127 if (create_cfg_template != NULL) 134 if (create_cfg_template != NULL)
128 GNUNET_asprintf (&cur_file,"%04u-%s",cur, create_cfg_template); 135 GNUNET_asprintf (&cur_file, "%04u-%s", cur, create_cfg_template);
129 else 136 else
130 GNUNET_asprintf (&cur_file,"%04u%s",cur, ".conf"); 137 GNUNET_asprintf (&cur_file, "%04u%s", cur, ".conf");
131 138
132 cfg_new = GNUNET_CONFIGURATION_dup (cfg_tmpl); 139 cfg_new = GNUNET_CONFIGURATION_dup (cfg_tmpl);
133 if (GNUNET_OK != 140 if (GNUNET_OK != GNUNET_TESTING_configuration_create (system, cfg_new))
134 GNUNET_TESTING_configuration_create (system, cfg_new))
135 { 141 {
136 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not create another configuration\n"); 142 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
143 "Could not create another configuration\n");
137 GNUNET_CONFIGURATION_destroy (cfg_new); 144 GNUNET_CONFIGURATION_destroy (cfg_new);
138 fail = GNUNET_YES; 145 fail = GNUNET_YES;
139 break; 146 break;
140 } 147 }
141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
142 "Writing configuration no. %u to file `%s' \n", cur, cur_file); 149 "Writing configuration no. %u to file `%s' \n",
143 if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg_new, cur_file)) 150 cur,
151 cur_file);
152 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg_new, cur_file))
144 { 153 {
145 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to write configuration no. %u \n", cur); 154 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
155 "Failed to write configuration no. %u \n",
156 cur);
146 fail = GNUNET_YES; 157 fail = GNUNET_YES;
147 } 158 }
148 GNUNET_CONFIGURATION_destroy (cfg_new); 159 GNUNET_CONFIGURATION_destroy (cfg_new);
@@ -150,7 +161,7 @@ create_unique_cfgs (const char * template, const unsigned int no)
150 if (GNUNET_YES == fail) 161 if (GNUNET_YES == fail)
151 break; 162 break;
152 } 163 }
153 GNUNET_CONFIGURATION_destroy(cfg_tmpl); 164 GNUNET_CONFIGURATION_destroy (cfg_tmpl);
154 GNUNET_TESTING_system_destroy (system, GNUNET_NO); 165 GNUNET_TESTING_system_destroy (system, GNUNET_NO);
155 if (GNUNET_YES == fail) 166 if (GNUNET_YES == fail)
156 return 1; 167 return 1;
@@ -170,22 +181,27 @@ create_hostkeys (const unsigned int no)
170 pk = GNUNET_TESTING_hostkey_get (system, create_no, &id); 181 pk = GNUNET_TESTING_hostkey_get (system, create_no, &id);
171 if (NULL == pk) 182 if (NULL == pk)
172 { 183 {
173 fprintf (stderr, _("Could not extract hostkey %u (offset too large?)\n"), create_no); 184 fprintf (stderr,
185 _ ("Could not extract hostkey %u (offset too large?)\n"),
186 create_no);
174 GNUNET_TESTING_system_destroy (system, GNUNET_YES); 187 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
175 return 1; 188 return 1;
176 } 189 }
177 (void) GNUNET_DISK_directory_create_for_file (create_hostkey); 190 (void) GNUNET_DISK_directory_create_for_file (create_hostkey);
178 fd = GNUNET_DISK_file_open (create_hostkey, 191 fd =
179 GNUNET_DISK_OPEN_READWRITE | 192 GNUNET_DISK_file_open (create_hostkey,
180 GNUNET_DISK_OPEN_CREATE, 193 GNUNET_DISK_OPEN_READWRITE | GNUNET_DISK_OPEN_CREATE,
181 GNUNET_DISK_PERM_USER_READ | 194 GNUNET_DISK_PERM_USER_READ |
182 GNUNET_DISK_PERM_USER_WRITE); 195 GNUNET_DISK_PERM_USER_WRITE);
183 GNUNET_assert (fd != NULL); 196 GNUNET_assert (fd != NULL);
184 ret = GNUNET_DISK_file_write (fd, pk, 197 ret = GNUNET_DISK_file_write (fd,
185 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)); 198 pk,
199 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
186 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); 200 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
187 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", 201 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
188 "Wrote hostkey to file: `%s'\n", create_hostkey); 202 "transport-testing",
203 "Wrote hostkey to file: `%s'\n",
204 create_hostkey);
189 GNUNET_free (pk); 205 GNUNET_free (pk);
190 GNUNET_TESTING_system_destroy (system, GNUNET_YES); 206 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
191 return 0; 207 return 0;
@@ -203,8 +219,10 @@ cleanup (void *cls)
203{ 219{
204 if (NULL != tmpfilename) 220 if (NULL != tmpfilename)
205 { 221 {
206 if (0 != UNLINK (tmpfilename)) 222 if (0 != unlink (tmpfilename))
207 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", tmpfilename); 223 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
224 "unlink",
225 tmpfilename);
208 } 226 }
209 if (NULL != tid) 227 if (NULL != tid)
210 { 228 {
@@ -250,12 +268,14 @@ stdin_cb (void *cls)
250 /* ignore whitespace */ 268 /* ignore whitespace */
251 break; 269 break;
252 default: 270 default:
253 fprintf (stderr, _("Unknown command, use 'q' to quit or 'r' to restart peer\n")); 271 fprintf (stderr,
272 _ ("Unknown command, use 'q' to quit or 'r' to restart peer\n"));
254 break; 273 break;
255 } 274 }
256 tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 275 tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
257 fh, 276 fh,
258 &stdin_cb, NULL); 277 &stdin_cb,
278 NULL);
259} 279}
260 280
261 281
@@ -268,7 +288,8 @@ stdin_cb (void *cls)
268 * @param peer handle to the peer 288 * @param peer handle to the peer
269 */ 289 */
270static void 290static void
271testing_main (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, 291testing_main (void *cls,
292 const struct GNUNET_CONFIGURATION_Handle *cfg,
272 struct GNUNET_TESTING_Peer *peer) 293 struct GNUNET_TESTING_Peer *peer)
273{ 294{
274 my_peer = peer; 295 my_peer = peer;
@@ -285,17 +306,17 @@ testing_main (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
285 GNUNET_break (0); 306 GNUNET_break (0);
286 return; 307 return;
287 } 308 }
288 printf("ok\n%s\n", tmpfilename); 309 printf ("ok\n%s\n", tmpfilename);
289 fflush(stdout); 310 fflush (stdout);
290 GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); 311 GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL);
291 fh = GNUNET_DISK_get_handle_from_native (stdin); 312 fh = GNUNET_DISK_get_handle_from_native (stdin);
292 tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 313 tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
293 fh, 314 fh,
294 &stdin_cb, NULL); 315 &stdin_cb,
316 NULL);
295} 317}
296 318
297 319
298
299/** 320/**
300 * Main function that will be running without scheduler. 321 * Main function that will be running without scheduler.
301 * 322 *
@@ -305,13 +326,18 @@ testing_main (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
305 * @param cfg configuration 326 * @param cfg configuration
306 */ 327 */
307static void 328static void
308run_no_scheduler (void *cls, char *const *args, const char *cfgfile, 329run_no_scheduler (void *cls,
309 const struct GNUNET_CONFIGURATION_Handle *cfg) 330 char *const *args,
331 const char *cfgfile,
332 const struct GNUNET_CONFIGURATION_Handle *cfg)
310{ 333{
311 if (NULL != run_service_name) 334 if (NULL != run_service_name)
312 { 335 {
313 ret = GNUNET_TESTING_service_run ("gnunet_service_test", run_service_name, 336 ret = GNUNET_TESTING_service_run ("gnunet_service_test",
314 cfgfile, &testing_main, NULL); 337 run_service_name,
338 cfgfile,
339 &testing_main,
340 NULL);
315 return; 341 return;
316 } 342 }
317 343
@@ -320,7 +346,9 @@ run_no_scheduler (void *cls, char *const *args, const char *cfgfile,
320 if (create_no > 0) 346 if (create_no > 0)
321 { 347 {
322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
323 "Creating %u configuration files based on template `%s'\n", create_no, create_cfg_template); 349 "Creating %u configuration files based on template `%s'\n",
350 create_no,
351 create_cfg_template);
324 ret = create_unique_cfgs (create_cfg_template, create_no); 352 ret = create_unique_cfgs (create_cfg_template, create_no);
325 } 353 }
326 else 354 else
@@ -348,37 +376,42 @@ run_no_scheduler (void *cls, char *const *args, const char *cfgfile,
348int 376int
349main (int argc, char *const *argv) 377main (int argc, char *const *argv)
350{ 378{
351 struct GNUNET_GETOPT_CommandLineOption options[] = { 379 struct GNUNET_GETOPT_CommandLineOption options[] =
352 GNUNET_GETOPT_option_flag ('C', 380 {GNUNET_GETOPT_option_flag ('C',
353 "cfg", 381 "cfg",
354 gettext_noop ("create unique configuration files"), 382 gettext_noop (
355 &create_cfg), 383 "create unique configuration files"),
356 GNUNET_GETOPT_option_string ('k', 384 &create_cfg),
357 "key", 385 GNUNET_GETOPT_option_string (
358 "FILENAME", 386 'k',
359 gettext_noop ("extract hostkey file from pre-computed hostkey list"), 387 "key",
360 &create_hostkey), 388 "FILENAME",
361 389 gettext_noop ("extract hostkey file from pre-computed hostkey list"),
362 GNUNET_GETOPT_option_uint ('n', 390 &create_hostkey),
363 "number", 391
364 "NUMBER", 392 GNUNET_GETOPT_option_uint (
365 gettext_noop ("number of unique configuration files to create, or number of the hostkey to extract"), 393 'n',
366 &create_no), 394 "number",
367 395 "NUMBER",
368 396 gettext_noop (
369 GNUNET_GETOPT_option_string ('t', 397 "number of unique configuration files to create, or number of the hostkey to extract"),
370 "template", 398 &create_no),
371 "FILENAME", 399
372 gettext_noop ("configuration template"), 400
373 &create_cfg_template), 401 GNUNET_GETOPT_option_string ('t',
374 402 "template",
375 GNUNET_GETOPT_option_string ('r', 403 "FILENAME",
376 "run", 404 gettext_noop ("configuration template"),
377 "SERVICE", 405 &create_cfg_template),
378 gettext_noop ("run the given service, wait on stdin for 'r' (restart) or 'q' (quit)"), 406
379 &run_service_name), 407 GNUNET_GETOPT_option_string (
380 GNUNET_GETOPT_OPTION_END 408 'r',
381 }; 409 "run",
410 "SERVICE",
411 gettext_noop (
412 "run the given service, wait on stdin for 'r' (restart) or 'q' (quit)"),
413 &run_service_name),
414 GNUNET_GETOPT_OPTION_END};
382 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 415 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
383 return 2; 416 return 2;
384 417
@@ -386,11 +419,20 @@ main (int argc, char *const *argv)
386 * GNUNET_TESTING_service_run, which starts the scheduler on its own. 419 * GNUNET_TESTING_service_run, which starts the scheduler on its own.
387 * Furthermore, the other functionality currently does not require the scheduler, too, 420 * Furthermore, the other functionality currently does not require the scheduler, too,
388 * but beware when extending gnunet-testing. */ 421 * but beware when extending gnunet-testing. */
389 ret = (GNUNET_OK == 422 ret =
390 GNUNET_PROGRAM_run2 (argc, argv, "gnunet-testing", 423 (GNUNET_OK ==
391 gettext_noop ("Command line tool to access the testing library"), options, &run_no_scheduler, 424 GNUNET_PROGRAM_run2 (argc,
392 NULL, GNUNET_YES)) ? ret : 1; 425 argv,
393 GNUNET_free ((void*) argv); 426 "gnunet-testing",
427 gettext_noop (
428 "Command line tool to access the testing library"),
429 options,
430 &run_no_scheduler,
431 NULL,
432 GNUNET_YES))
433 ? ret
434 : 1;
435 GNUNET_free ((void *) argv);
394 return ret; 436 return ret;
395} 437}
396 438
diff --git a/src/testing/list-keys.c b/src/testing/list-keys.c
index 9210486d3..39a48d071 100644
--- a/src/testing/list-keys.c
+++ b/src/testing/list-keys.c
@@ -15,7 +15,9 @@ static int result;
15 * @param cfg the configuration file handle 15 * @param cfg the configuration file handle
16 */ 16 */
17static void 17static void
18run (void *cls, char *const *args, const char *cfgfile, 18run (void *cls,
19 char *const *args,
20 const char *cfgfile,
19 const struct GNUNET_CONFIGURATION_Handle *config) 21 const struct GNUNET_CONFIGURATION_Handle *config)
20{ 22{
21 char *idfile; 23 char *idfile;
@@ -30,7 +32,7 @@ run (void *cls, char *const *args, const char *cfgfile,
30 32
31 if ((NULL == args) || (NULL == args[0])) 33 if ((NULL == args) || (NULL == args[0]))
32 { 34 {
33 FPRINTF (stderr, "Need the hostkey file\n"); 35 fprintf (stderr, "Need the hostkey file\n");
34 return; 36 return;
35 } 37 }
36 idfile = args[0]; 38 idfile = args[0];
@@ -42,11 +44,11 @@ run (void *cls, char *const *args, const char *cfgfile,
42 } 44 }
43 if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE)) 45 if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE))
44 { 46 {
45 FPRINTF (stderr, 47 fprintf (stderr, _ ("Incorrect hostkey file format: %s\n"), idfile);
46 _("Incorrect hostkey file format: %s\n"), idfile);
47 return; 48 return;
48 } 49 }
49 f = GNUNET_DISK_file_open (idfile, GNUNET_DISK_OPEN_READ, 50 f = GNUNET_DISK_file_open (idfile,
51 GNUNET_DISK_OPEN_READ,
50 GNUNET_DISK_PERM_NONE); 52 GNUNET_DISK_PERM_NONE);
51 if (NULL == f) 53 if (NULL == f)
52 { 54 {
@@ -65,14 +67,14 @@ run (void *cls, char *const *args, const char *cfgfile,
65 { 67 {
66 if (nskip + cnt >= nmax) 68 if (nskip + cnt >= nmax)
67 { 69 {
68 PRINTF ("Max keys %u reached\n", nmax); 70 printf ("Max keys %u reached\n", nmax);
69 break; 71 break;
70 } 72 }
71 GNUNET_memcpy (&pkey, 73 GNUNET_memcpy (&pkey,
72 data + (cnt * GNUNET_TESTING_HOSTKEYFILESIZE), 74 data + (cnt * GNUNET_TESTING_HOSTKEYFILESIZE),
73 GNUNET_TESTING_HOSTKEYFILESIZE); 75 GNUNET_TESTING_HOSTKEYFILESIZE);
74 GNUNET_CRYPTO_eddsa_key_get_public (&pkey, &id.public_key); 76 GNUNET_CRYPTO_eddsa_key_get_public (&pkey, &id.public_key);
75 PRINTF ("Key %u: %s\n", cnt, GNUNET_i2s_full (&id)); 77 printf ("Key %u: %s\n", cnt, GNUNET_i2s_full (&id));
76 } 78 }
77 result = GNUNET_OK; 79 result = GNUNET_OK;
78 GNUNET_DISK_file_unmap (map); 80 GNUNET_DISK_file_unmap (map);
@@ -80,23 +82,28 @@ run (void *cls, char *const *args, const char *cfgfile,
80} 82}
81 83
82 84
83int main (int argc, char *argv[]) 85int
86main (int argc, char *argv[])
84{ 87{
85 struct GNUNET_GETOPT_CommandLineOption option[] = { 88 struct GNUNET_GETOPT_CommandLineOption option[] =
86 GNUNET_GETOPT_option_uint ('n', 89 {GNUNET_GETOPT_option_uint ('n',
87 "num-keys", 90 "num-keys",
88 "COUNT", 91 "COUNT",
89 gettext_noop ("list COUNT number of keys"), 92 gettext_noop ("list COUNT number of keys"),
90 &nkeys), 93 &nkeys),
91 GNUNET_GETOPT_OPTION_END 94 GNUNET_GETOPT_OPTION_END};
92 };
93 int ret; 95 int ret;
94 96
95 result = GNUNET_SYSERR; 97 result = GNUNET_SYSERR;
96 nkeys = 10; 98 nkeys = 10;
97 ret = 99 ret =
98 GNUNET_PROGRAM_run (argc, argv, "list-keys", "Lists the peer IDs corresponding to the given keys file\n", 100 GNUNET_PROGRAM_run (argc,
99 option, &run, NULL); 101 argv,
102 "list-keys",
103 "Lists the peer IDs corresponding to the given keys file\n",
104 option,
105 &run,
106 NULL);
100 if (GNUNET_OK != ret) 107 if (GNUNET_OK != ret)
101 return 1; 108 return 1;
102 if (GNUNET_SYSERR == result) 109 if (GNUNET_SYSERR == result)
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 7dbd97294..c5c240b37 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -34,8 +34,7 @@
34#include "gnunet_arm_service.h" 34#include "gnunet_arm_service.h"
35#include "gnunet_testing_lib.h" 35#include "gnunet_testing_lib.h"
36 36
37#define LOG(kind,...) \ 37#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
38 GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
39 38
40 39
41/** 40/**
@@ -269,7 +268,8 @@ hostkeys_load (struct GNUNET_TESTING_System *system)
269 if (GNUNET_YES != GNUNET_DISK_file_test (filename)) 268 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
270 { 269 {
271 LOG (GNUNET_ERROR_TYPE_ERROR, 270 LOG (GNUNET_ERROR_TYPE_ERROR,
272 _("Hostkeys file not found: %s\n"), filename); 271 _ ("Hostkeys file not found: %s\n"),
272 filename);
273 GNUNET_free (filename); 273 GNUNET_free (filename);
274 return GNUNET_SYSERR; 274 return GNUNET_SYSERR;
275 } 275 }
@@ -280,17 +280,19 @@ hostkeys_load (struct GNUNET_TESTING_System *system)
280 if (0 == fs) 280 if (0 == fs)
281 { 281 {
282 GNUNET_free (filename); 282 GNUNET_free (filename);
283 return GNUNET_SYSERR; /* File is empty */ 283 return GNUNET_SYSERR; /* File is empty */
284 } 284 }
285 if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE)) 285 if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE))
286 { 286 {
287 LOG (GNUNET_ERROR_TYPE_ERROR, 287 LOG (GNUNET_ERROR_TYPE_ERROR,
288 _("Incorrect hostkey file format: %s\n"), filename); 288 _ ("Incorrect hostkey file format: %s\n"),
289 filename);
289 GNUNET_free (filename); 290 GNUNET_free (filename);
290 return GNUNET_SYSERR; 291 return GNUNET_SYSERR;
291 } 292 }
292 fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 293 fd = GNUNET_DISK_file_open (filename,
293 GNUNET_DISK_PERM_NONE); 294 GNUNET_DISK_OPEN_READ,
295 GNUNET_DISK_PERM_NONE);
294 if (NULL == fd) 296 if (NULL == fd)
295 { 297 {
296 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename); 298 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename);
@@ -298,10 +300,8 @@ hostkeys_load (struct GNUNET_TESTING_System *system)
298 return GNUNET_SYSERR; 300 return GNUNET_SYSERR;
299 } 301 }
300 GNUNET_free (filename); 302 GNUNET_free (filename);
301 system->hostkeys_data = GNUNET_DISK_file_map (fd, 303 system->hostkeys_data =
302 &system->map, 304 GNUNET_DISK_file_map (fd, &system->map, GNUNET_DISK_MAP_TYPE_READ, fs);
303 GNUNET_DISK_MAP_TYPE_READ,
304 fs);
305 GNUNET_DISK_file_close (fd); 305 GNUNET_DISK_file_close (fd);
306 if (NULL == system->hostkeys_data) 306 if (NULL == system->hostkeys_data)
307 return GNUNET_SYSERR; 307 return GNUNET_SYSERR;
@@ -336,8 +336,10 @@ hostkeys_unload (struct GNUNET_TESTING_System *system)
336 * @param value value of the option 336 * @param value value of the option
337 */ 337 */
338static void 338static void
339cfg_copy_iterator (void *cls, const char *section, 339cfg_copy_iterator (void *cls,
340 const char *option, const char *value) 340 const char *section,
341 const char *option,
342 const char *value)
341{ 343{
342 struct GNUNET_CONFIGURATION_Handle *cfg2 = cls; 344 struct GNUNET_CONFIGURATION_Handle *cfg2 = cls;
343 345
@@ -367,14 +369,13 @@ cfg_copy_iterator (void *cls, const char *section,
367 * @return handle to this system, NULL on error 369 * @return handle to this system, NULL on error
368 */ 370 */
369struct GNUNET_TESTING_System * 371struct GNUNET_TESTING_System *
370GNUNET_TESTING_system_create_with_portrange (const char *testdir, 372GNUNET_TESTING_system_create_with_portrange (
371 const char *trusted_ip, 373 const char *testdir,
372 const char *hostname, 374 const char *trusted_ip,
373 const struct 375 const char *hostname,
374 GNUNET_TESTING_SharedService * 376 const struct GNUNET_TESTING_SharedService *shared_services,
375 shared_services, 377 uint16_t lowport,
376 uint16_t lowport, 378 uint16_t highport)
377 uint16_t highport)
378{ 379{
379 struct GNUNET_TESTING_System *system; 380 struct GNUNET_TESTING_System *system;
380 struct GNUNET_TESTING_SharedService tss; 381 struct GNUNET_TESTING_SharedService tss;
@@ -411,14 +412,21 @@ GNUNET_TESTING_system_create_with_portrange (const char *testdir,
411 ss = GNUNET_new (struct SharedService); 412 ss = GNUNET_new (struct SharedService);
412 ss->sname = GNUNET_strdup (tss.service); 413 ss->sname = GNUNET_strdup (tss.service);
413 ss->cfg = GNUNET_CONFIGURATION_create (); 414 ss->cfg = GNUNET_CONFIGURATION_create ();
414 GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, ss->sname, 415 GNUNET_CONFIGURATION_iterate_section_values (tss.cfg,
415 &cfg_copy_iterator, ss->cfg); 416 ss->sname,
416 GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, "TESTING", 417 &cfg_copy_iterator,
417 &cfg_copy_iterator, ss->cfg); 418 ss->cfg);
418 GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, "PATHS", 419 GNUNET_CONFIGURATION_iterate_section_values (tss.cfg,
419 &cfg_copy_iterator, ss->cfg); 420 "TESTING",
421 &cfg_copy_iterator,
422 ss->cfg);
423 GNUNET_CONFIGURATION_iterate_section_values (tss.cfg,
424 "PATHS",
425 &cfg_copy_iterator,
426 ss->cfg);
420 ss->share = tss.share; 427 ss->share = tss.share;
421 GNUNET_array_append (system->shared_services, system->n_shared_services, 428 GNUNET_array_append (system->shared_services,
429 system->n_shared_services,
422 ss); 430 ss);
423 } 431 }
424 return system; 432 return system;
@@ -446,18 +454,18 @@ GNUNET_TESTING_system_create_with_portrange (const char *testdir,
446 * @return handle to this system, NULL on error 454 * @return handle to this system, NULL on error
447 */ 455 */
448struct GNUNET_TESTING_System * 456struct GNUNET_TESTING_System *
449GNUNET_TESTING_system_create (const char *testdir, 457GNUNET_TESTING_system_create (
450 const char *trusted_ip, 458 const char *testdir,
451 const char *hostname, 459 const char *trusted_ip,
452 const struct GNUNET_TESTING_SharedService * 460 const char *hostname,
453 shared_services) 461 const struct GNUNET_TESTING_SharedService *shared_services)
454{ 462{
455 return GNUNET_TESTING_system_create_with_portrange (testdir, 463 return GNUNET_TESTING_system_create_with_portrange (testdir,
456 trusted_ip, 464 trusted_ip,
457 hostname, 465 hostname,
458 shared_services, 466 shared_services,
459 LOW_PORT, 467 LOW_PORT,
460 HIGH_PORT); 468 HIGH_PORT);
461} 469}
462 470
463 471
@@ -490,7 +498,9 @@ start_shared_service_instance (struct SharedServiceInstance *i)
490 GNUNET_free (binary); 498 GNUNET_free (binary);
491 i->proc = GNUNET_OS_start_process (PIPE_CONTROL, 499 i->proc = GNUNET_OS_start_process (PIPE_CONTROL,
492 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 500 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
493 NULL, NULL, NULL, 501 NULL,
502 NULL,
503 NULL,
494 libexec_binary, 504 libexec_binary,
495 libexec_binary, 505 libexec_binary,
496 "-c", 506 "-c",
@@ -509,7 +519,8 @@ stop_shared_service_instance (struct SharedServiceInstance *i)
509 GNUNET_break (0 == i->n_refs); 519 GNUNET_break (0 == i->n_refs);
510 if (0 != GNUNET_OS_process_kill (i->proc, GNUNET_TERM_SIG)) 520 if (0 != GNUNET_OS_process_kill (i->proc, GNUNET_TERM_SIG))
511 LOG (GNUNET_ERROR_TYPE_WARNING, 521 LOG (GNUNET_ERROR_TYPE_WARNING,
512 "Killing shared service instance (%s) failed\n", i->ss->sname); 522 "Killing shared service instance (%s) failed\n",
523 i->ss->sname);
513 (void) GNUNET_OS_process_wait (i->proc); 524 (void) GNUNET_OS_process_wait (i->proc);
514 GNUNET_OS_process_destroy (i->proc); 525 GNUNET_OS_process_destroy (i->proc);
515 i->proc = NULL; 526 i->proc = NULL;
@@ -525,7 +536,7 @@ stop_shared_service_instance (struct SharedServiceInstance *i)
525 */ 536 */
526void 537void
527GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, 538GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system,
528 int remove_paths) 539 int remove_paths)
529{ 540{
530 struct SharedService *ss; 541 struct SharedService *ss;
531 struct SharedServiceInstance *i; 542 struct SharedServiceInstance *i;
@@ -589,19 +600,20 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system)
589 On system with either IPv4 or IPv6. A port is considered open if it's 600 On system with either IPv4 or IPv6. A port is considered open if it's
590 open in the respective address family 601 open in the respective address family
591 */ 602 */
592 hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */ 603 hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */
593 hint.ai_socktype = 0; 604 hint.ai_socktype = 0;
594 hint.ai_protocol = 0; 605 hint.ai_protocol = 0;
595 hint.ai_addrlen = 0; 606 hint.ai_addrlen = 0;
596 hint.ai_addr = NULL; 607 hint.ai_addr = NULL;
597 hint.ai_canonname = NULL; 608 hint.ai_canonname = NULL;
598 hint.ai_next = NULL; 609 hint.ai_next = NULL;
599 hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */ 610 hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */
600 port_buckets = system->reserved_ports; 611 port_buckets = system->reserved_ports;
601 for (index = (system->lowport / 32) + 1; index < (system->highport / 32); index++) 612 for (index = (system->lowport / 32) + 1; index < (system->highport / 32);
613 index++)
602 { 614 {
603 xor_image = (UINT32_MAX ^ port_buckets[index]); 615 xor_image = (UINT32_MAX ^ port_buckets[index]);
604 if (0 == xor_image) /* Ports in the bucket are full */ 616 if (0 == xor_image) /* Ports in the bucket are full */
605 continue; 617 continue;
606 pos = system->lowport % 32; 618 pos = system->lowport % 32;
607 while (pos < 32) 619 while (pos < 32)
@@ -613,7 +625,7 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system)
613 } 625 }
614 open_port = (index * 32) + pos; 626 open_port = (index * 32) + pos;
615 if (open_port >= system->highport) 627 if (open_port >= system->highport)
616 return 0; 628 return 0;
617 GNUNET_asprintf (&open_port_str, "%u", (unsigned int) open_port); 629 GNUNET_asprintf (&open_port_str, "%u", (unsigned int) open_port);
618 ret = NULL; 630 ret = NULL;
619 GNUNET_assert (0 == getaddrinfo (NULL, open_port_str, &hint, &ret)); 631 GNUNET_assert (0 == getaddrinfo (NULL, open_port_str, &hint, &ret));
@@ -624,18 +636,16 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system)
624 socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_STREAM, 0); 636 socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_STREAM, 0);
625 if (NULL == socket) 637 if (NULL == socket)
626 continue; 638 continue;
627 bind_status = GNUNET_NETWORK_socket_bind (socket, 639 bind_status =
628 ai->ai_addr, 640 GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen);
629 ai->ai_addrlen);
630 GNUNET_NETWORK_socket_close (socket); 641 GNUNET_NETWORK_socket_close (socket);
631 if (GNUNET_OK != bind_status) 642 if (GNUNET_OK != bind_status)
632 break; 643 break;
633 socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_DGRAM, 0); 644 socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_DGRAM, 0);
634 if (NULL == socket) 645 if (NULL == socket)
635 continue; 646 continue;
636 bind_status = GNUNET_NETWORK_socket_bind (socket, 647 bind_status =
637 ai->ai_addr, 648 GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen);
638 ai->ai_addrlen);
639 GNUNET_NETWORK_socket_close (socket); 649 GNUNET_NETWORK_socket_close (socket);
640 if (GNUNET_OK != bind_status) 650 if (GNUNET_OK != bind_status)
641 break; 651 break;
@@ -645,8 +655,9 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system)
645 if (GNUNET_OK == bind_status) 655 if (GNUNET_OK == bind_status)
646 { 656 {
647 LOG (GNUNET_ERROR_TYPE_DEBUG, 657 LOG (GNUNET_ERROR_TYPE_DEBUG,
648 "Found a free port %u\n", (unsigned int) open_port); 658 "Found a free port %u\n",
649 return open_port; 659 (unsigned int) open_port);
660 return open_port;
650 } 661 }
651 pos++; 662 pos++;
652 } 663 }
@@ -664,7 +675,7 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system)
664 */ 675 */
665void 676void
666GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system, 677GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system,
667 uint16_t port) 678 uint16_t port)
668{ 679{
669 uint32_t *port_buckets; 680 uint32_t *port_buckets;
670 uint16_t bucket; 681 uint16_t bucket;
@@ -676,7 +687,7 @@ GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system,
676 LOG (GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port); 687 LOG (GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port);
677 if (0 == (port_buckets[bucket] & (1U << pos))) 688 if (0 == (port_buckets[bucket] & (1U << pos)))
678 { 689 {
679 GNUNET_break(0); /* Port was not reserved by us using reserve_port() */ 690 GNUNET_break (0); /* Port was not reserved by us using reserve_port() */
680 return; 691 return;
681 } 692 }
682 port_buckets[bucket] &= ~(1U << pos); 693 port_buckets[bucket] &= ~(1U << pos);
@@ -702,8 +713,8 @@ GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system,
702 */ 713 */
703struct GNUNET_CRYPTO_EddsaPrivateKey * 714struct GNUNET_CRYPTO_EddsaPrivateKey *
704GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system, 715GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system,
705 uint32_t key_number, 716 uint32_t key_number,
706 struct GNUNET_PeerIdentity *id) 717 struct GNUNET_PeerIdentity *id)
707{ 718{
708 struct GNUNET_CRYPTO_EddsaPrivateKey *private_key; 719 struct GNUNET_CRYPTO_EddsaPrivateKey *private_key;
709 720
@@ -712,17 +723,16 @@ GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system,
712 if (key_number >= system->total_hostkeys) 723 if (key_number >= system->total_hostkeys)
713 { 724 {
714 LOG (GNUNET_ERROR_TYPE_ERROR, 725 LOG (GNUNET_ERROR_TYPE_ERROR,
715 _("Key number %u does not exist\n"), 726 _ ("Key number %u does not exist\n"),
716 key_number); 727 key_number);
717 return NULL; 728 return NULL;
718 } 729 }
719 private_key = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey); 730 private_key = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey);
720 GNUNET_memcpy (private_key, 731 GNUNET_memcpy (private_key,
721 system->hostkeys_data + 732 system->hostkeys_data +
722 (key_number * GNUNET_TESTING_HOSTKEYFILESIZE), 733 (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
723 GNUNET_TESTING_HOSTKEYFILESIZE); 734 GNUNET_TESTING_HOSTKEYFILESIZE);
724 GNUNET_CRYPTO_eddsa_key_get_public (private_key, 735 GNUNET_CRYPTO_eddsa_key_get_public (private_key, &id->public_key);
725 &id->public_key);
726 return private_key; 736 return private_key;
727} 737}
728 738
@@ -794,18 +804,17 @@ update_config (void *cls,
794 804
795 if (GNUNET_OK != uc->status) 805 if (GNUNET_OK != uc->status)
796 return; 806 return;
797 if (! ((0 == strcmp (option, "PORT")) 807 if (! ((0 == strcmp (option, "PORT")) || (0 == strcmp (option, "UNIXPATH")) ||
798 || (0 == strcmp (option, "UNIXPATH")) 808 (0 == strcmp (option, "HOSTNAME"))))
799 || (0 == strcmp (option, "HOSTNAME"))))
800 return; 809 return;
801 GNUNET_asprintf (&single_variable, "single_%s_per_host", section); 810 GNUNET_asprintf (&single_variable, "single_%s_per_host", section);
802 GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section); 811 GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section);
803 if ((0 == strcmp (option, "PORT")) && (1 == SSCANF (value, "%u", &ival))) 812 if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival)))
804 { 813 {
805 if ((ival != 0) && 814 if ((ival != 0) &&
806 (GNUNET_YES != 815 (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (uc->cfg,
807 GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, "testing", 816 "testing",
808 single_variable))) 817 single_variable)))
809 { 818 {
810 new_port = GNUNET_TESTING_reserve_port (uc->system); 819 new_port = GNUNET_TESTING_reserve_port (uc->system);
811 if (0 == new_port) 820 if (0 == new_port)
@@ -821,37 +830,41 @@ update_config (void *cls,
821 } 830 }
822 else if ((ival != 0) && 831 else if ((ival != 0) &&
823 (GNUNET_YES == 832 (GNUNET_YES ==
824 GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, "testing", 833 GNUNET_CONFIGURATION_get_value_yesno (uc->cfg,
834 "testing",
825 single_variable)) && 835 single_variable)) &&
826 GNUNET_CONFIGURATION_get_value_number (uc->cfg, "testing", 836 GNUNET_CONFIGURATION_get_value_number (uc->cfg,
837 "testing",
827 per_host_variable, 838 per_host_variable,
828 &num_per_host)) 839 &num_per_host))
829 { 840 {
830 /* GNUNET_snprintf (cval, sizeof (cval), "%u", */ 841 /* GNUNET_snprintf (cval, sizeof (cval), "%u", */
831 /* ival + ctx->fdnum % num_per_host); */ 842 /* ival + ctx->fdnum % num_per_host); */
832 /* value = cval; */ 843 /* value = cval; */
833 GNUNET_break (0); /* FIXME */ 844 GNUNET_break (0); /* FIXME */
834 } 845 }
835 } 846 }
836 if (0 == strcmp (option, "UNIXPATH")) 847 if (0 == strcmp (option, "UNIXPATH"))
837 { 848 {
838 if (GNUNET_YES != 849 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (uc->cfg,
839 GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, "testing", 850 "testing",
840 single_variable)) 851 single_variable))
841 { 852 {
842 GNUNET_snprintf (uval, 853 GNUNET_snprintf (uval,
843 sizeof (uval), 854 sizeof (uval),
844 "%s/%s.sock", 855 "%s/%s.sock",
845 uc->gnunet_home, section); 856 uc->gnunet_home,
857 section);
846 value = uval; 858 value = uval;
847 } 859 }
848 else if ((GNUNET_YES == 860 else if ((GNUNET_YES ==
849 GNUNET_CONFIGURATION_get_value_number (uc->cfg, "testing", 861 GNUNET_CONFIGURATION_get_value_number (uc->cfg,
862 "testing",
850 per_host_variable, 863 per_host_variable,
851 &num_per_host)) && 864 &num_per_host)) &&
852 (num_per_host > 0)) 865 (num_per_host > 0))
853 { 866 {
854 GNUNET_break(0); /* FIXME */ 867 GNUNET_break (0); /* FIXME */
855 } 868 }
856 } 869 }
857 if (0 == strcmp (option, "HOSTNAME")) 870 if (0 == strcmp (option, "HOSTNAME"))
@@ -872,8 +885,7 @@ update_config (void *cls,
872 * @param section name of the section 885 * @param section name of the section
873 */ 886 */
874static void 887static void
875update_config_sections (void *cls, 888update_config_sections (void *cls, const char *section)
876 const char *section)
877{ 889{
878 struct UpdateContext *uc = cls; 890 struct UpdateContext *uc = cls;
879 char **ikeys; 891 char **ikeys;
@@ -889,13 +901,14 @@ update_config_sections (void *cls,
889 val = NULL; 901 val = NULL;
890 /* Ignore certain options from sections. See 902 /* Ignore certain options from sections. See
891 https://gnunet.org/bugs/view.php?id=2476 */ 903 https://gnunet.org/bugs/view.php?id=2476 */
892 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (uc->cfg, section, 904 if (GNUNET_YES ==
893 "TESTING_IGNORE_KEYS")) 905 GNUNET_CONFIGURATION_have_value (uc->cfg, section, "TESTING_IGNORE_KEYS"))
894 { 906 {
895 GNUNET_assert 907 GNUNET_assert (GNUNET_YES ==
896 (GNUNET_YES == 908 GNUNET_CONFIGURATION_get_value_string (uc->cfg,
897 GNUNET_CONFIGURATION_get_value_string (uc->cfg, section, 909 section,
898 "TESTING_IGNORE_KEYS", &val)); 910 "TESTING_IGNORE_KEYS",
911 &val));
899 ptr = val; 912 ptr = val;
900 for (ikeys_cnt = 0; NULL != (ptr = strstr (ptr, ";")); ikeys_cnt++) 913 for (ikeys_cnt = 0; NULL != (ptr = strstr (ptr, ";")); ikeys_cnt++)
901 ptr++; 914 ptr++;
@@ -920,18 +933,22 @@ update_config_sections (void *cls,
920 for (key = 0; key < ikeys_cnt; key++) 933 for (key = 0; key < ikeys_cnt; key++)
921 { 934 {
922 if (NULL != strstr (ikeys[key], "ADVERTISED_PORT")) 935 if (NULL != strstr (ikeys[key], "ADVERTISED_PORT"))
923 break; 936 break;
924 } 937 }
925 if ((key == ikeys_cnt) && 938 if ((key == ikeys_cnt) &&
926 (GNUNET_YES == GNUNET_CONFIGURATION_have_value (uc->cfg, section, 939 (GNUNET_YES ==
927 "ADVERTISED_PORT"))) 940 GNUNET_CONFIGURATION_have_value (uc->cfg, section, "ADVERTISED_PORT")))
928 { 941 {
929 if (GNUNET_OK == 942 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (uc->cfg,
930 GNUNET_CONFIGURATION_get_value_string (uc->cfg, section, "PORT", &ptr)) 943 section,
944 "PORT",
945 &ptr))
931 { 946 {
932 GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, 947 GNUNET_CONFIGURATION_set_value_string (uc->cfg,
933 "ADVERTISED_PORT", ptr); 948 section,
934 GNUNET_free (ptr); 949 "ADVERTISED_PORT",
950 ptr);
951 GNUNET_free (ptr);
935 } 952 }
936 } 953 }
937 for (key = 0; key < ikeys_cnt; key++) 954 for (key = 0; key < ikeys_cnt; key++)
@@ -950,19 +967,24 @@ update_config_sections (void *cls,
950 if ((NULL != uc->system->trusted_ip) && 967 if ((NULL != uc->system->trusted_ip) &&
951 (NULL != strstr (uc->system->trusted_ip, ":"))) /* IPv6 in use */ 968 (NULL != strstr (uc->system->trusted_ip, ":"))) /* IPv6 in use */
952 ACCEPT_FROM_key = "ACCEPT_FROM6"; 969 ACCEPT_FROM_key = "ACCEPT_FROM6";
953 if (GNUNET_OK != 970 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (uc->cfg,
954 GNUNET_CONFIGURATION_get_value_string (uc->cfg, section, ACCEPT_FROM_key, 971 section,
955 &orig_allowed_hosts)) 972 ACCEPT_FROM_key,
973 &orig_allowed_hosts))
956 { 974 {
957 orig_allowed_hosts = GNUNET_strdup ("127.0.0.1;"); 975 orig_allowed_hosts = GNUNET_strdup ("127.0.0.1;");
958 } 976 }
959 if (NULL == uc->system->trusted_ip) 977 if (NULL == uc->system->trusted_ip)
960 allowed_hosts = GNUNET_strdup (orig_allowed_hosts); 978 allowed_hosts = GNUNET_strdup (orig_allowed_hosts);
961 else 979 else
962 GNUNET_asprintf (&allowed_hosts, "%s%s;", orig_allowed_hosts, 980 GNUNET_asprintf (&allowed_hosts,
981 "%s%s;",
982 orig_allowed_hosts,
963 uc->system->trusted_ip); 983 uc->system->trusted_ip);
964 GNUNET_free (orig_allowed_hosts); 984 GNUNET_free (orig_allowed_hosts);
965 GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, ACCEPT_FROM_key, 985 GNUNET_CONFIGURATION_set_value_string (uc->cfg,
986 section,
987 ACCEPT_FROM_key,
966 allowed_hosts); 988 allowed_hosts);
967 GNUNET_free (allowed_hosts); 989 GNUNET_free (allowed_hosts);
968} 990}
@@ -979,15 +1001,17 @@ associate_shared_service (struct GNUNET_TESTING_System *system,
979 uint32_t port; 1001 uint32_t port;
980 1002
981 ss->n_peers++; 1003 ss->n_peers++;
982 if ( ((0 == ss->share) && (NULL == ss->instances)) 1004 if (((0 == ss->share) && (NULL == ss->instances)) ||
983 || 1005 ((0 != ss->share) &&
984 ( (0 != ss->share) 1006 (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share))))
985 && (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share)) ) )
986 { 1007 {
987 i = GNUNET_new (struct SharedServiceInstance); 1008 i = GNUNET_new (struct SharedServiceInstance);
988 i->ss = ss; 1009 i->ss = ss;
989 (void) GNUNET_asprintf (&gnunet_home, "%s/shared/%s/%u", 1010 (void) GNUNET_asprintf (&gnunet_home,
990 system->tmppath, ss->sname, ss->n_instances); 1011 "%s/shared/%s/%u",
1012 system->tmppath,
1013 ss->sname,
1014 ss->n_instances);
991 (void) GNUNET_asprintf (&i->unix_sock, "%s/sock", gnunet_home); 1015 (void) GNUNET_asprintf (&i->unix_sock, "%s/sock", gnunet_home);
992 port = GNUNET_TESTING_reserve_port (system); 1016 port = GNUNET_TESTING_reserve_port (system);
993 if (0 == port) 1017 if (0 == port)
@@ -1000,12 +1024,18 @@ associate_shared_service (struct GNUNET_TESTING_System *system,
1000 temp = GNUNET_CONFIGURATION_dup (ss->cfg); 1024 temp = GNUNET_CONFIGURATION_dup (ss->cfg);
1001 (void) GNUNET_asprintf (&i->port_str, "%u", port); 1025 (void) GNUNET_asprintf (&i->port_str, "%u", port);
1002 (void) GNUNET_asprintf (&i->cfg_fn, "%s/config", gnunet_home); 1026 (void) GNUNET_asprintf (&i->cfg_fn, "%s/config", gnunet_home);
1003 GNUNET_CONFIGURATION_set_value_string (temp, "PATHS", "GNUNET_HOME", 1027 GNUNET_CONFIGURATION_set_value_string (temp,
1028 "PATHS",
1029 "GNUNET_HOME",
1004 gnunet_home); 1030 gnunet_home);
1005 GNUNET_free (gnunet_home); 1031 GNUNET_free (gnunet_home);
1006 GNUNET_CONFIGURATION_set_value_string (temp, ss->sname, "UNIXPATH", 1032 GNUNET_CONFIGURATION_set_value_string (temp,
1033 ss->sname,
1034 "UNIXPATH",
1007 i->unix_sock); 1035 i->unix_sock);
1008 GNUNET_CONFIGURATION_set_value_string (temp, ss->sname, "PORT", 1036 GNUNET_CONFIGURATION_set_value_string (temp,
1037 ss->sname,
1038 "PORT",
1009 i->port_str); 1039 i->port_str);
1010 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_write (temp, i->cfg_fn)) 1040 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_write (temp, i->cfg_fn))
1011 { 1041 {
@@ -1021,9 +1051,13 @@ associate_shared_service (struct GNUNET_TESTING_System *system,
1021 GNUNET_assert (0 < ss->n_instances); 1051 GNUNET_assert (0 < ss->n_instances);
1022 i = ss->instances[ss->n_instances - 1]; 1052 i = ss->instances[ss->n_instances - 1];
1023 } 1053 }
1024 GNUNET_CONFIGURATION_iterate_section_values(ss->cfg, ss->sname, 1054 GNUNET_CONFIGURATION_iterate_section_values (ss->cfg,
1025 &cfg_copy_iterator, cfg); 1055 ss->sname,
1026 GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "UNIXPATH", 1056 &cfg_copy_iterator,
1057 cfg);
1058 GNUNET_CONFIGURATION_set_value_string (cfg,
1059 ss->sname,
1060 "UNIXPATH",
1027 i->unix_sock); 1061 i->unix_sock);
1028 GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "PORT", i->port_str); 1062 GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "PORT", i->port_str);
1029 return i; 1063 return i;
@@ -1063,24 +1097,27 @@ GNUNET_TESTING_configuration_create_ (struct GNUNET_TESTING_System *system,
1063 uc.status = GNUNET_OK; 1097 uc.status = GNUNET_OK;
1064 uc.ports = NULL; 1098 uc.ports = NULL;
1065 uc.nports = 0; 1099 uc.nports = 0;
1066 GNUNET_asprintf (&uc.gnunet_home, "%s/%u", system->tmppath, 1100 GNUNET_asprintf (&uc.gnunet_home,
1101 "%s/%u",
1102 system->tmppath,
1067 system->path_counter++); 1103 system->path_counter++);
1068 GNUNET_asprintf (&default_config, "%s/config", uc.gnunet_home); 1104 GNUNET_asprintf (&default_config, "%s/config", uc.gnunet_home);
1069 GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", 1105 GNUNET_CONFIGURATION_set_value_string (cfg,
1070 default_config); 1106 "PATHS",
1071 GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", 1107 "DEFAULTCONFIG",
1072 default_config); 1108 default_config);
1109 GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", default_config);
1073 GNUNET_free (default_config); 1110 GNUNET_free (default_config);
1074 GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "GNUNET_HOME", 1111 GNUNET_CONFIGURATION_set_value_string (cfg,
1112 "PATHS",
1113 "GNUNET_HOME",
1075 uc.gnunet_home); 1114 uc.gnunet_home);
1076 /* make PORTs and UNIXPATHs unique */ 1115 /* make PORTs and UNIXPATHs unique */
1077 GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc); 1116 GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc);
1078 /* allow connections to services from system trusted_ip host */ 1117 /* allow connections to services from system trusted_ip host */
1079 GNUNET_CONFIGURATION_iterate_sections (cfg, &update_config_sections, &uc); 1118 GNUNET_CONFIGURATION_iterate_sections (cfg, &update_config_sections, &uc);
1080 /* enable loopback-based connections between peers */ 1119 /* enable loopback-based connections between peers */
1081 GNUNET_CONFIGURATION_set_value_string (cfg, 1120 GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "USE_LOCALADDR", "YES");
1082 "nat",
1083 "USE_LOCALADDR", "YES");
1084 GNUNET_free (uc.gnunet_home); 1121 GNUNET_free (uc.gnunet_home);
1085 if ((NULL != ports) && (NULL != nports)) 1122 if ((NULL != ports) && (NULL != nports))
1086 { 1123 {
@@ -1111,7 +1148,7 @@ GNUNET_TESTING_configuration_create_ (struct GNUNET_TESTING_System *system,
1111 */ 1148 */
1112int 1149int
1113GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system, 1150GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system,
1114 struct GNUNET_CONFIGURATION_Handle *cfg) 1151 struct GNUNET_CONFIGURATION_Handle *cfg)
1115{ 1152{
1116 return GNUNET_TESTING_configuration_create_ (system, cfg, NULL, NULL); 1153 return GNUNET_TESTING_configuration_create_ (system, cfg, NULL, NULL);
1117} 1154}
@@ -1132,10 +1169,10 @@ GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system,
1132 */ 1169 */
1133struct GNUNET_TESTING_Peer * 1170struct GNUNET_TESTING_Peer *
1134GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, 1171GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1135 struct GNUNET_CONFIGURATION_Handle *cfg, 1172 struct GNUNET_CONFIGURATION_Handle *cfg,
1136 uint32_t key_number, 1173 uint32_t key_number,
1137 struct GNUNET_PeerIdentity *id, 1174 struct GNUNET_PeerIdentity *id,
1138 char **emsg) 1175 char **emsg)
1139{ 1176{
1140 struct GNUNET_TESTING_Peer *peer; 1177 struct GNUNET_TESTING_Peer *peer;
1141 struct GNUNET_DISK_FileHandle *fd; 1178 struct GNUNET_DISK_FileHandle *fd;
@@ -1157,9 +1194,11 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1157 *emsg = NULL; 1194 *emsg = NULL;
1158 if (key_number >= system->total_hostkeys) 1195 if (key_number >= system->total_hostkeys)
1159 { 1196 {
1160 GNUNET_asprintf (&emsg_, 1197 GNUNET_asprintf (
1161 _("You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"), 1198 &emsg_,
1162 (unsigned int) system->total_hostkeys); 1199 _ (
1200 "You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"),
1201 (unsigned int) system->total_hostkeys);
1163 goto err_ret; 1202 goto err_ret;
1164 } 1203 }
1165 pk = NULL; 1204 pk = NULL;
@@ -1167,17 +1206,17 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1167 (NULL == (pk = GNUNET_TESTING_hostkey_get (system, key_number, id)))) 1206 (NULL == (pk = GNUNET_TESTING_hostkey_get (system, key_number, id))))
1168 { 1207 {
1169 GNUNET_asprintf (&emsg_, 1208 GNUNET_asprintf (&emsg_,
1170 _("Failed to initialize hostkey for peer %u\n"), 1209 _ ("Failed to initialize hostkey for peer %u\n"),
1171 (unsigned int) key_number); 1210 (unsigned int) key_number);
1172 goto err_ret; 1211 goto err_ret;
1173 } 1212 }
1174 if (NULL != pk) 1213 if (NULL != pk)
1175 GNUNET_free (pk); 1214 GNUNET_free (pk);
1176 if (GNUNET_NO == 1215 if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg, "PEER", "PRIVATE_KEY"))
1177 GNUNET_CONFIGURATION_have_value (cfg, "PEER", "PRIVATE_KEY"))
1178 { 1216 {
1179 GNUNET_asprintf (&emsg_, 1217 GNUNET_asprintf (
1180 _("PRIVATE_KEY option in PEER section missing in configuration\n")); 1218 &emsg_,
1219 _ ("PRIVATE_KEY option in PEER section missing in configuration\n"));
1181 goto err_ret; 1220 goto err_ret;
1182 } 1221 }
1183 /* Remove sections for shared services */ 1222 /* Remove sections for shared services */
@@ -1186,46 +1225,50 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1186 ss = system->shared_services[cnt]; 1225 ss = system->shared_services[cnt];
1187 GNUNET_CONFIGURATION_remove_section (cfg, ss->sname); 1226 GNUNET_CONFIGURATION_remove_section (cfg, ss->sname);
1188 } 1227 }
1189 if (GNUNET_OK != GNUNET_TESTING_configuration_create_ (system, cfg, 1228 if (GNUNET_OK !=
1190 &ports, &nports)) 1229 GNUNET_TESTING_configuration_create_ (system, cfg, &ports, &nports))
1191 { 1230 {
1192 GNUNET_asprintf (&emsg_, 1231 GNUNET_asprintf (&emsg_,
1193 _("Failed to create configuration for peer " 1232 _ ("Failed to create configuration for peer "
1194 "(not enough free ports?)\n")); 1233 "(not enough free ports?)\n"));
1195 goto err_ret; 1234 goto err_ret;
1196 } 1235 }
1197 GNUNET_assert (GNUNET_OK == 1236 GNUNET_assert (GNUNET_OK ==
1198 GNUNET_CONFIGURATION_get_value_filename (cfg, "PEER", 1237 GNUNET_CONFIGURATION_get_value_filename (cfg,
1199 "PRIVATE_KEY", 1238 "PEER",
1200 &hostkey_filename)); 1239 "PRIVATE_KEY",
1240 &hostkey_filename));
1201 fd = GNUNET_DISK_file_open (hostkey_filename, 1241 fd = GNUNET_DISK_file_open (hostkey_filename,
1202 GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_WRITE, 1242 GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_WRITE,
1203 GNUNET_DISK_PERM_USER_READ 1243 GNUNET_DISK_PERM_USER_READ |
1204 | GNUNET_DISK_PERM_USER_WRITE); 1244 GNUNET_DISK_PERM_USER_WRITE);
1205 if (NULL == fd) 1245 if (NULL == fd)
1206 { 1246 {
1207 GNUNET_asprintf (&emsg_, _("Cannot open hostkey file `%s': %s\n"), 1247 GNUNET_asprintf (&emsg_,
1208 hostkey_filename, STRERROR (errno)); 1248 _ ("Cannot open hostkey file `%s': %s\n"),
1249 hostkey_filename,
1250 strerror (errno));
1209 GNUNET_free (hostkey_filename); 1251 GNUNET_free (hostkey_filename);
1210 goto err_ret; 1252 goto err_ret;
1211 } 1253 }
1212 GNUNET_free (hostkey_filename); 1254 GNUNET_free (hostkey_filename);
1213 if (GNUNET_TESTING_HOSTKEYFILESIZE != 1255 if (GNUNET_TESTING_HOSTKEYFILESIZE !=
1214 GNUNET_DISK_file_write (fd, system->hostkeys_data 1256 GNUNET_DISK_file_write (fd,
1215 + (key_number * GNUNET_TESTING_HOSTKEYFILESIZE), 1257 system->hostkeys_data +
1216 GNUNET_TESTING_HOSTKEYFILESIZE)) 1258 (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
1259 GNUNET_TESTING_HOSTKEYFILESIZE))
1217 { 1260 {
1218 GNUNET_asprintf (&emsg_, 1261 GNUNET_asprintf (&emsg_,
1219 _("Failed to write hostkey file for peer %u: %s\n"), 1262 _ ("Failed to write hostkey file for peer %u: %s\n"),
1220 (unsigned int) key_number, 1263 (unsigned int) key_number,
1221 STRERROR (errno)); 1264 strerror (errno));
1222 GNUNET_DISK_file_close (fd); 1265 GNUNET_DISK_file_close (fd);
1223 goto err_ret; 1266 goto err_ret;
1224 } 1267 }
1225 GNUNET_DISK_file_close (fd); 1268 GNUNET_DISK_file_close (fd);
1226 ss_instances = GNUNET_malloc (sizeof (struct SharedServiceInstance *) 1269 ss_instances = GNUNET_malloc (sizeof (struct SharedServiceInstance *) *
1227 * system->n_shared_services); 1270 system->n_shared_services);
1228 for (cnt=0; cnt < system->n_shared_services; cnt++) 1271 for (cnt = 0; cnt < system->n_shared_services; cnt++)
1229 { 1272 {
1230 ss = system->shared_services[cnt]; 1273 ss = system->shared_services[cnt];
1231 ss_instances[cnt] = associate_shared_service (system, ss, cfg); 1274 ss_instances[cnt] = associate_shared_service (system, ss, cfg);
@@ -1236,15 +1279,18 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1236 } 1279 }
1237 } 1280 }
1238 GNUNET_assert (GNUNET_OK == 1281 GNUNET_assert (GNUNET_OK ==
1239 GNUNET_CONFIGURATION_get_value_filename 1282 GNUNET_CONFIGURATION_get_value_filename (cfg,
1240 (cfg, "PATHS", "DEFAULTCONFIG", &config_filename)); 1283 "PATHS",
1284 "DEFAULTCONFIG",
1285 &config_filename));
1241 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config_filename)) 1286 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config_filename))
1242 { 1287 {
1243 GNUNET_asprintf (&emsg_, 1288 GNUNET_asprintf (&emsg_,
1244 _("Failed to write configuration file `%s' for peer %u: %s\n"), 1289 _ (
1245 config_filename, 1290 "Failed to write configuration file `%s' for peer %u: %s\n"),
1246 (unsigned int) key_number, 1291 config_filename,
1247 STRERROR (errno)); 1292 (unsigned int) key_number,
1293 strerror (errno));
1248 GNUNET_free (config_filename); 1294 GNUNET_free (config_filename);
1249 goto err_ret; 1295 goto err_ret;
1250 } 1296 }
@@ -1253,10 +1299,14 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1253 peer->cfgfile = config_filename; /* Free in peer_destroy */ 1299 peer->cfgfile = config_filename; /* Free in peer_destroy */
1254 peer->cfg = GNUNET_CONFIGURATION_dup (cfg); 1300 peer->cfg = GNUNET_CONFIGURATION_dup (cfg);
1255 libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); 1301 libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
1256 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "arm", "PREFIX", &peer->main_binary)) 1302 if (GNUNET_SYSERR ==
1303 GNUNET_CONFIGURATION_get_value_string (cfg,
1304 "arm",
1305 "PREFIX",
1306 &peer->main_binary))
1257 { 1307 {
1258 /* No prefix */ 1308 /* No prefix */
1259 GNUNET_asprintf(&peer->main_binary, "%s", libexec_binary); 1309 GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary);
1260 peer->args = GNUNET_strdup (""); 1310 peer->args = GNUNET_strdup ("");
1261 } 1311 }
1262 else 1312 else
@@ -1266,11 +1316,11 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1266 peer->system = system; 1316 peer->system = system;
1267 peer->key_number = key_number; 1317 peer->key_number = key_number;
1268 GNUNET_free (libexec_binary); 1318 GNUNET_free (libexec_binary);
1269 peer->ports = ports; /* Free in peer_destroy */ 1319 peer->ports = ports; /* Free in peer_destroy */
1270 peer->nports = nports; 1320 peer->nports = nports;
1271 return peer; 1321 return peer;
1272 1322
1273 err_ret: 1323err_ret:
1274 GNUNET_free_non_null (ss_instances); 1324 GNUNET_free_non_null (ss_instances);
1275 GNUNET_free_non_null (ports); 1325 GNUNET_free_non_null (ports);
1276 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_); 1326 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_);
@@ -1290,7 +1340,7 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1290 */ 1340 */
1291void 1341void
1292GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer, 1342GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer,
1293 struct GNUNET_PeerIdentity *id) 1343 struct GNUNET_PeerIdentity *id)
1294{ 1344{
1295 if (NULL != peer->id) 1345 if (NULL != peer->id)
1296 { 1346 {
@@ -1298,9 +1348,8 @@ GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer,
1298 return; 1348 return;
1299 } 1349 }
1300 peer->id = GNUNET_new (struct GNUNET_PeerIdentity); 1350 peer->id = GNUNET_new (struct GNUNET_PeerIdentity);
1301 GNUNET_free (GNUNET_TESTING_hostkey_get (peer->system, 1351 GNUNET_free (
1302 peer->key_number, 1352 GNUNET_TESTING_hostkey_get (peer->system, peer->key_number, peer->id));
1303 peer->id));
1304 GNUNET_memcpy (id, peer->id, sizeof (struct GNUNET_PeerIdentity)); 1353 GNUNET_memcpy (id, peer->id, sizeof (struct GNUNET_PeerIdentity));
1305} 1354}
1306 1355
@@ -1326,26 +1375,28 @@ GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer)
1326 for (cnt = 0; cnt < peer->system->n_shared_services; cnt++) 1375 for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1327 { 1376 {
1328 i = peer->ss_instances[cnt]; 1377 i = peer->ss_instances[cnt];
1329 if ((0 == i->n_refs) 1378 if ((0 == i->n_refs) &&
1330 && (GNUNET_SYSERR == start_shared_service_instance (i)) ) 1379 (GNUNET_SYSERR == start_shared_service_instance (i)))
1331 return GNUNET_SYSERR; 1380 return GNUNET_SYSERR;
1332 i->n_refs++; 1381 i->n_refs++;
1333 } 1382 }
1334 peer->main_binary = GNUNET_CONFIGURATION_expand_dollar (peer->cfg, peer->main_binary); 1383 peer->main_binary =
1335 peer->main_process = GNUNET_OS_start_process_s (PIPE_CONTROL, 1384 GNUNET_CONFIGURATION_expand_dollar (peer->cfg, peer->main_binary);
1336 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 1385 peer->main_process =
1337 NULL, 1386 GNUNET_OS_start_process_s (PIPE_CONTROL,
1338 peer->main_binary, 1387 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
1339 peer->args, 1388 NULL,
1340 "-c", 1389 peer->main_binary,
1341 peer->cfgfile, 1390 peer->args,
1342 NULL); 1391 "-c",
1392 peer->cfgfile,
1393 NULL);
1343 if (NULL == peer->main_process) 1394 if (NULL == peer->main_process)
1344 { 1395 {
1345 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1396 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1346 _("Failed to start `%s': %s\n"), 1397 _ ("Failed to start `%s': %s\n"),
1347 peer->main_binary, 1398 peer->main_binary,
1348 STRERROR (errno)); 1399 strerror (errno));
1349 return GNUNET_SYSERR; 1400 return GNUNET_SYSERR;
1350 } 1401 }
1351 return GNUNET_OK; 1402 return GNUNET_OK;
@@ -1433,8 +1484,7 @@ GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer)
1433 * #GNUNET_SYSERR on error. 1484 * #GNUNET_SYSERR on error.
1434 */ 1485 */
1435static void 1486static void
1436disconn_status (void *cls, 1487disconn_status (void *cls, int connected)
1437 int connected)
1438{ 1488{
1439 struct GNUNET_TESTING_Peer *peer = cls; 1489 struct GNUNET_TESTING_Peer *peer = cls;
1440 1490
@@ -1551,12 +1601,11 @@ GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer)
1551 */ 1601 */
1552int 1602int
1553GNUNET_TESTING_peer_run (const char *testdir, 1603GNUNET_TESTING_peer_run (const char *testdir,
1554 const char *cfgfilename, 1604 const char *cfgfilename,
1555 GNUNET_TESTING_TestMain tm, 1605 GNUNET_TESTING_TestMain tm,
1556 void *tm_cls) 1606 void *tm_cls)
1557{ 1607{
1558 return GNUNET_TESTING_service_run (testdir, "arm", 1608 return GNUNET_TESTING_service_run (testdir, "arm", cfgfilename, tm, tm_cls);
1559 cfgfilename, tm, tm_cls);
1560} 1609}
1561 1610
1562 1611
@@ -1624,10 +1673,10 @@ service_run_main (void *cls)
1624 */ 1673 */
1625int 1674int
1626GNUNET_TESTING_service_run (const char *testdir, 1675GNUNET_TESTING_service_run (const char *testdir,
1627 const char *service_name, 1676 const char *service_name,
1628 const char *cfgfilename, 1677 const char *cfgfilename,
1629 GNUNET_TESTING_TestMain tm, 1678 GNUNET_TESTING_TestMain tm,
1630 void *tm_cls) 1679 void *tm_cls)
1631{ 1680{
1632 struct ServiceContext sc; 1681 struct ServiceContext sc;
1633 struct GNUNET_TESTING_System *system; 1682 struct GNUNET_TESTING_System *system;
@@ -1636,9 +1685,7 @@ GNUNET_TESTING_service_run (const char *testdir,
1636 char *binary; 1685 char *binary;
1637 char *libexec_binary; 1686 char *libexec_binary;
1638 1687
1639 GNUNET_log_setup (testdir, 1688 GNUNET_log_setup (testdir, "WARNING", NULL);
1640 "WARNING",
1641 NULL);
1642 system = GNUNET_TESTING_system_create (testdir, "127.0.0.1", NULL, NULL); 1689 system = GNUNET_TESTING_system_create (testdir, "127.0.0.1", NULL, NULL);
1643 if (NULL == system) 1690 if (NULL == system)
1644 return 1; 1691 return 1;
@@ -1646,7 +1693,8 @@ GNUNET_TESTING_service_run (const char *testdir,
1646 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgfilename)) 1693 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgfilename))
1647 { 1694 {
1648 LOG (GNUNET_ERROR_TYPE_ERROR, 1695 LOG (GNUNET_ERROR_TYPE_ERROR,
1649 _("Failed to load configuration from %s\n"), cfgfilename); 1696 _ ("Failed to load configuration from %s\n"),
1697 cfgfilename);
1650 GNUNET_CONFIGURATION_destroy (cfg); 1698 GNUNET_CONFIGURATION_destroy (cfg);
1651 GNUNET_TESTING_system_destroy (system, GNUNET_YES); 1699 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
1652 return 1; 1700 return 1;
@@ -1663,10 +1711,14 @@ GNUNET_TESTING_service_run (const char *testdir,
1663 GNUNET_free (peer->args); 1711 GNUNET_free (peer->args);
1664 GNUNET_asprintf (&binary, "gnunet-service-%s", service_name); 1712 GNUNET_asprintf (&binary, "gnunet-service-%s", service_name);
1665 libexec_binary = GNUNET_OS_get_libexec_binary_path (binary); 1713 libexec_binary = GNUNET_OS_get_libexec_binary_path (binary);
1666 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, service_name, "PREFIX", &peer->main_binary)) 1714 if (GNUNET_SYSERR ==
1715 GNUNET_CONFIGURATION_get_value_string (cfg,
1716 service_name,
1717 "PREFIX",
1718 &peer->main_binary))
1667 { 1719 {
1668 /* No prefix */ 1720 /* No prefix */
1669 GNUNET_asprintf(&peer->main_binary, "%s", libexec_binary); 1721 GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary);
1670 peer->args = GNUNET_strdup (""); 1722 peer->args = GNUNET_strdup ("");
1671 } 1723 }
1672 else 1724 else