2 This file is part of GNUnet
3 (C) 2008, 2009 Christian Grothoff (and other contributing authors)
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.
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.
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.
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
32 #ifndef GNUNET_TESTING_LIB_H
33 #define GNUNET_TESTING_LIB_H
35 #include "gnunet_util_lib.h"
36 #include "gnunet_statistics_service.h"
41 #if 0 /* keep Emacsens' auto-indent happy */
46 #define HOSTKEYFILESIZE 914
49 * Handle for a GNUnet daemon (technically a set of
50 * daemons; the handle is really for the master ARM
51 * daemon) started by the testing library.
53 struct GNUNET_TESTING_Daemon;
56 * Linked list of hostnames and ports to use for starting daemons.
58 struct GNUNET_TESTING_Host
61 * Pointer to next item in the list.
63 struct GNUNET_TESTING_Host *next;
66 * Hostname to connect to.
71 * Username to use when connecting (may be null).
76 * Port to use for SSH connection (used for ssh
77 * connection forwarding, 0 to let ssh decide)
83 * Prototype of a function that will be called whenever
84 * a daemon was started by the testing library.
87 * @param id identifier for the daemon, NULL on error
88 * @param d handle for the daemon
89 * @param emsg error message (NULL on success)
91 typedef void (*GNUNET_TESTING_NotifyHostkeyCreated)(void *cls,
92 const struct GNUNET_PeerIdentity *id,
93 struct GNUNET_TESTING_Daemon *d,
97 * Prototype of a function that will be called whenever
98 * a daemon was started by the testing library.
101 * @param id identifier for the daemon, NULL on error
102 * @param cfg configuration used by this daemon
103 * @param d handle for the daemon
104 * @param emsg error message (NULL on success)
106 typedef void (*GNUNET_TESTING_NotifyDaemonRunning)(void *cls,
107 const struct GNUNET_PeerIdentity *id,
108 const struct GNUNET_CONFIGURATION_Handle *cfg,
109 struct GNUNET_TESTING_Daemon *d,
114 * Handle to an entire testbed of GNUnet peers.
116 struct GNUNET_TESTING_Testbed;
119 * Phases of starting GNUnet on a system.
121 enum GNUNET_TESTING_StartPhase
124 * Copy the configuration file to the target system.
129 * Configuration file has been copied, generate hostkey.
134 * Create the hostkey for the peer.
139 * Hostkey generated, wait for topology to be finished.
144 * Topology has been created, now start ARM.
149 * ARM has been started, check that it has properly daemonized and
150 * then try to connect to the CORE service (which should be
151 * auto-started by ARM).
156 * We're waiting for CORE to start.
161 * CORE is up, now make sure we get the HELLO for this peer.
166 * Core has notified us that we've established a connection to the service.
167 * The main FSM halts here and waits to be moved to UPDATE or CLEANUP.
172 * We've been asked to terminate the instance and are now waiting for
173 * the remote command to stop the gnunet-arm process and delete temporary
179 * We should shutdown a *single* service via gnunet-arm. Call the dead_cb
180 * upon notification from gnunet-arm that the service has been stopped.
182 SP_SERVICE_SHUTDOWN_START,
185 * We should start a *single* service via gnunet-arm. Call the daemon cb
186 * upon notification from gnunet-arm that the service has been started.
191 * We've received a configuration update and are currently waiting for
192 * the copy process for the update to complete. Once it is, we will
193 * return to "SP_START_DONE" (and rely on ARM to restart all affected
200 * Prototype of a function that will be called when a
201 * particular operation was completed the testing library.
204 * @param emsg NULL on success
206 typedef void (*GNUNET_TESTING_NotifyCompletion)(void *cls,
210 * Prototype of a function that will be called with the
211 * number of connections created for a particular topology.
214 * @param num_connections the number of connections created
216 typedef void (*GNUNET_TESTING_NotifyConnections)(void *cls,
217 unsigned int num_connections);
220 * Handle for a GNUnet daemon (technically a set of
221 * daemons; the handle is really for the master ARM
222 * daemon) started by the testing library.
224 struct GNUNET_TESTING_Daemon
229 struct GNUNET_CONFIGURATION_Handle *cfg;
232 * At what time to give up starting the peer
234 struct GNUNET_TIME_Absolute max_timeout;
237 * Host to run GNUnet on.
242 * Port to use for ssh, NULL to let system choose default.
247 * Result of GNUNET_i2s of this peer,
253 * Username we are using.
258 * Name of the configuration file
263 * Callback to inform initiator that the peer's
264 * hostkey has been created.
266 GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback;
269 * Closure for hostkey creation callback.
274 * Function to call when the peer is running.
276 GNUNET_TESTING_NotifyDaemonRunning cb;
284 * Arguments from "daemon_stop" call.
286 GNUNET_TESTING_NotifyCompletion dead_cb;
289 * Closure for 'dead_cb'.
294 * Arguments from "daemon_stop" call.
296 GNUNET_TESTING_NotifyCompletion update_cb;
299 * Closure for 'update_cb'.
304 * Identity of this peer (once started).
306 struct GNUNET_PeerIdentity id;
309 * Flag to indicate that we've already been asked
310 * to terminate (but could not because some action
311 * was still pending).
316 * GNUNET_YES if the hostkey has been created
317 * for this peer, GNUNET_NO otherwise.
322 * PID of the process that we started last.
324 struct GNUNET_OS_Process *proc;
327 * In which phase are we during the start of
330 enum GNUNET_TESTING_StartPhase phase;
333 * ID of the current task.
335 GNUNET_SCHEDULER_TaskIdentifier task;
338 * Handle to the server.
340 struct GNUNET_CORE_Handle *server;
343 * Handle to the transport service of this peer
345 struct GNUNET_TRANSPORT_Handle *th;
348 * HELLO message for this peer
350 struct GNUNET_HELLO_Message *hello;
353 * Handle to a pipe for reading the hostkey.
355 struct GNUNET_DISK_PipeHandle *pipe_stdout;
358 * Output from gnunet-peerinfo is read into this buffer.
360 char hostkeybuf[105];
363 * Current position in 'hostkeybuf' (for reading from gnunet-peerinfo)
365 unsigned int hostkeybufpos;
368 * Set to GNUNET_YES once the peer is up.
373 * Used to tell shutdown not to remove configuration for the peer
374 * (if it's going to be restarted later)
379 * Currently, a single char * pointing to a service
380 * that has been churned off.
382 * FIXME: make this a linked list of services that have been churned off!!!
384 char *churned_services;
389 * Handle to a group of GNUnet peers.
391 struct GNUNET_TESTING_PeerGroup;
395 * Prototype of a function that will be called whenever
396 * two daemons are connected by the testing library.
399 * @param first peer id for first daemon
400 * @param second peer id for the second daemon
401 * @param distance distance between the connected peers
402 * @param first_cfg config for the first daemon
403 * @param second_cfg config for the second daemon
404 * @param first_daemon handle for the first daemon
405 * @param second_daemon handle for the second daemon
406 * @param emsg error message (NULL on success)
408 typedef void (*GNUNET_TESTING_NotifyConnection)(void *cls,
409 const struct GNUNET_PeerIdentity *first,
410 const struct GNUNET_PeerIdentity *second,
412 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
413 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
414 struct GNUNET_TESTING_Daemon *first_daemon,
415 struct GNUNET_TESTING_Daemon *second_daemon,
419 * Prototype of a callback function indicating that two peers
420 * are currently connected.
423 * @param first peer id for first daemon
424 * @param second peer id for the second daemon
425 * @param distance distance between the connected peers
426 * @param emsg error message (NULL on success)
428 typedef void (*GNUNET_TESTING_NotifyTopology)(void *cls,
429 const struct GNUNET_PeerIdentity *first,
430 const struct GNUNET_PeerIdentity *second,
434 * Starts a GNUnet daemon. GNUnet must be installed on the target
435 * system and available in the PATH. The machine must furthermore be
436 * reachable via "ssh" (unless the hostname is "NULL") without the
437 * need to enter a password.
439 * @param cfg configuration to use
440 * @param timeout how long to wait starting up peers
441 * @param pretend GNUNET_YES to set up files but not start peer GNUNET_NO
442 * to really start the peer (default)
443 * @param hostname name of the machine where to run GNUnet
444 * (use NULL for localhost).
445 * @param ssh_username ssh username to use when connecting to hostname
446 * @param sshport port to pass to ssh process when connecting to hostname
447 * @param hostkey pointer to a hostkey to be written to disk (instead of being generated)
448 * @param hostkey_callback function to call once the hostkey has been
449 * generated for this peer, but it hasn't yet been started
450 * (NULL to start immediately, otherwise waits on GNUNET_TESTING_daemon_continue_start)
451 * @param hostkey_cls closure for hostkey callback
452 * @param cb function to call once peer is up, or failed to start
453 * @param cb_cls closure for cb
454 * @return handle to the daemon (actual start will be completed asynchronously)
456 struct GNUNET_TESTING_Daemon *
457 GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
458 struct GNUNET_TIME_Relative timeout,
460 const char *hostname,
461 const char *ssh_username,
464 GNUNET_TESTING_NotifyHostkeyCreated
465 hostkey_callback, void *hostkey_cls,
466 GNUNET_TESTING_NotifyDaemonRunning cb,
470 * Continues GNUnet daemon startup when user wanted to be notified
471 * once a hostkey was generated (for creating friends files, blacklists,
474 * @param daemon the daemon to finish starting
477 GNUNET_TESTING_daemon_continue_startup(struct GNUNET_TESTING_Daemon *daemon);
480 * Check whether the given daemon is running.
482 * @param daemon the daemon to check
484 * @return GNUNET_YES if the daemon is up, GNUNET_NO if the
485 * daemon is down, GNUNET_SYSERR on error.
488 GNUNET_TESTING_daemon_running (struct GNUNET_TESTING_Daemon *daemon);
491 * Restart (stop and start) a GNUnet daemon.
493 * @param d the daemon that should be restarted
494 * @param cb function called once the daemon is (re)started
495 * @param cb_cls closure for cb
498 GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d,
499 GNUNET_TESTING_NotifyDaemonRunning cb, void *cb_cls);
502 * Start a peer that has previously been stopped using the daemon_stop
503 * call (and files weren't deleted and the allow restart flag)
505 * @param daemon the daemon to start (has been previously stopped)
506 * @param timeout how long to wait for restart
507 * @param cb the callback for notification when the peer is running
508 * @param cb_cls closure for the callback
511 GNUNET_TESTING_daemon_start_stopped (struct GNUNET_TESTING_Daemon *daemon,
512 struct GNUNET_TIME_Relative timeout,
513 GNUNET_TESTING_NotifyDaemonRunning cb,
517 * Stops a GNUnet daemon.
519 * @param d the daemon for which the service should be started
520 * @param service the name of the service to start
521 * @param timeout how long to wait for process for shutdown to complete
522 * @param cb function called once the daemon was stopped
523 * @param cb_cls closure for cb
526 GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d,
528 struct GNUNET_TIME_Relative timeout,
529 GNUNET_TESTING_NotifyDaemonRunning cb, void *cb_cls);
532 * Get a certain testing daemon handle.
534 * @param pg handle to the set of running peers
535 * @param position the number of the peer to return
537 struct GNUNET_TESTING_Daemon *
538 GNUNET_TESTING_daemon_get (struct GNUNET_TESTING_PeerGroup *pg,
539 unsigned int position);
542 * Get a daemon by peer identity, so callers can
543 * retrieve the daemon without knowing it's offset.
545 * @param pg the peer group to retrieve the daemon from
546 * @param peer_id the peer identity of the daemon to retrieve
548 * @return the daemon on success, or NULL if no such peer identity is found
550 struct GNUNET_TESTING_Daemon *
551 GNUNET_TESTING_daemon_get_by_id (struct GNUNET_TESTING_PeerGroup *pg,
552 struct GNUNET_PeerIdentity *peer_id);
555 * Stops a GNUnet daemon.
557 * @param d the daemon that should be stopped
558 * @param timeout how long to wait for process for shutdown to complete
559 * @param cb function called once the daemon was stopped
560 * @param cb_cls closure for cb
561 * @param delete_files GNUNET_YES to remove files, GNUNET_NO
562 * to leave them (i.e. for restarting at a later time,
563 * or logfile inspection once finished)
564 * @param allow_restart GNUNET_YES to restart peer later (using this API)
565 * GNUNET_NO to kill off and clean up for good
568 GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
569 struct GNUNET_TIME_Relative timeout,
570 GNUNET_TESTING_NotifyCompletion cb, void *cb_cls,
571 int delete_files, int allow_restart);
575 * Changes the configuration of a GNUnet daemon.
577 * @param d the daemon that should be modified
578 * @param cfg the new configuration for the daemon
579 * @param cb function called once the configuration was changed
580 * @param cb_cls closure for cb
582 void GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d,
583 struct GNUNET_CONFIGURATION_Handle *cfg,
584 GNUNET_TESTING_NotifyCompletion cb,
588 * Stops a single service of a GNUnet daemon. Used like daemon_stop,
589 * only doesn't stop the entire peer in any case. If the service
590 * is not currently running, this call is likely to fail after
593 * @param d the daemon that should be stopped
594 * @param service the name of the service to stop
595 * @param timeout how long to wait for process for shutdown to complete
596 * @param cb function called once the service was stopped
597 * @param cb_cls closure for cb
600 GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d,
602 struct GNUNET_TIME_Relative timeout,
603 GNUNET_TESTING_NotifyCompletion cb, void *cb_cls);
606 * Read a testing hosts file based on a configuration.
607 * Returns a DLL of hosts (caller must free!) on success
608 * or NULL on failure.
610 * @param cfg a configuration with a testing section
612 * @return DLL of hosts on success, NULL on failure
614 struct GNUNET_TESTING_Host *
615 GNUNET_TESTING_hosts_load (const struct GNUNET_CONFIGURATION_Handle *cfg);
619 * Start count gnunet instances with the same set of transports and
620 * applications. The port numbers (any option called "PORT") will be
621 * adjusted to ensure that no two peers running on the same system
622 * have the same port(s) in their respective configurations.
624 * @param cfg configuration template to use
625 * @param total number of daemons to start
626 * @param max_concurrent_connections for testing, how many peers can
627 * we connect to simultaneously
628 * @param max_concurrent_ssh when starting with ssh, how many ssh
629 * connections will we allow at once (based on remote hosts allowed!)
630 * @param timeout total time allowed for peers to start
631 * @param hostkey_callback function to call on each peers hostkey generation
632 * if NULL, peers will be started by this call, if non-null,
633 * GNUNET_TESTING_daemons_continue_startup must be called after
634 * successful hostkey generation
635 * @param hostkey_cls closure for hostkey callback
636 * @param cb function to call on each daemon that was started
637 * @param cb_cls closure for cb
638 * @param connect_callback function to call each time two hosts are connected
639 * @param connect_callback_cls closure for connect_callback
640 * @param hostnames linked list of host structs to use to start peers on
641 * (NULL to run on localhost only)
643 * @return NULL on error, otherwise handle to control peer group
645 struct GNUNET_TESTING_PeerGroup *
646 GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
648 unsigned int max_concurrent_connections,
649 unsigned int max_concurrent_ssh,
650 struct GNUNET_TIME_Relative timeout,
651 GNUNET_TESTING_NotifyHostkeyCreated
652 hostkey_callback, void *hostkey_cls,
653 GNUNET_TESTING_NotifyDaemonRunning cb,
655 GNUNET_TESTING_NotifyConnection
656 connect_callback, void *connect_callback_cls,
657 const struct GNUNET_TESTING_Host *hostnames);
660 * Function which continues a peer group starting up
661 * after successfully generating hostkeys for each peer.
663 * @param pg the peer group to continue starting
666 GNUNET_TESTING_daemons_continue_startup(struct GNUNET_TESTING_PeerGroup *pg);
670 * Establish a connection between two GNUnet daemons.
672 * @param d1 handle for the first daemon
673 * @param d2 handle for the second daemon
674 * @param timeout how long is the connection attempt
676 * @param max_connect_attempts how many times should we try to reconnect
678 * @param send_hello GNUNET_YES to send the HELLO, GNUNET_NO to assume
679 * the HELLO has already been exchanged
680 * @param cb function to call at the end
681 * @param cb_cls closure for cb
684 GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
685 struct GNUNET_TESTING_Daemon *d2,
686 struct GNUNET_TIME_Relative timeout,
687 unsigned int max_connect_attempts,
689 GNUNET_TESTING_NotifyConnection cb,
694 * Restart all peers in the given group.
696 * @param pg the handle to the peer group
697 * @param callback function to call on completion (or failure)
698 * @param callback_cls closure for the callback function
701 GNUNET_TESTING_daemons_restart (struct GNUNET_TESTING_PeerGroup *pg,
702 GNUNET_TESTING_NotifyCompletion callback,
707 * Shutdown all peers started in the given group.
709 * @param pg handle to the peer group
710 * @param timeout how long to wait for shutdown
711 * @param cb callback to notify upon success or failure
712 * @param cb_cls closure for cb
715 GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg,
716 struct GNUNET_TIME_Relative timeout,
717 GNUNET_TESTING_NotifyCompletion cb,
722 * Count the number of running peers.
724 * @param pg handle for the peer group
726 * @return the number of currently running peers in the peer group
729 GNUNET_TESTING_daemons_running (struct GNUNET_TESTING_PeerGroup *pg);
732 * Simulate churn by stopping some peers (and possibly
733 * re-starting others if churn is called multiple times). This
734 * function can only be used to create leave-join churn (peers "never"
735 * leave for good). First "voff" random peers that are currently
736 * online will be taken offline; then "von" random peers that are then
737 * offline will be put back online. No notifications will be
738 * generated for any of these operations except for the callback upon
739 * completion. Note that the implementation is at liberty to keep
740 * the ARM service itself (but none of the other services or daemons)
741 * running even though the "peer" is being varied offline.
743 * @param pg handle for the peer group
744 * @param service the service to churn on/off, NULL for all
745 * @param voff number of peers that should go offline
746 * @param von number of peers that should come back online;
747 * must be zero on first call (since "testbed_start"
748 * always starts all of the peers)
749 * @param timeout how long to wait for operations to finish before
751 * @param cb function to call at the end
752 * @param cb_cls closure for cb
755 GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
759 struct GNUNET_TIME_Relative timeout,
760 GNUNET_TESTING_NotifyCompletion cb,
764 * Callback function to process statistic values.
767 * @param peer the peer the statistics belong to
768 * @param subsystem name of subsystem that created the statistic
769 * @param name the name of the datum
770 * @param value the current value
771 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
772 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
774 typedef int (*GNUNET_TESTING_STATISTICS_Iterator) (void *cls,
775 const struct GNUNET_PeerIdentity *peer,
776 const char *subsystem,
782 * Iterate over all (running) peers in the peer group, retrieve
783 * all statistics from each.
785 * @param pg the peergroup to iterate statistics of
786 * @param cont continuation to call once call is completed(?)
787 * @param proc processing function for each statistic retrieved
788 * @param cls closure to pass to proc
791 GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg,
792 GNUNET_STATISTICS_Callback cont,
793 GNUNET_TESTING_STATISTICS_Iterator proc, void *cls);
796 * Topologies supported for testbeds.
798 enum GNUNET_TESTING_Topology
801 * A clique (everyone connected to everyone else).
803 GNUNET_TESTING_TOPOLOGY_CLIQUE,
806 * Small-world network (2d torus plus random links).
808 GNUNET_TESTING_TOPOLOGY_SMALL_WORLD,
811 * Small-world network (ring plus random links).
813 GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING,
818 GNUNET_TESTING_TOPOLOGY_RING,
823 GNUNET_TESTING_TOPOLOGY_2D_TORUS,
828 GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI,
831 * Certain percentage of peers are unable to communicate directly
832 * replicating NAT conditions
834 GNUNET_TESTING_TOPOLOGY_INTERNAT,
837 * Scale free topology.
839 GNUNET_TESTING_TOPOLOGY_SCALE_FREE,
842 * Straight line topology.
844 GNUNET_TESTING_TOPOLOGY_LINE,
847 * All peers are disconnected.
849 GNUNET_TESTING_TOPOLOGY_NONE,
852 * Read a topology from a given file.
854 GNUNET_TESTING_TOPOLOGY_FROM_FILE
858 * Options for connecting a topology.
860 enum GNUNET_TESTING_TopologyOption
863 * Try to connect all peers specified in the topology.
865 GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
868 * Choose a random subset of connections to create.
870 GNUNET_TESTING_TOPOLOGY_OPTION_RANDOM,
873 * Create at least X connections for each peer.
875 GNUNET_TESTING_TOPOLOGY_OPTION_MINIMUM,
878 * Using a depth first search, create one connection
879 * per peer. If any are missed (graph disconnected)
880 * start over at those peers until all have at least one
883 GNUNET_TESTING_TOPOLOGY_OPTION_DFS,
886 * Find the N closest peers to each allowed peer in the
887 * topology and make sure a connection to those peers
888 * exists in the connect topology.
890 GNUNET_TESTING_TOPOLOGY_OPTION_ADD_CLOSEST,
893 * No options specified.
895 GNUNET_TESTING_TOPOLOGY_OPTION_NONE
900 * Get a topology from a string input.
902 * @param topology where to write the retrieved topology
903 * @param topology_string The string to attempt to
904 * get a configuration value from
905 * @return GNUNET_YES if topology string matched a
906 * known topology, GNUNET_NO if not
909 GNUNET_TESTING_topology_get(enum GNUNET_TESTING_Topology *topology,
910 const char * topology_string);
913 * Get connect topology option from string input.
915 * @param topology_option where to write the retrieved topology
916 * @param topology_string The string to attempt to
917 * get a configuration value from
918 * @return GNUNET_YES if topology string matched a
919 * known topology, GNUNET_NO if not
922 GNUNET_TESTING_topology_option_get(enum GNUNET_TESTING_TopologyOption *topology_option,
923 const char * topology_string);
927 * Takes a peer group and creates a topology based on the
928 * one specified. Creates a topology means generates friend
929 * files for the peers so they can only connect to those allowed
930 * by the topology. This will only have an effect once peers
931 * are started if the FRIENDS_ONLY option is set in the base
934 * Also takes an optional restrict topology which
935 * disallows direct connections UNLESS they are specified in
936 * the restricted topology.
938 * A simple example; if the topology option is set to LINE
939 * peers can ONLY connect in a LINE. However, if the topology
940 * option is set to 2D-torus and the restrict option is set to
941 * line with restrict_transports equal to "tcp udp", then peers
942 * may connect in a 2D-torus, but will be restricted to tcp and
943 * udp connections only in a LINE. Generally it only makes
944 * sense to do this if restrict_topology is a subset of topology.
946 * For testing peer discovery, etc. it is generally better to
947 * leave restrict_topology as GNUNET_TESTING_TOPOLOGY_NONE and
948 * then use the connect_topology function to restrict the initial
951 * @param pg the peer group struct representing the running peers
952 * @param topology which topology to connect the peers in
953 * @param restrict_topology allow only direct connections in this topology,
954 * based on those listed in restrict_transports, set to
955 * GNUNET_TESTING_TOPOLOGY_NONE for no restrictions
956 * @param restrict_transports space delimited list of transports to blacklist
957 * to create restricted topology, NULL for none
959 * @return the maximum number of connections were all allowed peers
960 * connected to each other
963 GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
964 enum GNUNET_TESTING_Topology topology,
965 enum GNUNET_TESTING_Topology restrict_topology,
966 const char *restrict_transports);
969 * Iterate over all (running) peers in the peer group, retrieve
970 * all connections that each currently has.
972 * @param pg the peer group we are concerned with
973 * @param cb callback for topology information
974 * @param cls closure for callback
977 GNUNET_TESTING_get_topology (struct GNUNET_TESTING_PeerGroup *pg,
978 GNUNET_TESTING_NotifyTopology cb, void *cls);
981 * Stop the connection process temporarily.
983 * @param pg the peer group to stop connecting
985 void GNUNET_TESTING_stop_connections(struct GNUNET_TESTING_PeerGroup *pg);
988 * Resume the connection process.
990 * @param pg the peer group to resume connecting
992 void GNUNET_TESTING_resume_connections(struct GNUNET_TESTING_PeerGroup *pg);
995 * There are many ways to connect peers that are supported by this function.
996 * To connect peers in the same topology that was created via the
997 * GNUNET_TESTING_create_topology, the topology variable must be set to
998 * GNUNET_TESTING_TOPOLOGY_NONE. If the topology variable is specified,
999 * a new instance of that topology will be generated and attempted to be
1000 * connected. This could result in some connections being impossible,
1001 * because some topologies are non-deterministic.
1003 * @param pg the peer group struct representing the running peers
1004 * @param topology which topology to connect the peers in
1005 * @param options options for connecting the topology
1006 * @param option_modifier modifier for options that take a parameter
1007 * @param connect_timeout how long to wait before giving up on connecting
1009 * @param connect_attempts how many times to attempt to connect two peers
1010 * over the connect_timeout duration
1011 * @param notify_callback notification to be called once all connections completed
1012 * @param notify_cls closure for notification callback
1014 * @return the number of connections that will be attempted, GNUNET_SYSERR on error
1017 GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg,
1018 enum GNUNET_TESTING_Topology topology,
1019 enum GNUNET_TESTING_TopologyOption options,
1020 double option_modifier,
1021 struct GNUNET_TIME_Relative connect_timeout,
1022 unsigned int connect_attempts,
1023 GNUNET_TESTING_NotifyCompletion
1024 notify_callback, void *notify_cls);
1027 * Start or stop an individual peer from the given group.
1029 * @param pg handle to the peer group
1030 * @param offset which peer to start or stop
1031 * @param desired_status GNUNET_YES to have it running, GNUNET_NO to stop it
1032 * @param timeout how long to wait for shutdown
1033 * @param cb function to call at the end
1034 * @param cb_cls closure for cb
1037 GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg,
1038 unsigned int offset,
1040 struct GNUNET_TIME_Relative timeout,
1041 GNUNET_TESTING_NotifyCompletion cb,
1045 * Start a peer group with a given number of peers. Notify
1046 * on completion of peer startup and connection based on given
1047 * topological constraints. Optionally notify on each
1048 * established connection.
1050 * @param cfg configuration template to use
1051 * @param total number of daemons to start
1052 * @param timeout total time allowed for peers to start
1053 * @param connect_cb function to call each time two daemons are connected
1054 * @param peergroup_cb function to call once all peers are up and connected
1055 * @param peergroup_cls closure for peergroup callbacks
1056 * @param hostnames linked list of host structs to use to start peers on
1057 * (NULL to run on localhost only)
1059 * @return NULL on error, otherwise handle to control peer group
1061 struct GNUNET_TESTING_PeerGroup *
1062 GNUNET_TESTING_peergroup_start(
1063 const struct GNUNET_CONFIGURATION_Handle *cfg,
1065 struct GNUNET_TIME_Relative timeout,
1066 GNUNET_TESTING_NotifyConnection connect_cb,
1067 GNUNET_TESTING_NotifyCompletion peergroup_cb,
1068 void *peergroup_cls,
1069 const struct GNUNET_TESTING_Host *hostnames);
1072 * Print current topology to a graphviz readable file.
1074 * @param pg a currently running peergroup to print to file
1075 * @param output_filename the file to write the topology to
1076 * @param notify_cb callback to call upon completion or failure
1077 * @param notify_cb_cls closure for notify_cb
1081 GNUNET_TESTING_peergroup_topology_to_file(struct GNUNET_TESTING_PeerGroup *pg,
1082 const char *output_filename,
1083 GNUNET_TESTING_NotifyCompletion notify_cb,
1084 void *notify_cb_cls);
1087 #if 0 /* keep Emacsens' auto-indent happy */