aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-08-10 15:33:26 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-08-10 15:33:26 +0000
commit4693fb2d1f0c831dfc1621ab76e85e0ba233e3d7 (patch)
treeb71343462b72429fb749f463026174e34f7d79c3 /src/testbed
parent8c15f0c9f77a5014f0331f80e2a60914873f93b5 (diff)
downloadgnunet-4693fb2d1f0c831dfc1621ab76e85e0ba233e3d7.tar.gz
gnunet-4693fb2d1f0c831dfc1621ab76e85e0ba233e3d7.zip
controller hostname in init
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/gnunet-service-testbed.c44
-rw-r--r--src/testbed/testbed.h2
-rw-r--r--src/testbed/testbed_api.c19
3 files changed, 35 insertions, 30 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index ff19250aa..c9781ba4e 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -935,8 +935,8 @@ handle_init (void *cls,
935{ 935{
936 const struct GNUNET_TESTBED_InitMessage *msg; 936 const struct GNUNET_TESTBED_InitMessage *msg;
937 struct GNUNET_TESTBED_Host *host; 937 struct GNUNET_TESTBED_Host *host;
938 void *addr; 938 const char *controller_hostname;
939 size_t addrlen; 939 uint16_t msize;
940 940
941 if (NULL != master_context) 941 if (NULL != master_context)
942 { 942 {
@@ -944,29 +944,26 @@ handle_init (void *cls,
944 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 944 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
945 return; 945 return;
946 } 946 }
947 msg = (const struct GNUNET_TESTBED_InitMessage *) message; 947 msg = (const struct GNUNET_TESTBED_InitMessage *) message;
948 msize = ntohs (message->size);
949 if (msize <= sizeof (struct GNUNET_TESTBED_InitMessage))
950 {
951 GNUNET_break (0);
952 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
953 return;
954 }
955 msize -= sizeof (struct GNUNET_TESTBED_InitMessage);
956 controller_hostname = (const char *) &msg[1];
957 if ('\0' != controller_hostname[msize - 1])
958 {
959 GNUNET_break (0);
960 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
961 return;
962 }
948 master_context = GNUNET_malloc (sizeof (struct Context)); 963 master_context = GNUNET_malloc (sizeof (struct Context));
949 master_context->client = client; 964 master_context->client = client;
950 master_context->host_id = ntohl (msg->host_id); 965 master_context->host_id = ntohl (msg->host_id);
951 GNUNET_assert (GNUNET_OK == 966 master_context->master_ip = GNUNET_strdup (controller_hostname);
952 GNUNET_SERVER_client_get_address (client, &addr, &addrlen));
953 master_context->master_ip = GNUNET_malloc (NI_MAXHOST);
954 if (0 != getnameinfo (addr, addrlen, master_context->master_ip, NI_MAXHOST,
955 NULL, 0, NI_NUMERICHOST))
956 {
957 LOG (GNUNET_ERROR_TYPE_WARNING,
958 "Cannot determine the ip of master controller: %s\n", STRERROR (errno));
959 GNUNET_free (addr);
960 GNUNET_free (master_context->master_ip);
961 GNUNET_assert (0);
962 }
963 GNUNET_free (addr);
964 if (0 == strcasecmp (master_context->master_ip, "localhost"))
965 { /* Hack for connections via unix sockets */
966 LOG_DEBUG ("May be using local sockets - assuming loopback for master ip\n");
967 GNUNET_free (master_context->master_ip);
968 master_context->master_ip = strdup ("127.0.0.1");
969 }
970 LOG_DEBUG ("Master Controller IP: %s\n", master_context->master_ip); 967 LOG_DEBUG ("Master Controller IP: %s\n", master_context->master_ip);
971 master_context->system = 968 master_context->system =
972 GNUNET_TESTING_system_create ("testbed", master_context->master_ip); 969 GNUNET_TESTING_system_create ("testbed", master_context->master_ip);
@@ -2031,8 +2028,7 @@ testbed_run (void *cls,
2031{ 2028{
2032 static const struct GNUNET_SERVER_MessageHandler message_handlers[] = 2029 static const struct GNUNET_SERVER_MessageHandler message_handlers[] =
2033 { 2030 {
2034 {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 2031 {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0},
2035 sizeof (struct GNUNET_TESTBED_InitMessage)},
2036 {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST, 0}, 2032 {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST, 0},
2037 {&handle_configure_shared_service, NULL, 2033 {&handle_configure_shared_service, NULL,
2038 GNUNET_MESSAGE_TYPE_TESTBED_SERVICESHARE, 0}, 2034 GNUNET_MESSAGE_TYPE_TESTBED_SERVICESHARE, 0},
diff --git a/src/testbed/testbed.h b/src/testbed/testbed.h
index d4d081b08..d0f2accb4 100644
--- a/src/testbed/testbed.h
+++ b/src/testbed/testbed.h
@@ -54,6 +54,8 @@ struct GNUNET_TESTBED_InitMessage
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 2269db8e7..7f1c292be 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -997,6 +997,7 @@ GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg
997{ 997{
998 struct GNUNET_TESTBED_Controller *controller; 998 struct GNUNET_TESTBED_Controller *controller;
999 struct GNUNET_TESTBED_InitMessage *msg; 999 struct GNUNET_TESTBED_InitMessage *msg;
1000 const char *controller_hostname;
1000 unsigned long long max_parallel_peer_create; 1001 unsigned long long max_parallel_peer_create;
1001 1002
1002 if (GNUNET_OK != 1003 if (GNUNET_OK !=
@@ -1021,7 +1022,7 @@ GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg
1021 if (NULL == host) 1022 if (NULL == host)
1022 { 1023 {
1023 host = GNUNET_TESTBED_host_create_by_id_ (0); 1024 host = GNUNET_TESTBED_host_create_by_id_ (0);
1024 if (NULL == host) 1025 if (NULL == host) /* If the above host create fails */
1025 { 1026 {
1026 LOG (GNUNET_ERROR_TYPE_WARNING, 1027 LOG (GNUNET_ERROR_TYPE_WARNING,
1027 "Treating NULL host as localhost. Multiple references to localhost " 1028 "Treating NULL host as localhost. Multiple references to localhost "
@@ -1037,14 +1038,19 @@ GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg
1037 controller->opq_peer_create = 1038 controller->opq_peer_create =
1038 GNUNET_TESTBED_operation_queue_create_ ((unsigned int) 1039 GNUNET_TESTBED_operation_queue_create_ ((unsigned int)
1039 max_parallel_peer_create); 1040 max_parallel_peer_create);
1040 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_InitMessage)); 1041 controller_hostname = GNUNET_TESTBED_host_get_hostname_ (host);
1042 if (NULL == controller_hostname)
1043 controller_hostname = "127.0.0.1";
1044 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_InitMessage)
1045 + strlen (controller_hostname) + 1);
1041 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_INIT); 1046 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_INIT);
1042 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_InitMessage)); 1047 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_InitMessage)
1048 + strlen (controller_hostname) + 1);
1043 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host)); 1049 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host));
1044 msg->event_mask = GNUNET_htonll (controller->event_mask); 1050 msg->event_mask = GNUNET_htonll (controller->event_mask);
1051 strcpy ((char *) &msg[1], controller_hostname);
1045 GNUNET_TESTBED_queue_message_ (controller, (struct GNUNET_MessageHeader *) 1052 GNUNET_TESTBED_queue_message_ (controller, (struct GNUNET_MessageHeader *)
1046 msg); 1053 msg);
1047
1048 return controller; 1054 return controller;
1049} 1055}
1050 1056
@@ -1342,7 +1348,8 @@ GNUNET_TESTBED_overlay_write_topology_to_file (struct GNUNET_TESTBED_Controller
1342 1348
1343 1349
1344/** 1350/**
1345 * Creates a helper initialization message. Only for testing. 1351 * Creates a helper initialization message. This function is here because we
1352 * want to use this in testing
1346 * 1353 *
1347 * @param cname the ip address of the controlling host 1354 * @param cname the ip address of the controlling host
1348 * @param cfg the configuration that has to used to start the testbed service 1355 * @param cfg the configuration that has to used to start the testbed service