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 controller event mask
285 * Did we start the receive loop yet?
290 * Did we create the host for this?
295 * The number of parallel overlay connects we do currently
297 unsigned int num_parallel_connects;
300 * The threshold for the number of parallel overlay connects we do
302 unsigned int num_parallel_connects_threshold;
305 * The operation id counter. use current value and increment
307 uint32_t operation_counter;
313 * Queues a message in send queue for sending to the service
315 * @param controller the handle to the controller
316 * @param msg the message to queue
319 GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller,
320 struct GNUNET_MessageHeader *msg);
324 * Compresses given configuration using zlib compress
326 * @param config the serialized configuration
327 * @param size the size of config
328 * @param xconfig will be set to the compressed configuration (memory is fresly
330 * @return the size of the xconfig
333 GNUNET_TESTBED_compress_config_ (const char *config, size_t size,
338 * Adds an operation to the queue of operations
340 * @param op the operation to add
343 GNUNET_TESTBED_operation_add_ (struct GNUNET_TESTBED_Operation *op);
347 * Creates a helper initialization message. Only for testing.
349 * @param cname the ip address of the controlling host
350 * @param hostname the hostname of the destination this message is intended for
351 * @param cfg the configuration that has to used to start the testbed service
353 * @return the initialization message
355 struct GNUNET_TESTBED_HelperInit *
356 GNUNET_TESTBED_create_helper_init_msg_ (const char *cname,
357 const char *hostname,
358 const struct GNUNET_CONFIGURATION_Handle
363 * Sends the given message as an operation. The given callback is called when a
364 * reply for the operation is available. Call
365 * GNUNET_TESTBED_forward_operation_msg_cancel_() to cleanup the returned
366 * operation context if the cc hasn't been called
368 * @param controller the controller to which the message has to be sent
369 * @param operation_id the operation id of the message
370 * @param msg the message to send
371 * @param cc the callback to call when reply is available
372 * @param cc_cls the closure for the above callback
373 * @return the operation context which can be used to cancel the forwarded
376 struct OperationContext *
377 GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller
378 *controller, uint64_t operation_id,
379 const struct GNUNET_MessageHeader *msg,
380 GNUNET_CLIENT_MessageHandler cc,
384 * Function to cancel an operation created by simply forwarding an operation
387 * @param opc the operation context from GNUNET_TESTBED_forward_operation_msg_()
390 GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc);
394 * Generates configuration by uncompressing configuration in given message. The
395 * given message should be of the following types:
396 * GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG,
397 * GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG
399 * @param msg the message containing compressed configuration
400 * @return handle to the parsed configuration
402 struct GNUNET_CONFIGURATION_Handle *
403 GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg);
407 * Checks the integrity of the OpeationFailureEventMessage and if good returns
408 * the error message it contains.
410 * @param msg the OperationFailureEventMessage
411 * @return the error message
414 GNUNET_TESTBED_parse_error_string_ (const struct
415 GNUNET_TESTBED_OperationFailureEventMessage
420 * Function to return the operation id for a controller. The operation id is
421 * created from the controllers host id and its internal operation counter.
423 * @param controller the handle to the controller whose operation id has to be incremented
424 * @return the incremented operation id.
427 GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller *controller);
431 * Like GNUNET_TESTBED_get_slave_config(), however without the host registration
432 * check. Another difference is that this function takes the id of the slave
435 * @param op_cls the closure for the operation
436 * @param master the handle to master controller
437 * @param slave_host_id id of the host where the slave controller is running to
438 * the slave_host should remain valid until this operation is cancelled
439 * or marked as finished
440 * @return the operation handle;
442 struct GNUNET_TESTBED_Operation *
443 GNUNET_TESTBED_get_slave_config_ (void *op_cls,
444 struct GNUNET_TESTBED_Controller *master,
445 uint32_t slave_host_id);
449 * Same as the GNUNET_TESTBED_controller_link_2, but with ids for delegated host
452 * @param op_cls the operation closure for the event which is generated to
453 * signal success or failure of this operation
454 * @param master handle to the master controller who creates the association
455 * @param delegated_host_id id of the host to which requests should be delegated
456 * @param slave_host_id id of the host which is used to run the slave controller
457 * @param sxcfg serialized and compressed configuration
458 * @param sxcfg_size the size sxcfg
459 * @param scfg_size the size of uncompressed serialized configuration
460 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
461 * be started by the slave controller; GNUNET_NO if the slave
462 * controller has to connect to the already started delegated
463 * controller via TCP/IP
464 * @return the operation handle
466 struct GNUNET_TESTBED_Operation *
467 GNUNET_TESTBED_controller_link_2_ (void *op_cls,
468 struct GNUNET_TESTBED_Controller *master,
469 uint32_t delegated_host_id,
470 uint32_t slave_host_id,
471 const char *sxcfg, size_t sxcfg_size,
472 size_t scfg_size, int is_subordinate);
476 * Same as the GNUNET_TESTBED_controller_link, but with ids for delegated host
479 * @param op_cls the operation closure for the event which is generated to
480 * signal success or failure of this operation
481 * @param master handle to the master controller who creates the association
482 * @param delegated_host_id id of the host to which requests should be
483 * delegated; cannot be NULL
484 * @param slave_host_id id of the host which should connect to controller
485 * running on delegated host ; use NULL to make the master controller
486 * connect to the delegated host
487 * @param slave_cfg configuration to use for the slave controller
488 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
489 * be started by the slave controller; GNUNET_NO if the slave
490 * controller has to connect to the already started delegated
491 * controller via TCP/IP
492 * @return the operation handle
494 struct GNUNET_TESTBED_Operation *
495 GNUNET_TESTBED_controller_link_ (void *op_cls,
496 struct GNUNET_TESTBED_Controller *master,
497 uint32_t delegated_host_id,
498 uint32_t slave_host_id,
499 const struct GNUNET_CONFIGURATION_Handle
504 /* end of testbed_api.h */