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