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);
118 * Handle to an entire testbed of GNUnet peers.
120 struct GNUNET_TESTING_Testbed;
123 * Phases of starting GNUnet on a system.
125 enum GNUNET_TESTING_StartPhase
128 * Copy the configuration file to the target system.
133 * Configuration file has been copied, generate hostkey.
138 * Create the hostkey for the peer.
143 * Hostkey generated, wait for topology to be finished.
148 * Topology has been created, now start ARM.
153 * ARM has been started, check that it has properly daemonized and
154 * then try to connect to the CORE service (which should be
155 * auto-started by ARM).
160 * We're waiting for CORE to start.
165 * CORE is up, now make sure we get the HELLO for this peer.
170 * Core has notified us that we've established a connection to the service.
171 * The main FSM halts here and waits to be moved to UPDATE or CLEANUP.
176 * We've been asked to terminate the instance and are now waiting for
177 * the remote command to stop the gnunet-arm process and delete temporary
183 * We should shutdown a *single* service via gnunet-arm. Call the dead_cb
184 * upon notification from gnunet-arm that the service has been stopped.
186 SP_SERVICE_SHUTDOWN_START,
189 * We should start a *single* service via gnunet-arm. Call the daemon cb
190 * upon notification from gnunet-arm that the service has been started.
195 * We've received a configuration update and are currently waiting for
196 * the copy process for the update to complete. Once it is, we will
197 * return to "SP_START_DONE" (and rely on ARM to restart all affected
204 * Prototype of a function that will be called when a
205 * particular operation was completed the testing library.
208 * @param emsg NULL on success
210 typedef void (*GNUNET_TESTING_NotifyCompletion) (void *cls, const char *emsg);
213 * Prototype of a function that will be called with the
214 * number of connections created for a particular topology.
217 * @param num_connections the number of connections created
219 typedef void (*GNUNET_TESTING_NotifyConnections) (void *cls,
220 unsigned int num_connections);
223 * Handle for a GNUnet daemon (technically a set of
224 * daemons; the handle is really for the master ARM
225 * daemon) started by the testing library.
227 struct GNUNET_TESTING_Daemon
232 struct GNUNET_CONFIGURATION_Handle *cfg;
235 * At what time to give up starting the peer
237 struct GNUNET_TIME_Absolute max_timeout;
240 * Host to run GNUnet on.
245 * Port to use for ssh, NULL to let system choose default.
250 * Result of GNUNET_i2s of this peer,
256 * Username we are using.
261 * Name of the configuration file
266 * Callback to inform initiator that the peer's
267 * hostkey has been created.
269 GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback;
272 * Closure for hostkey creation callback.
277 * Function to call when the peer is running.
279 GNUNET_TESTING_NotifyDaemonRunning cb;
287 * Arguments from "daemon_stop" call.
289 GNUNET_TESTING_NotifyCompletion dead_cb;
292 * Closure for 'dead_cb'.
297 * Arguments from "daemon_stop" call.
299 GNUNET_TESTING_NotifyCompletion update_cb;
302 * Closure for 'update_cb'.
307 * PID of the process that we started last.
309 struct GNUNET_OS_Process *proc;
312 * Handle to the server.
314 struct GNUNET_CORE_Handle *server;
317 * Handle to the transport service of this peer
319 struct GNUNET_TRANSPORT_Handle *th;
322 * Handle for getting HELLOs from transport
324 struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
327 * HELLO message for this peer
329 struct GNUNET_HELLO_Message *hello;
332 * Handle to a pipe for reading the hostkey.
334 struct GNUNET_DISK_PipeHandle *pipe_stdout;
337 * Currently, a single char * pointing to a service
338 * that has been churned off.
340 * FIXME: make this a linked list of services that have been churned off!!!
342 char *churned_services;
345 * ID of the current task.
347 GNUNET_SCHEDULER_TaskIdentifier task;
350 * Identity of this peer (once started).
352 struct GNUNET_PeerIdentity id;
355 * Flag to indicate that we've already been asked
356 * to terminate (but could not because some action
357 * was still pending).
362 * GNUNET_YES if the hostkey has been created
363 * for this peer, GNUNET_NO otherwise.
368 * In which phase are we during the start of
371 enum GNUNET_TESTING_StartPhase phase;
374 * Current position in 'hostkeybuf' (for reading from gnunet-peerinfo)
376 unsigned int hostkeybufpos;
379 * Set to GNUNET_YES once the peer is up.
384 * Used to tell shutdown not to remove configuration for the peer
385 * (if it's going to be restarted later)
390 * Output from gnunet-peerinfo is read into this buffer.
392 char hostkeybuf[105];
398 * Handle to a group of GNUnet peers.
400 struct GNUNET_TESTING_PeerGroup;
404 * Prototype of a function that will be called whenever
405 * two daemons are connected by the testing library.
408 * @param first peer id for first daemon
409 * @param second peer id for the second daemon
410 * @param distance distance between the connected peers
411 * @param first_cfg config for the first daemon
412 * @param second_cfg config for the second daemon
413 * @param first_daemon handle for the first daemon
414 * @param second_daemon handle for the second daemon
415 * @param emsg error message (NULL on success)
417 typedef void (*GNUNET_TESTING_NotifyConnection) (void *cls,
419 GNUNET_PeerIdentity * first,
421 GNUNET_PeerIdentity * second,
424 GNUNET_CONFIGURATION_Handle *
427 GNUNET_CONFIGURATION_Handle *
429 struct GNUNET_TESTING_Daemon *
431 struct GNUNET_TESTING_Daemon *
437 * Prototype of a callback function indicating that two peers
438 * are currently connected.
441 * @param first peer id for first daemon
442 * @param second peer id for the second daemon
443 * @param distance distance between the connected peers
444 * @param emsg error message (NULL on success)
446 typedef void (*GNUNET_TESTING_NotifyTopology) (void *cls,
447 const struct GNUNET_PeerIdentity
449 const struct GNUNET_PeerIdentity
450 * second, const char *emsg);
454 * Starts a GNUnet daemon. GNUnet must be installed on the target
455 * system and available in the PATH. The machine must furthermore be
456 * reachable via "ssh" (unless the hostname is "NULL") without the
457 * need to enter a password.
459 * @param cfg configuration to use
460 * @param timeout how long to wait starting up peers
461 * @param pretend GNUNET_YES to set up files but not start peer GNUNET_NO
462 * to really start the peer (default)
463 * @param hostname name of the machine where to run GNUnet
464 * (use NULL for localhost).
465 * @param ssh_username ssh username to use when connecting to hostname
466 * @param sshport port to pass to ssh process when connecting to hostname
467 * @param hostkey pointer to a hostkey to be written to disk (instead of being generated)
468 * @param hostkey_callback function to call once the hostkey has been
469 * generated for this peer, but it hasn't yet been started
470 * (NULL to start immediately, otherwise waits on GNUNET_TESTING_daemon_continue_start)
471 * @param hostkey_cls closure for hostkey callback
472 * @param cb function to call once peer is up, or failed to start
473 * @param cb_cls closure for cb
474 * @return handle to the daemon (actual start will be completed asynchronously)
476 struct GNUNET_TESTING_Daemon *
477 GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
478 struct GNUNET_TIME_Relative timeout, int pretend,
479 const char *hostname, const char *ssh_username,
480 uint16_t sshport, const char *hostkey,
481 GNUNET_TESTING_NotifyHostkeyCreated
482 hostkey_callback, void *hostkey_cls,
483 GNUNET_TESTING_NotifyDaemonRunning cb,
487 * Continues GNUnet daemon startup when user wanted to be notified
488 * once a hostkey was generated (for creating friends files, blacklists,
491 * @param daemon the daemon to finish starting
494 GNUNET_TESTING_daemon_continue_startup (struct GNUNET_TESTING_Daemon *daemon);
498 * Check whether the given daemon is running.
500 * @param daemon the daemon to check
501 * @return GNUNET_YES if the daemon is up, GNUNET_NO if the
502 * daemon is down, GNUNET_SYSERR on error.
505 GNUNET_TESTING_test_daemon_running (struct GNUNET_TESTING_Daemon *daemon);
509 * Obtain the peer identity of the peer with the given configuration
510 * handle. This function reads the private key of the peer, obtains
511 * the public key and hashes it.
513 * @param cfg configuration of the peer
514 * @param pid where to store the peer identity
515 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
518 GNUNET_TESTING_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg,
519 struct GNUNET_PeerIdentity *pid);
523 * Restart (stop and start) a GNUnet daemon.
525 * @param d the daemon that should be restarted
526 * @param cb function called once the daemon is (re)started
527 * @param cb_cls closure for cb
530 GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d,
531 GNUNET_TESTING_NotifyDaemonRunning cb,
536 * Start a peer that has previously been stopped using the daemon_stop
537 * call (and files weren't deleted and the allow restart flag)
539 * @param daemon the daemon to start (has been previously stopped)
540 * @param timeout how long to wait for restart
541 * @param cb the callback for notification when the peer is running
542 * @param cb_cls closure for the callback
545 GNUNET_TESTING_daemon_start_stopped (struct GNUNET_TESTING_Daemon *daemon,
546 struct GNUNET_TIME_Relative timeout,
547 GNUNET_TESTING_NotifyDaemonRunning cb,
552 * Starts a GNUnet daemon's service.
554 * @param d the daemon for which the service should be started
555 * @param service the name of the service to start
556 * @param timeout how long to wait for process for startup
557 * @param cb function called once gnunet-arm returns
558 * @param cb_cls closure for cb
561 GNUNET_TESTING_daemon_start_service (struct GNUNET_TESTING_Daemon *d,
563 struct GNUNET_TIME_Relative timeout,
564 GNUNET_TESTING_NotifyDaemonRunning cb,
569 * Starts a GNUnet daemon's service which has been previously turned off.
571 * @param d the daemon for which the service should be started
572 * @param service the name of the service to start
573 * @param timeout how long to wait for process for startup
574 * @param cb function called once gnunet-arm returns
575 * @param cb_cls closure for cb
578 GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d,
580 struct GNUNET_TIME_Relative
582 GNUNET_TESTING_NotifyDaemonRunning
587 * Get a certain testing daemon handle.
589 * @param pg handle to the set of running peers
590 * @param position the number of the peer to return
592 struct GNUNET_TESTING_Daemon *
593 GNUNET_TESTING_daemon_get (struct GNUNET_TESTING_PeerGroup *pg,
594 unsigned int position);
598 * Get a daemon by peer identity, so callers can
599 * retrieve the daemon without knowing it's offset.
601 * @param pg the peer group to retrieve the daemon from
602 * @param peer_id the peer identity of the daemon to retrieve
604 * @return the daemon on success, or NULL if no such peer identity is found
606 struct GNUNET_TESTING_Daemon *
607 GNUNET_TESTING_daemon_get_by_id (struct GNUNET_TESTING_PeerGroup *pg,
608 const struct GNUNET_PeerIdentity *peer_id);
612 * Stops a GNUnet daemon.
614 * @param d the daemon that should be stopped
615 * @param timeout how long to wait for process for shutdown to complete
616 * @param cb function called once the daemon was stopped
617 * @param cb_cls closure for cb
618 * @param delete_files GNUNET_YES to remove files, GNUNET_NO
619 * to leave them (i.e. for restarting at a later time,
620 * or logfile inspection once finished)
621 * @param allow_restart GNUNET_YES to restart peer later (using this API)
622 * GNUNET_NO to kill off and clean up for good
625 GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
626 struct GNUNET_TIME_Relative timeout,
627 GNUNET_TESTING_NotifyCompletion cb, void *cb_cls,
628 int delete_files, int allow_restart);
633 * Create a new configuration using the given configuration
634 * as a template; however, each PORT in the existing cfg
635 * must be renumbered by incrementing "*port". If we run
636 * out of "*port" numbers, return NULL.
638 * @param cfg template configuration
639 * @param off the current peer offset
640 * @param port port numbers to use, update to reflect
641 * port numbers that were used
642 * @param upnum number to make unix domain socket names unique
643 * @param hostname hostname of the controlling host, to allow control connections from
644 * @param fdnum number used to offset the unix domain socket for grouped processes
645 * (such as statistics or peerinfo, which can be shared among others)
647 * @return new configuration, NULL on error
649 struct GNUNET_CONFIGURATION_Handle *
650 GNUNET_TESTING_create_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off,
651 uint16_t * port, uint32_t * upnum, const char *hostname,
655 * Changes the configuration of a GNUnet daemon.
657 * @param d the daemon that should be modified
658 * @param cfg the new configuration for the daemon
659 * @param cb function called once the configuration was changed
660 * @param cb_cls closure for cb
663 GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d,
664 struct GNUNET_CONFIGURATION_Handle *cfg,
665 GNUNET_TESTING_NotifyCompletion cb,
670 * Stops a single service of a GNUnet daemon. Used like daemon_stop,
671 * only doesn't stop the entire peer in any case. If the service
672 * is not currently running, this call is likely to fail after
675 * @param d the daemon that should be stopped
676 * @param service the name of the service to stop
677 * @param timeout how long to wait for process for shutdown to complete
678 * @param cb function called once the service was stopped
679 * @param cb_cls closure for cb
682 GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d,
684 struct GNUNET_TIME_Relative timeout,
685 GNUNET_TESTING_NotifyCompletion cb,
690 * Read a testing hosts file based on a configuration.
691 * Returns a DLL of hosts (caller must free!) on success
692 * or NULL on failure.
694 * @param cfg a configuration with a testing section
696 * @return DLL of hosts on success, NULL on failure
698 struct GNUNET_TESTING_Host *
699 GNUNET_TESTING_hosts_load (const struct GNUNET_CONFIGURATION_Handle *cfg);
703 * Start count gnunet instances with the same set of transports and
704 * applications. The port numbers (any option called "PORT") will be
705 * adjusted to ensure that no two peers running on the same system
706 * have the same port(s) in their respective configurations.
708 * @param cfg configuration template to use
709 * @param total number of daemons to start
710 * @param max_concurrent_connections for testing, how many peers can
711 * we connect to simultaneously
712 * @param max_concurrent_ssh when starting with ssh, how many ssh
713 * connections will we allow at once (based on remote hosts allowed!)
714 * @param timeout total time allowed for peers to start
715 * @param hostkey_callback function to call on each peers hostkey generation
716 * if NULL, peers will be started by this call, if non-null,
717 * GNUNET_TESTING_daemons_continue_startup must be called after
718 * successful hostkey generation
719 * @param hostkey_cls closure for hostkey callback
720 * @param cb function to call on each daemon that was started
721 * @param cb_cls closure for cb
722 * @param connect_callback function to call each time two hosts are connected
723 * @param connect_callback_cls closure for connect_callback
724 * @param hostnames linked list of host structs to use to start peers on
725 * (NULL to run on localhost only)
727 * @return NULL on error, otherwise handle to control peer group
729 struct GNUNET_TESTING_PeerGroup *
730 GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
732 unsigned int max_concurrent_connections,
733 unsigned int max_concurrent_ssh,
734 struct GNUNET_TIME_Relative timeout,
735 GNUNET_TESTING_NotifyHostkeyCreated
736 hostkey_callback, void *hostkey_cls,
737 GNUNET_TESTING_NotifyDaemonRunning cb,
739 GNUNET_TESTING_NotifyConnection connect_callback,
740 void *connect_callback_cls,
741 const struct GNUNET_TESTING_Host *hostnames);
745 * Function which continues a peer group starting up
746 * after successfully generating hostkeys for each peer.
748 * @param pg the peer group to continue starting
751 GNUNET_TESTING_daemons_continue_startup (struct GNUNET_TESTING_PeerGroup *pg);
755 * Handle for an active request to connect two peers.
757 struct GNUNET_TESTING_ConnectContext;
761 * Establish a connection between two GNUnet daemons. The daemons
762 * must both be running and not be stopped until either the
763 * 'cb' callback is called OR the connection request has been
764 * explicitly cancelled.
766 * @param d1 handle for the first daemon
767 * @param d2 handle for the second daemon
768 * @param timeout how long is the connection attempt
770 * @param max_connect_attempts how many times should we try to reconnect
772 * @param send_hello GNUNET_YES to send the HELLO, GNUNET_NO to assume
773 * the HELLO has already been exchanged
774 * @param cb function to call at the end
775 * @param cb_cls closure for cb
776 * @return handle to cancel the request, NULL on error
778 struct GNUNET_TESTING_ConnectContext *
779 GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
780 struct GNUNET_TESTING_Daemon *d2,
781 struct GNUNET_TIME_Relative timeout,
782 unsigned int max_connect_attempts,
784 GNUNET_TESTING_NotifyConnection cb,
790 * Cancel an attempt to connect two daemons.
792 * @param cc connect context
795 GNUNET_TESTING_daemons_connect_cancel (struct GNUNET_TESTING_ConnectContext
801 * Restart all peers in the given group.
803 * @param pg the handle to the peer group
804 * @param callback function to call on completion (or failure)
805 * @param callback_cls closure for the callback function
808 GNUNET_TESTING_daemons_restart (struct GNUNET_TESTING_PeerGroup *pg,
809 GNUNET_TESTING_NotifyCompletion callback,
814 * Shutdown all peers started in the given group.
816 * @param pg handle to the peer group
817 * @param timeout how long to wait for shutdown
818 * @param cb callback to notify upon success or failure
819 * @param cb_cls closure for cb
822 GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg,
823 struct GNUNET_TIME_Relative timeout,
824 GNUNET_TESTING_NotifyCompletion cb, void *cb_cls);
828 * Count the number of running peers.
830 * @param pg handle for the peer group
832 * @return the number of currently running peers in the peer group
835 GNUNET_TESTING_daemons_running (struct GNUNET_TESTING_PeerGroup *pg);
839 * Simulate churn by stopping some peers (and possibly
840 * re-starting others if churn is called multiple times). This
841 * function can only be used to create leave-join churn (peers "never"
842 * leave for good). First "voff" random peers that are currently
843 * online will be taken offline; then "von" random peers that are then
844 * offline will be put back online. No notifications will be
845 * generated for any of these operations except for the callback upon
846 * completion. Note that the implementation is at liberty to keep
847 * the ARM service itself (but none of the other services or daemons)
848 * running even though the "peer" is being varied offline.
850 * @param pg handle for the peer group
851 * @param service the service to churn on/off, NULL for all
852 * @param voff number of peers that should go offline
853 * @param von number of peers that should come back online;
854 * must be zero on first call (since "testbed_start"
855 * always starts all of the peers)
856 * @param timeout how long to wait for operations to finish before
858 * @param cb function to call at the end
859 * @param cb_cls closure for cb
862 GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
863 char *service, unsigned int voff,
865 struct GNUNET_TIME_Relative timeout,
866 GNUNET_TESTING_NotifyCompletion cb, void *cb_cls);
870 * Start a given service for each of the peers in the peer group.
872 * @param pg handle for the peer group
873 * @param service the service to start
874 * @param timeout how long to wait for operations to finish before
876 * @param cb function to call once finished
877 * @param cb_cls closure for cb
881 GNUNET_TESTING_daemons_start_service (struct GNUNET_TESTING_PeerGroup *pg,
883 struct GNUNET_TIME_Relative timeout,
884 GNUNET_TESTING_NotifyCompletion cb,
889 * Callback function to process statistic values.
892 * @param peer the peer the statistics belong to
893 * @param subsystem name of subsystem that created the statistic
894 * @param name the name of the datum
895 * @param value the current value
896 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
897 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
899 typedef int (*GNUNET_TESTING_STATISTICS_Iterator) (void *cls,
901 GNUNET_PeerIdentity * peer,
902 const char *subsystem,
909 * Iterate over all (running) peers in the peer group, retrieve
910 * all statistics from each.
912 * @param pg the peergroup to iterate statistics of
913 * @param cont continuation to call once call is completed(?)
914 * @param proc processing function for each statistic retrieved
915 * @param cls closure to pass to proc
918 GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg,
919 GNUNET_STATISTICS_Callback cont,
920 GNUNET_TESTING_STATISTICS_Iterator proc,
925 * Topologies supported for testbeds.
927 enum GNUNET_TESTING_Topology
930 * A clique (everyone connected to everyone else).
932 GNUNET_TESTING_TOPOLOGY_CLIQUE,
935 * Small-world network (2d torus plus random links).
937 GNUNET_TESTING_TOPOLOGY_SMALL_WORLD,
940 * Small-world network (ring plus random links).
942 GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING,
947 GNUNET_TESTING_TOPOLOGY_RING,
952 GNUNET_TESTING_TOPOLOGY_2D_TORUS,
957 GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI,
960 * Certain percentage of peers are unable to communicate directly
961 * replicating NAT conditions
963 GNUNET_TESTING_TOPOLOGY_INTERNAT,
966 * Scale free topology.
968 GNUNET_TESTING_TOPOLOGY_SCALE_FREE,
971 * Straight line topology.
973 GNUNET_TESTING_TOPOLOGY_LINE,
976 * All peers are disconnected.
978 GNUNET_TESTING_TOPOLOGY_NONE,
981 * Read a topology from a given file.
983 GNUNET_TESTING_TOPOLOGY_FROM_FILE
987 * Options for connecting a topology.
989 enum GNUNET_TESTING_TopologyOption
992 * Try to connect all peers specified in the topology.
994 GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
997 * Choose a random subset of connections to create.
999 GNUNET_TESTING_TOPOLOGY_OPTION_RANDOM,
1002 * Create at least X connections for each peer.
1004 GNUNET_TESTING_TOPOLOGY_OPTION_MINIMUM,
1007 * Using a depth first search, create one connection
1008 * per peer. If any are missed (graph disconnected)
1009 * start over at those peers until all have at least one
1012 GNUNET_TESTING_TOPOLOGY_OPTION_DFS,
1015 * Find the N closest peers to each allowed peer in the
1016 * topology and make sure a connection to those peers
1017 * exists in the connect topology.
1019 GNUNET_TESTING_TOPOLOGY_OPTION_ADD_CLOSEST,
1022 * No options specified.
1024 GNUNET_TESTING_TOPOLOGY_OPTION_NONE
1029 * Get a topology from a string input.
1031 * @param topology where to write the retrieved topology
1032 * @param topology_string The string to attempt to
1033 * get a configuration value from
1034 * @return GNUNET_YES if topology string matched a
1035 * known topology, GNUNET_NO if not
1038 GNUNET_TESTING_topology_get (enum GNUNET_TESTING_Topology *topology,
1039 const char *topology_string);
1043 * Get connect topology option from string input.
1045 * @param topology_option where to write the retrieved topology
1046 * @param topology_string The string to attempt to
1047 * get a configuration value from
1048 * @return GNUNET_YES if topology string matched a
1049 * known topology, GNUNET_NO if not
1052 GNUNET_TESTING_topology_option_get (enum GNUNET_TESTING_TopologyOption
1054 const char *topology_string);
1058 * Takes a peer group and creates a topology based on the
1059 * one specified. Creates a topology means generates friend
1060 * files for the peers so they can only connect to those allowed
1061 * by the topology. This will only have an effect once peers
1062 * are started if the FRIENDS_ONLY option is set in the base
1065 * Also takes an optional restrict topology which
1066 * disallows direct connections UNLESS they are specified in
1067 * the restricted topology.
1069 * A simple example; if the topology option is set to LINE
1070 * peers can ONLY connect in a LINE. However, if the topology
1071 * option is set to 2D-torus and the restrict option is set to
1072 * line with restrict_transports equal to "tcp udp", then peers
1073 * may connect in a 2D-torus, but will be restricted to tcp and
1074 * udp connections only in a LINE. Generally it only makes
1075 * sense to do this if restrict_topology is a subset of topology.
1077 * For testing peer discovery, etc. it is generally better to
1078 * leave restrict_topology as GNUNET_TESTING_TOPOLOGY_NONE and
1079 * then use the connect_topology function to restrict the initial
1082 * @param pg the peer group struct representing the running peers
1083 * @param topology which topology to connect the peers in
1084 * @param restrict_topology allow only direct connections in this topology,
1085 * based on those listed in restrict_transports, set to
1086 * GNUNET_TESTING_TOPOLOGY_NONE for no restrictions
1087 * @param restrict_transports space delimited list of transports to blacklist
1088 * to create restricted topology, NULL for none
1090 * @return the maximum number of connections were all allowed peers
1091 * connected to each other
1094 GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
1095 enum GNUNET_TESTING_Topology topology,
1096 enum GNUNET_TESTING_Topology restrict_topology,
1097 const char *restrict_transports);
1101 * Iterate over all (running) peers in the peer group, retrieve
1102 * all connections that each currently has.
1104 * @param pg the peer group we are concerned with
1105 * @param cb callback for topology information
1106 * @param cls closure for callback
1109 GNUNET_TESTING_get_topology (struct GNUNET_TESTING_PeerGroup *pg,
1110 GNUNET_TESTING_NotifyTopology cb, void *cls);
1114 * Stop the connection process temporarily.
1116 * @param pg the peer group to stop connecting
1119 GNUNET_TESTING_stop_connections (struct GNUNET_TESTING_PeerGroup *pg);
1123 * Resume the connection process.
1125 * @param pg the peer group to resume connecting
1128 GNUNET_TESTING_resume_connections (struct GNUNET_TESTING_PeerGroup *pg);
1132 * There are many ways to connect peers that are supported by this function.
1133 * To connect peers in the same topology that was created via the
1134 * GNUNET_TESTING_create_topology, the topology variable must be set to
1135 * GNUNET_TESTING_TOPOLOGY_NONE. If the topology variable is specified,
1136 * a new instance of that topology will be generated and attempted to be
1137 * connected. This could result in some connections being impossible,
1138 * because some topologies are non-deterministic.
1140 * @param pg the peer group struct representing the running peers
1141 * @param topology which topology to connect the peers in
1142 * @param options options for connecting the topology
1143 * @param option_modifier modifier for options that take a parameter
1144 * @param connect_timeout how long to wait before giving up on connecting
1146 * @param connect_attempts how many times to attempt to connect two peers
1147 * over the connect_timeout duration
1148 * @param notify_callback notification to be called once all connections completed
1149 * @param notify_cls closure for notification callback
1151 * @return the number of connections that will be attempted, GNUNET_SYSERR on error
1154 GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg,
1155 enum GNUNET_TESTING_Topology topology,
1156 enum GNUNET_TESTING_TopologyOption options,
1157 double option_modifier,
1158 struct GNUNET_TIME_Relative connect_timeout,
1159 unsigned int connect_attempts,
1160 GNUNET_TESTING_NotifyCompletion
1161 notify_callback, void *notify_cls);
1165 * Start or stop an individual peer from the given group.
1167 * @param pg handle to the peer group
1168 * @param offset which peer to start or stop
1169 * @param desired_status GNUNET_YES to have it running, GNUNET_NO to stop it
1170 * @param timeout how long to wait for shutdown
1171 * @param cb function to call at the end
1172 * @param cb_cls closure for cb
1175 GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg,
1176 unsigned int offset, int desired_status,
1177 struct GNUNET_TIME_Relative timeout,
1178 GNUNET_TESTING_NotifyCompletion cb, void *cb_cls);
1182 * Start a peer group with a given number of peers. Notify
1183 * on completion of peer startup and connection based on given
1184 * topological constraints. Optionally notify on each
1185 * established connection.
1187 * @param cfg configuration template to use
1188 * @param total number of daemons to start
1189 * @param timeout total time allowed for peers to start
1190 * @param connect_cb function to call each time two daemons are connected
1191 * @param peergroup_cb function to call once all peers are up and connected
1192 * @param peergroup_cls closure for peergroup callbacks
1193 * @param hostnames linked list of host structs to use to start peers on
1194 * (NULL to run on localhost only)
1196 * @return NULL on error, otherwise handle to control peer group
1198 struct GNUNET_TESTING_PeerGroup *
1199 GNUNET_TESTING_peergroup_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1201 struct GNUNET_TIME_Relative timeout,
1202 GNUNET_TESTING_NotifyConnection connect_cb,
1203 GNUNET_TESTING_NotifyCompletion peergroup_cb,
1204 void *peergroup_cls,
1205 const struct GNUNET_TESTING_Host *hostnames);
1209 * Print current topology to a graphviz readable file.
1211 * @param pg a currently running peergroup to print to file
1212 * @param output_filename the file to write the topology to
1213 * @param notify_cb callback to call upon completion or failure
1214 * @param notify_cb_cls closure for notify_cb
1218 GNUNET_TESTING_peergroup_topology_to_file (struct GNUNET_TESTING_PeerGroup *pg,
1219 const char *output_filename,
1220 GNUNET_TESTING_NotifyCompletion
1221 notify_cb, void *notify_cb_cls);
1224 #if 0 /* keep Emacsens' auto-indent happy */