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