diff options
author | ng0 <ng0@n0.is> | 2019-09-06 22:46:29 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-06 22:46:29 +0000 |
commit | 6e599264ad13e8fc105493d74d7c11d46f8739ed (patch) | |
tree | 169bef1ecbade5a659831fb169f3ae6943af127f /src/testing/testing.c | |
parent | 4f13bc15113021ebf71d5d81e99bc29f8a07fc9c (diff) | |
download | gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.tar.gz gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.zip |
first step to remove plibc
Diffstat (limited to 'src/testing/testing.c')
-rw-r--r-- | src/testing/testing.c | 450 |
1 files changed, 251 insertions, 199 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c index 7dbd97294..c5c240b37 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -34,8 +34,7 @@ | |||
34 | #include "gnunet_arm_service.h" | 34 | #include "gnunet_arm_service.h" |
35 | #include "gnunet_testing_lib.h" | 35 | #include "gnunet_testing_lib.h" |
36 | 36 | ||
37 | #define LOG(kind,...) \ | 37 | #define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__) |
38 | GNUNET_log_from (kind, "testing-api", __VA_ARGS__) | ||
39 | 38 | ||
40 | 39 | ||
41 | /** | 40 | /** |
@@ -269,7 +268,8 @@ hostkeys_load (struct GNUNET_TESTING_System *system) | |||
269 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) | 268 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) |
270 | { | 269 | { |
271 | LOG (GNUNET_ERROR_TYPE_ERROR, | 270 | LOG (GNUNET_ERROR_TYPE_ERROR, |
272 | _("Hostkeys file not found: %s\n"), filename); | 271 | _ ("Hostkeys file not found: %s\n"), |
272 | filename); | ||
273 | GNUNET_free (filename); | 273 | GNUNET_free (filename); |
274 | return GNUNET_SYSERR; | 274 | return GNUNET_SYSERR; |
275 | } | 275 | } |
@@ -280,17 +280,19 @@ hostkeys_load (struct GNUNET_TESTING_System *system) | |||
280 | if (0 == fs) | 280 | if (0 == fs) |
281 | { | 281 | { |
282 | GNUNET_free (filename); | 282 | GNUNET_free (filename); |
283 | return GNUNET_SYSERR; /* File is empty */ | 283 | return GNUNET_SYSERR; /* File is empty */ |
284 | } | 284 | } |
285 | if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE)) | 285 | if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE)) |
286 | { | 286 | { |
287 | LOG (GNUNET_ERROR_TYPE_ERROR, | 287 | LOG (GNUNET_ERROR_TYPE_ERROR, |
288 | _("Incorrect hostkey file format: %s\n"), filename); | 288 | _ ("Incorrect hostkey file format: %s\n"), |
289 | filename); | ||
289 | GNUNET_free (filename); | 290 | GNUNET_free (filename); |
290 | return GNUNET_SYSERR; | 291 | return GNUNET_SYSERR; |
291 | } | 292 | } |
292 | fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, | 293 | fd = GNUNET_DISK_file_open (filename, |
293 | GNUNET_DISK_PERM_NONE); | 294 | GNUNET_DISK_OPEN_READ, |
295 | GNUNET_DISK_PERM_NONE); | ||
294 | if (NULL == fd) | 296 | if (NULL == fd) |
295 | { | 297 | { |
296 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename); | 298 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename); |
@@ -298,10 +300,8 @@ hostkeys_load (struct GNUNET_TESTING_System *system) | |||
298 | return GNUNET_SYSERR; | 300 | return GNUNET_SYSERR; |
299 | } | 301 | } |
300 | GNUNET_free (filename); | 302 | GNUNET_free (filename); |
301 | system->hostkeys_data = GNUNET_DISK_file_map (fd, | 303 | system->hostkeys_data = |
302 | &system->map, | 304 | GNUNET_DISK_file_map (fd, &system->map, GNUNET_DISK_MAP_TYPE_READ, fs); |
303 | GNUNET_DISK_MAP_TYPE_READ, | ||
304 | fs); | ||
305 | GNUNET_DISK_file_close (fd); | 305 | GNUNET_DISK_file_close (fd); |
306 | if (NULL == system->hostkeys_data) | 306 | if (NULL == system->hostkeys_data) |
307 | return GNUNET_SYSERR; | 307 | return GNUNET_SYSERR; |
@@ -336,8 +336,10 @@ hostkeys_unload (struct GNUNET_TESTING_System *system) | |||
336 | * @param value value of the option | 336 | * @param value value of the option |
337 | */ | 337 | */ |
338 | static void | 338 | static void |
339 | cfg_copy_iterator (void *cls, const char *section, | 339 | cfg_copy_iterator (void *cls, |
340 | const char *option, const char *value) | 340 | const char *section, |
341 | const char *option, | ||
342 | const char *value) | ||
341 | { | 343 | { |
342 | struct GNUNET_CONFIGURATION_Handle *cfg2 = cls; | 344 | struct GNUNET_CONFIGURATION_Handle *cfg2 = cls; |
343 | 345 | ||
@@ -367,14 +369,13 @@ cfg_copy_iterator (void *cls, const char *section, | |||
367 | * @return handle to this system, NULL on error | 369 | * @return handle to this system, NULL on error |
368 | */ | 370 | */ |
369 | struct GNUNET_TESTING_System * | 371 | struct GNUNET_TESTING_System * |
370 | GNUNET_TESTING_system_create_with_portrange (const char *testdir, | 372 | GNUNET_TESTING_system_create_with_portrange ( |
371 | const char *trusted_ip, | 373 | const char *testdir, |
372 | const char *hostname, | 374 | const char *trusted_ip, |
373 | const struct | 375 | const char *hostname, |
374 | GNUNET_TESTING_SharedService * | 376 | const struct GNUNET_TESTING_SharedService *shared_services, |
375 | shared_services, | 377 | uint16_t lowport, |
376 | uint16_t lowport, | 378 | uint16_t highport) |
377 | uint16_t highport) | ||
378 | { | 379 | { |
379 | struct GNUNET_TESTING_System *system; | 380 | struct GNUNET_TESTING_System *system; |
380 | struct GNUNET_TESTING_SharedService tss; | 381 | struct GNUNET_TESTING_SharedService tss; |
@@ -411,14 +412,21 @@ GNUNET_TESTING_system_create_with_portrange (const char *testdir, | |||
411 | ss = GNUNET_new (struct SharedService); | 412 | ss = GNUNET_new (struct SharedService); |
412 | ss->sname = GNUNET_strdup (tss.service); | 413 | ss->sname = GNUNET_strdup (tss.service); |
413 | ss->cfg = GNUNET_CONFIGURATION_create (); | 414 | ss->cfg = GNUNET_CONFIGURATION_create (); |
414 | GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, ss->sname, | 415 | GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, |
415 | &cfg_copy_iterator, ss->cfg); | 416 | ss->sname, |
416 | GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, "TESTING", | 417 | &cfg_copy_iterator, |
417 | &cfg_copy_iterator, ss->cfg); | 418 | ss->cfg); |
418 | GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, "PATHS", | 419 | GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, |
419 | &cfg_copy_iterator, ss->cfg); | 420 | "TESTING", |
421 | &cfg_copy_iterator, | ||
422 | ss->cfg); | ||
423 | GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, | ||
424 | "PATHS", | ||
425 | &cfg_copy_iterator, | ||
426 | ss->cfg); | ||
420 | ss->share = tss.share; | 427 | ss->share = tss.share; |
421 | GNUNET_array_append (system->shared_services, system->n_shared_services, | 428 | GNUNET_array_append (system->shared_services, |
429 | system->n_shared_services, | ||
422 | ss); | 430 | ss); |
423 | } | 431 | } |
424 | return system; | 432 | return system; |
@@ -446,18 +454,18 @@ GNUNET_TESTING_system_create_with_portrange (const char *testdir, | |||
446 | * @return handle to this system, NULL on error | 454 | * @return handle to this system, NULL on error |
447 | */ | 455 | */ |
448 | struct GNUNET_TESTING_System * | 456 | struct GNUNET_TESTING_System * |
449 | GNUNET_TESTING_system_create (const char *testdir, | 457 | GNUNET_TESTING_system_create ( |
450 | const char *trusted_ip, | 458 | const char *testdir, |
451 | const char *hostname, | 459 | const char *trusted_ip, |
452 | const struct GNUNET_TESTING_SharedService * | 460 | const char *hostname, |
453 | shared_services) | 461 | const struct GNUNET_TESTING_SharedService *shared_services) |
454 | { | 462 | { |
455 | return GNUNET_TESTING_system_create_with_portrange (testdir, | 463 | return GNUNET_TESTING_system_create_with_portrange (testdir, |
456 | trusted_ip, | 464 | trusted_ip, |
457 | hostname, | 465 | hostname, |
458 | shared_services, | 466 | shared_services, |
459 | LOW_PORT, | 467 | LOW_PORT, |
460 | HIGH_PORT); | 468 | HIGH_PORT); |
461 | } | 469 | } |
462 | 470 | ||
463 | 471 | ||
@@ -490,7 +498,9 @@ start_shared_service_instance (struct SharedServiceInstance *i) | |||
490 | GNUNET_free (binary); | 498 | GNUNET_free (binary); |
491 | i->proc = GNUNET_OS_start_process (PIPE_CONTROL, | 499 | i->proc = GNUNET_OS_start_process (PIPE_CONTROL, |
492 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 500 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
493 | NULL, NULL, NULL, | 501 | NULL, |
502 | NULL, | ||
503 | NULL, | ||
494 | libexec_binary, | 504 | libexec_binary, |
495 | libexec_binary, | 505 | libexec_binary, |
496 | "-c", | 506 | "-c", |
@@ -509,7 +519,8 @@ stop_shared_service_instance (struct SharedServiceInstance *i) | |||
509 | GNUNET_break (0 == i->n_refs); | 519 | GNUNET_break (0 == i->n_refs); |
510 | if (0 != GNUNET_OS_process_kill (i->proc, GNUNET_TERM_SIG)) | 520 | if (0 != GNUNET_OS_process_kill (i->proc, GNUNET_TERM_SIG)) |
511 | LOG (GNUNET_ERROR_TYPE_WARNING, | 521 | LOG (GNUNET_ERROR_TYPE_WARNING, |
512 | "Killing shared service instance (%s) failed\n", i->ss->sname); | 522 | "Killing shared service instance (%s) failed\n", |
523 | i->ss->sname); | ||
513 | (void) GNUNET_OS_process_wait (i->proc); | 524 | (void) GNUNET_OS_process_wait (i->proc); |
514 | GNUNET_OS_process_destroy (i->proc); | 525 | GNUNET_OS_process_destroy (i->proc); |
515 | i->proc = NULL; | 526 | i->proc = NULL; |
@@ -525,7 +536,7 @@ stop_shared_service_instance (struct SharedServiceInstance *i) | |||
525 | */ | 536 | */ |
526 | void | 537 | void |
527 | GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, | 538 | GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, |
528 | int remove_paths) | 539 | int remove_paths) |
529 | { | 540 | { |
530 | struct SharedService *ss; | 541 | struct SharedService *ss; |
531 | struct SharedServiceInstance *i; | 542 | struct SharedServiceInstance *i; |
@@ -589,19 +600,20 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system) | |||
589 | On system with either IPv4 or IPv6. A port is considered open if it's | 600 | On system with either IPv4 or IPv6. A port is considered open if it's |
590 | open in the respective address family | 601 | open in the respective address family |
591 | */ | 602 | */ |
592 | hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */ | 603 | hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */ |
593 | hint.ai_socktype = 0; | 604 | hint.ai_socktype = 0; |
594 | hint.ai_protocol = 0; | 605 | hint.ai_protocol = 0; |
595 | hint.ai_addrlen = 0; | 606 | hint.ai_addrlen = 0; |
596 | hint.ai_addr = NULL; | 607 | hint.ai_addr = NULL; |
597 | hint.ai_canonname = NULL; | 608 | hint.ai_canonname = NULL; |
598 | hint.ai_next = NULL; | 609 | hint.ai_next = NULL; |
599 | hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */ | 610 | hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */ |
600 | port_buckets = system->reserved_ports; | 611 | port_buckets = system->reserved_ports; |
601 | for (index = (system->lowport / 32) + 1; index < (system->highport / 32); index++) | 612 | for (index = (system->lowport / 32) + 1; index < (system->highport / 32); |
613 | index++) | ||
602 | { | 614 | { |
603 | xor_image = (UINT32_MAX ^ port_buckets[index]); | 615 | xor_image = (UINT32_MAX ^ port_buckets[index]); |
604 | if (0 == xor_image) /* Ports in the bucket are full */ | 616 | if (0 == xor_image) /* Ports in the bucket are full */ |
605 | continue; | 617 | continue; |
606 | pos = system->lowport % 32; | 618 | pos = system->lowport % 32; |
607 | while (pos < 32) | 619 | while (pos < 32) |
@@ -613,7 +625,7 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system) | |||
613 | } | 625 | } |
614 | open_port = (index * 32) + pos; | 626 | open_port = (index * 32) + pos; |
615 | if (open_port >= system->highport) | 627 | if (open_port >= system->highport) |
616 | return 0; | 628 | return 0; |
617 | GNUNET_asprintf (&open_port_str, "%u", (unsigned int) open_port); | 629 | GNUNET_asprintf (&open_port_str, "%u", (unsigned int) open_port); |
618 | ret = NULL; | 630 | ret = NULL; |
619 | GNUNET_assert (0 == getaddrinfo (NULL, open_port_str, &hint, &ret)); | 631 | GNUNET_assert (0 == getaddrinfo (NULL, open_port_str, &hint, &ret)); |
@@ -624,18 +636,16 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system) | |||
624 | socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_STREAM, 0); | 636 | socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_STREAM, 0); |
625 | if (NULL == socket) | 637 | if (NULL == socket) |
626 | continue; | 638 | continue; |
627 | bind_status = GNUNET_NETWORK_socket_bind (socket, | 639 | bind_status = |
628 | ai->ai_addr, | 640 | GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen); |
629 | ai->ai_addrlen); | ||
630 | GNUNET_NETWORK_socket_close (socket); | 641 | GNUNET_NETWORK_socket_close (socket); |
631 | if (GNUNET_OK != bind_status) | 642 | if (GNUNET_OK != bind_status) |
632 | break; | 643 | break; |
633 | socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_DGRAM, 0); | 644 | socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_DGRAM, 0); |
634 | if (NULL == socket) | 645 | if (NULL == socket) |
635 | continue; | 646 | continue; |
636 | bind_status = GNUNET_NETWORK_socket_bind (socket, | 647 | bind_status = |
637 | ai->ai_addr, | 648 | GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen); |
638 | ai->ai_addrlen); | ||
639 | GNUNET_NETWORK_socket_close (socket); | 649 | GNUNET_NETWORK_socket_close (socket); |
640 | if (GNUNET_OK != bind_status) | 650 | if (GNUNET_OK != bind_status) |
641 | break; | 651 | break; |
@@ -645,8 +655,9 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system) | |||
645 | if (GNUNET_OK == bind_status) | 655 | if (GNUNET_OK == bind_status) |
646 | { | 656 | { |
647 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 657 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
648 | "Found a free port %u\n", (unsigned int) open_port); | 658 | "Found a free port %u\n", |
649 | return open_port; | 659 | (unsigned int) open_port); |
660 | return open_port; | ||
650 | } | 661 | } |
651 | pos++; | 662 | pos++; |
652 | } | 663 | } |
@@ -664,7 +675,7 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system) | |||
664 | */ | 675 | */ |
665 | void | 676 | void |
666 | GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system, | 677 | GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system, |
667 | uint16_t port) | 678 | uint16_t port) |
668 | { | 679 | { |
669 | uint32_t *port_buckets; | 680 | uint32_t *port_buckets; |
670 | uint16_t bucket; | 681 | uint16_t bucket; |
@@ -676,7 +687,7 @@ GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system, | |||
676 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port); | 687 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port); |
677 | if (0 == (port_buckets[bucket] & (1U << pos))) | 688 | if (0 == (port_buckets[bucket] & (1U << pos))) |
678 | { | 689 | { |
679 | GNUNET_break(0); /* Port was not reserved by us using reserve_port() */ | 690 | GNUNET_break (0); /* Port was not reserved by us using reserve_port() */ |
680 | return; | 691 | return; |
681 | } | 692 | } |
682 | port_buckets[bucket] &= ~(1U << pos); | 693 | port_buckets[bucket] &= ~(1U << pos); |
@@ -702,8 +713,8 @@ GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system, | |||
702 | */ | 713 | */ |
703 | struct GNUNET_CRYPTO_EddsaPrivateKey * | 714 | struct GNUNET_CRYPTO_EddsaPrivateKey * |
704 | GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system, | 715 | GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system, |
705 | uint32_t key_number, | 716 | uint32_t key_number, |
706 | struct GNUNET_PeerIdentity *id) | 717 | struct GNUNET_PeerIdentity *id) |
707 | { | 718 | { |
708 | struct GNUNET_CRYPTO_EddsaPrivateKey *private_key; | 719 | struct GNUNET_CRYPTO_EddsaPrivateKey *private_key; |
709 | 720 | ||
@@ -712,17 +723,16 @@ GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system, | |||
712 | if (key_number >= system->total_hostkeys) | 723 | if (key_number >= system->total_hostkeys) |
713 | { | 724 | { |
714 | LOG (GNUNET_ERROR_TYPE_ERROR, | 725 | LOG (GNUNET_ERROR_TYPE_ERROR, |
715 | _("Key number %u does not exist\n"), | 726 | _ ("Key number %u does not exist\n"), |
716 | key_number); | 727 | key_number); |
717 | return NULL; | 728 | return NULL; |
718 | } | 729 | } |
719 | private_key = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey); | 730 | private_key = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey); |
720 | GNUNET_memcpy (private_key, | 731 | GNUNET_memcpy (private_key, |
721 | system->hostkeys_data + | 732 | system->hostkeys_data + |
722 | (key_number * GNUNET_TESTING_HOSTKEYFILESIZE), | 733 | (key_number * GNUNET_TESTING_HOSTKEYFILESIZE), |
723 | GNUNET_TESTING_HOSTKEYFILESIZE); | 734 | GNUNET_TESTING_HOSTKEYFILESIZE); |
724 | GNUNET_CRYPTO_eddsa_key_get_public (private_key, | 735 | GNUNET_CRYPTO_eddsa_key_get_public (private_key, &id->public_key); |
725 | &id->public_key); | ||
726 | return private_key; | 736 | return private_key; |
727 | } | 737 | } |
728 | 738 | ||
@@ -794,18 +804,17 @@ update_config (void *cls, | |||
794 | 804 | ||
795 | if (GNUNET_OK != uc->status) | 805 | if (GNUNET_OK != uc->status) |
796 | return; | 806 | return; |
797 | if (! ((0 == strcmp (option, "PORT")) | 807 | if (! ((0 == strcmp (option, "PORT")) || (0 == strcmp (option, "UNIXPATH")) || |
798 | || (0 == strcmp (option, "UNIXPATH")) | 808 | (0 == strcmp (option, "HOSTNAME")))) |
799 | || (0 == strcmp (option, "HOSTNAME")))) | ||
800 | return; | 809 | return; |
801 | GNUNET_asprintf (&single_variable, "single_%s_per_host", section); | 810 | GNUNET_asprintf (&single_variable, "single_%s_per_host", section); |
802 | GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section); | 811 | GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section); |
803 | if ((0 == strcmp (option, "PORT")) && (1 == SSCANF (value, "%u", &ival))) | 812 | if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival))) |
804 | { | 813 | { |
805 | if ((ival != 0) && | 814 | if ((ival != 0) && |
806 | (GNUNET_YES != | 815 | (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, |
807 | GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, "testing", | 816 | "testing", |
808 | single_variable))) | 817 | single_variable))) |
809 | { | 818 | { |
810 | new_port = GNUNET_TESTING_reserve_port (uc->system); | 819 | new_port = GNUNET_TESTING_reserve_port (uc->system); |
811 | if (0 == new_port) | 820 | if (0 == new_port) |
@@ -821,37 +830,41 @@ update_config (void *cls, | |||
821 | } | 830 | } |
822 | else if ((ival != 0) && | 831 | else if ((ival != 0) && |
823 | (GNUNET_YES == | 832 | (GNUNET_YES == |
824 | GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, "testing", | 833 | GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, |
834 | "testing", | ||
825 | single_variable)) && | 835 | single_variable)) && |
826 | GNUNET_CONFIGURATION_get_value_number (uc->cfg, "testing", | 836 | GNUNET_CONFIGURATION_get_value_number (uc->cfg, |
837 | "testing", | ||
827 | per_host_variable, | 838 | per_host_variable, |
828 | &num_per_host)) | 839 | &num_per_host)) |
829 | { | 840 | { |
830 | /* GNUNET_snprintf (cval, sizeof (cval), "%u", */ | 841 | /* GNUNET_snprintf (cval, sizeof (cval), "%u", */ |
831 | /* ival + ctx->fdnum % num_per_host); */ | 842 | /* ival + ctx->fdnum % num_per_host); */ |
832 | /* value = cval; */ | 843 | /* value = cval; */ |
833 | GNUNET_break (0); /* FIXME */ | 844 | GNUNET_break (0); /* FIXME */ |
834 | } | 845 | } |
835 | } | 846 | } |
836 | if (0 == strcmp (option, "UNIXPATH")) | 847 | if (0 == strcmp (option, "UNIXPATH")) |
837 | { | 848 | { |
838 | if (GNUNET_YES != | 849 | if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, |
839 | GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, "testing", | 850 | "testing", |
840 | single_variable)) | 851 | single_variable)) |
841 | { | 852 | { |
842 | GNUNET_snprintf (uval, | 853 | GNUNET_snprintf (uval, |
843 | sizeof (uval), | 854 | sizeof (uval), |
844 | "%s/%s.sock", | 855 | "%s/%s.sock", |
845 | uc->gnunet_home, section); | 856 | uc->gnunet_home, |
857 | section); | ||
846 | value = uval; | 858 | value = uval; |
847 | } | 859 | } |
848 | else if ((GNUNET_YES == | 860 | else if ((GNUNET_YES == |
849 | GNUNET_CONFIGURATION_get_value_number (uc->cfg, "testing", | 861 | GNUNET_CONFIGURATION_get_value_number (uc->cfg, |
862 | "testing", | ||
850 | per_host_variable, | 863 | per_host_variable, |
851 | &num_per_host)) && | 864 | &num_per_host)) && |
852 | (num_per_host > 0)) | 865 | (num_per_host > 0)) |
853 | { | 866 | { |
854 | GNUNET_break(0); /* FIXME */ | 867 | GNUNET_break (0); /* FIXME */ |
855 | } | 868 | } |
856 | } | 869 | } |
857 | if (0 == strcmp (option, "HOSTNAME")) | 870 | if (0 == strcmp (option, "HOSTNAME")) |
@@ -872,8 +885,7 @@ update_config (void *cls, | |||
872 | * @param section name of the section | 885 | * @param section name of the section |
873 | */ | 886 | */ |
874 | static void | 887 | static void |
875 | update_config_sections (void *cls, | 888 | update_config_sections (void *cls, const char *section) |
876 | const char *section) | ||
877 | { | 889 | { |
878 | struct UpdateContext *uc = cls; | 890 | struct UpdateContext *uc = cls; |
879 | char **ikeys; | 891 | char **ikeys; |
@@ -889,13 +901,14 @@ update_config_sections (void *cls, | |||
889 | val = NULL; | 901 | val = NULL; |
890 | /* Ignore certain options from sections. See | 902 | /* Ignore certain options from sections. See |
891 | https://gnunet.org/bugs/view.php?id=2476 */ | 903 | https://gnunet.org/bugs/view.php?id=2476 */ |
892 | if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (uc->cfg, section, | 904 | if (GNUNET_YES == |
893 | "TESTING_IGNORE_KEYS")) | 905 | GNUNET_CONFIGURATION_have_value (uc->cfg, section, "TESTING_IGNORE_KEYS")) |
894 | { | 906 | { |
895 | GNUNET_assert | 907 | GNUNET_assert (GNUNET_YES == |
896 | (GNUNET_YES == | 908 | GNUNET_CONFIGURATION_get_value_string (uc->cfg, |
897 | GNUNET_CONFIGURATION_get_value_string (uc->cfg, section, | 909 | section, |
898 | "TESTING_IGNORE_KEYS", &val)); | 910 | "TESTING_IGNORE_KEYS", |
911 | &val)); | ||
899 | ptr = val; | 912 | ptr = val; |
900 | for (ikeys_cnt = 0; NULL != (ptr = strstr (ptr, ";")); ikeys_cnt++) | 913 | for (ikeys_cnt = 0; NULL != (ptr = strstr (ptr, ";")); ikeys_cnt++) |
901 | ptr++; | 914 | ptr++; |
@@ -920,18 +933,22 @@ update_config_sections (void *cls, | |||
920 | for (key = 0; key < ikeys_cnt; key++) | 933 | for (key = 0; key < ikeys_cnt; key++) |
921 | { | 934 | { |
922 | if (NULL != strstr (ikeys[key], "ADVERTISED_PORT")) | 935 | if (NULL != strstr (ikeys[key], "ADVERTISED_PORT")) |
923 | break; | 936 | break; |
924 | } | 937 | } |
925 | if ((key == ikeys_cnt) && | 938 | if ((key == ikeys_cnt) && |
926 | (GNUNET_YES == GNUNET_CONFIGURATION_have_value (uc->cfg, section, | 939 | (GNUNET_YES == |
927 | "ADVERTISED_PORT"))) | 940 | GNUNET_CONFIGURATION_have_value (uc->cfg, section, "ADVERTISED_PORT"))) |
928 | { | 941 | { |
929 | if (GNUNET_OK == | 942 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (uc->cfg, |
930 | GNUNET_CONFIGURATION_get_value_string (uc->cfg, section, "PORT", &ptr)) | 943 | section, |
944 | "PORT", | ||
945 | &ptr)) | ||
931 | { | 946 | { |
932 | GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, | 947 | GNUNET_CONFIGURATION_set_value_string (uc->cfg, |
933 | "ADVERTISED_PORT", ptr); | 948 | section, |
934 | GNUNET_free (ptr); | 949 | "ADVERTISED_PORT", |
950 | ptr); | ||
951 | GNUNET_free (ptr); | ||
935 | } | 952 | } |
936 | } | 953 | } |
937 | for (key = 0; key < ikeys_cnt; key++) | 954 | for (key = 0; key < ikeys_cnt; key++) |
@@ -950,19 +967,24 @@ update_config_sections (void *cls, | |||
950 | if ((NULL != uc->system->trusted_ip) && | 967 | if ((NULL != uc->system->trusted_ip) && |
951 | (NULL != strstr (uc->system->trusted_ip, ":"))) /* IPv6 in use */ | 968 | (NULL != strstr (uc->system->trusted_ip, ":"))) /* IPv6 in use */ |
952 | ACCEPT_FROM_key = "ACCEPT_FROM6"; | 969 | ACCEPT_FROM_key = "ACCEPT_FROM6"; |
953 | if (GNUNET_OK != | 970 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (uc->cfg, |
954 | GNUNET_CONFIGURATION_get_value_string (uc->cfg, section, ACCEPT_FROM_key, | 971 | section, |
955 | &orig_allowed_hosts)) | 972 | ACCEPT_FROM_key, |
973 | &orig_allowed_hosts)) | ||
956 | { | 974 | { |
957 | orig_allowed_hosts = GNUNET_strdup ("127.0.0.1;"); | 975 | orig_allowed_hosts = GNUNET_strdup ("127.0.0.1;"); |
958 | } | 976 | } |
959 | if (NULL == uc->system->trusted_ip) | 977 | if (NULL == uc->system->trusted_ip) |
960 | allowed_hosts = GNUNET_strdup (orig_allowed_hosts); | 978 | allowed_hosts = GNUNET_strdup (orig_allowed_hosts); |
961 | else | 979 | else |
962 | GNUNET_asprintf (&allowed_hosts, "%s%s;", orig_allowed_hosts, | 980 | GNUNET_asprintf (&allowed_hosts, |
981 | "%s%s;", | ||
982 | orig_allowed_hosts, | ||
963 | uc->system->trusted_ip); | 983 | uc->system->trusted_ip); |
964 | GNUNET_free (orig_allowed_hosts); | 984 | GNUNET_free (orig_allowed_hosts); |
965 | GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, ACCEPT_FROM_key, | 985 | GNUNET_CONFIGURATION_set_value_string (uc->cfg, |
986 | section, | ||
987 | ACCEPT_FROM_key, | ||
966 | allowed_hosts); | 988 | allowed_hosts); |
967 | GNUNET_free (allowed_hosts); | 989 | GNUNET_free (allowed_hosts); |
968 | } | 990 | } |
@@ -979,15 +1001,17 @@ associate_shared_service (struct GNUNET_TESTING_System *system, | |||
979 | uint32_t port; | 1001 | uint32_t port; |
980 | 1002 | ||
981 | ss->n_peers++; | 1003 | ss->n_peers++; |
982 | if ( ((0 == ss->share) && (NULL == ss->instances)) | 1004 | if (((0 == ss->share) && (NULL == ss->instances)) || |
983 | || | 1005 | ((0 != ss->share) && |
984 | ( (0 != ss->share) | 1006 | (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share)))) |
985 | && (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share)) ) ) | ||
986 | { | 1007 | { |
987 | i = GNUNET_new (struct SharedServiceInstance); | 1008 | i = GNUNET_new (struct SharedServiceInstance); |
988 | i->ss = ss; | 1009 | i->ss = ss; |
989 | (void) GNUNET_asprintf (&gnunet_home, "%s/shared/%s/%u", | 1010 | (void) GNUNET_asprintf (&gnunet_home, |
990 | system->tmppath, ss->sname, ss->n_instances); | 1011 | "%s/shared/%s/%u", |
1012 | system->tmppath, | ||
1013 | ss->sname, | ||
1014 | ss->n_instances); | ||
991 | (void) GNUNET_asprintf (&i->unix_sock, "%s/sock", gnunet_home); | 1015 | (void) GNUNET_asprintf (&i->unix_sock, "%s/sock", gnunet_home); |
992 | port = GNUNET_TESTING_reserve_port (system); | 1016 | port = GNUNET_TESTING_reserve_port (system); |
993 | if (0 == port) | 1017 | if (0 == port) |
@@ -1000,12 +1024,18 @@ associate_shared_service (struct GNUNET_TESTING_System *system, | |||
1000 | temp = GNUNET_CONFIGURATION_dup (ss->cfg); | 1024 | temp = GNUNET_CONFIGURATION_dup (ss->cfg); |
1001 | (void) GNUNET_asprintf (&i->port_str, "%u", port); | 1025 | (void) GNUNET_asprintf (&i->port_str, "%u", port); |
1002 | (void) GNUNET_asprintf (&i->cfg_fn, "%s/config", gnunet_home); | 1026 | (void) GNUNET_asprintf (&i->cfg_fn, "%s/config", gnunet_home); |
1003 | GNUNET_CONFIGURATION_set_value_string (temp, "PATHS", "GNUNET_HOME", | 1027 | GNUNET_CONFIGURATION_set_value_string (temp, |
1028 | "PATHS", | ||
1029 | "GNUNET_HOME", | ||
1004 | gnunet_home); | 1030 | gnunet_home); |
1005 | GNUNET_free (gnunet_home); | 1031 | GNUNET_free (gnunet_home); |
1006 | GNUNET_CONFIGURATION_set_value_string (temp, ss->sname, "UNIXPATH", | 1032 | GNUNET_CONFIGURATION_set_value_string (temp, |
1033 | ss->sname, | ||
1034 | "UNIXPATH", | ||
1007 | i->unix_sock); | 1035 | i->unix_sock); |
1008 | GNUNET_CONFIGURATION_set_value_string (temp, ss->sname, "PORT", | 1036 | GNUNET_CONFIGURATION_set_value_string (temp, |
1037 | ss->sname, | ||
1038 | "PORT", | ||
1009 | i->port_str); | 1039 | i->port_str); |
1010 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_write (temp, i->cfg_fn)) | 1040 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_write (temp, i->cfg_fn)) |
1011 | { | 1041 | { |
@@ -1021,9 +1051,13 @@ associate_shared_service (struct GNUNET_TESTING_System *system, | |||
1021 | GNUNET_assert (0 < ss->n_instances); | 1051 | GNUNET_assert (0 < ss->n_instances); |
1022 | i = ss->instances[ss->n_instances - 1]; | 1052 | i = ss->instances[ss->n_instances - 1]; |
1023 | } | 1053 | } |
1024 | GNUNET_CONFIGURATION_iterate_section_values(ss->cfg, ss->sname, | 1054 | GNUNET_CONFIGURATION_iterate_section_values (ss->cfg, |
1025 | &cfg_copy_iterator, cfg); | 1055 | ss->sname, |
1026 | GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "UNIXPATH", | 1056 | &cfg_copy_iterator, |
1057 | cfg); | ||
1058 | GNUNET_CONFIGURATION_set_value_string (cfg, | ||
1059 | ss->sname, | ||
1060 | "UNIXPATH", | ||
1027 | i->unix_sock); | 1061 | i->unix_sock); |
1028 | GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "PORT", i->port_str); | 1062 | GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "PORT", i->port_str); |
1029 | return i; | 1063 | return i; |
@@ -1063,24 +1097,27 @@ GNUNET_TESTING_configuration_create_ (struct GNUNET_TESTING_System *system, | |||
1063 | uc.status = GNUNET_OK; | 1097 | uc.status = GNUNET_OK; |
1064 | uc.ports = NULL; | 1098 | uc.ports = NULL; |
1065 | uc.nports = 0; | 1099 | uc.nports = 0; |
1066 | GNUNET_asprintf (&uc.gnunet_home, "%s/%u", system->tmppath, | 1100 | GNUNET_asprintf (&uc.gnunet_home, |
1101 | "%s/%u", | ||
1102 | system->tmppath, | ||
1067 | system->path_counter++); | 1103 | system->path_counter++); |
1068 | GNUNET_asprintf (&default_config, "%s/config", uc.gnunet_home); | 1104 | GNUNET_asprintf (&default_config, "%s/config", uc.gnunet_home); |
1069 | GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", | 1105 | GNUNET_CONFIGURATION_set_value_string (cfg, |
1070 | default_config); | 1106 | "PATHS", |
1071 | GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", | 1107 | "DEFAULTCONFIG", |
1072 | default_config); | 1108 | default_config); |
1109 | GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", default_config); | ||
1073 | GNUNET_free (default_config); | 1110 | GNUNET_free (default_config); |
1074 | GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "GNUNET_HOME", | 1111 | GNUNET_CONFIGURATION_set_value_string (cfg, |
1112 | "PATHS", | ||
1113 | "GNUNET_HOME", | ||
1075 | uc.gnunet_home); | 1114 | uc.gnunet_home); |
1076 | /* make PORTs and UNIXPATHs unique */ | 1115 | /* make PORTs and UNIXPATHs unique */ |
1077 | GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc); | 1116 | GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc); |
1078 | /* allow connections to services from system trusted_ip host */ | 1117 | /* allow connections to services from system trusted_ip host */ |
1079 | GNUNET_CONFIGURATION_iterate_sections (cfg, &update_config_sections, &uc); | 1118 | GNUNET_CONFIGURATION_iterate_sections (cfg, &update_config_sections, &uc); |
1080 | /* enable loopback-based connections between peers */ | 1119 | /* enable loopback-based connections between peers */ |
1081 | GNUNET_CONFIGURATION_set_value_string (cfg, | 1120 | GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "USE_LOCALADDR", "YES"); |
1082 | "nat", | ||
1083 | "USE_LOCALADDR", "YES"); | ||
1084 | GNUNET_free (uc.gnunet_home); | 1121 | GNUNET_free (uc.gnunet_home); |
1085 | if ((NULL != ports) && (NULL != nports)) | 1122 | if ((NULL != ports) && (NULL != nports)) |
1086 | { | 1123 | { |
@@ -1111,7 +1148,7 @@ GNUNET_TESTING_configuration_create_ (struct GNUNET_TESTING_System *system, | |||
1111 | */ | 1148 | */ |
1112 | int | 1149 | int |
1113 | GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system, | 1150 | GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system, |
1114 | struct GNUNET_CONFIGURATION_Handle *cfg) | 1151 | struct GNUNET_CONFIGURATION_Handle *cfg) |
1115 | { | 1152 | { |
1116 | return GNUNET_TESTING_configuration_create_ (system, cfg, NULL, NULL); | 1153 | return GNUNET_TESTING_configuration_create_ (system, cfg, NULL, NULL); |
1117 | } | 1154 | } |
@@ -1132,10 +1169,10 @@ GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system, | |||
1132 | */ | 1169 | */ |
1133 | struct GNUNET_TESTING_Peer * | 1170 | struct GNUNET_TESTING_Peer * |
1134 | GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, | 1171 | GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, |
1135 | struct GNUNET_CONFIGURATION_Handle *cfg, | 1172 | struct GNUNET_CONFIGURATION_Handle *cfg, |
1136 | uint32_t key_number, | 1173 | uint32_t key_number, |
1137 | struct GNUNET_PeerIdentity *id, | 1174 | struct GNUNET_PeerIdentity *id, |
1138 | char **emsg) | 1175 | char **emsg) |
1139 | { | 1176 | { |
1140 | struct GNUNET_TESTING_Peer *peer; | 1177 | struct GNUNET_TESTING_Peer *peer; |
1141 | struct GNUNET_DISK_FileHandle *fd; | 1178 | struct GNUNET_DISK_FileHandle *fd; |
@@ -1157,9 +1194,11 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, | |||
1157 | *emsg = NULL; | 1194 | *emsg = NULL; |
1158 | if (key_number >= system->total_hostkeys) | 1195 | if (key_number >= system->total_hostkeys) |
1159 | { | 1196 | { |
1160 | GNUNET_asprintf (&emsg_, | 1197 | GNUNET_asprintf ( |
1161 | _("You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"), | 1198 | &emsg_, |
1162 | (unsigned int) system->total_hostkeys); | 1199 | _ ( |
1200 | "You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"), | ||
1201 | (unsigned int) system->total_hostkeys); | ||
1163 | goto err_ret; | 1202 | goto err_ret; |
1164 | } | 1203 | } |
1165 | pk = NULL; | 1204 | pk = NULL; |
@@ -1167,17 +1206,17 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, | |||
1167 | (NULL == (pk = GNUNET_TESTING_hostkey_get (system, key_number, id)))) | 1206 | (NULL == (pk = GNUNET_TESTING_hostkey_get (system, key_number, id)))) |
1168 | { | 1207 | { |
1169 | GNUNET_asprintf (&emsg_, | 1208 | GNUNET_asprintf (&emsg_, |
1170 | _("Failed to initialize hostkey for peer %u\n"), | 1209 | _ ("Failed to initialize hostkey for peer %u\n"), |
1171 | (unsigned int) key_number); | 1210 | (unsigned int) key_number); |
1172 | goto err_ret; | 1211 | goto err_ret; |
1173 | } | 1212 | } |
1174 | if (NULL != pk) | 1213 | if (NULL != pk) |
1175 | GNUNET_free (pk); | 1214 | GNUNET_free (pk); |
1176 | if (GNUNET_NO == | 1215 | if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg, "PEER", "PRIVATE_KEY")) |
1177 | GNUNET_CONFIGURATION_have_value (cfg, "PEER", "PRIVATE_KEY")) | ||
1178 | { | 1216 | { |
1179 | GNUNET_asprintf (&emsg_, | 1217 | GNUNET_asprintf ( |
1180 | _("PRIVATE_KEY option in PEER section missing in configuration\n")); | 1218 | &emsg_, |
1219 | _ ("PRIVATE_KEY option in PEER section missing in configuration\n")); | ||
1181 | goto err_ret; | 1220 | goto err_ret; |
1182 | } | 1221 | } |
1183 | /* Remove sections for shared services */ | 1222 | /* Remove sections for shared services */ |
@@ -1186,46 +1225,50 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, | |||
1186 | ss = system->shared_services[cnt]; | 1225 | ss = system->shared_services[cnt]; |
1187 | GNUNET_CONFIGURATION_remove_section (cfg, ss->sname); | 1226 | GNUNET_CONFIGURATION_remove_section (cfg, ss->sname); |
1188 | } | 1227 | } |
1189 | if (GNUNET_OK != GNUNET_TESTING_configuration_create_ (system, cfg, | 1228 | if (GNUNET_OK != |
1190 | &ports, &nports)) | 1229 | GNUNET_TESTING_configuration_create_ (system, cfg, &ports, &nports)) |
1191 | { | 1230 | { |
1192 | GNUNET_asprintf (&emsg_, | 1231 | GNUNET_asprintf (&emsg_, |
1193 | _("Failed to create configuration for peer " | 1232 | _ ("Failed to create configuration for peer " |
1194 | "(not enough free ports?)\n")); | 1233 | "(not enough free ports?)\n")); |
1195 | goto err_ret; | 1234 | goto err_ret; |
1196 | } | 1235 | } |
1197 | GNUNET_assert (GNUNET_OK == | 1236 | GNUNET_assert (GNUNET_OK == |
1198 | GNUNET_CONFIGURATION_get_value_filename (cfg, "PEER", | 1237 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
1199 | "PRIVATE_KEY", | 1238 | "PEER", |
1200 | &hostkey_filename)); | 1239 | "PRIVATE_KEY", |
1240 | &hostkey_filename)); | ||
1201 | fd = GNUNET_DISK_file_open (hostkey_filename, | 1241 | fd = GNUNET_DISK_file_open (hostkey_filename, |
1202 | GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_WRITE, | 1242 | GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_WRITE, |
1203 | GNUNET_DISK_PERM_USER_READ | 1243 | GNUNET_DISK_PERM_USER_READ | |
1204 | | GNUNET_DISK_PERM_USER_WRITE); | 1244 | GNUNET_DISK_PERM_USER_WRITE); |
1205 | if (NULL == fd) | 1245 | if (NULL == fd) |
1206 | { | 1246 | { |
1207 | GNUNET_asprintf (&emsg_, _("Cannot open hostkey file `%s': %s\n"), | 1247 | GNUNET_asprintf (&emsg_, |
1208 | hostkey_filename, STRERROR (errno)); | 1248 | _ ("Cannot open hostkey file `%s': %s\n"), |
1249 | hostkey_filename, | ||
1250 | strerror (errno)); | ||
1209 | GNUNET_free (hostkey_filename); | 1251 | GNUNET_free (hostkey_filename); |
1210 | goto err_ret; | 1252 | goto err_ret; |
1211 | } | 1253 | } |
1212 | GNUNET_free (hostkey_filename); | 1254 | GNUNET_free (hostkey_filename); |
1213 | if (GNUNET_TESTING_HOSTKEYFILESIZE != | 1255 | if (GNUNET_TESTING_HOSTKEYFILESIZE != |
1214 | GNUNET_DISK_file_write (fd, system->hostkeys_data | 1256 | GNUNET_DISK_file_write (fd, |
1215 | + (key_number * GNUNET_TESTING_HOSTKEYFILESIZE), | 1257 | system->hostkeys_data + |
1216 | GNUNET_TESTING_HOSTKEYFILESIZE)) | 1258 | (key_number * GNUNET_TESTING_HOSTKEYFILESIZE), |
1259 | GNUNET_TESTING_HOSTKEYFILESIZE)) | ||
1217 | { | 1260 | { |
1218 | GNUNET_asprintf (&emsg_, | 1261 | GNUNET_asprintf (&emsg_, |
1219 | _("Failed to write hostkey file for peer %u: %s\n"), | 1262 | _ ("Failed to write hostkey file for peer %u: %s\n"), |
1220 | (unsigned int) key_number, | 1263 | (unsigned int) key_number, |
1221 | STRERROR (errno)); | 1264 | strerror (errno)); |
1222 | GNUNET_DISK_file_close (fd); | 1265 | GNUNET_DISK_file_close (fd); |
1223 | goto err_ret; | 1266 | goto err_ret; |
1224 | } | 1267 | } |
1225 | GNUNET_DISK_file_close (fd); | 1268 | GNUNET_DISK_file_close (fd); |
1226 | ss_instances = GNUNET_malloc (sizeof (struct SharedServiceInstance *) | 1269 | ss_instances = GNUNET_malloc (sizeof (struct SharedServiceInstance *) * |
1227 | * system->n_shared_services); | 1270 | system->n_shared_services); |
1228 | for (cnt=0; cnt < system->n_shared_services; cnt++) | 1271 | for (cnt = 0; cnt < system->n_shared_services; cnt++) |
1229 | { | 1272 | { |
1230 | ss = system->shared_services[cnt]; | 1273 | ss = system->shared_services[cnt]; |
1231 | ss_instances[cnt] = associate_shared_service (system, ss, cfg); | 1274 | ss_instances[cnt] = associate_shared_service (system, ss, cfg); |
@@ -1236,15 +1279,18 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, | |||
1236 | } | 1279 | } |
1237 | } | 1280 | } |
1238 | GNUNET_assert (GNUNET_OK == | 1281 | GNUNET_assert (GNUNET_OK == |
1239 | GNUNET_CONFIGURATION_get_value_filename | 1282 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
1240 | (cfg, "PATHS", "DEFAULTCONFIG", &config_filename)); | 1283 | "PATHS", |
1284 | "DEFAULTCONFIG", | ||
1285 | &config_filename)); | ||
1241 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config_filename)) | 1286 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config_filename)) |
1242 | { | 1287 | { |
1243 | GNUNET_asprintf (&emsg_, | 1288 | GNUNET_asprintf (&emsg_, |
1244 | _("Failed to write configuration file `%s' for peer %u: %s\n"), | 1289 | _ ( |
1245 | config_filename, | 1290 | "Failed to write configuration file `%s' for peer %u: %s\n"), |
1246 | (unsigned int) key_number, | 1291 | config_filename, |
1247 | STRERROR (errno)); | 1292 | (unsigned int) key_number, |
1293 | strerror (errno)); | ||
1248 | GNUNET_free (config_filename); | 1294 | GNUNET_free (config_filename); |
1249 | goto err_ret; | 1295 | goto err_ret; |
1250 | } | 1296 | } |
@@ -1253,10 +1299,14 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, | |||
1253 | peer->cfgfile = config_filename; /* Free in peer_destroy */ | 1299 | peer->cfgfile = config_filename; /* Free in peer_destroy */ |
1254 | peer->cfg = GNUNET_CONFIGURATION_dup (cfg); | 1300 | peer->cfg = GNUNET_CONFIGURATION_dup (cfg); |
1255 | libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); | 1301 | libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); |
1256 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "arm", "PREFIX", &peer->main_binary)) | 1302 | if (GNUNET_SYSERR == |
1303 | GNUNET_CONFIGURATION_get_value_string (cfg, | ||
1304 | "arm", | ||
1305 | "PREFIX", | ||
1306 | &peer->main_binary)) | ||
1257 | { | 1307 | { |
1258 | /* No prefix */ | 1308 | /* No prefix */ |
1259 | GNUNET_asprintf(&peer->main_binary, "%s", libexec_binary); | 1309 | GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary); |
1260 | peer->args = GNUNET_strdup (""); | 1310 | peer->args = GNUNET_strdup (""); |
1261 | } | 1311 | } |
1262 | else | 1312 | else |
@@ -1266,11 +1316,11 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, | |||
1266 | peer->system = system; | 1316 | peer->system = system; |
1267 | peer->key_number = key_number; | 1317 | peer->key_number = key_number; |
1268 | GNUNET_free (libexec_binary); | 1318 | GNUNET_free (libexec_binary); |
1269 | peer->ports = ports; /* Free in peer_destroy */ | 1319 | peer->ports = ports; /* Free in peer_destroy */ |
1270 | peer->nports = nports; | 1320 | peer->nports = nports; |
1271 | return peer; | 1321 | return peer; |
1272 | 1322 | ||
1273 | err_ret: | 1323 | err_ret: |
1274 | GNUNET_free_non_null (ss_instances); | 1324 | GNUNET_free_non_null (ss_instances); |
1275 | GNUNET_free_non_null (ports); | 1325 | GNUNET_free_non_null (ports); |
1276 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_); | 1326 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_); |
@@ -1290,7 +1340,7 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, | |||
1290 | */ | 1340 | */ |
1291 | void | 1341 | void |
1292 | GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer, | 1342 | GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer, |
1293 | struct GNUNET_PeerIdentity *id) | 1343 | struct GNUNET_PeerIdentity *id) |
1294 | { | 1344 | { |
1295 | if (NULL != peer->id) | 1345 | if (NULL != peer->id) |
1296 | { | 1346 | { |
@@ -1298,9 +1348,8 @@ GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer, | |||
1298 | return; | 1348 | return; |
1299 | } | 1349 | } |
1300 | peer->id = GNUNET_new (struct GNUNET_PeerIdentity); | 1350 | peer->id = GNUNET_new (struct GNUNET_PeerIdentity); |
1301 | GNUNET_free (GNUNET_TESTING_hostkey_get (peer->system, | 1351 | GNUNET_free ( |
1302 | peer->key_number, | 1352 | GNUNET_TESTING_hostkey_get (peer->system, peer->key_number, peer->id)); |
1303 | peer->id)); | ||
1304 | GNUNET_memcpy (id, peer->id, sizeof (struct GNUNET_PeerIdentity)); | 1353 | GNUNET_memcpy (id, peer->id, sizeof (struct GNUNET_PeerIdentity)); |
1305 | } | 1354 | } |
1306 | 1355 | ||
@@ -1326,26 +1375,28 @@ GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer) | |||
1326 | for (cnt = 0; cnt < peer->system->n_shared_services; cnt++) | 1375 | for (cnt = 0; cnt < peer->system->n_shared_services; cnt++) |
1327 | { | 1376 | { |
1328 | i = peer->ss_instances[cnt]; | 1377 | i = peer->ss_instances[cnt]; |
1329 | if ((0 == i->n_refs) | 1378 | if ((0 == i->n_refs) && |
1330 | && (GNUNET_SYSERR == start_shared_service_instance (i)) ) | 1379 | (GNUNET_SYSERR == start_shared_service_instance (i))) |
1331 | return GNUNET_SYSERR; | 1380 | return GNUNET_SYSERR; |
1332 | i->n_refs++; | 1381 | i->n_refs++; |
1333 | } | 1382 | } |
1334 | peer->main_binary = GNUNET_CONFIGURATION_expand_dollar (peer->cfg, peer->main_binary); | 1383 | peer->main_binary = |
1335 | peer->main_process = GNUNET_OS_start_process_s (PIPE_CONTROL, | 1384 | GNUNET_CONFIGURATION_expand_dollar (peer->cfg, peer->main_binary); |
1336 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 1385 | peer->main_process = |
1337 | NULL, | 1386 | GNUNET_OS_start_process_s (PIPE_CONTROL, |
1338 | peer->main_binary, | 1387 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
1339 | peer->args, | 1388 | NULL, |
1340 | "-c", | 1389 | peer->main_binary, |
1341 | peer->cfgfile, | 1390 | peer->args, |
1342 | NULL); | 1391 | "-c", |
1392 | peer->cfgfile, | ||
1393 | NULL); | ||
1343 | if (NULL == peer->main_process) | 1394 | if (NULL == peer->main_process) |
1344 | { | 1395 | { |
1345 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1396 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1346 | _("Failed to start `%s': %s\n"), | 1397 | _ ("Failed to start `%s': %s\n"), |
1347 | peer->main_binary, | 1398 | peer->main_binary, |
1348 | STRERROR (errno)); | 1399 | strerror (errno)); |
1349 | return GNUNET_SYSERR; | 1400 | return GNUNET_SYSERR; |
1350 | } | 1401 | } |
1351 | return GNUNET_OK; | 1402 | return GNUNET_OK; |
@@ -1433,8 +1484,7 @@ GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer) | |||
1433 | * #GNUNET_SYSERR on error. | 1484 | * #GNUNET_SYSERR on error. |
1434 | */ | 1485 | */ |
1435 | static void | 1486 | static void |
1436 | disconn_status (void *cls, | 1487 | disconn_status (void *cls, int connected) |
1437 | int connected) | ||
1438 | { | 1488 | { |
1439 | struct GNUNET_TESTING_Peer *peer = cls; | 1489 | struct GNUNET_TESTING_Peer *peer = cls; |
1440 | 1490 | ||
@@ -1551,12 +1601,11 @@ GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer) | |||
1551 | */ | 1601 | */ |
1552 | int | 1602 | int |
1553 | GNUNET_TESTING_peer_run (const char *testdir, | 1603 | GNUNET_TESTING_peer_run (const char *testdir, |
1554 | const char *cfgfilename, | 1604 | const char *cfgfilename, |
1555 | GNUNET_TESTING_TestMain tm, | 1605 | GNUNET_TESTING_TestMain tm, |
1556 | void *tm_cls) | 1606 | void *tm_cls) |
1557 | { | 1607 | { |
1558 | return GNUNET_TESTING_service_run (testdir, "arm", | 1608 | return GNUNET_TESTING_service_run (testdir, "arm", cfgfilename, tm, tm_cls); |
1559 | cfgfilename, tm, tm_cls); | ||
1560 | } | 1609 | } |
1561 | 1610 | ||
1562 | 1611 | ||
@@ -1624,10 +1673,10 @@ service_run_main (void *cls) | |||
1624 | */ | 1673 | */ |
1625 | int | 1674 | int |
1626 | GNUNET_TESTING_service_run (const char *testdir, | 1675 | GNUNET_TESTING_service_run (const char *testdir, |
1627 | const char *service_name, | 1676 | const char *service_name, |
1628 | const char *cfgfilename, | 1677 | const char *cfgfilename, |
1629 | GNUNET_TESTING_TestMain tm, | 1678 | GNUNET_TESTING_TestMain tm, |
1630 | void *tm_cls) | 1679 | void *tm_cls) |
1631 | { | 1680 | { |
1632 | struct ServiceContext sc; | 1681 | struct ServiceContext sc; |
1633 | struct GNUNET_TESTING_System *system; | 1682 | struct GNUNET_TESTING_System *system; |
@@ -1636,9 +1685,7 @@ GNUNET_TESTING_service_run (const char *testdir, | |||
1636 | char *binary; | 1685 | char *binary; |
1637 | char *libexec_binary; | 1686 | char *libexec_binary; |
1638 | 1687 | ||
1639 | GNUNET_log_setup (testdir, | 1688 | GNUNET_log_setup (testdir, "WARNING", NULL); |
1640 | "WARNING", | ||
1641 | NULL); | ||
1642 | system = GNUNET_TESTING_system_create (testdir, "127.0.0.1", NULL, NULL); | 1689 | system = GNUNET_TESTING_system_create (testdir, "127.0.0.1", NULL, NULL); |
1643 | if (NULL == system) | 1690 | if (NULL == system) |
1644 | return 1; | 1691 | return 1; |
@@ -1646,7 +1693,8 @@ GNUNET_TESTING_service_run (const char *testdir, | |||
1646 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgfilename)) | 1693 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgfilename)) |
1647 | { | 1694 | { |
1648 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1695 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1649 | _("Failed to load configuration from %s\n"), cfgfilename); | 1696 | _ ("Failed to load configuration from %s\n"), |
1697 | cfgfilename); | ||
1650 | GNUNET_CONFIGURATION_destroy (cfg); | 1698 | GNUNET_CONFIGURATION_destroy (cfg); |
1651 | GNUNET_TESTING_system_destroy (system, GNUNET_YES); | 1699 | GNUNET_TESTING_system_destroy (system, GNUNET_YES); |
1652 | return 1; | 1700 | return 1; |
@@ -1663,10 +1711,14 @@ GNUNET_TESTING_service_run (const char *testdir, | |||
1663 | GNUNET_free (peer->args); | 1711 | GNUNET_free (peer->args); |
1664 | GNUNET_asprintf (&binary, "gnunet-service-%s", service_name); | 1712 | GNUNET_asprintf (&binary, "gnunet-service-%s", service_name); |
1665 | libexec_binary = GNUNET_OS_get_libexec_binary_path (binary); | 1713 | libexec_binary = GNUNET_OS_get_libexec_binary_path (binary); |
1666 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, service_name, "PREFIX", &peer->main_binary)) | 1714 | if (GNUNET_SYSERR == |
1715 | GNUNET_CONFIGURATION_get_value_string (cfg, | ||
1716 | service_name, | ||
1717 | "PREFIX", | ||
1718 | &peer->main_binary)) | ||
1667 | { | 1719 | { |
1668 | /* No prefix */ | 1720 | /* No prefix */ |
1669 | GNUNET_asprintf(&peer->main_binary, "%s", libexec_binary); | 1721 | GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary); |
1670 | peer->args = GNUNET_strdup (""); | 1722 | peer->args = GNUNET_strdup (""); |
1671 | } | 1723 | } |
1672 | else | 1724 | else |