2 This file is part of GNUnet
3 (C) 2012 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file testbed/testbed_api.h
23 * @brief Interface for functions internally exported from testbed_api.c
24 * @author Sree Harsha Totakura
30 #include "gnunet_testbed_service.h"
35 * Testbed Helper binary name
37 #define HELPER_TESTBED_BINARY "gnunet-helper-testbed"
41 * Enumeration of operations
46 * Peer create operation
51 * Peer start operation
61 * Peer destroy operation
66 * Get peer information operation
71 * Overlay connection operation
81 * Link controllers operation
86 * Get slave config operation
94 * The message queue for sending messages to the controller service
99 * Structure for a controller link
101 struct ControllerLink;
105 * Enumeration of states of OperationContext
107 enum OperationContextState
110 * The initial state where the associated operation has just been created
111 * and is waiting in the operation queues to be started
116 * The operation has been started. It may occupy some resources which are to
117 * be freed if cancelled.
122 * The operation has finished. The end results of this operation may occupy
123 * some resources which are to be freed by operation_done
130 * Context information for GNUNET_TESTBED_Operation
132 struct OperationContext
137 struct OperationContext *next;
142 struct OperationContext *prev;
145 * The controller to which this operation context belongs to
147 struct GNUNET_TESTBED_Controller *c;
152 struct GNUNET_TESTBED_Operation *op;
155 * The operation closure
160 * Data relevant to the operation
165 * The id of the opearation
170 * The type of operation
172 enum OperationType type;
175 * The state of the operation
177 enum OperationContextState state;
182 * Handle to interact with a GNUnet testbed controller. Each
183 * controller has at least one master handle which is created when the
184 * controller is created; this master handle interacts with the
185 * controller process, destroying it destroys the controller (by
186 * closing stdin of the controller process). Additionally,
187 * controllers can interact with each other (in a P2P fashion); those
188 * links are established via TCP/IP on the controller's service port.
190 struct GNUNET_TESTBED_Controller
194 * The host where the controller is running
196 struct GNUNET_TESTBED_Host *host;
199 * The controller callback
201 GNUNET_TESTBED_ControllerCallback cc;
204 * The closure for controller callback
209 * The configuration to use while connecting to controller
211 struct GNUNET_CONFIGURATION_Handle *cfg;
214 * The client connection handle to the controller service
216 struct GNUNET_CLIENT_Connection *client;
219 * The head of the message queue
221 struct MessageQueue *mq_head;
224 * The tail of the message queue
226 struct MessageQueue *mq_tail;
229 * The head of the ControllerLink list
231 struct ControllerLink *cl_head;
234 * The tail of the ControllerLink list
236 struct ControllerLink *cl_tail;
239 * The client transmit handle
241 struct GNUNET_CLIENT_TransmitHandle *th;
244 * The host registration handle; NULL if no current registration requests are
247 struct GNUNET_TESTBED_HostRegistrationHandle *rh;
250 * The head of the opeartion context queue
252 struct OperationContext *ocq_head;
255 * The tail of the operation context queue
257 struct OperationContext *ocq_tail;
260 * Operation queue for simultaneous operations
262 struct OperationQueue *opq_parallel_operations;
265 * Operation queue for simultaneous service connections
267 struct OperationQueue *opq_parallel_service_connections;
270 * Operation queue for simultaneous topology configuration operations
272 struct OperationQueue *opq_parallel_topology_config_operations;
275 * Operation queue for simultaneous overlay connect operations
277 struct OperationQueue *opq_parallel_overlay_connect_operations;
280 * The operation id counter. use current value and increment
282 uint32_t operation_counter;
285 * The controller event mask
290 * Did we start the receive loop yet?
295 * Did we create the host for this?
302 * Queues a message in send queue for sending to the service
304 * @param controller the handle to the controller
305 * @param msg the message to queue
308 GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller,
309 struct GNUNET_MessageHeader *msg);
313 * Compresses given configuration using zlib compress
315 * @param config the serialized configuration
316 * @param size the size of config
317 * @param xconfig will be set to the compressed configuration (memory is fresly
319 * @return the size of the xconfig
322 GNUNET_TESTBED_compress_config_ (const char *config, size_t size,
327 * Adds an operation to the queue of operations
329 * @param op the operation to add
332 GNUNET_TESTBED_operation_add_ (struct GNUNET_TESTBED_Operation *op);
336 * Creates a helper initialization message. Only for testing.
338 * @param cname the ip address of the controlling host
339 * @param hostname the hostname of the destination this message is intended for
340 * @param cfg the configuration that has to used to start the testbed service
342 * @return the initialization message
344 struct GNUNET_TESTBED_HelperInit *
345 GNUNET_TESTBED_create_helper_init_msg_ (const char *cname,
346 const char *hostname,
347 const struct GNUNET_CONFIGURATION_Handle
352 * Sends the given message as an operation. The given callback is called when a
353 * reply for the operation is available. Call
354 * GNUNET_TESTBED_forward_operation_msg_cancel_() to cleanup the returned
355 * operation context if the cc hasn't been called
357 * @param controller the controller to which the message has to be sent
358 * @param operation_id the operation id of the message
359 * @param msg the message to send
360 * @param cc the callback to call when reply is available
361 * @param cc_cls the closure for the above callback
362 * @return the operation context which can be used to cancel the forwarded
365 struct OperationContext *
366 GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller
367 *controller, uint64_t operation_id,
368 const struct GNUNET_MessageHeader *msg,
369 GNUNET_CLIENT_MessageHandler cc,
373 * Function to cancel an operation created by simply forwarding an operation
376 * @param opc the operation context from GNUNET_TESTBED_forward_operation_msg_()
379 GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc);
383 * Generates configuration by uncompressing configuration in given message. The
384 * given message should be of the following types:
385 * GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG,
386 * GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG
388 * @param msg the message containing compressed configuration
389 * @return handle to the parsed configuration
391 struct GNUNET_CONFIGURATION_Handle *
392 GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg);
396 * Checks the integrity of the OpeationFailureEventMessage and if good returns
397 * the error message it contains.
399 * @param msg the OperationFailureEventMessage
400 * @return the error message
403 GNUNET_TESTBED_parse_error_string_ (const struct
404 GNUNET_TESTBED_OperationFailureEventMessage
409 * Function to return the operation id for a controller. The operation id is
410 * created from the controllers host id and its internal operation counter.
412 * @param controller the handle to the controller whose operation id has to be incremented
413 * @return the incremented operation id.
416 GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller *controller);
420 * Like GNUNET_TESTBED_get_slave_config(), however without the host registration
421 * check. Another difference is that this function takes the id of the slave
424 * @param op_cls the closure for the operation
425 * @param master the handle to master controller
426 * @param slave_host_id id of the host where the slave controller is running to
427 * the slave_host should remain valid until this operation is cancelled
428 * or marked as finished
429 * @return the operation handle;
431 struct GNUNET_TESTBED_Operation *
432 GNUNET_TESTBED_get_slave_config_ (void *op_cls,
433 struct GNUNET_TESTBED_Controller *master,
434 uint32_t slave_host_id);
438 * Same as the GNUNET_TESTBED_controller_link_2, but with ids for delegated host
441 * @param op_cls the operation closure for the event which is generated to
442 * signal success or failure of this operation
443 * @param master handle to the master controller who creates the association
444 * @param delegated_host_id id of the host to which requests should be delegated
445 * @param slave_host_id id of the host which is used to run the slave controller
446 * @param sxcfg serialized and compressed configuration
447 * @param sxcfg_size the size sxcfg
448 * @param scfg_size the size of uncompressed serialized configuration
449 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
450 * be started by the slave controller; GNUNET_NO if the slave
451 * controller has to connect to the already started delegated
452 * controller via TCP/IP
453 * @return the operation handle
455 struct GNUNET_TESTBED_Operation *
456 GNUNET_TESTBED_controller_link_2_ (void *op_cls,
457 struct GNUNET_TESTBED_Controller *master,
458 uint32_t delegated_host_id,
459 uint32_t slave_host_id,
460 const char *sxcfg, size_t sxcfg_size,
461 size_t scfg_size, int is_subordinate);
465 * Same as the GNUNET_TESTBED_controller_link, but with ids for delegated host
468 * @param op_cls the operation closure for the event which is generated to
469 * signal success or failure of this operation
470 * @param master handle to the master controller who creates the association
471 * @param delegated_host_id id of the host to which requests should be
472 * delegated; cannot be NULL
473 * @param slave_host_id id of the host which should connect to controller
474 * running on delegated host ; use NULL to make the master controller
475 * connect to the delegated host
476 * @param slave_cfg configuration to use for the slave controller
477 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
478 * be started by the slave controller; GNUNET_NO if the slave
479 * controller has to connect to the already started delegated
480 * controller via TCP/IP
481 * @return the operation handle
483 struct GNUNET_TESTBED_Operation *
484 GNUNET_TESTBED_controller_link_ (void *op_cls,
485 struct GNUNET_TESTBED_Controller *master,
486 uint32_t delegated_host_id,
487 uint32_t slave_host_id,
488 const struct GNUNET_CONFIGURATION_Handle
493 /* end of testbed_api.h */