diff options
-rw-r--r-- | src/testbed/gnunet-service-testbed.c | 87 | ||||
-rw-r--r-- | src/testbed/gnunet-service-testbed.h | 2 | ||||
-rw-r--r-- | src/testbed/gnunet-service-testbed_links.c | 2 | ||||
-rw-r--r-- | src/testbed/testbed.h | 2 | ||||
-rw-r--r-- | src/testbed/testbed_api.c | 48 | ||||
-rw-r--r-- | src/testbed/testbed_api_hosts.c | 1 |
6 files changed, 87 insertions, 55 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, |
diff --git a/src/testbed/gnunet-service-testbed.h b/src/testbed/gnunet-service-testbed.h index 345007cd7..ceb209877 100644 --- a/src/testbed/gnunet-service-testbed.h +++ b/src/testbed/gnunet-service-testbed.h | |||
@@ -260,7 +260,7 @@ struct Context | |||
260 | /** | 260 | /** |
261 | * The network address of the master controller | 261 | * The network address of the master controller |
262 | */ | 262 | */ |
263 | char *master_ip; | 263 | char *master_ips; |
264 | 264 | ||
265 | /** | 265 | /** |
266 | * The TESTING system handle for starting peers locally | 266 | * The TESTING system handle for starting peers locally |
diff --git a/src/testbed/gnunet-service-testbed_links.c b/src/testbed/gnunet-service-testbed_links.c index 7b0006d1f..ad41dc9c5 100644 --- a/src/testbed/gnunet-service-testbed_links.c +++ b/src/testbed/gnunet-service-testbed_links.c | |||
@@ -1248,7 +1248,7 @@ GST_handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client, | |||
1248 | lcc->client = client; | 1248 | lcc->client = client; |
1249 | slave->lcc = lcc; | 1249 | slave->lcc = lcc; |
1250 | slave->controller_proc = | 1250 | slave->controller_proc = |
1251 | GNUNET_TESTBED_controller_start (GST_context->master_ip, | 1251 | GNUNET_TESTBED_controller_start (GST_context->master_ips, |
1252 | GST_host_list[slave->host_id], | 1252 | GST_host_list[slave->host_id], |
1253 | &slave_status_cb, slave); | 1253 | &slave_status_cb, slave); |
1254 | new_route = GNUNET_malloc (sizeof (struct Route)); | 1254 | new_route = GNUNET_malloc (sizeof (struct Route)); |
diff --git a/src/testbed/testbed.h b/src/testbed/testbed.h index 904e7acba..635708376 100644 --- a/src/testbed/testbed.h +++ b/src/testbed/testbed.h | |||
@@ -54,8 +54,6 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
54 | * is interested in. In NBO. | 54 | * is interested in. In NBO. |
55 | */ | 55 | */ |
56 | uint64_t event_mask GNUNET_PACKED; | 56 | uint64_t event_mask GNUNET_PACKED; |
57 | |||
58 | /* Followed by 0-terminated hostname of the controller */ | ||
59 | }; | 57 | }; |
60 | 58 | ||
61 | 59 | ||
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 01df06729..80f940467 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -1436,10 +1436,9 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host, | |||
1436 | GNUNET_TESTBED_ControllerCallback cc, | 1436 | GNUNET_TESTBED_ControllerCallback cc, |
1437 | void *cc_cls) | 1437 | void *cc_cls) |
1438 | { | 1438 | { |
1439 | struct GNUNET_TESTBED_Controller *controller; | 1439 | struct GNUNET_TESTBED_Controller *c; |
1440 | struct GNUNET_TESTBED_InitMessage *msg; | 1440 | struct GNUNET_TESTBED_InitMessage *msg; |
1441 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 1441 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
1442 | const char *controller_hostname; | ||
1443 | unsigned long long max_parallel_operations; | 1442 | unsigned long long max_parallel_operations; |
1444 | unsigned long long max_parallel_service_connections; | 1443 | unsigned long long max_parallel_service_connections; |
1445 | unsigned long long max_parallel_topology_config_operations; | 1444 | unsigned long long max_parallel_topology_config_operations; |
@@ -1469,44 +1468,35 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host, | |||
1469 | GNUNET_break (0); | 1468 | GNUNET_break (0); |
1470 | return NULL; | 1469 | return NULL; |
1471 | } | 1470 | } |
1472 | controller = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Controller)); | 1471 | c = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Controller)); |
1473 | controller->cc = cc; | 1472 | c->cc = cc; |
1474 | controller->cc_cls = cc_cls; | 1473 | c->cc_cls = cc_cls; |
1475 | controller->event_mask = event_mask; | 1474 | c->event_mask = event_mask; |
1476 | controller->cfg = GNUNET_CONFIGURATION_dup (cfg); | 1475 | c->cfg = GNUNET_CONFIGURATION_dup (cfg); |
1477 | controller->client = GNUNET_CLIENT_connect ("testbed", controller->cfg); | 1476 | c->client = GNUNET_CLIENT_connect ("testbed", c->cfg); |
1478 | if (NULL == controller->client) | 1477 | if (NULL == c->client) |
1479 | { | 1478 | { |
1480 | GNUNET_TESTBED_controller_disconnect (controller); | 1479 | GNUNET_TESTBED_controller_disconnect (c); |
1481 | return NULL; | 1480 | return NULL; |
1482 | } | 1481 | } |
1483 | GNUNET_TESTBED_mark_host_registered_at_ (host, controller); | 1482 | GNUNET_TESTBED_mark_host_registered_at_ (host, c); |
1484 | controller->host = host; | 1483 | c->host = host; |
1485 | controller->opq_parallel_operations = | 1484 | c->opq_parallel_operations = |
1486 | GNUNET_TESTBED_operation_queue_create_ ((unsigned int) | 1485 | GNUNET_TESTBED_operation_queue_create_ ((unsigned int) |
1487 | max_parallel_operations); | 1486 | max_parallel_operations); |
1488 | controller->opq_parallel_service_connections = | 1487 | c->opq_parallel_service_connections = |
1489 | GNUNET_TESTBED_operation_queue_create_ ((unsigned int) | 1488 | GNUNET_TESTBED_operation_queue_create_ ((unsigned int) |
1490 | max_parallel_service_connections); | 1489 | max_parallel_service_connections); |
1491 | controller->opq_parallel_topology_config_operations = | 1490 | c->opq_parallel_topology_config_operations = |
1492 | GNUNET_TESTBED_operation_queue_create_ ((unsigned int) | 1491 | GNUNET_TESTBED_operation_queue_create_ ((unsigned int) |
1493 | max_parallel_topology_config_operations); | 1492 | max_parallel_topology_config_operations); |
1494 | controller_hostname = GNUNET_TESTBED_host_get_hostname (host); | 1493 | msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_InitMessage)); |
1495 | if (NULL == controller_hostname) | ||
1496 | controller_hostname = "127.0.0.1"; | ||
1497 | msg = | ||
1498 | GNUNET_malloc (sizeof (struct GNUNET_TESTBED_InitMessage) + | ||
1499 | strlen (controller_hostname) + 1); | ||
1500 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_INIT); | 1494 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_INIT); |
1501 | msg->header.size = | 1495 | msg->header.size = htons (sizeof (struct GNUNET_TESTBED_InitMessage)); |
1502 | htons (sizeof (struct GNUNET_TESTBED_InitMessage) + | ||
1503 | strlen (controller_hostname) + 1); | ||
1504 | msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host)); | 1496 | msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host)); |
1505 | msg->event_mask = GNUNET_htonll (controller->event_mask); | 1497 | msg->event_mask = GNUNET_htonll (c->event_mask); |
1506 | strcpy ((char *) &msg[1], controller_hostname); | 1498 | GNUNET_TESTBED_queue_message_ (c, &msg->header); |
1507 | GNUNET_TESTBED_queue_message_ (controller, | 1499 | return c; |
1508 | (struct GNUNET_MessageHeader *) msg); | ||
1509 | return controller; | ||
1510 | } | 1500 | } |
1511 | 1501 | ||
1512 | 1502 | ||
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c index c386d18a0..e76dada88 100644 --- a/src/testbed/testbed_api_hosts.c +++ b/src/testbed/testbed_api_hosts.c | |||
@@ -556,6 +556,7 @@ simple_resolve (const char *host) | |||
556 | in_addr = (const struct sockaddr_in *) res->ai_addr; | 556 | in_addr = (const struct sockaddr_in *) res->ai_addr; |
557 | hostip = inet_ntoa (in_addr->sin_addr); | 557 | hostip = inet_ntoa (in_addr->sin_addr); |
558 | GNUNET_assert (NULL != hostip); | 558 | GNUNET_assert (NULL != hostip); |
559 | freeaddrinfo (res); | ||
559 | LOG_DEBUG ("Resolved [%s] to [%s]\n", host, hostip); | 560 | LOG_DEBUG ("Resolved [%s] to [%s]\n", host, hostip); |
560 | return hostip; | 561 | return hostip; |
561 | } | 562 | } |