diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-10-12 13:40:16 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-10-12 13:40:16 +0000 |
commit | 7401d3bfb5eabc3f730b4f6e56d174796a141d30 (patch) | |
tree | 11e17fa58fa4044e379f606833289fc5161ce95f /src/testbed | |
parent | 2f12d9731c5ed40fc9e503515b15111a29527d9e (diff) | |
download | gnunet-7401d3bfb5eabc3f730b4f6e56d174796a141d30.tar.gz gnunet-7401d3bfb5eabc3f730b4f6e56d174796a141d30.zip |
host registrations in profiler
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/gnunet-testbed-profiler.c | 206 | ||||
-rw-r--r-- | src/testbed/testbed_api.c | 2 |
2 files changed, 180 insertions, 28 deletions
diff --git a/src/testbed/gnunet-testbed-profiler.c b/src/testbed/gnunet-testbed-profiler.c index 56b06a501..4247bbebf 100644 --- a/src/testbed/gnunet-testbed-profiler.c +++ b/src/testbed/gnunet-testbed-profiler.c | |||
@@ -29,6 +29,38 @@ | |||
29 | #include "gnunet_testbed_service.h" | 29 | #include "gnunet_testbed_service.h" |
30 | #include "testbed_api_hosts.h" | 30 | #include "testbed_api_hosts.h" |
31 | 31 | ||
32 | /** | ||
33 | * Generic loggins shorthand | ||
34 | */ | ||
35 | #define LOG(kind,...) \ | ||
36 | GNUNET_log_from (kind, "testbed-api-testbed", __VA_ARGS__) | ||
37 | |||
38 | /** | ||
39 | * DLL of operations | ||
40 | */ | ||
41 | struct DLLOperation | ||
42 | { | ||
43 | /** | ||
44 | * The testbed operation handle | ||
45 | */ | ||
46 | struct GNUNET_TESTBED_Operation *op; | ||
47 | |||
48 | /** | ||
49 | * Closure | ||
50 | */ | ||
51 | void *cls; | ||
52 | |||
53 | /** | ||
54 | * The next pointer for DLL | ||
55 | */ | ||
56 | struct DLLOperation *next; | ||
57 | |||
58 | /** | ||
59 | * The prev pointer for DLL | ||
60 | */ | ||
61 | struct DLLOperation *prev; | ||
62 | }; | ||
63 | |||
32 | 64 | ||
33 | /** | 65 | /** |
34 | * An array of hosts loaded from the hostkeys file | 66 | * An array of hosts loaded from the hostkeys file |
@@ -46,11 +78,41 @@ static struct GNUNET_TESTBED_Peer **peers; | |||
46 | static struct GNUNET_TESTBED_Operation *op; | 78 | static struct GNUNET_TESTBED_Operation *op; |
47 | 79 | ||
48 | /** | 80 | /** |
81 | * Host registration handle | ||
82 | */ | ||
83 | static struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle; | ||
84 | |||
85 | /** | ||
86 | * Handle to the master controller process | ||
87 | */ | ||
88 | struct GNUNET_TESTBED_ControllerProc *mc_proc; | ||
89 | |||
90 | /** | ||
91 | * Handle to the master controller | ||
92 | */ | ||
93 | struct GNUNET_TESTBED_Controller *mc; | ||
94 | |||
95 | /** | ||
96 | * Handle to global configuration | ||
97 | */ | ||
98 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
99 | |||
100 | /** | ||
49 | * Abort task identifier | 101 | * Abort task identifier |
50 | */ | 102 | */ |
51 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; | 103 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; |
52 | 104 | ||
53 | /** | 105 | /** |
106 | * Host registration task identifier | ||
107 | */ | ||
108 | static GNUNET_SCHEDULER_TaskIdentifier register_hosts_task; | ||
109 | |||
110 | /** | ||
111 | * Global event mask for all testbed events | ||
112 | */ | ||
113 | uint64_t event_mask; | ||
114 | |||
115 | /** | ||
54 | * Current peer id | 116 | * Current peer id |
55 | */ | 117 | */ |
56 | unsigned int peer_id; | 118 | unsigned int peer_id; |
@@ -84,12 +146,20 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
84 | 146 | ||
85 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) | 147 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) |
86 | GNUNET_SCHEDULER_cancel (abort_task); | 148 | GNUNET_SCHEDULER_cancel (abort_task); |
149 | if (GNUNET_SCHEDULER_NO_TASK != register_hosts_task) | ||
150 | GNUNET_SCHEDULER_cancel (register_hosts_task); | ||
87 | GNUNET_free_non_null (peers); | 151 | GNUNET_free_non_null (peers); |
152 | if (NULL != reg_handle) | ||
153 | GNUNET_TESTBED_cancel_registration (reg_handle); | ||
88 | for (nhost = 0; nhost < num_hosts; nhost++) | 154 | for (nhost = 0; nhost < num_hosts; nhost++) |
89 | if (NULL != hosts[nhost]) | 155 | if (NULL != hosts[nhost]) |
90 | GNUNET_TESTBED_host_destroy (hosts[nhost]); | 156 | GNUNET_TESTBED_host_destroy (hosts[nhost]); |
91 | GNUNET_free_non_null (hosts); | 157 | GNUNET_free_non_null (hosts); |
92 | GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */ | 158 | if (NULL != mc_proc) |
159 | GNUNET_TESTBED_controller_stop (mc_proc); | ||
160 | if (NULL != cfg) | ||
161 | GNUNET_CONFIGURATION_destroy (cfg); | ||
162 | GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */ | ||
93 | } | 163 | } |
94 | 164 | ||
95 | 165 | ||
@@ -102,29 +172,14 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
102 | static void | 172 | static void |
103 | do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 173 | do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
104 | { | 174 | { |
105 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Profiling timedout -- Aborting\n"); | 175 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting\n"); |
106 | abort_task = GNUNET_SCHEDULER_NO_TASK; | 176 | abort_task = GNUNET_SCHEDULER_NO_TASK; |
177 | result = GNUNET_SYSERR; | ||
107 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 178 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
108 | } | 179 | } |
109 | 180 | ||
110 | 181 | ||
111 | /** | 182 | /** |
112 | * Task to be executed when peers are ready | ||
113 | * | ||
114 | * @param cls NULL | ||
115 | * @param tc the task context | ||
116 | */ | ||
117 | static void | ||
118 | master_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
119 | { | ||
120 | result = GNUNET_OK; | ||
121 | GNUNET_assert (NULL != peers[0]); | ||
122 | op = GNUNET_TESTBED_peer_stop (peers[0], NULL, NULL); | ||
123 | GNUNET_assert (NULL != op); | ||
124 | } | ||
125 | |||
126 | |||
127 | /** | ||
128 | * Controller event callback | 183 | * Controller event callback |
129 | * | 184 | * |
130 | * @param cls NULL | 185 | * @param cls NULL |
@@ -155,6 +210,101 @@ controller_event_cb (void *cls, | |||
155 | 210 | ||
156 | 211 | ||
157 | /** | 212 | /** |
213 | * Task to register all hosts available in the global host list | ||
214 | * | ||
215 | * @param cls NULL | ||
216 | * @param tc the scheduler task context | ||
217 | */ | ||
218 | static void | ||
219 | register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
220 | |||
221 | |||
222 | /** | ||
223 | * Callback which will be called to after a host registration succeeded or failed | ||
224 | * | ||
225 | * @param cls the closure | ||
226 | * @param emsg the error message; NULL if host registration is successful | ||
227 | */ | ||
228 | static void | ||
229 | host_registration_completion (void *cls, const char *emsg) | ||
230 | { | ||
231 | reg_handle = NULL; | ||
232 | if (NULL != emsg) | ||
233 | { | ||
234 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
235 | _("Host registration failed for a host. Error: %s\n"), emsg); | ||
236 | GNUNET_SCHEDULER_cancel (abort_task); | ||
237 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); | ||
238 | return; | ||
239 | } | ||
240 | register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, NULL); | ||
241 | } | ||
242 | |||
243 | |||
244 | /** | ||
245 | * Task to register all hosts available in the global host list | ||
246 | * | ||
247 | * @param cls NULL | ||
248 | * @param tc the scheduler task context | ||
249 | */ | ||
250 | static void | ||
251 | register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
252 | { | ||
253 | static unsigned int reg_host; | ||
254 | |||
255 | register_hosts_task = GNUNET_SCHEDULER_NO_TASK; | ||
256 | if (reg_host == num_hosts) | ||
257 | { | ||
258 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
259 | "All hosts successfully registered\n"); | ||
260 | /* Start peer create task */ | ||
261 | } | ||
262 | reg_handle = GNUNET_TESTBED_register_host (mc, hosts[reg_host++], | ||
263 | host_registration_completion, | ||
264 | NULL); | ||
265 | } | ||
266 | |||
267 | |||
268 | /** | ||
269 | * Callback to signal successfull startup of the controller process | ||
270 | * | ||
271 | * @param cls the closure from GNUNET_TESTBED_controller_start() | ||
272 | * @param cfg the configuration with which the controller has been started; | ||
273 | * NULL if status is not GNUNET_OK | ||
274 | * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not, | ||
275 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case | ||
276 | */ | ||
277 | static void | ||
278 | status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int status) | ||
279 | { | ||
280 | GNUNET_SCHEDULER_cancel (abort_task); | ||
281 | if (GNUNET_OK != status) | ||
282 | { | ||
283 | mc_proc = NULL; | ||
284 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); | ||
285 | return; | ||
286 | } | ||
287 | event_mask = 0; | ||
288 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); | ||
289 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); | ||
290 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); | ||
291 | event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT); | ||
292 | mc = GNUNET_TESTBED_controller_connect (config, hosts[0], event_mask, | ||
293 | &controller_event_cb, NULL); | ||
294 | if (NULL == mc) | ||
295 | { | ||
296 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
297 | _("Unable to connect to master controller -- Check config\n")); | ||
298 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); | ||
299 | return; | ||
300 | } | ||
301 | register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, NULL); | ||
302 | abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | ||
303 | &do_abort, NULL); | ||
304 | } | ||
305 | |||
306 | |||
307 | /** | ||
158 | * Main function that will be run by the scheduler. | 308 | * Main function that will be run by the scheduler. |
159 | * | 309 | * |
160 | * @param cls closure | 310 | * @param cls closure |
@@ -166,7 +316,6 @@ static void | |||
166 | run (void *cls, char *const *args, const char *cfgfile, | 316 | run (void *cls, char *const *args, const char *cfgfile, |
167 | const struct GNUNET_CONFIGURATION_Handle *config) | 317 | const struct GNUNET_CONFIGURATION_Handle *config) |
168 | { | 318 | { |
169 | uint64_t event_mask; | ||
170 | unsigned int nhost; | 319 | unsigned int nhost; |
171 | 320 | ||
172 | if (NULL == args[0]) | 321 | if (NULL == args[0]) |
@@ -182,7 +331,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
182 | num_hosts = GNUNET_TESTBED_hosts_load_from_file (args[0], &hosts); | 331 | num_hosts = GNUNET_TESTBED_hosts_load_from_file (args[0], &hosts); |
183 | if (0 == num_hosts) | 332 | if (0 == num_hosts) |
184 | { | 333 | { |
185 | fprintf (stderr, _("No hosts loaded\n")); | 334 | fprintf (stderr, _("No hosts loaded. Need atleast one host\n")); |
186 | return; | 335 | return; |
187 | } | 336 | } |
188 | for (nhost = 0; nhost < num_hosts; nhost++) | 337 | for (nhost = 0; nhost < num_hosts; nhost++) |
@@ -196,17 +345,18 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
196 | } | 345 | } |
197 | if (num_hosts != nhost) | 346 | if (num_hosts != nhost) |
198 | { | 347 | { |
348 | fprintf (stderr, _("Exiting\n")); | ||
199 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 349 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
200 | return; | 350 | return; |
201 | } | 351 | } |
202 | peers = GNUNET_malloc (num_peers * sizeof (struct GNUNET_TESTBED_Peer *)); | 352 | cfg = GNUNET_CONFIGURATION_dup (config); |
203 | event_mask = 0; | 353 | mc_proc = |
204 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); | 354 | GNUNET_TESTBED_controller_start (GNUNET_TESTBED_host_get_hostname_ |
205 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); | 355 | (hosts[0]), |
206 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); | 356 | hosts[0], |
207 | event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT); | 357 | cfg, |
208 | GNUNET_TESTBED_run (NULL, config, num_peers, event_mask, &controller_event_cb, | 358 | status_cb, |
209 | NULL, &master_task, NULL); | 359 | NULL); |
210 | abort_task = | 360 | abort_task = |
211 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 361 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
212 | (GNUNET_TIME_UNIT_SECONDS, 5), &do_abort, | 362 | (GNUNET_TIME_UNIT_SECONDS, 5), &do_abort, |
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 1c5d01342..7cd536497 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -1683,6 +1683,8 @@ GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller | |||
1683 | memcpy (&msg[1], service_name, service_name_size); | 1683 | memcpy (&msg[1], service_name, service_name_size); |
1684 | GNUNET_TESTBED_queue_message_ (controller, | 1684 | GNUNET_TESTBED_queue_message_ (controller, |
1685 | (struct GNUNET_MessageHeader *) msg); | 1685 | (struct GNUNET_MessageHeader *) msg); |
1686 | GNUNET_break (0); /* This function is not yet implemented on the | ||
1687 | testbed service */ | ||
1686 | } | 1688 | } |
1687 | 1689 | ||
1688 | 1690 | ||