-ensure labels are less than 64 chars, add test for full DNS names
[oweals/gnunet.git] / src / include / gnunet_testbed_service.h
1 /*
2       This file is part of GNUnet
3       (C) 2008, 2009, 2012 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19  */
20
21 /**
22  * @file include/gnunet_testbed_service.h
23  * @brief API for writing tests and creating large-scale
24  *        emulation testbeds for GNUnet.
25  * @author Christian Grothoff
26  */
27
28 #ifndef GNUNET_TESTBED_SERVICE_H
29 #define GNUNET_TESTBED_SERVICE_H
30
31 #include "gnunet_util_lib.h"
32 #include "gnunet_testing_lib-new.h"
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #if 0                           /* keep Emacsens' auto-indent happy */
38 }
39 #endif
40 #endif
41
42
43 /**
44  * Opaque handle to a host running experiments managed by the testbed framework.
45  * The master process must be able to SSH to this host without password (via
46  * ssh-agent).
47  */
48 struct GNUNET_TESTBED_Host;
49
50 /**
51  * Opaque handle to a peer controlled by the testbed framework.  A peer runs
52  * at a particular host.
53  */
54 struct GNUNET_TESTBED_Peer;
55
56 /**
57  * Opaque handle to an abstract operation to be executed by the testbed framework.
58  */
59 struct GNUNET_TESTBED_Operation;
60
61 /**
62  * Handle to interact with a GNUnet testbed controller.  Each
63  * controller has at least one master handle which is created when the
64  * controller is created; this master handle interacts with the
65  * controller process, destroying it destroys the controller (by
66  * closing stdin of the controller process).  Additionally,
67  * controllers can interact with each other (in a P2P fashion); those
68  * links are established via TCP/IP on the controller's service port.
69  */
70 struct GNUNET_TESTBED_Controller;
71
72 /**
73  * Handle to a large-scale testbed that is managed at a high level.
74  */
75 struct GNUNET_TESTBED_Testbed;
76
77
78 /**
79  * Create a host to run peers and controllers on.
80  *
81  * @param hostname name of the host, use "NULL" for localhost
82  * @param username username to use for the login; may be NULL
83  * @param port port number to use for ssh; use 0 to let ssh decide
84  * @return handle to the host, NULL on error
85  */
86 struct GNUNET_TESTBED_Host *
87 GNUNET_TESTBED_host_create (const char *hostname,
88                             const char *username,
89                             uint16_t port);
90
91
92
93 /**
94  * Create a host to run peers and controllers on.  This function is used
95  * if a peer learns about a host via IPC between controllers (and thus
96  * some higher-level controller has already determined the unique IDs).
97  *
98  * @param id global host ID assigned to the host; 0 is
99  *        reserved to always mean 'localhost'
100  * @param hostname name of the host, use "NULL" for localhost
101  * @param username username to use for the login; may be NULL
102  * @param port port number to use for ssh; use 0 to let ssh decide
103  * @return handle to the host, NULL on error
104  */
105 struct GNUNET_TESTBED_Host *
106 GNUNET_TESTBED_host_create_with_id (uint32_t id,
107                                     const char *hostname,
108                                     const char *username,
109                                     uint16_t port);
110
111
112 /**
113  * Load a set of hosts from a configuration file.
114  *
115  * @param filename file with the host specification
116  * @param hosts set to the hosts found in the file; caller must free this if
117  *          number of hosts returned is greater than 0
118  * @return number of hosts returned in 'hosts', 0 on error
119  */
120 unsigned int
121 GNUNET_TESTBED_hosts_load_from_file (const char *filename,
122                                      struct GNUNET_TESTBED_Host ***hosts);
123
124
125 /**
126  * Destroy a host handle.  Must only be called once everything
127  * running on that host has been stopped.
128  *
129  * @param host handle to destroy
130  */
131 void
132 GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host);
133
134
135 /**
136  * The handle for whether a host is habitable or not
137  */
138 struct GNUNET_TESTBED_HostHabitableCheckHandle;
139
140
141 /**
142  * Callbacks of this type are called by GNUNET_TESTBED_is_host_habitable to
143  * inform whether the given host is habitable or not. The Handle returned by
144  * GNUNET_TESTBED_is_host_habitable() is invalid after this callback is called
145  *
146  * @param cls the closure given to GNUNET_TESTBED_is_host_habitable()
147  * @param host the host whose status is being reported; will be NULL if the host
148  *          given to GNUNET_TESTBED_is_host_habitable() is NULL
149  * @param status GNUNET_YES if it is habitable; GNUNET_NO if not
150  */
151 typedef void (*GNUNET_TESTBED_HostHabitableCallback) (void *cls,
152                                                       const struct
153                                                       GNUNET_TESTBED_Host
154                                                       *host,
155                                                       int status);
156
157
158 /**
159  * Checks whether a host can be used to start testbed service
160  *
161  * @param host the host to check
162  * @param config the configuration handle to lookup the path of the testbed
163  *          helper
164  * @param cb the callback to call to inform about habitability of the given host
165  * @param cb_cls the closure for the callback
166  * @return NULL upon any error or a handle which can be passed to
167  *           GNUNET_TESTBED_is_host_habitable_cancel()
168  */
169 struct GNUNET_TESTBED_HostHabitableCheckHandle *
170 GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host,
171                                   const struct GNUNET_CONFIGURATION_Handle
172                                   *config,
173                                   GNUNET_TESTBED_HostHabitableCallback cb,
174                                   void *cb_cls);
175
176
177 /**
178  * Function to cancel a request started using GNUNET_TESTBED_is_host_habitable()
179  *
180  * @param struct handle the habitability check handle
181  */
182 void
183 GNUNET_TESTBED_is_host_habitable_cancel (struct
184                                          GNUNET_TESTBED_HostHabitableCheckHandle
185                                          *handle);
186
187 /**
188  * Obtain the host's hostname.
189  *
190  * @param host handle to the host, NULL means 'localhost'
191  * @return hostname of the host
192  */
193 const char *
194 GNUNET_TESTBED_host_get_hostname (const struct GNUNET_TESTBED_Host *host);
195
196
197 /**
198  * Enumeration with (at most 64) possible event types that
199  * can be monitored using the testbed framework.
200  */
201 enum GNUNET_TESTBED_EventType
202 {
203   /**
204    * A peer has been started.
205    */
206   GNUNET_TESTBED_ET_PEER_START = 0,
207
208   /**
209    * A peer has been stopped.
210    */
211   GNUNET_TESTBED_ET_PEER_STOP = 1,
212
213   /**
214    * A connection between two peers was established.
215    */
216   GNUNET_TESTBED_ET_CONNECT = 2,
217
218   /**
219    * A connection between two peers was torn down.
220    */
221   GNUNET_TESTBED_ET_DISCONNECT = 3,
222
223   /**
224    * A requested testbed operation has been completed.
225    */
226   GNUNET_TESTBED_ET_OPERATION_FINISHED = 4,
227
228   /**
229    * The 'GNUNET_TESTBED_run' operation has been completed
230    */
231   GNUNET_TESTBED_ET_TESTBED_ONLINE = 5
232
233 };
234
235
236 /**
237  * Types of information that can be requested about a peer.
238  */
239 enum GNUNET_TESTBED_PeerInformationType
240 {
241
242   /**
243    * Special value (not valid for requesting information)
244    * that is used in the event struct if a 'generic' pointer
245    * is returned (for other operations not related to this
246    * enumeration).
247    */
248   GNUNET_TESTBED_PIT_GENERIC = 0,
249
250   /**
251    * What configuration is the peer using?  Returns a 'const struct
252    * GNUNET_CONFIGURATION_Handle *'.  Valid until
253    * 'GNUNET_TESTNIG_operation_done' is called.  However, the
254    * values may be inaccurate if the peer is reconfigured in
255    * the meantime.
256    */
257   GNUNET_TESTBED_PIT_CONFIGURATION,
258
259   /**
260    * What is the identity of the peer?  Returns a
261    * 'const struct GNUNET_PeerIdentity *'.  Valid until
262    * 'GNUNET_TESTNIG_operation_done' is called.
263    */
264   GNUNET_TESTBED_PIT_IDENTITY
265
266 };
267
268
269 /**
270  * Argument to GNUNET_TESTBED_ControllerCallback with details about
271  * the event.
272  */
273 struct GNUNET_TESTBED_EventInformation
274 {
275
276   /**
277    * Type of the event.
278    */
279   enum GNUNET_TESTBED_EventType type;
280
281   /**
282    * Details about the event.
283    */
284   union
285   {
286
287     /**
288      * Details about peer start event.
289      */
290     struct
291     {
292       /**
293        * Handle for the host where the peer
294        * was started.
295        */
296       struct GNUNET_TESTBED_Host *host;
297
298       /**
299        * Handle for the peer that was started.
300        */
301       struct GNUNET_TESTBED_Peer *peer;
302
303     } peer_start;
304
305     /**
306      * Details about peer stop event.
307      */
308     struct
309     {
310
311       /**
312        * Handle for the peer that was started.
313        */
314       struct GNUNET_TESTBED_Peer *peer;
315
316     } peer_stop;
317
318     /**
319      * Details about connect event.
320      */
321     struct
322     {
323       /**
324        * Handle for one of the connected peers.
325        */
326       struct GNUNET_TESTBED_Peer *peer1;
327
328       /**
329        * Handle for one of the connected peers.
330        */
331       struct GNUNET_TESTBED_Peer *peer2;
332
333     } peer_connect;
334
335     /**
336      * Details about disconnect event.
337      */
338     struct
339     {
340       /**
341        * Handle for one of the disconnected peers.
342        */
343       struct GNUNET_TESTBED_Peer *peer1;
344
345       /**
346        * Handle for one of the disconnected peers.
347        */
348       struct GNUNET_TESTBED_Peer *peer2;
349
350     } peer_disconnect;
351
352     /**
353      * Details about an operation finished event.
354      */
355     struct
356     {
357
358       /**
359        * Handle for the operation that was finished.
360        */
361       struct GNUNET_TESTBED_Operation *operation;
362
363       /**
364        * Closure that was passed in when the event was
365        * requested.
366        */
367       void *op_cls;
368
369       /**
370        * Error message for the operation, NULL on success.
371        */
372       const char *emsg;
373
374       /**
375        * No result (NULL pointer) or generic result
376        * (whatever the GNUNET_TESTBED_ConnectAdapter returned).
377        */
378       void *generic;
379
380     } operation_finished;
381
382     /**
383      * Details about an testbed run completed event.
384      */
385     struct
386     {
387
388       /**
389        * Error message for the operation, NULL on success.
390        */
391       const char *emsg;
392
393       /**
394        * Array of peers now running (valid until
395        * 'GNUNET_TESTBED_testbed_stop' is called).  Note that it is
396        * not allowed to call 'GNUNET_TESTBED_peer_destroy' on peers
397        * from this array.
398        */
399       struct GNUNET_TESTBED_Peer **peers;
400
401       /**
402        * Size of the 'peers' array.
403        */
404       unsigned int num_peers;
405
406     } testbed_run_finished;
407
408   } details;
409
410 };
411
412
413 /**
414  * Signature of the event handler function called by the
415  * respective event controller.
416  *
417  * @param cls closure
418  * @param event information about the event
419  */
420 typedef void (*GNUNET_TESTBED_ControllerCallback)(void *cls,
421                                                   const struct GNUNET_TESTBED_EventInformation *event);
422
423
424 /**
425  * Opaque Handle for Controller process
426  */
427 struct GNUNET_TESTBED_ControllerProc;
428
429
430 /**
431  * Callback to signal successfull startup of the controller process
432  *
433  * @param cls the closure from GNUNET_TESTBED_controller_start()
434  * @param cfg the configuration with which the controller has been started;
435  *          NULL if status is not GNUNET_OK
436  * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
437  *          GNUNET_TESTBED_controller_stop() shouldn't be called in this case
438  */
439 typedef void (*GNUNET_TESTBED_ControllerStatusCallback) (void *cls,
440                                                         const struct GNUNET_CONFIGURATION_Handle *cfg,
441                                                         int status);
442
443
444 /**
445  * Starts a controller process at the host.
446  *
447  * @param controller_ip the ip address of the controller. Will be set as TRUSTED
448  *          host when starting testbed controller at host
449  * @param host the host where the controller has to be started; NULL for
450  *          localhost
451  * @param cfg template configuration to use for the remote controller; the
452  *          remote controller will be started with a slightly modified
453  *          configuration (port numbers, unix domain sockets and service home
454  *          values are changed as per TESTING library on the remote host)
455  * @param cb function called when the controller is successfully started or
456  *          dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be
457  *          called if cb is called with GNUNET_SYSERR as status. Will never be
458  *          called in the same task as 'GNUNET_TESTBED_controller_start'
459  *          (synchronous errors will be signalled by returning NULL). This
460  *          parameter cannot be NULL.
461  * @param cls closure for above callbacks
462  * @return the controller process handle, NULL on errors
463  */
464 struct GNUNET_TESTBED_ControllerProc *
465 GNUNET_TESTBED_controller_start (const char *controller_ip,
466                                  struct GNUNET_TESTBED_Host *host,
467                                  const struct GNUNET_CONFIGURATION_Handle *cfg,
468                                  GNUNET_TESTBED_ControllerStatusCallback cb,
469                                  void *cls);
470
471
472 /**
473  * Stop the controller process (also will terminate all peers and controllers
474  * dependent on this controller).  This function blocks until the testbed has
475  * been fully terminated (!). The controller status cb from
476  * GNUNET_TESTBED_controller_start() will not be called.
477  *
478  * @param cproc the controller process handle
479  */
480 void
481 GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc);
482
483
484 /**
485  * Connect to a controller process using the given configuration at the
486  * given host.
487  *
488  * @param cfg configuration to use
489  * @param host host to run the controller on; This should be the same host if
490  *          the controller was previously started with
491  *          GNUNET_TESTBED_controller_start; NULL for localhost
492  * @param host host where this controller is being run;
493  * @param event_mask bit mask with set of events to call 'cc' for;
494  *                   or-ed values of "1LL" shifted by the
495  *                   respective 'enum GNUNET_TESTBED_EventType'
496  *                   (i.e.  "(1LL << GNUNET_TESTBED_ET_CONNECT) | ...")
497  * @param cc controller callback to invoke on events
498  * @param cc_cls closure for cc
499  * @return handle to the controller
500  */
501 struct GNUNET_TESTBED_Controller *
502 GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
503                                    struct GNUNET_TESTBED_Host *host,
504                                    uint64_t event_mask,
505                                    GNUNET_TESTBED_ControllerCallback cc,
506                                    void *cc_cls);
507
508
509 /**
510  * Configure shared services at a controller.  Using this function,
511  * you can specify that certain services (such as "resolver")
512  * should not be run for each peer but instead be shared
513  * across N peers on the specified host.  This function
514  * must be called before any peers are created at the host.
515  *
516  * @param controller controller to configure
517  * @param service_name name of the service to share
518  * @param num_peers number of peers that should share one instance
519  *        of the specified service (1 for no sharing is the default),
520  *        use 0 to disable the service
521  */
522 void
523 GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller *controller,
524                                              const char *service_name,
525                                              uint32_t num_peers);
526
527
528 /**
529  * Stop the given controller (also will terminate all peers and
530  * controllers dependent on this controller).  This function
531  * blocks until the testbed has been fully terminated (!).
532  *
533  * @param controller handle to controller to stop
534  */
535 void
536 GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *controller);
537
538
539 /**
540  * Opaque handle for host registration
541  */
542 struct GNUNET_TESTBED_HostRegistrationHandle;
543
544
545 /**
546  * Callback which will be called to after a host registration succeeded or failed
547  *
548  * @param cls the closure
549  * @param emsg the error message; NULL if host registration is successful
550  */
551 typedef void (* GNUNET_TESTBED_HostRegistrationCompletion) (void *cls,
552                                                             const char *emsg);
553
554
555 /**
556  * Register a host with the controller
557  *
558  * @param controller the controller handle
559  * @param host the host to register
560  * @param cc the completion callback to call to inform the status of
561  *          registration. After calling this callback the registration handle
562  *          will be invalid. Cannot be NULL
563  * @param cc_cls the closure for the cc
564  * @return handle to the host registration which can be used to cancel the
565  *           registration; NULL if another registration handle is present and
566  *           is not cancelled
567  */
568 struct GNUNET_TESTBED_HostRegistrationHandle *
569 GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
570                               struct GNUNET_TESTBED_Host *host,
571                               GNUNET_TESTBED_HostRegistrationCompletion cc,
572                               void *cc_cls);
573
574
575 /**
576  * Cancel the pending registration. Note that the registration message will
577  * already be queued to be sent to the service, cancellation has only the
578  * effect that the registration completion callback for the registration is
579  * never called and from our perspective the host is not registered until the
580  * completion callback is called.
581  *
582  * @param handle the registration handle to cancel
583  */
584 void
585 GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
586                                     *handle);
587
588
589 /**
590  * Callback to be called when an operation is completed
591  *
592  * @param cls the callback closure from functions generating an operation
593  * @param op the operation that has been finished
594  * @param emsg error message in case the operation has failed; will be NULL if
595  *          operation has executed successfully.
596  */
597 typedef void (*GNUNET_TESTBED_OperationCompletionCallback) (void *cls,
598                                                             struct
599                                                             GNUNET_TESTBED_Operation
600                                                             *op,
601                                                             const char *emsg);
602
603
604 /**
605  * Create a link from slave controller to delegated controller. Whenever the
606  * master controller is asked to start a peer at the delegated controller the
607  * request will be routed towards slave controller (if a route exists). The
608  * slave controller will then route it to the delegated controller. The
609  * configuration of the delegated controller is given and is used to either
610  * create the delegated controller or to connect to an existing controller. Note
611  * that while starting the delegated controller the configuration will be
612  * modified to accommodate available free ports.  the 'is_subordinate' specifies
613  * if the given delegated controller should be started and managed by the slave
614  * controller, or if the delegated controller already has a master and the slave
615  * controller connects to it as a non master controller. The success or failure
616  * of this operation will be signalled through the
617  * GNUNET_TESTBED_ControllerCallback() with an event of type
618  * GNUNET_TESTBED_ET_OPERATION_FINISHED
619  *
620  * @param op_cls the operation closure for the event which is generated to
621  *          signal success or failure of this operation
622  * @param master handle to the master controller who creates the association
623  * @param delegated_host requests to which host should be delegated; cannot be NULL
624  * @param slave_host which host is used to run the slave controller; use NULL to
625  *          make the master controller connect to the delegated host
626  * @param slave_cfg configuration to use for the slave controller
627  * @param is_subordinate GNUNET_YES if the controller at delegated_host should
628  *          be started by the slave controller; GNUNET_NO if the slave
629  *          controller has to connect to the already started delegated
630  *          controller via TCP/IP
631  * @return the operation handle
632  */
633 struct GNUNET_TESTBED_Operation *
634 GNUNET_TESTBED_controller_link (void *op_cls,
635                                 struct GNUNET_TESTBED_Controller *master,
636                                 struct GNUNET_TESTBED_Host *delegated_host,
637                                 struct GNUNET_TESTBED_Host *slave_host,
638                                 const struct GNUNET_CONFIGURATION_Handle
639                                 *slave_cfg,
640                                 int is_subordinate);
641
642
643 /**
644  * Same as the GNUNET_TESTBED_controller_link, however expects configuration in
645  * serialized and compressed
646  *
647  * @param op_cls the operation closure for the event which is generated to
648  *          signal success or failure of this operation
649  * @param master handle to the master controller who creates the association
650  * @param delegated_host requests to which host should be delegated; cannot be NULL
651  * @param slave_host which host is used to run the slave controller; use NULL to
652  *          make the master controller connect to the delegated host
653  * @param sxcfg serialized and compressed configuration
654  * @param sxcfg_size the size sxcfg
655  * @param scfg_size the size of uncompressed serialized configuration
656  * @param is_subordinate GNUNET_YES if the controller at delegated_host should
657  *          be started by the slave controller; GNUNET_NO if the slave
658  *          controller has to connect to the already started delegated
659  *          controller via TCP/IP
660  * @return the operation handle
661  */
662 struct GNUNET_TESTBED_Operation *
663 GNUNET_TESTBED_controller_link_2 (void *op_cls,
664                                   struct GNUNET_TESTBED_Controller *master,
665                                   struct GNUNET_TESTBED_Host *delegated_host,
666                                   struct GNUNET_TESTBED_Host *slave_host,
667                                   const char *sxcfg,
668                                   size_t sxcfg_size,
669                                   size_t scfg_size,
670                                   int is_subordinate);
671
672
673 /**
674  * Function to acquire the configuration of a running slave controller. The
675  * completion of the operation is signalled through the controller_cb from
676  * GNUNET_TESTBED_controller_connect(). If the operation is successful the
677  * handle to the configuration is available in the generic pointer of
678  * operation_finished field of struct GNUNET_TESTBED_EventInformation.
679  *
680  * @param op_cls the closure for the operation
681  * @param master the handle to master controller
682  * @param slave_host the host where the slave controller is running; the handle
683  *          to the slave_host should remain valid until this operation is
684  *          cancelled or marked as finished
685  * @return the operation handle; NULL if the slave_host is not registered at
686  *           master
687  */
688 struct GNUNET_TESTBED_Operation *
689 GNUNET_TESTBED_get_slave_config (void *op_cls,
690                                  struct GNUNET_TESTBED_Controller *master,
691                                  struct GNUNET_TESTBED_Host *slave_host);
692
693
694 /**
695  * Functions of this signature are called when a peer has been successfully
696  * created
697  *
698  * @param cls the closure from GNUNET_TESTBED_peer_create()
699  * @param peer the handle for the created peer; NULL on any error during
700  *          creation
701  * @param emsg NULL if peer is not NULL; else MAY contain the error description
702  */
703 typedef void (*GNUNET_TESTBED_PeerCreateCallback) (void *cls,
704                                                    struct GNUNET_TESTBED_Peer *peer,
705                                                    const char *emsg);
706
707
708 /**
709  * Create the given peer at the specified host using the given
710  * controller.  If the given controller is not running on the target
711  * host, it should find or create a controller at the target host and
712  * delegate creating the peer.  Explicit delegation paths can be setup
713  * using 'GNUNET_TESTBED_controller_link'.  If no explicit delegation
714  * path exists, a direct link with a subordinate controller is setup
715  * for the first delegated peer to a particular host; the subordinate
716  * controller is then destroyed once the last peer that was delegated
717  * to the remote host is stopped.
718  *
719  * Creating the peer only creates the handle to manipulate and further
720  * configure the peer; use "GNUNET_TESTBED_peer_start" and
721  * "GNUNET_TESTBED_peer_stop" to actually start/stop the peer's
722  * processes.
723  *
724  * Note that the given configuration will be adjusted by the
725  * controller to avoid port/path conflicts with other peers.
726  * The "final" configuration can be obtained using
727  * 'GNUNET_TESTBED_peer_get_information'.
728  *
729  * @param controller controller process to use
730  * @param host host to run the peer on
731  * @param cfg Template configuration to use for the peer. Should exist until
732  *          operation is cancelled or GNUNET_TESTBED_operation_done() is called
733  * @param cb the callback to call when the peer has been created
734  * @param cls the closure to the above callback
735  * @return the operation handle
736  */
737 struct GNUNET_TESTBED_Operation *
738 GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
739                             struct GNUNET_TESTBED_Host *host,
740                             const struct GNUNET_CONFIGURATION_Handle *cfg,
741                             GNUNET_TESTBED_PeerCreateCallback cb,
742                             void *cls);
743
744
745 /**
746  * Functions of this signature are called when a peer has been successfully
747  * started or stopped.
748  *
749  * @param cls the closure from GNUNET_TESTBED_peer_start/stop()
750  * @param emsg NULL on success; otherwise an error description
751  */
752 typedef void (*GNUNET_TESTBED_PeerChurnCallback) (void *cls,
753                                                   const char *emsg);
754
755
756 /**
757  * Start the given peer.
758  *
759  * @param op_cls the closure for this operation; will be set in
760  *          event->details.operation_finished.op_cls when this operation fails.
761  * @param peer peer to start
762  * @param pcc function to call upon completion
763  * @param pcc_cls closure for 'pcc'
764  * @return handle to the operation
765  */
766 struct GNUNET_TESTBED_Operation *
767 GNUNET_TESTBED_peer_start (void *op_cls,
768                            struct GNUNET_TESTBED_Peer *peer,
769                            GNUNET_TESTBED_PeerChurnCallback pcc,
770                            void *pcc_cls);
771
772
773 /**
774  * Stop the given peer.  The handle remains valid (use
775  * "GNUNET_TESTBED_peer_destroy" to fully clean up the
776  * state of the peer).
777  *
778  * @param peer peer to stop
779  * @param pcc function to call upon completion
780  * @param pcc_cls closure for 'pcc'
781  * @return handle to the operation
782  */
783 struct GNUNET_TESTBED_Operation *
784 GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer,
785                           GNUNET_TESTBED_PeerChurnCallback pcc,
786                           void *pcc_cls);
787
788
789 /**
790  * Data returned from GNUNET_TESTBED_peer_get_information
791  */
792 struct GNUNET_TESTBED_PeerInformation
793 {
794   /**
795    * Peer information type; captures which of the types
796    * in the 'op_result' is actually in use.
797    */
798   enum GNUNET_TESTBED_PeerInformationType pit;
799
800   /**
801    * The result of the get information operation; Choose according to the pit
802    */
803   union
804   {
805     /**
806      * The configuration of the peer
807      */
808     struct GNUNET_CONFIGURATION_Handle *cfg;
809
810     /**
811      * The identity of the peer
812      */
813     struct GNUNET_PeerIdentity *id;
814   } result;
815 };
816
817
818 /**
819  * Callback to be called when the requested peer information is available
820  *
821  * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
822  * @param op the operation this callback corresponds to
823  * @param pinfo the result; will be NULL if the operation has failed
824  * @param emsg error message if the operation has failed; will be NULL if the
825  *          operation is successfull
826  */
827 typedef void (*GNUNET_TESTBED_PeerInfoCallback) (void *cb_cls,
828                                                  struct GNUNET_TESTBED_Operation
829                                                  *op,
830                                                  const struct
831                                                  GNUNET_TESTBED_PeerInformation
832                                                  *pinfo,
833                                                  const char *emsg);
834
835
836 /**
837  * Request information about a peer. The controller callback will not be called
838  * with event type GNUNET_TESTBED_ET_OPERATION_FINISHED when result for this
839  * operation is available. Instead, the GNUNET_TESTBED_PeerInfoCallback() will
840  * be called.
841  *
842  * @param peer peer to request information about
843  * @param pit desired information
844  * @param cb the convenience callback to be called when results for this
845  *          operation are available
846  * @param cb_cls the closure for the above callback
847  * @return handle to the operation
848  */
849 struct GNUNET_TESTBED_Operation *
850 GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
851                                      enum GNUNET_TESTBED_PeerInformationType
852                                      pit,
853                                      GNUNET_TESTBED_PeerInfoCallback cb,
854                                      void *cb_cls);
855
856
857 /**
858  * Change peer configuration.  Must only be called while the
859  * peer is stopped.  Ports and paths cannot be changed this
860  * way.
861  *
862  * @param peer peer to change configuration for
863  * @param cfg new configuration (differences to existing
864  *            configuration only)
865  * @return handle to the operation
866  */
867 struct GNUNET_TESTBED_Operation *
868 GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
869                                           const struct GNUNET_CONFIGURATION_Handle *cfg);
870
871
872 /**
873  * Destroy the given peer; the peer should have been
874  * stopped first (if it was started).
875  *
876  * @param peer peer to stop
877  * @return handle to the operation
878  */
879 struct GNUNET_TESTBED_Operation *
880 GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer);
881
882
883 /**
884  * Options for peer connections.
885  */
886 enum GNUNET_TESTBED_ConnectOption
887 {
888   /**
889    * No option (not valid as an argument).
890    */
891   GNUNET_TESTBED_CO_NONE = 0,
892
893   /**
894    * Allow or disallow a connection between the specified peers.
895    * Followed by GNUNET_NO (int) if a connection is disallowed
896    * or GNUNET_YES if a connection is allowed.  Note that the
897    * default (all connections allowed or disallowed) is
898    * specified in the configuration of the controller.
899    */
900   GNUNET_TESTBED_CO_ALLOW = 1,
901
902   /**
903    * FIXME: add (and implement) options to limit connection to
904    * particular transports, force simulation of particular latencies
905    * or message loss rates, or set bandwidth limitations.
906    */
907
908 };
909
910
911 /**
912  * Manipulate the P2P underlay topology by configuring a link
913  * between two peers.
914  *
915  * @param op_cls closure argument to give with the operation event
916  * @param p1 first peer
917  * @param p2 second peer
918  * @param co option to change
919  * @param ap option-specific values
920  * @return handle to the operation, NULL if configuring the link at this
921  *         time is not allowed
922  */
923 struct GNUNET_TESTBED_Operation *
924 GNUNET_TESTBED_underlay_configure_link_va (void *op_cls,
925                                            struct GNUNET_TESTBED_Peer *p1,
926                                            struct GNUNET_TESTBED_Peer *p2,
927                                            enum GNUNET_TESTBED_ConnectOption co,
928                                            va_list ap);
929
930
931 /**
932  * Manipulate the P2P underlay topology by configuring a link
933  * between two peers.
934  *
935  * @param op_cls closure argument to give with the operation event
936  * @param p1 first peer
937  * @param p2 second peer
938  * @param co option to change
939  * @param ... option-specific values
940  * @return handle to the operation, NULL if configuring the link at this
941  *         time is not allowed
942  */
943 struct GNUNET_TESTBED_Operation *
944 GNUNET_TESTBED_underlay_configure_link (void *op_cls,
945                                         struct GNUNET_TESTBED_Peer *p1,
946                                         struct GNUNET_TESTBED_Peer *p2,
947                                         enum GNUNET_TESTBED_ConnectOption co, ...);
948
949
950
951 /**
952  * Topologies and topology options supported for testbeds. Options should always
953  * end with GNUNET_TESTBED_TOPOLOGY_OPTION_END
954  */
955 enum GNUNET_TESTBED_TopologyOption
956 {
957   /**
958    * A clique (everyone connected to everyone else).  No options. If there are N
959    * peers this topology results in (N * (N -1)) connections.
960    */
961   GNUNET_TESTBED_TOPOLOGY_CLIQUE,
962
963   /**
964    * Small-world network (2d torus plus random links).  Followed
965    * by the number of random links to add (unsigned int).
966    */
967   GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD,
968
969   /**
970    * Small-world network (ring plus random links).  Followed
971    * by the number of random links to add (unsigned int).
972    */
973   GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING,
974
975   /**
976    * Ring topology.  No options.
977    */
978   GNUNET_TESTBED_TOPOLOGY_RING,
979
980   /**
981    * 2-d torus.  No options.
982    */
983   GNUNET_TESTBED_TOPOLOGY_2D_TORUS,
984
985   /**
986    * Random graph.  Followed by the number of random links to be established
987    * (unsigned int)
988    */
989   GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
990
991   /**
992    * Certain percentage of peers are unable to communicate directly
993    * replicating NAT conditions.  Followed by the fraction of
994    * NAT'ed peers (float).
995    */
996   GNUNET_TESTBED_TOPOLOGY_INTERNAT,
997
998   /**
999    * Scale free topology.   FIXME: options?
1000    */
1001   GNUNET_TESTBED_TOPOLOGY_SCALE_FREE,
1002
1003   /**
1004    * Straight line topology.  No options.
1005    */
1006   GNUNET_TESTBED_TOPOLOGY_LINE,
1007
1008   /**
1009    * Read a topology from a given file.  Followed by the name of the file (const char *).
1010    */
1011   GNUNET_TESTBED_TOPOLOGY_FROM_FILE,
1012
1013   /**
1014    * All peers are disconnected.  No options.
1015    */
1016   GNUNET_TESTBED_TOPOLOGY_NONE,
1017
1018   /**
1019    * The options should always end with this
1020    */
1021   GNUNET_TESTBED_TOPOLOGY_OPTION_END,
1022
1023   /* The following are not topologies but influence how the topology has to be
1024      setup. These options should follow the topology specific options (if
1025      required by the chosen topology). Note that these should be given before
1026      GNUNET_TESTBED_TOPOLOGY_OPTION_END */
1027
1028   /**
1029    * Disable automatic retrying for failed overlay connections. The default is
1030    * to always retry failed overlay connections. This parameter takes no options.
1031    */
1032   GNUNET_TESTBED_TOPOLOGY_DISABLE_AUTO_RETRY
1033 };
1034
1035
1036 /**
1037  * Configure overall network topology to have a particular shape.
1038  *
1039  * @param op_cls closure argument to give with the operation event
1040  * @param num_peers number of peers in 'peers'
1041  * @param peers array of 'num_peers' with the peers to configure
1042  * @param topo desired underlay topology to use
1043  * @param ap topology-specific options
1044  * @return handle to the operation, NULL if configuring the topology
1045  *         is not allowed at this time
1046  */
1047 struct GNUNET_TESTBED_Operation *
1048 GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls,
1049                                                unsigned int num_peers,
1050                                                struct GNUNET_TESTBED_Peer **peers,
1051                                                enum GNUNET_TESTBED_TopologyOption topo,
1052                                                va_list ap);
1053
1054
1055 /**
1056  * Configure overall network topology to have a particular shape.
1057  *
1058  * @param op_cls closure argument to give with the operation event
1059  * @param num_peers number of peers in 'peers'
1060  * @param peers array of 'num_peers' with the peers to configure
1061  * @param topo desired underlay topology to use
1062  * @param ... topology-specific options
1063  * @return handle to the operation, NULL if configuring the topology
1064  *         is not allowed at this time
1065  */
1066 struct GNUNET_TESTBED_Operation *
1067 GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
1068                                             unsigned int num_peers,
1069                                             struct GNUNET_TESTBED_Peer **peers,
1070                                             enum GNUNET_TESTBED_TopologyOption topo,
1071                                             ...);
1072
1073
1074 /**
1075  * Both peers must have been started before calling this function.
1076  * This function then obtains a HELLO from 'p1', gives it to 'p2'
1077  * and asks 'p2' to connect to 'p1'.
1078  *
1079  * @param op_cls closure argument to give with the operation event
1080  * @param cb the callback to call when this operation has finished
1081  * @param cb_cls the closure for the above callback
1082  * @param p1 first peer
1083  * @param p2 second peer
1084  * @return handle to the operation, NULL if connecting these two
1085  *         peers is fundamentally not possible at this time (peers
1086  *         not running or underlay disallows)
1087  */
1088 struct GNUNET_TESTBED_Operation *
1089 GNUNET_TESTBED_overlay_connect (void *op_cls,
1090                                 GNUNET_TESTBED_OperationCompletionCallback cb,
1091                                 void *cb_cls,
1092                                 struct GNUNET_TESTBED_Peer *p1,
1093                                 struct GNUNET_TESTBED_Peer *p2);
1094
1095
1096 /**
1097  * All peers must have been started before calling this function.
1098  * This function then connects the given peers in the P2P overlay
1099  * using the given topology.
1100  *
1101  * @param op_cls closure argument to give with the operation event
1102  * @param num_peers number of peers in 'peers'
1103  * @param peers array of 'num_peers' with the peers to configure
1104  * @param max_connections the maximums number of overlay connections that will
1105  *          be made to achieve the given topology
1106  * @param topo desired underlay topology to use
1107  * @param va topology-specific options
1108  * @return handle to the operation, NULL if connecting these
1109  *         peers is fundamentally not possible at this time (peers
1110  *         not running or underlay disallows) or if num_peers is less than 2
1111  */
1112 struct GNUNET_TESTBED_Operation *
1113 GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
1114                                               unsigned int num_peers,
1115                                               struct GNUNET_TESTBED_Peer **peers,
1116                                               unsigned int *max_connections,
1117                                               enum GNUNET_TESTBED_TopologyOption topo,
1118                                               va_list va);
1119
1120
1121 /**
1122  * All peers must have been started before calling this function.
1123  * This function then connects the given peers in the P2P overlay
1124  * using the given topology.
1125  *
1126  * @param op_cls closure argument to give with the operation event
1127  * @param num_peers number of peers in 'peers'
1128  * @param peers array of 'num_peers' with the peers to configure
1129  * @param max_connections the maximums number of overlay connections that will
1130  *          be made to achieve the given topology
1131  * @param topo desired underlay topology to use
1132  * @param ... topology-specific options
1133  * @return handle to the operation, NULL if connecting these
1134  *         peers is fundamentally not possible at this time (peers
1135  *         not running or underlay disallows) or if num_peers is less than 2
1136  */
1137 struct GNUNET_TESTBED_Operation *
1138 GNUNET_TESTBED_overlay_configure_topology (void *op_cls,
1139                                            unsigned int num_peers,
1140                                            struct GNUNET_TESTBED_Peer **peers,
1141                                            unsigned int *max_connections,
1142                                            enum GNUNET_TESTBED_TopologyOption topo,
1143                                            ...);
1144
1145
1146 /**
1147  * Ask the testbed controller to write the current overlay topology to
1148  * a file.  Naturally, the file will only contain a snapshot as the
1149  * topology may evolve all the time.
1150  * FIXME: needs continuation!?
1151  *
1152  * @param controller overlay controller to inspect
1153  * @param filename name of the file the topology should
1154  *        be written to.
1155  */
1156 void
1157 GNUNET_TESTBED_overlay_write_topology_to_file (struct GNUNET_TESTBED_Controller *controller,
1158                                                const char *filename);
1159
1160
1161 /**
1162  * Adapter function called to establish a connection to
1163  * a service.
1164  *
1165  * @param cls closure
1166  * @param cfg configuration of the peer to connect to; will be available until
1167  *          GNUNET_TESTBED_operation_done() is called on the operation returned
1168  *          from GNUNET_TESTBED_service_connect()
1169  * @return service handle to return in 'op_result', NULL on error
1170  */
1171 typedef void * (*GNUNET_TESTBED_ConnectAdapter)(void *cls,
1172                                                 const struct GNUNET_CONFIGURATION_Handle *cfg);
1173
1174
1175 /**
1176  * Adapter function called to destroy a connection to
1177  * a service.
1178  *
1179  * @param cls closure
1180  * @param op_result service handle returned from the connect adapter
1181  */
1182 typedef void (*GNUNET_TESTBED_DisconnectAdapter)(void *cls,
1183                                                  void *op_result);
1184
1185
1186 /**
1187  * Callback to be called when a service connect operation is completed
1188  *
1189  * @param cls the callback closure from functions generating an operation
1190  * @param op the operation that has been finished
1191  * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
1192  * @param emsg error message in case the operation has failed; will be NULL if
1193  *          operation has executed successfully.
1194  */
1195 typedef void (*GNUNET_TESTBED_ServiceConnectCompletionCallback) (void *cls,
1196                                                                  struct
1197                                                                  GNUNET_TESTBED_Operation
1198                                                                  *op,
1199                                                                  void
1200                                                                  *ca_result,
1201                                                                  const char
1202                                                                  *emsg );
1203
1204
1205 /**
1206  * Connect to a service offered by the given peer.  Will ensure that
1207  * the request is queued to not overwhelm our ability to create and
1208  * maintain connections with other systems.  The actual service
1209  * handle is then returned via the 'op_result' member in the event
1210  * callback.  The 'ca' callback is used to create the connection
1211  * when the time is right; the 'da' callback will be used to
1212  * destroy the connection (upon 'GNUNET_TESTBED_operation_done').
1213  * 'GNUNET_TESTBED_operation_cancel' can be used to abort this
1214  * operation until the event callback has been called.
1215  *
1216  * @param op_cls closure to pass in operation event
1217  * @param peer peer that runs the service
1218  * @param service_name name of the service to connect to
1219  * @param cb the callback to call when this operation finishes
1220  * @param cb_cls closure for the above callback
1221  * @param ca helper function to establish the connection
1222  * @param da helper function to close the connection
1223  * @param cada_cls closure for ca and da
1224  * @return handle for the operation
1225  */
1226 struct GNUNET_TESTBED_Operation *
1227 GNUNET_TESTBED_service_connect (void *op_cls,
1228                                 struct GNUNET_TESTBED_Peer *peer,
1229                                 const char *service_name,
1230                                 GNUNET_TESTBED_ServiceConnectCompletionCallback cb,
1231                                 void *cb_cls,
1232                                 GNUNET_TESTBED_ConnectAdapter ca,
1233                                 GNUNET_TESTBED_DisconnectAdapter da,
1234                                 void *cada_cls);
1235
1236
1237 /**
1238  * This function is used to signal that the event information (struct
1239  * GNUNET_TESTBED_EventInformation) from an operation has been fully processed
1240  * i.e. if the event callback is ever called for this operation. If the event
1241  * callback for this operation has not yet been called, calling this function
1242  * cancels the operation, frees its resources and ensures the no event is
1243  * generated with respect to this operation. Note that however cancelling an
1244  * operation does NOT guarantee that the operation will be fully undone (or that
1245  * nothing ever happened). 
1246  *
1247  * This function MUST be called for every operation to fully remove the
1248  * operation from the operation queue.  After calling this function, if
1249  * operation is completed and its event information is of type
1250  * GNUNET_TESTBED_ET_OPERATION_FINISHED, the 'op_result' becomes invalid (!).
1251
1252  * If the operation is generated from GNUNET_TESTBED_service_connect() then
1253  * calling this function on such as operation calls the disconnect adapter if
1254  * the connect adapter was ever called.
1255  *
1256  * @param operation operation to signal completion or cancellation
1257  */
1258 void
1259 GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation);
1260
1261
1262 /**
1263  * Configure and run a testbed using the given
1264  * master controller on 'num_hosts' starting
1265  * 'num_peers' using the given peer configuration.
1266  *
1267  * @param controller master controller for the testbed
1268  *                   (must not be destroyed until after the
1269  *                    testbed is destroyed).
1270  * @param num_hosts number of hosts in 'hosts', 0 to only
1271  *        use 'localhost'
1272  * @param hosts list of hosts to use for the testbed
1273  * @param num_peers number of peers to start
1274  * @param cfg the configuration to use as a template for peers and also for
1275  *         checking the value of testbed helper binary
1276  * @param underlay_topology underlay topology to create
1277  * @param va topology-specific options
1278  * @return handle to the testbed
1279  */
1280 struct GNUNET_TESTBED_Testbed *
1281 GNUNET_TESTBED_create_va (struct GNUNET_TESTBED_Controller *controller,
1282                           unsigned int num_hosts,
1283                           struct GNUNET_TESTBED_Host **hosts,
1284                           unsigned int num_peers,
1285                           const struct GNUNET_CONFIGURATION_Handle *cfg,
1286                           enum GNUNET_TESTBED_TopologyOption underlay_topology,
1287                           va_list va);
1288
1289
1290 /**
1291  * Configure and run a testbed using the given
1292  * master controller on 'num_hosts' starting
1293  * 'num_peers' using the given peer configuration.
1294  *
1295  * @param controller master controller for the testbed
1296  *                   (must not be destroyed until after the
1297  *                    testbed is destroyed).
1298  * @param num_hosts number of hosts in 'hosts', 0 to only
1299  *        use 'localhost'
1300  * @param hosts list of hosts to use for the testbed
1301  * @param num_peers number of peers to start
1302  * @param cfg the configuration to use as a template for peers and also for
1303  *         checking the value of testbed helper binary
1304  * @param underlay_topology underlay topology to create
1305  * @param ... topology-specific options
1306  */
1307 struct GNUNET_TESTBED_Testbed *
1308 GNUNET_TESTBED_create (struct GNUNET_TESTBED_Controller *controller,
1309                        unsigned int num_hosts,
1310                        struct GNUNET_TESTBED_Host **hosts,
1311                        unsigned int num_peers,
1312                        const struct GNUNET_CONFIGURATION_Handle *cfg,
1313                        enum GNUNET_TESTBED_TopologyOption underlay_topology,
1314                        ...);
1315
1316
1317 /**
1318  * Destroy a testbed.  Stops all running peers and then
1319  * destroys all peers.  Does NOT destroy the master controller.
1320  *
1321  * @param testbed testbed to destroy
1322  */
1323 void
1324 GNUNET_TESTBED_destroy (struct GNUNET_TESTBED_Testbed *testbed);
1325
1326
1327 /**
1328  * Callback function to process statistic values from all peers.
1329  *
1330  * @param cls closure
1331  * @param peer the peer the statistic belong to
1332  * @param subsystem name of subsystem that created the statistic
1333  * @param name the name of the datum
1334  * @param value the current value
1335  * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
1336  * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
1337  */
1338 typedef int (*GNUNET_TESTBED_StatisticsIterator) (void *cls,
1339                                                   const struct GNUNET_TESTBED_Peer *peer,
1340                                                   const char *subsystem,
1341                                                   const char *name,
1342                                                   uint64_t value,
1343                                                   int is_persistent);
1344
1345
1346 /**
1347  * Convenience method that iterates over all (running) peers
1348  * and retrieves all statistics from each peer.
1349  *
1350  * @param num_peers number of peers to iterate over
1351  * @param peers array of peers to iterate over
1352  * @param proc processing function for each statistic retrieved
1353  * @param cont continuation to call once call is completed(?)
1354  * @param cls closure to pass to proc and cont
1355  * @return operation handle to cancel the operation
1356  */
1357 struct GNUNET_TESTBED_Operation *
1358 GNUNET_TESTBED_get_statistics (unsigned int num_peers,
1359                                struct GNUNET_TESTBED_Peer **peers,
1360                                GNUNET_TESTBED_StatisticsIterator proc,
1361                                GNUNET_TESTBED_OperationCompletionCallback cont,
1362                                void *cls);
1363
1364
1365 /**
1366  * Convenience method for running a testbed with
1367  * a single call.  Underlay and overlay topology
1368  * are configured using the "UNDERLAY" and "OVERLAY"
1369  * options in the "[testbed]" section of the configuration\
1370  * (with possible options given in "UNDERLAY_XXX" and/or
1371  * "OVERLAY_XXX").
1372  *
1373  * The testbed is to be terminated using a call to
1374  * "GNUNET_SCHEDULER_shutdown".
1375  *
1376  * @param host_filename name of the file with the 'hosts', NULL
1377  *        to run everything on 'localhost'
1378  * @param cfg configuration to use (for testbed, controller and peers)
1379  * @param num_peers number of peers to start; FIXME: maybe put that ALSO into
1380  *        cfg?; should be greater than 0
1381  * @param event_mask bit mask with set of events to call 'cc' for;
1382  *                   or-ed values of "1LL" shifted by the
1383  *                   respective 'enum GNUNET_TESTBED_EventType'
1384  *                   (i.e.  "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1385  * @param cc controller callback to invoke on events; This callback is called
1386  *        for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
1387  *        set in the event_mask as this is the only way get access to the
1388  *        handle of each peer
1389  * @param cc_cls closure for cc
1390  * @param master task to run once the testbed is ready
1391  * @param master_cls closure for 'task'.
1392  */
1393 void
1394 GNUNET_TESTBED_run (const char *host_filename,
1395                     const struct GNUNET_CONFIGURATION_Handle *cfg,
1396                     unsigned int num_peers,
1397                     uint64_t event_mask,
1398                     GNUNET_TESTBED_ControllerCallback cc,
1399                     void *cc_cls,
1400                     GNUNET_SCHEDULER_Task master,
1401                     void *master_cls);
1402
1403
1404 /**
1405  * Signature of a main function for a testcase.
1406  *
1407  * @param cls closure
1408  * @param num_peers number of peers in 'peers'
1409  * @param peers handle to peers run in the testbed
1410  */
1411 typedef void (*GNUNET_TESTBED_TestMaster)(void *cls,
1412                                           unsigned int num_peers,
1413                                           struct GNUNET_TESTBED_Peer **peers);
1414
1415
1416 /**
1417  * Convenience method for running a "simple" test on the local system
1418  * with a single call from 'main'.  Underlay and overlay topology are
1419  * configured using the "UNDERLAY" and "OVERLAY" options in the
1420  * "[testbed]" section of the configuration (with possible options
1421  * given in "UNDERLAY_XXX" and/or "OVERLAY_XXX").
1422  *
1423  * The test is to be terminated using a call to
1424  * "GNUNET_SCHEDULER_shutdown".  If starting the test fails,
1425  * the program is stopped without 'master' ever being run.
1426  *
1427  * NOTE: this function should be called from 'main', NOT from
1428  * within a GNUNET_SCHEDULER-loop.  This function will initialze
1429  * the scheduler loop, the testbed and then pass control to
1430  * 'master'.
1431  *
1432  * @param testname name of the testcase (to configure logging, etc.)
1433  * @param cfg_filename configuration filename to use
1434  *              (for testbed, controller and peers)
1435  * @param num_peers number of peers to start; should be greter than 0
1436  * @param event_mask bit mask with set of events to call 'cc' for;
1437  *                   or-ed values of "1LL" shifted by the
1438  *                   respective 'enum GNUNET_TESTBED_EventType'
1439  *                   (i.e.  "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1440  * @param cc controller callback to invoke on events; This callback is called
1441  *        for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
1442  *        set in the event_mask as this is the only way get access to the
1443  *        handle of each peer
1444  * @param cc_cls closure for cc
1445  * @param test_master task to run once the test is ready
1446  * @param test_master_cls closure for 'task'.
1447  */
1448 void
1449 GNUNET_TESTBED_test_run (const char *testname,
1450                          const char *cfg_filename,
1451                          unsigned int num_peers,
1452                          uint64_t event_mask,
1453                          GNUNET_TESTBED_ControllerCallback cc,
1454                          void *cc_cls,
1455                          GNUNET_TESTBED_TestMaster test_master,
1456                          void *test_master_cls);
1457
1458
1459 #if 0                           /* keep Emacsens' auto-indent happy */
1460 {
1461 #endif
1462
1463
1464 #ifdef __cplusplus
1465 }
1466 #endif
1467
1468 #endif