diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-02-21 14:20:35 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-02-21 14:20:35 +0000 |
commit | a6312a8a926cded91ff48ef2fb673954941f1ff5 (patch) | |
tree | a44845c05a7e064c454fbbfa5e861faae1033e93 /src/testbed/testbed_api_hosts.c | |
parent | 1c8093493c83f2b4fa7f7311340930bbe609f9ed (diff) | |
download | gnunet-a6312a8a926cded91ff48ef2fb673954941f1ff5.tar.gz gnunet-a6312a8a926cded91ff48ef2fb673954941f1ff5.zip |
host locking; warn upon API violation
Diffstat (limited to 'src/testbed/testbed_api_hosts.c')
-rw-r--r-- | src/testbed/testbed_api_hosts.c | 56 |
1 files changed, 36 insertions, 20 deletions
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c index ea1a1a570..65217ebdd 100644 --- a/src/testbed/testbed_api_hosts.c +++ b/src/testbed/testbed_api_hosts.c | |||
@@ -52,6 +52,17 @@ | |||
52 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__); | 52 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__); |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Prints API violation message | ||
56 | */ | ||
57 | #define API_VIOLATION(cond,errstr) \ | ||
58 | do { \ | ||
59 | if (cond) \ | ||
60 | break; \ | ||
61 | LOG (GNUNET_ERROR_TYPE_ERROR, "API violation detected: %s\n", errstr); \ | ||
62 | GNUNET_assert (0); \ | ||
63 | } while (0) | ||
64 | |||
65 | /** | ||
55 | * Number of extra elements we create space for when we grow host list | 66 | * Number of extra elements we create space for when we grow host list |
56 | */ | 67 | */ |
57 | #define HOST_LIST_GROW_STEP 10 | 68 | #define HOST_LIST_GROW_STEP 10 |
@@ -132,7 +143,8 @@ struct GNUNET_TESTBED_Host | |||
132 | /** | 143 | /** |
133 | * the configuration to use as a template while starting a controller on this | 144 | * the configuration to use as a template while starting a controller on this |
134 | * host. Operation queue size specific to a host are also read from this | 145 | * host. Operation queue size specific to a host are also read from this |
135 | * configuration handle | 146 | * configuration handle. After starting the controller, it points to the actual |
147 | * configuration with which the controller is running | ||
136 | */ | 148 | */ |
137 | struct GNUNET_CONFIGURATION_Handle *cfg; | 149 | struct GNUNET_CONFIGURATION_Handle *cfg; |
138 | 150 | ||
@@ -175,11 +187,16 @@ struct GNUNET_TESTBED_Host | |||
175 | unsigned int tslots_filled; | 187 | unsigned int tslots_filled; |
176 | 188 | ||
177 | /** | 189 | /** |
178 | * Is a controller started on this host? | 190 | * Is a controller started on this host? FIXME: Is this needed? |
179 | */ | 191 | */ |
180 | int controller_started; | 192 | int controller_started; |
181 | 193 | ||
182 | /** | 194 | /** |
195 | * Is this host locked by GNUNET_TESTBED_controller_start()? | ||
196 | */ | ||
197 | int locked; | ||
198 | |||
199 | /** | ||
183 | * Global ID we use to refer to a host on the network | 200 | * Global ID we use to refer to a host on the network |
184 | */ | 201 | */ |
185 | uint32_t id; | 202 | uint32_t id; |
@@ -631,11 +648,6 @@ struct GNUNET_TESTBED_ControllerProc | |||
631 | */ | 648 | */ |
632 | struct GNUNET_MessageHeader *msg; | 649 | struct GNUNET_MessageHeader *msg; |
633 | 650 | ||
634 | /** | ||
635 | * The configuration of the running testbed service | ||
636 | */ | ||
637 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
638 | |||
639 | }; | 651 | }; |
640 | 652 | ||
641 | 653 | ||
@@ -835,18 +847,22 @@ helper_mst (void *cls, void *client, const struct GNUNET_MessageHeader *message) | |||
835 | GNUNET_assert (Z_OK == | 847 | GNUNET_assert (Z_OK == |
836 | uncompress ((Bytef *) config, &config_size, | 848 | uncompress ((Bytef *) config, &config_size, |
837 | (const Bytef *) &msg[1], xconfig_size)); | 849 | (const Bytef *) &msg[1], xconfig_size)); |
838 | GNUNET_assert (NULL == cp->cfg); | 850 | /* Replace the configuration template present in the host with the |
839 | cp->cfg = GNUNET_CONFIGURATION_create (); | 851 | controller's running configuration */ |
852 | GNUNET_CONFIGURATION_destroy (cp->host->cfg); | ||
853 | cp->host->cfg = GNUNET_CONFIGURATION_create (); | ||
840 | GNUNET_assert (GNUNET_CONFIGURATION_deserialize | 854 | GNUNET_assert (GNUNET_CONFIGURATION_deserialize |
841 | (cp->cfg, config, config_size, GNUNET_NO)); | 855 | (cp->host->cfg, config, config_size, GNUNET_NO)); |
842 | GNUNET_free (config); | 856 | GNUNET_free (config); |
843 | if ((NULL == cp->host) || | 857 | if ((NULL == cp->host) || |
844 | (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host)))) | 858 | (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host)))) |
845 | hostname = "localhost"; | 859 | hostname = "localhost"; |
846 | /* Change the hostname so that we can connect to it */ | 860 | /* Change the hostname so that we can connect to it */ |
847 | GNUNET_CONFIGURATION_set_value_string (cp->cfg, "testbed", "hostname", | 861 | GNUNET_CONFIGURATION_set_value_string (cp->host->cfg, "testbed", "hostname", |
848 | hostname); | 862 | hostname); |
849 | cp->cb (cp->cls, cp->cfg, GNUNET_OK); | 863 | cp->host->locked = GNUNET_NO; |
864 | cp->host->controller_started = GNUNET_YES; | ||
865 | cp->cb (cp->cls, cp->host->cfg, GNUNET_OK); | ||
850 | return GNUNET_OK; | 866 | return GNUNET_OK; |
851 | } | 867 | } |
852 | 868 | ||
@@ -929,7 +945,12 @@ GNUNET_TESTBED_controller_start (const char *trusted_ip, | |||
929 | HELPER_TESTBED_BINARY, NULL | 945 | HELPER_TESTBED_BINARY, NULL |
930 | }; | 946 | }; |
931 | 947 | ||
932 | hostname = NULL; | 948 | hostname = NULL; |
949 | API_VIOLATION (GNUNET_NO == host->locked, | ||
950 | "Host is already locked by a previous call to GNUNET_TESTBED_controller_start()"); | ||
951 | host->locked = GNUNET_YES; | ||
952 | API_VIOLATION (GNUNET_NO == host->controller_started, | ||
953 | "Attempting to start a controller on a host which is already started a controller"); | ||
933 | cp = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ControllerProc)); | 954 | cp = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ControllerProc)); |
934 | if ((NULL == host) || (0 == GNUNET_TESTBED_host_get_id_ (host))) | 955 | if ((NULL == host) || (0 == GNUNET_TESTBED_host_get_id_ (host))) |
935 | { | 956 | { |
@@ -1014,10 +1035,10 @@ GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc) | |||
1014 | GNUNET_HELPER_send_cancel (cproc->shandle); | 1035 | GNUNET_HELPER_send_cancel (cproc->shandle); |
1015 | if (NULL != cproc->helper) | 1036 | if (NULL != cproc->helper) |
1016 | GNUNET_HELPER_soft_stop (cproc->helper); | 1037 | GNUNET_HELPER_soft_stop (cproc->helper); |
1017 | if (NULL != cproc->cfg) | ||
1018 | GNUNET_CONFIGURATION_destroy (cproc->cfg); | ||
1019 | if (NULL != cproc->helper_argv) | 1038 | if (NULL != cproc->helper_argv) |
1020 | free_argv (cproc->helper_argv); | 1039 | free_argv (cproc->helper_argv); |
1040 | cproc->host->controller_started = GNUNET_NO; | ||
1041 | cproc->host->locked = GNUNET_NO; | ||
1021 | GNUNET_free (cproc); | 1042 | GNUNET_free (cproc); |
1022 | } | 1043 | } |
1023 | 1044 | ||
@@ -1032,11 +1053,6 @@ struct GNUNET_TESTBED_HostHabitableCheckHandle | |||
1032 | */ | 1053 | */ |
1033 | const struct GNUNET_TESTBED_Host *host; | 1054 | const struct GNUNET_TESTBED_Host *host; |
1034 | 1055 | ||
1035 | /* /\** */ | ||
1036 | /* * the configuration handle to lookup the path of the testbed helper */ | ||
1037 | /* *\/ */ | ||
1038 | /* const struct GNUNET_CONFIGURATION_Handle *cfg; */ | ||
1039 | |||
1040 | /** | 1056 | /** |
1041 | * The callback to call once we have the status | 1057 | * The callback to call once we have the status |
1042 | */ | 1058 | */ |