diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-02-21 11:32:53 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-02-21 11:32:53 +0000 |
commit | a250da032ba65252d9da96e8429b22e265c69980 (patch) | |
tree | 89eb6410952e30bd6b37c0a827be4a6ec6a3e839 /src | |
parent | eb9d17abd52471e8cd3dcb45bbd4b93231da23c3 (diff) | |
download | gnunet-a250da032ba65252d9da96e8429b22e265c69980.tar.gz gnunet-a250da032ba65252d9da96e8429b22e265c69980.zip |
M testbed/testbed.h
naming consistency
include uncompressed config size
M testbed/testbed_api_hosts.c
pulled host registration functions from testbed_api.c
M testbed/testbed_api_hosts.h
export handler to handle ADD_HOST confirmation messages
M testbed/gnunet-service-testbed.c
parse the modified ADD_HOST message
M testbed/testbed_api.c
lose host registration code
extract configuration from ADD_HOST messages
M testbed/testbed_api.h
include hacks
Diffstat (limited to 'src')
-rw-r--r-- | src/testbed/gnunet-service-testbed.c | 78 | ||||
-rw-r--r-- | src/testbed/testbed.h | 7 | ||||
-rw-r--r-- | src/testbed/testbed_api.c | 204 | ||||
-rw-r--r-- | src/testbed/testbed_api.h | 2 | ||||
-rw-r--r-- | src/testbed/testbed_api_hosts.c | 190 | ||||
-rw-r--r-- | src/testbed/testbed_api_hosts.h | 21 |
6 files changed, 296 insertions, 206 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index 059423e96..c9cfd87b0 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c | |||
@@ -967,9 +967,11 @@ handle_add_host (void *cls, struct GNUNET_SERVER_Client *client, | |||
967 | struct GNUNET_TESTBED_Host *host; | 967 | struct GNUNET_TESTBED_Host *host; |
968 | const struct GNUNET_TESTBED_AddHostMessage *msg; | 968 | const struct GNUNET_TESTBED_AddHostMessage *msg; |
969 | struct GNUNET_TESTBED_HostConfirmedMessage *reply; | 969 | struct GNUNET_TESTBED_HostConfirmedMessage *reply; |
970 | struct GNUNET_CONFIGURATION_Handle *host_cfg; | ||
970 | char *username; | 971 | char *username; |
971 | char *hostname; | 972 | char *hostname; |
972 | char *emsg; | 973 | char *emsg; |
974 | const void *ptr; | ||
973 | uint32_t host_id; | 975 | uint32_t host_id; |
974 | uint16_t username_length; | 976 | uint16_t username_length; |
975 | uint16_t hostname_length; | 977 | uint16_t hostname_length; |
@@ -978,38 +980,72 @@ handle_add_host (void *cls, struct GNUNET_SERVER_Client *client, | |||
978 | 980 | ||
979 | msg = (const struct GNUNET_TESTBED_AddHostMessage *) message; | 981 | msg = (const struct GNUNET_TESTBED_AddHostMessage *) message; |
980 | msize = ntohs (msg->header.size); | 982 | msize = ntohs (msg->header.size); |
981 | username = (char *) &msg[1]; | 983 | if (msize <= sizeof (struct GNUNET_TESTBED_AddHostMessage)) |
982 | username_length = ntohs (msg->user_name_length); | 984 | { |
983 | if (0 != username_length) | 985 | GNUNET_break_op (0); |
984 | username_length++; | 986 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
987 | return; | ||
988 | } | ||
989 | username_length = ntohs (msg->username_length); | ||
990 | hostname_length = ntohs (msg->hostname_length); | ||
985 | /* msg must contain hostname */ | 991 | /* msg must contain hostname */ |
986 | GNUNET_assert (msize > | 992 | if ((msize <= (sizeof (struct GNUNET_TESTBED_AddHostMessage) + |
987 | (sizeof (struct GNUNET_TESTBED_AddHostMessage) + | 993 | username_length)) |
988 | username_length + 1)); | 994 | || (0 == hostname_length)) |
995 | { | ||
996 | GNUNET_break_op (0); | ||
997 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
998 | return; | ||
999 | } | ||
1000 | /* msg must contain configuration */ | ||
1001 | if (msize <= (sizeof (struct GNUNET_TESTBED_AddHostMessage) + | ||
1002 | username_length + hostname_length)) | ||
1003 | { | ||
1004 | GNUNET_break_op (0); | ||
1005 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1006 | return; | ||
1007 | } | ||
1008 | username = NULL; | ||
1009 | hostname = NULL; | ||
1010 | ptr = &msg[1]; | ||
989 | if (0 != username_length) | 1011 | if (0 != username_length) |
990 | GNUNET_assert ('\0' == username[username_length - 1]); | 1012 | { |
991 | hostname = username + username_length; | 1013 | username = GNUNET_malloc (username_length + 1); |
992 | hostname_length = | 1014 | strncpy (username, ptr, username_length); |
993 | msize - (sizeof (struct GNUNET_TESTBED_AddHostMessage) + username_length); | 1015 | ptr += username_length; |
994 | GNUNET_assert ('\0' == hostname[hostname_length - 1]); | 1016 | } |
995 | GNUNET_assert (strlen (hostname) == hostname_length - 1); | 1017 | hostname = GNUNET_malloc (hostname_length + 1); |
1018 | strncpy (hostname, ptr, hostname_length); | ||
1019 | ptr += hostname_length; | ||
1020 | if (NULL == (host_cfg = GNUNET_TESTBED_extract_config_ (message))) | ||
1021 | { | ||
1022 | GNUNET_free_non_null (username); | ||
1023 | GNUNET_free_non_null (hostname); | ||
1024 | GNUNET_break_op (0); | ||
1025 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1026 | return; | ||
1027 | } | ||
996 | host_id = ntohl (msg->host_id); | 1028 | host_id = ntohl (msg->host_id); |
997 | LOG_DEBUG ("Received ADDHOST %u message\n", host_id); | 1029 | LOG_DEBUG ("Received ADDHOST %u message\n", host_id); |
998 | LOG_DEBUG ("-------host id: %u\n", host_id); | 1030 | LOG_DEBUG ("-------host id: %u\n", host_id); |
999 | LOG_DEBUG ("-------hostname: %s\n", hostname); | 1031 | LOG_DEBUG ("-------hostname: %s\n", hostname); |
1000 | if (0 != username_length) | 1032 | if (NULL != username) |
1001 | LOG_DEBUG ("-------username: %s\n", username); | 1033 | LOG_DEBUG ("-------username: %s\n", username); |
1002 | else | 1034 | else |
1003 | { | 1035 | LOG_DEBUG ("-------username: <not given>\n"); |
1004 | LOG_DEBUG ("-------username: NULL\n"); | ||
1005 | username = NULL; | ||
1006 | } | ||
1007 | LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port)); | 1036 | LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port)); |
1008 | /* FIXME: should use configuration from ADDHOST message */ | ||
1009 | host = | 1037 | host = |
1010 | GNUNET_TESTBED_host_create_with_id (host_id, hostname, username, | 1038 | GNUNET_TESTBED_host_create_with_id (host_id, hostname, username, |
1011 | our_config, ntohs (msg->ssh_port)); | 1039 | host_cfg, ntohs (msg->ssh_port)); |
1012 | GNUNET_assert (NULL != host); | 1040 | GNUNET_free_non_null (username); |
1041 | GNUNET_free (hostname); | ||
1042 | GNUNET_CONFIGURATION_destroy (host_cfg); | ||
1043 | if (NULL == host) | ||
1044 | { | ||
1045 | GNUNET_break_op (0); | ||
1046 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1047 | return; | ||
1048 | } | ||
1013 | reply_size = sizeof (struct GNUNET_TESTBED_HostConfirmedMessage); | 1049 | reply_size = sizeof (struct GNUNET_TESTBED_HostConfirmedMessage); |
1014 | if (GNUNET_OK != host_list_add (host)) | 1050 | if (GNUNET_OK != host_list_add (host)) |
1015 | { | 1051 | { |
diff --git a/src/testbed/testbed.h b/src/testbed/testbed.h index 880a44864..3bed4ed56 100644 --- a/src/testbed/testbed.h +++ b/src/testbed/testbed.h | |||
@@ -85,7 +85,7 @@ struct GNUNET_TESTBED_AddHostMessage | |||
85 | * 0 to use no user name; otherwise 'strlen (username)', | 85 | * 0 to use no user name; otherwise 'strlen (username)', |
86 | * excluding 0-termination! | 86 | * excluding 0-termination! |
87 | */ | 87 | */ |
88 | uint16_t user_name_length GNUNET_PACKED; | 88 | uint16_t username_length GNUNET_PACKED; |
89 | 89 | ||
90 | /** | 90 | /** |
91 | * Number of bytes in the host name (excluding 0-termination) that follows the | 91 | * Number of bytes in the host name (excluding 0-termination) that follows the |
@@ -93,6 +93,11 @@ struct GNUNET_TESTBED_AddHostMessage | |||
93 | */ | 93 | */ |
94 | uint16_t hostname_length GNUNET_PACKED; | 94 | uint16_t hostname_length GNUNET_PACKED; |
95 | 95 | ||
96 | /** | ||
97 | * The length of the uncompressed configuration | ||
98 | */ | ||
99 | uint16_t config_size GNUNET_PACKED; | ||
100 | |||
96 | /* followed by non 0-terminated user name */ | 101 | /* followed by non 0-terminated user name */ |
97 | 102 | ||
98 | /* followed by non 0-terminated host name */ | 103 | /* followed by non 0-terminated host name */ |
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index eba4544eb..993883023 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -130,33 +130,6 @@ struct ControllerLink | |||
130 | 130 | ||
131 | 131 | ||
132 | /** | 132 | /** |
133 | * handle for host registration | ||
134 | */ | ||
135 | struct GNUNET_TESTBED_HostRegistrationHandle | ||
136 | { | ||
137 | /** | ||
138 | * The host being registered | ||
139 | */ | ||
140 | struct GNUNET_TESTBED_Host *host; | ||
141 | |||
142 | /** | ||
143 | * The controller at which this host is being registered | ||
144 | */ | ||
145 | struct GNUNET_TESTBED_Controller *c; | ||
146 | |||
147 | /** | ||
148 | * The Registartion completion callback | ||
149 | */ | ||
150 | GNUNET_TESTBED_HostRegistrationCompletion cc; | ||
151 | |||
152 | /** | ||
153 | * The closure for above callback | ||
154 | */ | ||
155 | void *cc_cls; | ||
156 | }; | ||
157 | |||
158 | |||
159 | /** | ||
160 | * Context data for forwarded Operation | 133 | * Context data for forwarded Operation |
161 | */ | 134 | */ |
162 | struct ForwardedOperationData | 135 | struct ForwardedOperationData |
@@ -236,61 +209,6 @@ find_opc (const struct GNUNET_TESTBED_Controller *c, const uint64_t id) | |||
236 | 209 | ||
237 | 210 | ||
238 | /** | 211 | /** |
239 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from | ||
240 | * controller (testbed service) | ||
241 | * | ||
242 | * @param c the controller handler | ||
243 | * @param msg message received | ||
244 | * @return GNUNET_YES if we can continue receiving from service; GNUNET_NO if | ||
245 | * not | ||
246 | */ | ||
247 | static int | ||
248 | handle_addhostconfirm (struct GNUNET_TESTBED_Controller *c, | ||
249 | const struct GNUNET_TESTBED_HostConfirmedMessage *msg) | ||
250 | { | ||
251 | struct GNUNET_TESTBED_HostRegistrationHandle *rh; | ||
252 | char *emsg; | ||
253 | uint16_t msg_size; | ||
254 | |||
255 | rh = c->rh; | ||
256 | if (NULL == rh) | ||
257 | { | ||
258 | return GNUNET_OK; | ||
259 | } | ||
260 | if (GNUNET_TESTBED_host_get_id_ (rh->host) != ntohl (msg->host_id)) | ||
261 | { | ||
262 | LOG_DEBUG ("Mismatch in host id's %u, %u of host confirm msg\n", | ||
263 | GNUNET_TESTBED_host_get_id_ (rh->host), ntohl (msg->host_id)); | ||
264 | return GNUNET_OK; | ||
265 | } | ||
266 | c->rh = NULL; | ||
267 | msg_size = ntohs (msg->header.size); | ||
268 | if (sizeof (struct GNUNET_TESTBED_HostConfirmedMessage) == msg_size) | ||
269 | { | ||
270 | LOG_DEBUG ("Host %u successfully registered\n", ntohl (msg->host_id)); | ||
271 | GNUNET_TESTBED_mark_host_registered_at_ (rh->host, c); | ||
272 | rh->cc (rh->cc_cls, NULL); | ||
273 | GNUNET_free (rh); | ||
274 | return GNUNET_OK; | ||
275 | } | ||
276 | /* We have an error message */ | ||
277 | emsg = (char *) &msg[1]; | ||
278 | if ('\0' != | ||
279 | emsg[msg_size - sizeof (struct GNUNET_TESTBED_HostConfirmedMessage)]) | ||
280 | { | ||
281 | GNUNET_break (0); | ||
282 | GNUNET_free (rh); | ||
283 | return GNUNET_NO; | ||
284 | } | ||
285 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Adding host %u failed with error: %s\n"), | ||
286 | ntohl (msg->host_id), emsg); | ||
287 | rh->cc (rh->cc_cls, emsg); | ||
288 | GNUNET_free (rh); | ||
289 | return GNUNET_OK; | ||
290 | } | ||
291 | |||
292 | |||
293 | /** | ||
294 | * Handler for forwarded operations | 212 | * Handler for forwarded operations |
295 | * | 213 | * |
296 | * @param c the controller handle | 214 | * @param c the controller handle |
@@ -857,9 +775,8 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
857 | GNUNET_assert (msize >= | 775 | GNUNET_assert (msize >= |
858 | sizeof (struct GNUNET_TESTBED_HostConfirmedMessage)); | 776 | sizeof (struct GNUNET_TESTBED_HostConfirmedMessage)); |
859 | status = | 777 | status = |
860 | handle_addhostconfirm (c, | 778 | GNUNET_TESTBED_host_handle_addhostconfirm_ |
861 | (const struct GNUNET_TESTBED_HostConfirmedMessage | 779 | (c, (const struct GNUNET_TESTBED_HostConfirmedMessage*) msg); |
862 | *) msg); | ||
863 | break; | 780 | break; |
864 | case GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS: | 781 | case GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS: |
865 | GNUNET_assert (msize == | 782 | GNUNET_assert (msize == |
@@ -1368,98 +1285,6 @@ GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller | |||
1368 | 1285 | ||
1369 | 1286 | ||
1370 | /** | 1287 | /** |
1371 | * Register a host with the controller | ||
1372 | * | ||
1373 | * @param controller the controller handle | ||
1374 | * @param host the host to register | ||
1375 | * @param cc the completion callback to call to inform the status of | ||
1376 | * registration. After calling this callback the registration handle | ||
1377 | * will be invalid. Cannot be NULL. | ||
1378 | * @param cc_cls the closure for the cc | ||
1379 | * @return handle to the host registration which can be used to cancel the | ||
1380 | * registration | ||
1381 | */ | ||
1382 | struct GNUNET_TESTBED_HostRegistrationHandle * | ||
1383 | GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller, | ||
1384 | struct GNUNET_TESTBED_Host *host, | ||
1385 | GNUNET_TESTBED_HostRegistrationCompletion cc, | ||
1386 | void *cc_cls) | ||
1387 | { | ||
1388 | struct GNUNET_TESTBED_HostRegistrationHandle *rh; | ||
1389 | struct GNUNET_TESTBED_AddHostMessage *msg; | ||
1390 | const char *username; | ||
1391 | const char *hostname; | ||
1392 | uint16_t msg_size; | ||
1393 | uint16_t user_name_length; | ||
1394 | |||
1395 | if (NULL != controller->rh) | ||
1396 | return NULL; | ||
1397 | hostname = GNUNET_TESTBED_host_get_hostname (host); | ||
1398 | if (GNUNET_YES == GNUNET_TESTBED_is_host_registered_ (host, controller)) | ||
1399 | { | ||
1400 | LOG (GNUNET_ERROR_TYPE_WARNING, "Host hostname: %s already registered\n", | ||
1401 | (NULL == hostname) ? "localhost" : hostname); | ||
1402 | return NULL; | ||
1403 | } | ||
1404 | rh = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HostRegistrationHandle)); | ||
1405 | rh->host = host; | ||
1406 | rh->c = controller; | ||
1407 | GNUNET_assert (NULL != cc); | ||
1408 | rh->cc = cc; | ||
1409 | rh->cc_cls = cc_cls; | ||
1410 | controller->rh = rh; | ||
1411 | username = GNUNET_TESTBED_host_get_username_ (host); | ||
1412 | msg_size = (sizeof (struct GNUNET_TESTBED_AddHostMessage)); | ||
1413 | user_name_length = 0; | ||
1414 | if (NULL != username) | ||
1415 | { | ||
1416 | user_name_length = strlen (username) + 1; | ||
1417 | msg_size += user_name_length; | ||
1418 | } | ||
1419 | /* FIXME: what happens when hostname is NULL? localhost */ | ||
1420 | GNUNET_assert (NULL != hostname); | ||
1421 | msg_size += strlen (hostname) + 1; | ||
1422 | msg = GNUNET_malloc (msg_size); | ||
1423 | msg->header.size = htons (msg_size); | ||
1424 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST); | ||
1425 | msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host)); | ||
1426 | msg->ssh_port = htons (GNUNET_TESTBED_host_get_ssh_port_ (host)); | ||
1427 | if (NULL != username) | ||
1428 | { | ||
1429 | msg->user_name_length = htons (user_name_length - 1); | ||
1430 | memcpy (&msg[1], username, user_name_length); | ||
1431 | } | ||
1432 | else | ||
1433 | msg->user_name_length = htons (user_name_length); | ||
1434 | strcpy (((void *) &msg[1]) + user_name_length, hostname); | ||
1435 | GNUNET_TESTBED_queue_message_ (controller, | ||
1436 | (struct GNUNET_MessageHeader *) msg); | ||
1437 | return rh; | ||
1438 | } | ||
1439 | |||
1440 | |||
1441 | /** | ||
1442 | * Cancel the pending registration. Note that if the registration message is | ||
1443 | * already sent to the service the cancellation has only the effect that the | ||
1444 | * registration completion callback for the registration is never called. | ||
1445 | * | ||
1446 | * @param handle the registration handle to cancel | ||
1447 | */ | ||
1448 | void | ||
1449 | GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle | ||
1450 | *handle) | ||
1451 | { | ||
1452 | if (handle != handle->c->rh) | ||
1453 | { | ||
1454 | GNUNET_break (0); | ||
1455 | return; | ||
1456 | } | ||
1457 | handle->c->rh = NULL; | ||
1458 | GNUNET_free (handle); | ||
1459 | } | ||
1460 | |||
1461 | |||
1462 | /** | ||
1463 | * Same as the GNUNET_TESTBED_controller_link_2, but with ids for delegated host | 1288 | * Same as the GNUNET_TESTBED_controller_link_2, but with ids for delegated host |
1464 | * and slave host | 1289 | * and slave host |
1465 | * | 1290 | * |
@@ -1870,11 +1695,12 @@ GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation) | |||
1870 | /** | 1695 | /** |
1871 | * Generates configuration by uncompressing configuration in given message. The | 1696 | * Generates configuration by uncompressing configuration in given message. The |
1872 | * given message should be of the following types: | 1697 | * given message should be of the following types: |
1873 | * GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG, | 1698 | * GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONFIGURATION, |
1874 | * GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG | 1699 | * GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION, |
1700 | * GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST | ||
1875 | * | 1701 | * |
1876 | * @param msg the message containing compressed configuration | 1702 | * @param msg the message containing compressed configuration |
1877 | * @return handle to the parsed configuration | 1703 | * @return handle to the parsed configuration; NULL upon error while parsing the message |
1878 | */ | 1704 | */ |
1879 | struct GNUNET_CONFIGURATION_Handle * | 1705 | struct GNUNET_CONFIGURATION_Handle * |
1880 | GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg) | 1706 | GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg) |
@@ -1912,13 +1738,29 @@ GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg) | |||
1912 | sizeof (struct GNUNET_TESTBED_SlaveConfiguration); | 1738 | sizeof (struct GNUNET_TESTBED_SlaveConfiguration); |
1913 | xdata = (const Bytef *) &imsg[1]; | 1739 | xdata = (const Bytef *) &imsg[1]; |
1914 | } | 1740 | } |
1741 | break; | ||
1742 | case GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST: | ||
1743 | { | ||
1744 | const struct GNUNET_TESTBED_AddHostMessage *imsg; | ||
1745 | uint16_t osize; | ||
1746 | |||
1747 | imsg = (const struct GNUNET_TESTBED_AddHostMessage *) msg; | ||
1748 | data_len = (uLong) ntohs (imsg->config_size); | ||
1749 | osize = sizeof (struct GNUNET_TESTBED_AddHostMessage) + | ||
1750 | ntohs (imsg->username_length) + ntohs (imsg->hostname_length); | ||
1751 | xdata_len = ntohs (imsg->header.size) - osize; | ||
1752 | xdata = (const Bytef *) ((const void *) imsg + osize); | ||
1753 | } | ||
1915 | break; | 1754 | break; |
1916 | default: | 1755 | default: |
1917 | GNUNET_assert (0); | 1756 | GNUNET_assert (0); |
1918 | } | 1757 | } |
1919 | data = GNUNET_malloc (data_len); | 1758 | data = GNUNET_malloc (data_len); |
1920 | if (Z_OK != (ret = uncompress (data, &data_len, xdata, xdata_len))) | 1759 | if (Z_OK != (ret = uncompress (data, &data_len, xdata, xdata_len))) |
1921 | GNUNET_assert (0); | 1760 | { |
1761 | GNUNET_free (data); | ||
1762 | return NULL; | ||
1763 | } | ||
1922 | cfg = GNUNET_CONFIGURATION_create (); | 1764 | cfg = GNUNET_CONFIGURATION_create (); |
1923 | GNUNET_assert (GNUNET_OK == | 1765 | GNUNET_assert (GNUNET_OK == |
1924 | GNUNET_CONFIGURATION_deserialize (cfg, (const char *) data, | 1766 | GNUNET_CONFIGURATION_deserialize (cfg, (const char *) data, |
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h index 26b0d5843..28a19daaf 100644 --- a/src/testbed/testbed_api.h +++ b/src/testbed/testbed_api.h | |||
@@ -29,7 +29,7 @@ | |||
29 | 29 | ||
30 | #include "gnunet_testbed_service.h" | 30 | #include "gnunet_testbed_service.h" |
31 | #include "testbed.h" | 31 | #include "testbed.h" |
32 | 32 | #include "testbed_helper.h" | |
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Testbed Helper binary name | 35 | * Testbed Helper binary name |
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c index d979d575b..9e671087a 100644 --- a/src/testbed/testbed_api_hosts.c +++ b/src/testbed/testbed_api_hosts.c | |||
@@ -33,6 +33,7 @@ | |||
33 | 33 | ||
34 | #include "testbed_api.h" | 34 | #include "testbed_api.h" |
35 | #include "testbed_api_hosts.h" | 35 | #include "testbed_api_hosts.h" |
36 | #include "testbed_helper.h" | ||
36 | #include "testbed_api_operations.h" | 37 | #include "testbed_api_operations.h" |
37 | #include "testbed_api_sd.h" | 38 | #include "testbed_api_sd.h" |
38 | 39 | ||
@@ -1208,6 +1209,138 @@ GNUNET_TESTBED_is_host_habitable_cancel (struct | |||
1208 | 1209 | ||
1209 | 1210 | ||
1210 | /** | 1211 | /** |
1212 | * handle for host registration | ||
1213 | */ | ||
1214 | struct GNUNET_TESTBED_HostRegistrationHandle | ||
1215 | { | ||
1216 | /** | ||
1217 | * The host being registered | ||
1218 | */ | ||
1219 | struct GNUNET_TESTBED_Host *host; | ||
1220 | |||
1221 | /** | ||
1222 | * The controller at which this host is being registered | ||
1223 | */ | ||
1224 | struct GNUNET_TESTBED_Controller *c; | ||
1225 | |||
1226 | /** | ||
1227 | * The Registartion completion callback | ||
1228 | */ | ||
1229 | GNUNET_TESTBED_HostRegistrationCompletion cc; | ||
1230 | |||
1231 | /** | ||
1232 | * The closure for above callback | ||
1233 | */ | ||
1234 | void *cc_cls; | ||
1235 | }; | ||
1236 | |||
1237 | |||
1238 | /** | ||
1239 | * Register a host with the controller | ||
1240 | * | ||
1241 | * @param controller the controller handle | ||
1242 | * @param host the host to register | ||
1243 | * @param cc the completion callback to call to inform the status of | ||
1244 | * registration. After calling this callback the registration handle | ||
1245 | * will be invalid. Cannot be NULL. | ||
1246 | * @param cc_cls the closure for the cc | ||
1247 | * @return handle to the host registration which can be used to cancel the | ||
1248 | * registration | ||
1249 | */ | ||
1250 | struct GNUNET_TESTBED_HostRegistrationHandle * | ||
1251 | GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller, | ||
1252 | struct GNUNET_TESTBED_Host *host, | ||
1253 | GNUNET_TESTBED_HostRegistrationCompletion cc, | ||
1254 | void *cc_cls) | ||
1255 | { | ||
1256 | struct GNUNET_TESTBED_HostRegistrationHandle *rh; | ||
1257 | struct GNUNET_TESTBED_AddHostMessage *msg; | ||
1258 | const char *username; | ||
1259 | const char *hostname; | ||
1260 | char *config; | ||
1261 | char *cconfig; | ||
1262 | void *ptr; | ||
1263 | size_t cc_size; | ||
1264 | size_t config_size; | ||
1265 | uint16_t msg_size; | ||
1266 | uint16_t username_length; | ||
1267 | uint16_t hostname_length; | ||
1268 | |||
1269 | if (NULL != controller->rh) | ||
1270 | return NULL; | ||
1271 | hostname = GNUNET_TESTBED_host_get_hostname (host); | ||
1272 | if (GNUNET_YES == GNUNET_TESTBED_is_host_registered_ (host, controller)) | ||
1273 | { | ||
1274 | LOG (GNUNET_ERROR_TYPE_WARNING, "Host hostname: %s already registered\n", | ||
1275 | (NULL == hostname) ? "localhost" : hostname); | ||
1276 | return NULL; | ||
1277 | } | ||
1278 | rh = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HostRegistrationHandle)); | ||
1279 | rh->host = host; | ||
1280 | rh->c = controller; | ||
1281 | GNUNET_assert (NULL != cc); | ||
1282 | rh->cc = cc; | ||
1283 | rh->cc_cls = cc_cls; | ||
1284 | controller->rh = rh; | ||
1285 | username = GNUNET_TESTBED_host_get_username_ (host); | ||
1286 | username_length = 0; | ||
1287 | if (NULL != username) | ||
1288 | username_length = strlen (username); | ||
1289 | GNUNET_assert (NULL != hostname); /* Hostname must be present */ | ||
1290 | hostname_length = strlen (hostname); | ||
1291 | GNUNET_assert (NULL != host->cfg); | ||
1292 | config = GNUNET_CONFIGURATION_serialize (host->cfg, &config_size); | ||
1293 | cc_size = GNUNET_TESTBED_compress_config_ (config, config_size, &cconfig); | ||
1294 | GNUNET_free (config); | ||
1295 | msg_size = (sizeof (struct GNUNET_TESTBED_AddHostMessage)); | ||
1296 | msg_size += username_length; | ||
1297 | msg_size += hostname_length; | ||
1298 | msg_size += cc_size; | ||
1299 | msg = GNUNET_malloc (msg_size); | ||
1300 | msg->header.size = htons (msg_size); | ||
1301 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST); | ||
1302 | msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host)); | ||
1303 | msg->ssh_port = htons (GNUNET_TESTBED_host_get_ssh_port_ (host)); | ||
1304 | ptr = &msg[1]; | ||
1305 | if (NULL != username) | ||
1306 | { | ||
1307 | msg->username_length = htons (username_length); | ||
1308 | ptr = mempcpy (ptr, username, username_length); | ||
1309 | } | ||
1310 | msg->hostname_length = htons (hostname_length); | ||
1311 | ptr = mempcpy (ptr, hostname, hostname_length); | ||
1312 | msg->config_size = htons (config_size); | ||
1313 | ptr = mempcpy (ptr, cconfig, cc_size); | ||
1314 | GNUNET_assert ((ptr - (void *) msg) == msg_size); | ||
1315 | GNUNET_free (cconfig); | ||
1316 | GNUNET_TESTBED_queue_message_ (controller, | ||
1317 | (struct GNUNET_MessageHeader *) msg); | ||
1318 | return rh; | ||
1319 | } | ||
1320 | |||
1321 | |||
1322 | /** | ||
1323 | * Cancel the pending registration. Note that if the registration message is | ||
1324 | * already sent to the service the cancellation has only the effect that the | ||
1325 | * registration completion callback for the registration is never called. | ||
1326 | * | ||
1327 | * @param handle the registration handle to cancel | ||
1328 | */ | ||
1329 | void | ||
1330 | GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle | ||
1331 | *handle) | ||
1332 | { | ||
1333 | if (handle != handle->c->rh) | ||
1334 | { | ||
1335 | GNUNET_break (0); | ||
1336 | return; | ||
1337 | } | ||
1338 | handle->c->rh = NULL; | ||
1339 | GNUNET_free (handle); | ||
1340 | } | ||
1341 | |||
1342 | |||
1343 | /** | ||
1211 | * Initializes the operation queue for parallel overlay connects | 1344 | * Initializes the operation queue for parallel overlay connects |
1212 | * | 1345 | * |
1213 | * @param h the host handle | 1346 | * @param h the host handle |
@@ -1409,4 +1542,61 @@ GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h, | |||
1409 | (h->opq_parallel_overlay_connect_operations, op); | 1542 | (h->opq_parallel_overlay_connect_operations, op); |
1410 | } | 1543 | } |
1411 | 1544 | ||
1545 | |||
1546 | /** | ||
1547 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from | ||
1548 | * controller (testbed service) | ||
1549 | * | ||
1550 | * @param c the controller handler | ||
1551 | * @param msg message received | ||
1552 | * @return GNUNET_YES if we can continue receiving from service; GNUNET_NO if | ||
1553 | * not | ||
1554 | */ | ||
1555 | int | ||
1556 | GNUNET_TESTBED_host_handle_addhostconfirm_ (struct GNUNET_TESTBED_Controller *c, | ||
1557 | const struct | ||
1558 | GNUNET_TESTBED_HostConfirmedMessage | ||
1559 | *msg) | ||
1560 | { | ||
1561 | struct GNUNET_TESTBED_HostRegistrationHandle *rh; | ||
1562 | char *emsg; | ||
1563 | uint16_t msg_size; | ||
1564 | |||
1565 | rh = c->rh; | ||
1566 | if (NULL == rh) | ||
1567 | { | ||
1568 | return GNUNET_OK; | ||
1569 | } | ||
1570 | if (GNUNET_TESTBED_host_get_id_ (rh->host) != ntohl (msg->host_id)) | ||
1571 | { | ||
1572 | LOG_DEBUG ("Mismatch in host id's %u, %u of host confirm msg\n", | ||
1573 | GNUNET_TESTBED_host_get_id_ (rh->host), ntohl (msg->host_id)); | ||
1574 | return GNUNET_OK; | ||
1575 | } | ||
1576 | c->rh = NULL; | ||
1577 | msg_size = ntohs (msg->header.size); | ||
1578 | if (sizeof (struct GNUNET_TESTBED_HostConfirmedMessage) == msg_size) | ||
1579 | { | ||
1580 | LOG_DEBUG ("Host %u successfully registered\n", ntohl (msg->host_id)); | ||
1581 | GNUNET_TESTBED_mark_host_registered_at_ (rh->host, c); | ||
1582 | rh->cc (rh->cc_cls, NULL); | ||
1583 | GNUNET_free (rh); | ||
1584 | return GNUNET_OK; | ||
1585 | } | ||
1586 | /* We have an error message */ | ||
1587 | emsg = (char *) &msg[1]; | ||
1588 | if ('\0' != | ||
1589 | emsg[msg_size - sizeof (struct GNUNET_TESTBED_HostConfirmedMessage)]) | ||
1590 | { | ||
1591 | GNUNET_break (0); | ||
1592 | GNUNET_free (rh); | ||
1593 | return GNUNET_NO; | ||
1594 | } | ||
1595 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Adding host %u failed with error: %s\n"), | ||
1596 | ntohl (msg->host_id), emsg); | ||
1597 | rh->cc (rh->cc_cls, emsg); | ||
1598 | GNUNET_free (rh); | ||
1599 | return GNUNET_OK; | ||
1600 | } | ||
1601 | |||
1412 | /* end of testbed_api_hosts.c */ | 1602 | /* end of testbed_api_hosts.c */ |
diff --git a/src/testbed/testbed_api_hosts.h b/src/testbed/testbed_api_hosts.h index 2d25fd596..91fea72b7 100644 --- a/src/testbed/testbed_api_hosts.h +++ b/src/testbed/testbed_api_hosts.h | |||
@@ -27,8 +27,9 @@ | |||
27 | #ifndef NEW_TESTING_API_HOSTS_H | 27 | #ifndef NEW_TESTING_API_HOSTS_H |
28 | #define NEW_TESTING_API_HOSTS_H | 28 | #define NEW_TESTING_API_HOSTS_H |
29 | 29 | ||
30 | #include "gnunet_testbed_service.h" | 30 | //#include "gnunet_testbed_service.h" |
31 | #include "testbed_helper.h" | 31 | //#include "testbed_helper.h" |
32 | #include "testbed.h" | ||
32 | 33 | ||
33 | 34 | ||
34 | /** | 35 | /** |
@@ -193,5 +194,21 @@ void | |||
193 | GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h, | 194 | GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h, |
194 | struct GNUNET_TESTBED_Operation *op); | 195 | struct GNUNET_TESTBED_Operation *op); |
195 | 196 | ||
197 | |||
198 | /** | ||
199 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from | ||
200 | * controller (testbed service) | ||
201 | * | ||
202 | * @param c the controller handler | ||
203 | * @param msg message received | ||
204 | * @return GNUNET_YES if we can continue receiving from service; GNUNET_NO if | ||
205 | * not | ||
206 | */ | ||
207 | int | ||
208 | GNUNET_TESTBED_host_handle_addhostconfirm_ (struct GNUNET_TESTBED_Controller *c, | ||
209 | const struct | ||
210 | GNUNET_TESTBED_HostConfirmedMessage | ||
211 | *msg); | ||
212 | |||
196 | #endif | 213 | #endif |
197 | /* end of testbed_api_hosts.h */ | 214 | /* end of testbed_api_hosts.h */ |