summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_protocols.h12
-rw-r--r--src/include/gnunet_testbed_service.h7
-rw-r--r--src/testbed/testbed.h57
-rw-r--r--src/testbed/testbed_api.c223
-rw-r--r--src/testbed/testbed_api.h10
-rw-r--r--src/testbed/testbed_api_services.c5
6 files changed, 280 insertions, 34 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 54c42143e..49a68ac4f 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -1537,10 +1537,20 @@ extern "C"
1537#define GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECTCANCEL 480 1537#define GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECTCANCEL 480
1538 1538
1539/** 1539/**
1540 * Message to request configuration of a slave controller
1541 */
1542#define GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG 481
1543
1544/**
1545 * Message which contains the configuration of slave controller
1546 */
1547#define GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG 482
1548
1549/**
1540 * Not really a message, but for careful checks on the testbed messages; Should 1550 * Not really a message, but for careful checks on the testbed messages; Should
1541 * always be the maximum and never be used to send messages with this type 1551 * always be the maximum and never be used to send messages with this type
1542 */ 1552 */
1543#define GNUNET_MESSAGE_TYPE_TESTBED_MAX 481 1553#define GNUNET_MESSAGE_TYPE_TESTBED_MAX 483
1544 1554
1545/** 1555/**
1546 * The initialization message towards gnunet-testbed-helper 1556 * The initialization message towards gnunet-testbed-helper
diff --git a/src/include/gnunet_testbed_service.h b/src/include/gnunet_testbed_service.h
index 505665dad..0b410bc1d 100644
--- a/src/include/gnunet_testbed_service.h
+++ b/src/include/gnunet_testbed_service.h
@@ -602,8 +602,11 @@ GNUNET_TESTBED_controller_link_2 (struct GNUNET_TESTBED_Controller *master,
602 * 602 *
603 * @param op_cls the closure for the operation 603 * @param op_cls the closure for the operation
604 * @param master the handle to master controller 604 * @param master the handle to master controller
605 * @param slave_host the host where the slave controller is running 605 * @param slave_host the host where the slave controller is running; the handle
606 * @return the operation handle 606 * to the slave_host should remain valid until this operation is
607 * cancelled or marked as finished
608 * @return the operation handle; NULL if the slave_host is not registered at
609 * master
607 */ 610 */
608struct GNUNET_TESTBED_Operation * 611struct GNUNET_TESTBED_Operation *
609GNUNET_TESTBED_get_slave_config (void *op_cls, 612GNUNET_TESTBED_get_slave_config (void *op_cls,
diff --git a/src/testbed/testbed.h b/src/testbed/testbed.h
index 27c8e3b93..ac8fed0a6 100644
--- a/src/testbed/testbed.h
+++ b/src/testbed/testbed.h
@@ -29,6 +29,7 @@
29 29
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31 31
32GNUNET_NETWORK_STRUCT_BEGIN
32 33
33/** 34/**
34 * Initial message from a client to a testing control service. 35 * Initial message from a client to a testing control service.
@@ -641,12 +642,66 @@ struct GNUNET_TESTBED_PeerConfigurationInformationMessage
641 /** 642 /**
642 * The size of configuration when uncompressed 643 * The size of configuration when uncompressed
643 */ 644 */
644 uint16_t config_size; 645 uint16_t config_size GNUNET_PACKED;
646
647 /* followed by gzip-compressed configuration of the peer */
648
649};
650
651
652/**
653 * Message to request configuration of a slave controller
654 */
655struct GNUNET_TESTBED_SlaveGetConfigurationMessage
656{
657 /**
658 * Type is GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG
659 */
660 struct GNUNET_MessageHeader header;
661
662 /**
663 * The id of the slave host
664 */
665 uint32_t slave_id GNUNET_PACKED;
666
667 /**
668 * Operation ID
669 */
670 uint64_t operation_id GNUNET_PACKED;
671
672};
673
674
675/**
676 * Reply to GETSLAVECONFIG message
677 */
678struct GNUNET_TESTBED_SlaveConfiguration
679{
680 /**
681 * Type is GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG
682 */
683 struct GNUNET_MessageHeader header;
684
685 /**
686 * The id of the host where the slave is running
687 */
688 uint32_t slave_id GNUNET_PACKED;
689
690 /**
691 * Operation ID
692 */
693 uint64_t operation_id GNUNET_PACKED;
694
695 /**
696 * The size of the configuration when uncompressed
697 */
698 uint16_t config_size GNUNET_PACKED;
645 699
646 /* followed by gzip-compressed configuration of the peer */ 700 /* followed by gzip-compressed configuration of the peer */
647 701
648}; 702};
649 703
704GNUNET_NETWORK_STRUCT_END
650 705
651#endif 706#endif
652/* end of testbed.h */ 707/* end of testbed.h */
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index e28109a13..582e0dff8 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -182,6 +182,24 @@ struct ForwardedOperationData
182 182
183 183
184/** 184/**
185 * Context data for get slave config operations
186 */
187struct GetSlaveConfigData
188{
189 /**
190 * The operation closure
191 */
192 void *op_cls;
193
194 /**
195 * The id of the slave controller
196 */
197 uint32_t slave_id;
198
199};
200
201
202/**
185 * Returns the operation context with the given id if found in the Operation 203 * Returns the operation context with the given id if found in the Operation
186 * context queues of the controller 204 * context queues of the controller
187 * 205 *
@@ -589,7 +607,7 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
589 break; 607 break;
590 case GNUNET_TESTBED_PIT_CONFIGURATION: 608 case GNUNET_TESTBED_PIT_CONFIGURATION:
591 pinfo->result.cfg = /* Freed in oprelease_peer_getinfo */ 609 pinfo->result.cfg = /* Freed in oprelease_peer_getinfo */
592 GNUNET_TESTBED_get_config_from_peerinfo_msg_ (msg); 610 GNUNET_TESTBED_get_config_from_peerinfo_msg_ (&msg->header);
593 break; 611 break;
594 case GNUNET_TESTBED_PIT_GENERIC: 612 case GNUNET_TESTBED_PIT_GENERIC:
595 GNUNET_assert (0); /* never reach here */ 613 GNUNET_assert (0); /* never reach here */
@@ -711,6 +729,56 @@ handle_op_fail_event (struct GNUNET_TESTBED_Controller *c,
711 729
712 730
713/** 731/**
732 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG message from controller
733 * (testbed service)
734 *
735 * @param c the controller handler
736 * @param msg message received
737 * @return GNUNET_YES if we can continue receiving from service; GNUNET_NO if
738 * not
739 */
740static int
741handle_slave_config (struct GNUNET_TESTBED_Controller *c,
742 const struct GNUNET_TESTBED_SlaveConfiguration * msg)
743{
744 struct OperationContext *opc;
745 void *op_cls;
746 uint64_t op_id;
747 struct GNUNET_TESTBED_EventInformation event;
748
749 op_id = GNUNET_ntohll (msg->operation_id);
750 if (NULL == (opc = find_opc (c, op_id)))
751 {
752 LOG_DEBUG ("Operation not found\n");
753 return GNUNET_YES;
754 }
755 if (OP_GET_SLAVE_CONFIG != opc->type)
756 {
757 GNUNET_break (0);
758 return GNUNET_YES;
759 }
760 op_cls = ((struct GetSlaveConfigData *) opc->data)->op_cls;
761 GNUNET_free (opc->data);
762 opc->data = NULL;
763 opc->state = OPC_STATE_FINISHED;
764 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
765 if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) &&
766 (NULL != c->cc))
767 {
768 opc->data =
769 GNUNET_TESTBED_get_config_from_peerinfo_msg_ (&msg->header);
770 event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED;
771 event.details.operation_finished.generic = opc->data;
772 event.details.operation_finished.operation = opc->op;
773 event.details.operation_finished.op_cls = op_cls;
774 event.details.operation_finished.emsg = NULL;
775 c->cc (c->cc_cls, &event);
776 }
777 return GNUNET_YES;
778}
779
780
781/**
714 * Handler for messages from controller (testbed service) 782 * Handler for messages from controller (testbed service)
715 * 783 *
716 * @param cls the controller handler 784 * @param cls the controller handler
@@ -797,6 +865,13 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
797 GNUNET_TESTBED_OperationFailureEventMessage *) 865 GNUNET_TESTBED_OperationFailureEventMessage *)
798 msg); 866 msg);
799 break; 867 break;
868 case GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG:
869 GNUNET_assert (msize >
870 sizeof (struct GNUNET_TESTBED_SlaveConfiguration));
871 status =
872 handle_slave_config (c, (const struct
873 GNUNET_TESTBED_SlaveConfiguration *) msg);
874 break;
800 default: 875 default:
801 GNUNET_assert (0); 876 GNUNET_assert (0);
802 } 877 }
@@ -1141,6 +1216,60 @@ oprelease_link_controllers (void *cls)
1141 1216
1142 1217
1143/** 1218/**
1219 * Function to be called when get slave config operation is ready
1220 *
1221 * @param cls the OperationContext of type OP_GET_SLAVE_CONFIG
1222 */
1223static void
1224opstart_get_slave_config (void *cls)
1225{
1226 struct OperationContext *opc = cls;
1227 struct GetSlaveConfigData *data;
1228 struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg;
1229 uint16_t msize;
1230
1231 data = opc->data;
1232 msize = sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage);
1233 msg = GNUNET_malloc (msize);
1234 msg->header.size = htons (msize);
1235 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG);
1236 msg->operation_id = GNUNET_htonll (opc->id);
1237 msg->slave_id = htonl (data->slave_id);
1238 GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc);
1239 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
1240 opc->state = OPC_STATE_STARTED;
1241}
1242
1243
1244/**
1245 * Function to be called when get slave config operation is cancelled or finished
1246 *
1247 * @param cls the OperationContext of type OP_GET_SLAVE_CONFIG
1248 */
1249static void
1250oprelease_get_slave_config (void *cls)
1251{
1252 struct OperationContext *opc = cls;
1253
1254 switch (opc->state)
1255 {
1256 case OPC_STATE_INIT:
1257 GNUNET_free (opc->data);
1258 break;
1259 case OPC_STATE_STARTED:
1260 GNUNET_free (opc->data);
1261 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
1262 break;
1263 case OPC_STATE_FINISHED:
1264 if (NULL != opc->data)
1265 GNUNET_CONFIGURATION_destroy (opc->data);
1266 break;
1267 }
1268 GNUNET_free (opc);
1269}
1270
1271
1272/**
1144 * Starts a controller process at the host. FIXME: add controller start callback 1273 * Starts a controller process at the host. FIXME: add controller start callback
1145 * with the configuration with which the controller is started 1274 * with the configuration with which the controller is started
1146 * 1275 *
@@ -1651,7 +1780,9 @@ GNUNET_TESTBED_controller_link (struct GNUNET_TESTBED_Controller *master,
1651 config = GNUNET_CONFIGURATION_serialize (slave_cfg, &config_size); 1780 config = GNUNET_CONFIGURATION_serialize (slave_cfg, &config_size);
1652 cc_size = GNUNET_TESTBED_compress_config_ (config, config_size, &cconfig); 1781 cc_size = GNUNET_TESTBED_compress_config_ (config, config_size, &cconfig);
1653 GNUNET_free (config); 1782 GNUNET_free (config);
1654 GNUNET_assert ((UINT16_MAX - sizeof (struct GNUNET_TESTBED_ControllerLinkMessage)) >= cc_size); /* Configuration doesn't fit in 1 message */ 1783 /* Configuration doesn't fit in 1 message */
1784 GNUNET_assert ((UINT16_MAX -
1785 sizeof (struct GNUNET_TESTBED_ControllerLinkMessage)) >= cc_size);
1655 op = GNUNET_TESTBED_controller_link_2 (master, delegated_host, slave_host, 1786 op = GNUNET_TESTBED_controller_link_2 (master, delegated_host, slave_host,
1656 (const char *) cconfig, cc_size, 1787 (const char *) cconfig, cc_size,
1657 config_size, is_subordinate); 1788 config_size, is_subordinate);
@@ -1669,16 +1800,37 @@ GNUNET_TESTBED_controller_link (struct GNUNET_TESTBED_Controller *master,
1669 * 1800 *
1670 * @param op_cls the closure for the operation 1801 * @param op_cls the closure for the operation
1671 * @param master the handle to master controller 1802 * @param master the handle to master controller
1672 * @param slave_host the host where the slave controller is running 1803 * @param slave_host the host where the slave controller is running; the handle
1673 * @return the operation handle 1804 * to the slave_host should remain valid until this operation is
1805 * cancelled or marked as finished
1806 * @return the operation handle; NULL if the slave_host is not registered at
1807 * master
1674 */ 1808 */
1675struct GNUNET_TESTBED_Operation * 1809struct GNUNET_TESTBED_Operation *
1676GNUNET_TESTBED_get_slave_config (void *op_cls, 1810GNUNET_TESTBED_get_slave_config (void *op_cls,
1677 struct GNUNET_TESTBED_Controller *master, 1811 struct GNUNET_TESTBED_Controller *master,
1678 struct GNUNET_TESTBED_Host *slave_host) 1812 struct GNUNET_TESTBED_Host *slave_host)
1679{ 1813{
1680 GNUNET_break (0); 1814 struct OperationContext *opc;
1681 return NULL; 1815 struct GetSlaveConfigData *data;
1816
1817 if (GNUNET_NO == GNUNET_TESTBED_is_host_registered_ (slave_host, master))
1818 return NULL;
1819 data = GNUNET_malloc (sizeof (struct GetSlaveConfigData));
1820 data->slave_id = GNUNET_TESTBED_host_get_id_ (slave_host);
1821 data->op_cls = op_cls;
1822 opc = GNUNET_malloc (sizeof (struct OperationContext));
1823 opc->state = OPC_STATE_INIT;
1824 opc->c = master;
1825 opc->id = master->operation_counter++;
1826 opc->type = OP_GET_SLAVE_CONFIG;
1827 opc->data = data;
1828 opc->op =
1829 GNUNET_TESTBED_operation_create_ (opc, &opstart_get_slave_config,
1830 &oprelease_get_slave_config);
1831 GNUNET_TESTBED_operation_queue_insert_ (master->opq_parallel_operations,
1832 opc->op);
1833 return opc->op;
1682} 1834}
1683 1835
1684 1836
@@ -1790,35 +1942,60 @@ GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation)
1790/** 1942/**
1791 * Generates configuration by parsing Peer configuration information reply message 1943 * Generates configuration by parsing Peer configuration information reply message
1792 * 1944 *
1793 * @param msg the peer configuration information message 1945 * @param msg the message containing compressed configuration. This message
1946 * should be of the following types: GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG,
1947 * GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG
1794 * @return handle to the parsed configuration 1948 * @return handle to the parsed configuration
1795 */ 1949 */
1796struct GNUNET_CONFIGURATION_Handle * 1950struct GNUNET_CONFIGURATION_Handle *
1797GNUNET_TESTBED_get_config_from_peerinfo_msg_ (const struct 1951GNUNET_TESTBED_get_config_from_peerinfo_msg_ (const struct GNUNET_MessageHeader *msg)
1798 GNUNET_TESTBED_PeerConfigurationInformationMessage 1952{
1799 *msg)
1800{
1801 struct GNUNET_CONFIGURATION_Handle *cfg; 1953 struct GNUNET_CONFIGURATION_Handle *cfg;
1802 char *config; 1954 Bytef *data;
1803 uLong config_size; 1955 const Bytef *xdata;
1956 uLong data_len;
1957 uLong xdata_len;
1804 int ret; 1958 int ret;
1805 uint16_t msize;
1806 1959
1807 config_size = (uLong) ntohs (msg->config_size); 1960 switch (ntohs (msg->type))
1808 config = GNUNET_malloc (config_size); 1961 {
1809 msize = ntohs (msg->header.size); 1962 case GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG:
1810 msize -= sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage); 1963 {
1964 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *imsg;
1965
1966 imsg = (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *)
1967 msg;
1968 data_len = (uLong) ntohs (imsg->config_size);
1969 xdata_len = ntohs (imsg->header.size)
1970 - sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage);
1971 xdata = (const Bytef *) &imsg[1];
1972 }
1973 break;
1974 case GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG:
1975 {
1976 const struct GNUNET_TESTBED_SlaveConfiguration *imsg;
1977
1978 imsg = (const struct GNUNET_TESTBED_SlaveConfiguration *) msg;
1979 data_len = (uLong) ntohs (imsg->config_size);
1980 xdata_len = ntohs (imsg->header.size)
1981 - sizeof (struct GNUNET_TESTBED_SlaveConfiguration);
1982 xdata = (const Bytef *) &imsg[1];
1983 }
1984 break;
1985 default:
1986 GNUNET_assert (0);
1987 }
1988 data = GNUNET_malloc (data_len);
1811 if (Z_OK != 1989 if (Z_OK !=
1812 (ret = 1990 (ret =
1813 uncompress ((Bytef *) config, &config_size, (const Bytef *) &msg[1], 1991 uncompress (data, &data_len, xdata, xdata_len)))
1814 (uLong) msize)))
1815 GNUNET_assert (0); 1992 GNUNET_assert (0);
1816 cfg = GNUNET_CONFIGURATION_create (); 1993 cfg = GNUNET_CONFIGURATION_create ();
1817 GNUNET_assert (GNUNET_OK == 1994 GNUNET_assert (GNUNET_OK ==
1818 GNUNET_CONFIGURATION_deserialize (cfg, config, 1995 GNUNET_CONFIGURATION_deserialize (cfg, (const char *) data,
1819 (size_t) config_size, 1996 (size_t) data_len,
1820 GNUNET_NO)); 1997 GNUNET_NO));
1821 GNUNET_free (config); 1998 GNUNET_free (data);
1822 return cfg; 1999 return cfg;
1823} 2000}
1824 2001
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h
index 9165c7c24..8bd8a0371 100644
--- a/src/testbed/testbed_api.h
+++ b/src/testbed/testbed_api.h
@@ -75,6 +75,11 @@ enum OperationType
75 */ 75 */
76 OP_LINK_CONTROLLERS, 76 OP_LINK_CONTROLLERS,
77 77
78 /**
79 * Get slave config operation
80 */
81 OP_GET_SLAVE_CONFIG
82
78}; 83};
79 84
80 85
@@ -399,9 +404,8 @@ GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc);
399 * @return handle to the parsed configuration 404 * @return handle to the parsed configuration
400 */ 405 */
401struct GNUNET_CONFIGURATION_Handle * 406struct GNUNET_CONFIGURATION_Handle *
402GNUNET_TESTBED_get_config_from_peerinfo_msg_ (const struct 407GNUNET_TESTBED_get_config_from_peerinfo_msg_ (const struct
403 GNUNET_TESTBED_PeerConfigurationInformationMessage 408 GNUNET_MessageHeader *msg);
404 *msg);
405 409
406 410
407/** 411/**
diff --git a/src/testbed/testbed_api_services.c b/src/testbed/testbed_api_services.c
index caa0a58be..28978e10e 100644
--- a/src/testbed/testbed_api_services.c
+++ b/src/testbed/testbed_api_services.c
@@ -136,7 +136,6 @@ static void
136configuration_receiver (void *cls, const struct GNUNET_MessageHeader *msg) 136configuration_receiver (void *cls, const struct GNUNET_MessageHeader *msg)
137{ 137{
138 struct ServiceConnectData *data = cls; 138 struct ServiceConnectData *data = cls;
139 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *imsg;
140 struct GNUNET_TESTBED_Controller *c; 139 struct GNUNET_TESTBED_Controller *c;
141 const char *emsg; 140 const char *emsg;
142 struct GNUNET_TESTBED_EventInformation info; 141 struct GNUNET_TESTBED_EventInformation info;
@@ -159,9 +158,7 @@ configuration_receiver (void *cls, const struct GNUNET_MessageHeader *msg)
159 info.details.operation_finished.generic = NULL; 158 info.details.operation_finished.generic = NULL;
160 goto call_cb; 159 goto call_cb;
161 } 160 }
162 imsg = 161 data->cfg = GNUNET_TESTBED_get_config_from_peerinfo_msg_ (msg);
163 (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *) msg;
164 data->cfg = GNUNET_TESTBED_get_config_from_peerinfo_msg_ (imsg);
165 GNUNET_assert (NULL == data->op_result); 162 GNUNET_assert (NULL == data->op_result);
166 data->op_result = data->ca (data->cada_cls, data->cfg); 163 data->op_result = data->ca (data->cada_cls, data->cfg);
167 info.details.operation_finished.emsg = NULL; 164 info.details.operation_finished.emsg = NULL;