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"
34 * Enumeration of operations
39 * Peer create operation
44 * Peer start operation
54 * Peer destroy operation
59 * Get peer information operation
64 * Overlay connection operation
74 * Link controllers operation
79 * Get slave config operation
87 * Testbed operation structure
89 struct GNUNET_TESTBED_Operation
92 * next pointer for DLL
94 struct GNUNET_TESTBED_Operation *next;
97 * prev pointer for DLL
99 struct GNUNET_TESTBED_Operation *prev;
102 * The controller on which this operation operates
104 struct GNUNET_TESTBED_Controller *controller;
107 * The ID for the operation;
109 uint64_t operation_id;
112 * The type of operation
114 enum OperationType type;
117 * Data specific to OperationType
124 * The message queue for sending messages to the controller service
129 * Structure for a controller link
131 struct ControllerLink;
135 * Enumeration of states of OperationContext
137 enum OperationContextState
140 * The initial state where the associated operation has just been created
141 * and is waiting in the operation queues to be started
146 * The operation has been started. It may occupy some resources which are to
147 * be freed if cancelled.
152 * The operation has finished. The end results of this operation may occupy
153 * some resources which are to be freed by operation_done
160 * Context information for GNUNET_TESTBED_Operation
162 struct OperationContext
167 struct OperationContext *next;
172 struct OperationContext *prev;
175 * The controller to which this operation context belongs to
177 struct GNUNET_TESTBED_Controller *c;
182 struct GNUNET_TESTBED_Operation *op;
185 * The operation closure
190 * Data relevant to the operation
195 * The id of the opearation
200 * The type of operation
202 enum OperationType type;
205 * The state of the operation
207 enum OperationContextState state;
212 * Handle to interact with a GNUnet testbed controller. Each
213 * controller has at least one master handle which is created when the
214 * controller is created; this master handle interacts with the
215 * controller process, destroying it destroys the controller (by
216 * closing stdin of the controller process). Additionally,
217 * controllers can interact with each other (in a P2P fashion); those
218 * links are established via TCP/IP on the controller's service port.
220 struct GNUNET_TESTBED_Controller
224 * The host where the controller is running
226 struct GNUNET_TESTBED_Host *host;
229 * The controller callback
231 GNUNET_TESTBED_ControllerCallback cc;
234 * The closure for controller callback
239 * The configuration to use while connecting to controller
241 struct GNUNET_CONFIGURATION_Handle *cfg;
244 * The client connection handle to the controller service
246 struct GNUNET_CLIENT_Connection *client;
249 * The head of the message queue
251 struct MessageQueue *mq_head;
254 * The tail of the message queue
256 struct MessageQueue *mq_tail;
259 * The head of the ControllerLink list
261 struct ControllerLink *cl_head;
264 * The tail of the ControllerLink list
266 struct ControllerLink *cl_tail;
269 * The client transmit handle
271 struct GNUNET_CLIENT_TransmitHandle *th;
274 * The host registration handle; NULL if no current registration requests are
277 struct GNUNET_TESTBED_HostRegistrationHandle *rh;
280 * The head of the opeartion context queue
282 struct OperationContext *ocq_head;
285 * The tail of the operation context queue
287 struct OperationContext *ocq_tail;
290 * Operation queue for simultaneous operations
292 struct OperationQueue *opq_parallel_operations;
295 * Operation queue for simultaneous service connections
297 struct OperationQueue *opq_parallel_service_connections;
300 * Operation queue for simultaneous topology configuration operations
302 struct OperationQueue *opq_parallel_topology_config_operations;
305 * The operation id counter. use current value and increment
307 uint32_t operation_counter;
310 * The controller event mask
315 * Did we start the receive loop yet?
320 * Did we create the host for this?
327 * Queues a message in send queue for sending to the service
329 * @param controller the handle to the controller
330 * @param msg the message to queue
333 GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller,
334 struct GNUNET_MessageHeader *msg);
338 * Compresses given configuration using zlib compress
340 * @param config the serialized configuration
341 * @param size the size of config
342 * @param xconfig will be set to the compressed configuration (memory is fresly
344 * @return the size of the xconfig
347 GNUNET_TESTBED_compress_config_ (const char *config, size_t size,
352 * Adds an operation to the queue of operations
354 * @param op the operation to add
357 GNUNET_TESTBED_operation_add_ (struct GNUNET_TESTBED_Operation *op);
361 * Creates a helper initialization message. Only for testing.
363 * @param cname the ip address of the controlling host
364 * @param hostname the hostname of the destination this message is intended for
365 * @param cfg the configuration that has to used to start the testbed service
367 * @return the initialization message
369 struct GNUNET_TESTBED_HelperInit *
370 GNUNET_TESTBED_create_helper_init_msg_ (const char *cname,
371 const char *hostname,
372 const struct GNUNET_CONFIGURATION_Handle
377 * Sends the given message as an operation. The given callback is called when a
378 * reply for the operation is available. Call
379 * GNUNET_TESTBED_forward_operation_msg_cancel_() to cleanup the returned
380 * operation context if the cc hasn't been called
382 * @param controller the controller to which the message has to be sent
383 * @param operation_id the operation id of the message
384 * @param msg the message to send
385 * @param cc the callback to call when reply is available
386 * @param cc_cls the closure for the above callback
387 * @return the operation context which can be used to cancel the forwarded
390 struct OperationContext *
391 GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller
392 *controller, uint64_t operation_id,
393 const struct GNUNET_MessageHeader *msg,
394 GNUNET_CLIENT_MessageHandler cc,
398 * Function to cancel an operation created by simply forwarding an operation
401 * @param opc the operation context from GNUNET_TESTBED_forward_operation_msg_()
404 GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc);
408 * Generates configuration by uncompressing configuration in given message. The
409 * given message should be of the following types:
410 * GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG,
411 * GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG
413 * @param msg the message containing compressed configuration
414 * @return handle to the parsed configuration
416 struct GNUNET_CONFIGURATION_Handle *
417 GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg);
421 * Checks the integrity of the OpeationFailureEventMessage and if good returns
422 * the error message it contains.
424 * @param msg the OperationFailureEventMessage
425 * @return the error message
428 GNUNET_TESTBED_parse_error_string_ (const struct
429 GNUNET_TESTBED_OperationFailureEventMessage
434 * Function to return the operation id for a controller. The operation id is
435 * created from the controllers host id and its internal operation counter.
437 * @param controller the handle to the controller whose operation id has to be incremented
438 * @return the incremented operation id.
441 GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller *controller);
445 * Like GNUNET_TESTBED_get_slave_config(), however without the host registration
446 * check. Another difference is that this function takes the id of the slave
449 * @param op_cls the closure for the operation
450 * @param master the handle to master controller
451 * @param slave_host_id id of the host where the slave controller is running to
452 * the slave_host should remain valid until this operation is cancelled
453 * or marked as finished
454 * @return the operation handle;
456 struct GNUNET_TESTBED_Operation *
457 GNUNET_TESTBED_get_slave_config_ (void *op_cls,
458 struct GNUNET_TESTBED_Controller *master,
459 uint32_t slave_host_id);
463 * Same as the GNUNET_TESTBED_controller_link_2, but with ids for delegated host
466 * @param op_cls the operation closure for the event which is generated to
467 * signal success or failure of this operation
468 * @param master handle to the master controller who creates the association
469 * @param delegated_host_id id of the host to which requests should be delegated
470 * @param slave_host_id id of the host which is used to run the slave controller
471 * @param sxcfg serialized and compressed configuration
472 * @param sxcfg_size the size sxcfg
473 * @param scfg_size the size of uncompressed serialized configuration
474 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
475 * be started by the slave controller; GNUNET_NO if the slave
476 * controller has to connect to the already started delegated
477 * controller via TCP/IP
478 * @return the operation handle
480 struct GNUNET_TESTBED_Operation *
481 GNUNET_TESTBED_controller_link_2_ (void *op_cls,
482 struct GNUNET_TESTBED_Controller *master,
483 uint32_t delegated_host_id,
484 uint32_t slave_host_id,
485 const char *sxcfg, size_t sxcfg_size,
486 size_t scfg_size, int is_subordinate);
490 * Same as the GNUNET_TESTBED_controller_link, but with ids for delegated host
493 * @param op_cls the operation closure for the event which is generated to
494 * signal success or failure of this operation
495 * @param master handle to the master controller who creates the association
496 * @param delegated_host_id id of the host to which requests should be
497 * delegated; cannot be NULL
498 * @param slave_host_id id of the host which should connect to controller
499 * running on delegated host ; use NULL to make the master controller
500 * connect to the delegated host
501 * @param slave_cfg configuration to use for the slave controller
502 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
503 * be started by the slave controller; GNUNET_NO if the slave
504 * controller has to connect to the already started delegated
505 * controller via TCP/IP
506 * @return the operation handle
508 struct GNUNET_TESTBED_Operation *
509 GNUNET_TESTBED_controller_link_ (void *op_cls,
510 struct GNUNET_TESTBED_Controller *master,
511 uint32_t delegated_host_id,
512 uint32_t slave_host_id,
513 const struct GNUNET_CONFIGURATION_Handle
518 /* end of testbed_api.h */