fixes
[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 /**
461  * Stops a GNUnet daemon.
462  *
463  * @param d the daemon that should be stopped
464  * @param timeout how long to wait for process for shutdown to complete
465  * @param cb function called once the daemon was stopped
466  * @param cb_cls closure for cb
467  * @param delete_files GNUNET_YES to remove files, GNUNET_NO
468  *        to leave them (i.e. for restarting at a later time,
469  *        or logfile inspection once finished)
470  * @param allow_restart GNUNET_YES to restart peer later (using this API)
471  *        GNUNET_NO to kill off and clean up for good
472  */
473 void
474 GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
475                             struct GNUNET_TIME_Relative timeout,
476                             GNUNET_TESTING_NotifyCompletion cb, void *cb_cls,
477                             int delete_files, int allow_restart);
478
479
480 /**
481  * Changes the configuration of a GNUnet daemon.
482  *
483  * @param d the daemon that should be modified
484  * @param cfg the new configuration for the daemon
485  * @param cb function called once the configuration was changed
486  * @param cb_cls closure for cb
487  */
488 void GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d,
489                                         struct GNUNET_CONFIGURATION_Handle *cfg,
490                                         GNUNET_TESTING_NotifyCompletion cb,
491                                         void * cb_cls);
492
493
494 /**
495  * Establish a connection between two GNUnet daemons.
496  *
497  * @param d1 handle for the first daemon
498  * @param d2 handle for the second daemon
499  * @param timeout how long is the connection attempt
500  *        allowed to take?
501  * @param max_connect_attempts how many times should we try to reconnect
502  *        (within timeout)
503  * @param cb function to call at the end
504  * @param cb_cls closure for cb
505  */
506 void GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
507                                      struct GNUNET_TESTING_Daemon *d2,
508                                      struct GNUNET_TIME_Relative timeout,
509                                      unsigned int max_connect_attempts,
510                                      GNUNET_TESTING_NotifyConnection cb,
511                                      void *cb_cls);
512
513
514
515
516 /**
517  * Start count gnunetd processes with the same set of transports and
518  * applications.  The port numbers (any option called "PORT") will be
519  * adjusted to ensure that no two peers running on the same system
520  * have the same port(s) in their respective configurations.
521  *
522  * @param sched scheduler to use
523  * @param cfg configuration template to use
524  * @param total number of daemons to start
525  * @param timeout total time allowed for peers to start
526  * @param hostkey_callback function to call on each peers hostkey generation
527  *        if NULL, peers will be started by this call, if non-null,
528  *        GNUNET_TESTING_daemons_continue_startup must be called after
529  *        successful hostkey generation
530  * @param hostkey_cls closure for hostkey callback
531  * @param cb function to call on each daemon that was started
532  * @param cb_cls closure for cb
533  * @param connect_callback function to call each time two hosts are connected
534  * @param connect_callback_cls closure for connect_callback
535  * @param hostnames linked list of hosts to use to start peers on (NULL to run on localhost only)
536  *
537  * @return NULL on error, otherwise handle to control peer group
538  */
539 struct GNUNET_TESTING_PeerGroup *
540 GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
541                               const struct GNUNET_CONFIGURATION_Handle *cfg,
542                               unsigned int total,
543                               struct GNUNET_TIME_Relative timeout,
544                               GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback,
545                               void *hostkey_cls,
546                               GNUNET_TESTING_NotifyDaemonRunning cb,
547                               void *cb_cls,
548                               GNUNET_TESTING_NotifyConnection
549                               connect_callback, void *connect_callback_cls,
550                               const struct GNUNET_TESTING_Host *hostnames);
551
552 /**
553  * Function which continues a peer group starting up
554  * after successfully generating hostkeys for each peer.
555  *
556  * @param pg the peer group to continue starting
557  */
558 void
559 GNUNET_TESTING_daemons_continue_startup(struct GNUNET_TESTING_PeerGroup *pg);
560
561 /**
562  * Restart all peers in the given group.
563  *
564  * @param pg the handle to the peer group
565  * @param callback function to call on completion (or failure)
566  * @param callback_cls closure for the callback function
567  */
568 void
569 GNUNET_TESTING_daemons_restart (struct GNUNET_TESTING_PeerGroup *pg,
570                                 GNUNET_TESTING_NotifyCompletion callback,
571                                 void *callback_cls);
572
573
574 /**
575  * Shutdown all peers started in the given group.
576  *
577  * @param pg handle to the peer group
578  * @param timeout how long to wait for shutdown
579  * @param cb callback to notify upon success or failure
580  * @param cb_cls closure for cb
581  */
582 void
583 GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, 
584                              struct GNUNET_TIME_Relative timeout,
585                              GNUNET_TESTING_NotifyCompletion cb,
586                              void *cb_cls);
587
588
589 /**
590  * Simulate churn by stopping some peers (and possibly
591  * re-starting others if churn is called multiple times).  This
592  * function can only be used to create leave-join churn (peers "never"
593  * leave for good).  First "voff" random peers that are currently
594  * online will be taken offline; then "von" random peers that are then
595  * offline will be put back online.  No notifications will be
596  * generated for any of these operations except for the callback upon
597  * completion.  Note that the implementation is at liberty to keep
598  * the ARM service itself (but none of the other services or daemons)
599  * running even though the "peer" is being varied offline.
600  *
601  * @param pg handle for the peer group
602  * @param voff number of peers that should go offline
603  * @param von number of peers that should come back online;
604  *            must be zero on first call (since "testbed_start"
605  *            always starts all of the peers)
606  * @param timeout how long to wait for operations to finish before
607  *        giving up
608  * @param cb function to call at the end
609  * @param cb_cls closure for cb
610  */
611 void
612 GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
613                               unsigned int voff,
614                               unsigned int von,
615                               struct GNUNET_TIME_Relative timeout,
616                               GNUNET_TESTING_NotifyCompletion cb,
617                               void *cb_cls);
618
619 /**
620  * Callback function to process statistic values.
621  *
622  * @param cls closure
623  * @param peer the peer the statistics belong to
624  * @param subsystem name of subsystem that created the statistic
625  * @param name the name of the datum
626  * @param value the current value
627  * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
628  * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
629  */
630 typedef int (*GNUNET_TESTING_STATISTICS_Iterator) (void *cls,
631                                                    const struct GNUNET_PeerIdentity *peer,
632                                                    const char *subsystem,
633                                                    const char *name,
634                                                    uint64_t value,
635                                                    int is_persistent);
636
637 /**
638  * Iterate over all (running) peers in the peer group, retrieve
639  * all statistics from each.
640  */
641 void
642 GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg,
643                                GNUNET_STATISTICS_Callback cont,
644                                GNUNET_TESTING_STATISTICS_Iterator proc, void *cls);
645
646 /**
647  * Topologies supported for testbeds.
648  */
649 enum GNUNET_TESTING_Topology
650 {
651   /**
652    * A clique (everyone connected to everyone else).
653    */
654   GNUNET_TESTING_TOPOLOGY_CLIQUE,
655
656   /**
657    * Small-world network (2d torus plus random links).
658    */
659   GNUNET_TESTING_TOPOLOGY_SMALL_WORLD,
660
661   /**
662    * Small-world network (ring plus random links).
663    */
664   GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING,
665
666   /**
667    * Ring topology.
668    */
669   GNUNET_TESTING_TOPOLOGY_RING,
670
671   /**
672    * 2-d torus.
673    */
674   GNUNET_TESTING_TOPOLOGY_2D_TORUS,
675
676   /**
677    * Random graph.
678    */
679   GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI,
680
681   /**
682    * Certain percentage of peers are unable to communicate directly
683    * replicating NAT conditions
684    */
685   GNUNET_TESTING_TOPOLOGY_INTERNAT,
686
687   /**
688    * Scale free topology.
689    */
690   GNUNET_TESTING_TOPOLOGY_SCALE_FREE,
691
692   /**
693    * Straight line topology.
694    */
695   GNUNET_TESTING_TOPOLOGY_LINE,
696
697   /**
698    * All peers are disconnected.
699    */
700   GNUNET_TESTING_TOPOLOGY_NONE
701 };
702
703 /**
704  * Options for connecting a topology.
705  */
706 enum GNUNET_TESTING_TopologyOption
707 {
708   /**
709    * Try to connect all peers specified in the topology.
710    */
711   GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
712
713   /**
714    * Choose a random subset of connections to create.
715    */
716   GNUNET_TESTING_TOPOLOGY_OPTION_RANDOM,
717
718   /**
719    * Create at least X connections for each peer.
720    */
721   GNUNET_TESTING_TOPOLOGY_OPTION_MINIMUM,
722
723   /**
724    * Using a depth first search, create one connection
725    * per peer.  If any are missed (graph disconnected)
726    * start over at those peers until all have at least one
727    * connection.
728    */
729   GNUNET_TESTING_TOPOLOGY_OPTION_DFS,
730
731   /**
732    * No options specified.
733    */
734   GNUNET_TESTING_TOPOLOGY_OPTION_NONE
735 };
736
737
738 /**
739  * Get a topology from a string input.
740  *
741  * @param topology where to write the retrieved topology
742  * @param topology_string The string to attempt to
743  *        get a configuration value from
744  * @return GNUNET_YES if topology string matched a
745  *         known topology, GNUNET_NO if not
746  */
747 int
748 GNUNET_TESTING_topology_get(enum GNUNET_TESTING_Topology *topology, char * topology_string);
749
750 /**
751  * Get connect topology option from string input.
752  *
753  * @param topology_option 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_option_get(enum GNUNET_TESTING_TopologyOption *topology_option,
761                                    char * topology_string);
762
763
764 /**
765  * Takes a peer group and creates a topology based on the
766  * one specified.  Creates a topology means generates friend
767  * files for the peers so they can only connect to those allowed
768  * by the topology.  This will only have an effect once peers
769  * are started if the FRIENDS_ONLY option is set in the base
770  * config.  Also takes an optional restrict topology which
771  * disallows direct TCP connections UNLESS they are specified in
772  * the restricted topology.
773  *
774  * @param pg the peer group struct representing the running peers
775  * @param topology which topology to connect the peers in
776  * @param restrict_topology allow only direct TCP connections in this topology
777  * @param restrict_transports space delimited list of transports to blacklist
778  *                            to create restricted topology
779  *
780  * @return the maximum number of connections were all allowed peers
781  *         connected to each other
782  */
783 int
784 GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
785                                 enum GNUNET_TESTING_Topology topology,
786                                 enum GNUNET_TESTING_Topology restrict_topology,
787                                 char *restrict_transports);
788
789 /**
790  * Iterate over all (running) peers in the peer group, retrieve
791  * all connections that each currently has.
792  *
793  * @param pg the peer group we are concerned with
794  * @param cb callback for topology information
795  * @param cls closure for callback
796  */
797 void
798 GNUNET_TESTING_get_topology (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_NotifyTopology cb, void *cls);
799
800 /**
801  * There are many ways to connect peers that are supported by this function.
802  * To connect peers in the same topology that was created via the
803  * GNUNET_TESTING_create_topology, the topology variable must be set to
804  * GNUNET_TESTING_TOPOLOGY_NONE.  If the topology variable is specified,
805  * a new instance of that topology will be generated and attempted to be
806  * connected.  This could result in some connections being impossible,
807  * because some topologies are non-deterministic.
808  *
809  * @param pg the peer group struct representing the running peers
810  * @param topology which topology to connect the peers in
811  * @param options options for connecting the topology
812  * @param option_modifier modifier for options that take a parameter
813  * @return the number of connections that will be attempted, GNUNET_SYSERR on error
814  */
815 int
816 GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg,
817                                  enum GNUNET_TESTING_Topology topology,
818                                  enum GNUNET_TESTING_TopologyOption options,
819                                  double option_modifier);
820
821 /**
822  * Start or stop an individual peer from the given group.
823  *
824  * @param pg handle to the peer group
825  * @param offset which peer to start or stop
826  * @param desired_status GNUNET_YES to have it running, GNUNET_NO to stop it
827  * @param timeout how long to wait for shutdown
828  * @param cb function to call at the end
829  * @param cb_cls closure for cb
830  */
831 void
832 GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg, 
833                              unsigned int offset,
834                              int desired_status,
835                              struct GNUNET_TIME_Relative timeout,
836                              GNUNET_TESTING_NotifyCompletion cb,
837                              void *cb_cls);
838
839
840 #if 0                           /* keep Emacsens' auto-indent happy */
841 {
842 #endif
843 #ifdef __cplusplus
844 }
845 #endif
846
847 #endif