From: Sree Harsha Totakura Date: Sun, 8 Jul 2012 20:28:46 +0000 (+0000) Subject: operation and peer_destroy X-Git-Tag: initial-import-from-subversion-38251~12590 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=8fa1a818df4f8466dbaeece10f2a1bdecc396595;p=oweals%2Fgnunet.git operation and peer_destroy --- diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 159b43daf..b290e748c 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c @@ -24,7 +24,10 @@ * This library is supposed to make it easier to write * testcases and script large-scale benchmarks. * @author Christian Grothoff + * @author Sree Harsha Totakura */ + + #include "platform.h" #include "gnunet_testbed_service.h" #include "gnunet_core_service.h" @@ -34,6 +37,7 @@ #include #include "testbed.h" +#include "testbed_api.h" #include "testbed_api_hosts.h" /** @@ -234,6 +238,34 @@ struct GNUNET_TESTBED_HostRegistrationHandle }; +/** + * The global operation id counter + */ +uint64_t GNUNET_TESTBED_operation_id; + +/** + * The head of the operation queue + */ +struct GNUNET_TESTBED_Operation *op_head; + +/** + * The tail of the operation queue + */ +struct GNUNET_TESTBED_Operation *op_tail; + + +/** + * Adds an operation to the queue of operations + * + * @param op the operation to add + */ +void +GNUNET_TESTBED_operation_add (struct GNUNET_TESTBED_Operation *op) +{ + GNUNET_CONTAINER_DLL_insert_tail (op_head, op_tail, op); +} + + /** * Handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from * controller (testbed service) diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h index aee284c40..53e4607ff 100644 --- a/src/testbed/testbed_api.h +++ b/src/testbed/testbed_api.h @@ -27,6 +27,57 @@ #ifndef TESTBED_API_H #define TESTBED_API_H + +/** + * Enumeration of operations + */ +enum OperationType + { + /** + * Peer destroy operation + */ + OP_PEER_DESTROY + }; + + +/** + * The counter for generating unique operation ids. Use its current value and + * increment it (defined in testbed_api.c) + */ +extern uint64_t GNUNET_TESTBED_operation_id; + +/** + * Testbed operation structure + */ +struct GNUNET_TESTBED_Operation +{ + /** + * next pointer for DLL + */ + struct GNUNET_TESTBED_Operation *next; + + /** + * prev pointer for DLL + */ + struct GNUNET_TESTBED_Operation *prev; + + /** + * The ID for the operation; + */ + uint64_t operation_id; + + /** + * The type of operation + */ + enum OperationType type; + + /** + * Data specific to OperationType + */ + void *data; +}; + + /** * Queues a message in send queue for sending to the service * @@ -51,4 +102,13 @@ size_t GNUNET_TESTBED_compress_config (const char *config, size_t size, char **xconfig); + +/** + * Adds an operation to the queue of operations + * + * @param op the operation to add + */ +void +GNUNET_TESTBED_operation_add (struct GNUNET_TESTBED_Operation *op); + #endif diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c index 844510cda..c225c7d12 100644 --- a/src/testbed/testbed_api_peers.c +++ b/src/testbed/testbed_api_peers.c @@ -272,6 +272,38 @@ GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer, } +/** + * Destroy the given peer; the peer should have been + * stopped first (if it was started). + * + * @param peer peer to stop + * @return handle to the operation + */ +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 = GNUNET_TESTBED_operation_id++; + 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 = peer->unique_id; + msg->operation_id = GNUNET_htonll (op->operation_id); + GNUNET_TESTBED_operation_add (op); + GNUNET_TESTBED_queue_message (peer->controller, + (struct GNUNET_MessageHeader *) msg); + return op; +} + + /** * Manipulate the P2P underlay topology by configuring a link * between two peers. diff --git a/src/testbed/testbed_api_peers.h b/src/testbed/testbed_api_peers.h index ea42c9810..3a9244fc2 100644 --- a/src/testbed/testbed_api_peers.h +++ b/src/testbed/testbed_api_peers.h @@ -30,6 +30,15 @@ #include "gnunet_helper_lib.h" +/** + * Data for the OperationType OP_PEER_DESTROY; + */ +struct PeerDestroyData +{ + struct GNUNET_TESTBED_Peer *peer; +}; + + /** * Create the given peer at the specified host using the given * controller. If the given controller is not running on the target