From: Sree Harsha Totakura Date: Tue, 31 Jul 2012 15:29:32 +0000 (+0000) Subject: peer destroy with new operations handling X-Git-Tag: initial-import-from-subversion-38251~12270 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=2eb3cf57de7d06f53f1a4dbcdcadcad2c9c09e39;p=oweals%2Fgnunet.git peer destroy with new operations handling --- diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index de64b3b49..cb7180882 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 3ecb38325..4f9fa768c 100644 --- a/src/testbed/testbed_api_peers.c +++ b/src/testbed/testbed_api_peers.c @@ -90,6 +90,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. * @@ -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 e7c1e9136..72c1c1b58 100644 --- a/src/testbed/testbed_api_peers.h +++ b/src/testbed/testbed_api_peers.h @@ -30,23 +30,6 @@ #include "gnunet_helper_lib.h" -/** - * 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 */ @@ -91,12 +74,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. */