aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/testing
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/gnunet-testing.c426
-rw-r--r--src/testing/list-keys.c110
-rw-r--r--src/testing/test_testing_peerstartup.c67
-rw-r--r--src/testing/test_testing_peerstartup2.c138
-rw-r--r--src/testing/test_testing_portreservation.c62
-rw-r--r--src/testing/test_testing_servicestartup.c27
-rw-r--r--src/testing/test_testing_sharedservices.c89
-rw-r--r--src/testing/testing.c1462
8 files changed, 1195 insertions, 1186 deletions
diff --git a/src/testing/gnunet-testing.c b/src/testing/gnunet-testing.c
index 834cf6cea..a13a32f77 100644
--- a/src/testing/gnunet-testing.c
+++ b/src/testing/gnunet-testing.c
@@ -28,7 +28,7 @@
28#include "gnunet_testing_lib.h" 28#include "gnunet_testing_lib.h"
29 29
30 30
31#define LOG(kind, ...) GNUNET_log_from(kind, "gnunet-testing", __VA_ARGS__) 31#define LOG(kind, ...) GNUNET_log_from (kind, "gnunet-testing", __VA_ARGS__)
32 32
33 33
34/** 34/**
@@ -84,7 +84,7 @@ static struct GNUNET_TESTING_Peer *my_peer;
84 84
85 85
86static int 86static int
87create_unique_cfgs(const char *template, const unsigned int no) 87create_unique_cfgs (const char *template, const unsigned int no)
88{ 88{
89 struct GNUNET_TESTING_System *system; 89 struct GNUNET_TESTING_System *system;
90 int fail; 90 int fail;
@@ -93,76 +93,76 @@ create_unique_cfgs(const char *template, const unsigned int no)
93 struct GNUNET_CONFIGURATION_Handle *cfg_new; 93 struct GNUNET_CONFIGURATION_Handle *cfg_new;
94 struct GNUNET_CONFIGURATION_Handle *cfg_tmpl; 94 struct GNUNET_CONFIGURATION_Handle *cfg_tmpl;
95 95
96 if (GNUNET_NO == GNUNET_DISK_file_test(template)) 96 if (GNUNET_NO == GNUNET_DISK_file_test (template))
97 { 97 {
98 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 98 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
99 "Configuration template `%s': file not found\n", 99 "Configuration template `%s': file not found\n",
100 create_cfg_template); 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) && 106 if ((create_cfg_template != NULL) &&
107 (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg_tmpl, create_cfg_template))) 107 (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg_tmpl, create_cfg_template)))
108 { 108 {
109 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 109 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
110 "Could not load template `%s'\n", 110 "Could not load template `%s'\n",
111 create_cfg_template); 111 create_cfg_template);
112 GNUNET_CONFIGURATION_destroy(cfg_tmpl); 112 GNUNET_CONFIGURATION_destroy (cfg_tmpl);
113 113
114 return 1; 114 return 1;
115 } 115 }
116 /* load defaults */ 116 /* load defaults */
117 if (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg_tmpl, NULL)) 117 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg_tmpl, NULL))
118 { 118 {
119 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 119 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
120 "Could not load template `%s'\n", 120 "Could not load template `%s'\n",
121 create_cfg_template); 121 create_cfg_template);
122 GNUNET_CONFIGURATION_destroy(cfg_tmpl); 122 GNUNET_CONFIGURATION_destroy (cfg_tmpl);
123 return 1; 123 return 1;
124 } 124 }
125 125
126 fail = GNUNET_NO; 126 fail = GNUNET_NO;
127 system = 127 system =
128 GNUNET_TESTING_system_create("testing", NULL /* controller */, NULL, NULL); 128 GNUNET_TESTING_system_create ("testing", NULL /* controller */, NULL, NULL);
129 for (cur = 0; cur < no; cur++) 129 for (cur = 0; cur < no; cur++)
130 {
131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
132 "Creating configuration no. %u \n",
133 cur);
134 if (create_cfg_template != NULL)
135 GNUNET_asprintf (&cur_file, "%04u-%s", cur, create_cfg_template);
136 else
137 GNUNET_asprintf (&cur_file, "%04u%s", cur, ".conf");
138
139 cfg_new = GNUNET_CONFIGURATION_dup (cfg_tmpl);
140 if (GNUNET_OK != GNUNET_TESTING_configuration_create (system, cfg_new))
130 { 141 {
131 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 142 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
132 "Creating configuration no. %u \n", 143 "Could not create another configuration\n");
133 cur); 144 GNUNET_CONFIGURATION_destroy (cfg_new);
134 if (create_cfg_template != NULL) 145 fail = GNUNET_YES;
135 GNUNET_asprintf(&cur_file, "%04u-%s", cur, create_cfg_template); 146 break;
136 else
137 GNUNET_asprintf(&cur_file, "%04u%s", cur, ".conf");
138
139 cfg_new = GNUNET_CONFIGURATION_dup(cfg_tmpl);
140 if (GNUNET_OK != GNUNET_TESTING_configuration_create(system, cfg_new))
141 {
142 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
143 "Could not create another configuration\n");
144 GNUNET_CONFIGURATION_destroy(cfg_new);
145 fail = GNUNET_YES;
146 break;
147 }
148 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
149 "Writing configuration no. %u to file `%s' \n",
150 cur,
151 cur_file);
152 if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg_new, cur_file))
153 {
154 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
155 "Failed to write configuration no. %u \n",
156 cur);
157 fail = GNUNET_YES;
158 }
159 GNUNET_CONFIGURATION_destroy(cfg_new);
160 GNUNET_free(cur_file);
161 if (GNUNET_YES == fail)
162 break;
163 } 147 }
164 GNUNET_CONFIGURATION_destroy(cfg_tmpl); 148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
165 GNUNET_TESTING_system_destroy(system, GNUNET_NO); 149 "Writing configuration no. %u to file `%s' \n",
150 cur,
151 cur_file);
152 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg_new, cur_file))
153 {
154 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
155 "Failed to write configuration no. %u \n",
156 cur);
157 fail = GNUNET_YES;
158 }
159 GNUNET_CONFIGURATION_destroy (cfg_new);
160 GNUNET_free (cur_file);
161 if (GNUNET_YES == fail)
162 break;
163 }
164 GNUNET_CONFIGURATION_destroy (cfg_tmpl);
165 GNUNET_TESTING_system_destroy (system, GNUNET_NO);
166 if (GNUNET_YES == fail) 166 if (GNUNET_YES == fail)
167 return 1; 167 return 1;
168 return 0; 168 return 0;
@@ -170,40 +170,40 @@ create_unique_cfgs(const char *template, const unsigned int no)
170 170
171 171
172static int 172static int
173create_hostkeys(const unsigned int no) 173create_hostkeys (const unsigned int no)
174{ 174{
175 struct GNUNET_TESTING_System *system; 175 struct GNUNET_TESTING_System *system;
176 struct GNUNET_PeerIdentity id; 176 struct GNUNET_PeerIdentity id;
177 struct GNUNET_DISK_FileHandle *fd; 177 struct GNUNET_DISK_FileHandle *fd;
178 struct GNUNET_CRYPTO_EddsaPrivateKey *pk; 178 struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
179 179
180 system = GNUNET_TESTING_system_create("testing", NULL, NULL, NULL); 180 system = GNUNET_TESTING_system_create ("testing", NULL, NULL, NULL);
181 pk = GNUNET_TESTING_hostkey_get(system, create_no, &id); 181 pk = GNUNET_TESTING_hostkey_get (system, create_no, &id);
182 if (NULL == pk) 182 if (NULL == pk)
183 { 183 {
184 fprintf(stderr, 184 fprintf (stderr,
185 _("Could not extract hostkey %u (offset too large?)\n"), 185 _ ("Could not extract hostkey %u (offset too large?)\n"),
186 create_no); 186 create_no);
187 GNUNET_TESTING_system_destroy(system, GNUNET_YES); 187 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
188 return 1; 188 return 1;
189 } 189 }
190 (void)GNUNET_DISK_directory_create_for_file(create_hostkey); 190 (void) GNUNET_DISK_directory_create_for_file (create_hostkey);
191 fd = 191 fd =
192 GNUNET_DISK_file_open(create_hostkey, 192 GNUNET_DISK_file_open (create_hostkey,
193 GNUNET_DISK_OPEN_READWRITE | GNUNET_DISK_OPEN_CREATE, 193 GNUNET_DISK_OPEN_READWRITE | GNUNET_DISK_OPEN_CREATE,
194 GNUNET_DISK_PERM_USER_READ | 194 GNUNET_DISK_PERM_USER_READ
195 GNUNET_DISK_PERM_USER_WRITE); 195 | GNUNET_DISK_PERM_USER_WRITE);
196 GNUNET_assert(fd != NULL); 196 GNUNET_assert (fd != NULL);
197 ret = GNUNET_DISK_file_write(fd, 197 ret = GNUNET_DISK_file_write (fd,
198 pk, 198 pk,
199 sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey)); 199 sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey));
200 GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fd)); 200 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
201 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, 201 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
202 "transport-testing", 202 "transport-testing",
203 "Wrote hostkey to file: `%s'\n", 203 "Wrote hostkey to file: `%s'\n",
204 create_hostkey); 204 create_hostkey);
205 GNUNET_free(pk); 205 GNUNET_free (pk);
206 GNUNET_TESTING_system_destroy(system, GNUNET_YES); 206 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
207 return 0; 207 return 0;
208} 208}
209 209
@@ -215,25 +215,25 @@ create_hostkeys(const unsigned int no)
215 * @param cls unused 215 * @param cls unused
216 */ 216 */
217static void 217static void
218cleanup(void *cls) 218cleanup (void *cls)
219{ 219{
220 if (NULL != tmpfilename) 220 if (NULL != tmpfilename)
221 { 221 {
222 if (0 != unlink(tmpfilename)) 222 if (0 != unlink (tmpfilename))
223 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, 223 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
224 "unlink", 224 "unlink",
225 tmpfilename); 225 tmpfilename);
226 } 226 }
227 if (NULL != tid) 227 if (NULL != tid)
228 { 228 {
229 GNUNET_SCHEDULER_cancel(tid); 229 GNUNET_SCHEDULER_cancel (tid);
230 tid = NULL; 230 tid = NULL;
231 } 231 }
232 if (NULL != fh) 232 if (NULL != fh)
233 { 233 {
234 GNUNET_DISK_file_close(fh); 234 GNUNET_DISK_file_close (fh);
235 fh = NULL; 235 fh = NULL;
236 } 236 }
237} 237}
238 238
239 239
@@ -243,42 +243,42 @@ cleanup(void *cls)
243 * @param cls unused 243 * @param cls unused
244 */ 244 */
245static void 245static void
246stdin_cb(void *cls) 246stdin_cb (void *cls)
247{ 247{
248 int c; 248 int c;
249 249
250 tid = NULL; 250 tid = NULL;
251 c = getchar(); 251 c = getchar ();
252 switch (c) 252 switch (c)
253 { 253 {
254 case EOF: 254 case EOF:
255 case 'q': 255 case 'q':
256 GNUNET_SCHEDULER_shutdown(); 256 GNUNET_SCHEDULER_shutdown ();
257 return; 257 return;
258 258
259 case 'r': 259 case 'r':
260 if (GNUNET_OK != GNUNET_TESTING_peer_stop(my_peer)) 260 if (GNUNET_OK != GNUNET_TESTING_peer_stop (my_peer))
261 LOG(GNUNET_ERROR_TYPE_ERROR, "Failed to stop the peer\n"); 261 LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to stop the peer\n");
262 if (GNUNET_OK != GNUNET_TESTING_peer_start(my_peer)) 262 if (GNUNET_OK != GNUNET_TESTING_peer_start (my_peer))
263 LOG(GNUNET_ERROR_TYPE_ERROR, "Failed to start the peer\n"); 263 LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to start the peer\n");
264 printf("restarted\n"); 264 printf ("restarted\n");
265 fflush(stdout); 265 fflush (stdout);
266 break; 266 break;
267 267
268 case '\n': 268 case '\n':
269 case '\r': 269 case '\r':
270 /* ignore whitespace */ 270 /* ignore whitespace */
271 break; 271 break;
272 272
273 default: 273 default:
274 fprintf(stderr, 274 fprintf (stderr,
275 _("Unknown command, use 'q' to quit or 'r' to restart peer\n")); 275 _ ("Unknown command, use 'q' to quit or 'r' to restart peer\n"));
276 break; 276 break;
277 } 277 }
278 tid = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, 278 tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
279 fh, 279 fh,
280 &stdin_cb, 280 &stdin_cb,
281 NULL); 281 NULL);
282} 282}
283 283
284 284
@@ -291,32 +291,32 @@ stdin_cb(void *cls)
291 * @param peer handle to the peer 291 * @param peer handle to the peer
292 */ 292 */
293static void 293static void
294testing_main(void *cls, 294testing_main (void *cls,
295 const struct GNUNET_CONFIGURATION_Handle *cfg, 295 const struct GNUNET_CONFIGURATION_Handle *cfg,
296 struct GNUNET_TESTING_Peer *peer) 296 struct GNUNET_TESTING_Peer *peer)
297{ 297{
298 my_peer = peer; 298 my_peer = peer;
299 if (NULL == (tmpfilename = GNUNET_DISK_mktemp("gnunet-testing"))) 299 if (NULL == (tmpfilename = GNUNET_DISK_mktemp ("gnunet-testing")))
300 { 300 {
301 GNUNET_break(0); 301 GNUNET_break (0);
302 GNUNET_SCHEDULER_shutdown(); 302 GNUNET_SCHEDULER_shutdown ();
303 return; 303 return;
304 } 304 }
305 if (GNUNET_SYSERR == 305 if (GNUNET_SYSERR ==
306 GNUNET_CONFIGURATION_write((struct GNUNET_CONFIGURATION_Handle *)cfg, 306 GNUNET_CONFIGURATION_write ((struct GNUNET_CONFIGURATION_Handle *) cfg,
307 tmpfilename)) 307 tmpfilename))
308 { 308 {
309 GNUNET_break(0); 309 GNUNET_break (0);
310 return; 310 return;
311 } 311 }
312 printf("ok\n%s\n", tmpfilename); 312 printf ("ok\n%s\n", tmpfilename);
313 fflush(stdout); 313 fflush (stdout);
314 GNUNET_SCHEDULER_add_shutdown(&cleanup, NULL); 314 GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL);
315 fh = GNUNET_DISK_get_handle_from_native(stdin); 315 fh = GNUNET_DISK_get_handle_from_native (stdin);
316 tid = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, 316 tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
317 fh, 317 fh,
318 &stdin_cb, 318 &stdin_cb,
319 NULL); 319 NULL);
320} 320}
321 321
322 322
@@ -329,43 +329,43 @@ testing_main(void *cls,
329 * @param cfg configuration 329 * @param cfg configuration
330 */ 330 */
331static void 331static void
332run_no_scheduler(void *cls, 332run_no_scheduler (void *cls,
333 char *const *args, 333 char *const *args,
334 const char *cfgfile, 334 const char *cfgfile,
335 const struct GNUNET_CONFIGURATION_Handle *cfg) 335 const struct GNUNET_CONFIGURATION_Handle *cfg)
336{ 336{
337 if (NULL != run_service_name) 337 if (NULL != run_service_name)
338 { 338 {
339 ret = GNUNET_TESTING_service_run("gnunet_service_test", 339 ret = GNUNET_TESTING_service_run ("gnunet_service_test",
340 run_service_name, 340 run_service_name,
341 cfgfile, 341 cfgfile,
342 &testing_main, 342 &testing_main,
343 NULL); 343 NULL);
344 return; 344 return;
345 } 345 }
346 346
347 if (GNUNET_YES == create_cfg) 347 if (GNUNET_YES == create_cfg)
348 {
349 if (create_no > 0)
348 { 350 {
349 if (create_no > 0) 351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
350 { 352 "Creating %u configuration files based on template `%s'\n",
351 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 353 create_no,
352 "Creating %u configuration files based on template `%s'\n", 354 create_cfg_template);
353 create_no, 355 ret = create_unique_cfgs (create_cfg_template, create_no);
354 create_cfg_template);
355 ret = create_unique_cfgs(create_cfg_template, create_no);
356 }
357 else
358 {
359 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Missing arguments! \n");
360 ret = 1;
361 }
362 } 356 }
363 if (NULL != create_hostkey) 357 else
364 { 358 {
365 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Extracting hostkey %u\n", create_no); 359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Missing arguments! \n");
366 ret = create_hostkeys(create_no); 360 ret = 1;
367 } 361 }
368 GNUNET_free_non_null(create_cfg_template); 362 }
363 if (NULL != create_hostkey)
364 {
365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Extracting hostkey %u\n", create_no);
366 ret = create_hostkeys (create_no);
367 }
368 GNUNET_free_non_null (create_cfg_template);
369} 369}
370 370
371 371
@@ -377,46 +377,46 @@ run_no_scheduler(void *cls,
377 * @return 0 ok, 1 on error 377 * @return 0 ok, 1 on error
378 */ 378 */
379int 379int
380main(int argc, char *const *argv) 380main (int argc, char *const *argv)
381{ 381{
382 struct GNUNET_GETOPT_CommandLineOption options[] = 382 struct GNUNET_GETOPT_CommandLineOption options[] =
383 { GNUNET_GETOPT_option_flag('C', 383 { GNUNET_GETOPT_option_flag ('C',
384 "cfg", 384 "cfg",
385 gettext_noop( 385 gettext_noop (
386 "create unique configuration files"), 386 "create unique configuration files"),
387 &create_cfg), 387 &create_cfg),
388 GNUNET_GETOPT_option_string( 388 GNUNET_GETOPT_option_string (
389 'k', 389 'k',
390 "key", 390 "key",
391 "FILENAME", 391 "FILENAME",
392 gettext_noop("extract hostkey file from pre-computed hostkey list"), 392 gettext_noop ("extract hostkey file from pre-computed hostkey list"),
393 &create_hostkey), 393 &create_hostkey),
394 394
395 GNUNET_GETOPT_option_uint( 395 GNUNET_GETOPT_option_uint (
396 'n', 396 'n',
397 "number", 397 "number",
398 "NUMBER", 398 "NUMBER",
399 gettext_noop( 399 gettext_noop (
400 "number of unique configuration files to create, or number of the hostkey to extract"), 400 "number of unique configuration files to create, or number of the hostkey to extract"),
401 &create_no), 401 &create_no),
402 402
403 403
404 GNUNET_GETOPT_option_string('t', 404 GNUNET_GETOPT_option_string ('t',
405 "template", 405 "template",
406 "FILENAME", 406 "FILENAME",
407 gettext_noop("configuration template"), 407 gettext_noop ("configuration template"),
408 &create_cfg_template), 408 &create_cfg_template),
409 409
410 GNUNET_GETOPT_option_string( 410 GNUNET_GETOPT_option_string (
411 'r', 411 'r',
412 "run", 412 "run",
413 "SERVICE", 413 "SERVICE",
414 gettext_noop( 414 gettext_noop (
415 "run the given service, wait on stdin for 'r' (restart) or 'q' (quit)"), 415 "run the given service, wait on stdin for 'r' (restart) or 'q' (quit)"),
416 &run_service_name), 416 &run_service_name),
417 GNUNET_GETOPT_OPTION_END }; 417 GNUNET_GETOPT_OPTION_END };
418 418
419 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 419 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
420 return 2; 420 return 2;
421 421
422 /* Run without scheduler, because we may want to call 422 /* Run without scheduler, because we may want to call
@@ -425,18 +425,18 @@ main(int argc, char *const *argv)
425 * but beware when extending gnunet-testing. */ 425 * but beware when extending gnunet-testing. */
426 ret = 426 ret =
427 (GNUNET_OK == 427 (GNUNET_OK ==
428 GNUNET_PROGRAM_run2(argc, 428 GNUNET_PROGRAM_run2 (argc,
429 argv, 429 argv,
430 "gnunet-testing", 430 "gnunet-testing",
431 gettext_noop( 431 gettext_noop (
432 "Command line tool to access the testing library"), 432 "Command line tool to access the testing library"),
433 options, 433 options,
434 &run_no_scheduler, 434 &run_no_scheduler,
435 NULL, 435 NULL,
436 GNUNET_YES)) 436 GNUNET_YES))
437 ? ret 437 ? ret
438 : 1; 438 : 1;
439 GNUNET_free((void *)argv); 439 GNUNET_free ((void *) argv);
440 return ret; 440 return ret;
441} 441}
442 442
diff --git a/src/testing/list-keys.c b/src/testing/list-keys.c
index 37b880b49..f65b45a77 100644
--- a/src/testing/list-keys.c
+++ b/src/testing/list-keys.c
@@ -15,10 +15,10 @@ 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, 18run (void *cls,
19 char *const *args, 19 char *const *args,
20 const char *cfgfile, 20 const char *cfgfile,
21 const struct GNUNET_CONFIGURATION_Handle *config) 21 const struct GNUNET_CONFIGURATION_Handle *config)
22{ 22{
23 char *idfile; 23 char *idfile;
24 struct GNUNET_DISK_FileHandle *f; 24 struct GNUNET_DISK_FileHandle *f;
@@ -31,79 +31,79 @@ run(void *cls,
31 unsigned int nmax; 31 unsigned int nmax;
32 32
33 if ((NULL == args) || (NULL == args[0])) 33 if ((NULL == args) || (NULL == args[0]))
34 { 34 {
35 fprintf(stderr, "Need the hostkey file\n"); 35 fprintf (stderr, "Need the hostkey file\n");
36 return; 36 return;
37 } 37 }
38 idfile = args[0]; 38 idfile = args[0];
39 if (GNUNET_OK != 39 if (GNUNET_OK !=
40 GNUNET_DISK_file_size(idfile, &fsize, GNUNET_YES, GNUNET_YES)) 40 GNUNET_DISK_file_size (idfile, &fsize, GNUNET_YES, GNUNET_YES))
41 { 41 {
42 GNUNET_break(0); 42 GNUNET_break (0);
43 return; 43 return;
44 } 44 }
45 if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE)) 45 if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE))
46 { 46 {
47 fprintf(stderr, _("Incorrect hostkey file format: %s\n"), idfile); 47 fprintf (stderr, _ ("Incorrect hostkey file format: %s\n"), idfile);
48 return; 48 return;
49 } 49 }
50 f = GNUNET_DISK_file_open(idfile, 50 f = GNUNET_DISK_file_open (idfile,
51 GNUNET_DISK_OPEN_READ, 51 GNUNET_DISK_OPEN_READ,
52 GNUNET_DISK_PERM_NONE); 52 GNUNET_DISK_PERM_NONE);
53 if (NULL == f) 53 if (NULL == f)
54 { 54 {
55 GNUNET_break(0); 55 GNUNET_break (0);
56 return; 56 return;
57 } 57 }
58 data = GNUNET_DISK_file_map(f, &map, GNUNET_DISK_MAP_TYPE_READ, fsize); 58 data = GNUNET_DISK_file_map (f, &map, GNUNET_DISK_MAP_TYPE_READ, fsize);
59 if (NULL == data) 59 if (NULL == data)
60 { 60 {
61 GNUNET_break(0); 61 GNUNET_break (0);
62 GNUNET_DISK_file_close(f); 62 GNUNET_DISK_file_close (f);
63 return; 63 return;
64 } 64 }
65 nmax = fsize / GNUNET_TESTING_HOSTKEYFILESIZE; 65 nmax = fsize / GNUNET_TESTING_HOSTKEYFILESIZE;
66 for (cnt = nskip; cnt < (nskip + nkeys); cnt++) 66 for (cnt = nskip; cnt < (nskip + nkeys); cnt++)
67 {
68 if (nskip + cnt >= nmax)
67 { 69 {
68 if (nskip + cnt >= nmax) 70 printf ("Max keys %u reached\n", nmax);
69 { 71 break;
70 printf("Max keys %u reached\n", nmax);
71 break;
72 }
73 GNUNET_memcpy(&pkey,
74 data + (cnt * GNUNET_TESTING_HOSTKEYFILESIZE),
75 GNUNET_TESTING_HOSTKEYFILESIZE);
76 GNUNET_CRYPTO_eddsa_key_get_public(&pkey, &id.public_key);
77 printf("Key %u: %s\n", cnt, GNUNET_i2s_full(&id));
78 } 72 }
73 GNUNET_memcpy (&pkey,
74 data + (cnt * GNUNET_TESTING_HOSTKEYFILESIZE),
75 GNUNET_TESTING_HOSTKEYFILESIZE);
76 GNUNET_CRYPTO_eddsa_key_get_public (&pkey, &id.public_key);
77 printf ("Key %u: %s\n", cnt, GNUNET_i2s_full (&id));
78 }
79 result = GNUNET_OK; 79 result = GNUNET_OK;
80 GNUNET_DISK_file_unmap(map); 80 GNUNET_DISK_file_unmap (map);
81 GNUNET_DISK_file_close(f); 81 GNUNET_DISK_file_close (f);
82} 82}
83 83
84 84
85int 85int
86main(int argc, char *argv[]) 86main (int argc, char *argv[])
87{ 87{
88 struct GNUNET_GETOPT_CommandLineOption option[] = 88 struct GNUNET_GETOPT_CommandLineOption option[] =
89 { GNUNET_GETOPT_option_uint('n', 89 { GNUNET_GETOPT_option_uint ('n',
90 "num-keys", 90 "num-keys",
91 "COUNT", 91 "COUNT",
92 gettext_noop("list COUNT number of keys"), 92 gettext_noop ("list COUNT number of keys"),
93 &nkeys), 93 &nkeys),
94 GNUNET_GETOPT_OPTION_END }; 94 GNUNET_GETOPT_OPTION_END };
95 int ret; 95 int ret;
96 96
97 result = GNUNET_SYSERR; 97 result = GNUNET_SYSERR;
98 nkeys = 10; 98 nkeys = 10;
99 ret = 99 ret =
100 GNUNET_PROGRAM_run(argc, 100 GNUNET_PROGRAM_run (argc,
101 argv, 101 argv,
102 "list-keys", 102 "list-keys",
103 "Lists the peer IDs corresponding to the given keys file\n", 103 "Lists the peer IDs corresponding to the given keys file\n",
104 option, 104 option,
105 &run, 105 &run,
106 NULL); 106 NULL);
107 if (GNUNET_OK != ret) 107 if (GNUNET_OK != ret)
108 return 1; 108 return 1;
109 if (GNUNET_SYSERR == result) 109 if (GNUNET_SYSERR == result)
diff --git a/src/testing/test_testing_peerstartup.c b/src/testing/test_testing_peerstartup.c
index a03e6b596..cfc79e618 100644
--- a/src/testing/test_testing_peerstartup.c
+++ b/src/testing/test_testing_peerstartup.c
@@ -30,7 +30,7 @@
30#include "gnunet_testing_lib.h" 30#include "gnunet_testing_lib.h"
31 31
32#define LOG(kind, ...) \ 32#define LOG(kind, ...) \
33 GNUNET_log(kind, __VA_ARGS__) 33 GNUNET_log (kind, __VA_ARGS__)
34 34
35/** 35/**
36 * The status of the test 36 * The status of the test
@@ -40,7 +40,8 @@ int status;
40/** 40/**
41 * The testing context 41 * The testing context
42 */ 42 */
43struct TestingContext { 43struct TestingContext
44{
44 /** 45 /**
45 * The testing system 46 * The testing system
46 */ 47 */
@@ -64,21 +65,21 @@ struct TestingContext {
64 * @param cls the testing context 65 * @param cls the testing context
65 */ 66 */
66static void 67static void
67do_shutdown(void *cls) 68do_shutdown (void *cls)
68{ 69{
69 struct TestingContext *test_ctx = cls; 70 struct TestingContext *test_ctx = cls;
70 71
71 GNUNET_assert(NULL != test_ctx); 72 GNUNET_assert (NULL != test_ctx);
72 if (NULL != test_ctx->peer) 73 if (NULL != test_ctx->peer)
73 { 74 {
74 (void)GNUNET_TESTING_peer_stop(test_ctx->peer); 75 (void) GNUNET_TESTING_peer_stop (test_ctx->peer);
75 GNUNET_TESTING_peer_destroy(test_ctx->peer); 76 GNUNET_TESTING_peer_destroy (test_ctx->peer);
76 } 77 }
77 if (NULL != test_ctx->cfg) 78 if (NULL != test_ctx->cfg)
78 GNUNET_CONFIGURATION_destroy(test_ctx->cfg); 79 GNUNET_CONFIGURATION_destroy (test_ctx->cfg);
79 if (NULL != test_ctx->system) 80 if (NULL != test_ctx->system)
80 GNUNET_TESTING_system_destroy(test_ctx->system, GNUNET_YES); 81 GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES);
81 GNUNET_free(test_ctx); 82 GNUNET_free (test_ctx);
82} 83}
83 84
84 85
@@ -86,42 +87,42 @@ do_shutdown(void *cls)
86 * Main point of test execution 87 * Main point of test execution
87 */ 88 */
88static void 89static void
89run(void *cls, char *const *args, const char *cfgfile, 90run (void *cls, char *const *args, const char *cfgfile,
90 const struct GNUNET_CONFIGURATION_Handle *cfg) 91 const struct GNUNET_CONFIGURATION_Handle *cfg)
91{ 92{
92 struct TestingContext *test_ctx; 93 struct TestingContext *test_ctx;
93 char *emsg; 94 char *emsg;
94 struct GNUNET_PeerIdentity id; 95 struct GNUNET_PeerIdentity id;
95 96
96 test_ctx = GNUNET_new(struct TestingContext); 97 test_ctx = GNUNET_new (struct TestingContext);
97 test_ctx->system = 98 test_ctx->system =
98 GNUNET_TESTING_system_create("test-gnunet-testing", 99 GNUNET_TESTING_system_create ("test-gnunet-testing",
99 "127.0.0.1", NULL, NULL); 100 "127.0.0.1", NULL, NULL);
100 emsg = NULL; 101 emsg = NULL;
101 if (NULL == test_ctx->system) 102 if (NULL == test_ctx->system)
102 goto end; 103 goto end;
103 test_ctx->cfg = GNUNET_CONFIGURATION_dup(cfg); 104 test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg);
104 test_ctx->peer = 105 test_ctx->peer =
105 GNUNET_TESTING_peer_configure(test_ctx->system, 106 GNUNET_TESTING_peer_configure (test_ctx->system,
106 test_ctx->cfg, 107 test_ctx->cfg,
107 0, &id, &emsg); 108 0, &id, &emsg);
108 if (NULL == test_ctx->peer) 109 if (NULL == test_ctx->peer)
109 { 110 {
110 if (NULL != emsg) 111 if (NULL != emsg)
111 printf("Test failed upon error: %s", emsg); 112 printf ("Test failed upon error: %s", emsg);
112 goto end; 113 goto end;
113 } 114 }
114 if (GNUNET_OK != GNUNET_TESTING_peer_start(test_ctx->peer)) 115 if (GNUNET_OK != GNUNET_TESTING_peer_start (test_ctx->peer))
115 goto end; 116 goto end;
116 status = GNUNET_OK; 117 status = GNUNET_OK;
117 118
118end: 119end:
119 GNUNET_SCHEDULER_add_now(&do_shutdown, test_ctx); 120 GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx);
120 GNUNET_free_non_null(emsg); 121 GNUNET_free_non_null (emsg);
121} 122}
122 123
123 124
124int main(int argc, char *argv[]) 125int main (int argc, char *argv[])
125{ 126{
126 struct GNUNET_GETOPT_CommandLineOption options[] = { 127 struct GNUNET_GETOPT_CommandLineOption options[] = {
127 GNUNET_GETOPT_OPTION_END 128 GNUNET_GETOPT_OPTION_END
@@ -129,10 +130,10 @@ int main(int argc, char *argv[])
129 130
130 status = GNUNET_SYSERR; 131 status = GNUNET_SYSERR;
131 if (GNUNET_OK != 132 if (GNUNET_OK !=
132 GNUNET_PROGRAM_run(argc, argv, 133 GNUNET_PROGRAM_run (argc, argv,
133 "test_testing_peerstartup", 134 "test_testing_peerstartup",
134 "test case for peerstartup using new testing library", 135 "test case for peerstartup using new testing library",
135 options, &run, NULL)) 136 options, &run, NULL))
136 return 1; 137 return 1;
137 return (GNUNET_OK == status) ? 0 : 1; 138 return (GNUNET_OK == status) ? 0 : 1;
138} 139}
diff --git a/src/testing/test_testing_peerstartup2.c b/src/testing/test_testing_peerstartup2.c
index 80a3b719a..316a55951 100644
--- a/src/testing/test_testing_peerstartup2.c
+++ b/src/testing/test_testing_peerstartup2.c
@@ -30,18 +30,18 @@
30#include "gnunet_testing_lib.h" 30#include "gnunet_testing_lib.h"
31 31
32#define LOG(kind, ...) \ 32#define LOG(kind, ...) \
33 GNUNET_log(kind, __VA_ARGS__) 33 GNUNET_log (kind, __VA_ARGS__)
34 34
35 35
36#define FAIL_TEST(cond) \ 36#define FAIL_TEST(cond) \
37 do { \ 37 do { \
38 if (!(cond)) { \ 38 if (! (cond)) { \
39 GNUNET_break(0); \ 39 GNUNET_break (0); \
40 if (GNUNET_OK == status) { \ 40 if (GNUNET_OK == status) { \
41 status = GNUNET_SYSERR; \ 41 status = GNUNET_SYSERR; \
42 } \ 42 } \
43 } \ 43 } \
44 } while (0) \ 44 } while (0) \
45 45
46 46
47/** 47/**
@@ -52,7 +52,8 @@ int status;
52/** 52/**
53 * The testing context 53 * The testing context
54 */ 54 */
55struct TestingContext { 55struct TestingContext
56{
56 /** 57 /**
57 * The testing system 58 * The testing system
58 */ 59 */
@@ -71,7 +72,8 @@ struct TestingContext {
71 /** 72 /**
72 * State 73 * State
73 */ 74 */
74 enum { 75 enum
76 {
75 PEER_INIT, 77 PEER_INIT,
76 78
77 PEER_STARTED, 79 PEER_STARTED,
@@ -82,17 +84,17 @@ struct TestingContext {
82 84
83 85
84static void 86static void
85do_shutdown2(void *cls) 87do_shutdown2 (void *cls)
86{ 88{
87 struct TestingContext *test_ctx = cls; 89 struct TestingContext *test_ctx = cls;
88 90
89 if (NULL != test_ctx->peer) 91 if (NULL != test_ctx->peer)
90 GNUNET_TESTING_peer_destroy(test_ctx->peer); 92 GNUNET_TESTING_peer_destroy (test_ctx->peer);
91 if (NULL != test_ctx->cfg) 93 if (NULL != test_ctx->cfg)
92 GNUNET_CONFIGURATION_destroy(test_ctx->cfg); 94 GNUNET_CONFIGURATION_destroy (test_ctx->cfg);
93 if (NULL != test_ctx->system) 95 if (NULL != test_ctx->system)
94 GNUNET_TESTING_system_destroy(test_ctx->system, GNUNET_YES); 96 GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES);
95 GNUNET_free(test_ctx); 97 GNUNET_free (test_ctx);
96} 98}
97 99
98 100
@@ -102,29 +104,29 @@ do_shutdown2(void *cls)
102 * @param cls the testing context 104 * @param cls the testing context
103 */ 105 */
104static void 106static void
105do_shutdown(void *cls); 107do_shutdown (void *cls);
106 108
107 109
108static void 110static void
109peer_status_cb(void *cls, struct GNUNET_TESTING_Peer *peer, int success) 111peer_status_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success)
110{ 112{
111 struct TestingContext *test_ctx = cls; 113 struct TestingContext *test_ctx = cls;
112 114
113 switch (test_ctx->state) 115 switch (test_ctx->state)
114 { 116 {
115 case PEER_INIT: 117 case PEER_INIT:
116 FAIL_TEST(0); 118 FAIL_TEST (0);
117 break; 119 break;
118 120
119 case PEER_STARTED: 121 case PEER_STARTED:
120 FAIL_TEST(GNUNET_YES == success); 122 FAIL_TEST (GNUNET_YES == success);
121 test_ctx->state = PEER_STOPPED; 123 test_ctx->state = PEER_STOPPED;
122 GNUNET_SCHEDULER_add_now(&do_shutdown2, cls); 124 GNUNET_SCHEDULER_add_now (&do_shutdown2, cls);
123 break; 125 break;
124 126
125 case PEER_STOPPED: 127 case PEER_STOPPED:
126 FAIL_TEST(0); 128 FAIL_TEST (0);
127 } 129 }
128} 130}
129 131
130 132
@@ -134,20 +136,20 @@ peer_status_cb(void *cls, struct GNUNET_TESTING_Peer *peer, int success)
134 * @param cls the testing context 136 * @param cls the testing context
135 */ 137 */
136static void 138static void
137do_shutdown(void *cls) 139do_shutdown (void *cls)
138{ 140{
139 struct TestingContext *test_ctx = cls; 141 struct TestingContext *test_ctx = cls;
140 142
141 GNUNET_assert(NULL != test_ctx); 143 GNUNET_assert (NULL != test_ctx);
142 if (NULL != test_ctx->peer) 144 if (NULL != test_ctx->peer)
143 { 145 {
144 FAIL_TEST(GNUNET_OK == 146 FAIL_TEST (GNUNET_OK ==
145 GNUNET_TESTING_peer_stop_async(test_ctx->peer, 147 GNUNET_TESTING_peer_stop_async (test_ctx->peer,
146 &peer_status_cb, 148 &peer_status_cb,
147 test_ctx)); 149 test_ctx));
148 } 150 }
149 else 151 else
150 do_shutdown2(test_ctx); 152 do_shutdown2 (test_ctx);
151} 153}
152 154
153 155
@@ -155,51 +157,51 @@ do_shutdown(void *cls)
155 * Main point of test execution 157 * Main point of test execution
156 */ 158 */
157static void 159static void
158run(void *cls, char *const *args, const char *cfgfile, 160run (void *cls, char *const *args, const char *cfgfile,
159 const struct GNUNET_CONFIGURATION_Handle *cfg) 161 const struct GNUNET_CONFIGURATION_Handle *cfg)
160{ 162{
161 struct TestingContext *test_ctx; 163 struct TestingContext *test_ctx;
162 char *emsg; 164 char *emsg;
163 struct GNUNET_PeerIdentity id; 165 struct GNUNET_PeerIdentity id;
164 166
165 test_ctx = GNUNET_new(struct TestingContext); 167 test_ctx = GNUNET_new (struct TestingContext);
166 test_ctx->system = 168 test_ctx->system =
167 GNUNET_TESTING_system_create("test-gnunet-testing", 169 GNUNET_TESTING_system_create ("test-gnunet-testing",
168 "127.0.0.1", NULL, NULL); 170 "127.0.0.1", NULL, NULL);
169 emsg = NULL; 171 emsg = NULL;
170 if (NULL == test_ctx->system) 172 if (NULL == test_ctx->system)
171 goto end; 173 goto end;
172 test_ctx->cfg = GNUNET_CONFIGURATION_dup(cfg); 174 test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg);
173 test_ctx->peer = 175 test_ctx->peer =
174 GNUNET_TESTING_peer_configure(test_ctx->system, 176 GNUNET_TESTING_peer_configure (test_ctx->system,
175 test_ctx->cfg, 177 test_ctx->cfg,
176 0, &id, &emsg); 178 0, &id, &emsg);
177 if (NULL == test_ctx->peer) 179 if (NULL == test_ctx->peer)
178 { 180 {
179 if (NULL != emsg) 181 if (NULL != emsg)
180 printf("Test failed upon error: %s", emsg); 182 printf ("Test failed upon error: %s", emsg);
181 goto end; 183 goto end;
182 } 184 }
183 if (GNUNET_OK != GNUNET_TESTING_peer_start(test_ctx->peer)) 185 if (GNUNET_OK != GNUNET_TESTING_peer_start (test_ctx->peer))
184 goto end; 186 goto end;
185 test_ctx->state = PEER_STARTED; 187 test_ctx->state = PEER_STARTED;
186 FAIL_TEST(GNUNET_OK == 188 FAIL_TEST (GNUNET_OK ==
187 GNUNET_TESTING_peer_stop_async(test_ctx->peer, 189 GNUNET_TESTING_peer_stop_async (test_ctx->peer,
188 &peer_status_cb, 190 &peer_status_cb,
189 test_ctx)); 191 test_ctx));
190 GNUNET_TESTING_peer_stop_async_cancel(test_ctx->peer); 192 GNUNET_TESTING_peer_stop_async_cancel (test_ctx->peer);
191 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 193 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
192 &do_shutdown, test_ctx); 194 &do_shutdown, test_ctx);
193 return; 195 return;
194 196
195end: 197end:
196 FAIL_TEST(0); 198 FAIL_TEST (0);
197 GNUNET_SCHEDULER_add_now(&do_shutdown, test_ctx); 199 GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx);
198 GNUNET_free_non_null(emsg); 200 GNUNET_free_non_null (emsg);
199} 201}
200 202
201 203
202int main(int argc, char *argv[]) 204int main (int argc, char *argv[])
203{ 205{
204 struct GNUNET_GETOPT_CommandLineOption options[] = { 206 struct GNUNET_GETOPT_CommandLineOption options[] = {
205 GNUNET_GETOPT_OPTION_END 207 GNUNET_GETOPT_OPTION_END
@@ -207,10 +209,10 @@ int main(int argc, char *argv[])
207 209
208 status = GNUNET_OK; 210 status = GNUNET_OK;
209 if (GNUNET_OK != 211 if (GNUNET_OK !=
210 GNUNET_PROGRAM_run(argc, argv, 212 GNUNET_PROGRAM_run (argc, argv,
211 "test_testing_new_peerstartup", 213 "test_testing_new_peerstartup",
212 "test case for peerstartup using new testing library", 214 "test case for peerstartup using new testing library",
213 options, &run, NULL)) 215 options, &run, NULL))
214 return 1; 216 return 1;
215 return (GNUNET_OK == status) ? 0 : 1; 217 return (GNUNET_OK == status) ? 0 : 1;
216} 218}
diff --git a/src/testing/test_testing_portreservation.c b/src/testing/test_testing_portreservation.c
index 308d462b7..d810ad8cf 100644
--- a/src/testing/test_testing_portreservation.c
+++ b/src/testing/test_testing_portreservation.c
@@ -30,7 +30,7 @@
30#include "gnunet_testing_lib.h" 30#include "gnunet_testing_lib.h"
31 31
32#define LOG(kind, ...) \ 32#define LOG(kind, ...) \
33 GNUNET_log(kind, __VA_ARGS__) 33 GNUNET_log (kind, __VA_ARGS__)
34 34
35/** 35/**
36 * The status of the test 36 * The status of the test
@@ -41,46 +41,46 @@ int status;
41 * Main point of test execution 41 * Main point of test execution
42 */ 42 */
43static void 43static void
44run(void *cls, char *const *args, const char *cfgfile, 44run (void *cls, char *const *args, const char *cfgfile,
45 const struct GNUNET_CONFIGURATION_Handle *cfg) 45 const struct GNUNET_CONFIGURATION_Handle *cfg)
46{ 46{
47 struct GNUNET_TESTING_System *system; 47 struct GNUNET_TESTING_System *system;
48 uint16_t new_port1; 48 uint16_t new_port1;
49 uint16_t new_port2; 49 uint16_t new_port2;
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, NULL); 53 "localhost", NULL, NULL);
54 GNUNET_assert(NULL != system); 54 GNUNET_assert (NULL != system);
55 new_port1 = GNUNET_TESTING_reserve_port(system); 55 new_port1 = GNUNET_TESTING_reserve_port (system);
56 LOG(GNUNET_ERROR_TYPE_DEBUG, 56 LOG (GNUNET_ERROR_TYPE_DEBUG,
57 "Reserved TCP port %u\n", new_port1); 57 "Reserved TCP port %u\n", new_port1);
58 if (0 == new_port1) 58 if (0 == new_port1)
59 goto end; 59 goto end;
60 new_port2 = GNUNET_TESTING_reserve_port(system); 60 new_port2 = GNUNET_TESTING_reserve_port (system);
61 LOG(GNUNET_ERROR_TYPE_DEBUG, 61 LOG (GNUNET_ERROR_TYPE_DEBUG,
62 "Reserved TCP port %u\n", new_port2); 62 "Reserved TCP port %u\n", new_port2);
63 if (0 == new_port2) 63 if (0 == new_port2)
64 goto end; 64 goto end;
65 GNUNET_assert(new_port1 != new_port2); 65 GNUNET_assert (new_port1 != new_port2);
66 GNUNET_TESTING_release_port(system, new_port1); 66 GNUNET_TESTING_release_port (system, new_port1);
67 old_port1 = new_port1; 67 old_port1 = new_port1;
68 new_port1 = 0; 68 new_port1 = 0;
69 new_port1 = GNUNET_TESTING_reserve_port(system); 69 new_port1 = GNUNET_TESTING_reserve_port (system);
70 LOG(GNUNET_ERROR_TYPE_DEBUG, 70 LOG (GNUNET_ERROR_TYPE_DEBUG,
71 "Reserved TCP port %u\n", new_port1); 71 "Reserved TCP port %u\n", new_port1);
72 GNUNET_assert(0 != new_port1); 72 GNUNET_assert (0 != new_port1);
73 GNUNET_assert(old_port1 == new_port1); 73 GNUNET_assert (old_port1 == new_port1);
74 GNUNET_TESTING_release_port(system, new_port1); 74 GNUNET_TESTING_release_port (system, new_port1);
75 GNUNET_TESTING_release_port(system, new_port2); 75 GNUNET_TESTING_release_port (system, new_port2);
76 status = GNUNET_OK; 76 status = GNUNET_OK;
77 77
78end: 78end:
79 GNUNET_TESTING_system_destroy(system, GNUNET_YES); 79 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
80} 80}
81 81
82 82
83int main(int argc, char *argv[]) 83int main (int argc, char *argv[])
84{ 84{
85 struct GNUNET_GETOPT_CommandLineOption options[] = { 85 struct GNUNET_GETOPT_CommandLineOption options[] = {
86 GNUNET_GETOPT_OPTION_END 86 GNUNET_GETOPT_OPTION_END
@@ -88,14 +88,14 @@ int main(int argc, char *argv[])
88 88
89 status = GNUNET_SYSERR; 89 status = GNUNET_SYSERR;
90 if (GNUNET_OK != 90 if (GNUNET_OK !=
91 GNUNET_PROGRAM_run(argc, 91 GNUNET_PROGRAM_run (argc,
92 argv, 92 argv,
93 "test_testing_new_portreservation", 93 "test_testing_new_portreservation",
94 "test case for testing port reservation routines" 94 "test case for testing port reservation routines"
95 " from the new testing library API", 95 " from the new testing library API",
96 options, 96 options,
97 &run, 97 &run,
98 NULL)) 98 NULL))
99 return 1; 99 return 1;
100 return (GNUNET_OK == status) ? 0 : 1; 100 return (GNUNET_OK == status) ? 0 : 1;
101} 101}
diff --git a/src/testing/test_testing_servicestartup.c b/src/testing/test_testing_servicestartup.c
index 18786ea86..d25c16167 100644
--- a/src/testing/test_testing_servicestartup.c
+++ b/src/testing/test_testing_servicestartup.c
@@ -29,7 +29,7 @@
29 29
30 30
31#define LOG(kind, ...) \ 31#define LOG(kind, ...) \
32 GNUNET_log(kind, __VA_ARGS__) 32 GNUNET_log (kind, __VA_ARGS__)
33 33
34 34
35/** 35/**
@@ -45,30 +45,29 @@ static int test_success;
45 * @param cfg the configuration with which the current testing service is run 45 * @param cfg the configuration with which the current testing service is run
46 */ 46 */
47static void 47static void
48test_run(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, 48test_run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
49 struct GNUNET_TESTING_Peer *peer) 49 struct GNUNET_TESTING_Peer *peer)
50{ 50{
51 GNUNET_assert(NULL == cls); 51 GNUNET_assert (NULL == cls);
52 GNUNET_assert(NULL != cfg); 52 GNUNET_assert (NULL != cfg);
53 LOG(GNUNET_ERROR_TYPE_DEBUG, "Service arm started successfully\n"); 53 LOG (GNUNET_ERROR_TYPE_DEBUG, "Service arm started successfully\n");
54 test_success = GNUNET_YES; 54 test_success = GNUNET_YES;
55 GNUNET_SCHEDULER_shutdown(); 55 GNUNET_SCHEDULER_shutdown ();
56} 56}
57 57
58 58
59/** 59/**
60 * The main point of execution 60 * The main point of execution
61 */ 61 */
62int main(int argc, char *argv[]) 62int main (int argc, char *argv[])
63{ 63{
64 test_success = GNUNET_NO; 64 test_success = GNUNET_NO;
65 GNUNET_assert(0 == GNUNET_TESTING_service_run("test-testing-servicestartup", 65 GNUNET_assert (0 == GNUNET_TESTING_service_run ("test-testing-servicestartup",
66 "arm", 66 "arm",
67 "test_testing_defaults.conf", 67 "test_testing_defaults.conf",
68 &test_run, 68 &test_run,
69 NULL)); 69 NULL));
70 return (GNUNET_YES == test_success) ? 0 : 1; 70 return (GNUNET_YES == test_success) ? 0 : 1;
71} 71}
72 72
73/* end of test_testing_servicestartup.c */ 73/* end of test_testing_servicestartup.c */
74
diff --git a/src/testing/test_testing_sharedservices.c b/src/testing/test_testing_sharedservices.c
index 86e9f017c..13219bf5d 100644
--- a/src/testing/test_testing_sharedservices.c
+++ b/src/testing/test_testing_sharedservices.c
@@ -29,7 +29,7 @@
29#include "gnunet_testing_lib.h" 29#include "gnunet_testing_lib.h"
30 30
31#define LOG(kind, ...) \ 31#define LOG(kind, ...) \
32 GNUNET_log(kind, __VA_ARGS__) 32 GNUNET_log (kind, __VA_ARGS__)
33 33
34#define NUM_PEERS 4 34#define NUM_PEERS 4
35 35
@@ -41,7 +41,8 @@ int status;
41/** 41/**
42 * The testing context 42 * The testing context
43 */ 43 */
44struct TestingContext { 44struct TestingContext
45{
45 /** 46 /**
46 * The testing system 47 * The testing system
47 */ 48 */
@@ -65,26 +66,26 @@ struct TestingContext {
65 * @param cls the testing context 66 * @param cls the testing context
66 */ 67 */
67static void 68static void
68do_shutdown(void *cls) 69do_shutdown (void *cls)
69{ 70{
70 struct TestingContext *test_ctx = cls; 71 struct TestingContext *test_ctx = cls;
71 struct GNUNET_TESTING_Peer *peer; 72 struct GNUNET_TESTING_Peer *peer;
72 unsigned int cnt; 73 unsigned int cnt;
73 74
74 GNUNET_assert(NULL != test_ctx); 75 GNUNET_assert (NULL != test_ctx);
75 for (cnt = 0; cnt < NUM_PEERS; cnt++) 76 for (cnt = 0; cnt < NUM_PEERS; cnt++)
76 { 77 {
77 peer = test_ctx->peers[cnt]; 78 peer = test_ctx->peers[cnt];
78 if (NULL == peer) 79 if (NULL == peer)
79 continue; 80 continue;
80 (void)GNUNET_TESTING_peer_stop(peer); 81 (void) GNUNET_TESTING_peer_stop (peer);
81 GNUNET_TESTING_peer_destroy(peer); 82 GNUNET_TESTING_peer_destroy (peer);
82 } 83 }
83 if (NULL != test_ctx->cfg) 84 if (NULL != test_ctx->cfg)
84 GNUNET_CONFIGURATION_destroy(test_ctx->cfg); 85 GNUNET_CONFIGURATION_destroy (test_ctx->cfg);
85 if (NULL != test_ctx->system) 86 if (NULL != test_ctx->system)
86 GNUNET_TESTING_system_destroy(test_ctx->system, GNUNET_YES); 87 GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES);
87 GNUNET_free(test_ctx); 88 GNUNET_free (test_ctx);
88} 89}
89 90
90 91
@@ -92,8 +93,8 @@ do_shutdown(void *cls)
92 * Main point of test execution 93 * Main point of test execution
93 */ 94 */
94static void 95static void
95run(void *cls, char *const *args, const char *cfgfile, 96run (void *cls, char *const *args, const char *cfgfile,
96 const struct GNUNET_CONFIGURATION_Handle *cfg) 97 const struct GNUNET_CONFIGURATION_Handle *cfg)
97{ 98{
98 struct TestingContext *test_ctx; 99 struct TestingContext *test_ctx;
99 char *emsg; 100 char *emsg;
@@ -105,44 +106,44 @@ run(void *cls, char *const *args, const char *cfgfile,
105 struct GNUNET_TESTING_Peer *peer; 106 struct GNUNET_TESTING_Peer *peer;
106 unsigned int cnt; 107 unsigned int cnt;
107 108
108 test_ctx = GNUNET_new(struct TestingContext); 109 test_ctx = GNUNET_new (struct TestingContext);
109 test_ctx->system = 110 test_ctx->system =
110 GNUNET_TESTING_system_create("test-gnunet-testing", 111 GNUNET_TESTING_system_create ("test-gnunet-testing",
111 "127.0.0.1", NULL, ss); 112 "127.0.0.1", NULL, ss);
112 emsg = NULL; 113 emsg = NULL;
113 if (NULL == test_ctx->system) 114 if (NULL == test_ctx->system)
114 goto end; 115 goto end;
115 test_ctx->cfg = GNUNET_CONFIGURATION_dup(cfg); 116 test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg);
116 for (cnt = 0; cnt < NUM_PEERS; cnt++) 117 for (cnt = 0; cnt < NUM_PEERS; cnt++)
118 {
119 peer = GNUNET_TESTING_peer_configure (test_ctx->system,
120 test_ctx->cfg,
121 0, &id, &emsg);
122 if (NULL == peer)
123 {
124 if (NULL != emsg)
125 printf ("Test failed upon error: %s", emsg);
126 goto end;
127 }
128 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer))
117 { 129 {
118 peer = GNUNET_TESTING_peer_configure(test_ctx->system, 130 GNUNET_TESTING_peer_destroy (peer);
119 test_ctx->cfg, 131 goto end;
120 0, &id, &emsg);
121 if (NULL == peer)
122 {
123 if (NULL != emsg)
124 printf("Test failed upon error: %s", emsg);
125 goto end;
126 }
127 if (GNUNET_OK != GNUNET_TESTING_peer_start(peer))
128 {
129 GNUNET_TESTING_peer_destroy(peer);
130 goto end;
131 }
132 test_ctx->peers[cnt] = peer;
133 } 132 }
133 test_ctx->peers[cnt] = peer;
134 }
134 status = GNUNET_OK; 135 status = GNUNET_OK;
135 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 136 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
136 &do_shutdown, test_ctx); 137 &do_shutdown, test_ctx);
137 return; 138 return;
138 139
139end: 140end:
140 GNUNET_SCHEDULER_add_now(&do_shutdown, test_ctx); 141 GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx);
141 GNUNET_free_non_null(emsg); 142 GNUNET_free_non_null (emsg);
142} 143}
143 144
144 145
145int main(int argc, char *argv[]) 146int main (int argc, char *argv[])
146{ 147{
147 struct GNUNET_GETOPT_CommandLineOption options[] = { 148 struct GNUNET_GETOPT_CommandLineOption options[] = {
148 GNUNET_GETOPT_OPTION_END 149 GNUNET_GETOPT_OPTION_END
@@ -153,10 +154,10 @@ int main(int argc, char *argv[])
153 154
154 status = GNUNET_SYSERR; 155 status = GNUNET_SYSERR;
155 if (GNUNET_OK != 156 if (GNUNET_OK !=
156 GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, 157 GNUNET_PROGRAM_run ((sizeof(argv2) / sizeof(char *)) - 1, argv2,
157 "test_testing_sharedservices", 158 "test_testing_sharedservices",
158 "test case for testing service sharing among peers started by testing", 159 "test case for testing service sharing among peers started by testing",
159 options, &run, NULL)) 160 options, &run, NULL))
160 return 1; 161 return 1;
161 return (GNUNET_OK == status) ? 0 : 3; 162 return (GNUNET_OK == status) ? 0 : 3;
162} 163}
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 26e866225..362a24af5 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -34,7 +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, ...) GNUNET_log_from(kind, "testing-api", __VA_ARGS__) 37#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
38 38
39 39
40/** 40/**
@@ -59,7 +59,8 @@
59#define HIGH_PORT 56000 59#define HIGH_PORT 56000
60 60
61 61
62struct SharedServiceInstance { 62struct SharedServiceInstance
63{
63 struct SharedService *ss; 64 struct SharedService *ss;
64 65
65 char *cfg_fn; 66 char *cfg_fn;
@@ -73,7 +74,8 @@ struct SharedServiceInstance {
73 unsigned int n_refs; 74 unsigned int n_refs;
74}; 75};
75 76
76struct SharedService { 77struct SharedService
78{
77 char *sname; 79 char *sname;
78 80
79 struct SharedServiceInstance **instances; 81 struct SharedServiceInstance **instances;
@@ -92,7 +94,8 @@ struct SharedService {
92 * Handle for a system on which GNUnet peers are executed; 94 * Handle for a system on which GNUnet peers are executed;
93 * a system is used for reserving unique paths and ports. 95 * a system is used for reserving unique paths and ports.
94 */ 96 */
95struct GNUNET_TESTING_System { 97struct GNUNET_TESTING_System
98{
96 /** 99 /**
97 * Prefix (i.e. "/tmp/gnunet-testing/") we prepend to each 100 * Prefix (i.e. "/tmp/gnunet-testing/") we prepend to each
98 * GNUNET_HOME. 101 * GNUNET_HOME.
@@ -164,7 +167,8 @@ struct GNUNET_TESTING_System {
164/** 167/**
165 * Handle for a GNUnet peer controlled by testing. 168 * Handle for a GNUnet peer controlled by testing.
166 */ 169 */
167struct GNUNET_TESTING_Peer { 170struct GNUNET_TESTING_Peer
171{
168 /** 172 /**
169 * The TESTING system associated with this peer 173 * The TESTING system associated with this peer
170 */ 174 */
@@ -245,56 +249,56 @@ struct GNUNET_TESTING_Peer {
245 * @return #GNUNET_OK on success; #GNUNET_SYSERR on error 249 * @return #GNUNET_OK on success; #GNUNET_SYSERR on error
246 */ 250 */
247static int 251static int
248hostkeys_load(struct GNUNET_TESTING_System *system) 252hostkeys_load (struct GNUNET_TESTING_System *system)
249{ 253{
250 uint64_t fs; 254 uint64_t fs;
251 char *data_dir; 255 char *data_dir;
252 char *filename; 256 char *filename;
253 struct GNUNET_DISK_FileHandle *fd; 257 struct GNUNET_DISK_FileHandle *fd;
254 258
255 GNUNET_assert(NULL == system->hostkeys_data); 259 GNUNET_assert (NULL == system->hostkeys_data);
256 data_dir = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_DATADIR); 260 data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
257 GNUNET_asprintf(&filename, "%s/testing_hostkeys.ecc", data_dir); 261 GNUNET_asprintf (&filename, "%s/testing_hostkeys.ecc", data_dir);
258 GNUNET_free(data_dir); 262 GNUNET_free (data_dir);
259 263
260 if (GNUNET_YES != GNUNET_DISK_file_test(filename)) 264 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
261 { 265 {
262 LOG(GNUNET_ERROR_TYPE_ERROR, 266 LOG (GNUNET_ERROR_TYPE_ERROR,
263 _("Hostkeys file not found: %s\n"), 267 _ ("Hostkeys file not found: %s\n"),
264 filename); 268 filename);
265 GNUNET_free(filename); 269 GNUNET_free (filename);
266 return GNUNET_SYSERR; 270 return GNUNET_SYSERR;
267 } 271 }
268 /* Check hostkey file size, read entire thing into memory */ 272 /* Check hostkey file size, read entire thing into memory */
269 if (GNUNET_OK != 273 if (GNUNET_OK !=
270 GNUNET_DISK_file_size(filename, &fs, GNUNET_YES, GNUNET_YES)) 274 GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
271 fs = 0; 275 fs = 0;
272 if (0 == fs) 276 if (0 == fs)
273 { 277 {
274 GNUNET_free(filename); 278 GNUNET_free (filename);
275 return GNUNET_SYSERR; /* File is empty */ 279 return GNUNET_SYSERR; /* File is empty */
276 } 280 }
277 if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE)) 281 if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE))
278 { 282 {
279 LOG(GNUNET_ERROR_TYPE_ERROR, 283 LOG (GNUNET_ERROR_TYPE_ERROR,
280 _("Incorrect hostkey file format: %s\n"), 284 _ ("Incorrect hostkey file format: %s\n"),
281 filename); 285 filename);
282 GNUNET_free(filename); 286 GNUNET_free (filename);
283 return GNUNET_SYSERR; 287 return GNUNET_SYSERR;
284 } 288 }
285 fd = GNUNET_DISK_file_open(filename, 289 fd = GNUNET_DISK_file_open (filename,
286 GNUNET_DISK_OPEN_READ, 290 GNUNET_DISK_OPEN_READ,
287 GNUNET_DISK_PERM_NONE); 291 GNUNET_DISK_PERM_NONE);
288 if (NULL == fd) 292 if (NULL == fd)
289 { 293 {
290 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", filename); 294 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename);
291 GNUNET_free(filename); 295 GNUNET_free (filename);
292 return GNUNET_SYSERR; 296 return GNUNET_SYSERR;
293 } 297 }
294 GNUNET_free(filename); 298 GNUNET_free (filename);
295 system->hostkeys_data = 299 system->hostkeys_data =
296 GNUNET_DISK_file_map(fd, &system->map, GNUNET_DISK_MAP_TYPE_READ, fs); 300 GNUNET_DISK_file_map (fd, &system->map, GNUNET_DISK_MAP_TYPE_READ, fs);
297 GNUNET_DISK_file_close(fd); 301 GNUNET_DISK_file_close (fd);
298 if (NULL == system->hostkeys_data) 302 if (NULL == system->hostkeys_data)
299 return GNUNET_SYSERR; 303 return GNUNET_SYSERR;
300 system->total_hostkeys = fs / GNUNET_TESTING_HOSTKEYFILESIZE; 304 system->total_hostkeys = fs / GNUNET_TESTING_HOSTKEYFILESIZE;
@@ -308,11 +312,11 @@ hostkeys_load(struct GNUNET_TESTING_System *system)
308 * @param system the testing system handle 312 * @param system the testing system handle
309 */ 313 */
310static void 314static void
311hostkeys_unload(struct GNUNET_TESTING_System *system) 315hostkeys_unload (struct GNUNET_TESTING_System *system)
312{ 316{
313 GNUNET_break(NULL != system->hostkeys_data); 317 GNUNET_break (NULL != system->hostkeys_data);
314 system->hostkeys_data = NULL; 318 system->hostkeys_data = NULL;
315 GNUNET_DISK_file_unmap(system->map); 319 GNUNET_DISK_file_unmap (system->map);
316 system->map = NULL; 320 system->map = NULL;
317 system->hostkeys_data = NULL; 321 system->hostkeys_data = NULL;
318 system->total_hostkeys = 0; 322 system->total_hostkeys = 0;
@@ -328,14 +332,14 @@ hostkeys_unload(struct GNUNET_TESTING_System *system)
328 * @param value value of the option 332 * @param value value of the option
329 */ 333 */
330static void 334static void
331cfg_copy_iterator(void *cls, 335cfg_copy_iterator (void *cls,
332 const char *section, 336 const char *section,
333 const char *option, 337 const char *option,
334 const char *value) 338 const char *value)
335{ 339{
336 struct GNUNET_CONFIGURATION_Handle *cfg2 = cls; 340 struct GNUNET_CONFIGURATION_Handle *cfg2 = cls;
337 341
338 GNUNET_CONFIGURATION_set_value_string(cfg2, section, option, value); 342 GNUNET_CONFIGURATION_set_value_string (cfg2, section, option, value);
339} 343}
340 344
341 345
@@ -361,7 +365,7 @@ cfg_copy_iterator(void *cls,
361 * @return handle to this system, NULL on error 365 * @return handle to this system, NULL on error
362 */ 366 */
363struct GNUNET_TESTING_System * 367struct GNUNET_TESTING_System *
364GNUNET_TESTING_system_create_with_portrange( 368GNUNET_TESTING_system_create_with_portrange (
365 const char *testdir, 369 const char *testdir,
366 const char *trusted_ip, 370 const char *trusted_ip,
367 const char *hostname, 371 const char *hostname,
@@ -374,53 +378,53 @@ GNUNET_TESTING_system_create_with_portrange(
374 struct SharedService *ss; 378 struct SharedService *ss;
375 unsigned int cnt; 379 unsigned int cnt;
376 380
377 GNUNET_assert(NULL != testdir); 381 GNUNET_assert (NULL != testdir);
378 system = GNUNET_new(struct GNUNET_TESTING_System); 382 system = GNUNET_new (struct GNUNET_TESTING_System);
379 if (NULL == (system->tmppath = getenv(GNUNET_TESTING_PREFIX))) 383 if (NULL == (system->tmppath = getenv (GNUNET_TESTING_PREFIX)))
380 system->tmppath = GNUNET_DISK_mkdtemp(testdir); 384 system->tmppath = GNUNET_DISK_mkdtemp (testdir);
381 else 385 else
382 system->tmppath = GNUNET_strdup(system->tmppath); 386 system->tmppath = GNUNET_strdup (system->tmppath);
383 system->lowport = lowport; 387 system->lowport = lowport;
384 system->highport = highport; 388 system->highport = highport;
385 if (NULL == system->tmppath) 389 if (NULL == system->tmppath)
386 { 390 {
387 GNUNET_free(system); 391 GNUNET_free (system);
388 return NULL; 392 return NULL;
389 } 393 }
390 if (NULL != trusted_ip) 394 if (NULL != trusted_ip)
391 system->trusted_ip = GNUNET_strdup(trusted_ip); 395 system->trusted_ip = GNUNET_strdup (trusted_ip);
392 if (NULL != hostname) 396 if (NULL != hostname)
393 system->hostname = GNUNET_strdup(hostname); 397 system->hostname = GNUNET_strdup (hostname);
394 if (GNUNET_OK != hostkeys_load(system)) 398 if (GNUNET_OK != hostkeys_load (system))
395 { 399 {
396 GNUNET_TESTING_system_destroy(system, GNUNET_YES); 400 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
397 return NULL; 401 return NULL;
398 } 402 }
399 if (NULL == shared_services) 403 if (NULL == shared_services)
400 return system; 404 return system;
401 for (cnt = 0; NULL != shared_services[cnt].service; cnt++) 405 for (cnt = 0; NULL != shared_services[cnt].service; cnt++)
402 { 406 {
403 tss = shared_services[cnt]; 407 tss = shared_services[cnt];
404 ss = GNUNET_new(struct SharedService); 408 ss = GNUNET_new (struct SharedService);
405 ss->sname = GNUNET_strdup(tss.service); 409 ss->sname = GNUNET_strdup (tss.service);
406 ss->cfg = GNUNET_CONFIGURATION_create(); 410 ss->cfg = GNUNET_CONFIGURATION_create ();
407 GNUNET_CONFIGURATION_iterate_section_values(tss.cfg, 411 GNUNET_CONFIGURATION_iterate_section_values (tss.cfg,
408 ss->sname, 412 ss->sname,
409 &cfg_copy_iterator, 413 &cfg_copy_iterator,
410 ss->cfg); 414 ss->cfg);
411 GNUNET_CONFIGURATION_iterate_section_values(tss.cfg, 415 GNUNET_CONFIGURATION_iterate_section_values (tss.cfg,
412 "TESTING", 416 "TESTING",
413 &cfg_copy_iterator, 417 &cfg_copy_iterator,
414 ss->cfg); 418 ss->cfg);
415 GNUNET_CONFIGURATION_iterate_section_values(tss.cfg, 419 GNUNET_CONFIGURATION_iterate_section_values (tss.cfg,
416 "PATHS", 420 "PATHS",
417 &cfg_copy_iterator, 421 &cfg_copy_iterator,
418 ss->cfg); 422 ss->cfg);
419 ss->share = tss.share; 423 ss->share = tss.share;
420 GNUNET_array_append(system->shared_services, 424 GNUNET_array_append (system->shared_services,
421 system->n_shared_services, 425 system->n_shared_services,
422 ss); 426 ss);
423 } 427 }
424 return system; 428 return system;
425} 429}
426 430
@@ -446,59 +450,59 @@ GNUNET_TESTING_system_create_with_portrange(
446 * @return handle to this system, NULL on error 450 * @return handle to this system, NULL on error
447 */ 451 */
448struct GNUNET_TESTING_System * 452struct GNUNET_TESTING_System *
449GNUNET_TESTING_system_create( 453GNUNET_TESTING_system_create (
450 const char *testdir, 454 const char *testdir,
451 const char *trusted_ip, 455 const char *trusted_ip,
452 const char *hostname, 456 const char *hostname,
453 const struct GNUNET_TESTING_SharedService *shared_services) 457 const struct GNUNET_TESTING_SharedService *shared_services)
454{ 458{
455 return GNUNET_TESTING_system_create_with_portrange(testdir, 459 return GNUNET_TESTING_system_create_with_portrange (testdir,
456 trusted_ip, 460 trusted_ip,
457 hostname, 461 hostname,
458 shared_services, 462 shared_services,
459 LOW_PORT, 463 LOW_PORT,
460 HIGH_PORT); 464 HIGH_PORT);
461} 465}
462 466
463 467
464static void 468static void
465cleanup_shared_service_instance(struct SharedServiceInstance *i) 469cleanup_shared_service_instance (struct SharedServiceInstance *i)
466{ 470{
467 if (NULL != i->cfg_fn) 471 if (NULL != i->cfg_fn)
468 { 472 {
469 (void)unlink(i->cfg_fn); 473 (void) unlink (i->cfg_fn);
470 GNUNET_free(i->cfg_fn); 474 GNUNET_free (i->cfg_fn);
471 } 475 }
472 GNUNET_free_non_null(i->unix_sock); 476 GNUNET_free_non_null (i->unix_sock);
473 GNUNET_free_non_null(i->port_str); 477 GNUNET_free_non_null (i->port_str);
474 GNUNET_break(NULL == i->proc); 478 GNUNET_break (NULL == i->proc);
475 GNUNET_break(0 == i->n_refs); 479 GNUNET_break (0 == i->n_refs);
476 GNUNET_free(i); 480 GNUNET_free (i);
477} 481}
478 482
479 483
480static int 484static int
481start_shared_service_instance(struct SharedServiceInstance *i) 485start_shared_service_instance (struct SharedServiceInstance *i)
482{ 486{
483 char *binary; 487 char *binary;
484 char *libexec_binary; 488 char *libexec_binary;
485 489
486 GNUNET_assert(NULL == i->proc); 490 GNUNET_assert (NULL == i->proc);
487 GNUNET_assert(NULL != i->cfg_fn); 491 GNUNET_assert (NULL != i->cfg_fn);
488 (void)GNUNET_asprintf(&binary, "gnunet-service-%s", i->ss->sname); 492 (void) GNUNET_asprintf (&binary, "gnunet-service-%s", i->ss->sname);
489 libexec_binary = GNUNET_OS_get_libexec_binary_path(binary); 493 libexec_binary = GNUNET_OS_get_libexec_binary_path (binary);
490 GNUNET_free(binary); 494 GNUNET_free (binary);
491 i->proc = GNUNET_OS_start_process(PIPE_CONTROL, 495 i->proc = GNUNET_OS_start_process (PIPE_CONTROL,
492 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 496 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
493 NULL, 497 NULL,
494 NULL, 498 NULL,
495 NULL, 499 NULL,
496 libexec_binary, 500 libexec_binary,
497 libexec_binary, 501 libexec_binary,
498 "-c", 502 "-c",
499 i->cfg_fn, 503 i->cfg_fn,
500 NULL); 504 NULL);
501 GNUNET_free(libexec_binary); 505 GNUNET_free (libexec_binary);
502 if (NULL == i->proc) 506 if (NULL == i->proc)
503 return GNUNET_SYSERR; 507 return GNUNET_SYSERR;
504 return GNUNET_OK; 508 return GNUNET_OK;
@@ -506,15 +510,15 @@ start_shared_service_instance(struct SharedServiceInstance *i)
506 510
507 511
508static void 512static void
509stop_shared_service_instance(struct SharedServiceInstance *i) 513stop_shared_service_instance (struct SharedServiceInstance *i)
510{ 514{
511 GNUNET_break(0 == i->n_refs); 515 GNUNET_break (0 == i->n_refs);
512 if (0 != GNUNET_OS_process_kill(i->proc, GNUNET_TERM_SIG)) 516 if (0 != GNUNET_OS_process_kill (i->proc, GNUNET_TERM_SIG))
513 LOG(GNUNET_ERROR_TYPE_WARNING, 517 LOG (GNUNET_ERROR_TYPE_WARNING,
514 "Killing shared service instance (%s) failed\n", 518 "Killing shared service instance (%s) failed\n",
515 i->ss->sname); 519 i->ss->sname);
516 (void)GNUNET_OS_process_wait(i->proc); 520 (void) GNUNET_OS_process_wait (i->proc);
517 GNUNET_OS_process_destroy(i->proc); 521 GNUNET_OS_process_destroy (i->proc);
518 i->proc = NULL; 522 i->proc = NULL;
519} 523}
520 524
@@ -527,8 +531,8 @@ stop_shared_service_instance(struct SharedServiceInstance *i)
527 * be removed (clean up on shutdown)? 531 * be removed (clean up on shutdown)?
528 */ 532 */
529void 533void
530GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system, 534GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system,
531 int remove_paths) 535 int remove_paths)
532{ 536{
533 struct SharedService *ss; 537 struct SharedService *ss;
534 struct SharedServiceInstance *i; 538 struct SharedServiceInstance *i;
@@ -536,29 +540,29 @@ GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system,
536 unsigned int i_cnt; 540 unsigned int i_cnt;
537 541
538 if (NULL != system->hostkeys_data) 542 if (NULL != system->hostkeys_data)
539 hostkeys_unload(system); 543 hostkeys_unload (system);
540 for (ss_cnt = 0; ss_cnt < system->n_shared_services; ss_cnt++) 544 for (ss_cnt = 0; ss_cnt < system->n_shared_services; ss_cnt++)
545 {
546 ss = system->shared_services[ss_cnt];
547 for (i_cnt = 0; i_cnt < ss->n_instances; i_cnt++)
541 { 548 {
542 ss = system->shared_services[ss_cnt]; 549 i = ss->instances[i_cnt];
543 for (i_cnt = 0; i_cnt < ss->n_instances; i_cnt++) 550 if (NULL != i->proc)
544 { 551 stop_shared_service_instance (i);
545 i = ss->instances[i_cnt]; 552 cleanup_shared_service_instance (i);
546 if (NULL != i->proc)
547 stop_shared_service_instance(i);
548 cleanup_shared_service_instance(i);
549 }
550 GNUNET_free_non_null(ss->instances);
551 GNUNET_CONFIGURATION_destroy(ss->cfg);
552 GNUNET_free(ss->sname);
553 GNUNET_free(ss);
554 } 553 }
555 GNUNET_free_non_null(system->shared_services); 554 GNUNET_free_non_null (ss->instances);
555 GNUNET_CONFIGURATION_destroy (ss->cfg);
556 GNUNET_free (ss->sname);
557 GNUNET_free (ss);
558 }
559 GNUNET_free_non_null (system->shared_services);
556 if (GNUNET_YES == remove_paths) 560 if (GNUNET_YES == remove_paths)
557 GNUNET_DISK_directory_remove(system->tmppath); 561 GNUNET_DISK_directory_remove (system->tmppath);
558 GNUNET_free(system->tmppath); 562 GNUNET_free (system->tmppath);
559 GNUNET_free_non_null(system->trusted_ip); 563 GNUNET_free_non_null (system->trusted_ip);
560 GNUNET_free_non_null(system->hostname); 564 GNUNET_free_non_null (system->hostname);
561 GNUNET_free(system); 565 GNUNET_free (system);
562} 566}
563 567
564 568
@@ -569,7 +573,7 @@ GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system,
569 * @return 0 if no free port was available 573 * @return 0 if no free port was available
570 */ 574 */
571uint16_t 575uint16_t
572GNUNET_TESTING_reserve_port(struct GNUNET_TESTING_System *system) 576GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system)
573{ 577{
574 struct GNUNET_NETWORK_Handle *socket; 578 struct GNUNET_NETWORK_Handle *socket;
575 struct addrinfo hint; 579 struct addrinfo hint;
@@ -603,57 +607,57 @@ GNUNET_TESTING_reserve_port(struct GNUNET_TESTING_System *system)
603 port_buckets = system->reserved_ports; 607 port_buckets = system->reserved_ports;
604 for (index = (system->lowport / 32) + 1; index < (system->highport / 32); 608 for (index = (system->lowport / 32) + 1; index < (system->highport / 32);
605 index++) 609 index++)
610 {
611 xor_image = (UINT32_MAX ^ port_buckets[index]);
612 if (0 == xor_image) /* Ports in the bucket are full */
613 continue;
614 pos = system->lowport % 32;
615 while (pos < 32)
606 { 616 {
607 xor_image = (UINT32_MAX ^ port_buckets[index]); 617 if (0 == ((xor_image >> pos) & 1U))
608 if (0 == xor_image) /* Ports in the bucket are full */ 618 {
619 pos++;
609 continue; 620 continue;
610 pos = system->lowport % 32; 621 }
611 while (pos < 32) 622 open_port = (index * 32) + pos;
612 { 623 if (open_port >= system->highport)
613 if (0 == ((xor_image >> pos) & 1U)) 624 return 0;
614 { 625 GNUNET_asprintf (&open_port_str, "%u", (unsigned int) open_port);
615 pos++; 626 ret = NULL;
616 continue; 627 GNUNET_assert (0 == getaddrinfo (NULL, open_port_str, &hint, &ret));
617 } 628 GNUNET_free (open_port_str);
618 open_port = (index * 32) + pos; 629 bind_status = GNUNET_NO;
619 if (open_port >= system->highport) 630 for (ai = ret; NULL != ai; ai = ai->ai_next)
620 return 0; 631 {
621 GNUNET_asprintf(&open_port_str, "%u", (unsigned int)open_port); 632 socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_STREAM, 0);
622 ret = NULL; 633 if (NULL == socket)
623 GNUNET_assert(0 == getaddrinfo(NULL, open_port_str, &hint, &ret)); 634 continue;
624 GNUNET_free(open_port_str); 635 bind_status =
625 bind_status = GNUNET_NO; 636 GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen);
626 for (ai = ret; NULL != ai; ai = ai->ai_next) 637 GNUNET_NETWORK_socket_close (socket);
627 { 638 if (GNUNET_OK != bind_status)
628 socket = GNUNET_NETWORK_socket_create(ai->ai_family, SOCK_STREAM, 0); 639 break;
629 if (NULL == socket) 640 socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_DGRAM, 0);
630 continue; 641 if (NULL == socket)
631 bind_status = 642 continue;
632 GNUNET_NETWORK_socket_bind(socket, ai->ai_addr, ai->ai_addrlen); 643 bind_status =
633 GNUNET_NETWORK_socket_close(socket); 644 GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen);
634 if (GNUNET_OK != bind_status) 645 GNUNET_NETWORK_socket_close (socket);
635 break; 646 if (GNUNET_OK != bind_status)
636 socket = GNUNET_NETWORK_socket_create(ai->ai_family, SOCK_DGRAM, 0); 647 break;
637 if (NULL == socket) 648 }
638 continue; 649 port_buckets[index] |= (1U << pos); /* Set the port bit */
639 bind_status = 650 freeaddrinfo (ret);
640 GNUNET_NETWORK_socket_bind(socket, ai->ai_addr, ai->ai_addrlen); 651 if (GNUNET_OK == bind_status)
641 GNUNET_NETWORK_socket_close(socket); 652 {
642 if (GNUNET_OK != bind_status) 653 LOG (GNUNET_ERROR_TYPE_DEBUG,
643 break; 654 "Found a free port %u\n",
644 } 655 (unsigned int) open_port);
645 port_buckets[index] |= (1U << pos); /* Set the port bit */ 656 return open_port;
646 freeaddrinfo(ret); 657 }
647 if (GNUNET_OK == bind_status) 658 pos++;
648 {
649 LOG(GNUNET_ERROR_TYPE_DEBUG,
650 "Found a free port %u\n",
651 (unsigned int)open_port);
652 return open_port;
653 }
654 pos++;
655 }
656 } 659 }
660 }
657 return 0; 661 return 0;
658} 662}
659 663
@@ -666,8 +670,8 @@ GNUNET_TESTING_reserve_port(struct GNUNET_TESTING_System *system)
666 * @param port reserved port to release 670 * @param port reserved port to release
667 */ 671 */
668void 672void
669GNUNET_TESTING_release_port(struct GNUNET_TESTING_System *system, 673GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system,
670 uint16_t port) 674 uint16_t port)
671{ 675{
672 uint32_t *port_buckets; 676 uint32_t *port_buckets;
673 uint16_t bucket; 677 uint16_t bucket;
@@ -676,12 +680,12 @@ GNUNET_TESTING_release_port(struct GNUNET_TESTING_System *system,
676 port_buckets = system->reserved_ports; 680 port_buckets = system->reserved_ports;
677 bucket = port / 32; 681 bucket = port / 32;
678 pos = port % 32; 682 pos = port % 32;
679 LOG(GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port); 683 LOG (GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port);
680 if (0 == (port_buckets[bucket] & (1U << pos))) 684 if (0 == (port_buckets[bucket] & (1U << pos)))
681 { 685 {
682 GNUNET_break(0); /* Port was not reserved by us using reserve_port() */ 686 GNUNET_break (0); /* Port was not reserved by us using reserve_port() */
683 return; 687 return;
684 } 688 }
685 port_buckets[bucket] &= ~(1U << pos); 689 port_buckets[bucket] &= ~(1U << pos);
686} 690}
687 691
@@ -704,27 +708,27 @@ GNUNET_TESTING_release_port(struct GNUNET_TESTING_System *system,
704 * @return NULL on error (not enough keys) 708 * @return NULL on error (not enough keys)
705 */ 709 */
706struct GNUNET_CRYPTO_EddsaPrivateKey * 710struct GNUNET_CRYPTO_EddsaPrivateKey *
707GNUNET_TESTING_hostkey_get(const struct GNUNET_TESTING_System *system, 711GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system,
708 uint32_t key_number, 712 uint32_t key_number,
709 struct GNUNET_PeerIdentity *id) 713 struct GNUNET_PeerIdentity *id)
710{ 714{
711 struct GNUNET_CRYPTO_EddsaPrivateKey *private_key; 715 struct GNUNET_CRYPTO_EddsaPrivateKey *private_key;
712 716
713 if ((NULL == id) || (NULL == system->hostkeys_data)) 717 if ((NULL == id) || (NULL == system->hostkeys_data))
714 return NULL; 718 return NULL;
715 if (key_number >= system->total_hostkeys) 719 if (key_number >= system->total_hostkeys)
716 { 720 {
717 LOG(GNUNET_ERROR_TYPE_ERROR, 721 LOG (GNUNET_ERROR_TYPE_ERROR,
718 _("Key number %u does not exist\n"), 722 _ ("Key number %u does not exist\n"),
719 key_number); 723 key_number);
720 return NULL; 724 return NULL;
721 } 725 }
722 private_key = GNUNET_new(struct GNUNET_CRYPTO_EddsaPrivateKey); 726 private_key = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey);
723 GNUNET_memcpy(private_key, 727 GNUNET_memcpy (private_key,
724 system->hostkeys_data + 728 system->hostkeys_data
725 (key_number * GNUNET_TESTING_HOSTKEYFILESIZE), 729 + (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
726 GNUNET_TESTING_HOSTKEYFILESIZE); 730 GNUNET_TESTING_HOSTKEYFILESIZE);
727 GNUNET_CRYPTO_eddsa_key_get_public(private_key, &id->public_key); 731 GNUNET_CRYPTO_eddsa_key_get_public (private_key, &id->public_key);
728 return private_key; 732 return private_key;
729} 733}
730 734
@@ -733,7 +737,8 @@ GNUNET_TESTING_hostkey_get(const struct GNUNET_TESTING_System *system,
733 * Structure for holding data to build new configurations from a configuration 737 * Structure for holding data to build new configurations from a configuration
734 * template 738 * template
735 */ 739 */
736struct UpdateContext { 740struct UpdateContext
741{
737 /** 742 /**
738 * The system for which we are building configurations 743 * The system for which we are building configurations
739 */ 744 */
@@ -779,10 +784,10 @@ struct UpdateContext {
779 * @param value value of the option 784 * @param value value of the option
780 */ 785 */
781static void 786static void
782update_config(void *cls, 787update_config (void *cls,
783 const char *section, 788 const char *section,
784 const char *option, 789 const char *option,
785 const char *value) 790 const char *value)
786{ 791{
787 struct UpdateContext *uc = cls; 792 struct UpdateContext *uc = cls;
788 unsigned int ival; 793 unsigned int ival;
@@ -795,76 +800,76 @@ update_config(void *cls,
795 800
796 if (GNUNET_OK != uc->status) 801 if (GNUNET_OK != uc->status)
797 return; 802 return;
798 if (!((0 == strcmp(option, "PORT")) || (0 == strcmp(option, "UNIXPATH")) || 803 if (! ((0 == strcmp (option, "PORT")) || (0 == strcmp (option, "UNIXPATH")) ||
799 (0 == strcmp(option, "HOSTNAME")))) 804 (0 == strcmp (option, "HOSTNAME"))))
800 return; 805 return;
801 GNUNET_asprintf(&single_variable, "single_%s_per_host", section); 806 GNUNET_asprintf (&single_variable, "single_%s_per_host", section);
802 GNUNET_asprintf(&per_host_variable, "num_%s_per_host", section); 807 GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section);
803 if ((0 == strcmp(option, "PORT")) && (1 == sscanf(value, "%u", &ival))) 808 if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival)))
809 {
810 if ((ival != 0) &&
811 (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (uc->cfg,
812 "testing",
813 single_variable)))
804 { 814 {
805 if ((ival != 0) && 815 new_port = GNUNET_TESTING_reserve_port (uc->system);
806 (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno(uc->cfg, 816 if (0 == new_port)
807 "testing", 817 {
808 single_variable))) 818 uc->status = GNUNET_SYSERR;
809 { 819 GNUNET_free (single_variable);
810 new_port = GNUNET_TESTING_reserve_port(uc->system); 820 GNUNET_free (per_host_variable);
811 if (0 == new_port) 821 return;
812 { 822 }
813 uc->status = GNUNET_SYSERR; 823 GNUNET_snprintf (cval, sizeof(cval), "%u", new_port);
814 GNUNET_free(single_variable); 824 value = cval;
815 GNUNET_free(per_host_variable); 825 GNUNET_array_append (uc->ports, uc->nports, new_port);
816 return;
817 }
818 GNUNET_snprintf(cval, sizeof(cval), "%u", new_port);
819 value = cval;
820 GNUNET_array_append(uc->ports, uc->nports, new_port);
821 }
822 else if ((ival != 0) &&
823 (GNUNET_YES ==
824 GNUNET_CONFIGURATION_get_value_yesno(uc->cfg,
825 "testing",
826 single_variable)) &&
827 GNUNET_CONFIGURATION_get_value_number(uc->cfg,
828 "testing",
829 per_host_variable,
830 &num_per_host))
831 {
832 /* GNUNET_snprintf (cval, sizeof (cval), "%u", */
833 /* ival + ctx->fdnum % num_per_host); */
834 /* value = cval; */
835 GNUNET_break(0); /* FIXME */
836 }
837 } 826 }
838 if (0 == strcmp(option, "UNIXPATH")) 827 else if ((ival != 0) &&
828 (GNUNET_YES ==
829 GNUNET_CONFIGURATION_get_value_yesno (uc->cfg,
830 "testing",
831 single_variable)) &&
832 GNUNET_CONFIGURATION_get_value_number (uc->cfg,
833 "testing",
834 per_host_variable,
835 &num_per_host))
839 { 836 {
840 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno(uc->cfg, 837 /* GNUNET_snprintf (cval, sizeof (cval), "%u", */
841 "testing", 838 /* ival + ctx->fdnum % num_per_host); */
842 single_variable)) 839 /* value = cval; */
843 { 840 GNUNET_break (0); /* FIXME */
844 GNUNET_snprintf(uval, 841 }
845 sizeof(uval), 842 }
846 "%s/%s.sock", 843 if (0 == strcmp (option, "UNIXPATH"))
847 uc->gnunet_home, 844 {
848 section); 845 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (uc->cfg,
849 value = uval; 846 "testing",
850 } 847 single_variable))
851 else if ((GNUNET_YES == 848 {
852 GNUNET_CONFIGURATION_get_value_number(uc->cfg, 849 GNUNET_snprintf (uval,
853 "testing", 850 sizeof(uval),
854 per_host_variable, 851 "%s/%s.sock",
855 &num_per_host)) && 852 uc->gnunet_home,
856 (num_per_host > 0)) 853 section);
857 { 854 value = uval;
858 GNUNET_break(0); /* FIXME */
859 }
860 } 855 }
861 if (0 == strcmp(option, "HOSTNAME")) 856 else if ((GNUNET_YES ==
857 GNUNET_CONFIGURATION_get_value_number (uc->cfg,
858 "testing",
859 per_host_variable,
860 &num_per_host)) &&
861 (num_per_host > 0))
862 { 862 {
863 value = (NULL == uc->system->hostname) ? "localhost" : uc->system->hostname; 863 GNUNET_break (0); /* FIXME */
864 } 864 }
865 GNUNET_free(single_variable); 865 }
866 GNUNET_free(per_host_variable); 866 if (0 == strcmp (option, "HOSTNAME"))
867 GNUNET_CONFIGURATION_set_value_string(uc->cfg, section, option, value); 867 {
868 value = (NULL == uc->system->hostname) ? "localhost" : uc->system->hostname;
869 }
870 GNUNET_free (single_variable);
871 GNUNET_free (per_host_variable);
872 GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, option, value);
868} 873}
869 874
870 875
@@ -876,7 +881,7 @@ update_config(void *cls,
876 * @param section name of the section 881 * @param section name of the section
877 */ 882 */
878static void 883static void
879update_config_sections(void *cls, const char *section) 884update_config_sections (void *cls, const char *section)
880{ 885{
881 struct UpdateContext *uc = cls; 886 struct UpdateContext *uc = cls;
882 char **ikeys; 887 char **ikeys;
@@ -893,98 +898,98 @@ update_config_sections(void *cls, const char *section)
893 /* Ignore certain options from sections. See 898 /* Ignore certain options from sections. See
894 https://gnunet.org/bugs/view.php?id=2476 */ 899 https://gnunet.org/bugs/view.php?id=2476 */
895 if (GNUNET_YES == 900 if (GNUNET_YES ==
896 GNUNET_CONFIGURATION_have_value(uc->cfg, section, "TESTING_IGNORE_KEYS")) 901 GNUNET_CONFIGURATION_have_value (uc->cfg, section, "TESTING_IGNORE_KEYS"))
897 { 902 {
898 GNUNET_assert(GNUNET_YES == 903 GNUNET_assert (GNUNET_YES ==
899 GNUNET_CONFIGURATION_get_value_string(uc->cfg, 904 GNUNET_CONFIGURATION_get_value_string (uc->cfg,
900 section, 905 section,
901 "TESTING_IGNORE_KEYS", 906 "TESTING_IGNORE_KEYS",
902 &val)); 907 &val));
908 ptr = val;
909 for (ikeys_cnt = 0; NULL != (ptr = strstr (ptr, ";")); ikeys_cnt++)
910 ptr++;
911 if (0 == ikeys_cnt)
912 GNUNET_break (0);
913 else
914 {
915 ikeys = GNUNET_malloc ((sizeof(char *)) * ikeys_cnt);
903 ptr = val; 916 ptr = val;
904 for (ikeys_cnt = 0; NULL != (ptr = strstr(ptr, ";")); ikeys_cnt++) 917 for (key = 0; key < ikeys_cnt; key++)
918 {
919 ikeys[key] = ptr;
920 ptr = strstr (ptr, ";");
921 GNUNET_assert (NULL != ptr); /* worked just before... */
922 *ptr = '\0';
905 ptr++; 923 ptr++;
906 if (0 == ikeys_cnt) 924 }
907 GNUNET_break(0);
908 else
909 {
910 ikeys = GNUNET_malloc((sizeof(char *)) * ikeys_cnt);
911 ptr = val;
912 for (key = 0; key < ikeys_cnt; key++)
913 {
914 ikeys[key] = ptr;
915 ptr = strstr(ptr, ";");
916 GNUNET_assert(NULL != ptr); /* worked just before... */
917 *ptr = '\0';
918 ptr++;
919 }
920 }
921 } 925 }
926 }
922 if (0 != ikeys_cnt) 927 if (0 != ikeys_cnt)
928 {
929 for (key = 0; key < ikeys_cnt; key++)
923 { 930 {
924 for (key = 0; key < ikeys_cnt; key++) 931 if (NULL != strstr (ikeys[key], "ADVERTISED_PORT"))
925 { 932 break;
926 if (NULL != strstr(ikeys[key], "ADVERTISED_PORT"))
927 break;
928 }
929 if ((key == ikeys_cnt) &&
930 (GNUNET_YES ==
931 GNUNET_CONFIGURATION_have_value(uc->cfg, section, "ADVERTISED_PORT")))
932 {
933 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(uc->cfg,
934 section,
935 "PORT",
936 &ptr))
937 {
938 GNUNET_CONFIGURATION_set_value_string(uc->cfg,
939 section,
940 "ADVERTISED_PORT",
941 ptr);
942 GNUNET_free(ptr);
943 }
944 }
945 for (key = 0; key < ikeys_cnt; key++)
946 {
947 if (NULL != strstr(ikeys[key], "ACCEPT_FROM"))
948 {
949 GNUNET_free(ikeys);
950 GNUNET_free(val);
951 return;
952 }
953 }
954 GNUNET_free(ikeys);
955 } 933 }
956 GNUNET_free_non_null(val); 934 if ((key == ikeys_cnt) &&
935 (GNUNET_YES ==
936 GNUNET_CONFIGURATION_have_value (uc->cfg, section, "ADVERTISED_PORT")))
937 {
938 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (uc->cfg,
939 section,
940 "PORT",
941 &ptr))
942 {
943 GNUNET_CONFIGURATION_set_value_string (uc->cfg,
944 section,
945 "ADVERTISED_PORT",
946 ptr);
947 GNUNET_free (ptr);
948 }
949 }
950 for (key = 0; key < ikeys_cnt; key++)
951 {
952 if (NULL != strstr (ikeys[key], "ACCEPT_FROM"))
953 {
954 GNUNET_free (ikeys);
955 GNUNET_free (val);
956 return;
957 }
958 }
959 GNUNET_free (ikeys);
960 }
961 GNUNET_free_non_null (val);
957 ACCEPT_FROM_key = "ACCEPT_FROM"; 962 ACCEPT_FROM_key = "ACCEPT_FROM";
958 if ((NULL != uc->system->trusted_ip) && 963 if ((NULL != uc->system->trusted_ip) &&
959 (NULL != strstr(uc->system->trusted_ip, ":"))) /* IPv6 in use */ 964 (NULL != strstr (uc->system->trusted_ip, ":"))) /* IPv6 in use */
960 ACCEPT_FROM_key = "ACCEPT_FROM6"; 965 ACCEPT_FROM_key = "ACCEPT_FROM6";
961 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(uc->cfg, 966 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (uc->cfg,
962 section, 967 section,
963 ACCEPT_FROM_key, 968 ACCEPT_FROM_key,
964 &orig_allowed_hosts)) 969 &orig_allowed_hosts))
965 { 970 {
966 orig_allowed_hosts = GNUNET_strdup("127.0.0.1;"); 971 orig_allowed_hosts = GNUNET_strdup ("127.0.0.1;");
967 } 972 }
968 if (NULL == uc->system->trusted_ip) 973 if (NULL == uc->system->trusted_ip)
969 allowed_hosts = GNUNET_strdup(orig_allowed_hosts); 974 allowed_hosts = GNUNET_strdup (orig_allowed_hosts);
970 else 975 else
971 GNUNET_asprintf(&allowed_hosts, 976 GNUNET_asprintf (&allowed_hosts,
972 "%s%s;", 977 "%s%s;",
973 orig_allowed_hosts, 978 orig_allowed_hosts,
974 uc->system->trusted_ip); 979 uc->system->trusted_ip);
975 GNUNET_free(orig_allowed_hosts); 980 GNUNET_free (orig_allowed_hosts);
976 GNUNET_CONFIGURATION_set_value_string(uc->cfg, 981 GNUNET_CONFIGURATION_set_value_string (uc->cfg,
977 section, 982 section,
978 ACCEPT_FROM_key, 983 ACCEPT_FROM_key,
979 allowed_hosts); 984 allowed_hosts);
980 GNUNET_free(allowed_hosts); 985 GNUNET_free (allowed_hosts);
981} 986}
982 987
983 988
984static struct SharedServiceInstance * 989static struct SharedServiceInstance *
985associate_shared_service(struct GNUNET_TESTING_System *system, 990associate_shared_service (struct GNUNET_TESTING_System *system,
986 struct SharedService *ss, 991 struct SharedService *ss,
987 struct GNUNET_CONFIGURATION_Handle *cfg) 992 struct GNUNET_CONFIGURATION_Handle *cfg)
988{ 993{
989 struct SharedServiceInstance *i; 994 struct SharedServiceInstance *i;
990 struct GNUNET_CONFIGURATION_Handle *temp; 995 struct GNUNET_CONFIGURATION_Handle *temp;
@@ -995,62 +1000,62 @@ associate_shared_service(struct GNUNET_TESTING_System *system,
995 if (((0 == ss->share) && (NULL == ss->instances)) || 1000 if (((0 == ss->share) && (NULL == ss->instances)) ||
996 ((0 != ss->share) && 1001 ((0 != ss->share) &&
997 (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share)))) 1002 (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share))))
998 { 1003 {
999 i = GNUNET_new(struct SharedServiceInstance); 1004 i = GNUNET_new (struct SharedServiceInstance);
1000 i->ss = ss; 1005 i->ss = ss;
1001 (void)GNUNET_asprintf(&gnunet_home, 1006 (void) GNUNET_asprintf (&gnunet_home,
1002 "%s/shared/%s/%u", 1007 "%s/shared/%s/%u",
1003 system->tmppath, 1008 system->tmppath,
1004 ss->sname, 1009 ss->sname,
1005 ss->n_instances); 1010 ss->n_instances);
1006 (void)GNUNET_asprintf(&i->unix_sock, "%s/sock", gnunet_home); 1011 (void) GNUNET_asprintf (&i->unix_sock, "%s/sock", gnunet_home);
1007 port = GNUNET_TESTING_reserve_port(system); 1012 port = GNUNET_TESTING_reserve_port (system);
1008 if (0 == port) 1013 if (0 == port)
1009 { 1014 {
1010 GNUNET_free(gnunet_home); 1015 GNUNET_free (gnunet_home);
1011 cleanup_shared_service_instance(i); 1016 cleanup_shared_service_instance (i);
1012 return NULL; 1017 return NULL;
1013 }
1014 GNUNET_array_append(ss->instances, ss->n_instances, i);
1015 temp = GNUNET_CONFIGURATION_dup(ss->cfg);
1016 (void)GNUNET_asprintf(&i->port_str, "%u", port);
1017 (void)GNUNET_asprintf(&i->cfg_fn, "%s/config", gnunet_home);
1018 GNUNET_CONFIGURATION_set_value_string(temp,
1019 "PATHS",
1020 "GNUNET_HOME",
1021 gnunet_home);
1022 GNUNET_free(gnunet_home);
1023 GNUNET_CONFIGURATION_set_value_string(temp,
1024 ss->sname,
1025 "UNIXPATH",
1026 i->unix_sock);
1027 GNUNET_CONFIGURATION_set_value_string(temp,
1028 ss->sname,
1029 "PORT",
1030 i->port_str);
1031 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_write(temp, i->cfg_fn))
1032 {
1033 GNUNET_CONFIGURATION_destroy(temp);
1034 cleanup_shared_service_instance(i);
1035 return NULL;
1036 }
1037 GNUNET_CONFIGURATION_destroy(temp);
1038 } 1018 }
1039 else 1019 GNUNET_array_append (ss->instances, ss->n_instances, i);
1020 temp = GNUNET_CONFIGURATION_dup (ss->cfg);
1021 (void) GNUNET_asprintf (&i->port_str, "%u", port);
1022 (void) GNUNET_asprintf (&i->cfg_fn, "%s/config", gnunet_home);
1023 GNUNET_CONFIGURATION_set_value_string (temp,
1024 "PATHS",
1025 "GNUNET_HOME",
1026 gnunet_home);
1027 GNUNET_free (gnunet_home);
1028 GNUNET_CONFIGURATION_set_value_string (temp,
1029 ss->sname,
1030 "UNIXPATH",
1031 i->unix_sock);
1032 GNUNET_CONFIGURATION_set_value_string (temp,
1033 ss->sname,
1034 "PORT",
1035 i->port_str);
1036 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_write (temp, i->cfg_fn))
1040 { 1037 {
1041 GNUNET_assert(NULL != ss->instances); 1038 GNUNET_CONFIGURATION_destroy (temp);
1042 GNUNET_assert(0 < ss->n_instances); 1039 cleanup_shared_service_instance (i);
1043 i = ss->instances[ss->n_instances - 1]; 1040 return NULL;
1044 } 1041 }
1045 GNUNET_CONFIGURATION_iterate_section_values(ss->cfg, 1042 GNUNET_CONFIGURATION_destroy (temp);
1046 ss->sname, 1043 }
1047 &cfg_copy_iterator, 1044 else
1048 cfg); 1045 {
1049 GNUNET_CONFIGURATION_set_value_string(cfg, 1046 GNUNET_assert (NULL != ss->instances);
1050 ss->sname, 1047 GNUNET_assert (0 < ss->n_instances);
1051 "UNIXPATH", 1048 i = ss->instances[ss->n_instances - 1];
1052 i->unix_sock); 1049 }
1053 GNUNET_CONFIGURATION_set_value_string(cfg, ss->sname, "PORT", i->port_str); 1050 GNUNET_CONFIGURATION_iterate_section_values (ss->cfg,
1051 ss->sname,
1052 &cfg_copy_iterator,
1053 cfg);
1054 GNUNET_CONFIGURATION_set_value_string (cfg,
1055 ss->sname,
1056 "UNIXPATH",
1057 i->unix_sock);
1058 GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "PORT", i->port_str);
1054 return i; 1059 return i;
1055} 1060}
1056 1061
@@ -1075,10 +1080,10 @@ associate_shared_service(struct GNUNET_TESTING_System *system,
1075 * be incomplete and should not be used there upon 1080 * be incomplete and should not be used there upon
1076 */ 1081 */
1077static int 1082static int
1078GNUNET_TESTING_configuration_create_(struct GNUNET_TESTING_System *system, 1083GNUNET_TESTING_configuration_create_ (struct GNUNET_TESTING_System *system,
1079 struct GNUNET_CONFIGURATION_Handle *cfg, 1084 struct GNUNET_CONFIGURATION_Handle *cfg,
1080 uint16_t **ports, 1085 uint16_t **ports,
1081 unsigned int *nports) 1086 unsigned int *nports)
1082{ 1087{
1083 struct UpdateContext uc; 1088 struct UpdateContext uc;
1084 char *default_config; 1089 char *default_config;
@@ -1088,35 +1093,35 @@ GNUNET_TESTING_configuration_create_(struct GNUNET_TESTING_System *system,
1088 uc.status = GNUNET_OK; 1093 uc.status = GNUNET_OK;
1089 uc.ports = NULL; 1094 uc.ports = NULL;
1090 uc.nports = 0; 1095 uc.nports = 0;
1091 GNUNET_asprintf(&uc.gnunet_home, 1096 GNUNET_asprintf (&uc.gnunet_home,
1092 "%s/%u", 1097 "%s/%u",
1093 system->tmppath, 1098 system->tmppath,
1094 system->path_counter++); 1099 system->path_counter++);
1095 GNUNET_asprintf(&default_config, "%s/config", uc.gnunet_home); 1100 GNUNET_asprintf (&default_config, "%s/config", uc.gnunet_home);
1096 GNUNET_CONFIGURATION_set_value_string(cfg, 1101 GNUNET_CONFIGURATION_set_value_string (cfg,
1097 "PATHS", 1102 "PATHS",
1098 "DEFAULTCONFIG", 1103 "DEFAULTCONFIG",
1099 default_config); 1104 default_config);
1100 GNUNET_CONFIGURATION_set_value_string(cfg, "arm", "CONFIG", default_config); 1105 GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", default_config);
1101 GNUNET_free(default_config); 1106 GNUNET_free (default_config);
1102 GNUNET_CONFIGURATION_set_value_string(cfg, 1107 GNUNET_CONFIGURATION_set_value_string (cfg,
1103 "PATHS", 1108 "PATHS",
1104 "GNUNET_HOME", 1109 "GNUNET_HOME",
1105 uc.gnunet_home); 1110 uc.gnunet_home);
1106 /* make PORTs and UNIXPATHs unique */ 1111 /* make PORTs and UNIXPATHs unique */
1107 GNUNET_CONFIGURATION_iterate(cfg, &update_config, &uc); 1112 GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc);
1108 /* allow connections to services from system trusted_ip host */ 1113 /* allow connections to services from system trusted_ip host */
1109 GNUNET_CONFIGURATION_iterate_sections(cfg, &update_config_sections, &uc); 1114 GNUNET_CONFIGURATION_iterate_sections (cfg, &update_config_sections, &uc);
1110 /* enable loopback-based connections between peers */ 1115 /* enable loopback-based connections between peers */
1111 GNUNET_CONFIGURATION_set_value_string(cfg, "nat", "USE_LOCALADDR", "YES"); 1116 GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "USE_LOCALADDR", "YES");
1112 GNUNET_free(uc.gnunet_home); 1117 GNUNET_free (uc.gnunet_home);
1113 if ((NULL != ports) && (NULL != nports)) 1118 if ((NULL != ports) && (NULL != nports))
1114 { 1119 {
1115 *ports = uc.ports; 1120 *ports = uc.ports;
1116 *nports = uc.nports; 1121 *nports = uc.nports;
1117 } 1122 }
1118 else 1123 else
1119 GNUNET_free_non_null(uc.ports); 1124 GNUNET_free_non_null (uc.ports);
1120 return uc.status; 1125 return uc.status;
1121} 1126}
1122 1127
@@ -1138,10 +1143,10 @@ GNUNET_TESTING_configuration_create_(struct GNUNET_TESTING_System *system,
1138 * be incomplete and should not be used there upon 1143 * be incomplete and should not be used there upon
1139 */ 1144 */
1140int 1145int
1141GNUNET_TESTING_configuration_create(struct GNUNET_TESTING_System *system, 1146GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system,
1142 struct GNUNET_CONFIGURATION_Handle *cfg) 1147 struct GNUNET_CONFIGURATION_Handle *cfg)
1143{ 1148{
1144 return GNUNET_TESTING_configuration_create_(system, cfg, NULL, NULL); 1149 return GNUNET_TESTING_configuration_create_ (system, cfg, NULL, NULL);
1145} 1150}
1146 1151
1147 1152
@@ -1159,11 +1164,11 @@ GNUNET_TESTING_configuration_create(struct GNUNET_TESTING_System *system,
1159 * @return handle to the peer, NULL on error 1164 * @return handle to the peer, NULL on error
1160 */ 1165 */
1161struct GNUNET_TESTING_Peer * 1166struct GNUNET_TESTING_Peer *
1162GNUNET_TESTING_peer_configure(struct GNUNET_TESTING_System *system, 1167GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1163 struct GNUNET_CONFIGURATION_Handle *cfg, 1168 struct GNUNET_CONFIGURATION_Handle *cfg,
1164 uint32_t key_number, 1169 uint32_t key_number,
1165 struct GNUNET_PeerIdentity *id, 1170 struct GNUNET_PeerIdentity *id,
1166 char **emsg) 1171 char **emsg)
1167{ 1172{
1168 struct GNUNET_TESTING_Peer *peer; 1173 struct GNUNET_TESTING_Peer *peer;
1169 struct GNUNET_DISK_FileHandle *fd; 1174 struct GNUNET_DISK_FileHandle *fd;
@@ -1184,141 +1189,141 @@ GNUNET_TESTING_peer_configure(struct GNUNET_TESTING_System *system,
1184 if (NULL != emsg) 1189 if (NULL != emsg)
1185 *emsg = NULL; 1190 *emsg = NULL;
1186 if (key_number >= system->total_hostkeys) 1191 if (key_number >= system->total_hostkeys)
1187 { 1192 {
1188 GNUNET_asprintf( 1193 GNUNET_asprintf (
1189 &emsg_, 1194 &emsg_,
1190 _( 1195 _ (
1191 "You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"), 1196 "You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"),
1192 (unsigned int)system->total_hostkeys); 1197 (unsigned int) system->total_hostkeys);
1193 goto err_ret; 1198 goto err_ret;
1194 } 1199 }
1195 pk = NULL; 1200 pk = NULL;
1196 if ((NULL != id) && 1201 if ((NULL != id) &&
1197 (NULL == (pk = GNUNET_TESTING_hostkey_get(system, key_number, id)))) 1202 (NULL == (pk = GNUNET_TESTING_hostkey_get (system, key_number, id))))
1198 { 1203 {
1199 GNUNET_asprintf(&emsg_, 1204 GNUNET_asprintf (&emsg_,
1200 _("Failed to initialize hostkey for peer %u\n"), 1205 _ ("Failed to initialize hostkey for peer %u\n"),
1201 (unsigned int)key_number); 1206 (unsigned int) key_number);
1202 goto err_ret; 1207 goto err_ret;
1203 } 1208 }
1204 if (NULL != pk) 1209 if (NULL != pk)
1205 GNUNET_free(pk); 1210 GNUNET_free (pk);
1206 if (GNUNET_NO == GNUNET_CONFIGURATION_have_value(cfg, "PEER", "PRIVATE_KEY")) 1211 if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg, "PEER", "PRIVATE_KEY"))
1207 { 1212 {
1208 GNUNET_asprintf( 1213 GNUNET_asprintf (
1209 &emsg_, 1214 &emsg_,
1210 _("PRIVATE_KEY option in PEER section missing in configuration\n")); 1215 _ ("PRIVATE_KEY option in PEER section missing in configuration\n"));
1211 goto err_ret; 1216 goto err_ret;
1212 } 1217 }
1213 /* Remove sections for shared services */ 1218 /* Remove sections for shared services */
1214 for (cnt = 0; cnt < system->n_shared_services; cnt++) 1219 for (cnt = 0; cnt < system->n_shared_services; cnt++)
1215 { 1220 {
1216 ss = system->shared_services[cnt]; 1221 ss = system->shared_services[cnt];
1217 GNUNET_CONFIGURATION_remove_section(cfg, ss->sname); 1222 GNUNET_CONFIGURATION_remove_section (cfg, ss->sname);
1218 } 1223 }
1219 if (GNUNET_OK != 1224 if (GNUNET_OK !=
1220 GNUNET_TESTING_configuration_create_(system, cfg, &ports, &nports)) 1225 GNUNET_TESTING_configuration_create_ (system, cfg, &ports, &nports))
1221 { 1226 {
1222 GNUNET_asprintf(&emsg_, 1227 GNUNET_asprintf (&emsg_,
1223 _("Failed to create configuration for peer " 1228 _ ("Failed to create configuration for peer "
1224 "(not enough free ports?)\n")); 1229 "(not enough free ports?)\n"));
1225 goto err_ret; 1230 goto err_ret;
1226 } 1231 }
1227 GNUNET_assert(GNUNET_OK == 1232 GNUNET_assert (GNUNET_OK ==
1228 GNUNET_CONFIGURATION_get_value_filename(cfg, 1233 GNUNET_CONFIGURATION_get_value_filename (cfg,
1229 "PEER", 1234 "PEER",
1230 "PRIVATE_KEY", 1235 "PRIVATE_KEY",
1231 &hostkey_filename)); 1236 &hostkey_filename));
1232 fd = GNUNET_DISK_file_open(hostkey_filename, 1237 fd = GNUNET_DISK_file_open (hostkey_filename,
1233 GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_WRITE, 1238 GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_WRITE,
1234 GNUNET_DISK_PERM_USER_READ | 1239 GNUNET_DISK_PERM_USER_READ
1235 GNUNET_DISK_PERM_USER_WRITE); 1240 | GNUNET_DISK_PERM_USER_WRITE);
1236 if (NULL == fd) 1241 if (NULL == fd)
1237 { 1242 {
1238 GNUNET_asprintf(&emsg_, 1243 GNUNET_asprintf (&emsg_,
1239 _("Cannot open hostkey file `%s': %s\n"), 1244 _ ("Cannot open hostkey file `%s': %s\n"),
1240 hostkey_filename, 1245 hostkey_filename,
1241 strerror(errno)); 1246 strerror (errno));
1242 GNUNET_free(hostkey_filename); 1247 GNUNET_free (hostkey_filename);
1243 goto err_ret; 1248 goto err_ret;
1244 } 1249 }
1245 GNUNET_free(hostkey_filename); 1250 GNUNET_free (hostkey_filename);
1246 if (GNUNET_TESTING_HOSTKEYFILESIZE != 1251 if (GNUNET_TESTING_HOSTKEYFILESIZE !=
1247 GNUNET_DISK_file_write(fd, 1252 GNUNET_DISK_file_write (fd,
1248 system->hostkeys_data + 1253 system->hostkeys_data
1249 (key_number * GNUNET_TESTING_HOSTKEYFILESIZE), 1254 + (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
1250 GNUNET_TESTING_HOSTKEYFILESIZE)) 1255 GNUNET_TESTING_HOSTKEYFILESIZE))
1251 { 1256 {
1252 GNUNET_asprintf(&emsg_, 1257 GNUNET_asprintf (&emsg_,
1253 _("Failed to write hostkey file for peer %u: %s\n"), 1258 _ ("Failed to write hostkey file for peer %u: %s\n"),
1254 (unsigned int)key_number, 1259 (unsigned int) key_number,
1255 strerror(errno)); 1260 strerror (errno));
1256 GNUNET_DISK_file_close(fd); 1261 GNUNET_DISK_file_close (fd);
1257 goto err_ret; 1262 goto err_ret;
1258 } 1263 }
1259 GNUNET_DISK_file_close(fd); 1264 GNUNET_DISK_file_close (fd);
1260 ss_instances = GNUNET_malloc(sizeof(struct SharedServiceInstance *) * 1265 ss_instances = GNUNET_malloc (sizeof(struct SharedServiceInstance *)
1261 system->n_shared_services); 1266 * system->n_shared_services);
1262 for (cnt = 0; cnt < system->n_shared_services; cnt++) 1267 for (cnt = 0; cnt < system->n_shared_services; cnt++)
1268 {
1269 ss = system->shared_services[cnt];
1270 ss_instances[cnt] = associate_shared_service (system, ss, cfg);
1271 if (NULL == ss_instances[cnt])
1263 { 1272 {
1264 ss = system->shared_services[cnt]; 1273 emsg_ = GNUNET_strdup ("FIXME");
1265 ss_instances[cnt] = associate_shared_service(system, ss, cfg);
1266 if (NULL == ss_instances[cnt])
1267 {
1268 emsg_ = GNUNET_strdup("FIXME");
1269 goto err_ret;
1270 }
1271 }
1272 GNUNET_assert(GNUNET_OK ==
1273 GNUNET_CONFIGURATION_get_value_filename(cfg,
1274 "PATHS",
1275 "DEFAULTCONFIG",
1276 &config_filename));
1277 if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg, config_filename))
1278 {
1279 GNUNET_asprintf(&emsg_,
1280 _(
1281 "Failed to write configuration file `%s' for peer %u: %s\n"),
1282 config_filename,
1283 (unsigned int)key_number,
1284 strerror(errno));
1285 GNUNET_free(config_filename);
1286 goto err_ret; 1274 goto err_ret;
1287 } 1275 }
1288 peer = GNUNET_new(struct GNUNET_TESTING_Peer); 1276 }
1277 GNUNET_assert (GNUNET_OK ==
1278 GNUNET_CONFIGURATION_get_value_filename (cfg,
1279 "PATHS",
1280 "DEFAULTCONFIG",
1281 &config_filename));
1282 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config_filename))
1283 {
1284 GNUNET_asprintf (&emsg_,
1285 _ (
1286 "Failed to write configuration file `%s' for peer %u: %s\n"),
1287 config_filename,
1288 (unsigned int) key_number,
1289 strerror (errno));
1290 GNUNET_free (config_filename);
1291 goto err_ret;
1292 }
1293 peer = GNUNET_new (struct GNUNET_TESTING_Peer);
1289 peer->ss_instances = ss_instances; 1294 peer->ss_instances = ss_instances;
1290 peer->cfgfile = config_filename; /* Free in peer_destroy */ 1295 peer->cfgfile = config_filename; /* Free in peer_destroy */
1291 peer->cfg = GNUNET_CONFIGURATION_dup(cfg); 1296 peer->cfg = GNUNET_CONFIGURATION_dup (cfg);
1292 libexec_binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm"); 1297 libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
1293 if (GNUNET_SYSERR == 1298 if (GNUNET_SYSERR ==
1294 GNUNET_CONFIGURATION_get_value_string(cfg, 1299 GNUNET_CONFIGURATION_get_value_string (cfg,
1295 "arm", 1300 "arm",
1296 "PREFIX", 1301 "PREFIX",
1297 &peer->main_binary)) 1302 &peer->main_binary))
1298 { 1303 {
1299 /* No prefix */ 1304 /* No prefix */
1300 GNUNET_asprintf(&peer->main_binary, "%s", libexec_binary); 1305 GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary);
1301 peer->args = GNUNET_strdup(""); 1306 peer->args = GNUNET_strdup ("");
1302 } 1307 }
1303 else 1308 else
1304 { 1309 {
1305 peer->args = GNUNET_strdup(libexec_binary); 1310 peer->args = GNUNET_strdup (libexec_binary);
1306 } 1311 }
1307 peer->system = system; 1312 peer->system = system;
1308 peer->key_number = key_number; 1313 peer->key_number = key_number;
1309 GNUNET_free(libexec_binary); 1314 GNUNET_free (libexec_binary);
1310 peer->ports = ports; /* Free in peer_destroy */ 1315 peer->ports = ports; /* Free in peer_destroy */
1311 peer->nports = nports; 1316 peer->nports = nports;
1312 return peer; 1317 return peer;
1313 1318
1314err_ret: 1319err_ret:
1315 GNUNET_free_non_null(ss_instances); 1320 GNUNET_free_non_null (ss_instances);
1316 GNUNET_free_non_null(ports); 1321 GNUNET_free_non_null (ports);
1317 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s", emsg_); 1322 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_);
1318 if (NULL != emsg) 1323 if (NULL != emsg)
1319 *emsg = emsg_; 1324 *emsg = emsg_;
1320 else 1325 else
1321 GNUNET_free(emsg_); 1326 GNUNET_free (emsg_);
1322 return NULL; 1327 return NULL;
1323} 1328}
1324 1329
@@ -1330,18 +1335,18 @@ err_ret:
1330 * @param id identifier for the daemon, will be set 1335 * @param id identifier for the daemon, will be set
1331 */ 1336 */
1332void 1337void
1333GNUNET_TESTING_peer_get_identity(struct GNUNET_TESTING_Peer *peer, 1338GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer,
1334 struct GNUNET_PeerIdentity *id) 1339 struct GNUNET_PeerIdentity *id)
1335{ 1340{
1336 if (NULL != peer->id) 1341 if (NULL != peer->id)
1337 { 1342 {
1338 GNUNET_memcpy(id, peer->id, sizeof(struct GNUNET_PeerIdentity)); 1343 GNUNET_memcpy (id, peer->id, sizeof(struct GNUNET_PeerIdentity));
1339 return; 1344 return;
1340 } 1345 }
1341 peer->id = GNUNET_new(struct GNUNET_PeerIdentity); 1346 peer->id = GNUNET_new (struct GNUNET_PeerIdentity);
1342 GNUNET_free( 1347 GNUNET_free (
1343 GNUNET_TESTING_hostkey_get(peer->system, peer->key_number, peer->id)); 1348 GNUNET_TESTING_hostkey_get (peer->system, peer->key_number, peer->id));
1344 GNUNET_memcpy(id, peer->id, sizeof(struct GNUNET_PeerIdentity)); 1349 GNUNET_memcpy (id, peer->id, sizeof(struct GNUNET_PeerIdentity));
1345} 1350}
1346 1351
1347 1352
@@ -1352,44 +1357,44 @@ GNUNET_TESTING_peer_get_identity(struct GNUNET_TESTING_Peer *peer,
1352 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error (i.e. peer already running) 1357 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error (i.e. peer already running)
1353 */ 1358 */
1354int 1359int
1355GNUNET_TESTING_peer_start(struct GNUNET_TESTING_Peer *peer) 1360GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer)
1356{ 1361{
1357 struct SharedServiceInstance *i; 1362 struct SharedServiceInstance *i;
1358 unsigned int cnt; 1363 unsigned int cnt;
1359 1364
1360 if (NULL != peer->main_process) 1365 if (NULL != peer->main_process)
1361 { 1366 {
1362 GNUNET_break(0); 1367 GNUNET_break (0);
1363 return GNUNET_SYSERR; 1368 return GNUNET_SYSERR;
1364 } 1369 }
1365 GNUNET_assert(NULL != peer->cfgfile); 1370 GNUNET_assert (NULL != peer->cfgfile);
1366 for (cnt = 0; cnt < peer->system->n_shared_services; cnt++) 1371 for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1367 { 1372 {
1368 i = peer->ss_instances[cnt]; 1373 i = peer->ss_instances[cnt];
1369 if ((0 == i->n_refs) && 1374 if ((0 == i->n_refs) &&
1370 (GNUNET_SYSERR == start_shared_service_instance(i))) 1375 (GNUNET_SYSERR == start_shared_service_instance (i)))
1371 return GNUNET_SYSERR; 1376 return GNUNET_SYSERR;
1372 i->n_refs++; 1377 i->n_refs++;
1373 } 1378 }
1374 peer->main_binary = 1379 peer->main_binary =
1375 GNUNET_CONFIGURATION_expand_dollar(peer->cfg, peer->main_binary); 1380 GNUNET_CONFIGURATION_expand_dollar (peer->cfg, peer->main_binary);
1376 peer->main_process = 1381 peer->main_process =
1377 GNUNET_OS_start_process_s(PIPE_CONTROL, 1382 GNUNET_OS_start_process_s (PIPE_CONTROL,
1378 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 1383 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
1379 NULL, 1384 NULL,
1380 peer->main_binary, 1385 peer->main_binary,
1381 peer->args, 1386 peer->args,
1382 "-c", 1387 "-c",
1383 peer->cfgfile, 1388 peer->cfgfile,
1384 NULL); 1389 NULL);
1385 if (NULL == peer->main_process) 1390 if (NULL == peer->main_process)
1386 { 1391 {
1387 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1392 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1388 _("Failed to start `%s': %s\n"), 1393 _ ("Failed to start `%s': %s\n"),
1389 peer->main_binary, 1394 peer->main_binary,
1390 strerror(errno)); 1395 strerror (errno));
1391 return GNUNET_SYSERR; 1396 return GNUNET_SYSERR;
1392 } 1397 }
1393 return GNUNET_OK; 1398 return GNUNET_OK;
1394} 1399}
1395 1400
@@ -1402,26 +1407,26 @@ GNUNET_TESTING_peer_start(struct GNUNET_TESTING_Peer *peer)
1402 * or upon any error while sending SIGTERM 1407 * or upon any error while sending SIGTERM
1403 */ 1408 */
1404int 1409int
1405GNUNET_TESTING_peer_kill(struct GNUNET_TESTING_Peer *peer) 1410GNUNET_TESTING_peer_kill (struct GNUNET_TESTING_Peer *peer)
1406{ 1411{
1407 struct SharedServiceInstance *i; 1412 struct SharedServiceInstance *i;
1408 unsigned int cnt; 1413 unsigned int cnt;
1409 1414
1410 if (NULL == peer->main_process) 1415 if (NULL == peer->main_process)
1411 { 1416 {
1412 GNUNET_break(0); 1417 GNUNET_break (0);
1413 return GNUNET_SYSERR; 1418 return GNUNET_SYSERR;
1414 } 1419 }
1415 if (0 != GNUNET_OS_process_kill(peer->main_process, GNUNET_TERM_SIG)) 1420 if (0 != GNUNET_OS_process_kill (peer->main_process, GNUNET_TERM_SIG))
1416 return GNUNET_SYSERR; 1421 return GNUNET_SYSERR;
1417 for (cnt = 0; cnt < peer->system->n_shared_services; cnt++) 1422 for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1418 { 1423 {
1419 i = peer->ss_instances[cnt]; 1424 i = peer->ss_instances[cnt];
1420 GNUNET_assert(0 != i->n_refs); 1425 GNUNET_assert (0 != i->n_refs);
1421 i->n_refs--; 1426 i->n_refs--;
1422 if (0 == i->n_refs) 1427 if (0 == i->n_refs)
1423 stop_shared_service_instance(i); 1428 stop_shared_service_instance (i);
1424 } 1429 }
1425 return GNUNET_OK; 1430 return GNUNET_OK;
1426} 1431}
1427 1432
@@ -1434,17 +1439,17 @@ GNUNET_TESTING_peer_kill(struct GNUNET_TESTING_Peer *peer)
1434 * or upon any error while waiting 1439 * or upon any error while waiting
1435 */ 1440 */
1436int 1441int
1437GNUNET_TESTING_peer_wait(struct GNUNET_TESTING_Peer *peer) 1442GNUNET_TESTING_peer_wait (struct GNUNET_TESTING_Peer *peer)
1438{ 1443{
1439 int ret; 1444 int ret;
1440 1445
1441 if (NULL == peer->main_process) 1446 if (NULL == peer->main_process)
1442 { 1447 {
1443 GNUNET_break(0); 1448 GNUNET_break (0);
1444 return GNUNET_SYSERR; 1449 return GNUNET_SYSERR;
1445 } 1450 }
1446 ret = GNUNET_OS_process_wait(peer->main_process); 1451 ret = GNUNET_OS_process_wait (peer->main_process);
1447 GNUNET_OS_process_destroy(peer->main_process); 1452 GNUNET_OS_process_destroy (peer->main_process);
1448 peer->main_process = NULL; 1453 peer->main_process = NULL;
1449 return ret; 1454 return ret;
1450} 1455}
@@ -1457,11 +1462,11 @@ GNUNET_TESTING_peer_wait(struct GNUNET_TESTING_Peer *peer)
1457 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 1462 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1458 */ 1463 */
1459int 1464int
1460GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer) 1465GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer)
1461{ 1466{
1462 if (GNUNET_SYSERR == GNUNET_TESTING_peer_kill(peer)) 1467 if (GNUNET_SYSERR == GNUNET_TESTING_peer_kill (peer))
1463 return GNUNET_SYSERR; 1468 return GNUNET_SYSERR;
1464 if (GNUNET_SYSERR == GNUNET_TESTING_peer_wait(peer)) 1469 if (GNUNET_SYSERR == GNUNET_TESTING_peer_wait (peer))
1465 return GNUNET_SYSERR; 1470 return GNUNET_SYSERR;
1466 return GNUNET_OK; 1471 return GNUNET_OK;
1467} 1472}
@@ -1475,24 +1480,24 @@ GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer)
1475 * #GNUNET_SYSERR on error. 1480 * #GNUNET_SYSERR on error.
1476 */ 1481 */
1477static void 1482static void
1478disconn_status(void *cls, int connected) 1483disconn_status (void *cls, int connected)
1479{ 1484{
1480 struct GNUNET_TESTING_Peer *peer = cls; 1485 struct GNUNET_TESTING_Peer *peer = cls;
1481 1486
1482 if (GNUNET_SYSERR == connected) 1487 if (GNUNET_SYSERR == connected)
1483 { 1488 {
1484 peer->cb(peer->cb_cls, peer, connected); 1489 peer->cb (peer->cb_cls, peer, connected);
1485 return; 1490 return;
1486 } 1491 }
1487 if (GNUNET_YES == connected) 1492 if (GNUNET_YES == connected)
1488 { 1493 {
1489 GNUNET_break(GNUNET_OK == GNUNET_TESTING_peer_kill(peer)); 1494 GNUNET_break (GNUNET_OK == GNUNET_TESTING_peer_kill (peer));
1490 return; 1495 return;
1491 } 1496 }
1492 GNUNET_break(GNUNET_OK == GNUNET_TESTING_peer_wait(peer)); 1497 GNUNET_break (GNUNET_OK == GNUNET_TESTING_peer_wait (peer));
1493 GNUNET_ARM_disconnect(peer->ah); 1498 GNUNET_ARM_disconnect (peer->ah);
1494 peer->ah = NULL; 1499 peer->ah = NULL;
1495 peer->cb(peer->cb_cls, peer, GNUNET_YES); 1500 peer->cb (peer->cb_cls, peer, GNUNET_YES);
1496} 1501}
1497 1502
1498 1503
@@ -1508,13 +1513,13 @@ disconn_status(void *cls, int connected)
1508 * upon any error. 1513 * upon any error.
1509 */ 1514 */
1510int 1515int
1511GNUNET_TESTING_peer_stop_async(struct GNUNET_TESTING_Peer *peer, 1516GNUNET_TESTING_peer_stop_async (struct GNUNET_TESTING_Peer *peer,
1512 GNUNET_TESTING_PeerStopCallback cb, 1517 GNUNET_TESTING_PeerStopCallback cb,
1513 void *cb_cls) 1518 void *cb_cls)
1514{ 1519{
1515 if (NULL == peer->main_process) 1520 if (NULL == peer->main_process)
1516 return GNUNET_SYSERR; 1521 return GNUNET_SYSERR;
1517 peer->ah = GNUNET_ARM_connect(peer->cfg, &disconn_status, peer); 1522 peer->ah = GNUNET_ARM_connect (peer->cfg, &disconn_status, peer);
1518 if (NULL == peer->ah) 1523 if (NULL == peer->ah)
1519 return GNUNET_SYSERR; 1524 return GNUNET_SYSERR;
1520 peer->cb = cb; 1525 peer->cb = cb;
@@ -1533,10 +1538,10 @@ GNUNET_TESTING_peer_stop_async(struct GNUNET_TESTING_Peer *peer,
1533 * before. 1538 * before.
1534 */ 1539 */
1535void 1540void
1536GNUNET_TESTING_peer_stop_async_cancel(struct GNUNET_TESTING_Peer *peer) 1541GNUNET_TESTING_peer_stop_async_cancel (struct GNUNET_TESTING_Peer *peer)
1537{ 1542{
1538 GNUNET_assert(NULL != peer->ah); 1543 GNUNET_assert (NULL != peer->ah);
1539 GNUNET_ARM_disconnect(peer->ah); 1544 GNUNET_ARM_disconnect (peer->ah);
1540 peer->ah = NULL; 1545 peer->ah = NULL;
1541} 1546}
1542 1547
@@ -1549,28 +1554,28 @@ GNUNET_TESTING_peer_stop_async_cancel(struct GNUNET_TESTING_Peer *peer)
1549 * @param peer peer to destroy 1554 * @param peer peer to destroy
1550 */ 1555 */
1551void 1556void
1552GNUNET_TESTING_peer_destroy(struct GNUNET_TESTING_Peer *peer) 1557GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer)
1553{ 1558{
1554 unsigned int cnt; 1559 unsigned int cnt;
1555 1560
1556 if (NULL != peer->main_process) 1561 if (NULL != peer->main_process)
1557 GNUNET_TESTING_peer_stop(peer); 1562 GNUNET_TESTING_peer_stop (peer);
1558 if (NULL != peer->ah) 1563 if (NULL != peer->ah)
1559 GNUNET_ARM_disconnect(peer->ah); 1564 GNUNET_ARM_disconnect (peer->ah);
1560 GNUNET_free(peer->cfgfile); 1565 GNUNET_free (peer->cfgfile);
1561 if (NULL != peer->cfg) 1566 if (NULL != peer->cfg)
1562 GNUNET_CONFIGURATION_destroy(peer->cfg); 1567 GNUNET_CONFIGURATION_destroy (peer->cfg);
1563 GNUNET_free(peer->main_binary); 1568 GNUNET_free (peer->main_binary);
1564 GNUNET_free(peer->args); 1569 GNUNET_free (peer->args);
1565 GNUNET_free_non_null(peer->id); 1570 GNUNET_free_non_null (peer->id);
1566 GNUNET_free_non_null(peer->ss_instances); 1571 GNUNET_free_non_null (peer->ss_instances);
1567 if (NULL != peer->ports) 1572 if (NULL != peer->ports)
1568 { 1573 {
1569 for (cnt = 0; cnt < peer->nports; cnt++) 1574 for (cnt = 0; cnt < peer->nports; cnt++)
1570 GNUNET_TESTING_release_port(peer->system, peer->ports[cnt]); 1575 GNUNET_TESTING_release_port (peer->system, peer->ports[cnt]);
1571 GNUNET_free(peer->ports); 1576 GNUNET_free (peer->ports);
1572 } 1577 }
1573 GNUNET_free(peer); 1578 GNUNET_free (peer);
1574} 1579}
1575 1580
1576 1581
@@ -1591,19 +1596,20 @@ GNUNET_TESTING_peer_destroy(struct GNUNET_TESTING_Peer *peer)
1591 * @return 0 on success, 1 on error 1596 * @return 0 on success, 1 on error
1592 */ 1597 */
1593int 1598int
1594GNUNET_TESTING_peer_run(const char *testdir, 1599GNUNET_TESTING_peer_run (const char *testdir,
1595 const char *cfgfilename, 1600 const char *cfgfilename,
1596 GNUNET_TESTING_TestMain tm, 1601 GNUNET_TESTING_TestMain tm,
1597 void *tm_cls) 1602 void *tm_cls)
1598{ 1603{
1599 return GNUNET_TESTING_service_run(testdir, "arm", cfgfilename, tm, tm_cls); 1604 return GNUNET_TESTING_service_run (testdir, "arm", cfgfilename, tm, tm_cls);
1600} 1605}
1601 1606
1602 1607
1603/** 1608/**
1604 * Structure for holding service data 1609 * Structure for holding service data
1605 */ 1610 */
1606struct ServiceContext { 1611struct ServiceContext
1612{
1607 /** 1613 /**
1608 * The configuration of the peer in which the service is run 1614 * The configuration of the peer in which the service is run
1609 */ 1615 */
@@ -1632,11 +1638,11 @@ struct ServiceContext {
1632 * @param cls the ServiceContext 1638 * @param cls the ServiceContext
1633 */ 1639 */
1634static void 1640static void
1635service_run_main(void *cls) 1641service_run_main (void *cls)
1636{ 1642{
1637 struct ServiceContext *sc = cls; 1643 struct ServiceContext *sc = cls;
1638 1644
1639 sc->tm(sc->tm_cls, sc->cfg, sc->peer); 1645 sc->tm (sc->tm_cls, sc->cfg, sc->peer);
1640} 1646}
1641 1647
1642 1648
@@ -1662,11 +1668,11 @@ service_run_main(void *cls)
1662 * @return 0 on success, 1 on error 1668 * @return 0 on success, 1 on error
1663 */ 1669 */
1664int 1670int
1665GNUNET_TESTING_service_run(const char *testdir, 1671GNUNET_TESTING_service_run (const char *testdir,
1666 const char *service_name, 1672 const char *service_name,
1667 const char *cfgfilename, 1673 const char *cfgfilename,
1668 GNUNET_TESTING_TestMain tm, 1674 GNUNET_TESTING_TestMain tm,
1669 void *tm_cls) 1675 void *tm_cls)
1670{ 1676{
1671 struct ServiceContext sc; 1677 struct ServiceContext sc;
1672 struct GNUNET_TESTING_System *system; 1678 struct GNUNET_TESTING_System *system;
@@ -1675,70 +1681,70 @@ GNUNET_TESTING_service_run(const char *testdir,
1675 char *binary; 1681 char *binary;
1676 char *libexec_binary; 1682 char *libexec_binary;
1677 1683
1678 GNUNET_log_setup(testdir, "WARNING", NULL); 1684 GNUNET_log_setup (testdir, "WARNING", NULL);
1679 system = GNUNET_TESTING_system_create(testdir, "127.0.0.1", NULL, NULL); 1685 system = GNUNET_TESTING_system_create (testdir, "127.0.0.1", NULL, NULL);
1680 if (NULL == system) 1686 if (NULL == system)
1681 return 1; 1687 return 1;
1682 cfg = GNUNET_CONFIGURATION_create(); 1688 cfg = GNUNET_CONFIGURATION_create ();
1683 if (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg, cfgfilename)) 1689 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgfilename))
1684 { 1690 {
1685 LOG(GNUNET_ERROR_TYPE_ERROR, 1691 LOG (GNUNET_ERROR_TYPE_ERROR,
1686 _("Failed to load configuration from %s\n"), 1692 _ ("Failed to load configuration from %s\n"),
1687 cfgfilename); 1693 cfgfilename);
1688 GNUNET_CONFIGURATION_destroy(cfg); 1694 GNUNET_CONFIGURATION_destroy (cfg);
1689 GNUNET_TESTING_system_destroy(system, GNUNET_YES); 1695 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
1690 return 1; 1696 return 1;
1691 } 1697 }
1692 peer = GNUNET_TESTING_peer_configure(system, cfg, 0, NULL, NULL); 1698 peer = GNUNET_TESTING_peer_configure (system, cfg, 0, NULL, NULL);
1693 if (NULL == peer) 1699 if (NULL == peer)
1694 { 1700 {
1695 GNUNET_CONFIGURATION_destroy(cfg); 1701 GNUNET_CONFIGURATION_destroy (cfg);
1696 hostkeys_unload(system); 1702 hostkeys_unload (system);
1697 GNUNET_TESTING_system_destroy(system, GNUNET_YES); 1703 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
1698 return 1; 1704 return 1;
1699 } 1705 }
1700 GNUNET_free(peer->main_binary); 1706 GNUNET_free (peer->main_binary);
1701 GNUNET_free(peer->args); 1707 GNUNET_free (peer->args);
1702 GNUNET_asprintf(&binary, "gnunet-service-%s", service_name); 1708 GNUNET_asprintf (&binary, "gnunet-service-%s", service_name);
1703 libexec_binary = GNUNET_OS_get_libexec_binary_path(binary); 1709 libexec_binary = GNUNET_OS_get_libexec_binary_path (binary);
1704 if (GNUNET_SYSERR == 1710 if (GNUNET_SYSERR ==
1705 GNUNET_CONFIGURATION_get_value_string(cfg, 1711 GNUNET_CONFIGURATION_get_value_string (cfg,
1706 service_name, 1712 service_name,
1707 "PREFIX", 1713 "PREFIX",
1708 &peer->main_binary)) 1714 &peer->main_binary))
1709 { 1715 {
1710 /* No prefix */ 1716 /* No prefix */
1711 GNUNET_asprintf(&peer->main_binary, "%s", libexec_binary); 1717 GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary);
1712 peer->args = GNUNET_strdup(""); 1718 peer->args = GNUNET_strdup ("");
1713 } 1719 }
1714 else 1720 else
1715 peer->args = GNUNET_strdup(libexec_binary); 1721 peer->args = GNUNET_strdup (libexec_binary);
1716 1722
1717 GNUNET_free(libexec_binary); 1723 GNUNET_free (libexec_binary);
1718 GNUNET_free(binary); 1724 GNUNET_free (binary);
1719 if (GNUNET_OK != GNUNET_TESTING_peer_start(peer)) 1725 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer))
1720 { 1726 {
1721 GNUNET_TESTING_peer_destroy(peer); 1727 GNUNET_TESTING_peer_destroy (peer);
1722 GNUNET_CONFIGURATION_destroy(cfg); 1728 GNUNET_CONFIGURATION_destroy (cfg);
1723 GNUNET_TESTING_system_destroy(system, GNUNET_YES); 1729 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
1724 return 1; 1730 return 1;
1725 } 1731 }
1726 sc.cfg = cfg; 1732 sc.cfg = cfg;
1727 sc.tm = tm; 1733 sc.tm = tm;
1728 sc.tm_cls = tm_cls; 1734 sc.tm_cls = tm_cls;
1729 sc.peer = peer; 1735 sc.peer = peer;
1730 GNUNET_SCHEDULER_run(&service_run_main, &sc); /* Scheduler loop */ 1736 GNUNET_SCHEDULER_run (&service_run_main, &sc); /* Scheduler loop */
1731 if ((NULL != peer->main_process) && 1737 if ((NULL != peer->main_process) &&
1732 (GNUNET_OK != GNUNET_TESTING_peer_stop(peer))) 1738 (GNUNET_OK != GNUNET_TESTING_peer_stop (peer)))
1733 { 1739 {
1734 GNUNET_TESTING_peer_destroy(peer); 1740 GNUNET_TESTING_peer_destroy (peer);
1735 GNUNET_CONFIGURATION_destroy(cfg); 1741 GNUNET_CONFIGURATION_destroy (cfg);
1736 GNUNET_TESTING_system_destroy(system, GNUNET_YES); 1742 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
1737 return 1; 1743 return 1;
1738 } 1744 }
1739 GNUNET_TESTING_peer_destroy(peer); 1745 GNUNET_TESTING_peer_destroy (peer);
1740 GNUNET_CONFIGURATION_destroy(cfg); 1746 GNUNET_CONFIGURATION_destroy (cfg);
1741 GNUNET_TESTING_system_destroy(system, GNUNET_YES); 1747 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
1742 return 0; 1748 return 0;
1743} 1749}
1744 1750
@@ -1757,22 +1763,22 @@ GNUNET_TESTING_service_run(const char *testdir,
1757 * NULL if argv0 has no '_' 1763 * NULL if argv0 has no '_'
1758 */ 1764 */
1759char * 1765char *
1760GNUNET_TESTING_get_testname_from_underscore(const char *argv0) 1766GNUNET_TESTING_get_testname_from_underscore (const char *argv0)
1761{ 1767{
1762 size_t slen = strlen(argv0) + 1; 1768 size_t slen = strlen (argv0) + 1;
1763 char sbuf[slen]; 1769 char sbuf[slen];
1764 char *ret; 1770 char *ret;
1765 char *dot; 1771 char *dot;
1766 1772
1767 GNUNET_memcpy(sbuf, argv0, slen); 1773 GNUNET_memcpy (sbuf, argv0, slen);
1768 ret = strrchr(sbuf, '_'); 1774 ret = strrchr (sbuf, '_');
1769 if (NULL == ret) 1775 if (NULL == ret)
1770 return NULL; 1776 return NULL;
1771 ret++; /* skip underscore */ 1777 ret++; /* skip underscore */
1772 dot = strchr(ret, '.'); 1778 dot = strchr (ret, '.');
1773 if (NULL != dot) 1779 if (NULL != dot)
1774 *dot = '\0'; 1780 *dot = '\0';
1775 return GNUNET_strdup(ret); 1781 return GNUNET_strdup (ret);
1776} 1782}
1777 1783
1778 1784