diff options
Diffstat (limited to 'src/testbed/testbed_api_hosts.c')
-rw-r--r-- | src/testbed/testbed_api_hosts.c | 1053 |
1 files changed, 529 insertions, 524 deletions
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c index cbcfe1a18..fdff952a0 100644 --- a/src/testbed/testbed_api_hosts.c +++ b/src/testbed/testbed_api_hosts.c | |||
@@ -42,24 +42,24 @@ | |||
42 | /** | 42 | /** |
43 | * Generic logging shorthand | 43 | * Generic logging shorthand |
44 | */ | 44 | */ |
45 | #define LOG(kind, ...) GNUNET_log_from(kind, "testbed-api-hosts", __VA_ARGS__); | 45 | #define LOG(kind, ...) GNUNET_log_from (kind, "testbed-api-hosts", __VA_ARGS__); |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Debug logging shorthand | 48 | * Debug logging shorthand |
49 | */ | 49 | */ |
50 | #define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__); | 50 | #define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__); |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * Prints API violation message | 53 | * Prints API violation message |
54 | */ | 54 | */ |
55 | #define API_VIOLATION(cond, errstr) \ | 55 | #define API_VIOLATION(cond, errstr) \ |
56 | do \ | 56 | do \ |
57 | { \ | 57 | { \ |
58 | if (cond) \ | 58 | if (cond) \ |
59 | break; \ | 59 | break; \ |
60 | LOG (GNUNET_ERROR_TYPE_ERROR, "API violation detected: %s\n", errstr); \ | 60 | LOG (GNUNET_ERROR_TYPE_ERROR, "API violation detected: %s\n", errstr); \ |
61 | GNUNET_assert(0); \ | 61 | GNUNET_assert (0); \ |
62 | } while (0) | 62 | } while (0) |
63 | 63 | ||
64 | /** | 64 | /** |
65 | * Log an error message at log-level 'level' that indicates a failure of the | 65 | * Log an error message at log-level 'level' that indicates a failure of the |
@@ -67,14 +67,14 @@ | |||
67 | */ | 67 | */ |
68 | #define LOG_GAI(level, cmd, rc) \ | 68 | #define LOG_GAI(level, cmd, rc) \ |
69 | do \ | 69 | do \ |
70 | { \ | 70 | { \ |
71 | LOG(level, \ | 71 | LOG (level, \ |
72 | _("`%s' failed at %s:%d with error: %s\n"), \ | 72 | _ ("`%s' failed at %s:%d with error: %s\n"), \ |
73 | cmd, \ | 73 | cmd, \ |
74 | __FILE__, \ | 74 | __FILE__, \ |
75 | __LINE__, \ | 75 | __LINE__, \ |
76 | gai_strerror(rc)); \ | 76 | gai_strerror (rc)); \ |
77 | } while (0) | 77 | } while (0) |
78 | 78 | ||
79 | /** | 79 | /** |
80 | * Number of extra elements we create space for when we grow host list | 80 | * Number of extra elements we create space for when we grow host list |
@@ -85,7 +85,8 @@ | |||
85 | /** | 85 | /** |
86 | * A list entry for registered controllers list | 86 | * A list entry for registered controllers list |
87 | */ | 87 | */ |
88 | struct RegisteredController { | 88 | struct RegisteredController |
89 | { | ||
89 | /** | 90 | /** |
90 | * The controller at which this host is registered | 91 | * The controller at which this host is registered |
91 | */ | 92 | */ |
@@ -108,7 +109,8 @@ struct RegisteredController { | |||
108 | * The master process must be able to SSH to this host without password (via | 109 | * The master process must be able to SSH to this host without password (via |
109 | * ssh-agent). | 110 | * ssh-agent). |
110 | */ | 111 | */ |
111 | struct GNUNET_TESTBED_Host { | 112 | struct GNUNET_TESTBED_Host |
113 | { | ||
112 | /** | 114 | /** |
113 | * The hostname of the host; NULL for localhost | 115 | * The hostname of the host; NULL for localhost |
114 | */ | 116 | */ |
@@ -184,7 +186,7 @@ static unsigned int host_list_size; | |||
184 | * @return handle to the host, NULL if host not found | 186 | * @return handle to the host, NULL if host not found |
185 | */ | 187 | */ |
186 | struct GNUNET_TESTBED_Host * | 188 | struct GNUNET_TESTBED_Host * |
187 | GNUNET_TESTBED_host_lookup_by_id_(uint32_t id) | 189 | GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id) |
188 | { | 190 | { |
189 | if (host_list_size <= id) | 191 | if (host_list_size <= id) |
190 | return NULL; | 192 | return NULL; |
@@ -205,11 +207,11 @@ GNUNET_TESTBED_host_lookup_by_id_(uint32_t id) | |||
205 | * @return handle to the host, NULL on error | 207 | * @return handle to the host, NULL on error |
206 | */ | 208 | */ |
207 | struct GNUNET_TESTBED_Host * | 209 | struct GNUNET_TESTBED_Host * |
208 | GNUNET_TESTBED_host_create_by_id_( | 210 | GNUNET_TESTBED_host_create_by_id_ ( |
209 | uint32_t id, | 211 | uint32_t id, |
210 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 212 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
211 | { | 213 | { |
212 | return GNUNET_TESTBED_host_create_with_id(id, NULL, NULL, cfg, 0); | 214 | return GNUNET_TESTBED_host_create_with_id (id, NULL, NULL, cfg, 0); |
213 | } | 215 | } |
214 | 216 | ||
215 | 217 | ||
@@ -221,7 +223,7 @@ GNUNET_TESTBED_host_create_by_id_( | |||
221 | * 'localhost', but then obviously not globally unique) | 223 | * 'localhost', but then obviously not globally unique) |
222 | */ | 224 | */ |
223 | uint32_t | 225 | uint32_t |
224 | GNUNET_TESTBED_host_get_id_(const struct GNUNET_TESTBED_Host *host) | 226 | GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host) |
225 | { | 227 | { |
226 | return host->id; | 228 | return host->id; |
227 | } | 229 | } |
@@ -234,7 +236,7 @@ GNUNET_TESTBED_host_get_id_(const struct GNUNET_TESTBED_Host *host) | |||
234 | * @return hostname of the host | 236 | * @return hostname of the host |
235 | */ | 237 | */ |
236 | const char * | 238 | const char * |
237 | GNUNET_TESTBED_host_get_hostname(const struct GNUNET_TESTBED_Host *host) | 239 | GNUNET_TESTBED_host_get_hostname (const struct GNUNET_TESTBED_Host *host) |
238 | { | 240 | { |
239 | return host->hostname; | 241 | return host->hostname; |
240 | } | 242 | } |
@@ -247,7 +249,7 @@ GNUNET_TESTBED_host_get_hostname(const struct GNUNET_TESTBED_Host *host) | |||
247 | * @return username to login to the host | 249 | * @return username to login to the host |
248 | */ | 250 | */ |
249 | const char * | 251 | const char * |
250 | GNUNET_TESTBED_host_get_username_(const struct GNUNET_TESTBED_Host *host) | 252 | GNUNET_TESTBED_host_get_username_ (const struct GNUNET_TESTBED_Host *host) |
251 | { | 253 | { |
252 | return host->username; | 254 | return host->username; |
253 | } | 255 | } |
@@ -260,7 +262,7 @@ GNUNET_TESTBED_host_get_username_(const struct GNUNET_TESTBED_Host *host) | |||
260 | * @return username to login to the host | 262 | * @return username to login to the host |
261 | */ | 263 | */ |
262 | uint16_t | 264 | uint16_t |
263 | GNUNET_TESTBED_host_get_ssh_port_(const struct GNUNET_TESTBED_Host *host) | 265 | GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host *host) |
264 | { | 266 | { |
265 | return host->port; | 267 | return host->port; |
266 | } | 268 | } |
@@ -273,7 +275,7 @@ GNUNET_TESTBED_host_get_ssh_port_(const struct GNUNET_TESTBED_Host *host) | |||
273 | * @return GNUNET_YES if the controller is already started; GNUNET_NO if not | 275 | * @return GNUNET_YES if the controller is already started; GNUNET_NO if not |
274 | */ | 276 | */ |
275 | int | 277 | int |
276 | GNUNET_TESTBED_host_controller_started(const struct GNUNET_TESTBED_Host *host) | 278 | GNUNET_TESTBED_host_controller_started (const struct GNUNET_TESTBED_Host *host) |
277 | { | 279 | { |
278 | return host->controller_started; | 280 | return host->controller_started; |
279 | } | 281 | } |
@@ -286,7 +288,7 @@ GNUNET_TESTBED_host_controller_started(const struct GNUNET_TESTBED_Host *host) | |||
286 | * @return the host's configuration template | 288 | * @return the host's configuration template |
287 | */ | 289 | */ |
288 | const struct GNUNET_CONFIGURATION_Handle * | 290 | const struct GNUNET_CONFIGURATION_Handle * |
289 | GNUNET_TESTBED_host_get_cfg_(const struct GNUNET_TESTBED_Host *host) | 291 | GNUNET_TESTBED_host_get_cfg_ (const struct GNUNET_TESTBED_Host *host) |
290 | { | 292 | { |
291 | return host->cfg; | 293 | return host->cfg; |
292 | } | 294 | } |
@@ -299,12 +301,12 @@ GNUNET_TESTBED_host_get_cfg_(const struct GNUNET_TESTBED_Host *host) | |||
299 | * @param new_cfg the new configuration to replace the old one | 301 | * @param new_cfg the new configuration to replace the old one |
300 | */ | 302 | */ |
301 | void | 303 | void |
302 | GNUNET_TESTBED_host_replace_cfg_( | 304 | GNUNET_TESTBED_host_replace_cfg_ ( |
303 | struct GNUNET_TESTBED_Host *host, | 305 | struct GNUNET_TESTBED_Host *host, |
304 | const struct GNUNET_CONFIGURATION_Handle *new_cfg) | 306 | const struct GNUNET_CONFIGURATION_Handle *new_cfg) |
305 | { | 307 | { |
306 | GNUNET_CONFIGURATION_destroy(host->cfg); | 308 | GNUNET_CONFIGURATION_destroy (host->cfg); |
307 | host->cfg = GNUNET_CONFIGURATION_dup(new_cfg); | 309 | host->cfg = GNUNET_CONFIGURATION_dup (new_cfg); |
308 | } | 310 | } |
309 | 311 | ||
310 | 312 | ||
@@ -322,7 +324,7 @@ GNUNET_TESTBED_host_replace_cfg_( | |||
322 | * @return handle to the host, NULL on error | 324 | * @return handle to the host, NULL on error |
323 | */ | 325 | */ |
324 | struct GNUNET_TESTBED_Host * | 326 | struct GNUNET_TESTBED_Host * |
325 | GNUNET_TESTBED_host_create_with_id( | 327 | GNUNET_TESTBED_host_create_with_id ( |
326 | uint32_t id, | 328 | uint32_t id, |
327 | const char *hostname, | 329 | const char *hostname, |
328 | const char *username, | 330 | const char *username, |
@@ -333,26 +335,26 @@ GNUNET_TESTBED_host_create_with_id( | |||
333 | unsigned int new_size; | 335 | unsigned int new_size; |
334 | 336 | ||
335 | if ((id < host_list_size) && (NULL != host_list[id])) | 337 | if ((id < host_list_size) && (NULL != host_list[id])) |
336 | { | 338 | { |
337 | LOG(GNUNET_ERROR_TYPE_WARNING, "Host with id: %u already created\n", id); | 339 | LOG (GNUNET_ERROR_TYPE_WARNING, "Host with id: %u already created\n", id); |
338 | return NULL; | 340 | return NULL; |
339 | } | 341 | } |
340 | host = GNUNET_new(struct GNUNET_TESTBED_Host); | 342 | host = GNUNET_new (struct GNUNET_TESTBED_Host); |
341 | host->hostname = (NULL != hostname) ? GNUNET_strdup(hostname) : NULL; | 343 | host->hostname = (NULL != hostname) ? GNUNET_strdup (hostname) : NULL; |
342 | host->username = (NULL != username) ? GNUNET_strdup(username) : NULL; | 344 | host->username = (NULL != username) ? GNUNET_strdup (username) : NULL; |
343 | host->id = id; | 345 | host->id = id; |
344 | host->port = (0 == port) ? 22 : port; | 346 | host->port = (0 == port) ? 22 : port; |
345 | host->cfg = GNUNET_CONFIGURATION_dup(cfg); | 347 | host->cfg = GNUNET_CONFIGURATION_dup (cfg); |
346 | host->opq_parallel_overlay_connect_operations = | 348 | host->opq_parallel_overlay_connect_operations = |
347 | GNUNET_TESTBED_operation_queue_create_(OPERATION_QUEUE_TYPE_ADAPTIVE, | 349 | GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_ADAPTIVE, |
348 | UINT_MAX); | 350 | UINT_MAX); |
349 | new_size = host_list_size; | 351 | new_size = host_list_size; |
350 | while (id >= new_size) | 352 | while (id >= new_size) |
351 | new_size += HOST_LIST_GROW_STEP; | 353 | new_size += HOST_LIST_GROW_STEP; |
352 | if (new_size != host_list_size) | 354 | if (new_size != host_list_size) |
353 | GNUNET_array_grow(host_list, host_list_size, new_size); | 355 | GNUNET_array_grow (host_list, host_list_size, new_size); |
354 | GNUNET_assert(id < host_list_size); | 356 | GNUNET_assert (id < host_list_size); |
355 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Adding host with id: %u\n", host->id); | 357 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding host with id: %u\n", host->id); |
356 | host_list[id] = host; | 358 | host_list[id] = host; |
357 | return host; | 359 | return host; |
358 | } | 360 | } |
@@ -370,24 +372,24 @@ GNUNET_TESTBED_host_create_with_id( | |||
370 | * @return handle to the host, NULL on error | 372 | * @return handle to the host, NULL on error |
371 | */ | 373 | */ |
372 | struct GNUNET_TESTBED_Host * | 374 | struct GNUNET_TESTBED_Host * |
373 | GNUNET_TESTBED_host_create(const char *hostname, | 375 | GNUNET_TESTBED_host_create (const char *hostname, |
374 | const char *username, | 376 | const char *username, |
375 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 377 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
376 | uint16_t port) | 378 | uint16_t port) |
377 | { | 379 | { |
378 | static uint32_t uid_generator; | 380 | static uint32_t uid_generator; |
379 | 381 | ||
380 | if (NULL == hostname) | 382 | if (NULL == hostname) |
381 | return GNUNET_TESTBED_host_create_with_id(0, | 383 | return GNUNET_TESTBED_host_create_with_id (0, |
382 | hostname, | 384 | hostname, |
383 | username, | 385 | username, |
384 | cfg, | 386 | cfg, |
385 | port); | 387 | port); |
386 | return GNUNET_TESTBED_host_create_with_id(++uid_generator, | 388 | return GNUNET_TESTBED_host_create_with_id (++uid_generator, |
387 | hostname, | 389 | hostname, |
388 | username, | 390 | username, |
389 | cfg, | 391 | cfg, |
390 | port); | 392 | port); |
391 | } | 393 | } |
392 | 394 | ||
393 | 395 | ||
@@ -403,7 +405,7 @@ GNUNET_TESTBED_host_create(const char *hostname, | |||
403 | * @return number of hosts returned in 'hosts', 0 on error | 405 | * @return number of hosts returned in 'hosts', 0 on error |
404 | */ | 406 | */ |
405 | unsigned int | 407 | unsigned int |
406 | GNUNET_TESTBED_hosts_load_from_file( | 408 | GNUNET_TESTBED_hosts_load_from_file ( |
407 | const char *filename, | 409 | const char *filename, |
408 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 410 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
409 | struct GNUNET_TESTBED_Host ***hosts) | 411 | struct GNUNET_TESTBED_Host ***hosts) |
@@ -421,104 +423,104 @@ GNUNET_TESTBED_hosts_load_from_file( | |||
421 | unsigned int count; | 423 | unsigned int count; |
422 | 424 | ||
423 | 425 | ||
424 | GNUNET_assert(NULL != filename); | 426 | GNUNET_assert (NULL != filename); |
425 | if (GNUNET_YES != GNUNET_DISK_file_test(filename)) | 427 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) |
426 | { | 428 | { |
427 | LOG(GNUNET_ERROR_TYPE_WARNING, _("Hosts file %s not found\n"), filename); | 429 | LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Hosts file %s not found\n"), filename); |
428 | return 0; | 430 | return 0; |
429 | } | 431 | } |
430 | if (GNUNET_OK != | 432 | if (GNUNET_OK != |
431 | GNUNET_DISK_file_size(filename, &fs, GNUNET_YES, GNUNET_YES)) | 433 | GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) |
432 | fs = 0; | 434 | fs = 0; |
433 | if (0 == fs) | 435 | if (0 == fs) |
434 | { | 436 | { |
435 | LOG(GNUNET_ERROR_TYPE_WARNING, | 437 | LOG (GNUNET_ERROR_TYPE_WARNING, |
436 | _("Hosts file %s has no data\n"), | 438 | _ ("Hosts file %s has no data\n"), |
437 | filename); | 439 | filename); |
438 | return 0; | 440 | return 0; |
439 | } | 441 | } |
440 | data = GNUNET_malloc(fs); | 442 | data = GNUNET_malloc (fs); |
441 | if (fs != GNUNET_DISK_fn_read(filename, data, fs)) | 443 | if (fs != GNUNET_DISK_fn_read (filename, data, fs)) |
442 | { | 444 | { |
443 | GNUNET_free(data); | 445 | GNUNET_free (data); |
444 | LOG(GNUNET_ERROR_TYPE_WARNING, | 446 | LOG (GNUNET_ERROR_TYPE_WARNING, |
445 | _("Hosts file %s cannot be read\n"), | 447 | _ ("Hosts file %s cannot be read\n"), |
446 | filename); | 448 | filename); |
447 | return 0; | 449 | return 0; |
448 | } | 450 | } |
449 | buf = data; | 451 | buf = data; |
450 | offset = 0; | 452 | offset = 0; |
451 | starting_host = NULL; | 453 | starting_host = NULL; |
452 | count = 0; | 454 | count = 0; |
453 | /* refer RFC 952 and RFC 1123 for valid hostnames */ | 455 | /* refer RFC 952 and RFC 1123 for valid hostnames */ |
454 | GNUNET_assert(0 == regcomp(&rex, | 456 | GNUNET_assert (0 == regcomp (&rex, |
455 | "^(([[:alnum:]]+)@)?" /* username */ | 457 | "^(([[:alnum:]]+)@)?" /* username */ |
456 | "([[:alnum:]]+[-[:alnum:]_\\.]+)" /* hostname */ | 458 | "([[:alnum:]]+[-[:alnum:]_\\.]+)" /* hostname */ |
457 | "(:([[:digit:]]{1,5}))?", /* port */ | 459 | "(:([[:digit:]]{1,5}))?", /* port */ |
458 | REG_EXTENDED | REG_ICASE)); | 460 | REG_EXTENDED | REG_ICASE)); |
459 | while (offset < (fs - 1)) | 461 | while (offset < (fs - 1)) |
462 | { | ||
463 | offset++; | ||
464 | if (((data[offset] == '\n')) && (buf != &data[offset])) | ||
460 | { | 465 | { |
461 | offset++; | 466 | unsigned int size; |
462 | if (((data[offset] == '\n')) && (buf != &data[offset])) | 467 | |
463 | { | 468 | data[offset] = '\0'; |
464 | unsigned int size; | 469 | username = NULL; |
465 | 470 | hostname = NULL; | |
466 | data[offset] = '\0'; | 471 | port = 0; |
467 | username = NULL; | 472 | if ((REG_NOMATCH == regexec (&rex, buf, 6, pmatch, 0)) || |
468 | hostname = NULL; | 473 | (-1 == pmatch[3].rm_so)) |
469 | port = 0; | 474 | { |
470 | if ((REG_NOMATCH == regexec(&rex, buf, 6, pmatch, 0)) || | 475 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
471 | (-1 == pmatch[3].rm_so)) | 476 | "Error reading line `%s' in hostfile\n", |
472 | { | 477 | buf); |
473 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
474 | "Error reading line `%s' in hostfile\n", | ||
475 | buf); | ||
476 | buf = &data[offset + 1]; | ||
477 | continue; | ||
478 | } | ||
479 | if (-1 != pmatch[2].rm_so) | ||
480 | { | ||
481 | size = pmatch[2].rm_eo - pmatch[2].rm_so; | ||
482 | username = GNUNET_malloc(size + 1); | ||
483 | GNUNET_assert( | ||
484 | 0 != GNUNET_strlcpy(username, buf + pmatch[2].rm_so, size + 1)); | ||
485 | } | ||
486 | if (-1 != pmatch[5].rm_so) | ||
487 | { | ||
488 | (void)sscanf(buf + pmatch[5].rm_so, "%5hd", &port); | ||
489 | } | ||
490 | size = pmatch[3].rm_eo - pmatch[3].rm_so; | ||
491 | hostname = GNUNET_malloc(size + 1); | ||
492 | GNUNET_assert( | ||
493 | 0 != GNUNET_strlcpy(hostname, buf + pmatch[3].rm_so, size + 1)); | ||
494 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
495 | "Successfully read host %s, port %d and user %s from file\n", | ||
496 | (NULL == hostname) ? "NULL" : hostname, | ||
497 | port, | ||
498 | (NULL == username) ? "NULL" : username); | ||
499 | /* We store hosts in a static list; hence we only require the starting | ||
500 | * host pointer in that list to access the newly created list of hosts */ | ||
501 | if (NULL == starting_host) | ||
502 | starting_host = | ||
503 | GNUNET_TESTBED_host_create(hostname, username, cfg, port); | ||
504 | else | ||
505 | (void)GNUNET_TESTBED_host_create(hostname, username, cfg, port); | ||
506 | count++; | ||
507 | GNUNET_free_non_null(username); | ||
508 | GNUNET_free(hostname); | ||
509 | buf = &data[offset + 1]; | ||
510 | } | ||
511 | else if ((data[offset] == '\n') || (data[offset] == '\0')) | ||
512 | buf = &data[offset + 1]; | 478 | buf = &data[offset + 1]; |
479 | continue; | ||
480 | } | ||
481 | if (-1 != pmatch[2].rm_so) | ||
482 | { | ||
483 | size = pmatch[2].rm_eo - pmatch[2].rm_so; | ||
484 | username = GNUNET_malloc (size + 1); | ||
485 | GNUNET_assert ( | ||
486 | 0 != GNUNET_strlcpy (username, buf + pmatch[2].rm_so, size + 1)); | ||
487 | } | ||
488 | if (-1 != pmatch[5].rm_so) | ||
489 | { | ||
490 | (void) sscanf (buf + pmatch[5].rm_so, "%5hd", &port); | ||
491 | } | ||
492 | size = pmatch[3].rm_eo - pmatch[3].rm_so; | ||
493 | hostname = GNUNET_malloc (size + 1); | ||
494 | GNUNET_assert ( | ||
495 | 0 != GNUNET_strlcpy (hostname, buf + pmatch[3].rm_so, size + 1)); | ||
496 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
497 | "Successfully read host %s, port %d and user %s from file\n", | ||
498 | (NULL == hostname) ? "NULL" : hostname, | ||
499 | port, | ||
500 | (NULL == username) ? "NULL" : username); | ||
501 | /* We store hosts in a static list; hence we only require the starting | ||
502 | * host pointer in that list to access the newly created list of hosts */ | ||
503 | if (NULL == starting_host) | ||
504 | starting_host = | ||
505 | GNUNET_TESTBED_host_create (hostname, username, cfg, port); | ||
506 | else | ||
507 | (void) GNUNET_TESTBED_host_create (hostname, username, cfg, port); | ||
508 | count++; | ||
509 | GNUNET_free_non_null (username); | ||
510 | GNUNET_free (hostname); | ||
511 | buf = &data[offset + 1]; | ||
513 | } | 512 | } |
514 | regfree(&rex); | 513 | else if ((data[offset] == '\n') || (data[offset] == '\0')) |
515 | GNUNET_free(data); | 514 | buf = &data[offset + 1]; |
515 | } | ||
516 | regfree (&rex); | ||
517 | GNUNET_free (data); | ||
516 | if (NULL == starting_host) | 518 | if (NULL == starting_host) |
517 | return 0; | 519 | return 0; |
518 | *hosts = GNUNET_malloc(sizeof(struct GNUNET_TESTBED_Host *) * count); | 520 | *hosts = GNUNET_malloc (sizeof(struct GNUNET_TESTBED_Host *) * count); |
519 | GNUNET_memcpy(*hosts, | 521 | GNUNET_memcpy (*hosts, |
520 | &host_list[GNUNET_TESTBED_host_get_id_(starting_host)], | 522 | &host_list[GNUNET_TESTBED_host_get_id_ (starting_host)], |
521 | sizeof(struct GNUNET_TESTBED_Host *) * count); | 523 | sizeof(struct GNUNET_TESTBED_Host *) * count); |
522 | return count; | 524 | return count; |
523 | } | 525 | } |
524 | 526 | ||
@@ -530,7 +532,7 @@ GNUNET_TESTBED_hosts_load_from_file( | |||
530 | * @return the string representing the IPv4 address of the given host; NULL upon error | 532 | * @return the string representing the IPv4 address of the given host; NULL upon error |
531 | */ | 533 | */ |
532 | const char * | 534 | const char * |
533 | simple_resolve(const char *host) | 535 | simple_resolve (const char *host) |
534 | { | 536 | { |
535 | struct addrinfo *res; | 537 | struct addrinfo *res; |
536 | const struct sockaddr_in *in_addr; | 538 | const struct sockaddr_in *in_addr; |
@@ -547,20 +549,20 @@ simple_resolve(const char *host) | |||
547 | hint.ai_next = NULL; | 549 | hint.ai_next = NULL; |
548 | hint.ai_flags = AI_NUMERICSERV; | 550 | hint.ai_flags = AI_NUMERICSERV; |
549 | res = NULL; | 551 | res = NULL; |
550 | LOG_DEBUG("Resolving [%s]\n", host); | 552 | LOG_DEBUG ("Resolving [%s]\n", host); |
551 | if (0 != (rc = getaddrinfo(host, "22", &hint, &res))) | 553 | if (0 != (rc = getaddrinfo (host, "22", &hint, &res))) |
552 | { | 554 | { |
553 | LOG_GAI(GNUNET_ERROR_TYPE_ERROR, "getaddrinfo", rc); | 555 | LOG_GAI (GNUNET_ERROR_TYPE_ERROR, "getaddrinfo", rc); |
554 | return NULL; | 556 | return NULL; |
555 | } | 557 | } |
556 | GNUNET_assert(NULL != res); | 558 | GNUNET_assert (NULL != res); |
557 | GNUNET_assert(NULL != res->ai_addr); | 559 | GNUNET_assert (NULL != res->ai_addr); |
558 | GNUNET_assert(sizeof(struct sockaddr_in) == res->ai_addrlen); | 560 | GNUNET_assert (sizeof(struct sockaddr_in) == res->ai_addrlen); |
559 | in_addr = (const struct sockaddr_in *)res->ai_addr; | 561 | in_addr = (const struct sockaddr_in *) res->ai_addr; |
560 | hostip = inet_ntoa(in_addr->sin_addr); | 562 | hostip = inet_ntoa (in_addr->sin_addr); |
561 | GNUNET_assert(NULL != hostip); | 563 | GNUNET_assert (NULL != hostip); |
562 | freeaddrinfo(res); | 564 | freeaddrinfo (res); |
563 | LOG_DEBUG("Resolved [%s] to [%s]\n", host, hostip); | 565 | LOG_DEBUG ("Resolved [%s] to [%s]\n", host, hostip); |
564 | return hostip; | 566 | return hostip; |
565 | } | 567 | } |
566 | 568 | ||
@@ -578,24 +580,24 @@ simple_resolve(const char *host) | |||
578 | * @return number of hosts returned in 'hosts', 0 on error | 580 | * @return number of hosts returned in 'hosts', 0 on error |
579 | */ | 581 | */ |
580 | unsigned int | 582 | unsigned int |
581 | GNUNET_TESTBED_hosts_load_from_loadleveler( | 583 | GNUNET_TESTBED_hosts_load_from_loadleveler ( |
582 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 584 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
583 | struct GNUNET_TESTBED_Host ***hosts) | 585 | struct GNUNET_TESTBED_Host ***hosts) |
584 | { | 586 | { |
585 | #if !ENABLE_SUPERMUC | 587 | #if ! ENABLE_SUPERMUC |
586 | LOG(GNUNET_ERROR_TYPE_ERROR, | 588 | LOG (GNUNET_ERROR_TYPE_ERROR, |
587 | _("The function %s is only available when compiled with (--with-ll)\n"), | 589 | _ ("The function %s is only available when compiled with (--with-ll)\n"), |
588 | __func__); | 590 | __func__); |
589 | GNUNET_assert(0); | 591 | GNUNET_assert (0); |
590 | #else | 592 | #else |
591 | const char *hostfile; | 593 | const char *hostfile; |
592 | 594 | ||
593 | if (NULL == (hostfile = getenv("MP_SAVEHOSTFILE"))) | 595 | if (NULL == (hostfile = getenv ("MP_SAVEHOSTFILE"))) |
594 | { | 596 | { |
595 | GNUNET_break(0); | 597 | GNUNET_break (0); |
596 | return 0; | 598 | return 0; |
597 | } | 599 | } |
598 | return GNUNET_TESTBED_hosts_load_from_file(hostfile, cfg, hosts); | 600 | return GNUNET_TESTBED_hosts_load_from_file (hostfile, cfg, hosts); |
599 | #endif | 601 | #endif |
600 | } | 602 | } |
601 | 603 | ||
@@ -607,41 +609,41 @@ GNUNET_TESTBED_hosts_load_from_loadleveler( | |||
607 | * @param host handle to destroy | 609 | * @param host handle to destroy |
608 | */ | 610 | */ |
609 | void | 611 | void |
610 | GNUNET_TESTBED_host_destroy(struct GNUNET_TESTBED_Host *host) | 612 | GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host) |
611 | { | 613 | { |
612 | struct RegisteredController *rc; | 614 | struct RegisteredController *rc; |
613 | uint32_t id; | 615 | uint32_t id; |
614 | 616 | ||
615 | GNUNET_assert(host->id < host_list_size); | 617 | GNUNET_assert (host->id < host_list_size); |
616 | GNUNET_assert(host_list[host->id] == host); | 618 | GNUNET_assert (host_list[host->id] == host); |
617 | host_list[host->id] = NULL; | 619 | host_list[host->id] = NULL; |
618 | /* clear registered controllers list */ | 620 | /* clear registered controllers list */ |
619 | for (rc = host->rc_head; NULL != rc; rc = host->rc_head) | 621 | for (rc = host->rc_head; NULL != rc; rc = host->rc_head) |
620 | { | 622 | { |
621 | GNUNET_CONTAINER_DLL_remove(host->rc_head, host->rc_tail, rc); | 623 | GNUNET_CONTAINER_DLL_remove (host->rc_head, host->rc_tail, rc); |
622 | GNUNET_free(rc); | 624 | GNUNET_free (rc); |
623 | } | 625 | } |
624 | GNUNET_free_non_null((char *)host->username); | 626 | GNUNET_free_non_null ((char *) host->username); |
625 | GNUNET_free_non_null((char *)host->hostname); | 627 | GNUNET_free_non_null ((char *) host->hostname); |
626 | GNUNET_TESTBED_operation_queue_destroy_( | 628 | GNUNET_TESTBED_operation_queue_destroy_ ( |
627 | host->opq_parallel_overlay_connect_operations); | 629 | host->opq_parallel_overlay_connect_operations); |
628 | GNUNET_CONFIGURATION_destroy(host->cfg); | 630 | GNUNET_CONFIGURATION_destroy (host->cfg); |
629 | GNUNET_free(host); | 631 | GNUNET_free (host); |
630 | while (host_list_size >= HOST_LIST_GROW_STEP) | 632 | while (host_list_size >= HOST_LIST_GROW_STEP) |
631 | { | 633 | { |
632 | for (id = host_list_size - 1; id > host_list_size - HOST_LIST_GROW_STEP; | 634 | for (id = host_list_size - 1; id > host_list_size - HOST_LIST_GROW_STEP; |
633 | id--) | 635 | id--) |
634 | if (NULL != host_list[id]) | ||
635 | break; | ||
636 | if (id != host_list_size - HOST_LIST_GROW_STEP) | ||
637 | break; | ||
638 | if (NULL != host_list[id]) | 636 | if (NULL != host_list[id]) |
639 | break; | 637 | break; |
640 | host_list_size -= HOST_LIST_GROW_STEP; | 638 | if (id != host_list_size - HOST_LIST_GROW_STEP) |
641 | } | 639 | break; |
640 | if (NULL != host_list[id]) | ||
641 | break; | ||
642 | host_list_size -= HOST_LIST_GROW_STEP; | ||
643 | } | ||
642 | host_list = | 644 | host_list = |
643 | GNUNET_realloc(host_list, | 645 | GNUNET_realloc (host_list, |
644 | sizeof(struct GNUNET_TESTBED_Host *) * host_list_size); | 646 | sizeof(struct GNUNET_TESTBED_Host *) * host_list_size); |
645 | } | 647 | } |
646 | 648 | ||
647 | 649 | ||
@@ -652,23 +654,23 @@ GNUNET_TESTBED_host_destroy(struct GNUNET_TESTBED_Host *host) | |||
652 | * @param controller the controller at which this host is registered | 654 | * @param controller the controller at which this host is registered |
653 | */ | 655 | */ |
654 | void | 656 | void |
655 | GNUNET_TESTBED_mark_host_registered_at_( | 657 | GNUNET_TESTBED_mark_host_registered_at_ ( |
656 | struct GNUNET_TESTBED_Host *host, | 658 | struct GNUNET_TESTBED_Host *host, |
657 | const struct GNUNET_TESTBED_Controller *const controller) | 659 | const struct GNUNET_TESTBED_Controller *const controller) |
658 | { | 660 | { |
659 | struct RegisteredController *rc; | 661 | struct RegisteredController *rc; |
660 | 662 | ||
661 | for (rc = host->rc_head; NULL != rc; rc = rc->next) | 663 | for (rc = host->rc_head; NULL != rc; rc = rc->next) |
664 | { | ||
665 | if (controller == rc->controller) /* already registered at controller */ | ||
662 | { | 666 | { |
663 | if (controller == rc->controller) /* already registered at controller */ | 667 | GNUNET_break (0); |
664 | { | 668 | return; |
665 | GNUNET_break(0); | ||
666 | return; | ||
667 | } | ||
668 | } | 669 | } |
669 | rc = GNUNET_new(struct RegisteredController); | 670 | } |
671 | rc = GNUNET_new (struct RegisteredController); | ||
670 | rc->controller = controller; | 672 | rc->controller = controller; |
671 | GNUNET_CONTAINER_DLL_insert_tail(host->rc_head, host->rc_tail, rc); | 673 | GNUNET_CONTAINER_DLL_insert_tail (host->rc_head, host->rc_tail, rc); |
672 | } | 674 | } |
673 | 675 | ||
674 | 676 | ||
@@ -679,7 +681,7 @@ GNUNET_TESTBED_mark_host_registered_at_( | |||
679 | * @param controller the controller at which this host has to be unmarked | 681 | * @param controller the controller at which this host has to be unmarked |
680 | */ | 682 | */ |
681 | void | 683 | void |
682 | GNUNET_TESTBED_deregister_host_at_( | 684 | GNUNET_TESTBED_deregister_host_at_ ( |
683 | struct GNUNET_TESTBED_Host *host, | 685 | struct GNUNET_TESTBED_Host *host, |
684 | const struct GNUNET_TESTBED_Controller *const controller) | 686 | const struct GNUNET_TESTBED_Controller *const controller) |
685 | { | 687 | { |
@@ -689,12 +691,12 @@ GNUNET_TESTBED_deregister_host_at_( | |||
689 | if (controller == rc->controller) | 691 | if (controller == rc->controller) |
690 | break; | 692 | break; |
691 | if (NULL == rc) | 693 | if (NULL == rc) |
692 | { | 694 | { |
693 | GNUNET_break(0); | 695 | GNUNET_break (0); |
694 | return; | 696 | return; |
695 | } | 697 | } |
696 | GNUNET_CONTAINER_DLL_remove(host->rc_head, host->rc_tail, rc); | 698 | GNUNET_CONTAINER_DLL_remove (host->rc_head, host->rc_tail, rc); |
697 | GNUNET_free(rc); | 699 | GNUNET_free (rc); |
698 | } | 700 | } |
699 | 701 | ||
700 | 702 | ||
@@ -706,19 +708,19 @@ GNUNET_TESTBED_deregister_host_at_( | |||
706 | * @return GNUNET_YES if registered; GNUNET_NO if not | 708 | * @return GNUNET_YES if registered; GNUNET_NO if not |
707 | */ | 709 | */ |
708 | int | 710 | int |
709 | GNUNET_TESTBED_is_host_registered_( | 711 | GNUNET_TESTBED_is_host_registered_ ( |
710 | const struct GNUNET_TESTBED_Host *host, | 712 | const struct GNUNET_TESTBED_Host *host, |
711 | const struct GNUNET_TESTBED_Controller *const controller) | 713 | const struct GNUNET_TESTBED_Controller *const controller) |
712 | { | 714 | { |
713 | struct RegisteredController *rc; | 715 | struct RegisteredController *rc; |
714 | 716 | ||
715 | for (rc = host->rc_head; NULL != rc; rc = rc->next) | 717 | for (rc = host->rc_head; NULL != rc; rc = rc->next) |
718 | { | ||
719 | if (controller == rc->controller) /* already registered at controller */ | ||
716 | { | 720 | { |
717 | if (controller == rc->controller) /* already registered at controller */ | 721 | return GNUNET_YES; |
718 | { | ||
719 | return GNUNET_YES; | ||
720 | } | ||
721 | } | 722 | } |
723 | } | ||
722 | return GNUNET_NO; | 724 | return GNUNET_NO; |
723 | } | 725 | } |
724 | 726 | ||
@@ -726,7 +728,8 @@ GNUNET_TESTBED_is_host_registered_( | |||
726 | /** | 728 | /** |
727 | * Handle for controller process | 729 | * Handle for controller process |
728 | */ | 730 | */ |
729 | struct GNUNET_TESTBED_ControllerProc { | 731 | struct GNUNET_TESTBED_ControllerProc |
732 | { | ||
730 | /** | 733 | /** |
731 | * The process handle | 734 | * The process handle |
732 | */ | 735 | */ |
@@ -771,17 +774,17 @@ struct GNUNET_TESTBED_ControllerProc { | |||
771 | * @return the copied NULL terminated arguments | 774 | * @return the copied NULL terminated arguments |
772 | */ | 775 | */ |
773 | static char ** | 776 | static char ** |
774 | copy_argv(const char *const *argv) | 777 | copy_argv (const char *const *argv) |
775 | { | 778 | { |
776 | char **argv_dup; | 779 | char **argv_dup; |
777 | unsigned int argp; | 780 | unsigned int argp; |
778 | 781 | ||
779 | GNUNET_assert(NULL != argv); | 782 | GNUNET_assert (NULL != argv); |
780 | for (argp = 0; NULL != argv[argp]; argp++) | 783 | for (argp = 0; NULL != argv[argp]; argp++) |
781 | ; | 784 | ; |
782 | argv_dup = GNUNET_malloc(sizeof(char *) * (argp + 1)); | 785 | argv_dup = GNUNET_malloc (sizeof(char *) * (argp + 1)); |
783 | for (argp = 0; NULL != argv[argp]; argp++) | 786 | for (argp = 0; NULL != argv[argp]; argp++) |
784 | argv_dup[argp] = GNUNET_strdup(argv[argp]); | 787 | argv_dup[argp] = GNUNET_strdup (argv[argp]); |
785 | return argv_dup; | 788 | return argv_dup; |
786 | } | 789 | } |
787 | 790 | ||
@@ -794,7 +797,7 @@ copy_argv(const char *const *argv) | |||
794 | * @return the joined NULL terminated arguments | 797 | * @return the joined NULL terminated arguments |
795 | */ | 798 | */ |
796 | static char ** | 799 | static char ** |
797 | join_argv(const char *const *argv1, const char *const *argv2) | 800 | join_argv (const char *const *argv1, const char *const *argv2) |
798 | { | 801 | { |
799 | char **argvj; | 802 | char **argvj; |
800 | char *argv; | 803 | char *argv; |
@@ -804,16 +807,16 @@ join_argv(const char *const *argv1, const char *const *argv2) | |||
804 | carg = 0; | 807 | carg = 0; |
805 | argvj = NULL; | 808 | argvj = NULL; |
806 | for (cnt = 0; NULL != argv1[cnt]; cnt++) | 809 | for (cnt = 0; NULL != argv1[cnt]; cnt++) |
807 | { | 810 | { |
808 | argv = GNUNET_strdup(argv1[cnt]); | 811 | argv = GNUNET_strdup (argv1[cnt]); |
809 | GNUNET_array_append(argvj, carg, argv); | 812 | GNUNET_array_append (argvj, carg, argv); |
810 | } | 813 | } |
811 | for (cnt = 0; NULL != argv2[cnt]; cnt++) | 814 | for (cnt = 0; NULL != argv2[cnt]; cnt++) |
812 | { | 815 | { |
813 | argv = GNUNET_strdup(argv2[cnt]); | 816 | argv = GNUNET_strdup (argv2[cnt]); |
814 | GNUNET_array_append(argvj, carg, argv); | 817 | GNUNET_array_append (argvj, carg, argv); |
815 | } | 818 | } |
816 | GNUNET_array_append(argvj, carg, NULL); | 819 | GNUNET_array_append (argvj, carg, NULL); |
817 | return argvj; | 820 | return argvj; |
818 | } | 821 | } |
819 | 822 | ||
@@ -824,13 +827,13 @@ join_argv(const char *const *argv1, const char *const *argv2) | |||
824 | * @param argv the NULL terminated list of arguments | 827 | * @param argv the NULL terminated list of arguments |
825 | */ | 828 | */ |
826 | static void | 829 | static void |
827 | free_argv(char **argv) | 830 | free_argv (char **argv) |
828 | { | 831 | { |
829 | unsigned int argp; | 832 | unsigned int argp; |
830 | 833 | ||
831 | for (argp = 0; NULL != argv[argp]; argp++) | 834 | for (argp = 0; NULL != argv[argp]; argp++) |
832 | GNUNET_free(argv[argp]); | 835 | GNUNET_free (argv[argp]); |
833 | GNUNET_free(argv); | 836 | GNUNET_free (argv); |
834 | } | 837 | } |
835 | 838 | ||
836 | 839 | ||
@@ -849,7 +852,7 @@ free_argv(char **argv) | |||
849 | * @return NULL terminated list of arguments | 852 | * @return NULL terminated list of arguments |
850 | */ | 853 | */ |
851 | static char ** | 854 | static char ** |
852 | gen_rsh_args(const char *port, const char *hostname, const char *username) | 855 | gen_rsh_args (const char *port, const char *hostname, const char *username) |
853 | { | 856 | { |
854 | static const char *default_ssh_args[] = | 857 | static const char *default_ssh_args[] = |
855 | { "ssh", | 858 | { "ssh", |
@@ -872,48 +875,48 @@ gen_rsh_args(const char *port, const char *hostname, const char *username) | |||
872 | unsigned int cnt; | 875 | unsigned int cnt; |
873 | 876 | ||
874 | ssh_args = NULL; | 877 | ssh_args = NULL; |
875 | if (NULL != (ssh_cmd = getenv("GNUNET_TESTBED_RSH_CMD"))) | 878 | if (NULL != (ssh_cmd = getenv ("GNUNET_TESTBED_RSH_CMD"))) |
876 | { | 879 | { |
877 | ssh_cmd = GNUNET_strdup(ssh_cmd); | 880 | ssh_cmd = GNUNET_strdup (ssh_cmd); |
878 | ssh_cmd_cp = ssh_cmd; | 881 | ssh_cmd_cp = ssh_cmd; |
879 | for (size = 0; NULL != (arg = strtok(ssh_cmd, " ")); ssh_cmd = NULL) | 882 | for (size = 0; NULL != (arg = strtok (ssh_cmd, " ")); ssh_cmd = NULL) |
880 | GNUNET_array_append(ssh_args, size, GNUNET_strdup(arg)); | 883 | GNUNET_array_append (ssh_args, size, GNUNET_strdup (arg)); |
881 | GNUNET_free(ssh_cmd_cp); | 884 | GNUNET_free (ssh_cmd_cp); |
882 | } | 885 | } |
883 | else | 886 | else |
884 | { | 887 | { |
885 | ssh_args = copy_argv(default_ssh_args); | 888 | ssh_args = copy_argv (default_ssh_args); |
886 | size = (sizeof(default_ssh_args)) / (sizeof(const char *)); | 889 | size = (sizeof(default_ssh_args)) / (sizeof(const char *)); |
887 | GNUNET_array_grow(ssh_args, size, size - 1); | 890 | GNUNET_array_grow (ssh_args, size, size - 1); |
888 | } | 891 | } |
889 | for (cnt = 0; cnt < size; cnt++) | 892 | for (cnt = 0; cnt < size; cnt++) |
893 | { | ||
894 | arg = ssh_args[cnt]; | ||
895 | if ('%' != arg[0]) | ||
896 | continue; | ||
897 | switch (arg[1]) | ||
890 | { | 898 | { |
891 | arg = ssh_args[cnt]; | 899 | case 'p': |
892 | if ('%' != arg[0]) | 900 | new_arg = port; |
893 | continue; | 901 | break; |
894 | switch (arg[1]) | 902 | |
895 | { | 903 | case 'u': |
896 | case 'p': | 904 | new_arg = username; |
897 | new_arg = port; | 905 | break; |
898 | break; | 906 | |
899 | 907 | case 'h': | |
900 | case 'u': | 908 | new_arg = hostname; |
901 | new_arg = username; | 909 | break; |
902 | break; | 910 | |
903 | 911 | default: | |
904 | case 'h': | 912 | continue; |
905 | new_arg = hostname; | ||
906 | break; | ||
907 | |||
908 | default: | ||
909 | continue; | ||
910 | } | ||
911 | if (NULL == new_arg) | ||
912 | continue; | ||
913 | GNUNET_free(arg); | ||
914 | ssh_args[cnt] = GNUNET_strdup(new_arg); | ||
915 | } | 913 | } |
916 | GNUNET_array_append(ssh_args, size, NULL); | 914 | if (NULL == new_arg) |
915 | continue; | ||
916 | GNUNET_free (arg); | ||
917 | ssh_args[cnt] = GNUNET_strdup (new_arg); | ||
918 | } | ||
919 | GNUNET_array_append (ssh_args, size, NULL); | ||
917 | return ssh_args; | 920 | return ssh_args; |
918 | } | 921 | } |
919 | 922 | ||
@@ -929,7 +932,7 @@ gen_rsh_args(const char *port, const char *hostname, const char *username) | |||
929 | * @return NULL-terminated args | 932 | * @return NULL-terminated args |
930 | */ | 933 | */ |
931 | static char ** | 934 | static char ** |
932 | gen_rsh_suffix_args(const char *const *append_args) | 935 | gen_rsh_suffix_args (const char *const *append_args) |
933 | { | 936 | { |
934 | char **rshell_args; | 937 | char **rshell_args; |
935 | char *rshell_cmd; | 938 | char *rshell_cmd; |
@@ -940,22 +943,22 @@ gen_rsh_suffix_args(const char *const *append_args) | |||
940 | 943 | ||
941 | rshell_args = NULL; | 944 | rshell_args = NULL; |
942 | cnt = 0; | 945 | cnt = 0; |
943 | if (NULL != (rshell_cmd = getenv("GNUNET_TESTBED_RSH_CMD_SUFFIX"))) | 946 | if (NULL != (rshell_cmd = getenv ("GNUNET_TESTBED_RSH_CMD_SUFFIX"))) |
944 | { | 947 | { |
945 | rshell_cmd = GNUNET_strdup(rshell_cmd); | 948 | rshell_cmd = GNUNET_strdup (rshell_cmd); |
946 | rshell_cmd_cp = rshell_cmd; | 949 | rshell_cmd_cp = rshell_cmd; |
947 | for (; NULL != (arg = strtok(rshell_cmd, " ")); rshell_cmd = NULL) | 950 | for (; NULL != (arg = strtok (rshell_cmd, " ")); rshell_cmd = NULL) |
948 | GNUNET_array_append(rshell_args, cnt, GNUNET_strdup(arg)); | 951 | GNUNET_array_append (rshell_args, cnt, GNUNET_strdup (arg)); |
949 | GNUNET_free(rshell_cmd_cp); | 952 | GNUNET_free (rshell_cmd_cp); |
950 | } | 953 | } |
951 | if (NULL != append_args) | 954 | if (NULL != append_args) |
952 | { | 955 | { |
953 | for (append_cnt = 0; NULL != append_args[append_cnt]; append_cnt++) | 956 | for (append_cnt = 0; NULL != append_args[append_cnt]; append_cnt++) |
954 | GNUNET_array_append(rshell_args, | 957 | GNUNET_array_append (rshell_args, |
955 | cnt, | 958 | cnt, |
956 | GNUNET_strdup(append_args[append_cnt])); | 959 | GNUNET_strdup (append_args[append_cnt])); |
957 | } | 960 | } |
958 | GNUNET_array_append(rshell_args, cnt, NULL); | 961 | GNUNET_array_append (rshell_args, cnt, NULL); |
959 | return rshell_args; | 962 | return rshell_args; |
960 | } | 963 | } |
961 | 964 | ||
@@ -973,7 +976,7 @@ gen_rsh_suffix_args(const char *const *append_args) | |||
973 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing | 976 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing |
974 | */ | 977 | */ |
975 | static int | 978 | static int |
976 | helper_mst(void *cls, const struct GNUNET_MessageHeader *message) | 979 | helper_mst (void *cls, const struct GNUNET_MessageHeader *message) |
977 | { | 980 | { |
978 | struct GNUNET_TESTBED_ControllerProc *cp = cls; | 981 | struct GNUNET_TESTBED_ControllerProc *cp = cls; |
979 | const struct GNUNET_TESTBED_HelperReply *msg; | 982 | const struct GNUNET_TESTBED_HelperReply *msg; |
@@ -982,38 +985,38 @@ helper_mst(void *cls, const struct GNUNET_MessageHeader *message) | |||
982 | uLongf config_size; | 985 | uLongf config_size; |
983 | uLongf xconfig_size; | 986 | uLongf xconfig_size; |
984 | 987 | ||
985 | msg = (const struct GNUNET_TESTBED_HelperReply *)message; | 988 | msg = (const struct GNUNET_TESTBED_HelperReply *) message; |
986 | GNUNET_assert(sizeof(struct GNUNET_TESTBED_HelperReply) < | 989 | GNUNET_assert (sizeof(struct GNUNET_TESTBED_HelperReply) < |
987 | ntohs(msg->header.size)); | 990 | ntohs (msg->header.size)); |
988 | GNUNET_assert(GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY == | 991 | GNUNET_assert (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY == |
989 | ntohs(msg->header.type)); | 992 | ntohs (msg->header.type)); |
990 | config_size = (uLongf)ntohs(msg->config_size); | 993 | config_size = (uLongf) ntohs (msg->config_size); |
991 | xconfig_size = (uLongf)(ntohs(msg->header.size) - | 994 | xconfig_size = (uLongf) (ntohs (msg->header.size) |
992 | sizeof(struct GNUNET_TESTBED_HelperReply)); | 995 | - sizeof(struct GNUNET_TESTBED_HelperReply)); |
993 | config = GNUNET_malloc(config_size); | 996 | config = GNUNET_malloc (config_size); |
994 | GNUNET_assert(Z_OK == uncompress((Bytef *)config, | 997 | GNUNET_assert (Z_OK == uncompress ((Bytef *) config, |
995 | &config_size, | 998 | &config_size, |
996 | (const Bytef *)&msg[1], | 999 | (const Bytef *) &msg[1], |
997 | xconfig_size)); | 1000 | xconfig_size)); |
998 | /* Replace the configuration template present in the host with the | 1001 | /* Replace the configuration template present in the host with the |
999 | controller's running configuration */ | 1002 | controller's running configuration */ |
1000 | GNUNET_CONFIGURATION_destroy(cp->host->cfg); | 1003 | GNUNET_CONFIGURATION_destroy (cp->host->cfg); |
1001 | cp->host->cfg = GNUNET_CONFIGURATION_create(); | 1004 | cp->host->cfg = GNUNET_CONFIGURATION_create (); |
1002 | GNUNET_assert(GNUNET_CONFIGURATION_deserialize(cp->host->cfg, | 1005 | GNUNET_assert (GNUNET_CONFIGURATION_deserialize (cp->host->cfg, |
1003 | config, | 1006 | config, |
1004 | config_size, | 1007 | config_size, |
1005 | NULL)); | 1008 | NULL)); |
1006 | GNUNET_free(config); | 1009 | GNUNET_free (config); |
1007 | if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname(cp->host))) | 1010 | if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host))) |
1008 | hostname = "localhost"; | 1011 | hostname = "localhost"; |
1009 | /* Change the hostname so that we can connect to it */ | 1012 | /* Change the hostname so that we can connect to it */ |
1010 | GNUNET_CONFIGURATION_set_value_string(cp->host->cfg, | 1013 | GNUNET_CONFIGURATION_set_value_string (cp->host->cfg, |
1011 | "testbed", | 1014 | "testbed", |
1012 | "hostname", | 1015 | "hostname", |
1013 | hostname); | 1016 | hostname); |
1014 | cp->host->locked = GNUNET_NO; | 1017 | cp->host->locked = GNUNET_NO; |
1015 | cp->host->controller_started = GNUNET_YES; | 1018 | cp->host->controller_started = GNUNET_YES; |
1016 | cp->cb(cp->cls, cp->host->cfg, GNUNET_OK); | 1019 | cp->cb (cp->cls, cp->host->cfg, GNUNET_OK); |
1017 | return GNUNET_OK; | 1020 | return GNUNET_OK; |
1018 | } | 1021 | } |
1019 | 1022 | ||
@@ -1027,13 +1030,13 @@ helper_mst(void *cls, const struct GNUNET_MessageHeader *message) | |||
1027 | * GNUNET_SYSERR during GNUNET_HELPER_stop | 1030 | * GNUNET_SYSERR during GNUNET_HELPER_stop |
1028 | */ | 1031 | */ |
1029 | static void | 1032 | static void |
1030 | clear_msg(void *cls, int result) | 1033 | clear_msg (void *cls, int result) |
1031 | { | 1034 | { |
1032 | struct GNUNET_TESTBED_ControllerProc *cp = cls; | 1035 | struct GNUNET_TESTBED_ControllerProc *cp = cls; |
1033 | 1036 | ||
1034 | GNUNET_assert(NULL != cp->shandle); | 1037 | GNUNET_assert (NULL != cp->shandle); |
1035 | cp->shandle = NULL; | 1038 | cp->shandle = NULL; |
1036 | GNUNET_free(cp->msg); | 1039 | GNUNET_free (cp->msg); |
1037 | cp->msg = NULL; | 1040 | cp->msg = NULL; |
1038 | } | 1041 | } |
1039 | 1042 | ||
@@ -1045,7 +1048,7 @@ clear_msg(void *cls, int result) | |||
1045 | * @param cls the closure from GNUNET_HELPER_start() | 1048 | * @param cls the closure from GNUNET_HELPER_start() |
1046 | */ | 1049 | */ |
1047 | static void | 1050 | static void |
1048 | helper_exp_cb(void *cls) | 1051 | helper_exp_cb (void *cls) |
1049 | { | 1052 | { |
1050 | struct GNUNET_TESTBED_ControllerProc *cp = cls; | 1053 | struct GNUNET_TESTBED_ControllerProc *cp = cls; |
1051 | GNUNET_TESTBED_ControllerStatusCallback cb; | 1054 | GNUNET_TESTBED_ControllerStatusCallback cb; |
@@ -1054,9 +1057,9 @@ helper_exp_cb(void *cls) | |||
1054 | cb = cp->cb; | 1057 | cb = cp->cb; |
1055 | cb_cls = cp->cls; | 1058 | cb_cls = cp->cls; |
1056 | cp->helper = NULL; | 1059 | cp->helper = NULL; |
1057 | GNUNET_TESTBED_controller_stop(cp); | 1060 | GNUNET_TESTBED_controller_stop (cp); |
1058 | if (NULL != cb) | 1061 | if (NULL != cb) |
1059 | cb(cb_cls, NULL, GNUNET_SYSERR); | 1062 | cb (cb_cls, NULL, GNUNET_SYSERR); |
1060 | } | 1063 | } |
1061 | 1064 | ||
1062 | 1065 | ||
@@ -1084,10 +1087,10 @@ helper_exp_cb(void *cls) | |||
1084 | * @return the controller process handle, NULL on errors | 1087 | * @return the controller process handle, NULL on errors |
1085 | */ | 1088 | */ |
1086 | struct GNUNET_TESTBED_ControllerProc * | 1089 | struct GNUNET_TESTBED_ControllerProc * |
1087 | GNUNET_TESTBED_controller_start(const char *trusted_ip, | 1090 | GNUNET_TESTBED_controller_start (const char *trusted_ip, |
1088 | struct GNUNET_TESTBED_Host *host, | 1091 | struct GNUNET_TESTBED_Host *host, |
1089 | GNUNET_TESTBED_ControllerStatusCallback cb, | 1092 | GNUNET_TESTBED_ControllerStatusCallback cb, |
1090 | void *cls) | 1093 | void *cls) |
1091 | { | 1094 | { |
1092 | struct GNUNET_TESTBED_ControllerProc *cp; | 1095 | struct GNUNET_TESTBED_ControllerProc *cp; |
1093 | struct GNUNET_TESTBED_HelperInit *msg; | 1096 | struct GNUNET_TESTBED_HelperInit *msg; |
@@ -1095,95 +1098,95 @@ GNUNET_TESTBED_controller_start(const char *trusted_ip, | |||
1095 | const char *hostname; | 1098 | const char *hostname; |
1096 | static char *const binary_argv[] = { HELPER_TESTBED_BINARY, NULL }; | 1099 | static char *const binary_argv[] = { HELPER_TESTBED_BINARY, NULL }; |
1097 | 1100 | ||
1098 | GNUNET_assert(NULL != host); | 1101 | GNUNET_assert (NULL != host); |
1099 | GNUNET_assert(NULL != (cfg = GNUNET_TESTBED_host_get_cfg_(host))); | 1102 | GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (host))); |
1100 | hostname = NULL; | 1103 | hostname = NULL; |
1101 | API_VIOLATION( | 1104 | API_VIOLATION ( |
1102 | GNUNET_NO == host->locked, | 1105 | GNUNET_NO == host->locked, |
1103 | "Host is already locked by a previous call to GNUNET_TESTBED_controller_start()"); | 1106 | "Host is already locked by a previous call to GNUNET_TESTBED_controller_start()"); |
1104 | host->locked = GNUNET_YES; | 1107 | host->locked = GNUNET_YES; |
1105 | API_VIOLATION( | 1108 | API_VIOLATION ( |
1106 | GNUNET_NO == host->controller_started, | 1109 | GNUNET_NO == host->controller_started, |
1107 | "Attempting to start a controller on a host which is already started a controller"); | 1110 | "Attempting to start a controller on a host which is already started a controller"); |
1108 | cp = GNUNET_new(struct GNUNET_TESTBED_ControllerProc); | 1111 | cp = GNUNET_new (struct GNUNET_TESTBED_ControllerProc); |
1109 | if (0 == GNUNET_TESTBED_host_get_id_(host)) | 1112 | if (0 == GNUNET_TESTBED_host_get_id_ (host)) |
1110 | { | 1113 | { |
1111 | cp->helper = GNUNET_HELPER_start(GNUNET_YES, | 1114 | cp->helper = GNUNET_HELPER_start (GNUNET_YES, |
1112 | HELPER_TESTBED_BINARY, | 1115 | HELPER_TESTBED_BINARY, |
1113 | binary_argv, | 1116 | binary_argv, |
1114 | &helper_mst, | 1117 | &helper_mst, |
1115 | &helper_exp_cb, | 1118 | &helper_exp_cb, |
1116 | cp); | 1119 | cp); |
1117 | } | 1120 | } |
1118 | else | 1121 | else |
1122 | { | ||
1123 | char *helper_binary_path_args[2]; | ||
1124 | char **rsh_args; | ||
1125 | char **rsh_suffix_args; | ||
1126 | const char *username; | ||
1127 | char *port; | ||
1128 | char *argstr; | ||
1129 | char *aux; | ||
1130 | unsigned int cnt; | ||
1131 | |||
1132 | username = host->username; | ||
1133 | hostname = host->hostname; | ||
1134 | GNUNET_asprintf (&port, "%u", host->port); | ||
1135 | LOG_DEBUG ("Starting remote connection to destination %s\n", hostname); | ||
1136 | if (GNUNET_OK != | ||
1137 | GNUNET_CONFIGURATION_get_value_filename (cfg, | ||
1138 | "testbed", | ||
1139 | "HELPER_BINARY_PATH", | ||
1140 | &helper_binary_path_args[0])) | ||
1141 | helper_binary_path_args[0] = | ||
1142 | GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY); | ||
1143 | helper_binary_path_args[1] = NULL; | ||
1144 | rsh_args = gen_rsh_args (port, hostname, username); | ||
1145 | rsh_suffix_args = | ||
1146 | gen_rsh_suffix_args ((const char **) helper_binary_path_args); | ||
1147 | cp->helper_argv = | ||
1148 | join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args); | ||
1149 | free_argv (rsh_args); | ||
1150 | free_argv (rsh_suffix_args); | ||
1151 | GNUNET_free (port); | ||
1152 | argstr = GNUNET_strdup (""); | ||
1153 | for (cnt = 0; NULL != cp->helper_argv[cnt]; cnt++) | ||
1119 | { | 1154 | { |
1120 | char *helper_binary_path_args[2]; | 1155 | aux = argstr; |
1121 | char **rsh_args; | 1156 | GNUNET_assert ( |
1122 | char **rsh_suffix_args; | 1157 | 0 < GNUNET_asprintf (&argstr, "%s %s", aux, cp->helper_argv[cnt])); |
1123 | const char *username; | 1158 | GNUNET_free (aux); |
1124 | char *port; | ||
1125 | char *argstr; | ||
1126 | char *aux; | ||
1127 | unsigned int cnt; | ||
1128 | |||
1129 | username = host->username; | ||
1130 | hostname = host->hostname; | ||
1131 | GNUNET_asprintf(&port, "%u", host->port); | ||
1132 | LOG_DEBUG("Starting remote connection to destination %s\n", hostname); | ||
1133 | if (GNUNET_OK != | ||
1134 | GNUNET_CONFIGURATION_get_value_filename(cfg, | ||
1135 | "testbed", | ||
1136 | "HELPER_BINARY_PATH", | ||
1137 | &helper_binary_path_args[0])) | ||
1138 | helper_binary_path_args[0] = | ||
1139 | GNUNET_OS_get_libexec_binary_path(HELPER_TESTBED_BINARY); | ||
1140 | helper_binary_path_args[1] = NULL; | ||
1141 | rsh_args = gen_rsh_args(port, hostname, username); | ||
1142 | rsh_suffix_args = | ||
1143 | gen_rsh_suffix_args((const char **)helper_binary_path_args); | ||
1144 | cp->helper_argv = | ||
1145 | join_argv((const char **)rsh_args, (const char **)rsh_suffix_args); | ||
1146 | free_argv(rsh_args); | ||
1147 | free_argv(rsh_suffix_args); | ||
1148 | GNUNET_free(port); | ||
1149 | argstr = GNUNET_strdup(""); | ||
1150 | for (cnt = 0; NULL != cp->helper_argv[cnt]; cnt++) | ||
1151 | { | ||
1152 | aux = argstr; | ||
1153 | GNUNET_assert( | ||
1154 | 0 < GNUNET_asprintf(&argstr, "%s %s", aux, cp->helper_argv[cnt])); | ||
1155 | GNUNET_free(aux); | ||
1156 | } | ||
1157 | LOG_DEBUG("Helper cmd str: %s\n", argstr); | ||
1158 | GNUNET_free(argstr); | ||
1159 | cp->helper = GNUNET_HELPER_start(GNUNET_NO, | ||
1160 | cp->helper_argv[0], | ||
1161 | cp->helper_argv, | ||
1162 | &helper_mst, | ||
1163 | &helper_exp_cb, | ||
1164 | cp); | ||
1165 | GNUNET_free(helper_binary_path_args[0]); | ||
1166 | } | 1159 | } |
1160 | LOG_DEBUG ("Helper cmd str: %s\n", argstr); | ||
1161 | GNUNET_free (argstr); | ||
1162 | cp->helper = GNUNET_HELPER_start (GNUNET_NO, | ||
1163 | cp->helper_argv[0], | ||
1164 | cp->helper_argv, | ||
1165 | &helper_mst, | ||
1166 | &helper_exp_cb, | ||
1167 | cp); | ||
1168 | GNUNET_free (helper_binary_path_args[0]); | ||
1169 | } | ||
1167 | if (NULL == cp->helper) | 1170 | if (NULL == cp->helper) |
1168 | { | 1171 | { |
1169 | if (NULL != cp->helper_argv) | 1172 | if (NULL != cp->helper_argv) |
1170 | free_argv(cp->helper_argv); | 1173 | free_argv (cp->helper_argv); |
1171 | GNUNET_free(cp); | 1174 | GNUNET_free (cp); |
1172 | return NULL; | 1175 | return NULL; |
1173 | } | 1176 | } |
1174 | cp->host = host; | 1177 | cp->host = host; |
1175 | cp->cb = cb; | 1178 | cp->cb = cb; |
1176 | cp->cls = cls; | 1179 | cp->cls = cls; |
1177 | msg = GNUNET_TESTBED_create_helper_init_msg_(trusted_ip, hostname, cfg); | 1180 | msg = GNUNET_TESTBED_create_helper_init_msg_ (trusted_ip, hostname, cfg); |
1178 | cp->msg = &msg->header; | 1181 | cp->msg = &msg->header; |
1179 | cp->shandle = | 1182 | cp->shandle = |
1180 | GNUNET_HELPER_send(cp->helper, &msg->header, GNUNET_NO, &clear_msg, cp); | 1183 | GNUNET_HELPER_send (cp->helper, &msg->header, GNUNET_NO, &clear_msg, cp); |
1181 | if (NULL == cp->shandle) | 1184 | if (NULL == cp->shandle) |
1182 | { | 1185 | { |
1183 | GNUNET_free(msg); | 1186 | GNUNET_free (msg); |
1184 | GNUNET_TESTBED_controller_stop(cp); | 1187 | GNUNET_TESTBED_controller_stop (cp); |
1185 | return NULL; | 1188 | return NULL; |
1186 | } | 1189 | } |
1187 | return cp; | 1190 | return cp; |
1188 | } | 1191 | } |
1189 | 1192 | ||
@@ -1194,12 +1197,12 @@ GNUNET_TESTBED_controller_start(const char *trusted_ip, | |||
1194 | * @param cproc the handle to the controller's helper process | 1197 | * @param cproc the handle to the controller's helper process |
1195 | */ | 1198 | */ |
1196 | void | 1199 | void |
1197 | GNUNET_TESTBED_controller_kill_(struct GNUNET_TESTBED_ControllerProc *cproc) | 1200 | GNUNET_TESTBED_controller_kill_ (struct GNUNET_TESTBED_ControllerProc *cproc) |
1198 | { | 1201 | { |
1199 | if (NULL != cproc->shandle) | 1202 | if (NULL != cproc->shandle) |
1200 | GNUNET_HELPER_send_cancel(cproc->shandle); | 1203 | GNUNET_HELPER_send_cancel (cproc->shandle); |
1201 | if (NULL != cproc->helper) | 1204 | if (NULL != cproc->helper) |
1202 | GNUNET_HELPER_kill(cproc->helper, GNUNET_YES); | 1205 | GNUNET_HELPER_kill (cproc->helper, GNUNET_YES); |
1203 | } | 1206 | } |
1204 | 1207 | ||
1205 | 1208 | ||
@@ -1209,19 +1212,19 @@ GNUNET_TESTBED_controller_kill_(struct GNUNET_TESTBED_ControllerProc *cproc) | |||
1209 | * @param cproc the handle to the controller's helper process | 1212 | * @param cproc the handle to the controller's helper process |
1210 | */ | 1213 | */ |
1211 | void | 1214 | void |
1212 | GNUNET_TESTBED_controller_destroy_(struct GNUNET_TESTBED_ControllerProc *cproc) | 1215 | GNUNET_TESTBED_controller_destroy_ (struct GNUNET_TESTBED_ControllerProc *cproc) |
1213 | { | 1216 | { |
1214 | if (NULL != cproc->helper) | 1217 | if (NULL != cproc->helper) |
1215 | { | 1218 | { |
1216 | GNUNET_break(GNUNET_OK == GNUNET_HELPER_wait(cproc->helper)); | 1219 | GNUNET_break (GNUNET_OK == GNUNET_HELPER_wait (cproc->helper)); |
1217 | GNUNET_HELPER_destroy(cproc->helper); | 1220 | GNUNET_HELPER_destroy (cproc->helper); |
1218 | } | 1221 | } |
1219 | if (NULL != cproc->helper_argv) | 1222 | if (NULL != cproc->helper_argv) |
1220 | free_argv(cproc->helper_argv); | 1223 | free_argv (cproc->helper_argv); |
1221 | cproc->host->controller_started = GNUNET_NO; | 1224 | cproc->host->controller_started = GNUNET_NO; |
1222 | cproc->host->locked = GNUNET_NO; | 1225 | cproc->host->locked = GNUNET_NO; |
1223 | GNUNET_free_non_null(cproc->msg); | 1226 | GNUNET_free_non_null (cproc->msg); |
1224 | GNUNET_free(cproc); | 1227 | GNUNET_free (cproc); |
1225 | } | 1228 | } |
1226 | 1229 | ||
1227 | 1230 | ||
@@ -1234,17 +1237,18 @@ GNUNET_TESTBED_controller_destroy_(struct GNUNET_TESTBED_ControllerProc *cproc) | |||
1234 | * @param cproc the controller process handle | 1237 | * @param cproc the controller process handle |
1235 | */ | 1238 | */ |
1236 | void | 1239 | void |
1237 | GNUNET_TESTBED_controller_stop(struct GNUNET_TESTBED_ControllerProc *cproc) | 1240 | GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc) |
1238 | { | 1241 | { |
1239 | GNUNET_TESTBED_controller_kill_(cproc); | 1242 | GNUNET_TESTBED_controller_kill_ (cproc); |
1240 | GNUNET_TESTBED_controller_destroy_(cproc); | 1243 | GNUNET_TESTBED_controller_destroy_ (cproc); |
1241 | } | 1244 | } |
1242 | 1245 | ||
1243 | 1246 | ||
1244 | /** | 1247 | /** |
1245 | * The handle for whether a host is habitable or not | 1248 | * The handle for whether a host is habitable or not |
1246 | */ | 1249 | */ |
1247 | struct GNUNET_TESTBED_HostHabitableCheckHandle { | 1250 | struct GNUNET_TESTBED_HostHabitableCheckHandle |
1251 | { | ||
1248 | /** | 1252 | /** |
1249 | * The host to check | 1253 | * The host to check |
1250 | */ | 1254 | */ |
@@ -1289,7 +1293,7 @@ struct GNUNET_TESTBED_HostHabitableCheckHandle { | |||
1289 | * @param cls GNUNET_TESTBED_HostHabitableCheckHandle | 1293 | * @param cls GNUNET_TESTBED_HostHabitableCheckHandle |
1290 | */ | 1294 | */ |
1291 | static void | 1295 | static void |
1292 | habitability_check(void *cls) | 1296 | habitability_check (void *cls) |
1293 | { | 1297 | { |
1294 | struct GNUNET_TESTBED_HostHabitableCheckHandle *h = cls; | 1298 | struct GNUNET_TESTBED_HostHabitableCheckHandle *h = cls; |
1295 | void *cb_cls; | 1299 | void *cb_cls; |
@@ -1300,34 +1304,34 @@ habitability_check(void *cls) | |||
1300 | int ret; | 1304 | int ret; |
1301 | 1305 | ||
1302 | h->habitability_check_task = NULL; | 1306 | h->habitability_check_task = NULL; |
1303 | ret = GNUNET_OS_process_status(h->auxp, &type, &code); | 1307 | ret = GNUNET_OS_process_status (h->auxp, &type, &code); |
1304 | if (GNUNET_SYSERR == ret) | 1308 | if (GNUNET_SYSERR == ret) |
1305 | { | 1309 | { |
1306 | GNUNET_break(0); | 1310 | GNUNET_break (0); |
1307 | ret = GNUNET_NO; | 1311 | ret = GNUNET_NO; |
1308 | goto call_cb; | 1312 | goto call_cb; |
1309 | } | 1313 | } |
1310 | if (GNUNET_NO == ret) | 1314 | if (GNUNET_NO == ret) |
1311 | { | 1315 | { |
1312 | h->wait_time = GNUNET_TIME_STD_BACKOFF(h->wait_time); | 1316 | h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time); |
1313 | h->habitability_check_task = | 1317 | h->habitability_check_task = |
1314 | GNUNET_SCHEDULER_add_delayed(h->wait_time, &habitability_check, h); | 1318 | GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h); |
1315 | return; | 1319 | return; |
1316 | } | 1320 | } |
1317 | GNUNET_OS_process_destroy(h->auxp); | 1321 | GNUNET_OS_process_destroy (h->auxp); |
1318 | h->auxp = NULL; | 1322 | h->auxp = NULL; |
1319 | ret = (0 != code) ? GNUNET_NO : GNUNET_YES; | 1323 | ret = (0 != code) ? GNUNET_NO : GNUNET_YES; |
1320 | 1324 | ||
1321 | call_cb: | 1325 | call_cb: |
1322 | if (NULL != h->auxp) | 1326 | if (NULL != h->auxp) |
1323 | GNUNET_OS_process_destroy(h->auxp); | 1327 | GNUNET_OS_process_destroy (h->auxp); |
1324 | cb = h->cb; | 1328 | cb = h->cb; |
1325 | cb_cls = h->cb_cls; | 1329 | cb_cls = h->cb_cls; |
1326 | host = h->host; | 1330 | host = h->host; |
1327 | free_argv(h->helper_argv); | 1331 | free_argv (h->helper_argv); |
1328 | GNUNET_free(h); | 1332 | GNUNET_free (h); |
1329 | if (NULL != cb) | 1333 | if (NULL != cb) |
1330 | cb(cb_cls, host, ret); | 1334 | cb (cb_cls, host, ret); |
1331 | } | 1335 | } |
1332 | 1336 | ||
1333 | 1337 | ||
@@ -1343,7 +1347,7 @@ call_cb: | |||
1343 | * GNUNET_TESTBED_is_host_habitable_cancel() | 1347 | * GNUNET_TESTBED_is_host_habitable_cancel() |
1344 | */ | 1348 | */ |
1345 | struct GNUNET_TESTBED_HostHabitableCheckHandle * | 1349 | struct GNUNET_TESTBED_HostHabitableCheckHandle * |
1346 | GNUNET_TESTBED_is_host_habitable( | 1350 | GNUNET_TESTBED_is_host_habitable ( |
1347 | const struct GNUNET_TESTBED_Host *host, | 1351 | const struct GNUNET_TESTBED_Host *host, |
1348 | const struct GNUNET_CONFIGURATION_Handle *config, | 1352 | const struct GNUNET_CONFIGURATION_Handle *config, |
1349 | GNUNET_TESTBED_HostHabitableCallback cb, | 1353 | GNUNET_TESTBED_HostHabitableCallback cb, |
@@ -1356,45 +1360,45 @@ GNUNET_TESTBED_is_host_habitable( | |||
1356 | const char *hostname; | 1360 | const char *hostname; |
1357 | char *port; | 1361 | char *port; |
1358 | 1362 | ||
1359 | h = GNUNET_new(struct GNUNET_TESTBED_HostHabitableCheckHandle); | 1363 | h = GNUNET_new (struct GNUNET_TESTBED_HostHabitableCheckHandle); |
1360 | h->cb = cb; | 1364 | h->cb = cb; |
1361 | h->cb_cls = cb_cls; | 1365 | h->cb_cls = cb_cls; |
1362 | h->host = host; | 1366 | h->host = host; |
1363 | hostname = (NULL == host->hostname) ? "127.0.0.1" : host->hostname; | 1367 | hostname = (NULL == host->hostname) ? "127.0.0.1" : host->hostname; |
1364 | if (GNUNET_OK != | 1368 | if (GNUNET_OK != |
1365 | GNUNET_CONFIGURATION_get_value_filename(config, | 1369 | GNUNET_CONFIGURATION_get_value_filename (config, |
1366 | "testbed", | 1370 | "testbed", |
1367 | "HELPER_BINARY_PATH", | 1371 | "HELPER_BINARY_PATH", |
1368 | &stat_args[1])) | 1372 | &stat_args[1])) |
1369 | stat_args[1] = GNUNET_OS_get_libexec_binary_path(HELPER_TESTBED_BINARY); | 1373 | stat_args[1] = GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY); |
1370 | GNUNET_asprintf(&port, "%u", host->port); | 1374 | GNUNET_asprintf (&port, "%u", host->port); |
1371 | rsh_args = gen_rsh_args(port, hostname, host->username); | 1375 | rsh_args = gen_rsh_args (port, hostname, host->username); |
1372 | GNUNET_free(port); | 1376 | GNUNET_free (port); |
1373 | port = NULL; | 1377 | port = NULL; |
1374 | stat_args[0] = "stat"; | 1378 | stat_args[0] = "stat"; |
1375 | stat_args[2] = NULL; | 1379 | stat_args[2] = NULL; |
1376 | rsh_suffix_args = gen_rsh_suffix_args((const char **)stat_args); | 1380 | rsh_suffix_args = gen_rsh_suffix_args ((const char **) stat_args); |
1377 | GNUNET_free(stat_args[1]); | 1381 | GNUNET_free (stat_args[1]); |
1378 | h->helper_argv = | 1382 | h->helper_argv = |
1379 | join_argv((const char **)rsh_args, (const char **)rsh_suffix_args); | 1383 | join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args); |
1380 | free_argv(rsh_suffix_args); | 1384 | free_argv (rsh_suffix_args); |
1381 | free_argv(rsh_args); | 1385 | free_argv (rsh_args); |
1382 | h->auxp = GNUNET_OS_start_process_vap(GNUNET_NO, | 1386 | h->auxp = GNUNET_OS_start_process_vap (GNUNET_NO, |
1383 | GNUNET_OS_INHERIT_STD_ERR, | 1387 | GNUNET_OS_INHERIT_STD_ERR, |
1384 | NULL, | 1388 | NULL, |
1385 | NULL, | 1389 | NULL, |
1386 | NULL, | 1390 | NULL, |
1387 | h->helper_argv[0], | 1391 | h->helper_argv[0], |
1388 | h->helper_argv); | 1392 | h->helper_argv); |
1389 | if (NULL == h->auxp) | 1393 | if (NULL == h->auxp) |
1390 | { | 1394 | { |
1391 | GNUNET_break(0); /* Cannot exec SSH? */ | 1395 | GNUNET_break (0); /* Cannot exec SSH? */ |
1392 | GNUNET_free(h); | 1396 | GNUNET_free (h); |
1393 | return NULL; | 1397 | return NULL; |
1394 | } | 1398 | } |
1395 | h->wait_time = GNUNET_TIME_STD_BACKOFF(h->wait_time); | 1399 | h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time); |
1396 | h->habitability_check_task = | 1400 | h->habitability_check_task = |
1397 | GNUNET_SCHEDULER_add_delayed(h->wait_time, &habitability_check, h); | 1401 | GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h); |
1398 | return h; | 1402 | return h; |
1399 | } | 1403 | } |
1400 | 1404 | ||
@@ -1405,15 +1409,15 @@ GNUNET_TESTBED_is_host_habitable( | |||
1405 | * @param handle the habitability check handle | 1409 | * @param handle the habitability check handle |
1406 | */ | 1410 | */ |
1407 | void | 1411 | void |
1408 | GNUNET_TESTBED_is_host_habitable_cancel( | 1412 | GNUNET_TESTBED_is_host_habitable_cancel ( |
1409 | struct GNUNET_TESTBED_HostHabitableCheckHandle *handle) | 1413 | struct GNUNET_TESTBED_HostHabitableCheckHandle *handle) |
1410 | { | 1414 | { |
1411 | GNUNET_SCHEDULER_cancel(handle->habitability_check_task); | 1415 | GNUNET_SCHEDULER_cancel (handle->habitability_check_task); |
1412 | (void)GNUNET_OS_process_kill(handle->auxp, GNUNET_TERM_SIG); | 1416 | (void) GNUNET_OS_process_kill (handle->auxp, GNUNET_TERM_SIG); |
1413 | (void)GNUNET_OS_process_wait(handle->auxp); | 1417 | (void) GNUNET_OS_process_wait (handle->auxp); |
1414 | GNUNET_OS_process_destroy(handle->auxp); | 1418 | GNUNET_OS_process_destroy (handle->auxp); |
1415 | free_argv(handle->helper_argv); | 1419 | free_argv (handle->helper_argv); |
1416 | GNUNET_free(handle); | 1420 | GNUNET_free (handle); |
1417 | } | 1421 | } |
1418 | 1422 | ||
1419 | 1423 | ||
@@ -1430,10 +1434,10 @@ GNUNET_TESTBED_is_host_habitable_cancel( | |||
1430 | * registration | 1434 | * registration |
1431 | */ | 1435 | */ |
1432 | struct GNUNET_TESTBED_HostRegistrationHandle * | 1436 | struct GNUNET_TESTBED_HostRegistrationHandle * |
1433 | GNUNET_TESTBED_register_host(struct GNUNET_TESTBED_Controller *controller, | 1437 | GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller, |
1434 | struct GNUNET_TESTBED_Host *host, | 1438 | struct GNUNET_TESTBED_Host *host, |
1435 | GNUNET_TESTBED_HostRegistrationCompletion cc, | 1439 | GNUNET_TESTBED_HostRegistrationCompletion cc, |
1436 | void *cc_cls) | 1440 | void *cc_cls) |
1437 | { | 1441 | { |
1438 | struct GNUNET_TESTBED_HostRegistrationHandle *rh; | 1442 | struct GNUNET_TESTBED_HostRegistrationHandle *rh; |
1439 | struct GNUNET_TESTBED_AddHostMessage *msg; | 1443 | struct GNUNET_TESTBED_AddHostMessage *msg; |
@@ -1450,57 +1454,57 @@ GNUNET_TESTBED_register_host(struct GNUNET_TESTBED_Controller *controller, | |||
1450 | 1454 | ||
1451 | if (NULL != controller->rh) | 1455 | if (NULL != controller->rh) |
1452 | return NULL; | 1456 | return NULL; |
1453 | hostname = GNUNET_TESTBED_host_get_hostname(host); | 1457 | hostname = GNUNET_TESTBED_host_get_hostname (host); |
1454 | if (GNUNET_YES == GNUNET_TESTBED_is_host_registered_(host, controller)) | 1458 | if (GNUNET_YES == GNUNET_TESTBED_is_host_registered_ (host, controller)) |
1455 | { | 1459 | { |
1456 | LOG(GNUNET_ERROR_TYPE_WARNING, | 1460 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1457 | "Host hostname: %s already registered\n", | 1461 | "Host hostname: %s already registered\n", |
1458 | (NULL == hostname) ? "localhost" : hostname); | 1462 | (NULL == hostname) ? "localhost" : hostname); |
1459 | return NULL; | 1463 | return NULL; |
1460 | } | 1464 | } |
1461 | rh = GNUNET_new(struct GNUNET_TESTBED_HostRegistrationHandle); | 1465 | rh = GNUNET_new (struct GNUNET_TESTBED_HostRegistrationHandle); |
1462 | rh->host = host; | 1466 | rh->host = host; |
1463 | rh->c = controller; | 1467 | rh->c = controller; |
1464 | GNUNET_assert(NULL != cc); | 1468 | GNUNET_assert (NULL != cc); |
1465 | rh->cc = cc; | 1469 | rh->cc = cc; |
1466 | rh->cc_cls = cc_cls; | 1470 | rh->cc_cls = cc_cls; |
1467 | controller->rh = rh; | 1471 | controller->rh = rh; |
1468 | username = GNUNET_TESTBED_host_get_username_(host); | 1472 | username = GNUNET_TESTBED_host_get_username_ (host); |
1469 | username_length = 0; | 1473 | username_length = 0; |
1470 | if (NULL != username) | 1474 | if (NULL != username) |
1471 | username_length = strlen(username); | 1475 | username_length = strlen (username); |
1472 | GNUNET_assert(NULL != hostname); /* Hostname must be present */ | 1476 | GNUNET_assert (NULL != hostname); /* Hostname must be present */ |
1473 | hostname_length = strlen(hostname); | 1477 | hostname_length = strlen (hostname); |
1474 | GNUNET_assert(NULL != host->cfg); | 1478 | GNUNET_assert (NULL != host->cfg); |
1475 | config = GNUNET_CONFIGURATION_serialize(host->cfg, &config_size); | 1479 | config = GNUNET_CONFIGURATION_serialize (host->cfg, &config_size); |
1476 | cc_size = GNUNET_TESTBED_compress_config_(config, config_size, &cconfig); | 1480 | cc_size = GNUNET_TESTBED_compress_config_ (config, config_size, &cconfig); |
1477 | GNUNET_free(config); | 1481 | GNUNET_free (config); |
1478 | msg_size = (sizeof(struct GNUNET_TESTBED_AddHostMessage)); | 1482 | msg_size = (sizeof(struct GNUNET_TESTBED_AddHostMessage)); |
1479 | msg_size += username_length; | 1483 | msg_size += username_length; |
1480 | msg_size += hostname_length; | 1484 | msg_size += hostname_length; |
1481 | msg_size += cc_size; | 1485 | msg_size += cc_size; |
1482 | msg = GNUNET_malloc(msg_size); | 1486 | msg = GNUNET_malloc (msg_size); |
1483 | msg->header.size = htons(msg_size); | 1487 | msg->header.size = htons (msg_size); |
1484 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST); | 1488 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST); |
1485 | msg->host_id = htonl(GNUNET_TESTBED_host_get_id_(host)); | 1489 | msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host)); |
1486 | msg->ssh_port = htons(GNUNET_TESTBED_host_get_ssh_port_(host)); | 1490 | msg->ssh_port = htons (GNUNET_TESTBED_host_get_ssh_port_ (host)); |
1487 | ptr = &msg[1]; | 1491 | ptr = &msg[1]; |
1488 | if (NULL != username) | 1492 | if (NULL != username) |
1489 | { | 1493 | { |
1490 | msg->username_length = htons(username_length); | 1494 | msg->username_length = htons (username_length); |
1491 | GNUNET_memcpy(ptr, username, username_length); | 1495 | GNUNET_memcpy (ptr, username, username_length); |
1492 | ptr += username_length; | 1496 | ptr += username_length; |
1493 | } | 1497 | } |
1494 | msg->hostname_length = htons(hostname_length); | 1498 | msg->hostname_length = htons (hostname_length); |
1495 | GNUNET_memcpy(ptr, hostname, hostname_length); | 1499 | GNUNET_memcpy (ptr, hostname, hostname_length); |
1496 | ptr += hostname_length; | 1500 | ptr += hostname_length; |
1497 | msg->config_size = htons(config_size); | 1501 | msg->config_size = htons (config_size); |
1498 | GNUNET_memcpy(ptr, cconfig, cc_size); | 1502 | GNUNET_memcpy (ptr, cconfig, cc_size); |
1499 | ptr += cc_size; | 1503 | ptr += cc_size; |
1500 | GNUNET_assert((ptr - (void *)msg) == msg_size); | 1504 | GNUNET_assert ((ptr - (void *) msg) == msg_size); |
1501 | GNUNET_free(cconfig); | 1505 | GNUNET_free (cconfig); |
1502 | GNUNET_TESTBED_queue_message_(controller, | 1506 | GNUNET_TESTBED_queue_message_ (controller, |
1503 | (struct GNUNET_MessageHeader *)msg); | 1507 | (struct GNUNET_MessageHeader *) msg); |
1504 | return rh; | 1508 | return rh; |
1505 | } | 1509 | } |
1506 | 1510 | ||
@@ -1513,16 +1517,16 @@ GNUNET_TESTBED_register_host(struct GNUNET_TESTBED_Controller *controller, | |||
1513 | * @param handle the registration handle to cancel | 1517 | * @param handle the registration handle to cancel |
1514 | */ | 1518 | */ |
1515 | void | 1519 | void |
1516 | GNUNET_TESTBED_cancel_registration( | 1520 | GNUNET_TESTBED_cancel_registration ( |
1517 | struct GNUNET_TESTBED_HostRegistrationHandle *handle) | 1521 | struct GNUNET_TESTBED_HostRegistrationHandle *handle) |
1518 | { | 1522 | { |
1519 | if (handle != handle->c->rh) | 1523 | if (handle != handle->c->rh) |
1520 | { | 1524 | { |
1521 | GNUNET_break(0); | 1525 | GNUNET_break (0); |
1522 | return; | 1526 | return; |
1523 | } | 1527 | } |
1524 | handle->c->rh = NULL; | 1528 | handle->c->rh = NULL; |
1525 | GNUNET_free(handle); | 1529 | GNUNET_free (handle); |
1526 | } | 1530 | } |
1527 | 1531 | ||
1528 | 1532 | ||
@@ -1535,11 +1539,12 @@ GNUNET_TESTBED_cancel_registration( | |||
1535 | * queue | 1539 | * queue |
1536 | */ | 1540 | */ |
1537 | void | 1541 | void |
1538 | GNUNET_TESTBED_host_queue_oc_(struct GNUNET_TESTBED_Host *h, | 1542 | GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h, |
1539 | struct GNUNET_TESTBED_Operation *op) | 1543 | struct GNUNET_TESTBED_Operation *op) |
1540 | { | 1544 | { |
1541 | GNUNET_TESTBED_operation_queue_insert_(h->opq_parallel_overlay_connect_operations, | 1545 | GNUNET_TESTBED_operation_queue_insert_ ( |
1542 | op); | 1546 | h->opq_parallel_overlay_connect_operations, |
1547 | op); | ||
1543 | } | 1548 | } |
1544 | 1549 | ||
1545 | 1550 | ||
@@ -1549,20 +1554,20 @@ GNUNET_TESTBED_host_queue_oc_(struct GNUNET_TESTBED_Host *h, | |||
1549 | * @param host the host whose hostname is to be resolved | 1554 | * @param host the host whose hostname is to be resolved |
1550 | */ | 1555 | */ |
1551 | void | 1556 | void |
1552 | GNUNET_TESTBED_host_resolve_(struct GNUNET_TESTBED_Host *host) | 1557 | GNUNET_TESTBED_host_resolve_ (struct GNUNET_TESTBED_Host *host) |
1553 | { | 1558 | { |
1554 | char *hostname; | 1559 | char *hostname; |
1555 | 1560 | ||
1556 | hostname = (char *)host->hostname; | 1561 | hostname = (char *) host->hostname; |
1557 | host->hostname = simple_resolve(hostname); | 1562 | host->hostname = simple_resolve (hostname); |
1558 | if (NULL == host->hostname) | 1563 | if (NULL == host->hostname) |
1559 | { | 1564 | { |
1560 | GNUNET_break(0); | 1565 | GNUNET_break (0); |
1561 | host->hostname = hostname; | 1566 | host->hostname = hostname; |
1562 | return; | 1567 | return; |
1563 | } | 1568 | } |
1564 | GNUNET_free(hostname); | 1569 | GNUNET_free (hostname); |
1565 | host->hostname = GNUNET_strdup(host->hostname); | 1570 | host->hostname = GNUNET_strdup (host->hostname); |
1566 | } | 1571 | } |
1567 | 1572 | ||
1568 | /* end of testbed_api_hosts.c */ | 1573 | /* end of testbed_api_hosts.c */ |