From 6ebfc499830f2d447ef20514c66a1bb9e24f1dad Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Fri, 17 May 2013 09:23:41 +0000 Subject: [PATCH] - revert 27104 --- src/testbed/gnunet-service-testbed.c | 87 ++++++---------------- src/testbed/gnunet-service-testbed.h | 2 +- src/testbed/gnunet-service-testbed_links.c | 2 +- src/testbed/testbed.h | 2 + src/testbed/testbed_api.c | 48 +++++++----- 5 files changed, 55 insertions(+), 86 deletions(-) diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index f3d629f5f..1b74ad1df 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c @@ -473,48 +473,6 @@ parse_shared_services (char *ss_str, struct GNUNET_CONFIGURATION_Handle *cfg) } -/** - * Callback function invoked for each interface found. - * - * @param cls NULL - * @param name name of the interface (can be NULL for unknown) - * @param isDefault is this presumably the default interface - * @param addr address of this interface (can be NULL for unknown or unassigned) - * @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned) - * @param netmask the network mask (can be NULL for unknown or unassigned)) - * @param addrlen length of the address - * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort - */ -static int -addr_proc (void *cls, const char *name, int isDefault, - const struct sockaddr *addr, - const struct sockaddr *broadcast_addr, - const struct sockaddr *netmask, socklen_t addrlen) -{ - struct Context *ctx = cls; - const struct sockaddr_in *in_addr; - char *ipaddr; - char *tmp; - - if (sizeof (struct sockaddr_in) != addrlen) - return GNUNET_OK; - in_addr = (const struct sockaddr_in *) addr; - if (NULL == (ipaddr = inet_ntoa (in_addr->sin_addr))) - return GNUNET_OK; - if (NULL == ctx->master_ips) - { - ctx->master_ips = GNUNET_strdup (ipaddr); - return GNUNET_OK; - } - tmp = NULL; - (void) GNUNET_asprintf (&tmp, "%s; %s", ctx->master_ips, ipaddr); - GNUNET_free (ctx->master_ips); - ctx->master_ips = tmp; - return GNUNET_OK; -} - - - /** * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages * @@ -528,11 +486,11 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client, { const struct GNUNET_TESTBED_InitMessage *msg; struct GNUNET_TESTBED_Host *host; + const char *controller_hostname; char *ss_str; struct GNUNET_TESTING_SharedService *ss; - char *hostname; unsigned int cnt; - unsigned int len; + uint16_t msize; if (NULL != GST_context) { @@ -541,11 +499,18 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client, return; } msg = (const struct GNUNET_TESTBED_InitMessage *) message; - len = GNUNET_OS_get_hostname_max_length (); - hostname = GNUNET_malloc (len); - if (0 != gethostname (hostname, len)) + msize = ntohs (message->size); + if (msize <= sizeof (struct GNUNET_TESTBED_InitMessage)) + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } + msize -= sizeof (struct GNUNET_TESTBED_InitMessage); + controller_hostname = (const char *) &msg[1]; + if ('\0' != controller_hostname[msize - 1]) { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "gethostname"); + GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } @@ -563,18 +528,10 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_SERVER_client_keep (client); GST_context->client = client; GST_context->host_id = ntohl (msg->host_id); - GNUNET_OS_network_interfaces_list (&addr_proc, GST_context); - if (NULL == GST_context->master_ips) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Testbed needs networking, but no network interfaces are found on this host. Exiting\n"); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - GNUNET_SCHEDULER_shutdown (); - return; - } - LOG_DEBUG ("Our IP addresses: %s\n", GST_context->master_ips); + GST_context->master_ip = GNUNET_strdup (controller_hostname); + LOG_DEBUG ("Our IP: %s\n", GST_context->master_ip); GST_context->system = - GNUNET_TESTING_system_create ("testbed", GST_context->master_ips, + GNUNET_TESTING_system_create ("testbed", GST_context->master_ip, hostname, ss); if (NULL != ss) { @@ -586,9 +543,10 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_free (ss); ss = NULL; } - - host = GNUNET_TESTBED_host_create_with_id (GST_context->host_id, hostname, - NULL, our_config, 0); + host = + GNUNET_TESTBED_host_create_with_id (GST_context->host_id, + GST_context->master_ip, NULL, + our_config, 0); host_list_add (host); LOG_DEBUG ("Created master context with host ID: %u\n", GST_context->host_id); GNUNET_SERVER_receive_done (client, GNUNET_OK); @@ -850,7 +808,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_free_non_null (GST_host_list); if (NULL != GST_context) { - GNUNET_free_non_null (GST_context->master_ips); + GNUNET_free_non_null (GST_context->master_ip); if (NULL != GST_context->system) GNUNET_TESTING_system_destroy (GST_context->system, GNUNET_YES); GNUNET_SERVER_client_drop (GST_context->client); @@ -912,8 +870,7 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server, const struct GNUNET_CONFIGURATION_Handle *cfg) { static const struct GNUNET_SERVER_MessageHandler message_handlers[] = { - {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, - sizeof (struct GNUNET_TESTBED_InitMessage)}, + {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0}, {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, 0}, {&GST_handle_link_controllers, NULL, GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, diff --git a/src/testbed/gnunet-service-testbed.h b/src/testbed/gnunet-service-testbed.h index ceb209877..345007cd7 100644 --- a/src/testbed/gnunet-service-testbed.h +++ b/src/testbed/gnunet-service-testbed.h @@ -260,7 +260,7 @@ struct Context /** * The network address of the master controller */ - char *master_ips; + char *master_ip; /** * 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 ad41dc9c5..7b0006d1f 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, lcc->client = client; slave->lcc = lcc; slave->controller_proc = - GNUNET_TESTBED_controller_start (GST_context->master_ips, + GNUNET_TESTBED_controller_start (GST_context->master_ip, GST_host_list[slave->host_id], &slave_status_cb, slave); new_route = GNUNET_malloc (sizeof (struct Route)); diff --git a/src/testbed/testbed.h b/src/testbed/testbed.h index 635708376..904e7acba 100644 --- a/src/testbed/testbed.h +++ b/src/testbed/testbed.h @@ -54,6 +54,8 @@ GNUNET_NETWORK_STRUCT_BEGIN * is interested in. In NBO. */ uint64_t event_mask GNUNET_PACKED; + + /* Followed by 0-terminated hostname of the controller */ }; diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 93bdb03e5..e1068a2b6 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c @@ -1440,9 +1440,10 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host, GNUNET_TESTBED_ControllerCallback cc, void *cc_cls) { - struct GNUNET_TESTBED_Controller *c; + struct GNUNET_TESTBED_Controller *controller; struct GNUNET_TESTBED_InitMessage *msg; const struct GNUNET_CONFIGURATION_Handle *cfg; + const char *controller_hostname; unsigned long long max_parallel_operations; unsigned long long max_parallel_service_connections; unsigned long long max_parallel_topology_config_operations; @@ -1472,35 +1473,44 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host, GNUNET_break (0); return NULL; } - c = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Controller)); - c->cc = cc; - c->cc_cls = cc_cls; - c->event_mask = event_mask; - c->cfg = GNUNET_CONFIGURATION_dup (cfg); - c->client = GNUNET_CLIENT_connect ("testbed", c->cfg); - if (NULL == c->client) + controller = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Controller)); + controller->cc = cc; + controller->cc_cls = cc_cls; + controller->event_mask = event_mask; + controller->cfg = GNUNET_CONFIGURATION_dup (cfg); + controller->client = GNUNET_CLIENT_connect ("testbed", controller->cfg); + if (NULL == controller->client) { - GNUNET_TESTBED_controller_disconnect (c); + GNUNET_TESTBED_controller_disconnect (controller); return NULL; } - GNUNET_TESTBED_mark_host_registered_at_ (host, c); - c->host = host; - c->opq_parallel_operations = + GNUNET_TESTBED_mark_host_registered_at_ (host, controller); + controller->host = host; + controller->opq_parallel_operations = GNUNET_TESTBED_operation_queue_create_ ((unsigned int) max_parallel_operations); - c->opq_parallel_service_connections = + controller->opq_parallel_service_connections = GNUNET_TESTBED_operation_queue_create_ ((unsigned int) max_parallel_service_connections); - c->opq_parallel_topology_config_operations = + controller->opq_parallel_topology_config_operations = GNUNET_TESTBED_operation_queue_create_ ((unsigned int) max_parallel_topology_config_operations); - msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_InitMessage)); + controller_hostname = GNUNET_TESTBED_host_get_hostname (host); + if (NULL == controller_hostname) + controller_hostname = "127.0.0.1"; + msg = + GNUNET_malloc (sizeof (struct GNUNET_TESTBED_InitMessage) + + strlen (controller_hostname) + 1); msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_INIT); - msg->header.size = htons (sizeof (struct GNUNET_TESTBED_InitMessage)); + msg->header.size = + htons (sizeof (struct GNUNET_TESTBED_InitMessage) + + strlen (controller_hostname) + 1); msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host)); - msg->event_mask = GNUNET_htonll (c->event_mask); - GNUNET_TESTBED_queue_message_ (c, &msg->header); - return c; + msg->event_mask = GNUNET_htonll (controller->event_mask); + strcpy ((char *) &msg[1], controller_hostname); + GNUNET_TESTBED_queue_message_ (controller, + (struct GNUNET_MessageHeader *) msg); + return controller; } -- 2.25.1