74addb443991be0e8e15ca812b40f597ca46d5f6
[oweals/gnunet.git] / src / include / gnunet_testing_lib.h
1 /*
2       This file is part of GNUnet
3       (C) 2008, 2009 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 2, 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_testing_lib.h
23  * @brief convenience API for writing testcases for GNUnet
24  *        Many testcases need to start and stop gnunetd,
25  *        and this library is supposed to make that easier
26  *        for TESTCASES.  Normal programs should always
27  *        use functions from gnunet_{util,arm}_lib.h.  This API is
28  *        ONLY for writing testcases!
29  * @author Christian Grothoff
30  */
31
32 #ifndef GNUNET_TESTING_LIB_H
33 #define GNUNET_TESTING_LIB_H
34
35 #include "gnunet_util_lib.h"
36
37 #ifdef __cplusplus
38 extern "C"
39 {
40 #if 0                           /* keep Emacsens' auto-indent happy */
41 }
42 #endif
43 #endif
44
45 /**
46  * Handle for a GNUnet daemon (technically a set of
47  * daemons; the handle is really for the master ARM
48  * daemon) started by the testing library.
49  */
50 struct GNUNET_TESTING_Daemon;
51
52 /**
53  * Prototype of a function that will be called whenever
54  * a daemon was started by the testing library.
55  *
56  * @param cls closure
57  * @param id identifier for the daemon, NULL on error
58  * @param d handle for the daemon
59  * @param emsg error message (NULL on success)
60  */
61 typedef void (*GNUNET_TESTING_NotifyHostkeyCreated)(void *cls,
62                                                     const struct GNUNET_PeerIdentity *id,
63                                                     struct GNUNET_TESTING_Daemon *d,
64                                                     const char *emsg);
65
66 /**
67  * Prototype of a function that will be called whenever
68  * a daemon was started by the testing library.
69  *
70  * @param cls closure
71  * @param id identifier for the daemon, NULL on error
72  * @param cfg configuration used by this daemon
73  * @param d handle for the daemon
74  * @param emsg error message (NULL on success)
75  */
76 typedef void (*GNUNET_TESTING_NotifyDaemonRunning)(void *cls,
77                                                    const struct GNUNET_PeerIdentity *id,
78                                                    const struct GNUNET_CONFIGURATION_Handle *cfg,
79                                                    struct GNUNET_TESTING_Daemon *d,
80                                                    const char *emsg);
81
82
83 /**
84  * Handle to an entire testbed of GNUnet peers.
85  */
86 struct GNUNET_TESTING_Testbed;
87
88 /**
89  * Phases of starting GNUnet on a system.
90  */
91 enum GNUNET_TESTING_StartPhase
92 {
93   /**
94    * Copy the configuration file to the target system.
95    */
96   SP_COPYING,
97
98   /**
99    * Configuration file has been copied, generate hostkey.
100    */
101   SP_COPIED,
102
103   /**
104    * Create the hostkey for the peer.
105    */
106   SP_HOSTKEY_CREATE,
107
108   /**
109    * Hostkey generated, wait for topology to be finished.
110    */
111   SP_HOSTKEY_CREATED,
112
113   /**
114    * Topology has been created, now start ARM.
115    */
116   SP_TOPOLOGY_SETUP,
117
118   /**
119    * ARM has been started, check that it has properly daemonized and
120    * then try to connect to the CORE service (which should be
121    * auto-started by ARM).
122    */
123   SP_START_ARMING,
124
125   /**
126    * We're waiting for CORE to start.
127    */
128   SP_START_CORE,
129
130   /**
131    * Core has notified us that we've established a connection to the service.
132    * The main FSM halts here and waits to be moved to UPDATE or CLEANUP.
133    */
134   SP_START_DONE,
135
136   /**
137    * We've been asked to terminate the instance and are now waiting for
138    * the remote command to stop the gnunet-arm process and delete temporary
139    * files.
140    */
141   SP_SHUTDOWN_START,
142
143   /**
144    * We've received a configuration update and are currently waiting for
145    * the copy process for the update to complete.  Once it is, we will
146    * return to "SP_START_DONE" (and rely on ARM to restart all affected
147    * services).
148    */
149   SP_CONFIG_UPDATE
150 };
151
152 /**
153  * Prototype of a function that will be called when a
154  * particular operation was completed the testing library.
155  *
156  * @param cls closure
157  * @param emsg NULL on success
158  */
159 typedef void (*GNUNET_TESTING_NotifyCompletion)(void *cls,
160                                                 const char *emsg);
161
162 /**
163  * Prototype of a function that will be called with the
164  * number of connections created for a particular topology.
165  *
166  * @param cls closure
167  * @param num_connections the number of connections created
168  */
169 typedef void (*GNUNET_TESTING_NotifyConnections)(void *cls,
170                                                 unsigned int num_connections);
171
172 /**
173  * Handle for a GNUnet daemon (technically a set of
174  * daemons; the handle is really for the master ARM
175  * daemon) started by the testing library.
176  */
177 struct GNUNET_TESTING_Daemon
178 {
179   /**
180    * Our scheduler.
181    */
182   struct GNUNET_SCHEDULER_Handle *sched;
183
184   /**
185    * Our configuration.
186    */
187   struct GNUNET_CONFIGURATION_Handle *cfg;
188
189   /**
190    * At what time to give up starting the peer
191    */
192   struct GNUNET_TIME_Absolute max_timeout;
193
194   /**
195    * Host to run GNUnet on.
196    */
197   char *hostname;
198
199   /**
200    * Result of GNUNET_i2s of this peer,
201    * for printing
202    */
203   char *shortname;
204
205   /**
206    * Username we are using.
207    */
208   char *username;
209
210   /**
211    * Name of the configuration file
212    */
213   char *cfgfile;
214
215   /**
216    * Callback to inform initiator that the peer's
217    * hostkey has been created.
218    */
219   GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback;
220
221   /**
222    * Closure for hostkey creation callback.
223    */
224   void *hostkey_cls;
225
226   /**
227    * Function to call when the peer is running.
228    */
229   GNUNET_TESTING_NotifyDaemonRunning cb;
230
231   /**
232    * Closure for cb.
233    */
234   void *cb_cls;
235
236   /**
237    * Arguments from "daemon_stop" call.
238    */
239   GNUNET_TESTING_NotifyCompletion dead_cb;
240
241   /**
242    * Closure for 'dead_cb'.
243    */
244   void *dead_cb_cls;
245
246   /**
247    * Arguments from "daemon_stop" call.
248    */
249   GNUNET_TESTING_NotifyCompletion update_cb;
250
251   /**
252    * Closure for 'update_cb'.
253    */
254   void *update_cb_cls;
255
256   /**
257    * Identity of this peer (once started).
258    */
259   struct GNUNET_PeerIdentity id;
260
261   /**
262    * Flag to indicate that we've already been asked
263    * to terminate (but could not because some action
264    * was still pending).
265    */
266   int dead;
267
268   /**
269    * PID of the process that we started last.
270    */
271   pid_t pid;
272
273   /**
274    * In which phase are we during the start of
275    * this process?
276    */
277   enum GNUNET_TESTING_StartPhase phase;
278
279   /**
280    * ID of the current task.
281    */
282   GNUNET_SCHEDULER_TaskIdentifier task;
283
284   /**
285    * Handle to the server.
286    */
287   struct GNUNET_CORE_Handle *server;
288
289   /**
290    * Handle to the transport service of this peer
291    */
292   struct GNUNET_TRANSPORT_Handle *th;
293
294   /**
295    * HELLO message for this peer
296    */
297   struct GNUNET_HELLO_Message *hello;
298
299   /**
300    * Handle to a pipe for reading the hostkey.
301    */
302   struct GNUNET_DISK_PipeHandle *pipe_stdout;
303
304   /**
305    * Output from gnunet-peerinfo is read into this buffer.
306    */
307   char hostkeybuf[105];
308
309   /**
310    * Current position in 'hostkeybuf' (for reading from gnunet-peerinfo)
311    */
312   unsigned int hostkeybufpos;
313
314   /**
315    * Set to GNUNET_YES once the peer is up.
316    */
317   int running;
318
319   /**
320    * Used to tell shutdown not to remove configuration for the peer
321    * (if it's going to be restarted later)
322    */
323   int churn;
324 };
325
326
327 /**
328  * Handle to a group of GNUnet peers.
329  */
330 struct GNUNET_TESTING_PeerGroup;
331
332
333 /**
334  * Prototype of a function that will be called whenever
335  * two daemons are connected by the testing library.
336  *
337  * @param cls closure
338  * @param first peer id for first daemon
339  * @param second peer id for the second daemon
340  * @param first_cfg config for the first daemon
341  * @param second_cfg config for the second daemon
342  * @param first_daemon handle for the first daemon
343  * @param second_daemon handle for the second daemon
344  * @param emsg error message (NULL on success)
345  */
346 typedef void (*GNUNET_TESTING_NotifyConnection)(void *cls,
347                                                    const struct GNUNET_PeerIdentity *first,
348                                                    const struct GNUNET_PeerIdentity *second,
349                                                    const struct GNUNET_CONFIGURATION_Handle *first_cfg,
350                                                    const struct GNUNET_CONFIGURATION_Handle *second_cfg,
351                                                    struct GNUNET_TESTING_Daemon *first_daemon,
352                                                    struct GNUNET_TESTING_Daemon *second_daemon,
353                                                    const char *emsg);
354
355 /**
356  * Starts a GNUnet daemon.  GNUnet must be installed on the target
357  * system and available in the PATH.  The machine must furthermore be
358  * reachable via "ssh" (unless the hostname is "NULL") without the
359  * need to enter a password.
360  *
361  * @param sched scheduler to use
362  * @param cfg configuration to use
363  * @param timeout how long to wait starting up peers
364  * @param hostname name of the machine where to run GNUnet
365  *        (use NULL for localhost).
366  * @param hostkey_callback function to call once the hostkey has been
367  *        generated for this peer, but it hasn't yet been started
368  *        (NULL to start immediately, otherwise waits on GNUNET_TESTING_daemon_continue_start)
369  * @param hostkey_cls closure for hostkey callback
370  * @param cb function to call with the result
371  * @param cb_cls closure for cb
372  * @return handle to the daemon (actual start will be completed asynchronously)
373  */
374 struct GNUNET_TESTING_Daemon *
375 GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
376                              const struct GNUNET_CONFIGURATION_Handle *cfg,
377                              struct GNUNET_TIME_Relative timeout,
378                              const char *hostname,
379                              GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback,
380                              void *hostkey_cls,
381                              GNUNET_TESTING_NotifyDaemonRunning cb,
382                              void *cb_cls);
383
384 /**
385  * Continues GNUnet daemon startup when user wanted to be notified
386  * once a hostkey was generated (for creating friends files, blacklists,
387  * etc.).
388  *
389  * @param daemon the daemon to finish starting
390  */
391 void
392 GNUNET_TESTING_daemon_continue_startup(struct GNUNET_TESTING_Daemon *daemon);
393
394 /**
395  * Restart (stop and start) a GNUnet daemon.
396  *
397  * @param d the daemon that should be restarted
398  * @param cb function called once the daemon is (re)started
399  * @param cb_cls closure for cb
400  */
401 void
402 GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d,
403                                GNUNET_TESTING_NotifyDaemonRunning cb, void *cb_cls);
404
405 /**
406  * Start a peer that has previously been stopped using the daemon_stop
407  * call (and files weren't deleted and the allow restart flag)
408  *
409  * @param daemon the daemon to start (has been previously stopped)
410  * @param timeout how long to wait for restart
411  * @param cb the callback for notification when the peer is running
412  * @param cb_cls closure for the callback
413  */
414 void
415 GNUNET_TESTING_daemon_start_stopped (struct GNUNET_TESTING_Daemon *daemon,
416                                      struct GNUNET_TIME_Relative timeout,
417                                      GNUNET_TESTING_NotifyDaemonRunning cb,
418                                      void *cb_cls);
419
420 /**
421  * Get a certain testing daemon handle.
422  *
423  * @param pg handle to the set of running peers
424  * @param position the number of the peer to return
425  */
426 struct GNUNET_TESTING_Daemon *
427 GNUNET_TESTING_daemon_get (struct GNUNET_TESTING_PeerGroup *pg, 
428                            unsigned int position);
429
430
431 /**
432  * Stops a GNUnet daemon.
433  *
434  * @param d the daemon that should be stopped
435  * @param timeout how long to wait for process for shutdown to complete
436  * @param cb function called once the daemon was stopped
437  * @param cb_cls closure for cb
438  * @param delete_files GNUNET_YES to remove files, GNUNET_NO
439  *        to leave them (i.e. for restarting at a later time,
440  *        or logfile inspection once finished)
441  * @param allow_restart GNUNET_YES to restart peer later (using this API)
442  *        GNUNET_NO to kill off and clean up for good
443  */
444 void
445 GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
446                             struct GNUNET_TIME_Relative timeout,
447                             GNUNET_TESTING_NotifyCompletion cb, void *cb_cls,
448                             int delete_files, int allow_restart);
449
450
451 /**
452  * Changes the configuration of a GNUnet daemon.
453  *
454  * @param d the daemon that should be modified
455  * @param cfg the new configuration for the daemon
456  * @param cb function called once the configuration was changed
457  * @param cb_cls closure for cb
458  */
459 void GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d,
460                                         struct GNUNET_CONFIGURATION_Handle *cfg,
461                                         GNUNET_TESTING_NotifyCompletion cb,
462                                         void * cb_cls);
463
464
465 /**
466  * Establish a connection between two GNUnet daemons.
467  *
468  * @param d1 handle for the first daemon
469  * @param d2 handle for the second daemon
470  * @param timeout how long is the connection attempt
471  *        allowed to take?
472  * @param max_connect_attempts how many times should we try to reconnect
473  *        (within timeout)
474  * @param cb function to call at the end
475  * @param cb_cls closure for cb
476  */
477 void GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
478                                      struct GNUNET_TESTING_Daemon *d2,
479                                      struct GNUNET_TIME_Relative timeout,
480                                      unsigned int max_connect_attempts,
481                                      GNUNET_TESTING_NotifyConnection cb,
482                                      void *cb_cls);
483
484
485
486
487 /**
488  * Start count gnunetd processes with the same set of transports and
489  * applications.  The port numbers (any option called "PORT") will be
490  * adjusted to ensure that no two peers running on the same system
491  * have the same port(s) in their respective configurations.
492  *
493  * @param sched scheduler to use
494  * @param cfg configuration template to use
495  * @param total number of daemons to start
496  * @param timeout total time allowed for peers to start
497  * @param hostkey_callback function to call on each peers hostkey generation
498  *        if NULL, peers will be started by this call, if non-null,
499  *        GNUNET_TESTING_daemons_continue_startup must be called after
500  *        successful hostkey generation
501  * @param hostkey_cls closure for hostkey callback
502  * @param cb function to call on each daemon that was started
503  * @param cb_cls closure for cb
504  * @param connect_callback function to call each time two hosts are connected
505  * @param connect_callback_cls closure for connect_callback
506  * @param hostnames space-separated list of hostnames to use; can be NULL (to run
507  *        everything on localhost).
508  * @return NULL on error, otherwise handle to control peer group
509  */
510 struct GNUNET_TESTING_PeerGroup *
511 GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
512                               const struct GNUNET_CONFIGURATION_Handle *cfg,
513                               unsigned int total,
514                               struct GNUNET_TIME_Relative timeout,
515                               GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback,
516                               void *hostkey_cls,
517                               GNUNET_TESTING_NotifyDaemonRunning cb,
518                               void *cb_cls,
519                               GNUNET_TESTING_NotifyConnection
520                               connect_callback, void *connect_callback_cls,
521                               const char *hostnames);
522
523 /**
524  * Function which continues a peer group starting up
525  * after successfully generating hostkeys for each peer.
526  *
527  * @param pg the peer group to continue starting
528  */
529 void
530 GNUNET_TESTING_daemons_continue_startup(struct GNUNET_TESTING_PeerGroup *pg);
531
532 /**
533  * Restart all peers in the given group.
534  *
535  * @param pg the handle to the peer group
536  * @param callback function to call on completion (or failure)
537  * @param callback_cls closure for the callback function
538  */
539 void
540 GNUNET_TESTING_daemons_restart (struct GNUNET_TESTING_PeerGroup *pg,
541                                 GNUNET_TESTING_NotifyCompletion callback,
542                                 void *callback_cls);
543
544
545 /**
546  * Shutdown all peers started in the given group.
547  *
548  * @param pg handle to the peer group
549  * @param timeout how long to wait for shutdown
550  */
551 void
552 GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, 
553                              struct GNUNET_TIME_Relative timeout);
554
555
556 /**
557  * Simulate churn by stopping some peers (and possibly
558  * re-starting others if churn is called multiple times).  This
559  * function can only be used to create leave-join churn (peers "never"
560  * leave for good).  First "voff" random peers that are currently
561  * online will be taken offline; then "von" random peers that are then
562  * offline will be put back online.  No notifications will be
563  * generated for any of these operations except for the callback upon
564  * completion.  Note that the implementation is at liberty to keep
565  * the ARM service itself (but none of the other services or daemons)
566  * running even though the "peer" is being varied offline.
567  *
568  * @param pg handle for the peer group
569  * @param voff number of peers that should go offline
570  * @param von number of peers that should come back online;
571  *            must be zero on first call (since "testbed_start"
572  *            always starts all of the peers)
573  * @param timeout how long to wait for operations to finish before
574  *        giving up
575  * @param cb function to call at the end
576  * @param cb_cls closure for cb
577  */
578 void
579 GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
580                               unsigned int voff,
581                               unsigned int von,
582                               struct GNUNET_TIME_Relative timeout,
583                               GNUNET_TESTING_NotifyCompletion cb,
584                               void *cb_cls);
585
586
587 /**
588  * Topologies supported for testbeds.
589  */
590 enum GNUNET_TESTING_Topology
591 {
592   /**
593    * A clique (everyone connected to everyone else).
594    */
595   GNUNET_TESTING_TOPOLOGY_CLIQUE,
596
597   /**
598    * Small-world network (2d torus plus random links).
599    */
600   GNUNET_TESTING_TOPOLOGY_SMALL_WORLD,
601
602   /**
603    * Small-world network (ring plus random links).
604    */
605   GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING,
606
607   /**
608    * Ring topology.
609    */
610   GNUNET_TESTING_TOPOLOGY_RING,
611
612   /**
613    * 2-d torus.
614    */
615   GNUNET_TESTING_TOPOLOGY_2D_TORUS,
616
617   /**
618    * Random graph.
619    */
620   GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI,
621
622   /**
623    * Certain percentage of peers are unable to communicate directly
624    * replicating NAT conditions
625    */
626   GNUNET_TESTING_TOPOLOGY_INTERNAT,
627
628   /**
629    * Scale free topology.
630    */
631   GNUNET_TESTING_TOPOLOGY_SCALE_FREE,
632
633   /**
634    * All peers are disconnected.
635    */
636   GNUNET_TESTING_TOPOLOGY_NONE
637 };
638
639 /**
640  * Options for connecting a topology.
641  */
642 enum GNUNET_TESTING_TopologyOption
643 {
644   /**
645    * Try to connect all peers specified in the topology.
646    */
647   GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
648
649   /**
650    * Choose a random subset of connections to create.
651    */
652   GNUNET_TESTING_TOPOLOGY_OPTION_RANDOM,
653
654   /**
655    * Create at least X connections for each peer.
656    */
657   GNUNET_TESTING_TOPOLOGY_OPTION_MINIMUM,
658
659   /**
660    * Using a depth first search, create one connection
661    * per peer.  If any are missed (graph disconnected)
662    * start over at those peers until all have at least one
663    * connection.
664    */
665   GNUNET_TESTING_TOPOLOGY_OPTION_DFS,
666
667   /**
668    * No options specified.
669    */
670   GNUNET_TESTING_TOPOLOGY_OPTION_NONE
671 };
672
673
674 /**
675  * Get a topology from a string input.
676  *
677  * @param topology where to write the retrieved topology
678  * @param topology_string The string to attempt to
679  *        get a configuration value from
680  * @return GNUNET_YES if topology string matched a
681  *         known topology, GNUNET_NO if not
682  */
683 int
684 GNUNET_TESTING_topology_get(enum GNUNET_TESTING_Topology *topology, char * topology_string);
685
686 /**
687  * Get connect topology option from string input.
688  *
689  * @param topology where to write the retrieved topology
690  * @param topology_string The string to attempt to
691  *        get a configuration value from
692  * @return GNUNET_YES if topology string matched a
693  *         known topology, GNUNET_NO if not
694  */
695 int
696 GNUNET_TESTING_topology_option_get(enum GNUNET_TESTING_TopologyOption *topology, char * topology_string);
697
698
699 /**
700  * Takes a peer group and creates a topology based on the
701  * one specified.  Creates a topology means generates friend
702  * files for the peers so they can only connect to those allowed
703  * by the topology.  This will only have an effect once peers
704  * are started if the FRIENDS_ONLY option is set in the base
705  * config.  Also takes an optional restrict topology which
706  * disallows direct TCP connections UNLESS they are specified in
707  * the restricted topology.
708  *
709  * @param pg the peer group struct representing the running peers
710  * @param topology which topology to connect the peers in
711  * @param restrict_topology allow only direct TCP connections in this topology
712  * @param restrict_transports space delimited list of transports to blacklist
713  *                            to create restricted topology
714  *
715  * @return the maximum number of connections were all allowed peers
716  *         connected to each other
717  */
718 int
719 GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
720                                 enum GNUNET_TESTING_Topology topology,
721                                 enum GNUNET_TESTING_Topology restrict_topology,
722                                 char *restrict_transports);
723
724 /**
725  * There are many ways to connect peers that are supported by this function.
726  * To connect peers in the same topology that was created via the
727  * GNUNET_TESTING_create_topology, the topology variable must be set to
728  * GNUNET_TESTING_TOPOLOGY_NONE.  If the topology variable is specified,
729  * a new instance of that topology will be generated and attempted to be
730  * connected.  This could result in some connections being impossible,
731  * because some topologies are non-deterministic.
732  *
733  * @param pg the peer group struct representing the running peers
734  * @param topology which topology to connect the peers in
735  * @param options options for connecting the topology
736  * @param option_modifier modifier for options that take a parameter
737  * @return the number of connections that will be attempted, GNUNET_SYSERR on error
738  */
739 int
740 GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg,
741                                  enum GNUNET_TESTING_Topology topology,
742                                  enum GNUNET_TESTING_TopologyOption options,
743                                  double option_modifier);
744
745 /**
746  * Start or stop an individual peer from the given group.
747  *
748  * @param pg handle to the peer group
749  * @param offset which peer to start or stop
750  * @param desired_status GNUNET_YES to have it running, GNUNET_NO to stop it
751  * @param timeout how long to wait for shutdown
752  * @param cb function to call at the end
753  * @param cb_cls closure for cb
754  */
755 void
756 GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg, 
757                              unsigned int offset,
758                              int desired_status,
759                              struct GNUNET_TIME_Relative timeout,
760                              GNUNET_TESTING_NotifyCompletion cb,
761                              void *cb_cls);
762
763
764 /**
765  * Start "count" GNUnet daemons with a particular topology.
766  *
767  * @param sched scheduler to use
768  * @param cfg configuration template to use
769  * @param count number of peers the testbed should have
770  * @param topology desired topology (enforced via F2F)
771  * @param cb function to call on each daemon that was started
772  * @param cb_cls closure for cb
773  * @param hostname where to run the peers; can be NULL (to run
774  *        everything on localhost). Additional
775  *        hosts can be specified using a NULL-terminated list of
776  *        varargs, hosts will then be used round-robin from that
777  *        list.
778  * @return handle to control the testbed
779  */
780 struct GNUNET_TESTING_Testbed *
781 GNUNET_TESTING_testbed_start (struct GNUNET_SCHEDULER_Handle *sched,
782                               const struct GNUNET_CONFIGURATION_Handle *cfg,
783                               unsigned int count,
784                               enum GNUNET_TESTING_Topology topology,
785                               GNUNET_TESTING_NotifyDaemonRunning cb,
786                               void *cb_cls,
787                               const char *hostname,
788                               ...);
789
790
791 /**
792  * Stop all of the daemons started with the start function.
793  *
794  * @param tb handle for the testbed
795  * @param cb function to call when done
796  * @param cb_cls closure for cb
797  */
798 void
799 GNUNET_TESTING_testbed_stop (struct GNUNET_TESTING_Testbed *tb,
800                              GNUNET_TESTING_NotifyCompletion cb,
801                              void *cb_cls );
802
803
804 /**
805  * Simulate churn in the testbed by stopping some peers (and possibly
806  * re-starting others if churn is called multiple times).  This
807  * function can only be used to create leave-join churn (peers "never"
808  * leave for good).  First "voff" random peers that are currently
809  * online will be taken offline; then "von" random peers that are then
810  * offline will be put back online.  No notifications will be
811  * generated for any of these operations except for the callback upon
812  * completion.  Note that the implementation is at liberty to keep
813  * the ARM service itself (but none of the other services or daemons)
814  * running even though the "peer" is being varied offline.
815  *
816  * @param tb handle for the testbed
817  * @param voff number of peers that should go offline
818  * @param von number of peers that should come back online;
819  *            must be zero on first call (since "testbed_start"
820  *            always starts all of the peers)
821  * @param cb function to call at the end
822  * @param cb_cls closure for cb
823  */
824 void
825 GNUNET_TESTING_testbed_churn (struct GNUNET_TESTING_Testbed *tb,
826                               unsigned int voff,
827                               unsigned int von,
828                               GNUNET_TESTING_NotifyCompletion cb,
829                               void *cb_cls);
830
831
832 #if 0                           /* keep Emacsens' auto-indent happy */
833 {
834 #endif
835 #ifdef __cplusplus
836 }
837 #endif
838
839 #endif