summaryrefslogtreecommitdiff
path: root/src/testing/testing.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing.c')
-rw-r--r--src/testing/testing.c1462
1 files changed, 734 insertions, 728 deletions
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