diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-17 14:54:29 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-17 14:54:29 +0000 |
commit | 14c98ff17a8b1e4db1e6445f6116b7be5b4b8934 (patch) | |
tree | f08a66a8d151a4d0a16641cfcd5b0b8152bce24f /src/testbed/testbed_api.c | |
parent | d6f2d6cd9b3a14e9dc7cea1e5d1863d6d59af0af (diff) | |
download | gnunet-14c98ff17a8b1e4db1e6445f6116b7be5b4b8934.tar.gz gnunet-14c98ff17a8b1e4db1e6445f6116b7be5b4b8934.zip |
controller link as operation
Diffstat (limited to 'src/testbed/testbed_api.c')
-rw-r--r-- | src/testbed/testbed_api.c | 90 |
1 files changed, 71 insertions, 19 deletions
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index afac22fba..f2431c630 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -285,25 +285,26 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c, | |||
285 | { | 285 | { |
286 | case OP_PEER_DESTROY: | 286 | case OP_PEER_DESTROY: |
287 | { | 287 | { |
288 | struct GNUNET_TESTBED_Peer *peer; | 288 | struct GNUNET_TESTBED_Peer *peer; |
289 | |||
290 | if (NULL != event) | ||
291 | { | ||
292 | event->details.operation_finished.operation = opc->op; | ||
293 | event->details.operation_finished.op_cls = NULL; | ||
294 | event->details.operation_finished.emsg = NULL; | ||
295 | event->details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC; | ||
296 | event->details.operation_finished.op_result.generic = NULL; | ||
297 | } | ||
298 | peer = opc->data; | 289 | peer = opc->data; |
299 | GNUNET_free (peer); | 290 | GNUNET_free (peer); |
300 | opc->data = NULL; | 291 | opc->data = NULL; |
301 | //PEERDESTROYDATA | 292 | //PEERDESTROYDATA |
302 | } | 293 | } |
303 | break; | 294 | break; |
295 | case OP_LINK_CONTROLLERS: | ||
296 | break; | ||
304 | default: | 297 | default: |
305 | GNUNET_assert (0); | 298 | GNUNET_assert (0); |
306 | } | 299 | } |
300 | if (NULL != event) | ||
301 | { | ||
302 | event->details.operation_finished.operation = opc->op; | ||
303 | event->details.operation_finished.op_cls = NULL; | ||
304 | event->details.operation_finished.emsg = NULL; | ||
305 | event->details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC; | ||
306 | event->details.operation_finished.op_result.generic = NULL; | ||
307 | } | ||
307 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); | 308 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); |
308 | opc->state = OPC_STATE_FINISHED; | 309 | opc->state = OPC_STATE_FINISHED; |
309 | if (NULL != event) | 310 | if (NULL != event) |
@@ -953,6 +954,45 @@ helper_exp_cb (void *cls) | |||
953 | 954 | ||
954 | 955 | ||
955 | /** | 956 | /** |
957 | * Function to call to start a link-controllers type operation once all queues | ||
958 | * the operation is part of declare that the operation can be activated. | ||
959 | * | ||
960 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
961 | */ | ||
962 | static void | ||
963 | opstart_link_controllers (void *cls) | ||
964 | { | ||
965 | struct OperationContext *opc = cls; | ||
966 | struct GNUNET_TESTBED_ControllerLinkMessage *msg; | ||
967 | |||
968 | GNUNET_assert (NULL != opc->data); | ||
969 | msg = opc->data; | ||
970 | opc->data = NULL; | ||
971 | opc->state = OPC_STATE_STARTED; | ||
972 | GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc); | ||
973 | GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); | ||
974 | } | ||
975 | |||
976 | |||
977 | /** | ||
978 | * Callback which will be called when link-controllers type operation is released | ||
979 | * | ||
980 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
981 | */ | ||
982 | static void | ||
983 | oprelease_link_controllers (void *cls) | ||
984 | { | ||
985 | struct OperationContext *opc = cls; | ||
986 | |||
987 | if (OPC_STATE_INIT == opc->state) | ||
988 | GNUNET_free (opc->data); | ||
989 | if (OPC_STATE_STARTED == opc->state) | ||
990 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); | ||
991 | GNUNET_free (opc); | ||
992 | } | ||
993 | |||
994 | |||
995 | /** | ||
956 | * Starts a controller process at the host. FIXME: add controller start callback | 996 | * Starts a controller process at the host. FIXME: add controller start callback |
957 | * with the configuration with which the controller is started | 997 | * with the configuration with which the controller is started |
958 | * | 998 | * |
@@ -1320,7 +1360,7 @@ GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle | |||
1320 | * be started by the master controller; GNUNET_NO if we are just | 1360 | * be started by the master controller; GNUNET_NO if we are just |
1321 | * allowed to use the slave via TCP/IP | 1361 | * allowed to use the slave via TCP/IP |
1322 | */ | 1362 | */ |
1323 | void | 1363 | struct GNUNET_TESTBED_Operation * |
1324 | GNUNET_TESTBED_controller_link_2 (struct GNUNET_TESTBED_Controller *master, | 1364 | GNUNET_TESTBED_controller_link_2 (struct GNUNET_TESTBED_Controller *master, |
1325 | struct GNUNET_TESTBED_Host *delegated_host, | 1365 | struct GNUNET_TESTBED_Host *delegated_host, |
1326 | struct GNUNET_TESTBED_Host *slave_host, | 1366 | struct GNUNET_TESTBED_Host *slave_host, |
@@ -1329,6 +1369,7 @@ GNUNET_TESTBED_controller_link_2 (struct GNUNET_TESTBED_Controller *master, | |||
1329 | size_t scfg_size, | 1369 | size_t scfg_size, |
1330 | int is_subordinate) | 1370 | int is_subordinate) |
1331 | { | 1371 | { |
1372 | struct OperationContext *opc; | ||
1332 | struct GNUNET_TESTBED_ControllerLinkMessage *msg; | 1373 | struct GNUNET_TESTBED_ControllerLinkMessage *msg; |
1333 | uint16_t msg_size; | 1374 | uint16_t msg_size; |
1334 | 1375 | ||
@@ -1347,7 +1388,17 @@ GNUNET_TESTBED_controller_link_2 (struct GNUNET_TESTBED_Controller *master, | |||
1347 | msg->config_size = htons ((uint16_t) scfg_size); | 1388 | msg->config_size = htons ((uint16_t) scfg_size); |
1348 | msg->is_subordinate = (GNUNET_YES == is_subordinate) ? 1 : 0; | 1389 | msg->is_subordinate = (GNUNET_YES == is_subordinate) ? 1 : 0; |
1349 | memcpy (&msg[1], sxcfg, sxcfg_size); | 1390 | memcpy (&msg[1], sxcfg, sxcfg_size); |
1350 | GNUNET_TESTBED_queue_message_ (master, (struct GNUNET_MessageHeader *) msg); | 1391 | opc = GNUNET_malloc (sizeof (struct OperationContext)); |
1392 | opc->c = master; | ||
1393 | opc->data = msg; | ||
1394 | opc->type = OP_LINK_CONTROLLERS; | ||
1395 | opc->id = master->operation_counter++; | ||
1396 | opc->state = OPC_STATE_INIT; | ||
1397 | msg->operation_id = GNUNET_htonll (opc->id); | ||
1398 | opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_link_controllers, | ||
1399 | &oprelease_link_controllers); | ||
1400 | GNUNET_TESTBED_operation_queue_insert_ (master->opq_peer_create, opc->op); | ||
1401 | return opc->op; | ||
1351 | } | 1402 | } |
1352 | 1403 | ||
1353 | 1404 | ||
@@ -1395,23 +1446,25 @@ GNUNET_TESTBED_compress_config_ (const char *config, size_t size, | |||
1395 | * @param is_subordinate GNUNET_YES if the slave should be started (and stopped) | 1446 | * @param is_subordinate GNUNET_YES if the slave should be started (and stopped) |
1396 | * by the master controller; GNUNET_NO if we are just | 1447 | * by the master controller; GNUNET_NO if we are just |
1397 | * allowed to use the slave via TCP/IP | 1448 | * allowed to use the slave via TCP/IP |
1449 | * @return the operation handle | ||
1398 | */ | 1450 | */ |
1399 | void | 1451 | struct GNUNET_TESTBED_Operation * |
1400 | GNUNET_TESTBED_controller_link (struct GNUNET_TESTBED_Controller *master, | 1452 | GNUNET_TESTBED_controller_link (struct GNUNET_TESTBED_Controller *master, |
1401 | struct GNUNET_TESTBED_Host *delegated_host, | 1453 | struct GNUNET_TESTBED_Host *delegated_host, |
1402 | struct GNUNET_TESTBED_Host *slave_host, | 1454 | struct GNUNET_TESTBED_Host *slave_host, |
1403 | const struct GNUNET_CONFIGURATION_Handle *slave_cfg, | 1455 | const struct GNUNET_CONFIGURATION_Handle *slave_cfg, |
1404 | int is_subordinate) | 1456 | int is_subordinate) |
1405 | { | 1457 | { |
1458 | struct GNUNET_TESTBED_Operation *op; | ||
1406 | char *config; | 1459 | char *config; |
1407 | char *cconfig; | 1460 | char *cconfig; |
1408 | size_t cc_size; | 1461 | size_t cc_size; |
1409 | size_t config_size; | 1462 | size_t config_size; |
1410 | 1463 | ||
1411 | GNUNET_assert (GNUNET_YES == | 1464 | GNUNET_assert (GNUNET_YES == |
1412 | GNUNET_TESTBED_is_host_registered_ (delegated_host, master)); | 1465 | GNUNET_TESTBED_is_host_registered_ (delegated_host, master)); |
1413 | if ((NULL != slave_host) && (0 != GNUNET_TESTBED_host_get_id_ (slave_host))) | 1466 | if ((NULL != slave_host) && (0 != GNUNET_TESTBED_host_get_id_ (slave_host))) |
1414 | GNUNET_assert (GNUNET_YES == | 1467 | GNUNET_assert (GNUNET_YES == |
1415 | GNUNET_TESTBED_is_host_registered_ (slave_host, master)); | 1468 | GNUNET_TESTBED_is_host_registered_ (slave_host, master)); |
1416 | config = GNUNET_CONFIGURATION_serialize (slave_cfg, &config_size); | 1469 | config = GNUNET_CONFIGURATION_serialize (slave_cfg, &config_size); |
1417 | cc_size = GNUNET_TESTBED_compress_config_ (config, config_size, &cconfig); | 1470 | cc_size = GNUNET_TESTBED_compress_config_ (config, config_size, &cconfig); |
@@ -1419,10 +1472,11 @@ GNUNET_TESTBED_controller_link (struct GNUNET_TESTBED_Controller *master, | |||
1419 | GNUNET_assert ((UINT16_MAX - | 1472 | GNUNET_assert ((UINT16_MAX - |
1420 | sizeof (struct GNUNET_TESTBED_ControllerLinkMessage)) | 1473 | sizeof (struct GNUNET_TESTBED_ControllerLinkMessage)) |
1421 | >= cc_size); /* Configuration doesn't fit in 1 message */ | 1474 | >= cc_size); /* Configuration doesn't fit in 1 message */ |
1422 | GNUNET_TESTBED_controller_link_2 (master, delegated_host, slave_host, | 1475 | op = GNUNET_TESTBED_controller_link_2 (master, delegated_host, slave_host, |
1423 | (const char *) cconfig, | 1476 | (const char *) cconfig, |
1424 | cc_size, config_size, is_subordinate); | 1477 | cc_size, config_size, is_subordinate); |
1425 | GNUNET_free (cconfig); | 1478 | GNUNET_free (cconfig); |
1479 | return op; | ||
1426 | } | 1480 | } |
1427 | 1481 | ||
1428 | 1482 | ||
@@ -1495,9 +1549,6 @@ GNUNET_TESTBED_create_helper_init_msg_ (const char *cname, | |||
1495 | void | 1549 | void |
1496 | GNUNET_TESTBED_operation_cancel (struct GNUNET_TESTBED_Operation *operation) | 1550 | GNUNET_TESTBED_operation_cancel (struct GNUNET_TESTBED_Operation *operation) |
1497 | { | 1551 | { |
1498 | GNUNET_CONTAINER_DLL_remove (operation->controller->op_head, | ||
1499 | operation->controller->op_tail, | ||
1500 | operation); | ||
1501 | GNUNET_TESTBED_operation_done (operation); | 1552 | GNUNET_TESTBED_operation_done (operation); |
1502 | } | 1553 | } |
1503 | 1554 | ||
@@ -1522,6 +1573,7 @@ GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation) | |||
1522 | case OP_PEER_STOP: | 1573 | case OP_PEER_STOP: |
1523 | case OP_PEER_INFO: | 1574 | case OP_PEER_INFO: |
1524 | case OP_OVERLAY_CONNECT: | 1575 | case OP_OVERLAY_CONNECT: |
1576 | case OP_LINK_CONTROLLERS: | ||
1525 | GNUNET_TESTBED_operation_release_ (operation); | 1577 | GNUNET_TESTBED_operation_release_ (operation); |
1526 | return; | 1578 | return; |
1527 | default: | 1579 | default: |