diff options
author | harsha <harsha@140774ce-b5e7-0310-ab8b-a85725594a96> | 2012-07-31 15:29:32 +0000 |
---|---|---|
committer | harsha <harsha@140774ce-b5e7-0310-ab8b-a85725594a96> | 2012-07-31 15:29:32 +0000 |
commit | a757672fefb91ee5f1c5af4b8cc1b2fed27702b4 (patch) | |
tree | fde9fe16f606ffbbce44a14b7edc32f2235dc401 /src/testbed | |
parent | 823634976826e5fc681efb2dcc0f543ec06d4308 (diff) |
peer destroy with new operations handling
git-svn-id: https://gnunet.org/svn/gnunet@23020 140774ce-b5e7-0310-ab8b-a85725594a96
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/testbed_api.c | 32 | ||||
-rw-r--r-- | src/testbed/testbed_api_peers.c | 75 | ||||
-rw-r--r-- | src/testbed/testbed_api_peers.h | 23 |
3 files changed, 66 insertions, 64 deletions
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index de64b3b49c..cb71808824 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c @@ -224,18 +224,18 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c, const struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg) { - struct GNUNET_TESTBED_Operation *op; + struct OperationContext *opc; struct GNUNET_TESTBED_EventInformation *event; uint64_t op_id; op_id = GNUNET_ntohll (msg->operation_id); LOG_DEBUG ("Operation %ul successful\n", op_id); - for (op = c->op_head; NULL != op; op = op->next) + for (opc = c->ocq_head; NULL != opc; opc = opc->next) { - if (op->operation_id == op_id) + if (opc->id == op_id) break; } - if (NULL == op) + if (NULL == opc) { LOG_DEBUG ("Operation not found\n"); return GNUNET_YES; @@ -245,37 +245,29 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c, event = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_EventInformation)); if (NULL != event) event->type = GNUNET_TESTBED_ET_OPERATION_FINISHED; - switch (op->type) + switch (opc->type) { case OP_PEER_DESTROY: { - struct PeerDestroyData *data; + struct GNUNET_TESTBED_Peer *peer; if (NULL != event) { - event->details.operation_finished.operation = op; + event->details.operation_finished.operation = opc->op; event->details.operation_finished.op_cls = NULL; event->details.operation_finished.emsg = NULL; event->details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC; event->details.operation_finished.op_result.generic = NULL; } - data = (struct PeerDestroyData *) op->data; - if (NULL != data->peer->details) - { - if (NULL != data->peer->details->cfg) - GNUNET_CONFIGURATION_destroy (data->peer->details->cfg); - //PEER_DETAILS - } - GNUNET_free (data->peer); - GNUNET_free (data); - op->data = NULL; + peer = opc->data; + GNUNET_free (peer); + opc->data = NULL; //PEERDESTROYDATA } break; default: GNUNET_assert (0); } - GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op); if (NULL != event) { if (NULL != c->cc) @@ -1354,8 +1346,8 @@ GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation) GNUNET_TESTBED_operation_release_ (operation); return; case OP_PEER_DESTROY: - GNUNET_free_non_null (operation->data); - break; + GNUNET_TESTBED_operation_release_ (operation); + return; case OP_PEER_START: case OP_PEER_STOP: break; diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c index 3ecb383259..4f9fa768c8 100644 --- a/src/testbed/testbed_api_peers.c +++ b/src/testbed/testbed_api_peers.c @@ -91,6 +91,48 @@ oprelease_peer_create (void *cls) /** + * Function to called when a peer destroy operation is ready + * + * @param cls the closure from GNUNET_TESTBED_operation_create_() + */ +static void +opstart_peer_destroy (void *cls) +{ + struct OperationContext *opc = cls; + struct GNUNET_TESTBED_Peer *peer; + struct GNUNET_TESTBED_PeerDestroyMessage *msg; + + GNUNET_assert (OP_PEER_DESTROY == opc->type); + peer = opc->data; + GNUNET_assert (NULL != peer); + msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)); + msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)); + msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER); + msg->peer_id = htonl (peer->unique_id); + msg->operation_id = GNUNET_htonll (opc->id); + GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, + opc->c->ocq_tail, opc); + GNUNET_TESTBED_queue_message_ (peer->controller, + (struct GNUNET_MessageHeader *) msg); +} + + +/** + * Callback which will be called when peer_create type operation is released + * + * @param cls the closure from GNUNET_TESTBED_operation_create_() + */ +static void +oprelease_peer_destroy (void *cls) +{ + struct OperationContext *opc = cls; + + GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); + GNUNET_free (opc); +} + + +/** * Lookup a peer by ID. * * @param id global peer ID assigned to the peer @@ -347,27 +389,18 @@ GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer, struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer) { - struct GNUNET_TESTBED_Operation *op; - struct PeerDestroyData *data; - struct GNUNET_TESTBED_PeerDestroyMessage *msg; - - data = GNUNET_malloc (sizeof (struct PeerDestroyData)); - data->peer = peer; - op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation)); - op->operation_id = peer->controller->operation_counter++; - op->controller = peer->controller; - op->type = OP_PEER_DESTROY; - op->data = data; - msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)); - msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)); - msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER); - msg->peer_id = htonl (peer->unique_id); - msg->operation_id = GNUNET_htonll (op->operation_id); - GNUNET_CONTAINER_DLL_insert_tail (peer->controller->op_head, - peer->controller->op_tail, op); - GNUNET_TESTBED_queue_message_ (peer->controller, - (struct GNUNET_MessageHeader *) msg); - return op; + struct OperationContext *opc; + + opc = GNUNET_malloc (sizeof (struct OperationContext)); + opc->data = peer; + opc->c = peer->controller; + opc->id = peer->controller->operation_counter++; + opc->type = OP_PEER_DESTROY; + opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_destroy, + &oprelease_peer_destroy); + GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_peer_create, + opc->op); + return opc->op; } diff --git a/src/testbed/testbed_api_peers.h b/src/testbed/testbed_api_peers.h index e7c1e91365..72c1c1b58f 100644 --- a/src/testbed/testbed_api_peers.h +++ b/src/testbed/testbed_api_peers.h @@ -31,23 +31,6 @@ /** - * Details about a peer; kept in a separate struct to avoid bloating - * memory consumption everywhere... - */ -struct PeerDetails -{ - /** - * Configuration of the peer; NULL if we are not sure what the peer's correct - * configuration actually is; non-NULL if this peer is controlled by this - * process. - */ - struct GNUNET_CONFIGURATION_Handle *cfg; - - //PEER_DETAILS -}; - - -/** * Enumeration of possible states a peer could be in */ enum PeerState @@ -92,12 +75,6 @@ struct GNUNET_TESTBED_Peer struct GNUNET_TESTBED_Host *host; /** - * Internals of the peer for the controlling process; NULL if - * this process is not controlling this peer. - */ - struct PeerDetails *details; - - /** * Globally unique ID of the peer. */ uint32_t unique_id; |