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