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,
93 GNUNET_PeerIdentity * id,
95 GNUNET_TESTING_Daemon * d,
99 * Prototype of a function that will be called whenever
100 * a daemon was started by the testing library.
103 * @param id identifier for the daemon, NULL on error
104 * @param cfg configuration used by this daemon
105 * @param d handle for the daemon
106 * @param emsg error message (NULL on success)
108 typedef void (*GNUNET_TESTING_NotifyDaemonRunning) (void *cls,
110 GNUNET_PeerIdentity * id,
112 GNUNET_CONFIGURATION_Handle
114 struct GNUNET_TESTING_Daemon
115 * d, const char *emsg);
119 * Handle to an entire testbed of GNUnet peers.
121 struct GNUNET_TESTING_Testbed;
124 * Phases of starting GNUnet on a system.
126 enum GNUNET_TESTING_StartPhase
129 * Copy the configuration file to the target system.
134 * Configuration file has been copied, generate hostkey.
139 * Create the hostkey for the peer.
144 * Hostkey generated, wait for topology to be finished.
149 * Topology has been created, now start ARM.
154 * ARM has been started, check that it has properly daemonized and
155 * then try to connect to the CORE service (which should be
156 * auto-started by ARM).
161 * We're waiting for CORE to start.
166 * CORE is up, now make sure we get the HELLO for this peer.
171 * Core has notified us that we've established a connection to the service.
172 * The main FSM halts here and waits to be moved to UPDATE or CLEANUP.
177 * We've been asked to terminate the instance and are now waiting for
178 * the remote command to stop the gnunet-arm process and delete temporary
184 * We should shutdown a *single* service via gnunet-arm. Call the dead_cb
185 * upon notification from gnunet-arm that the service has been stopped.
187 SP_SERVICE_SHUTDOWN_START,
190 * We should start a *single* service via gnunet-arm. Call the daemon cb
191 * upon notification from gnunet-arm that the service has been started.
196 * We've received a configuration update and are currently waiting for
197 * the copy process for the update to complete. Once it is, we will
198 * return to "SP_START_DONE" (and rely on ARM to restart all affected
205 * Prototype of a function that will be called when a
206 * particular operation was completed the testing library.
209 * @param emsg NULL on success
211 typedef void (*GNUNET_TESTING_NotifyCompletion) (void *cls, const char *emsg);
214 * Prototype of a function that will be called with the
215 * number of connections created for a particular topology.
218 * @param num_connections the number of connections created
220 typedef void (*GNUNET_TESTING_NotifyConnections) (void *cls,
221 unsigned int num_connections);
224 * Handle for a GNUnet daemon (technically a set of
225 * daemons; the handle is really for the master ARM
226 * daemon) started by the testing library.
228 struct GNUNET_TESTING_Daemon
233 struct GNUNET_CONFIGURATION_Handle *cfg;
236 * At what time to give up starting the peer
238 struct GNUNET_TIME_Absolute max_timeout;
241 * Host to run GNUnet on.
246 * Port to use for ssh, NULL to let system choose default.
251 * Result of GNUNET_i2s of this peer,
257 * Username we are using.
262 * Name of the configuration file
267 * Callback to inform initiator that the peer's
268 * hostkey has been created.
270 GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback;
273 * Closure for hostkey creation callback.
278 * Function to call when the peer is running.
280 GNUNET_TESTING_NotifyDaemonRunning cb;
288 * Arguments from "daemon_stop" call.
290 GNUNET_TESTING_NotifyCompletion dead_cb;
293 * Closure for 'dead_cb'.
298 * Arguments from "daemon_stop" call.
300 GNUNET_TESTING_NotifyCompletion update_cb;
303 * Closure for 'update_cb'.
308 * Identity of this peer (once started).
310 struct GNUNET_PeerIdentity id;
313 * Flag to indicate that we've already been asked
314 * to terminate (but could not because some action
315 * was still pending).
320 * GNUNET_YES if the hostkey has been created
321 * for this peer, GNUNET_NO otherwise.
326 * PID of the process that we started last.
328 struct GNUNET_OS_Process *proc;
331 * In which phase are we during the start of
334 enum GNUNET_TESTING_StartPhase phase;
337 * ID of the current task.
339 GNUNET_SCHEDULER_TaskIdentifier task;
342 * Handle to the server.
344 struct GNUNET_CORE_Handle *server;
347 * Handle to the transport service of this peer
349 struct GNUNET_TRANSPORT_Handle *th;
352 * HELLO message for this peer
354 struct GNUNET_HELLO_Message *hello;
357 * Handle to a pipe for reading the hostkey.
359 struct GNUNET_DISK_PipeHandle *pipe_stdout;
362 * Output from gnunet-peerinfo is read into this buffer.
364 char hostkeybuf[105];
367 * Current position in 'hostkeybuf' (for reading from gnunet-peerinfo)
369 unsigned int hostkeybufpos;
372 * Set to GNUNET_YES once the peer is up.
377 * Used to tell shutdown not to remove configuration for the peer
378 * (if it's going to be restarted later)
383 * Currently, a single char * pointing to a service
384 * that has been churned off.
386 * FIXME: make this a linked list of services that have been churned off!!!
388 char *churned_services;
393 * Handle to a group of GNUnet peers.
395 struct GNUNET_TESTING_PeerGroup;
399 * Prototype of a function that will be called whenever
400 * two daemons are connected by the testing library.
403 * @param first peer id for first daemon
404 * @param second peer id for the second daemon
405 * @param distance distance between the connected peers
406 * @param first_cfg config for the first daemon
407 * @param second_cfg config for the second daemon
408 * @param first_daemon handle for the first daemon
409 * @param second_daemon handle for the second daemon
410 * @param emsg error message (NULL on success)
412 typedef void (*GNUNET_TESTING_NotifyConnection) (void *cls,
414 GNUNET_PeerIdentity * first,
416 GNUNET_PeerIdentity * second,
419 GNUNET_CONFIGURATION_Handle *
422 GNUNET_CONFIGURATION_Handle *
424 struct GNUNET_TESTING_Daemon *
426 struct GNUNET_TESTING_Daemon *
431 * Prototype of a callback function indicating that two peers
432 * are currently connected.
435 * @param first peer id for first daemon
436 * @param second peer id for the second daemon
437 * @param distance distance between the connected peers
438 * @param emsg error message (NULL on success)
440 typedef void (*GNUNET_TESTING_NotifyTopology) (void *cls,
441 const struct GNUNET_PeerIdentity
443 const struct GNUNET_PeerIdentity
444 * second, const char *emsg);
447 * Starts a GNUnet daemon. GNUnet must be installed on the target
448 * system and available in the PATH. The machine must furthermore be
449 * reachable via "ssh" (unless the hostname is "NULL") without the
450 * need to enter a password.
452 * @param cfg configuration to use
453 * @param timeout how long to wait starting up peers
454 * @param pretend GNUNET_YES to set up files but not start peer GNUNET_NO
455 * to really start the peer (default)
456 * @param hostname name of the machine where to run GNUnet
457 * (use NULL for localhost).
458 * @param ssh_username ssh username to use when connecting to hostname
459 * @param sshport port to pass to ssh process when connecting to hostname
460 * @param hostkey pointer to a hostkey to be written to disk (instead of being generated)
461 * @param hostkey_callback function to call once the hostkey has been
462 * generated for this peer, but it hasn't yet been started
463 * (NULL to start immediately, otherwise waits on GNUNET_TESTING_daemon_continue_start)
464 * @param hostkey_cls closure for hostkey callback
465 * @param cb function to call once peer is up, or failed to start
466 * @param cb_cls closure for cb
467 * @return handle to the daemon (actual start will be completed asynchronously)
469 struct GNUNET_TESTING_Daemon *
470 GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
471 struct GNUNET_TIME_Relative timeout, int pretend,
472 const char *hostname, const char *ssh_username,
473 uint16_t sshport, const char *hostkey,
474 GNUNET_TESTING_NotifyHostkeyCreated
475 hostkey_callback, void *hostkey_cls,
476 GNUNET_TESTING_NotifyDaemonRunning cb,
480 * Continues GNUnet daemon startup when user wanted to be notified
481 * once a hostkey was generated (for creating friends files, blacklists,
484 * @param daemon the daemon to finish starting
487 GNUNET_TESTING_daemon_continue_startup (struct GNUNET_TESTING_Daemon *daemon);
490 * Check whether the given daemon is running.
492 * @param daemon the daemon to check
494 * @return GNUNET_YES if the daemon is up, GNUNET_NO if the
495 * daemon is down, GNUNET_SYSERR on error.
498 GNUNET_TESTING_daemon_running (struct GNUNET_TESTING_Daemon *daemon);
501 * Restart (stop and start) a GNUnet daemon.
503 * @param d the daemon that should be restarted
504 * @param cb function called once the daemon is (re)started
505 * @param cb_cls closure for cb
508 GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d,
509 GNUNET_TESTING_NotifyDaemonRunning cb,
513 * Start a peer that has previously been stopped using the daemon_stop
514 * call (and files weren't deleted and the allow restart flag)
516 * @param daemon the daemon to start (has been previously stopped)
517 * @param timeout how long to wait for restart
518 * @param cb the callback for notification when the peer is running
519 * @param cb_cls closure for the callback
522 GNUNET_TESTING_daemon_start_stopped (struct GNUNET_TESTING_Daemon *daemon,
523 struct GNUNET_TIME_Relative timeout,
524 GNUNET_TESTING_NotifyDaemonRunning cb,
528 * Starts a GNUnet daemon's service.
530 * @param d the daemon for which the service should be started
531 * @param service the name of the service to start
532 * @param timeout how long to wait for process for startup
533 * @param cb function called once gnunet-arm returns
534 * @param cb_cls closure for cb
537 GNUNET_TESTING_daemon_start_service (struct GNUNET_TESTING_Daemon *d,
539 struct GNUNET_TIME_Relative timeout,
540 GNUNET_TESTING_NotifyDaemonRunning cb,
544 * Starts a GNUnet daemon's service which has been previously turned off.
546 * @param d the daemon for which the service should be started
547 * @param service the name of the service to start
548 * @param timeout how long to wait for process for startup
549 * @param cb function called once gnunet-arm returns
550 * @param cb_cls closure for cb
553 GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d,
555 struct GNUNET_TIME_Relative
557 GNUNET_TESTING_NotifyDaemonRunning
561 * Get a certain testing daemon handle.
563 * @param pg handle to the set of running peers
564 * @param position the number of the peer to return
566 struct GNUNET_TESTING_Daemon *
567 GNUNET_TESTING_daemon_get (struct GNUNET_TESTING_PeerGroup *pg,
568 unsigned int position);
571 * Get a daemon by peer identity, so callers can
572 * retrieve the daemon without knowing it's offset.
574 * @param pg the peer group to retrieve the daemon from
575 * @param peer_id the peer identity of the daemon to retrieve
577 * @return the daemon on success, or NULL if no such peer identity is found
579 struct GNUNET_TESTING_Daemon *
580 GNUNET_TESTING_daemon_get_by_id (struct GNUNET_TESTING_PeerGroup *pg,
581 struct GNUNET_PeerIdentity *peer_id);
584 * Stops a GNUnet daemon.
586 * @param d the daemon that should be stopped
587 * @param timeout how long to wait for process for shutdown to complete
588 * @param cb function called once the daemon was stopped
589 * @param cb_cls closure for cb
590 * @param delete_files GNUNET_YES to remove files, GNUNET_NO
591 * to leave them (i.e. for restarting at a later time,
592 * or logfile inspection once finished)
593 * @param allow_restart GNUNET_YES to restart peer later (using this API)
594 * GNUNET_NO to kill off and clean up for good
597 GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
598 struct GNUNET_TIME_Relative timeout,
599 GNUNET_TESTING_NotifyCompletion cb, void *cb_cls,
600 int delete_files, int allow_restart);
604 * Changes the configuration of a GNUnet daemon.
606 * @param d the daemon that should be modified
607 * @param cfg the new configuration for the daemon
608 * @param cb function called once the configuration was changed
609 * @param cb_cls closure for cb
612 GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d,
613 struct GNUNET_CONFIGURATION_Handle *cfg,
614 GNUNET_TESTING_NotifyCompletion cb,
618 * Stops a single service of a GNUnet daemon. Used like daemon_stop,
619 * only doesn't stop the entire peer in any case. If the service
620 * is not currently running, this call is likely to fail after
623 * @param d the daemon that should be stopped
624 * @param service the name of the service to stop
625 * @param timeout how long to wait for process for shutdown to complete
626 * @param cb function called once the service was stopped
627 * @param cb_cls closure for cb
630 GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d,
632 struct GNUNET_TIME_Relative timeout,
633 GNUNET_TESTING_NotifyCompletion cb,
637 * Read a testing hosts file based on a configuration.
638 * Returns a DLL of hosts (caller must free!) on success
639 * or NULL on failure.
641 * @param cfg a configuration with a testing section
643 * @return DLL of hosts on success, NULL on failure
645 struct GNUNET_TESTING_Host *
646 GNUNET_TESTING_hosts_load (const struct GNUNET_CONFIGURATION_Handle *cfg);
650 * Start count gnunet instances with the same set of transports and
651 * applications. The port numbers (any option called "PORT") will be
652 * adjusted to ensure that no two peers running on the same system
653 * have the same port(s) in their respective configurations.
655 * @param cfg configuration template to use
656 * @param total number of daemons to start
657 * @param max_concurrent_connections for testing, how many peers can
658 * we connect to simultaneously
659 * @param max_concurrent_ssh when starting with ssh, how many ssh
660 * connections will we allow at once (based on remote hosts allowed!)
661 * @param timeout total time allowed for peers to start
662 * @param hostkey_callback function to call on each peers hostkey generation
663 * if NULL, peers will be started by this call, if non-null,
664 * GNUNET_TESTING_daemons_continue_startup must be called after
665 * successful hostkey generation
666 * @param hostkey_cls closure for hostkey callback
667 * @param cb function to call on each daemon that was started
668 * @param cb_cls closure for cb
669 * @param connect_callback function to call each time two hosts are connected
670 * @param connect_callback_cls closure for connect_callback
671 * @param hostnames linked list of host structs to use to start peers on
672 * (NULL to run on localhost only)
674 * @return NULL on error, otherwise handle to control peer group
676 struct GNUNET_TESTING_PeerGroup *
677 GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
679 unsigned int max_concurrent_connections,
680 unsigned int max_concurrent_ssh,
681 struct GNUNET_TIME_Relative timeout,
682 GNUNET_TESTING_NotifyHostkeyCreated
683 hostkey_callback, void *hostkey_cls,
684 GNUNET_TESTING_NotifyDaemonRunning cb,
686 GNUNET_TESTING_NotifyConnection connect_callback,
687 void *connect_callback_cls,
688 const struct GNUNET_TESTING_Host *hostnames);
691 * Function which continues a peer group starting up
692 * after successfully generating hostkeys for each peer.
694 * @param pg the peer group to continue starting
697 GNUNET_TESTING_daemons_continue_startup (struct GNUNET_TESTING_PeerGroup *pg);
701 * Establish a connection between two GNUnet daemons.
703 * @param d1 handle for the first daemon
704 * @param d2 handle for the second daemon
705 * @param timeout how long is the connection attempt
707 * @param max_connect_attempts how many times should we try to reconnect
709 * @param send_hello GNUNET_YES to send the HELLO, GNUNET_NO to assume
710 * the HELLO has already been exchanged
711 * @param cb function to call at the end
712 * @param cb_cls closure for cb
715 GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
716 struct GNUNET_TESTING_Daemon *d2,
717 struct GNUNET_TIME_Relative timeout,
718 unsigned int max_connect_attempts,
720 GNUNET_TESTING_NotifyConnection cb,
725 * Restart all peers in the given group.
727 * @param pg the handle to the peer group
728 * @param callback function to call on completion (or failure)
729 * @param callback_cls closure for the callback function
732 GNUNET_TESTING_daemons_restart (struct GNUNET_TESTING_PeerGroup *pg,
733 GNUNET_TESTING_NotifyCompletion callback,
738 * Shutdown all peers started in the given group.
740 * @param pg handle to the peer group
741 * @param timeout how long to wait for shutdown
742 * @param cb callback to notify upon success or failure
743 * @param cb_cls closure for cb
746 GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg,
747 struct GNUNET_TIME_Relative timeout,
748 GNUNET_TESTING_NotifyCompletion cb, void *cb_cls);
752 * Count the number of running peers.
754 * @param pg handle for the peer group
756 * @return the number of currently running peers in the peer group
759 GNUNET_TESTING_daemons_running (struct GNUNET_TESTING_PeerGroup *pg);
762 * Simulate churn by stopping some peers (and possibly
763 * re-starting others if churn is called multiple times). This
764 * function can only be used to create leave-join churn (peers "never"
765 * leave for good). First "voff" random peers that are currently
766 * online will be taken offline; then "von" random peers that are then
767 * offline will be put back online. No notifications will be
768 * generated for any of these operations except for the callback upon
769 * completion. Note that the implementation is at liberty to keep
770 * the ARM service itself (but none of the other services or daemons)
771 * running even though the "peer" is being varied offline.
773 * @param pg handle for the peer group
774 * @param service the service to churn on/off, NULL for all
775 * @param voff number of peers that should go offline
776 * @param von number of peers that should come back online;
777 * must be zero on first call (since "testbed_start"
778 * always starts all of the peers)
779 * @param timeout how long to wait for operations to finish before
781 * @param cb function to call at the end
782 * @param cb_cls closure for cb
785 GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
786 char *service, unsigned int voff,
788 struct GNUNET_TIME_Relative timeout,
789 GNUNET_TESTING_NotifyCompletion cb, void *cb_cls);
791 * Start a given service for each of the peers in the peer group.
793 * @param pg handle for the peer group
794 * @param service the service to start
795 * @param timeout how long to wait for operations to finish before
797 * @param cb function to call once finished
798 * @param cb_cls closure for cb
802 GNUNET_TESTING_daemons_start_service (struct GNUNET_TESTING_PeerGroup *pg,
804 struct GNUNET_TIME_Relative timeout,
805 GNUNET_TESTING_NotifyCompletion cb,
809 * Callback function to process statistic values.
812 * @param peer the peer the statistics belong to
813 * @param subsystem name of subsystem that created the statistic
814 * @param name the name of the datum
815 * @param value the current value
816 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
817 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
819 typedef int (*GNUNET_TESTING_STATISTICS_Iterator) (void *cls,
821 GNUNET_PeerIdentity * peer,
822 const char *subsystem,
828 * Iterate over all (running) peers in the peer group, retrieve
829 * all statistics from each.
831 * @param pg the peergroup to iterate statistics of
832 * @param cont continuation to call once call is completed(?)
833 * @param proc processing function for each statistic retrieved
834 * @param cls closure to pass to proc
837 GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg,
838 GNUNET_STATISTICS_Callback cont,
839 GNUNET_TESTING_STATISTICS_Iterator proc,
843 * Topologies supported for testbeds.
845 enum GNUNET_TESTING_Topology
848 * A clique (everyone connected to everyone else).
850 GNUNET_TESTING_TOPOLOGY_CLIQUE,
853 * Small-world network (2d torus plus random links).
855 GNUNET_TESTING_TOPOLOGY_SMALL_WORLD,
858 * Small-world network (ring plus random links).
860 GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING,
865 GNUNET_TESTING_TOPOLOGY_RING,
870 GNUNET_TESTING_TOPOLOGY_2D_TORUS,
875 GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI,
878 * Certain percentage of peers are unable to communicate directly
879 * replicating NAT conditions
881 GNUNET_TESTING_TOPOLOGY_INTERNAT,
884 * Scale free topology.
886 GNUNET_TESTING_TOPOLOGY_SCALE_FREE,
889 * Straight line topology.
891 GNUNET_TESTING_TOPOLOGY_LINE,
894 * All peers are disconnected.
896 GNUNET_TESTING_TOPOLOGY_NONE,
899 * Read a topology from a given file.
901 GNUNET_TESTING_TOPOLOGY_FROM_FILE
905 * Options for connecting a topology.
907 enum GNUNET_TESTING_TopologyOption
910 * Try to connect all peers specified in the topology.
912 GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
915 * Choose a random subset of connections to create.
917 GNUNET_TESTING_TOPOLOGY_OPTION_RANDOM,
920 * Create at least X connections for each peer.
922 GNUNET_TESTING_TOPOLOGY_OPTION_MINIMUM,
925 * Using a depth first search, create one connection
926 * per peer. If any are missed (graph disconnected)
927 * start over at those peers until all have at least one
930 GNUNET_TESTING_TOPOLOGY_OPTION_DFS,
933 * Find the N closest peers to each allowed peer in the
934 * topology and make sure a connection to those peers
935 * exists in the connect topology.
937 GNUNET_TESTING_TOPOLOGY_OPTION_ADD_CLOSEST,
940 * No options specified.
942 GNUNET_TESTING_TOPOLOGY_OPTION_NONE
947 * Get a topology from a string input.
949 * @param topology where to write the retrieved topology
950 * @param topology_string The string to attempt to
951 * get a configuration value from
952 * @return GNUNET_YES if topology string matched a
953 * known topology, GNUNET_NO if not
956 GNUNET_TESTING_topology_get (enum GNUNET_TESTING_Topology *topology,
957 const char *topology_string);
960 * Get connect topology option from string input.
962 * @param topology_option where to write the retrieved topology
963 * @param topology_string The string to attempt to
964 * get a configuration value from
965 * @return GNUNET_YES if topology string matched a
966 * known topology, GNUNET_NO if not
969 GNUNET_TESTING_topology_option_get (enum GNUNET_TESTING_TopologyOption
971 const char *topology_string);
975 * Takes a peer group and creates a topology based on the
976 * one specified. Creates a topology means generates friend
977 * files for the peers so they can only connect to those allowed
978 * by the topology. This will only have an effect once peers
979 * are started if the FRIENDS_ONLY option is set in the base
982 * Also takes an optional restrict topology which
983 * disallows direct connections UNLESS they are specified in
984 * the restricted topology.
986 * A simple example; if the topology option is set to LINE
987 * peers can ONLY connect in a LINE. However, if the topology
988 * option is set to 2D-torus and the restrict option is set to
989 * line with restrict_transports equal to "tcp udp", then peers
990 * may connect in a 2D-torus, but will be restricted to tcp and
991 * udp connections only in a LINE. Generally it only makes
992 * sense to do this if restrict_topology is a subset of topology.
994 * For testing peer discovery, etc. it is generally better to
995 * leave restrict_topology as GNUNET_TESTING_TOPOLOGY_NONE and
996 * then use the connect_topology function to restrict the initial
999 * @param pg the peer group struct representing the running peers
1000 * @param topology which topology to connect the peers in
1001 * @param restrict_topology allow only direct connections in this topology,
1002 * based on those listed in restrict_transports, set to
1003 * GNUNET_TESTING_TOPOLOGY_NONE for no restrictions
1004 * @param restrict_transports space delimited list of transports to blacklist
1005 * to create restricted topology, NULL for none
1007 * @return the maximum number of connections were all allowed peers
1008 * connected to each other
1011 GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
1012 enum GNUNET_TESTING_Topology topology,
1013 enum GNUNET_TESTING_Topology restrict_topology,
1014 const char *restrict_transports);
1017 * Iterate over all (running) peers in the peer group, retrieve
1018 * all connections that each currently has.
1020 * @param pg the peer group we are concerned with
1021 * @param cb callback for topology information
1022 * @param cls closure for callback
1025 GNUNET_TESTING_get_topology (struct GNUNET_TESTING_PeerGroup *pg,
1026 GNUNET_TESTING_NotifyTopology cb, void *cls);
1029 * Stop the connection process temporarily.
1031 * @param pg the peer group to stop connecting
1034 GNUNET_TESTING_stop_connections (struct GNUNET_TESTING_PeerGroup *pg);
1037 * Resume the connection process.
1039 * @param pg the peer group to resume connecting
1042 GNUNET_TESTING_resume_connections (struct GNUNET_TESTING_PeerGroup *pg);
1045 * There are many ways to connect peers that are supported by this function.
1046 * To connect peers in the same topology that was created via the
1047 * GNUNET_TESTING_create_topology, the topology variable must be set to
1048 * GNUNET_TESTING_TOPOLOGY_NONE. If the topology variable is specified,
1049 * a new instance of that topology will be generated and attempted to be
1050 * connected. This could result in some connections being impossible,
1051 * because some topologies are non-deterministic.
1053 * @param pg the peer group struct representing the running peers
1054 * @param topology which topology to connect the peers in
1055 * @param options options for connecting the topology
1056 * @param option_modifier modifier for options that take a parameter
1057 * @param connect_timeout how long to wait before giving up on connecting
1059 * @param connect_attempts how many times to attempt to connect two peers
1060 * over the connect_timeout duration
1061 * @param notify_callback notification to be called once all connections completed
1062 * @param notify_cls closure for notification callback
1064 * @return the number of connections that will be attempted, GNUNET_SYSERR on error
1067 GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg,
1068 enum GNUNET_TESTING_Topology topology,
1069 enum GNUNET_TESTING_TopologyOption options,
1070 double option_modifier,
1071 struct GNUNET_TIME_Relative connect_timeout,
1072 unsigned int connect_attempts,
1073 GNUNET_TESTING_NotifyCompletion
1074 notify_callback, void *notify_cls);
1077 * Start or stop an individual peer from the given group.
1079 * @param pg handle to the peer group
1080 * @param offset which peer to start or stop
1081 * @param desired_status GNUNET_YES to have it running, GNUNET_NO to stop it
1082 * @param timeout how long to wait for shutdown
1083 * @param cb function to call at the end
1084 * @param cb_cls closure for cb
1087 GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg,
1088 unsigned int offset, int desired_status,
1089 struct GNUNET_TIME_Relative timeout,
1090 GNUNET_TESTING_NotifyCompletion cb, void *cb_cls);
1093 * Start a peer group with a given number of peers. Notify
1094 * on completion of peer startup and connection based on given
1095 * topological constraints. Optionally notify on each
1096 * established connection.
1098 * @param cfg configuration template to use
1099 * @param total number of daemons to start
1100 * @param timeout total time allowed for peers to start
1101 * @param connect_cb function to call each time two daemons are connected
1102 * @param peergroup_cb function to call once all peers are up and connected
1103 * @param peergroup_cls closure for peergroup callbacks
1104 * @param hostnames linked list of host structs to use to start peers on
1105 * (NULL to run on localhost only)
1107 * @return NULL on error, otherwise handle to control peer group
1109 struct GNUNET_TESTING_PeerGroup *
1110 GNUNET_TESTING_peergroup_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1112 struct GNUNET_TIME_Relative timeout,
1113 GNUNET_TESTING_NotifyConnection connect_cb,
1114 GNUNET_TESTING_NotifyCompletion peergroup_cb,
1115 void *peergroup_cls,
1116 const struct GNUNET_TESTING_Host *hostnames);
1119 * Print current topology to a graphviz readable file.
1121 * @param pg a currently running peergroup to print to file
1122 * @param output_filename the file to write the topology to
1123 * @param notify_cb callback to call upon completion or failure
1124 * @param notify_cb_cls closure for notify_cb
1128 GNUNET_TESTING_peergroup_topology_to_file (struct GNUNET_TESTING_PeerGroup *pg,
1129 const char *output_filename,
1130 GNUNET_TESTING_NotifyCompletion
1131 notify_cb, void *notify_cb_cls);
1134 #if 0 /* keep Emacsens' auto-indent happy */