diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-21 11:59:57 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-21 11:59:57 +0000 |
commit | 1d9c7c19acf2483b07882cfe35336bdad4572a79 (patch) | |
tree | 3ed49b7df89845d9d250324f9a13dc248f002ce5 /src/testbed | |
parent | e7dea84a13da4c2a9bf6f70d57550c99de6538d1 (diff) | |
download | gnunet-1d9c7c19acf2483b07882cfe35336bdad4572a79.tar.gz gnunet-1d9c7c19acf2483b07882cfe35336bdad4572a79.zip |
modified link controller forwarding to use forwarded operations
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/gnunet-service-testbed.c | 163 | ||||
-rw-r--r-- | src/testbed/testbed_api.c | 13 |
2 files changed, 118 insertions, 58 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index 07a8aa714..72a2f8fda 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c | |||
@@ -214,34 +214,29 @@ enum LCFContextState | |||
214 | struct LCFContext | 214 | struct LCFContext |
215 | { | 215 | { |
216 | /** | 216 | /** |
217 | * The serialized and compressed configuration | ||
218 | */ | ||
219 | char *sxcfg; | ||
220 | |||
221 | /** | ||
222 | * The gateway which will pass the link message to delegated host | 217 | * The gateway which will pass the link message to delegated host |
223 | */ | 218 | */ |
224 | struct Slave *gateway; | 219 | struct Slave *gateway; |
225 | 220 | ||
226 | /** | 221 | /** |
227 | * The host registration handle while registered hosts in this context | 222 | * The controller link message that has to be forwarded to |
228 | */ | 223 | */ |
229 | struct GNUNET_TESTBED_HostRegistrationHandle *rhandle; | 224 | struct GNUNET_TESTBED_ControllerLinkMessage *msg; |
230 | 225 | ||
231 | /** | 226 | /** |
232 | * The size of the compressed serialized configuration | 227 | * The client which has asked to perform this operation |
233 | */ | 228 | */ |
234 | size_t sxcfg_size; | 229 | struct GNUNET_SERVER_Client *client; |
235 | 230 | ||
236 | /** | 231 | /** |
237 | * The size of the uncompressed configuration | 232 | * The host registration handle while registered hosts in this context |
238 | */ | 233 | */ |
239 | size_t scfg_size; | 234 | struct GNUNET_TESTBED_HostRegistrationHandle *rhandle; |
240 | 235 | ||
241 | /** | 236 | /** |
242 | * Should the delegated host be started by the slave host? | 237 | * The id of the operation which created this context |
243 | */ | 238 | */ |
244 | int is_subordinate; | 239 | uint64_t operation_id; |
245 | 240 | ||
246 | /** | 241 | /** |
247 | * The state of this context | 242 | * The state of this context |
@@ -866,6 +861,29 @@ send_operation_fail_msg (struct GNUNET_SERVER_Client *client, | |||
866 | 861 | ||
867 | 862 | ||
868 | /** | 863 | /** |
864 | * Function to send generic operation success message to given client | ||
865 | * | ||
866 | * @param client the client to send the message to | ||
867 | * @param operation_id the id of the operation which was successful | ||
868 | */ | ||
869 | static void | ||
870 | send_operation_success_msg (struct GNUNET_SERVER_Client *client, | ||
871 | uint64_t operation_id) | ||
872 | { | ||
873 | struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg; | ||
874 | uint16_t msize; | ||
875 | |||
876 | msize = sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage); | ||
877 | msg = GNUNET_malloc (msize); | ||
878 | msg->header.size = htons (msize); | ||
879 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS); | ||
880 | msg->operation_id = GNUNET_htonll (operation_id); | ||
881 | msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED); | ||
882 | queue_message (client, &msg->header); | ||
883 | } | ||
884 | |||
885 | |||
886 | /** | ||
869 | * The Link Controller forwarding task | 887 | * The Link Controller forwarding task |
870 | * | 888 | * |
871 | * @param cls the LCFContext | 889 | * @param cls the LCFContext |
@@ -916,6 +934,50 @@ lcf_proc_cc (void *cls, const char *emsg) | |||
916 | 934 | ||
917 | 935 | ||
918 | /** | 936 | /** |
937 | * Callback to be called when forwarded link controllers operation is | ||
938 | * successfull. We have to relay the reply msg back to the client | ||
939 | * | ||
940 | * @param cls ForwardedOperationContext | ||
941 | * @param msg the peer create success message | ||
942 | */ | ||
943 | static void | ||
944 | forwarded_link_controllers_reply_relay (void *cls, | ||
945 | const struct GNUNET_MessageHeader *msg) | ||
946 | { | ||
947 | struct ForwardedOperationContext *fopc = cls; | ||
948 | struct GNUNET_MessageHeader *dup_msg; | ||
949 | uint16_t msize; | ||
950 | |||
951 | msize = ntohs (msg->size); | ||
952 | dup_msg = GNUNET_malloc (msize); | ||
953 | (void) memcpy (dup_msg, msg, msize); | ||
954 | queue_message (fopc->client, dup_msg); | ||
955 | GNUNET_SERVER_client_drop (fopc->client); | ||
956 | GNUNET_SCHEDULER_cancel (fopc->timeout_task); | ||
957 | GNUNET_free (fopc); | ||
958 | } | ||
959 | |||
960 | |||
961 | /** | ||
962 | * Task to free resources when forwarded link controllers has been timedout | ||
963 | * | ||
964 | * @param cls the ForwardedOperationContext | ||
965 | * @param tc the task context from scheduler | ||
966 | */ | ||
967 | static void | ||
968 | forwarded_link_controllers_timeout (void *cls, | ||
969 | const struct GNUNET_SCHEDULER_TaskContext | ||
970 | *tc) | ||
971 | { | ||
972 | struct ForwardedOperationContext *fopc = cls; | ||
973 | |||
974 | GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc); | ||
975 | GNUNET_SERVER_client_drop (fopc->client); | ||
976 | GNUNET_free (fopc); | ||
977 | } | ||
978 | |||
979 | |||
980 | /** | ||
919 | * The Link Controller forwarding task | 981 | * The Link Controller forwarding task |
920 | * | 982 | * |
921 | * @param cls the LCFContext | 983 | * @param cls the LCFContext |
@@ -926,7 +988,8 @@ lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
926 | { | 988 | { |
927 | struct LCFContext *lcf = cls; | 989 | struct LCFContext *lcf = cls; |
928 | struct LCFContextQueue *lcfq; | 990 | struct LCFContextQueue *lcfq; |
929 | 991 | struct ForwardedOperationContext *fopc; | |
992 | |||
930 | lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK; | 993 | lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK; |
931 | switch (lcf->state) | 994 | switch (lcf->state) |
932 | { | 995 | { |
@@ -963,19 +1026,25 @@ lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
963 | } | 1026 | } |
964 | break; | 1027 | break; |
965 | case SLAVE_HOST_REGISTERED: | 1028 | case SLAVE_HOST_REGISTERED: |
966 | GNUNET_TESTBED_controller_link_2 (lcf->gateway->controller, | 1029 | fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext)); |
967 | host_list[lcf->delegated_host_id], | 1030 | fopc->client = lcf->client; |
968 | host_list[lcf->slave_host_id], | 1031 | fopc->operation_id = lcf->operation_id; |
969 | lcf->sxcfg, lcf->sxcfg_size, | 1032 | fopc->opc = |
970 | lcf->scfg_size, | 1033 | GNUNET_TESTBED_forward_operation_msg_ (lcf->gateway->controller, |
971 | lcf->is_subordinate); | 1034 | lcf->operation_id, |
1035 | &lcf->msg->header, | ||
1036 | &forwarded_link_controllers_reply_relay, | ||
1037 | fopc); | ||
1038 | fopc->timeout_task = | ||
1039 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
1040 | &forwarded_link_controllers_timeout, fopc); | ||
972 | lcf->state = FINISHED; | 1041 | lcf->state = FINISHED; |
973 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); | 1042 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); |
974 | break; | 1043 | break; |
975 | case FINISHED: | 1044 | case FINISHED: |
976 | lcfq = lcfq_head; | 1045 | lcfq = lcfq_head; |
977 | GNUNET_assert (lcfq->lcf == lcf); | 1046 | GNUNET_assert (lcfq->lcf == lcf); |
978 | GNUNET_free (lcf->sxcfg); | 1047 | GNUNET_free (lcf->msg); |
979 | GNUNET_free (lcf); | 1048 | GNUNET_free (lcf); |
980 | GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq); | 1049 | GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq); |
981 | GNUNET_free (lcfq); | 1050 | GNUNET_free (lcfq); |
@@ -993,37 +1062,14 @@ lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
993 | * @param event information about the event | 1062 | * @param event information about the event |
994 | */ | 1063 | */ |
995 | static void | 1064 | static void |
996 | slave_event_callback(void *cls, | 1065 | slave_event_callback (void *cls, |
997 | const struct GNUNET_TESTBED_EventInformation *event) | 1066 | const struct GNUNET_TESTBED_EventInformation *event) |
998 | { | 1067 | { |
999 | GNUNET_break (0); | 1068 | GNUNET_break (0); |
1000 | } | 1069 | } |
1001 | 1070 | ||
1002 | 1071 | ||
1003 | /** | 1072 | /** |
1004 | * Function to send generic operation success message to given client | ||
1005 | * | ||
1006 | * @param client the client to send the message to | ||
1007 | * @param operation_id the id of the operation which was successful | ||
1008 | */ | ||
1009 | static void | ||
1010 | send_operation_success_msg (struct GNUNET_SERVER_Client *client, | ||
1011 | uint64_t operation_id) | ||
1012 | { | ||
1013 | struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg; | ||
1014 | uint16_t msize; | ||
1015 | |||
1016 | msize = sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage); | ||
1017 | msg = GNUNET_malloc (msize); | ||
1018 | msg->header.size = htons (msize); | ||
1019 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS); | ||
1020 | msg->operation_id = GNUNET_htonll (operation_id); | ||
1021 | msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED); | ||
1022 | queue_message (client, &msg->header); | ||
1023 | } | ||
1024 | |||
1025 | |||
1026 | /** | ||
1027 | * Callback to signal successfull startup of the controller process | 1073 | * Callback to signal successfull startup of the controller process |
1028 | * | 1074 | * |
1029 | * @param cls the closure from GNUNET_TESTBED_controller_start() | 1075 | * @param cls the closure from GNUNET_TESTBED_controller_start() |
@@ -1345,13 +1391,14 @@ handle_link_controllers (void *cls, | |||
1345 | LOG (GNUNET_ERROR_TYPE_WARNING, "Slave and delegated host are same\n"); | 1391 | LOG (GNUNET_ERROR_TYPE_WARNING, "Slave and delegated host are same\n"); |
1346 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1392 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1347 | return; | 1393 | return; |
1348 | } | 1394 | } |
1349 | msize -= sizeof (struct GNUNET_TESTBED_ControllerLinkMessage); | ||
1350 | config_size = ntohs (msg->config_size); | ||
1351 | 1395 | ||
1352 | if (slave_host_id == master_context->host_id) /* Link from us */ | 1396 | if (slave_host_id == master_context->host_id) /* Link from us */ |
1353 | { | 1397 | { |
1354 | struct Slave *slave; | 1398 | struct Slave *slave; |
1399 | |||
1400 | msize -= sizeof (struct GNUNET_TESTBED_ControllerLinkMessage); | ||
1401 | config_size = ntohs (msg->config_size); | ||
1355 | if ((delegated_host_id < slave_list_size) && | 1402 | if ((delegated_host_id < slave_list_size) && |
1356 | (NULL != slave_list[delegated_host_id])) /* We have already added */ | 1403 | (NULL != slave_list[delegated_host_id])) /* We have already added */ |
1357 | { | 1404 | { |
@@ -1397,7 +1444,6 @@ handle_link_controllers (void *cls, | |||
1397 | slave = GNUNET_malloc (sizeof (struct Slave)); | 1444 | slave = GNUNET_malloc (sizeof (struct Slave)); |
1398 | slave->host_id = delegated_host_id; | 1445 | slave->host_id = delegated_host_id; |
1399 | slave_list_add (slave); | 1446 | slave_list_add (slave); |
1400 | |||
1401 | if (1 == msg->is_subordinate) | 1447 | if (1 == msg->is_subordinate) |
1402 | { | 1448 | { |
1403 | struct LinkControllersContext *lcc; | 1449 | struct LinkControllersContext *lcc; |
@@ -1447,22 +1493,23 @@ handle_link_controllers (void *cls, | |||
1447 | GNUNET_assert (NULL != route); /* because we add routes carefully */ | 1493 | GNUNET_assert (NULL != route); /* because we add routes carefully */ |
1448 | GNUNET_assert (route->dest < slave_list_size); | 1494 | GNUNET_assert (route->dest < slave_list_size); |
1449 | GNUNET_assert (NULL != slave_list[route->dest]); | 1495 | GNUNET_assert (NULL != slave_list[route->dest]); |
1450 | lcfq->lcf->is_subordinate = | ||
1451 | (1 == msg->is_subordinate) ? GNUNET_YES : GNUNET_NO; | ||
1452 | lcfq->lcf->state = INIT; | 1496 | lcfq->lcf->state = INIT; |
1497 | lcfq->lcf->operation_id = GNUNET_ntohll (msg->operation_id); | ||
1453 | lcfq->lcf->gateway = slave_list[route->dest]; | 1498 | lcfq->lcf->gateway = slave_list[route->dest]; |
1454 | lcfq->lcf->sxcfg_size = msize; | 1499 | lcfq->lcf->msg = GNUNET_malloc (msize); |
1455 | lcfq->lcf->sxcfg = GNUNET_malloc (msize); | 1500 | (void) memcpy (lcfq->lcf->msg, msg, msize); |
1456 | lcfq->lcf->scfg_size = config_size; | 1501 | GNUNET_SERVER_client_keep (client); |
1457 | (void) memcpy (lcfq->lcf->sxcfg, &msg[1], msize); | 1502 | lcfq->lcf->client = client; |
1458 | if (NULL == lcfq_head) | 1503 | if (NULL == lcfq_head) |
1459 | { | 1504 | { |
1460 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id); | 1505 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id); |
1461 | GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq); | 1506 | GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq); |
1462 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq); | 1507 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq->lcf); |
1463 | } | 1508 | } |
1464 | else | 1509 | else |
1465 | GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq); | 1510 | GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq); |
1511 | /* FIXME: Adding a new route should happen after the controllers are linked | ||
1512 | successfully */ | ||
1466 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1513 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1467 | new_route = GNUNET_malloc (sizeof (struct Route)); | 1514 | new_route = GNUNET_malloc (sizeof (struct Route)); |
1468 | new_route->dest = delegated_host_id; | 1515 | new_route->dest = delegated_host_id; |
@@ -2186,7 +2233,7 @@ shutdown_task (void *cls, | |||
2186 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id); | 2233 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id); |
2187 | for (lcfq = lcfq_head; NULL != lcfq; lcfq = lcfq_head) | 2234 | for (lcfq = lcfq_head; NULL != lcfq; lcfq = lcfq_head) |
2188 | { | 2235 | { |
2189 | GNUNET_free (lcfq->lcf->sxcfg); | 2236 | GNUNET_free (lcfq->lcf->msg); |
2190 | GNUNET_free (lcfq->lcf); | 2237 | GNUNET_free (lcfq->lcf); |
2191 | GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq); | 2238 | GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq); |
2192 | GNUNET_free (lcfq); | 2239 | GNUNET_free (lcfq); |
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index f2431c630..01abc97a8 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -283,6 +283,19 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c, | |||
283 | event->type = GNUNET_TESTBED_ET_OPERATION_FINISHED; | 283 | event->type = GNUNET_TESTBED_ET_OPERATION_FINISHED; |
284 | switch (opc->type) | 284 | switch (opc->type) |
285 | { | 285 | { |
286 | case OP_FORWARDED: | ||
287 | { | ||
288 | struct ForwardedOperationData *fo_data; | ||
289 | |||
290 | fo_data = opc->data; | ||
291 | if (NULL != fo_data->cc) | ||
292 | fo_data->cc (fo_data->cc_cls, (const struct GNUNET_MessageHeader *) msg); | ||
293 | GNUNET_CONTAINER_DLL_remove (c->ocq_head, c->ocq_tail, opc); | ||
294 | GNUNET_free (fo_data); | ||
295 | GNUNET_free (opc); | ||
296 | return GNUNET_YES; | ||
297 | } | ||
298 | break; | ||
286 | case OP_PEER_DESTROY: | 299 | case OP_PEER_DESTROY: |
287 | { | 300 | { |
288 | struct GNUNET_TESTBED_Peer *peer; | 301 | struct GNUNET_TESTBED_Peer *peer; |