diff options
Diffstat (limited to 'src/testbed/testbed_api.c')
-rw-r--r-- | src/testbed/testbed_api.c | 169 |
1 files changed, 138 insertions, 31 deletions
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index aa410e010..3a42e87a8 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -426,76 +426,179 @@ GNUNET_TESTBED_queue_message (struct GNUNET_TESTBED_Controller *controller, | |||
426 | struct GNUNET_TESTBED_ControllerProc | 426 | struct GNUNET_TESTBED_ControllerProc |
427 | { | 427 | { |
428 | /** | 428 | /** |
429 | * The helper handle | 429 | * The process handle |
430 | */ | 430 | */ |
431 | struct GNUNET_TESTBED_HelperHandle *helper; | 431 | struct GNUNET_HELPER_Handle *helper; |
432 | 432 | ||
433 | /** | 433 | /** |
434 | * The controller error callback | 434 | * The controller error callback |
435 | */ | 435 | */ |
436 | GNUNET_TESTBED_ControllerErrorCallback cec; | 436 | GNUNET_TESTBED_ControllerStatusCallback cb; |
437 | 437 | ||
438 | /** | 438 | /** |
439 | * The closure for the above callback | 439 | * The closure for the above callback |
440 | */ | 440 | */ |
441 | void *cec_cls; | 441 | void *cls; |
442 | |||
443 | /** | ||
444 | * The send handle for the helper | ||
445 | */ | ||
446 | struct GNUNET_HELPER_SendHandle *shandle; | ||
447 | |||
448 | /** | ||
449 | * The port number for ssh; used for helpers starting ssh | ||
450 | */ | ||
451 | char *port; | ||
452 | |||
453 | /** | ||
454 | * The ssh destination string; used for helpers starting ssh | ||
455 | */ | ||
456 | char *dst; | ||
457 | |||
442 | }; | 458 | }; |
443 | 459 | ||
444 | 460 | ||
445 | /** | 461 | /** |
462 | * Functions with this signature are called whenever a | ||
463 | * complete message is received by the tokenizer. | ||
464 | * | ||
465 | * Do not call GNUNET_SERVER_mst_destroy in callback | ||
466 | * | ||
467 | * @param cls closure | ||
468 | * @param client identification of the client | ||
469 | * @param message the actual message | ||
470 | * | ||
471 | * @return GNUNET_OK on success, GNUNET_SYSERR to stop further processing | ||
472 | */ | ||
473 | static int helper_mst (void *cls, void *client, | ||
474 | const struct GNUNET_MessageHeader *message) | ||
475 | { | ||
476 | GNUNET_break (0); | ||
477 | return GNUNET_OK; | ||
478 | } | ||
479 | |||
480 | |||
481 | /** | ||
482 | * Continuation function from GNUNET_HELPER_send() | ||
483 | * | ||
484 | * @param cls closure | ||
485 | * @param result GNUNET_OK on success, | ||
486 | * GNUNET_NO if helper process died | ||
487 | * GNUNET_SYSERR during GNUNET_HELPER_stop | ||
488 | */ | ||
489 | static void | ||
490 | clear_msg (void *cls, int result) | ||
491 | { | ||
492 | GNUNET_free (cls); | ||
493 | } | ||
494 | |||
495 | |||
496 | /** | ||
446 | * Callback that will be called when the helper process dies. This is not called | 497 | * Callback that will be called when the helper process dies. This is not called |
447 | * when the helper process is stoped using GNUNET_HELPER_stop() | 498 | * when the helper process is stoped using GNUNET_HELPER_stop() |
448 | * | 499 | * |
449 | * @param cls the closure from GNUNET_HELPER_start() | 500 | * @param cls the closure from GNUNET_HELPER_start() |
450 | */ | 501 | */ |
451 | static void | 502 | static void |
452 | controller_exp_cb (void *cls) | 503 | helper_exp_cb (void *cls) |
453 | { | 504 | { |
454 | struct GNUNET_TESTBED_ControllerProc *cproc = cls; | 505 | struct GNUNET_TESTBED_ControllerProc *cp = cls; |
455 | 506 | GNUNET_TESTBED_ControllerStatusCallback cb; | |
456 | if (NULL != cproc->cec) | 507 | void *cb_cls; |
457 | cproc->cec (cproc->cec_cls, NULL); /* FIXME: How to get the error message? */ | 508 | |
509 | cb = cp->cb; | ||
510 | cb_cls = cp->cls; | ||
511 | GNUNET_TESTBED_controller_stop (cp); | ||
512 | if (NULL != cb) | ||
513 | cb (cb_cls, NULL, GNUNET_SYSERR); | ||
458 | } | 514 | } |
459 | 515 | ||
460 | 516 | ||
461 | /** | 517 | /** |
462 | * Starts a controller process at the host | 518 | * Starts a controller process at the host. FIXME: add controller start callback |
519 | * with the configuration with which the controller is started | ||
463 | * | 520 | * |
464 | * @param controller_ip the ip address of the controller. Will be set as TRUSTED | 521 | * @param controller_ip the ip address of the controller. Will be set as TRUSTED |
465 | * host when starting testbed controller at host | 522 | * host when starting testbed controller at host |
466 | * @param host the host where the controller has to be started; NULL for localhost | 523 | * @param host the host where the controller has to be started; NULL for |
524 | * localhost | ||
467 | * @param cfg template configuration to use for the remote controller; the | 525 | * @param cfg template configuration to use for the remote controller; the |
468 | * remote controller will be started with a slightly modified | 526 | * remote controller will be started with a slightly modified |
469 | * configuration (port numbers, unix domain sockets and service home | 527 | * configuration (port numbers, unix domain sockets and service home |
470 | * values are changed as per TESTING library on the remote host) | 528 | * values are changed as per TESTING library on the remote host) |
471 | * @param cec function called if the contoller dies unexpectedly; will not be | 529 | * @param cb function called when the controller is successfully started or |
472 | * invoked after GNUNET_TESTBED_controller_stop, if 'cec' was called, | 530 | * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be |
473 | * GNUNET_TESTBED_controller_stop must no longer be called; will | 531 | * called if cb is called with GNUNET_SYSERR as status. Will never be |
474 | * never be called in the same task as 'GNUNET_TESTBED_controller_start' | 532 | * called in the same task as 'GNUNET_TESTBED_controller_start' |
475 | * (synchronous errors will be signalled by returning NULL) | 533 | * (synchronous errors will be signalled by returning NULL) |
476 | * @param cec_cls closure for 'cec' | 534 | * @param cls closure for above callbacks |
477 | * @return the controller process handle, NULL on errors | 535 | * @return the controller process handle, NULL on errors |
478 | */ | 536 | */ |
479 | struct GNUNET_TESTBED_ControllerProc * | 537 | struct GNUNET_TESTBED_ControllerProc * |
480 | GNUNET_TESTBED_controller_start (const char *controller_ip, | 538 | GNUNET_TESTBED_controller_start (const char *controller_ip, |
481 | struct GNUNET_TESTBED_Host *host, | 539 | struct GNUNET_TESTBED_Host *host, |
482 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 540 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
483 | GNUNET_TESTBED_ControllerErrorCallback cec, | 541 | GNUNET_TESTBED_ControllerStatusCallback cb, |
484 | void *cec_cls) | 542 | void *cls) |
485 | { | 543 | { |
486 | struct GNUNET_TESTBED_ControllerProc *cproc; | 544 | struct GNUNET_TESTBED_ControllerProc *cp; |
545 | struct GNUNET_TESTBED_HelperInit *msg; | ||
487 | 546 | ||
488 | cproc = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ControllerProc)); | 547 | cp = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ControllerProc)); |
489 | cproc->helper = GNUNET_TESTBED_host_run_ (controller_ip, host, cfg, | 548 | if ((NULL == host) || (0 == GNUNET_TESTBED_host_get_id_ (host))) |
490 | &controller_exp_cb, cproc); | 549 | { |
491 | if (NULL == cproc->helper) | 550 | char * const binary_argv[] = { |
551 | "gnunet-testbed-helper", NULL | ||
552 | }; | ||
553 | |||
554 | cp->helper = GNUNET_HELPER_start ("gnunet-testbed-helper", binary_argv, | ||
555 | &helper_mst, &helper_exp_cb, cp); | ||
556 | } | ||
557 | else | ||
558 | { | ||
559 | char *remote_args[6 + 1]; | ||
560 | unsigned int argp; | ||
561 | const char *username; | ||
562 | const char *hostname; | ||
563 | |||
564 | username = GNUNET_TESTBED_host_get_username_ (host); | ||
565 | hostname = GNUNET_TESTBED_host_get_hostname_ (host); | ||
566 | GNUNET_asprintf (&cp->port, "%u", GNUNET_TESTBED_host_get_ssh_port_ (host)); | ||
567 | if (NULL == username) | ||
568 | GNUNET_asprintf (&cp->dst, "%s", hostname); | ||
569 | else | ||
570 | GNUNET_asprintf (&cp->dst, "%s@%s", hostname, username); | ||
571 | argp = 0; | ||
572 | remote_args[argp++] = "ssh"; | ||
573 | remote_args[argp++] = "-p"; | ||
574 | remote_args[argp++] = cp->port; | ||
575 | remote_args[argp++] = "-q"; | ||
576 | remote_args[argp++] = cp->dst; | ||
577 | remote_args[argp++] = "gnunet-testbed-helper"; | ||
578 | remote_args[argp++] = NULL; | ||
579 | GNUNET_assert (argp == 6 + 1); | ||
580 | cp->helper = GNUNET_HELPER_start ("ssh", remote_args, | ||
581 | &helper_mst, &helper_exp_cb, cp); | ||
582 | } | ||
583 | if (NULL == cp->helper) | ||
584 | { | ||
585 | GNUNET_free_non_null (cp->port); | ||
586 | GNUNET_free_non_null (cp->dst); | ||
587 | GNUNET_free (cp); | ||
588 | return NULL; | ||
589 | } | ||
590 | cp->cb = cb; | ||
591 | cp->cls = cls; | ||
592 | msg = GNUNET_TESTBED_create_helper_init_msg_ (controller_ip, cfg); | ||
593 | cp->shandle = GNUNET_HELPER_send (cp->helper, &msg->header, GNUNET_NO, | ||
594 | &clear_msg, msg); | ||
595 | if (NULL == cp->shandle) | ||
492 | { | 596 | { |
493 | GNUNET_free (cproc); | 597 | GNUNET_free (msg); |
598 | GNUNET_TESTBED_controller_stop (cp); | ||
494 | return NULL; | 599 | return NULL; |
495 | } | 600 | } |
496 | cproc->cec = cec; | 601 | return cp; |
497 | cproc->cec_cls = cec_cls; | ||
498 | return cproc; | ||
499 | } | 602 | } |
500 | 603 | ||
501 | 604 | ||
@@ -507,10 +610,14 @@ GNUNET_TESTBED_controller_start (const char *controller_ip, | |||
507 | * @param cproc the controller process handle | 610 | * @param cproc the controller process handle |
508 | */ | 611 | */ |
509 | void | 612 | void |
510 | GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc) | 613 | GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cp) |
511 | { | 614 | { |
512 | GNUNET_TESTBED_host_stop_ (cproc->helper); | 615 | if (NULL != cp->shandle) |
513 | GNUNET_free (cproc); | 616 | GNUNET_HELPER_send_cancel (cp->shandle); |
617 | GNUNET_HELPER_stop (cp->helper); | ||
618 | GNUNET_free_non_null (cp->port); | ||
619 | GNUNET_free_non_null (cp->dst); | ||
620 | GNUNET_free (cp); | ||
514 | } | 621 | } |
515 | 622 | ||
516 | 623 | ||