diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-05-17 09:23:41 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-05-17 09:23:41 +0000 |
commit | 6ebfc499830f2d447ef20514c66a1bb9e24f1dad (patch) | |
tree | efab039fde14230dbab2032268774c4c8dd3ceb8 /src | |
parent | c47979fd1c48558a4981ca853348d8b8d4c4197d (diff) | |
download | gnunet-6ebfc499830f2d447ef20514c66a1bb9e24f1dad.tar.gz gnunet-6ebfc499830f2d447ef20514c66a1bb9e24f1dad.zip |
- revert 27104
Diffstat (limited to 'src')
-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 |
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 | |||
@@ -474,48 +474,6 @@ 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 | /** | ||
519 | * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages | 477 | * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages |
520 | * | 478 | * |
521 | * @param cls NULL | 479 | * @param cls NULL |
@@ -528,11 +486,11 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client, | |||
528 | { | 486 | { |
529 | const struct GNUNET_TESTBED_InitMessage *msg; | 487 | const struct GNUNET_TESTBED_InitMessage *msg; |
530 | struct GNUNET_TESTBED_Host *host; | 488 | struct GNUNET_TESTBED_Host *host; |
489 | const char *controller_hostname; | ||
531 | char *ss_str; | 490 | char *ss_str; |
532 | struct GNUNET_TESTING_SharedService *ss; | 491 | struct GNUNET_TESTING_SharedService *ss; |
533 | char *hostname; | ||
534 | unsigned int cnt; | 492 | unsigned int cnt; |
535 | unsigned int len; | 493 | uint16_t msize; |
536 | 494 | ||
537 | if (NULL != GST_context) | 495 | if (NULL != GST_context) |
538 | { | 496 | { |
@@ -541,11 +499,18 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client, | |||
541 | return; | 499 | return; |
542 | } | 500 | } |
543 | msg = (const struct GNUNET_TESTBED_InitMessage *) message; | 501 | msg = (const struct GNUNET_TESTBED_InitMessage *) message; |
544 | len = GNUNET_OS_get_hostname_max_length (); | 502 | msize = ntohs (message->size); |
545 | hostname = GNUNET_malloc (len); | 503 | if (msize <= sizeof (struct GNUNET_TESTBED_InitMessage)) |
546 | if (0 != gethostname (hostname, len)) | 504 | { |
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]) | ||
547 | { | 512 | { |
548 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "gethostname"); | 513 | GNUNET_break (0); |
549 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 514 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
550 | return; | 515 | return; |
551 | } | 516 | } |
@@ -563,18 +528,10 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client, | |||
563 | GNUNET_SERVER_client_keep (client); | 528 | GNUNET_SERVER_client_keep (client); |
564 | GST_context->client = client; | 529 | GST_context->client = client; |
565 | GST_context->host_id = ntohl (msg->host_id); | 530 | GST_context->host_id = ntohl (msg->host_id); |
566 | GNUNET_OS_network_interfaces_list (&addr_proc, GST_context); | 531 | GST_context->master_ip = GNUNET_strdup (controller_hostname); |
567 | if (NULL == GST_context->master_ips) | 532 | LOG_DEBUG ("Our IP: %s\n", GST_context->master_ip); |
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); | ||
576 | GST_context->system = | 533 | GST_context->system = |
577 | GNUNET_TESTING_system_create ("testbed", GST_context->master_ips, | 534 | GNUNET_TESTING_system_create ("testbed", GST_context->master_ip, |
578 | hostname, ss); | 535 | hostname, ss); |
579 | if (NULL != ss) | 536 | if (NULL != ss) |
580 | { | 537 | { |
@@ -586,9 +543,10 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client, | |||
586 | GNUNET_free (ss); | 543 | GNUNET_free (ss); |
587 | ss = NULL; | 544 | ss = NULL; |
588 | } | 545 | } |
589 | 546 | host = | |
590 | host = GNUNET_TESTBED_host_create_with_id (GST_context->host_id, hostname, | 547 | GNUNET_TESTBED_host_create_with_id (GST_context->host_id, |
591 | NULL, our_config, 0); | 548 | GST_context->master_ip, NULL, |
549 | our_config, 0); | ||
592 | host_list_add (host); | 550 | host_list_add (host); |
593 | LOG_DEBUG ("Created master context with host ID: %u\n", GST_context->host_id); | 551 | LOG_DEBUG ("Created master context with host ID: %u\n", GST_context->host_id); |
594 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 552 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -850,7 +808,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
850 | GNUNET_free_non_null (GST_host_list); | 808 | GNUNET_free_non_null (GST_host_list); |
851 | if (NULL != GST_context) | 809 | if (NULL != GST_context) |
852 | { | 810 | { |
853 | GNUNET_free_non_null (GST_context->master_ips); | 811 | GNUNET_free_non_null (GST_context->master_ip); |
854 | if (NULL != GST_context->system) | 812 | if (NULL != GST_context->system) |
855 | GNUNET_TESTING_system_destroy (GST_context->system, GNUNET_YES); | 813 | GNUNET_TESTING_system_destroy (GST_context->system, GNUNET_YES); |
856 | GNUNET_SERVER_client_drop (GST_context->client); | 814 | GNUNET_SERVER_client_drop (GST_context->client); |
@@ -912,8 +870,7 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
912 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 870 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
913 | { | 871 | { |
914 | static const struct GNUNET_SERVER_MessageHandler message_handlers[] = { | 872 | static const struct GNUNET_SERVER_MessageHandler message_handlers[] = { |
915 | {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, | 873 | {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0}, |
916 | sizeof (struct GNUNET_TESTBED_InitMessage)}, | ||
917 | {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, 0}, | 874 | {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, 0}, |
918 | {&GST_handle_link_controllers, NULL, | 875 | {&GST_handle_link_controllers, NULL, |
919 | GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, | 876 | 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 | |||
260 | /** | 260 | /** |
261 | * The network address of the master controller | 261 | * The network address of the master controller |
262 | */ | 262 | */ |
263 | char *master_ips; | 263 | char *master_ip; |
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 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, | |||
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_ips, | 1251 | GNUNET_TESTBED_controller_start (GST_context->master_ip, |
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 635708376..904e7acba 100644 --- a/src/testbed/testbed.h +++ b/src/testbed/testbed.h | |||
@@ -54,6 +54,8 @@ 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 */ | ||
57 | }; | 59 | }; |
58 | 60 | ||
59 | 61 | ||
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, | |||
1440 | GNUNET_TESTBED_ControllerCallback cc, | 1440 | GNUNET_TESTBED_ControllerCallback cc, |
1441 | void *cc_cls) | 1441 | void *cc_cls) |
1442 | { | 1442 | { |
1443 | struct GNUNET_TESTBED_Controller *c; | 1443 | struct GNUNET_TESTBED_Controller *controller; |
1444 | struct GNUNET_TESTBED_InitMessage *msg; | 1444 | struct GNUNET_TESTBED_InitMessage *msg; |
1445 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 1445 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
1446 | const char *controller_hostname; | ||
1446 | unsigned long long max_parallel_operations; | 1447 | unsigned long long max_parallel_operations; |
1447 | unsigned long long max_parallel_service_connections; | 1448 | unsigned long long max_parallel_service_connections; |
1448 | unsigned long long max_parallel_topology_config_operations; | 1449 | unsigned long long max_parallel_topology_config_operations; |
@@ -1472,35 +1473,44 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host, | |||
1472 | GNUNET_break (0); | 1473 | GNUNET_break (0); |
1473 | return NULL; | 1474 | return NULL; |
1474 | } | 1475 | } |
1475 | c = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Controller)); | 1476 | controller = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Controller)); |
1476 | c->cc = cc; | 1477 | controller->cc = cc; |
1477 | c->cc_cls = cc_cls; | 1478 | controller->cc_cls = cc_cls; |
1478 | c->event_mask = event_mask; | 1479 | controller->event_mask = event_mask; |
1479 | c->cfg = GNUNET_CONFIGURATION_dup (cfg); | 1480 | controller->cfg = GNUNET_CONFIGURATION_dup (cfg); |
1480 | c->client = GNUNET_CLIENT_connect ("testbed", c->cfg); | 1481 | controller->client = GNUNET_CLIENT_connect ("testbed", controller->cfg); |
1481 | if (NULL == c->client) | 1482 | if (NULL == controller->client) |
1482 | { | 1483 | { |
1483 | GNUNET_TESTBED_controller_disconnect (c); | 1484 | GNUNET_TESTBED_controller_disconnect (controller); |
1484 | return NULL; | 1485 | return NULL; |
1485 | } | 1486 | } |
1486 | GNUNET_TESTBED_mark_host_registered_at_ (host, c); | 1487 | GNUNET_TESTBED_mark_host_registered_at_ (host, controller); |
1487 | c->host = host; | 1488 | controller->host = host; |
1488 | c->opq_parallel_operations = | 1489 | controller->opq_parallel_operations = |
1489 | GNUNET_TESTBED_operation_queue_create_ ((unsigned int) | 1490 | GNUNET_TESTBED_operation_queue_create_ ((unsigned int) |
1490 | max_parallel_operations); | 1491 | max_parallel_operations); |
1491 | c->opq_parallel_service_connections = | 1492 | controller->opq_parallel_service_connections = |
1492 | GNUNET_TESTBED_operation_queue_create_ ((unsigned int) | 1493 | GNUNET_TESTBED_operation_queue_create_ ((unsigned int) |
1493 | max_parallel_service_connections); | 1494 | max_parallel_service_connections); |
1494 | c->opq_parallel_topology_config_operations = | 1495 | controller->opq_parallel_topology_config_operations = |
1495 | GNUNET_TESTBED_operation_queue_create_ ((unsigned int) | 1496 | GNUNET_TESTBED_operation_queue_create_ ((unsigned int) |
1496 | max_parallel_topology_config_operations); | 1497 | max_parallel_topology_config_operations); |
1497 | msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_InitMessage)); | 1498 | controller_hostname = GNUNET_TESTBED_host_get_hostname (host); |
1499 | if (NULL == controller_hostname) | ||
1500 | controller_hostname = "127.0.0.1"; | ||
1501 | msg = | ||
1502 | GNUNET_malloc (sizeof (struct GNUNET_TESTBED_InitMessage) + | ||
1503 | strlen (controller_hostname) + 1); | ||
1498 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_INIT); | 1504 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_INIT); |
1499 | msg->header.size = htons (sizeof (struct GNUNET_TESTBED_InitMessage)); | 1505 | msg->header.size = |
1506 | htons (sizeof (struct GNUNET_TESTBED_InitMessage) + | ||
1507 | strlen (controller_hostname) + 1); | ||
1500 | msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host)); | 1508 | msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host)); |
1501 | msg->event_mask = GNUNET_htonll (c->event_mask); | 1509 | msg->event_mask = GNUNET_htonll (controller->event_mask); |
1502 | GNUNET_TESTBED_queue_message_ (c, &msg->header); | 1510 | strcpy ((char *) &msg[1], controller_hostname); |
1503 | return c; | 1511 | GNUNET_TESTBED_queue_message_ (controller, |
1512 | (struct GNUNET_MessageHeader *) msg); | ||
1513 | return controller; | ||
1504 | } | 1514 | } |
1505 | 1515 | ||
1506 | 1516 | ||