diff options
Diffstat (limited to 'src/testbed/gnunet-service-testbed.c')
-rw-r--r-- | src/testbed/gnunet-service-testbed.c | 87 |
1 files changed, 65 insertions, 22 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index 1b74ad1df..f3d629f5f 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c | |||
@@ -474,6 +474,48 @@ parse_shared_services (char *ss_str, struct GNUNET_CONFIGURATION_Handle *cfg) | |||
474 | 474 | ||
475 | 475 | ||
476 | /** | 476 | /** |
477 | * Callback function invoked for each interface found. | ||
478 | * | ||
479 | * @param cls NULL | ||
480 | * @param name name of the interface (can be NULL for unknown) | ||
481 | * @param isDefault is this presumably the default interface | ||
482 | * @param addr address of this interface (can be NULL for unknown or unassigned) | ||
483 | * @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned) | ||
484 | * @param netmask the network mask (can be NULL for unknown or unassigned)) | ||
485 | * @param addrlen length of the address | ||
486 | * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort | ||
487 | */ | ||
488 | static int | ||
489 | addr_proc (void *cls, const char *name, int isDefault, | ||
490 | const struct sockaddr *addr, | ||
491 | const struct sockaddr *broadcast_addr, | ||
492 | const struct sockaddr *netmask, socklen_t addrlen) | ||
493 | { | ||
494 | struct Context *ctx = cls; | ||
495 | const struct sockaddr_in *in_addr; | ||
496 | char *ipaddr; | ||
497 | char *tmp; | ||
498 | |||
499 | if (sizeof (struct sockaddr_in) != addrlen) | ||
500 | return GNUNET_OK; | ||
501 | in_addr = (const struct sockaddr_in *) addr; | ||
502 | if (NULL == (ipaddr = inet_ntoa (in_addr->sin_addr))) | ||
503 | return GNUNET_OK; | ||
504 | if (NULL == ctx->master_ips) | ||
505 | { | ||
506 | ctx->master_ips = GNUNET_strdup (ipaddr); | ||
507 | return GNUNET_OK; | ||
508 | } | ||
509 | tmp = NULL; | ||
510 | (void) GNUNET_asprintf (&tmp, "%s; %s", ctx->master_ips, ipaddr); | ||
511 | GNUNET_free (ctx->master_ips); | ||
512 | ctx->master_ips = tmp; | ||
513 | return GNUNET_OK; | ||
514 | } | ||
515 | |||
516 | |||
517 | |||
518 | /** | ||
477 | * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages | 519 | * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages |
478 | * | 520 | * |
479 | * @param cls NULL | 521 | * @param cls NULL |
@@ -486,11 +528,11 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client, | |||
486 | { | 528 | { |
487 | const struct GNUNET_TESTBED_InitMessage *msg; | 529 | const struct GNUNET_TESTBED_InitMessage *msg; |
488 | struct GNUNET_TESTBED_Host *host; | 530 | struct GNUNET_TESTBED_Host *host; |
489 | const char *controller_hostname; | ||
490 | char *ss_str; | 531 | char *ss_str; |
491 | struct GNUNET_TESTING_SharedService *ss; | 532 | struct GNUNET_TESTING_SharedService *ss; |
533 | char *hostname; | ||
492 | unsigned int cnt; | 534 | unsigned int cnt; |
493 | uint16_t msize; | 535 | unsigned int len; |
494 | 536 | ||
495 | if (NULL != GST_context) | 537 | if (NULL != GST_context) |
496 | { | 538 | { |
@@ -499,18 +541,11 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client, | |||
499 | return; | 541 | return; |
500 | } | 542 | } |
501 | msg = (const struct GNUNET_TESTBED_InitMessage *) message; | 543 | msg = (const struct GNUNET_TESTBED_InitMessage *) message; |
502 | msize = ntohs (message->size); | 544 | len = GNUNET_OS_get_hostname_max_length (); |
503 | if (msize <= sizeof (struct GNUNET_TESTBED_InitMessage)) | 545 | hostname = GNUNET_malloc (len); |
504 | { | 546 | if (0 != gethostname (hostname, len)) |
505 | GNUNET_break (0); | ||
506 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
507 | return; | ||
508 | } | ||
509 | msize -= sizeof (struct GNUNET_TESTBED_InitMessage); | ||
510 | controller_hostname = (const char *) &msg[1]; | ||
511 | if ('\0' != controller_hostname[msize - 1]) | ||
512 | { | 547 | { |
513 | GNUNET_break (0); | 548 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "gethostname"); |
514 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 549 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
515 | return; | 550 | return; |
516 | } | 551 | } |
@@ -528,10 +563,18 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client, | |||
528 | GNUNET_SERVER_client_keep (client); | 563 | GNUNET_SERVER_client_keep (client); |
529 | GST_context->client = client; | 564 | GST_context->client = client; |
530 | GST_context->host_id = ntohl (msg->host_id); | 565 | GST_context->host_id = ntohl (msg->host_id); |
531 | GST_context->master_ip = GNUNET_strdup (controller_hostname); | 566 | GNUNET_OS_network_interfaces_list (&addr_proc, GST_context); |
532 | LOG_DEBUG ("Our IP: %s\n", GST_context->master_ip); | 567 | if (NULL == GST_context->master_ips) |
568 | { | ||
569 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
570 | "Testbed needs networking, but no network interfaces are found on this host. Exiting\n"); | ||
571 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
572 | GNUNET_SCHEDULER_shutdown (); | ||
573 | return; | ||
574 | } | ||
575 | LOG_DEBUG ("Our IP addresses: %s\n", GST_context->master_ips); | ||
533 | GST_context->system = | 576 | GST_context->system = |
534 | GNUNET_TESTING_system_create ("testbed", GST_context->master_ip, | 577 | GNUNET_TESTING_system_create ("testbed", GST_context->master_ips, |
535 | hostname, ss); | 578 | hostname, ss); |
536 | if (NULL != ss) | 579 | if (NULL != ss) |
537 | { | 580 | { |
@@ -543,10 +586,9 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client, | |||
543 | GNUNET_free (ss); | 586 | GNUNET_free (ss); |
544 | ss = NULL; | 587 | ss = NULL; |
545 | } | 588 | } |
546 | host = | 589 | |
547 | GNUNET_TESTBED_host_create_with_id (GST_context->host_id, | 590 | host = GNUNET_TESTBED_host_create_with_id (GST_context->host_id, hostname, |
548 | GST_context->master_ip, NULL, | 591 | NULL, our_config, 0); |
549 | our_config, 0); | ||
550 | host_list_add (host); | 592 | host_list_add (host); |
551 | LOG_DEBUG ("Created master context with host ID: %u\n", GST_context->host_id); | 593 | LOG_DEBUG ("Created master context with host ID: %u\n", GST_context->host_id); |
552 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 594 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -808,7 +850,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
808 | GNUNET_free_non_null (GST_host_list); | 850 | GNUNET_free_non_null (GST_host_list); |
809 | if (NULL != GST_context) | 851 | if (NULL != GST_context) |
810 | { | 852 | { |
811 | GNUNET_free_non_null (GST_context->master_ip); | 853 | GNUNET_free_non_null (GST_context->master_ips); |
812 | if (NULL != GST_context->system) | 854 | if (NULL != GST_context->system) |
813 | GNUNET_TESTING_system_destroy (GST_context->system, GNUNET_YES); | 855 | GNUNET_TESTING_system_destroy (GST_context->system, GNUNET_YES); |
814 | GNUNET_SERVER_client_drop (GST_context->client); | 856 | GNUNET_SERVER_client_drop (GST_context->client); |
@@ -870,7 +912,8 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
870 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 912 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
871 | { | 913 | { |
872 | static const struct GNUNET_SERVER_MessageHandler message_handlers[] = { | 914 | static const struct GNUNET_SERVER_MessageHandler message_handlers[] = { |
873 | {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0}, | 915 | {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, |
916 | sizeof (struct GNUNET_TESTBED_InitMessage)}, | ||
874 | {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, 0}, | 917 | {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, 0}, |
875 | {&GST_handle_link_controllers, NULL, | 918 | {&GST_handle_link_controllers, NULL, |
876 | GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, | 919 | GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, |