diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-10-10 09:38:50 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-10-10 09:38:50 +0000 |
commit | 79e6c27371e642717aa5d175b70900fd9c14d71f (patch) | |
tree | a9c7ac74fc6453aa87d1e84308c38ca56865b0e2 /src/testbed | |
parent | 9fc4852d5a463232edf3fb02b4ca8c0c14b514d3 (diff) | |
download | gnunet-79e6c27371e642717aa5d175b70900fd9c14d71f.tar.gz gnunet-79e6c27371e642717aa5d175b70900fd9c14d71f.zip |
towards handling suboperations during overlay connect
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/testbed_api.c | 94 | ||||
-rw-r--r-- | src/testbed/testbed_api_peers.c | 1 | ||||
-rw-r--r-- | src/testbed/testbed_api_peers.h | 35 |
3 files changed, 120 insertions, 10 deletions
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 35956f852..9bed63a97 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -810,6 +810,29 @@ handle_op_fail_event (struct GNUNET_TESTBED_Controller *c, | |||
810 | 810 | ||
811 | 811 | ||
812 | /** | 812 | /** |
813 | * Function to build GET_SLAVE_CONFIG message | ||
814 | * | ||
815 | * @param op_id the id this message should contain in its operation id field | ||
816 | * @param slave_id the id this message should contain in its slave id field | ||
817 | * @return newly allocated SlaveGetConfigurationMessage | ||
818 | */ | ||
819 | static struct GNUNET_TESTBED_SlaveGetConfigurationMessage * | ||
820 | GNUNET_TESTBED_generate_slavegetconfig_msg_ (uint64_t op_id, uint32_t slave_id) | ||
821 | { | ||
822 | struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg; | ||
823 | uint16_t msize; | ||
824 | |||
825 | msize = sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage); | ||
826 | msg = GNUNET_malloc (msize); | ||
827 | msg->header.size = htons (msize); | ||
828 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG); | ||
829 | msg->operation_id = GNUNET_htonll (op_id); | ||
830 | msg->slave_id = htonl (slave_id); | ||
831 | return msg; | ||
832 | } | ||
833 | |||
834 | |||
835 | /** | ||
813 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG message from controller | 836 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG message from controller |
814 | * (testbed service) | 837 | * (testbed service) |
815 | * | 838 | * |
@@ -859,6 +882,41 @@ handle_slave_config (struct GNUNET_TESTBED_Controller *c, | |||
859 | 882 | ||
860 | 883 | ||
861 | /** | 884 | /** |
885 | * Callback to check status for suboperations generated during overlay connect. | ||
886 | * | ||
887 | * @param cls the OverlayConnectData | ||
888 | * @param message the reply message to the suboperation | ||
889 | */ | ||
890 | static void | ||
891 | overlay_connect_ondemand_handler (void *cls, | ||
892 | const struct GNUNET_MessageHeader *message) | ||
893 | { | ||
894 | struct OverlayConnectData *oc_data = cls; | ||
895 | |||
896 | switch (oc_data->state) | ||
897 | { | ||
898 | case OCD_CFG_ACQUIRE: | ||
899 | { | ||
900 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
901 | |||
902 | if (GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG != ntohs (message->type)) | ||
903 | { | ||
904 | GNUNET_break (0); /* treat operation as failed */ | ||
905 | } | ||
906 | cfg = GNUNET_TESTBED_extract_config_ (message); | ||
907 | if (NULL == cfg) | ||
908 | { | ||
909 | GNUNET_break (0); /* failed operation */ | ||
910 | } | ||
911 | oc_data->state = OCD_LINK_CONTROLLERS; | ||
912 | } | ||
913 | default: | ||
914 | GNUNET_assert (0); | ||
915 | } | ||
916 | } | ||
917 | |||
918 | |||
919 | /** | ||
862 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_NEEDCONTROLLERCONFIG message from | 920 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_NEEDCONTROLLERCONFIG message from |
863 | * controller (testbed service) | 921 | * controller (testbed service) |
864 | * | 922 | * |
@@ -887,13 +945,35 @@ handle_need_controller_config (struct GNUNET_TESTBED_Controller *c, | |||
887 | (const struct GNUNET_MessageHeader *) msg); | 945 | (const struct GNUNET_MessageHeader *) msg); |
888 | return GNUNET_YES; | 946 | return GNUNET_YES; |
889 | } | 947 | } |
948 | GNUNET_assert (OP_OVERLAY_CONNECT == opc->type); | ||
890 | oc_data = opc->data; | 949 | oc_data = opc->data; |
891 | /* FIXME: Should spawn operations to: | 950 | /* FIXME: Should spawn operations to: |
892 | 1. Acquire configuration of peer2's controller, | 951 | 1. Acquire configuration of peer2's controller, |
893 | 2. link peer1's controller to peer2's controller | 952 | 2. link peer1's controller to peer2's controller |
894 | 3. ask them to attempt overlay connect on peer1 and peer2 again */ | 953 | 3. ask them to attempt overlay connect on peer1 and peer2 again */ |
895 | GNUNET_break (NULL == oc_data); | 954 | switch (oc_data->state) |
896 | GNUNET_break (0); | 955 | { |
956 | case OCD_INIT: | ||
957 | { | ||
958 | struct GNUNET_TESTBED_SlaveGetConfigurationMessage *get_cfg_msg; | ||
959 | uint64_t sub_op_id; | ||
960 | |||
961 | GNUNET_assert (NULL == oc_data->sub_opc); | ||
962 | sub_op_id = oc_data->p1->controller->operation_counter++; | ||
963 | get_cfg_msg = | ||
964 | GNUNET_TESTBED_generate_slavegetconfig_msg_ | ||
965 | (sub_op_id, GNUNET_TESTBED_host_get_id_ (oc_data->p2->host)); | ||
966 | oc_data->state = OCD_CFG_ACQUIRE; | ||
967 | oc_data->sub_opc = | ||
968 | GNUNET_TESTBED_forward_operation_msg_ (oc_data->p1->controller, | ||
969 | sub_op_id, &get_cfg_msg->header, | ||
970 | overlay_connect_ondemand_handler, | ||
971 | oc_data); | ||
972 | } | ||
973 | break; | ||
974 | default: | ||
975 | GNUNET_assert (0); | ||
976 | } | ||
897 | return GNUNET_YES; | 977 | return GNUNET_YES; |
898 | } | 978 | } |
899 | 979 | ||
@@ -1313,15 +1393,9 @@ opstart_get_slave_config (void *cls) | |||
1313 | struct OperationContext *opc = cls; | 1393 | struct OperationContext *opc = cls; |
1314 | struct GetSlaveConfigData *data; | 1394 | struct GetSlaveConfigData *data; |
1315 | struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg; | 1395 | struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg; |
1316 | uint16_t msize; | 1396 | |
1317 | |||
1318 | data = opc->data; | 1397 | data = opc->data; |
1319 | msize = sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage); | 1398 | msg = GNUNET_TESTBED_generate_slavegetconfig_msg_ (opc->id, data->slave_id); |
1320 | msg = GNUNET_malloc (msize); | ||
1321 | msg->header.size = htons (msize); | ||
1322 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG); | ||
1323 | msg->operation_id = GNUNET_htonll (opc->id); | ||
1324 | msg->slave_id = htonl (data->slave_id); | ||
1325 | GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc); | 1399 | GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc); |
1326 | GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); | 1400 | GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); |
1327 | opc->state = OPC_STATE_STARTED; | 1401 | opc->state = OPC_STATE_STARTED; |
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c index 38c8f6aa8..ab54cecfa 100644 --- a/src/testbed/testbed_api_peers.c +++ b/src/testbed/testbed_api_peers.c | |||
@@ -706,6 +706,7 @@ GNUNET_TESTBED_overlay_connect (void *op_cls, | |||
706 | data->p2 = p2; | 706 | data->p2 = p2; |
707 | data->cb = cb; | 707 | data->cb = cb; |
708 | data->cb_cls = cb_cls; | 708 | data->cb_cls = cb_cls; |
709 | data->state = OCD_INIT; | ||
709 | opc = GNUNET_malloc (sizeof (struct OperationContext)); | 710 | opc = GNUNET_malloc (sizeof (struct OperationContext)); |
710 | opc->data = data; | 711 | opc->data = data; |
711 | opc->c = p1->controller; | 712 | opc->c = p1->controller; |
diff --git a/src/testbed/testbed_api_peers.h b/src/testbed/testbed_api_peers.h index 357f45e51..f16dd8a30 100644 --- a/src/testbed/testbed_api_peers.h +++ b/src/testbed/testbed_api_peers.h | |||
@@ -190,6 +190,7 @@ struct PeerInfoData | |||
190 | */ | 190 | */ |
191 | struct OverlayConnectData | 191 | struct OverlayConnectData |
192 | { | 192 | { |
193 | |||
193 | /** | 194 | /** |
194 | * Peer A to connect to peer B | 195 | * Peer A to connect to peer B |
195 | */ | 196 | */ |
@@ -210,6 +211,40 @@ struct OverlayConnectData | |||
210 | */ | 211 | */ |
211 | void *cb_cls; | 212 | void *cb_cls; |
212 | 213 | ||
214 | /** | ||
215 | * OperationContext for forwarded operations generated when peer1's controller doesn't have the | ||
216 | * configuration of peer2's controller for linking laterally to attemp an | ||
217 | * overlay connection between peer 1 and peer 2. | ||
218 | */ | ||
219 | struct OperationContext *sub_opc; | ||
220 | |||
221 | /** | ||
222 | * State information for this context data | ||
223 | */ | ||
224 | enum OCDState { | ||
225 | |||
226 | /** | ||
227 | * The initial state | ||
228 | */ | ||
229 | OCD_INIT, | ||
230 | |||
231 | /** | ||
232 | * State where we attempt to acquire peer2's controller's configuration | ||
233 | */ | ||
234 | OCD_CFG_ACQUIRE, | ||
235 | |||
236 | /** | ||
237 | * State where we link peer1's controller to peer2's controller | ||
238 | */ | ||
239 | OCD_LINK_CONTROLLERS, | ||
240 | |||
241 | /** | ||
242 | * State where we re-ask controller of peer1 to attempt an overlay connect | ||
243 | * between peer1 and peer2 | ||
244 | */ | ||
245 | OCD_REATTEMPT_OVERLAY_CONNECT | ||
246 | } state; | ||
247 | |||
213 | }; | 248 | }; |
214 | 249 | ||
215 | 250 | ||