- fix encryption/decryption visisbility
[oweals/gnunet.git] / src / include / gnunet_testbed_service.h
1 /*
2       This file is part of GNUnet
3       (C) 2008--2013 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
257
258 /**
259  * Types of information that can be requested about a peer.
260  */
261 enum GNUNET_TESTBED_PeerInformationType
262 {
263
264   /**
265    * Special value (not valid for requesting information)
266    * that is used in the event struct if a 'generic' pointer
267    * is returned (for other operations not related to this
268    * enumeration).
269    */
270   GNUNET_TESTBED_PIT_GENERIC = 0,
271
272   /**
273    * What configuration is the peer using?  Returns a 'const struct
274    * GNUNET_CONFIGURATION_Handle *'.  Valid until
275    * 'GNUNET_TESTNIG_operation_done' is called.  However, the
276    * values may be inaccurate if the peer is reconfigured in
277    * the meantime.
278    */
279   GNUNET_TESTBED_PIT_CONFIGURATION,
280
281   /**
282    * What is the identity of the peer?  Returns a
283    * 'const struct GNUNET_PeerIdentity *'.  Valid until
284    * 'GNUNET_TESTNIG_operation_done' is called.
285    */
286   GNUNET_TESTBED_PIT_IDENTITY
287
288 };
289
290
291 /**
292  * Argument to GNUNET_TESTBED_ControllerCallback with details about
293  * the event.
294  */
295 struct GNUNET_TESTBED_EventInformation
296 {
297
298   /**
299    * Type of the event.
300    */
301   enum GNUNET_TESTBED_EventType type;
302
303   /**
304    * Handle for the corresponding operation that generated this event
305    */
306   struct GNUNET_TESTBED_Operation *op;
307
308   /**
309    * Closure given while creating the above operation
310    */
311   void *op_cls;
312
313   /**
314    * Details about the event.
315    */
316   union
317   {
318
319     /**
320      * Details about peer start event.
321      */
322     struct
323     {
324       /**
325        * Handle for the host where the peer
326        * was started.
327        */
328       struct GNUNET_TESTBED_Host *host;
329
330       /**
331        * Handle for the peer that was started.
332        */
333       struct GNUNET_TESTBED_Peer *peer;
334
335     } peer_start;
336
337     /**
338      * Details about peer stop event.
339      */
340     struct
341     {
342
343       /**
344        * Handle for the peer that was started.
345        */
346       struct GNUNET_TESTBED_Peer *peer;
347
348     } peer_stop;
349
350     /**
351      * Details about connect event.
352      */
353     struct
354     {
355       /**
356        * Handle for one of the connected peers.
357        */
358       struct GNUNET_TESTBED_Peer *peer1;
359
360       /**
361        * Handle for one of the connected peers.
362        */
363       struct GNUNET_TESTBED_Peer *peer2;
364
365     } peer_connect;
366
367     /**
368      * Details about disconnect event.
369      */
370     struct
371     {
372       /**
373        * Handle for one of the disconnected peers.
374        */
375       struct GNUNET_TESTBED_Peer *peer1;
376
377       /**
378        * Handle for one of the disconnected peers.
379        */
380       struct GNUNET_TESTBED_Peer *peer2;
381
382     } peer_disconnect;
383
384     /**
385      * Details about an operation finished event.
386      */
387     struct
388     {
389       /**
390        * Error message for the operation, NULL on success.
391        */
392       const char *emsg;
393
394       /**
395        * No result (NULL pointer) or generic result
396        * (whatever the GNUNET_TESTBED_ConnectAdapter returned).
397        */
398       void *generic;
399
400     } operation_finished;
401
402   } details;
403
404 };
405
406
407 /**
408  * Signature of the event handler function called by the
409  * respective event controller.
410  *
411  * @param cls closure
412  * @param event information about the event
413  */
414 typedef void (*GNUNET_TESTBED_ControllerCallback)(void *cls,
415                                                   const struct GNUNET_TESTBED_EventInformation *event);
416
417
418 /**
419  * Opaque Handle for Controller process
420  */
421 struct GNUNET_TESTBED_ControllerProc;
422
423
424 /**
425  * Callback to signal successfull startup of the controller process
426  *
427  * @param cls the closure from GNUNET_TESTBED_controller_start()
428  * @param cfg the configuration with which the controller has been started;
429  *          NULL if status is not GNUNET_OK
430  * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
431  *          GNUNET_TESTBED_controller_stop() shouldn't be called in this case
432  */
433 typedef void (*GNUNET_TESTBED_ControllerStatusCallback) (void *cls,
434                                                         const struct GNUNET_CONFIGURATION_Handle *cfg,
435                                                         int status);
436
437
438 /**
439  * Starts a controller process at the given host.  The given host's configration
440  * is used as a Template configuration to use for the remote controller; the
441  * remote controller will be started with a slightly modified configuration
442  * (port numbers, unix domain sockets and service home values are changed as per
443  * TESTING library on the remote host).  The modified configuration replaces the
444  * host's existing configuration before signalling success through the
445  * GNUNET_TESTBED_ControllerStatusCallback()
446  *
447  * @param trusted_ip the ip address of the controller which will be set as TRUSTED
448  *          HOST(all connections form this ip are permitted by the testbed) when
449  *          starting testbed controller at host. This can either be a single ip
450  *          address or a network address in CIDR notation.
451  * @param host the host where the controller has to be started.  CANNOT be NULL.
452  * @param cb function called when the controller is successfully started or
453  *          dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be
454  *          called if cb is called with GNUNET_SYSERR as status. Will never be
455  *          called in the same task as 'GNUNET_TESTBED_controller_start'
456  *          (synchronous errors will be signalled by returning NULL). This
457  *          parameter cannot be NULL.
458  * @param cls closure for above callbacks
459  * @return the controller process handle, NULL on errors
460  */
461 struct GNUNET_TESTBED_ControllerProc *
462 GNUNET_TESTBED_controller_start (const char *trusted_ip,
463                                  struct GNUNET_TESTBED_Host *host,
464                                  GNUNET_TESTBED_ControllerStatusCallback cb,
465                                  void *cls);
466
467
468 /**
469  * Stop the controller process (also will terminate all peers and controllers
470  * dependent on this controller).  This function blocks until the testbed has
471  * been fully terminated (!). The controller status cb from
472  * GNUNET_TESTBED_controller_start() will not be called.
473  *
474  * @param cproc the controller process handle
475  */
476 void
477 GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc);
478
479
480 /**
481  * Connect to a controller process.  The configuration to use for the connection
482  * is retreived from the given host where a controller is started using
483  * GNUNET_TESTBED_controller_start().
484  *
485  * @param host host to run the controller on; This should be the same host if
486  *          the controller was previously started with
487  *          GNUNET_TESTBED_controller_start()
488  * @param event_mask bit mask with set of events to call 'cc' for;
489  *                   or-ed values of "1LL" shifted by the
490  *                   respective 'enum GNUNET_TESTBED_EventType'
491  *                   (i.e.  "(1LL << GNUNET_TESTBED_ET_CONNECT) | ...")
492  * @param cc controller callback to invoke on events
493  * @param cc_cls closure for cc
494  * @return handle to the controller
495  */
496 struct GNUNET_TESTBED_Controller *
497 GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
498                                    uint64_t event_mask,
499                                    GNUNET_TESTBED_ControllerCallback cc,
500                                    void *cc_cls);
501
502
503 /**
504  * Stop the given controller (also will terminate all peers and
505  * controllers dependent on this controller).  This function
506  * blocks until the testbed has been fully terminated (!).
507  *
508  * @param c handle to controller to stop
509  */
510 void
511 GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *c);
512
513
514 /**
515  * Opaque handle for host registration
516  */
517 struct GNUNET_TESTBED_HostRegistrationHandle;
518
519
520 /**
521  * Callback which will be called to after a host registration succeeded or failed
522  *
523  * @param cls the closure
524  * @param emsg the error message; NULL if host registration is successful
525  */
526 typedef void (* GNUNET_TESTBED_HostRegistrationCompletion) (void *cls,
527                                                             const char *emsg);
528
529
530 /**
531  * Register a host with the controller. This makes the controller aware of the
532  * host. A host should be registered at the controller before starting a
533  * sub-controller on that host using GNUNET_TESTBED_controller_link().
534  *
535  * @param controller the controller handle
536  * @param host the host to register
537  * @param cc the completion callback to call to inform the status of
538  *          registration. After calling this callback the registration handle
539  *          will be invalid. Cannot be NULL
540  * @param cc_cls the closure for the cc
541  * @return handle to the host registration which can be used to cancel the
542  *           registration; NULL if another registration handle is present and
543  *           is not cancelled
544  */
545 struct GNUNET_TESTBED_HostRegistrationHandle *
546 GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
547                               struct GNUNET_TESTBED_Host *host,
548                               GNUNET_TESTBED_HostRegistrationCompletion cc,
549                               void *cc_cls);
550
551
552 /**
553  * Cancel the pending registration. Note that the registration message will
554  * already be queued to be sent to the service, cancellation has only the
555  * effect that the registration completion callback for the registration is
556  * never called and from our perspective the host is not registered until the
557  * completion callback is called.
558  *
559  * @param handle the registration handle to cancel
560  */
561 void
562 GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
563                                     *handle);
564
565
566 /**
567  * Callback to be called when an operation is completed
568  *
569  * @param cls the callback closure from functions generating an operation
570  * @param op the operation that has been finished
571  * @param emsg error message in case the operation has failed; will be NULL if
572  *          operation has executed successfully.
573  */
574 typedef void (*GNUNET_TESTBED_OperationCompletionCallback) (void *cls,
575                                                             struct
576                                                             GNUNET_TESTBED_Operation
577                                                             *op,
578                                                             const char *emsg);
579
580
581 /**
582  * Create a link from slave controller to delegated controller. Whenever the
583  * master controller is asked to start a peer at the delegated controller the
584  * request will be routed towards slave controller (if a route exists). The
585  * slave controller will then route it to the delegated controller. The
586  * configuration of the delegated controller is given and is used to either
587  * create the delegated controller or to connect to an existing controller. Note
588  * that while starting the delegated controller the configuration will be
589  * modified to accommodate available free ports.  the 'is_subordinate' specifies
590  * if the given delegated controller should be started and managed by the slave
591  * controller, or if the delegated controller already has a master and the slave
592  * controller connects to it as a non master controller. The success or failure
593  * of this operation will be signalled through the
594  * GNUNET_TESTBED_ControllerCallback() with an event of type
595  * #GNUNET_TESTBED_ET_OPERATION_FINISHED
596  *
597  * @param op_cls the operation closure for the event which is generated to
598  *          signal success or failure of this operation
599  * @param master handle to the master controller who creates the association
600  * @param delegated_host requests to which host should be delegated; cannot be NULL
601  * @param slave_host which host is used to run the slave controller; use NULL to
602  *          make the master controller connect to the delegated host
603  * @param is_subordinate #GNUNET_YES if the controller at delegated_host should
604  *          be started by the slave controller; #GNUNET_NO if the slave
605  *          controller has to connect to the already started delegated
606  *          controller via TCP/IP
607  * @return the operation handle
608  */
609 struct GNUNET_TESTBED_Operation *
610 GNUNET_TESTBED_controller_link (void *op_cls,
611                                 struct GNUNET_TESTBED_Controller *master,
612                                 struct GNUNET_TESTBED_Host *delegated_host,
613                                 struct GNUNET_TESTBED_Host *slave_host,
614                                 int is_subordinate);
615
616
617 /**
618  * Function to acquire the configuration of a running slave controller. The
619  * completion of the operation is signalled through the controller_cb from
620  * GNUNET_TESTBED_controller_connect(). If the operation is successful the
621  * handle to the configuration is available in the generic pointer of
622  * operation_finished field of `struct GNUNET_TESTBED_EventInformation`.
623  *
624  * @param op_cls the closure for the operation
625  * @param master the handle to master controller
626  * @param slave_host the host where the slave controller is running; the handle
627  *          to the slave_host should remain valid until this operation is
628  *          cancelled or marked as finished
629  * @return the operation handle; NULL if the slave_host is not registered at
630  *           master
631  */
632 struct GNUNET_TESTBED_Operation *
633 GNUNET_TESTBED_get_slave_config (void *op_cls,
634                                  struct GNUNET_TESTBED_Controller *master,
635                                  struct GNUNET_TESTBED_Host *slave_host);
636
637
638 /**
639  * Functions of this signature are called when a peer has been successfully
640  * created
641  *
642  * @param cls the closure from GNUNET_TESTBED_peer_create()
643  * @param peer the handle for the created peer; NULL on any error during
644  *          creation
645  * @param emsg NULL if peer is not NULL; else MAY contain the error description
646  */
647 typedef void (*GNUNET_TESTBED_PeerCreateCallback) (void *cls,
648                                                    struct GNUNET_TESTBED_Peer *peer,
649                                                    const char *emsg);
650
651
652 /**
653  * Create the given peer at the specified host using the given
654  * controller.  If the given controller is not running on the target
655  * host, it should find or create a controller at the target host and
656  * delegate creating the peer.  Explicit delegation paths can be setup
657  * using 'GNUNET_TESTBED_controller_link'.  If no explicit delegation
658  * path exists, a direct link with a subordinate controller is setup
659  * for the first delegated peer to a particular host; the subordinate
660  * controller is then destroyed once the last peer that was delegated
661  * to the remote host is stopped.
662  *
663  * Creating the peer only creates the handle to manipulate and further
664  * configure the peer; use #GNUNET_TESTBED_peer_start and
665  * #GNUNET_TESTBED_peer_stop to actually start/stop the peer's
666  * processes.
667  *
668  * Note that the given configuration will be adjusted by the
669  * controller to avoid port/path conflicts with other peers.
670  * The "final" configuration can be obtained using
671  * #GNUNET_TESTBED_peer_get_information.
672  *
673  * @param controller controller process to use
674  * @param host host to run the peer on; cannot be NULL
675  * @param cfg Template configuration to use for the peer. Should exist until
676  *          operation is cancelled or GNUNET_TESTBED_operation_done() is called
677  * @param cb the callback to call when the peer has been created
678  * @param cls the closure to the above callback
679  * @return the operation handle
680  */
681 struct GNUNET_TESTBED_Operation *
682 GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
683                             struct GNUNET_TESTBED_Host *host,
684                             const struct GNUNET_CONFIGURATION_Handle *cfg,
685                             GNUNET_TESTBED_PeerCreateCallback cb,
686                             void *cls);
687
688
689 /**
690  * Functions of this signature are called when a peer has been successfully
691  * started or stopped.
692  *
693  * @param cls the closure from GNUNET_TESTBED_peer_start/stop()
694  * @param emsg NULL on success; otherwise an error description
695  */
696 typedef void (*GNUNET_TESTBED_PeerChurnCallback) (void *cls,
697                                                   const char *emsg);
698
699
700 /**
701  * Start the given peer.
702  *
703  * @param op_cls the closure for this operation; will be set in the event
704  *          information
705  * @param peer peer to start
706  * @param pcc function to call upon completion
707  * @param pcc_cls closure for 'pcc'
708  * @return handle to the operation
709  */
710 struct GNUNET_TESTBED_Operation *
711 GNUNET_TESTBED_peer_start (void *op_cls,
712                            struct GNUNET_TESTBED_Peer *peer,
713                            GNUNET_TESTBED_PeerChurnCallback pcc,
714                            void *pcc_cls);
715
716
717 /**
718  * Stop the given peer.  The handle remains valid (use
719  * #GNUNET_TESTBED_peer_destroy to fully clean up the
720  * state of the peer).
721  *
722  * @param op_cls the closure for this operation; will be set in the event
723  *          information
724  * @param peer peer to stop
725  * @param pcc function to call upon completion
726  * @param pcc_cls closure for 'pcc'
727  * @return handle to the operation
728  */
729 struct GNUNET_TESTBED_Operation *
730 GNUNET_TESTBED_peer_stop (void *op_cls,
731                           struct GNUNET_TESTBED_Peer *peer,
732                           GNUNET_TESTBED_PeerChurnCallback pcc,
733                           void *pcc_cls);
734
735
736 /**
737  * Data returned from GNUNET_TESTBED_peer_get_information
738  */
739 struct GNUNET_TESTBED_PeerInformation
740 {
741   /**
742    * Peer information type; captures which of the types
743    * in the 'op_result' is actually in use.
744    */
745   enum GNUNET_TESTBED_PeerInformationType pit;
746
747   /**
748    * The result of the get information operation; Choose according to the pit
749    */
750   union
751   {
752     /**
753      * The configuration of the peer
754      */
755     struct GNUNET_CONFIGURATION_Handle *cfg;
756
757     /**
758      * The identity of the peer
759      */
760     struct GNUNET_PeerIdentity *id;
761   } result;
762 };
763
764
765 /**
766  * Callback to be called when the requested peer information is available
767  * The peer information in the callback is valid until the operation 'op' is canceled.
768  *
769  * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
770  * @param op the operation this callback corresponds to
771  * @param pinfo the result; will be NULL if the operation has failed
772  * @param emsg error message if the operation has failed; will be NULL if the
773  *          operation is successfull
774  */
775 typedef void (*GNUNET_TESTBED_PeerInfoCallback) (void *cb_cls,
776                                                  struct GNUNET_TESTBED_Operation
777                                                  *op,
778                                                  const struct
779                                                  GNUNET_TESTBED_PeerInformation
780                                                  *pinfo,
781                                                  const char *emsg);
782
783
784 /**
785  * Request information about a peer. The controller callback will not be called
786  * with event type #GNUNET_TESTBED_ET_OPERATION_FINISHED when result for this
787  * operation is available. Instead, the GNUNET_TESTBED_PeerInfoCallback() will
788  * be called.
789  * The peer information in the callback is valid until the operation is canceled.
790  *
791  * @param peer peer to request information about
792  * @param pit desired information
793  * @param cb the convenience callback to be called when results for this
794  *          operation are available
795  * @param cb_cls the closure for @a cb
796  * @return handle to the operation
797  */
798 struct GNUNET_TESTBED_Operation *
799 GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
800                                      enum GNUNET_TESTBED_PeerInformationType
801                                      pit,
802                                      GNUNET_TESTBED_PeerInfoCallback cb,
803                                      void *cb_cls);
804
805
806 /**
807  * Change @a peer configuration.  Ports and paths cannot be changed this
808  * way.
809  *
810  * @param peer peer to change configuration for
811  * @param cfg new configuration
812  * @return handle to the operation
813  */
814 struct GNUNET_TESTBED_Operation *
815 GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
816                                           const struct GNUNET_CONFIGURATION_Handle *cfg);
817
818
819 /**
820  * Destroy the given peer; the peer should have been
821  * stopped first (if it was started).
822  *
823  * @param peer peer to stop
824  * @return handle to the operation
825  */
826 struct GNUNET_TESTBED_Operation *
827 GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer);
828
829
830 /**
831  * Start or stop given service at a peer.  This should not be called to
832  * start/stop the peer's ARM service.  Use GNUNET_TESTBED_peer_start(),
833  * GNUNET_TESTBED_peer_stop() for starting/stopping peer's ARM service.  Success
834  * or failure of the generated operation is signalled through the controller
835  * event callback and/or operation completion callback.
836  *
837  * @param op_cls the closure for the operation
838  * @param peer the peer whose service is to be started/stopped
839  * @param service_name the name of the service
840  * @param cb the operation completion callback
841  * @param cb_cls the closure for @a cb
842  * @param start 1 to start the service; 0 to stop the service
843  * @return an operation handle; NULL upon error (peer not running)
844  */
845 struct GNUNET_TESTBED_Operation *
846 GNUNET_TESTBED_peer_manage_service (void *op_cls,
847                                     struct GNUNET_TESTBED_Peer *peer,
848                                     const char *service_name,
849                                     GNUNET_TESTBED_OperationCompletionCallback cb,
850                                     void *cb_cls,
851                                     unsigned int start);
852
853
854 /**
855  * Stops and destroys all peers.  Is equivalent of calling
856  * GNUNET_TESTBED_peer_stop() and GNUNET_TESTBED_peer_destroy() on all peers,
857  * except that the peer stop event and operation finished event corresponding to
858  * the respective functions are not generated.  This function should be called
859  * when there are no other pending operations.  If there are pending operations,
860  * it will return NULL
861  *
862  * @param c the controller to send this message to
863  * @param op_cls closure for the operation
864  * @param cb the callback to call when all peers are stopped and destroyed
865  * @param cb_cls the closure for the callback
866  * @return operation handle on success; NULL if any pending operations are
867  *           present
868  */
869 struct GNUNET_TESTBED_Operation *
870 GNUNET_TESTBED_shutdown_peers (struct GNUNET_TESTBED_Controller *c,
871                                void *op_cls,
872                                GNUNET_TESTBED_OperationCompletionCallback cb,
873                                void *cb_cls);
874
875
876
877 /**
878  * Options for peer connections.
879  */
880 enum GNUNET_TESTBED_ConnectOption
881 {
882   /**
883    * No option (not valid as an argument).
884    */
885   GNUNET_TESTBED_CO_NONE = 0,
886
887   /**
888    * Allow or disallow a connection between the specified peers.
889    * Followed by #GNUNET_NO (int) if a connection is disallowed
890    * or #GNUNET_YES if a connection is allowed.  Note that the
891    * default (all connections allowed or disallowed) is
892    * specified in the configuration of the controller.
893    */
894   GNUNET_TESTBED_CO_ALLOW = 1,
895
896   /**
897    * FIXME: add (and implement) options to limit connection to
898    * particular transports, force simulation of particular latencies
899    * or message loss rates, or set bandwidth limitations.
900    */
901
902 };
903
904
905 /**
906  * Manipulate the P2P underlay topology by configuring a link
907  * between two peers.
908  *
909  * @param op_cls closure argument to give with the operation event
910  * @param p1 first peer
911  * @param p2 second peer
912  * @param co option to change
913  * @param ap option-specific values
914  * @return handle to the operation, NULL if configuring the link at this
915  *         time is not allowed
916  */
917 struct GNUNET_TESTBED_Operation *
918 GNUNET_TESTBED_underlay_configure_link_va (void *op_cls,
919                                            struct GNUNET_TESTBED_Peer *p1,
920                                            struct GNUNET_TESTBED_Peer *p2,
921                                            enum GNUNET_TESTBED_ConnectOption co,
922                                            va_list ap);
923
924
925 /**
926  * Manipulate the P2P underlay topology by configuring a link
927  * between two peers.
928  *
929  * @param op_cls closure argument to give with the operation event
930  * @param p1 first peer
931  * @param p2 second peer
932  * @param co option to change
933  * @param ... option-specific values
934  * @return handle to the operation, NULL if configuring the link at this
935  *         time is not allowed
936  */
937 struct GNUNET_TESTBED_Operation *
938 GNUNET_TESTBED_underlay_configure_link (void *op_cls,
939                                         struct GNUNET_TESTBED_Peer *p1,
940                                         struct GNUNET_TESTBED_Peer *p2,
941                                         enum GNUNET_TESTBED_ConnectOption co, ...);
942
943
944
945 /**
946  * Topologies and topology options supported for testbeds. Options should always
947  * end with GNUNET_TESTBED_TOPOLOGY_OPTION_END
948  */
949 enum GNUNET_TESTBED_TopologyOption
950 {
951   /**
952    * A clique (everyone connected to everyone else).  No options. If there are N
953    * peers this topology results in (N * (N -1)) connections.
954    */
955   GNUNET_TESTBED_TOPOLOGY_CLIQUE,
956
957   /**
958    * Small-world network (2d torus plus random links).  Followed
959    * by the number of random links to add (unsigned int).
960    */
961   GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD,
962
963   /**
964    * Small-world network (ring plus random links).  Followed
965    * by the number of random links to add (unsigned int).
966    */
967   GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING,
968
969   /**
970    * Ring topology.  No options.
971    */
972   GNUNET_TESTBED_TOPOLOGY_RING,
973
974   /**
975    * 2-d torus.  No options.
976    */
977   GNUNET_TESTBED_TOPOLOGY_2D_TORUS,
978
979   /**
980    * Random graph.  Followed by the number of random links to be established
981    * (unsigned int)
982    */
983   GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
984
985   /**
986    * Certain percentage of peers are unable to communicate directly
987    * replicating NAT conditions.  Followed by the fraction of
988    * NAT'ed peers (float).
989    */
990   GNUNET_TESTBED_TOPOLOGY_INTERNAT,
991
992   /**
993    * Scale free topology.  It is generated according to the method described in
994    * "Emergence of Scaling in Random Networks." Science 286, 509-512, 1999.
995    *
996    * This options takes two arguments in the following order: an uint16_t to
997    * determine the maximum number of edges a peer is permitted to have while
998    * generating scale free topology, a good value for this argument is 70; and
999    * an uint8_t to determine the number of edges to be established when adding a
1000    * new node to the scale free network, a good value for this argument is 4.
1001    */
1002   GNUNET_TESTBED_TOPOLOGY_SCALE_FREE,
1003
1004   /**
1005    * Straight line topology.  No options.
1006    */
1007   GNUNET_TESTBED_TOPOLOGY_LINE,
1008
1009   /**
1010    * Read a topology from a given file.  Followed by the name of the file (const char *).
1011    */
1012   GNUNET_TESTBED_TOPOLOGY_FROM_FILE,
1013
1014   /**
1015    * All peers are disconnected.  No options.
1016    */
1017   GNUNET_TESTBED_TOPOLOGY_NONE,
1018
1019   /**
1020    * The options should always end with this
1021    */
1022   GNUNET_TESTBED_TOPOLOGY_OPTION_END,
1023
1024   /* The following are not topologies but influence how the topology has to be
1025      setup. These options should follow the topology specific options (if
1026      required by the chosen topology). Note that these should be given before
1027      GNUNET_TESTBED_TOPOLOGY_OPTION_END */
1028
1029   /**
1030    * How many times should the failed overlay connect operations be retried
1031    * before giving up.  The default if this option is not specified is to retry
1032    * 3 times.  This option takes and unsigned integer as a parameter.  Use this
1033    * option with parameter 0 to disable retrying of failed overlay connect
1034    * operations.
1035    */
1036   GNUNET_TESTBED_TOPOLOGY_RETRY_CNT
1037 };
1038
1039
1040 /**
1041  * Configure overall network topology to have a particular shape.
1042  *
1043  * @param op_cls closure argument to give with the operation event
1044  * @param num_peers number of peers in 'peers'
1045  * @param peers array of 'num_peers' with the peers to configure
1046  * @param topo desired underlay topology to use
1047  * @param ap topology-specific options
1048  * @return handle to the operation, NULL if configuring the topology
1049  *         is not allowed at this time
1050  */
1051 struct GNUNET_TESTBED_Operation *
1052 GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls,
1053                                                unsigned int num_peers,
1054                                                struct GNUNET_TESTBED_Peer **peers,
1055                                                enum GNUNET_TESTBED_TopologyOption topo,
1056                                                va_list ap);
1057
1058
1059 /**
1060  * Configure overall network topology to have a particular shape.
1061  *
1062  * @param op_cls closure argument to give with the operation event
1063  * @param num_peers number of peers in 'peers'
1064  * @param peers array of 'num_peers' with the peers to configure
1065  * @param topo desired underlay topology to use
1066  * @param ... topology-specific options
1067  * @return handle to the operation, NULL if configuring the topology
1068  *         is not allowed at this time
1069  */
1070 struct GNUNET_TESTBED_Operation *
1071 GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
1072                                             unsigned int num_peers,
1073                                             struct GNUNET_TESTBED_Peer **peers,
1074                                             enum GNUNET_TESTBED_TopologyOption topo,
1075                                             ...);
1076
1077
1078 /**
1079  * Both peers must have been started before calling this function.
1080  * This function then obtains a HELLO from @a p1, gives it to @a p2
1081  * and asks @a p2 to connect to @a p1.
1082  *
1083  * @param op_cls closure argument to give with the operation event
1084  * @param cb the callback to call when this operation has finished
1085  * @param cb_cls the closure for @a cb
1086  * @param p1 first peer
1087  * @param p2 second peer
1088  * @return handle to the operation, NULL if connecting these two
1089  *         peers is fundamentally not possible at this time (peers
1090  *         not running or underlay disallows)
1091  */
1092 struct GNUNET_TESTBED_Operation *
1093 GNUNET_TESTBED_overlay_connect (void *op_cls,
1094                                 GNUNET_TESTBED_OperationCompletionCallback cb,
1095                                 void *cb_cls,
1096                                 struct GNUNET_TESTBED_Peer *p1,
1097                                 struct GNUNET_TESTBED_Peer *p2);
1098
1099
1100 /**
1101  * Callbacks of this type are called when topology configuration is completed
1102  *
1103  * @param cls the operation closure given to
1104  *          GNUNET_TESTBED_overlay_configure_topology_va() and
1105  *          GNUNET_TESTBED_overlay_configure() calls
1106  * @param nsuccess the number of successful overlay connects
1107  * @param nfailures the number of overlay connects which failed
1108  */
1109 typedef void (*GNUNET_TESTBED_TopologyCompletionCallback) (void *cls,
1110                                                           unsigned int nsuccess,
1111                                                           unsigned int nfailures);
1112
1113
1114 /**
1115  * All peers must have been started before calling this function.
1116  * This function then connects the given peers in the P2P overlay
1117  * using the given topology.
1118  *
1119  * @param op_cls closure argument to give with the peer connect operation events
1120  *          generated through this function
1121  * @param num_peers number of peers in 'peers'
1122  * @param peers array of 'num_peers' with the peers to configure
1123  * @param max_connections the maximums number of overlay connections that will
1124  *          be made to achieve the given topology
1125  * @param comp_cb the completion callback to call when the topology generation
1126  *          is completed
1127  * @param comp_cb_cls closure for the @a comp_cb
1128  * @param topo desired underlay topology to use
1129  * @param va topology-specific options
1130  * @return handle to the operation, NULL if connecting these
1131  *         peers is fundamentally not possible at this time (peers
1132  *         not running or underlay disallows) or if num_peers is less than 2
1133  */
1134 struct GNUNET_TESTBED_Operation *
1135 GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
1136                                               unsigned int num_peers,
1137                                               struct GNUNET_TESTBED_Peer **peers,
1138                                               unsigned int *max_connections,
1139                                               GNUNET_TESTBED_TopologyCompletionCallback
1140                                               comp_cb,
1141                                               void *comp_cb_cls,
1142                                               enum GNUNET_TESTBED_TopologyOption topo,
1143                                               va_list va);
1144
1145
1146 /**
1147  * All peers must have been started before calling this function.
1148  * This function then connects the given peers in the P2P overlay
1149  * using the given topology.
1150  *
1151  * @param op_cls closure argument to give with the peer connect operation events
1152  *          generated through this function
1153  * @param num_peers number of peers in 'peers'
1154  * @param peers array of 'num_peers' with the peers to configure
1155  * @param max_connections the maximums number of overlay connections that will
1156  *          be made to achieve the given topology
1157  * @param comp_cb the completion callback to call when the topology generation
1158  *          is completed
1159  * @param comp_cb_cls closure for the above completion callback
1160  * @param topo desired underlay topology to use
1161  * @param ... topology-specific options
1162  * @return handle to the operation, NULL if connecting these
1163  *         peers is fundamentally not possible at this time (peers
1164  *         not running or underlay disallows) or if num_peers is less than 2
1165  */
1166 struct GNUNET_TESTBED_Operation *
1167 GNUNET_TESTBED_overlay_configure_topology (void *op_cls,
1168                                            unsigned int num_peers,
1169                                            struct GNUNET_TESTBED_Peer **peers,
1170                                            unsigned int *max_connections,
1171                                            GNUNET_TESTBED_TopologyCompletionCallback
1172                                            comp_cb,
1173                                            void *comp_cb_cls,
1174                                            enum GNUNET_TESTBED_TopologyOption topo,
1175                                            ...);
1176
1177
1178 /**
1179  * Ask the testbed controller to write the current overlay topology to
1180  * a file.  Naturally, the file will only contain a snapshot as the
1181  * topology may evolve all the time.
1182  * FIXME: needs continuation!?
1183  *
1184  * @param controller overlay controller to inspect
1185  * @param filename name of the file the topology should
1186  *        be written to.
1187  */
1188 void
1189 GNUNET_TESTBED_overlay_write_topology_to_file (struct GNUNET_TESTBED_Controller *controller,
1190                                                const char *filename);
1191
1192
1193 /**
1194  * Adapter function called to establish a connection to
1195  * a service.
1196  *
1197  * @param cls closure
1198  * @param cfg configuration of the peer to connect to; will be available until
1199  *          GNUNET_TESTBED_operation_done() is called on the operation returned
1200  *          from GNUNET_TESTBED_service_connect()
1201  * @return service handle to return in 'op_result', NULL on error
1202  */
1203 typedef void * (*GNUNET_TESTBED_ConnectAdapter)(void *cls,
1204                                                 const struct GNUNET_CONFIGURATION_Handle *cfg);
1205
1206
1207 /**
1208  * Adapter function called to destroy a connection to
1209  * a service.
1210  *
1211  * @param cls closure
1212  * @param op_result service handle returned from the connect adapter
1213  */
1214 typedef void (*GNUNET_TESTBED_DisconnectAdapter)(void *cls,
1215                                                  void *op_result);
1216
1217
1218 /**
1219  * Callback to be called when a service connect operation is completed
1220  *
1221  * @param cls the callback closure from functions generating an operation
1222  * @param op the operation that has been finished
1223  * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
1224  * @param emsg error message in case the operation has failed; will be NULL if
1225  *          operation has executed successfully.
1226  */
1227 typedef void (*GNUNET_TESTBED_ServiceConnectCompletionCallback) (void *cls,
1228                                                                  struct
1229                                                                  GNUNET_TESTBED_Operation
1230                                                                  *op,
1231                                                                  void
1232                                                                  *ca_result,
1233                                                                  const char
1234                                                                  *emsg );
1235
1236
1237 /**
1238  * Connect to a service offered by the given peer.  Will ensure that
1239  * the request is queued to not overwhelm our ability to create and
1240  * maintain connections with other systems.  The actual service
1241  * handle is then returned via the 'op_result' member in the event
1242  * callback.  The @a ca callback is used to create the connection
1243  * when the time is right; the @a da callback will be used to
1244  * destroy the connection (upon #GNUNET_TESTBED_operation_done).
1245  * #GNUNET_TESTBED_operation_done can be used to abort this
1246  * operation until the event callback has been called.
1247  *
1248  * @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
1249  * @param peer peer that runs the service
1250  * @param service_name name of the service to connect to
1251  * @param cb the callback to call when this operation is ready (that is,
1252  *        right after the connect adapter returns)
1253  * @param cb_cls closure for @a cb
1254  * @param ca helper function to establish the connection
1255  * @param da helper function to close the connection
1256  * @param cada_cls closure for @a ca and @a da
1257  * @return handle for the operation
1258  */
1259 struct GNUNET_TESTBED_Operation *
1260 GNUNET_TESTBED_service_connect (void *op_cls,
1261                                 struct GNUNET_TESTBED_Peer *peer,
1262                                 const char *service_name,
1263                                 GNUNET_TESTBED_ServiceConnectCompletionCallback cb,
1264                                 void *cb_cls,
1265                                 GNUNET_TESTBED_ConnectAdapter ca,
1266                                 GNUNET_TESTBED_DisconnectAdapter da,
1267                                 void *cada_cls);
1268
1269
1270 /**
1271  * This function is used to signal that the event information (struct
1272  * GNUNET_TESTBED_EventInformation) from an operation has been fully processed
1273  * i.e. if the event callback is ever called for this operation. If the event
1274  * callback for this operation has not yet been called, calling this function
1275  * cancels the operation, frees its resources and ensures the no event is
1276  * generated with respect to this operation. Note that however cancelling an
1277  * operation does NOT guarantee that the operation will be fully undone (or that
1278  * nothing ever happened).
1279  *
1280  * This function MUST be called for every operation to fully remove the
1281  * operation from the operation queue.  After calling this function, if
1282  * operation is completed and its event information is of type
1283  * GNUNET_TESTBED_ET_OPERATION_FINISHED, the 'op_result' becomes invalid (!).
1284
1285  * If the operation is generated from GNUNET_TESTBED_service_connect() then
1286  * calling this function on such as operation calls the disconnect adapter if
1287  * the connect adapter was ever called.
1288  *
1289  * @param operation operation to signal completion or cancellation
1290  */
1291 void
1292 GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation);
1293
1294
1295 /**
1296  * Callback function to process statistic values from all peers.
1297  *
1298  * @param cls closure
1299  * @param peer the peer the statistic belong to
1300  * @param subsystem name of subsystem that created the statistic
1301  * @param name the name of the datum
1302  * @param value the current value
1303  * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
1304  * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
1305  */
1306 typedef int (*GNUNET_TESTBED_StatisticsIterator) (void *cls,
1307                                                   const struct GNUNET_TESTBED_Peer *peer,
1308                                                   const char *subsystem,
1309                                                   const char *name,
1310                                                   uint64_t value,
1311                                                   int is_persistent);
1312
1313
1314 /**
1315  * Convenience method that iterates over all (running) peers
1316  * and retrieves all statistics from each peer.
1317  *
1318  * @param num_peers number of peers to iterate over
1319  * @param peers array of peers to iterate over
1320  * @param subsystem limit to the specified subsystem, NULL for all subsystems
1321  * @param name name of the statistic value, NULL for all values
1322  * @param proc processing function for each statistic retrieved
1323  * @param cont continuation to call once call is completed.  The completion of this
1324  *          operation is *ONLY* signalled through this callback -- no
1325  *          GNUNET_TESTBED_ET_OPERATION_FINISHED is generated
1326  * @param cls closure to pass to proc and cont
1327  * @return operation handle to cancel the operation
1328  */
1329 struct GNUNET_TESTBED_Operation *
1330 GNUNET_TESTBED_get_statistics (unsigned int num_peers,
1331                                struct GNUNET_TESTBED_Peer **peers,
1332                                const char *subsystem, const char *name,
1333                                GNUNET_TESTBED_StatisticsIterator proc,
1334                                GNUNET_TESTBED_OperationCompletionCallback cont,
1335                                void *cls);
1336
1337 /**
1338  * Handle for testbed run helper funtions
1339  */
1340 struct GNUNET_TESTBED_RunHandle;
1341
1342 /**
1343  * Signature of a main function for a testcase.
1344  *
1345  * @param cls closure
1346  * @param h the run handle
1347  * @param num_peers number of peers in 'peers'
1348  * @param peers handle to peers run in the testbed.  NULL upon timeout (see
1349  *          GNUNET_TESTBED_test_run()).
1350  * @param links_succeeded the number of overlay link connection attempts that
1351  *          succeeded
1352  * @param links_failed the number of overlay link connection attempts that
1353  *          failed
1354  * @see GNUNET_TESTBED_test_run()
1355  */
1356 typedef void (*GNUNET_TESTBED_TestMaster)(void *cls,
1357                                           struct GNUNET_TESTBED_RunHandle *h,
1358                                           unsigned int num_peers,
1359                                           struct GNUNET_TESTBED_Peer **peers,
1360                                           unsigned int links_succeeded,
1361                                           unsigned int links_failed);
1362
1363
1364 /**
1365  * Convenience method for running a testbed with
1366  * a single call.  Underlay and overlay topology
1367  * are configured using the "UNDERLAY" and "OVERLAY"
1368  * options in the "[testbed]" section of the configuration\
1369  * (with possible options given in "UNDERLAY_XXX" and/or
1370  * "OVERLAY_XXX").
1371  *
1372  * The test_master callback will be called once the testbed setup is finished or
1373  * upon a timeout.  This timeout is given through the configuration file by
1374  * setting the option "SETUP_TIMEOUT" in "[TESTBED]" section.
1375  *
1376  * The testbed is to be terminated using a call to
1377  * "GNUNET_SCHEDULER_shutdown".
1378  *
1379  * @param host_filename name of the file with the 'hosts', NULL
1380  *        to run everything on 'localhost'
1381  * @param cfg configuration to use (for testbed, controller and peers)
1382  * @param num_peers number of peers to start; FIXME: maybe put that ALSO into
1383  *        cfg?; should be greater than 0
1384  * @param event_mask bit mask with set of events to call 'cc' for;
1385  *                   or-ed values of "1LL" shifted by the
1386  *                   respective 'enum GNUNET_TESTBED_EventType'
1387  *                   (i.e.  "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1388  * @param cc controller callback to invoke on events; This callback is called
1389  *        for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
1390  *        set in the event_mask as this is the only way get access to the
1391  *        handle of each peer
1392  * @param cc_cls closure for cc
1393  * @param test_master this callback will be called once the test is ready or
1394  *          upon timeout
1395  * @param test_master_cls closure for 'test_master'.
1396  */
1397 void
1398 GNUNET_TESTBED_run (const char *host_filename,
1399                     const struct GNUNET_CONFIGURATION_Handle *cfg,
1400                     unsigned int num_peers,
1401                     uint64_t event_mask,
1402                     GNUNET_TESTBED_ControllerCallback cc,
1403                     void *cc_cls,
1404                     GNUNET_TESTBED_TestMaster test_master,
1405                     void *test_master_cls);
1406
1407
1408 /**
1409  * Convenience method for running a "simple" test on the local system
1410  * with a single call from 'main'.  Underlay and overlay topology are
1411  * configured using the "UNDERLAY" and "OVERLAY" options in the
1412  * "[TESTBED]" section of the configuration (with possible options
1413  * given in "UNDERLAY_XXX" and/or "OVERLAY_XXX").
1414  *
1415  * The test_master callback will be called once the testbed setup is finished or
1416  * upon a timeout.  This timeout is given through the configuration file by
1417  * setting the option "SETUP_TIMEOUT" in "[TESTBED]" section.
1418  *
1419  * The test is to be terminated using a call to
1420  * "GNUNET_SCHEDULER_shutdown".  If starting the test fails,
1421  * the program is stopped without 'master' ever being run.
1422  *
1423  * NOTE: this function should be called from 'main', NOT from
1424  * within a GNUNET_SCHEDULER-loop.  This function will initialze
1425  * the scheduler loop, the testbed and then pass control to
1426  * 'master'.
1427  *
1428  * @param testname name of the testcase (to configure logging, etc.)
1429  * @param cfg_filename configuration filename to use
1430  *              (for testbed, controller and peers)
1431  * @param num_peers number of peers to start; should be greter than 0
1432  * @param event_mask bit mask with set of events to call 'cc' for;
1433  *                   or-ed values of "1LL" shifted by the
1434  *                   respective 'enum GNUNET_TESTBED_EventType'
1435  *                   (i.e.  "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1436  * @param cc controller callback to invoke on events; This callback is called
1437  *        for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
1438  *        set in the event_mask as this is the only way get access to the
1439  *        handle of each peer
1440  * @param cc_cls closure for cc
1441  * @param test_master this callback will be called once the test is ready or
1442  *          upon timeout
1443  * @param test_master_cls closure for 'test_master'.
1444  * @return GNUNET_SYSERR on error, GNUNET_OK on success
1445  */
1446 int
1447 GNUNET_TESTBED_test_run (const char *testname,
1448                          const char *cfg_filename,
1449                          unsigned int num_peers,
1450                          uint64_t event_mask,
1451                          GNUNET_TESTBED_ControllerCallback cc,
1452                          void *cc_cls,
1453                          GNUNET_TESTBED_TestMaster test_master,
1454                          void *test_master_cls);
1455
1456
1457 /**
1458  * Obtain handle to the master controller from a testbed run.  The handle
1459  * returned should not be disconnected.
1460  *
1461  * @param h the testbed run handle
1462  * @return handle to the master controller
1463  */
1464 struct GNUNET_TESTBED_Controller *
1465 GNUNET_TESTBED_run_get_controller_handle (struct GNUNET_TESTBED_RunHandle *h);
1466
1467 /**
1468  * Opaque handle for barrier
1469  */
1470 struct GNUNET_TESTBED_Barrier;
1471
1472
1473 /**
1474  * Status of a barrier
1475  */
1476 enum GNUNET_TESTBED_BarrierStatus
1477 {
1478   /**
1479    * Barrier initialised successfully
1480    */
1481   GNUNET_TESTBED_BARRIERSTATUS_INITIALISED = 1,
1482
1483   /**
1484    * Barrier is crossed
1485    */
1486   GNUNET_TESTBED_BARRIERSTATUS_CROSSED,
1487
1488   /**
1489    * Error status
1490    */
1491   GNUNET_TESTBED_BARRIERSTATUS_ERROR,
1492
1493 };
1494
1495
1496 /**
1497  * Functions of this type are to be given as callback argument to
1498  * GNUNET_TESTBED_barrier_init().  The callback will be called when status
1499  * information is available for the barrier.
1500  *
1501  * @param cls the closure given to GNUNET_TESTBED_barrier_init()
1502  * @param name the name of the barrier
1503  * @param barrier the barrier handle
1504  * @param status status of the barrier; GNUNET_OK if the barrier is crossed;
1505  *   GNUNET_SYSERR upon error
1506  * @param emsg if the status were to be GNUNET_SYSERR, this parameter has the
1507  *   error messsage
1508  */
1509 typedef void (*GNUNET_TESTBED_barrier_status_cb) (void *cls,
1510                                                   const char *name,
1511                                                   struct GNUNET_TESTBED_Barrier
1512                                                   *barrier,
1513                                                   enum GNUNET_TESTBED_BarrierStatus status,
1514                                                   const char *emsg);
1515
1516
1517 /**
1518  * Initialise a barrier and call the given callback when the required percentage
1519  * of peers (quorum) reach the barrier.
1520  *
1521  * @param controller the handle to the controller
1522  * @param name identification name of the barrier
1523  * @param quorum the percentage of peers that is required to reach the barrier.
1524  *   Peers signal reaching a barrier by calling
1525  *   GNUNET_TESTBED_barrier_reached().
1526  * @param cb the callback to call when the barrier is reached or upon error.
1527  *   Cannot be NULL.
1528  * @param cls closure for the above callback
1529  * @return barrier handle
1530  */
1531 struct GNUNET_TESTBED_Barrier *
1532 GNUNET_TESTBED_barrier_init (struct GNUNET_TESTBED_Controller *controller,
1533                              const char *name,
1534                              unsigned int quorum,
1535                              GNUNET_TESTBED_barrier_status_cb cb, void *cls);
1536
1537
1538 /**
1539  * Cancel a barrier.
1540  *
1541  * @param barrier the barrier handle
1542  */
1543 void
1544 GNUNET_TESTBED_barrier_cancel (struct GNUNET_TESTBED_Barrier *barrier);
1545
1546
1547 /**
1548  * Opaque handle for barrier wait
1549  */
1550 struct GNUNET_TESTBED_BarrierWaitHandle;
1551
1552
1553 /**
1554  * Functions of this type are to be given as acallback argumetn to
1555  * GNUNET_TESTBED_barrier_wait().  The callback will be called when the barrier
1556  * corresponding given in GNUNET_TESTBED_barrier_wait() is crossed or cancelled.
1557  *
1558  * @param cls closure pointer given to GNUNET_TESTBED_barrier_wait()
1559  * @param name the barrier name
1560  * @param status GNUNET_SYSERR in case of error while waiting for the barrier;
1561  *   GNUNET_OK if the barrier is crossed
1562  */
1563 typedef void (*GNUNET_TESTBED_barrier_wait_cb) (void *cls,
1564                                                 const char *name,
1565                                                 int status);
1566
1567
1568 /**
1569  * Wait for a barrier to be crossed.  This function should be called by the
1570  * peers which have been started by the testbed.  If the peer is not started by
1571  * testbed this function may return error
1572  *
1573  * @param name the name of the barrier
1574  * @param cb the barrier wait callback
1575  * @param cls the closure for the above callback
1576  * @return barrier wait handle which can be used to cancel the waiting at
1577  *   anytime before the callback is called.  NULL upon error.
1578  */
1579 struct GNUNET_TESTBED_BarrierWaitHandle *
1580 GNUNET_TESTBED_barrier_wait (const char *name,
1581                              GNUNET_TESTBED_barrier_wait_cb cb,
1582                              void *cls);
1583
1584
1585 /**
1586  * Cancel a barrier wait handle.  Should not be called in or after the callback
1587  * given to GNUNET_TESTBED_barrier_wait() has been called.
1588  *
1589  * @param h the barrier wait handle
1590  */
1591 void
1592 GNUNET_TESTBED_barrier_wait_cancel (struct GNUNET_TESTBED_BarrierWaitHandle *h);
1593
1594
1595 #if 0                           /* keep Emacsens' auto-indent happy */
1596 {
1597 #endif
1598
1599
1600 #ifdef __cplusplus
1601 }
1602 #endif
1603
1604 #endif