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"
32 #include "testbed_helper.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
91 * Stop and destroy all peers
98 * The message queue for sending messages to the controller service
104 * Enumeration of states of OperationContext
106 enum OperationContextState
109 * The initial state where the associated operation has just been created
110 * and is waiting in the operation queues to be started
115 * The operation has been started. It may occupy some resources which are to
116 * be freed if cancelled.
121 * The operation has finished. The end results of this operation may occupy
122 * some resources which are to be freed by operation_done
129 * Context information for GNUNET_TESTBED_Operation
131 struct OperationContext
136 struct OperationContext *next;
141 struct OperationContext *prev;
144 * The controller to which this operation context belongs to
146 struct GNUNET_TESTBED_Controller *c;
151 struct GNUNET_TESTBED_Operation *op;
154 * The operation closure
159 * Data relevant to the operation
164 * The id of the opearation
169 * The type of operation
171 enum OperationType type;
174 * The state of the operation
176 enum OperationContextState state;
181 * Handle to interact with a GNUnet testbed controller. Each
182 * controller has at least one master handle which is created when the
183 * controller is created; this master handle interacts with the
184 * controller process, destroying it destroys the controller (by
185 * closing stdin of the controller process). Additionally,
186 * controllers can interact with each other (in a P2P fashion); those
187 * links are established via TCP/IP on the controller's service port.
189 struct GNUNET_TESTBED_Controller
192 * The host where the controller is running
194 struct GNUNET_TESTBED_Host *host;
197 * The controller callback
199 GNUNET_TESTBED_ControllerCallback cc;
202 * The closure for controller callback
207 * The configuration to use while connecting to controller
209 struct GNUNET_CONFIGURATION_Handle *cfg;
212 * The client connection handle to the controller service
214 struct GNUNET_CLIENT_Connection *client;
217 * The head of the message queue
219 struct MessageQueue *mq_head;
222 * The tail of the message queue
224 struct MessageQueue *mq_tail;
227 * The client transmit handle
229 struct GNUNET_CLIENT_TransmitHandle *th;
232 * The host registration handle; NULL if no current registration requests are
235 struct GNUNET_TESTBED_HostRegistrationHandle *rh;
238 * The head of the opeartion context queue
240 struct OperationContext *ocq_head;
243 * The tail of the operation context queue
245 struct OperationContext *ocq_tail;
248 * Operation queue for simultaneous operations
250 struct OperationQueue *opq_parallel_operations;
253 * Operation queue for simultaneous service connections
255 struct OperationQueue *opq_parallel_service_connections;
258 * Operation queue for simultaneous topology configuration operations
260 struct OperationQueue *opq_parallel_topology_config_operations;
263 * The controller event mask
268 * Did we start the receive loop yet?
273 * Did we create the host for this?
278 * The operation id counter. use current value and increment
280 uint32_t operation_counter;
286 * Queues a message in send queue for sending to the service
288 * @param controller the handle to the controller
289 * @param msg the message to queue
292 GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller,
293 struct GNUNET_MessageHeader *msg);
297 * Compresses given configuration using zlib compress
299 * @param config the serialized configuration
300 * @param size the size of config
301 * @param xconfig will be set to the compressed configuration (memory is fresly
303 * @return the size of the xconfig
306 GNUNET_TESTBED_compress_config_ (const char *config, size_t size,
311 * Function to serialize and compress using zlib a configuration through a
312 * configuration handle
314 * @param cfg the configuration
315 * @param size the size of configuration when serialize. Will be set on success.
316 * @param xsize the sizeo of the compressed configuration. Will be set on success.
317 * @return the serialized and compressed configuration
320 GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg,
321 size_t *size, size_t *xsize);
325 * Adds an operation to the queue of operations
327 * @param op the operation to add
330 GNUNET_TESTBED_operation_add_ (struct GNUNET_TESTBED_Operation *op);
334 * Creates a helper initialization message. This function is here because we
335 * want to use this in testing
337 * @param trusted_ip the ip address of the controller which will be set as TRUSTED
338 * HOST(all connections form this ip are permitted by the testbed) when
339 * starting testbed controller at host. This can either be a single ip
340 * address or a network address in CIDR notation.
341 * @param hostname the hostname of the destination this message is intended for
342 * @param cfg the configuration that has to used to start the testbed service
344 * @return the initialization message
346 struct GNUNET_TESTBED_HelperInit *
347 GNUNET_TESTBED_create_helper_init_msg_ (const char *cname, const char *hostname,
348 const struct GNUNET_CONFIGURATION_Handle
353 * Sends the given message as an operation. The given callback is called when a
354 * reply for the operation is available. Call
355 * GNUNET_TESTBED_forward_operation_msg_cancel_() to cleanup the returned
356 * operation context if the cc hasn't been called
358 * @param controller the controller to which the message has to be sent
359 * @param operation_id the operation id of the message
360 * @param msg the message to send
361 * @param cc the callback to call when reply is available
362 * @param cc_cls the closure for the above callback
363 * @return the operation context which can be used to cancel the forwarded
366 struct OperationContext *
367 GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller
368 *controller, uint64_t operation_id,
369 const struct GNUNET_MessageHeader *msg,
370 GNUNET_CLIENT_MessageHandler cc,
374 * Function to cancel an operation created by simply forwarding an operation
377 * @param opc the operation context from GNUNET_TESTBED_forward_operation_msg_()
380 GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc);
384 * Generates configuration by uncompressing configuration in given message. The
385 * given message should be of the following types:
386 * GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG,
387 * GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG
389 * @param msg the message containing compressed configuration
390 * @return handle to the parsed configuration
392 struct GNUNET_CONFIGURATION_Handle *
393 GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg);
397 * Checks the integrity of the OpeationFailureEventMessage and if good returns
398 * the error message it contains.
400 * @param msg the OperationFailureEventMessage
401 * @return the error message
404 GNUNET_TESTBED_parse_error_string_ (const struct
405 GNUNET_TESTBED_OperationFailureEventMessage
410 * Function to return the operation id for a controller. The operation id is
411 * created from the controllers host id and its internal operation counter.
413 * @param controller the handle to the controller whose operation id has to be incremented
414 * @return the incremented operation id.
417 GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller *controller);
421 * Like GNUNET_TESTBED_get_slave_config(), however without the host registration
422 * check. Another difference is that this function takes the id of the slave
425 * @param op_cls the closure for the operation
426 * @param master the handle to master controller
427 * @param slave_host_id id of the host where the slave controller is running to
428 * the slave_host should remain valid until this operation is cancelled
429 * or marked as finished
430 * @return the operation handle;
432 struct GNUNET_TESTBED_Operation *
433 GNUNET_TESTBED_get_slave_config_ (void *op_cls,
434 struct GNUNET_TESTBED_Controller *master,
435 uint32_t slave_host_id);
439 * Same as the GNUNET_TESTBED_controller_link_2, but with ids for delegated host
442 * @param op_cls the operation closure for the event which is generated to
443 * signal success or failure of this operation
444 * @param master handle to the master controller who creates the association
445 * @param delegated_host_id id of the host to which requests should be delegated
446 * @param slave_host_id id of the host which is used to run the slave controller
447 * @param sxcfg serialized and compressed configuration
448 * @param sxcfg_size the size sxcfg
449 * @param scfg_size the size of uncompressed serialized configuration
450 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
451 * be started by the slave controller; GNUNET_NO if the slave
452 * controller has to connect to the already started delegated
453 * controller via TCP/IP
454 * @return the operation handle
456 struct GNUNET_TESTBED_Operation *
457 GNUNET_TESTBED_controller_link_2_ (void *op_cls,
458 struct GNUNET_TESTBED_Controller *master,
459 uint32_t delegated_host_id,
460 uint32_t slave_host_id, const char *sxcfg,
461 size_t sxcfg_size, size_t scfg_size,
466 * Same as the GNUNET_TESTBED_controller_link, but with ids for delegated host
469 * @param op_cls the operation closure for the event which is generated to
470 * signal success or failure of this operation
471 * @param master handle to the master controller who creates the association
472 * @param delegated_host_id id of the host to which requests should be
473 * delegated; cannot be NULL
474 * @param slave_host_id id of the host which should connect to controller
475 * running on delegated host ; use NULL to make the master controller
476 * connect to the delegated host
477 * @param slave_cfg configuration to use for the slave controller
478 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
479 * be started by the slave controller; GNUNET_NO if the slave
480 * controller has to connect to the already started delegated
481 * controller via TCP/IP
482 * @return the operation handle
484 struct GNUNET_TESTBED_Operation *
485 GNUNET_TESTBED_controller_link_ (void *op_cls,
486 struct GNUNET_TESTBED_Controller *master,
487 uint32_t delegated_host_id,
488 uint32_t slave_host_id,
489 const struct GNUNET_CONFIGURATION_Handle
490 *slave_cfg, int is_subordinate);
496 /* end of testbed_api.h */