aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_hosts.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-07-17 14:59:10 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-07-17 14:59:10 +0000
commiteb3f4006fc74ef71296e53d83b1d4b6990b639d1 (patch)
tree39704da526a6107925ebec9684d6a1e7d65f6e4e /src/testbed/testbed_api_hosts.c
parent90b5375e31986484f5007ec62c57f455bb8178dc (diff)
downloadgnunet-eb3f4006fc74ef71296e53d83b1d4b6990b639d1.tar.gz
gnunet-eb3f4006fc74ef71296e53d83b1d4b6990b639d1.zip
helper integration to GNUNET_TESTBED_host_run_()
todo: add controller start callback with the configuration with which the controller is started
Diffstat (limited to 'src/testbed/testbed_api_hosts.c')
-rw-r--r--src/testbed/testbed_api_hosts.c117
1 files changed, 74 insertions, 43 deletions
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c
index fd129283e..5fe525b9e 100644
--- a/src/testbed/testbed_api_hosts.c
+++ b/src/testbed/testbed_api_hosts.c
@@ -35,6 +35,7 @@
35 35
36#include "testbed_api.h" 36#include "testbed_api.h"
37#include "testbed_api_hosts.h" 37#include "testbed_api_hosts.h"
38#include "testbed_helper.h"
38 39
39/** 40/**
40 * Generic logging shorthand 41 * Generic logging shorthand
@@ -337,46 +338,86 @@ GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host)
337 338
338 339
339/** 340/**
341 * Continuation function from GNUNET_HELPER_send()
342 *
343 * @param cls closure
344 * @param result GNUNET_OK on success,
345 * GNUNET_NO if helper process died
346 * GNUNET_SYSERR during GNUNET_HELPER_stop
347 */
348static void
349clear_msg (void *cls, int result)
350{
351 GNUNET_free (cls);
352}
353
354
355/**
356 * Callback that will be called when the helper process dies. This is not called
357 * when the helper process is stoped using GNUNET_HELPER_stop()
358 *
359 * @param cls the closure from GNUNET_HELPER_start()
360 * @param h the handle representing the helper process. This handle is invalid
361 * in this callback. It is only presented for reference. No operations
362 * can be performed using it.
363 */
364static void
365helper_exp_cb (void *cls, const struct GNUNET_HELPER_Handle *h)
366{
367 struct GNUNET_TESTBED_HelperHandle *handle = cls;
368
369 handle->is_stopped = GNUNET_YES;
370 GNUNET_TESTBED_host_stop_ (handle);
371 handle->exp_cb (handle->exp_cb_cls, h);
372}
373
374
375/**
340 * Run a given helper process at the given host. Communication 376 * Run a given helper process at the given host. Communication
341 * with the helper will be via GNUnet messages on stdin/stdout. 377 * with the helper will be via GNUnet messages on stdin/stdout.
342 * Runs the process via 'ssh' at the specified host, or locally. 378 * Runs the process via 'ssh' at the specified host, or locally.
343 * Essentially an SSH-wrapper around the 'gnunet_helper_lib.h' API. 379 * Essentially an SSH-wrapper around the 'gnunet_helper_lib.h' API.
344 * 380 *
381 * @param controller_ip the ip address of the controller. Will be set as TRUSTED
382 * host when starting testbed controller at host
345 * @param host host to use, use "NULL" for localhost 383 * @param host host to use, use "NULL" for localhost
346 * @param binary_argv binary name and command-line arguments to give to the binary 384 * @param binary_argv binary name and command-line arguments to give to the
385 * binary
386 * @param cfg template configuration to use for the remote controller; the
387 * remote controller will be started with a slightly modified
388 * configuration (port numbers, unix domain sockets and service home
389 * values are changed as per TESTING library on the remote host)
390 * @param cb the callback to run when helper process dies; cannot be NULL
391 * @param cb_cls the closure for the above callback
347 * @return handle to terminate the command, NULL on error 392 * @return handle to terminate the command, NULL on error
348 */ 393 */
349struct GNUNET_TESTBED_HelperHandle * 394struct GNUNET_TESTBED_HelperHandle *
350GNUNET_TESTBED_host_run_ (const struct GNUNET_TESTBED_Host *host, 395GNUNET_TESTBED_host_run_ (const char *controller_ip,
351 char *const binary_argv[]) 396 const struct GNUNET_TESTBED_Host *host,
397 const struct GNUNET_CONFIGURATION_Handle *cfg,
398 GNUNET_HELPER_ExceptionCallback cb,
399 void *cb_cls)
352{ 400{
353 struct GNUNET_TESTBED_HelperHandle *h; 401 struct GNUNET_TESTBED_HelperHandle *h;
354 unsigned int argc; 402 struct GNUNET_TESTBED_HelperInit *msg;
355 403
356 argc = 0; 404 GNUNET_assert (NULL != cb);
357 while (NULL != binary_argv[argc])
358 argc++;
359 h = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HelperHandle)); 405 h = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HelperHandle));
360 h->cpipe_in = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO); 406 h->exp_cb = cb;
361 h->cpipe_out = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_YES); 407 h->exp_cb_cls = cb_cls;
362 if ((NULL == h->cpipe_in) || (NULL == h->cpipe_out)) 408 h->is_stopped = GNUNET_NO;
363 {
364 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
365 "pipe");
366 GNUNET_free (h);
367 return NULL;
368 }
369 if ((NULL == host) || (0 == host->id)) 409 if ((NULL == host) || (0 == host->id))
370 { 410 {
371 h->process = GNUNET_OS_start_process_vap (GNUNET_YES, 411 char * const binary_argv[] = {
372 GNUNET_OS_INHERIT_STD_ALL, 412 "gnunet-testbed-helper", NULL
373 h->cpipe_in, h->cpipe_out, 413 };
374 "gnunet-service-testbed", 414
375 binary_argv); 415 h->helper =
416 GNUNET_HELPER_start ("gnunet-testbed-helper", binary_argv, NULL, &helper_exp_cb, h);
376 } 417 }
377 else 418 else
378 { 419 {
379 char *remote_args[argc + 6 + 1]; 420 char *remote_args[6 + 1];
380 unsigned int argp; 421 unsigned int argp;
381 422
382 GNUNET_asprintf (&h->port, "%d", host->port); 423 GNUNET_asprintf (&h->port, "%d", host->port);
@@ -390,29 +431,22 @@ GNUNET_TESTBED_host_run_ (const struct GNUNET_TESTBED_Host *host,
390 remote_args[argp++] = h->port; 431 remote_args[argp++] = h->port;
391 remote_args[argp++] = "-q"; 432 remote_args[argp++] = "-q";
392 remote_args[argp++] = h->dst; 433 remote_args[argp++] = h->dst;
393 remote_args[argp++] = "gnunet-service-testbed"; 434 remote_args[argp++] = "gnunet-testbed-helper";
394 while (NULL != binary_argv[argp-6])
395 {
396 remote_args[argp] = binary_argv[argp - 6];
397 argp++;
398 }
399 remote_args[argp++] = NULL; 435 remote_args[argp++] = NULL;
400 GNUNET_assert (argp == argc + 6 + 1); 436 GNUNET_assert (argp == 6 + 1);
401 h->process = GNUNET_OS_start_process_vap (GNUNET_YES, 437 h->helper = GNUNET_HELPER_start ("ssh", remote_args, NULL, &helper_exp_cb, h);
402 GNUNET_OS_INHERIT_STD_ALL,
403 h->cpipe_in, NULL,
404 "ssh",
405 remote_args);
406 } 438 }
407 if (NULL == h->process) 439 msg = GNUNET_TESTBED_create_helper_init_msg_ (controller_ip, cfg);
440 if ((NULL == h->helper) ||
441 (NULL == (h->helper_shandle = GNUNET_HELPER_send (h->helper, &msg->header, GNUNET_NO,
442 &clear_msg, msg))))
408 { 443 {
409 GNUNET_break (GNUNET_OK == GNUNET_DISK_pipe_close (h->cpipe_in)); 444 GNUNET_free (msg);
410 GNUNET_free_non_null (h->port); 445 GNUNET_free_non_null (h->port);
411 GNUNET_free_non_null (h->dst); 446 GNUNET_free_non_null (h->dst);
412 GNUNET_free (h); 447 GNUNET_free (h);
413 return NULL; 448 return NULL;
414 } 449 }
415 GNUNET_break (GNUNET_OK == GNUNET_DISK_pipe_close_end (h->cpipe_in, GNUNET_DISK_PIPE_END_READ));
416 return h; 450 return h;
417} 451}
418 452
@@ -425,11 +459,8 @@ GNUNET_TESTBED_host_run_ (const struct GNUNET_TESTBED_Host *host,
425void 459void
426GNUNET_TESTBED_host_stop_ (struct GNUNET_TESTBED_HelperHandle *handle) 460GNUNET_TESTBED_host_stop_ (struct GNUNET_TESTBED_HelperHandle *handle)
427{ 461{
428 GNUNET_break (GNUNET_OK == GNUNET_DISK_pipe_close (handle->cpipe_in)); 462 if (GNUNET_YES != handle->is_stopped)
429 GNUNET_break (GNUNET_OK == GNUNET_DISK_pipe_close (handle->cpipe_out)); 463 GNUNET_HELPER_stop (handle->helper);
430 GNUNET_break (0 == GNUNET_OS_process_kill (handle->process, SIGTERM));
431 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (handle->process));
432 GNUNET_OS_process_destroy (handle->process);
433 GNUNET_free_non_null (handle->port); 464 GNUNET_free_non_null (handle->port);
434 GNUNET_free_non_null (handle->dst); 465 GNUNET_free_non_null (handle->dst);
435 GNUNET_free (handle); 466 GNUNET_free (handle);