X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Ftestbed%2Ftestbed_api.h;h=17cd38df35c755e2ce3b0de0f4dc486870828880;hb=d17a17ea785f91c18b5694eab3372c4e4564d95e;hp=ed5b38b1dad340333f0fe96a4cb44745cd890eb2;hpb=12125a5027fffe8fccf873b46c08f2c8cb1b96c6;p=oweals%2Fgnunet.git diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h index ed5b38b1d..17cd38df3 100644 --- a/src/testbed/testbed_api.h +++ b/src/testbed/testbed_api.h @@ -1,21 +1,21 @@ /* This file is part of GNUnet - (C) 2012 Christian Grothoff (and other contributing authors) + Copyright (C) 2008--2013 GNUnet e.V. - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + Affero General Public License for more details. - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + SPDX-License-Identifier: AGPL3.0-or-later */ /** @@ -27,9 +27,10 @@ #ifndef TESTBED_API_H #define TESTBED_API_H +#include "gnunet_util_lib.h" #include "gnunet_testbed_service.h" #include "testbed.h" - +#include "testbed_helper.h" /** * Testbed Helper binary name @@ -42,63 +43,66 @@ */ enum OperationType { - /** - * Peer create operation - */ + /** + * Peer create operation + */ OP_PEER_CREATE, - /** - * Peer start operation - */ + /** + * Peer start operation + */ OP_PEER_START, - /** - * Peer stop operation - */ + /** + * Peer stop operation + */ OP_PEER_STOP, - /** - * Peer destroy operation - */ + /** + * Peer destroy operation + */ OP_PEER_DESTROY, - /** - * Get peer information operation - */ + /** + * Get peer information operation + */ OP_PEER_INFO, - /** - * Overlay connection operation - */ + /** + * Reconfigure a peer + */ + OP_PEER_RECONFIGURE, + + /** + * Overlay connection operation + */ OP_OVERLAY_CONNECT, - /** - * Forwarded operation - */ + /** + * Forwarded operation + */ OP_FORWARDED, - /** - * Link controllers operation - */ + /** + * Link controllers operation + */ OP_LINK_CONTROLLERS, /** * Get slave config operation */ - OP_GET_SLAVE_CONFIG - -}; - + OP_GET_SLAVE_CONFIG, -/** - * The message queue for sending messages to the controller service - */ -struct MessageQueue; + /** + * Stop and destroy all peers + */ + OP_SHUTDOWN_PEERS, -/** - * Structure for a controller link - */ -struct ControllerLink; + /** + * Start/stop service at a peer + */ + OP_MANAGE_SERVICE +}; /** @@ -106,22 +110,22 @@ struct ControllerLink; */ enum OperationContextState { - /** - * The initial state where the associated operation has just been created - * and is waiting in the operation queues to be started - */ + /** + * The initial state where the associated operation has just been created + * and is waiting in the operation queues to be started + */ OPC_STATE_INIT = 0, - /** - * The operation has been started. It may occupy some resources which are to - * be freed if cancelled. - */ + /** + * The operation has been started. It may occupy some resources which are to + * be freed if cancelled. + */ OPC_STATE_STARTED, - /** - * The operation has finished. The end results of this operation may occupy - * some resources which are to be freed by operation_done - */ + /** + * The operation has finished. The end results of this operation may occupy + * some resources which are to be freed by operation_done + */ OPC_STATE_FINISHED }; @@ -131,16 +135,6 @@ enum OperationContextState */ struct OperationContext { - /** - * next ptr for DLL - */ - struct OperationContext *next; - - /** - * prev ptr for DLL - */ - struct OperationContext *prev; - /** * The controller to which this operation context belongs to */ @@ -179,27 +173,12 @@ struct OperationContext /** - * Opaque handle for SD calculations - */ -struct SDHandle; - - -/** - * A slot to record time taken by an overlay connect operation + * Operation empty callback + * + * @param cls closure */ -struct TimeSlot -{ - /** - * A key to identify this timeslot - */ - void *key; - - /** - * Time - */ - struct GNUNET_TIME_Relative time; - -}; +typedef void +(*TESTBED_opcq_empty_cb) (void *cls); /** @@ -234,34 +213,9 @@ struct GNUNET_TESTBED_Controller struct GNUNET_CONFIGURATION_Handle *cfg; /** - * The client connection handle to the controller service - */ - struct GNUNET_CLIENT_Connection *client; - - /** - * The head of the message queue - */ - struct MessageQueue *mq_head; - - /** - * The tail of the message queue + * The message queue to the controller service */ - struct MessageQueue *mq_tail; - - /** - * The head of the ControllerLink list - */ - struct ControllerLink *cl_head; - - /** - * The tail of the ControllerLink list - */ - struct ControllerLink *cl_tail; - - /** - * The client transmit handle - */ - struct GNUNET_CLIENT_TransmitHandle *th; + struct GNUNET_MQ_Handle *mq; /** * The host registration handle; NULL if no current registration requests are @@ -270,14 +224,19 @@ struct GNUNET_TESTBED_Controller struct GNUNET_TESTBED_HostRegistrationHandle *rh; /** - * The head of the opeartion context queue + * The map of active operation contexts + */ + struct GNUNET_CONTAINER_MultiHashMap32 *opc_map; + + /** + * If this callback is not NULL, schedule it as a task when opc_map gets empty */ - struct OperationContext *ocq_head; + TESTBED_opcq_empty_cb opcq_empty_cb; /** - * The tail of the operation context queue + * Closure for the above task */ - struct OperationContext *ocq_tail; + void *opcq_empty_cls; /** * Operation queue for simultaneous operations @@ -295,52 +254,57 @@ struct GNUNET_TESTBED_Controller struct OperationQueue *opq_parallel_topology_config_operations; /** - * Operation queue for simultaneous overlay connect operations + * handle for hashtable of barrier handles, values are + * of type `struct GNUNET_TESTBED_Barrier`. */ - struct OperationQueue *opq_parallel_overlay_connect_operations; + struct GNUNET_CONTAINER_MultiHashMap *barrier_map; /** - * An array of timing slots; size should be equal to the current number of parallel - * overlay connects + * The controller event mask */ - struct TimeSlot *tslots; + uint64_t event_mask; /** - * Handle for SD calculations amount parallel overlay connect operation finish - * times + * The operation id counter. use current value and increment */ - struct SDHandle *poc_sd; + uint32_t operation_counter; +}; + +/** + * Handle for barrier + */ +struct GNUNET_TESTBED_Barrier +{ /** - * The controller event mask + * hashcode identifying this barrier in the hashmap */ - uint64_t event_mask; - + struct GNUNET_HashCode key; + /** - * Did we start the receive loop yet? + * The controller handle given while initiliasing this barrier */ - int in_receive; + struct GNUNET_TESTBED_Controller *c; /** - * Did we create the host for this? + * The name of the barrier */ - int aux_host; + char *name; /** - * The number of parallel overlay connects we do currently + * The continuation callback to call when we have a status update on this */ - unsigned int num_parallel_connects; + GNUNET_TESTBED_barrier_status_cb cb; /** - * Counter to indicate when all the available time slots are filled + * the closure for the above callback */ - unsigned int tslots_filled; + void *cls; /** - * The operation id counter. use current value and increment + * Should the barrier crossed status message be echoed back to the controller? */ - uint32_t operation_counter; - + int echo; }; @@ -349,12 +313,38 @@ struct GNUNET_TESTBED_Controller * * @param controller the handle to the controller * @param msg the message to queue + * @deprecated */ void GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller, struct GNUNET_MessageHeader *msg); +/** + * Inserts the given operation context into the operation context map of the + * given controller. Creates the operation context map if one does not exist + * for the controller + * + * @param c the controller + * @param opc the operation context to be inserted + */ +void +GNUNET_TESTBED_insert_opc_ (struct GNUNET_TESTBED_Controller *c, + struct OperationContext *opc); + + +/** + * Removes the given operation context from the operation context map of the + * given controller + * + * @param c the controller + * @param opc the operation context to remove + */ +void +GNUNET_TESTBED_remove_opc_ (const struct GNUNET_TESTBED_Controller *c, + struct OperationContext *opc); + + /** * Compresses given configuration using zlib compress * @@ -365,17 +355,24 @@ GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller, * @return the size of the xconfig */ size_t -GNUNET_TESTBED_compress_config_ (const char *config, size_t size, +GNUNET_TESTBED_compress_config_ (const char *config, + size_t size, char **xconfig); /** - * Adds an operation to the queue of operations + * Function to serialize and compress using zlib a configuration through a + * configuration handle * - * @param op the operation to add + * @param cfg the configuration + * @param size the size of configuration when serialize. Will be set on success. + * @param xsize the sizeo of the compressed configuration. Will be set on success. + * @return the serialized and compressed configuration */ -void -GNUNET_TESTBED_operation_add_ (struct GNUNET_TESTBED_Operation *op); +char * +GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg, + size_t *size, + size_t *xsize); /** @@ -393,9 +390,9 @@ GNUNET_TESTBED_operation_add_ (struct GNUNET_TESTBED_Operation *op); */ struct GNUNET_TESTBED_HelperInit * GNUNET_TESTBED_create_helper_init_msg_ (const char *cname, - const char *hostname, - const struct GNUNET_CONFIGURATION_Handle - *cfg); + const char *hostname, + const struct + GNUNET_CONFIGURATION_Handle *cfg); /** @@ -413,10 +410,11 @@ GNUNET_TESTBED_create_helper_init_msg_ (const char *cname, * operation */ struct OperationContext * -GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller - *controller, uint64_t operation_id, +GNUNET_TESTBED_forward_operation_msg_ (struct + GNUNET_TESTBED_Controller *controller, + uint64_t operation_id, const struct GNUNET_MessageHeader *msg, - GNUNET_CLIENT_MessageHandler cc, + GNUNET_MQ_MessageCallback cc, void *cc_cls); /** @@ -432,8 +430,8 @@ GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc); /** * Generates configuration by uncompressing configuration in given message. The * given message should be of the following types: - * GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG, - * GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG + * #GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG, + * #GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG * * @param msg the message containing compressed configuration * @return handle to the parsed configuration @@ -485,105 +483,38 @@ GNUNET_TESTBED_get_slave_config_ (void *op_cls, /** - * Same as the GNUNET_TESTBED_controller_link_2, but with ids for delegated host - * and slave host - * - * @param op_cls the operation closure for the event which is generated to - * signal success or failure of this operation - * @param master handle to the master controller who creates the association - * @param delegated_host_id id of the host to which requests should be delegated - * @param slave_host_id id of the host which is used to run the slave controller - * @param sxcfg serialized and compressed configuration - * @param sxcfg_size the size sxcfg - * @param scfg_size the size of uncompressed serialized configuration - * @param is_subordinate GNUNET_YES if the controller at delegated_host should - * be started by the slave controller; GNUNET_NO if the slave - * controller has to connect to the already started delegated - * controller via TCP/IP - * @return the operation handle - */ -struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_controller_link_2_ (void *op_cls, - struct GNUNET_TESTBED_Controller *master, - uint32_t delegated_host_id, - uint32_t slave_host_id, - const char *sxcfg, size_t sxcfg_size, - size_t scfg_size, int is_subordinate); - - -/** - * Same as the GNUNET_TESTBED_controller_link, but with ids for delegated host - * and slave host - * - * @param op_cls the operation closure for the event which is generated to - * signal success or failure of this operation - * @param master handle to the master controller who creates the association - * @param delegated_host_id id of the host to which requests should be - * delegated; cannot be NULL - * @param slave_host_id id of the host which should connect to controller - * running on delegated host ; use NULL to make the master controller - * connect to the delegated host - * @param slave_cfg configuration to use for the slave controller - * @param is_subordinate GNUNET_YES if the controller at delegated_host should - * be started by the slave controller; GNUNET_NO if the slave - * controller has to connect to the already started delegated - * controller via TCP/IP - * @return the operation handle - */ -struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_controller_link_ (void *op_cls, - struct GNUNET_TESTBED_Controller *master, - uint32_t delegated_host_id, - uint32_t slave_host_id, - const struct GNUNET_CONFIGURATION_Handle - *slave_cfg, - int is_subordinate); - - -/** - * Returns a timing slot which will be exclusively locked + * Initialise a barrier and call the given callback when the required percentage + * of peers (quorum) reach the barrier OR upon error. * - * @param c the controller handle - * @param key a pointer which is associated to the returned slot; should not be - * NULL. It serves as a key to determine the correct owner of the slot - * @return the time slot index in the array of time slots in the controller - * handle + * @param controller the handle to the controller + * @param name identification name of the barrier + * @param quorum the percentage of peers that is required to reach the barrier. + * Peers signal reaching a barrier by calling + * GNUNET_TESTBED_barrier_reached(). + * @param cb the callback to call when the barrier is reached or upon error. + * Cannot be NULL. + * @param cls closure for the above callback + * @param echo #GNUNET_YES to echo the barrier crossed status message back to the + * controller + * @return barrier handle; NULL upon error */ -unsigned int -GNUNET_TESTBED_get_tslot_ (struct GNUNET_TESTBED_Controller *c, void *key); +struct GNUNET_TESTBED_Barrier * +GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller, + const char *name, + unsigned int quorum, + GNUNET_TESTBED_barrier_status_cb cb, + void *cls, + int echo); /** - * Function to update a time slot + * Remove a barrier and it was the last one in the barrier hash map, destroy the + * hash map * - * @param c the controller handle - * @param index the index of the time slot to update - * @param key the key to identify ownership of the slot - * @param time the new time + * @param barrier the barrier to remove */ void -GNUNET_TESTBED_update_time_slot_ (struct GNUNET_TESTBED_Controller *c, - unsigned int index, - void *key, - struct GNUNET_TIME_Relative time); - - -/** - * Releases a time slot thus making it available for be used again - * - * @param c the controller handle - * @param index the index of the the time slot - * @param key the key to prove ownership of the timeslot - * @return GNUNET_YES if the time slot is successfully removed; GNUNET_NO if the - * time slot cannot be removed - this could be because of the index - * greater than existing number of time slots or `key' being different - */ -int -GNUNET_TESTBED_release_time_slot_ (struct GNUNET_TESTBED_Controller *c, - unsigned int index, - void *key); - - +GNUNET_TESTBED_barrier_remove_ (struct GNUNET_TESTBED_Barrier *barrier); #endif