diff options
author | Nathan S. Evans <evans@in.tum.de> | 2011-07-26 12:39:23 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2011-07-26 12:39:23 +0000 |
commit | 66e9353163686f84163816a7fee09209ce522fcb (patch) | |
tree | 2776423670bd69f4f21ef0e6e39af340585ed99b | |
parent | e8bc36209dd09c9720c6ea8657e4f49c35c08956 (diff) | |
download | gnunet-66e9353163686f84163816a7fee09209ce522fcb.tar.gz gnunet-66e9353163686f84163816a7fee09209ce522fcb.zip |
load hosts from file, implementation in testing
-rw-r--r-- | src/include/gnunet_testing_lib.h | 55 | ||||
-rw-r--r-- | src/nse/nse-profiler.c | 5 | ||||
-rw-r--r-- | src/testing/testing_group.c | 99 |
3 files changed, 136 insertions, 23 deletions
diff --git a/src/include/gnunet_testing_lib.h b/src/include/gnunet_testing_lib.h index 34920bbab..0b998cf95 100644 --- a/src/include/gnunet_testing_lib.h +++ b/src/include/gnunet_testing_lib.h | |||
@@ -602,31 +602,17 @@ GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d, | |||
602 | struct GNUNET_TIME_Relative timeout, | 602 | struct GNUNET_TIME_Relative timeout, |
603 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls); | 603 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls); |
604 | 604 | ||
605 | |||
606 | /** | 605 | /** |
607 | * Establish a connection between two GNUnet daemons. | 606 | * Read a testing hosts file based on a configuration. |
607 | * Returns a DLL of hosts (caller must free!) on success | ||
608 | * or NULL on failure. | ||
608 | * | 609 | * |
609 | * @param d1 handle for the first daemon | 610 | * @param cfg a configuration with a testing section |
610 | * @param d2 handle for the second daemon | 611 | * |
611 | * @param timeout how long is the connection attempt | 612 | * @return DLL of hosts on success, NULL on failure |
612 | * allowed to take? | ||
613 | * @param max_connect_attempts how many times should we try to reconnect | ||
614 | * (within timeout) | ||
615 | * @param send_hello GNUNET_YES to send the HELLO, GNUNET_NO to assume | ||
616 | * the HELLO has already been exchanged | ||
617 | * @param cb function to call at the end | ||
618 | * @param cb_cls closure for cb | ||
619 | */ | 613 | */ |
620 | void | 614 | struct GNUNET_TESTING_Host * |
621 | GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, | 615 | GNUNET_TESTING_hosts_load (const struct GNUNET_CONFIGURATION_Handle *cfg); |
622 | struct GNUNET_TESTING_Daemon *d2, | ||
623 | struct GNUNET_TIME_Relative timeout, | ||
624 | unsigned int max_connect_attempts, | ||
625 | int send_hello, | ||
626 | GNUNET_TESTING_NotifyConnection cb, | ||
627 | void *cb_cls); | ||
628 | |||
629 | |||
630 | 616 | ||
631 | 617 | ||
632 | /** | 618 | /** |
@@ -679,6 +665,31 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
679 | void | 665 | void |
680 | GNUNET_TESTING_daemons_continue_startup(struct GNUNET_TESTING_PeerGroup *pg); | 666 | GNUNET_TESTING_daemons_continue_startup(struct GNUNET_TESTING_PeerGroup *pg); |
681 | 667 | ||
668 | |||
669 | /** | ||
670 | * Establish a connection between two GNUnet daemons. | ||
671 | * | ||
672 | * @param d1 handle for the first daemon | ||
673 | * @param d2 handle for the second daemon | ||
674 | * @param timeout how long is the connection attempt | ||
675 | * allowed to take? | ||
676 | * @param max_connect_attempts how many times should we try to reconnect | ||
677 | * (within timeout) | ||
678 | * @param send_hello GNUNET_YES to send the HELLO, GNUNET_NO to assume | ||
679 | * the HELLO has already been exchanged | ||
680 | * @param cb function to call at the end | ||
681 | * @param cb_cls closure for cb | ||
682 | */ | ||
683 | void | ||
684 | GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, | ||
685 | struct GNUNET_TESTING_Daemon *d2, | ||
686 | struct GNUNET_TIME_Relative timeout, | ||
687 | unsigned int max_connect_attempts, | ||
688 | int send_hello, | ||
689 | GNUNET_TESTING_NotifyConnection cb, | ||
690 | void *cb_cls); | ||
691 | |||
692 | |||
682 | /** | 693 | /** |
683 | * Restart all peers in the given group. | 694 | * Restart all peers in the given group. |
684 | * | 695 | * |
diff --git a/src/nse/nse-profiler.c b/src/nse/nse-profiler.c index 8d90ca260..3194979a5 100644 --- a/src/nse/nse-profiler.c +++ b/src/nse/nse-profiler.c | |||
@@ -580,6 +580,7 @@ run (void *cls, | |||
580 | { | 580 | { |
581 | char *temp_str; | 581 | char *temp_str; |
582 | unsigned long long temp_wait; | 582 | unsigned long long temp_wait; |
583 | struct GNUNET_TESTING_Host *hosts; | ||
583 | 584 | ||
584 | ok = 1; | 585 | ok = 1; |
585 | testing_cfg = GNUNET_CONFIGURATION_create(); | 586 | testing_cfg = GNUNET_CONFIGURATION_create(); |
@@ -673,12 +674,14 @@ run (void *cls, | |||
673 | } | 674 | } |
674 | GNUNET_free_non_null(temp_str); | 675 | GNUNET_free_non_null(temp_str); |
675 | 676 | ||
677 | hosts = GNUNET_TESTING_hosts_load (testing_cfg); | ||
678 | |||
676 | pg = GNUNET_TESTING_peergroup_start(testing_cfg, | 679 | pg = GNUNET_TESTING_peergroup_start(testing_cfg, |
677 | num_peers, | 680 | num_peers, |
678 | TIMEOUT, | 681 | TIMEOUT, |
679 | &connect_cb, | 682 | &connect_cb, |
680 | &my_cb, NULL, | 683 | &my_cb, NULL, |
681 | NULL); | 684 | hosts); |
682 | GNUNET_assert (pg != NULL); | 685 | GNUNET_assert (pg != NULL); |
683 | shutdown_handle = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever(), | 686 | shutdown_handle = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever(), |
684 | &shutdown_task, | 687 | &shutdown_task, |
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index 5b5981707..89e866d10 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c | |||
@@ -6811,6 +6811,105 @@ schedule_shutdown_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
6811 | 6811 | ||
6812 | } | 6812 | } |
6813 | 6813 | ||
6814 | /** | ||
6815 | * Read a testing hosts file based on a configuration. | ||
6816 | * Returns a DLL of hosts (caller must free!) on success | ||
6817 | * or NULL on failure. | ||
6818 | * | ||
6819 | * @param cfg a configuration with a testing section | ||
6820 | * | ||
6821 | * @return DLL of hosts on success, NULL on failure | ||
6822 | */ | ||
6823 | struct GNUNET_TESTING_Host * | ||
6824 | GNUNET_TESTING_hosts_load (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
6825 | { | ||
6826 | struct GNUNET_TESTING_Host *hosts; | ||
6827 | struct GNUNET_TESTING_Host *temphost; | ||
6828 | char *data; | ||
6829 | char *buf; | ||
6830 | char *hostfile; | ||
6831 | struct stat frstat; | ||
6832 | int count; | ||
6833 | int ret; | ||
6834 | |||
6835 | /* Check for a hostfile containing user@host:port triples */ | ||
6836 | if (GNUNET_OK | ||
6837 | != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "hostfile", | ||
6838 | &hostfile)) | ||
6839 | return NULL; | ||
6840 | |||
6841 | hosts = NULL; | ||
6842 | temphost = NULL; | ||
6843 | data = NULL; | ||
6844 | if (hostfile != NULL) | ||
6845 | { | ||
6846 | if (GNUNET_OK != GNUNET_DISK_file_test (hostfile)) | ||
6847 | GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ | ||
6848 | | GNUNET_DISK_PERM_USER_WRITE); | ||
6849 | if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0)) | ||
6850 | { | ||
6851 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
6852 | "Could not open file specified for host list, ending test!"); | ||
6853 | GNUNET_free(hostfile); | ||
6854 | return NULL; | ||
6855 | } | ||
6856 | |||
6857 | data = GNUNET_malloc_large (frstat.st_size); | ||
6858 | GNUNET_assert(data != NULL); | ||
6859 | if (frstat.st_size | ||
6860 | != GNUNET_DISK_fn_read (hostfile, data, frstat.st_size)) | ||
6861 | { | ||
6862 | GNUNET_log ( | ||
6863 | GNUNET_ERROR_TYPE_ERROR, | ||
6864 | "Could not read file %s specified for host list, ending test!", | ||
6865 | hostfile); | ||
6866 | GNUNET_free (hostfile); | ||
6867 | GNUNET_free (data); | ||
6868 | return NULL; | ||
6869 | } | ||
6870 | |||
6871 | GNUNET_free_non_null(hostfile); | ||
6872 | |||
6873 | buf = data; | ||
6874 | count = 0; | ||
6875 | while (count < frstat.st_size - 1) | ||
6876 | { | ||
6877 | count++; | ||
6878 | if (((data[count] == '\n')) && (buf != &data[count])) | ||
6879 | { | ||
6880 | data[count] = '\0'; | ||
6881 | temphost = GNUNET_malloc(sizeof(struct GNUNET_TESTING_Host)); | ||
6882 | ret = sscanf (buf, "%a[a-zA-Z0-9_]@%a[a-zA-Z0-9.]:%hd", | ||
6883 | &temphost->username, &temphost->hostname, | ||
6884 | &temphost->port); | ||
6885 | if (3 == ret) | ||
6886 | { | ||
6887 | GNUNET_log ( | ||
6888 | GNUNET_ERROR_TYPE_DEBUG, | ||
6889 | "Successfully read host %s, port %d and user %s from file\n", | ||
6890 | temphost->hostname, temphost->port, | ||
6891 | temphost->username); | ||
6892 | } | ||
6893 | else | ||
6894 | { | ||
6895 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
6896 | "Error reading line `%s' in hostfile\n", buf); | ||
6897 | GNUNET_free(temphost); | ||
6898 | buf = &data[count + 1]; | ||
6899 | continue; | ||
6900 | } | ||
6901 | temphost->next = hosts; | ||
6902 | hosts = temphost; | ||
6903 | buf = &data[count + 1]; | ||
6904 | } | ||
6905 | else if ((data[count] == '\n') || (data[count] == '\0')) | ||
6906 | buf = &data[count + 1]; | ||
6907 | } | ||
6908 | } | ||
6909 | GNUNET_free_non_null(data); | ||
6910 | |||
6911 | return hosts; | ||
6912 | } | ||
6814 | 6913 | ||
6815 | /** | 6914 | /** |
6816 | * Shutdown all peers started in the given group. | 6915 | * Shutdown all peers started in the given group. |