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