+ * @param cfg configuration used by this daemon
+ * @param d handle for the daemon
+ * @param emsg error message (NULL on success)
+ */
+typedef void (*GNUNET_TESTING_NotifyDaemonRunning) (void *cls,
+ const struct
+ GNUNET_PeerIdentity * id,
+ const struct
+ GNUNET_CONFIGURATION_Handle
+ * cfg,
+ struct GNUNET_TESTING_Daemon
+ * d, const char *emsg);
+
+/**
+ * Handle to an entire testbed of GNUnet peers.
+ */
+struct GNUNET_TESTING_Testbed;
+
+/**
+ * Phases of starting GNUnet on a system.
+ */
+enum GNUNET_TESTING_StartPhase
+{
+ /**
+ * Copy the configuration file to the target system.
+ */
+ SP_COPYING,
+
+ /**
+ * Configuration file has been copied, generate hostkey.
+ */
+ SP_COPIED,
+
+ /**
+ * Create the hostkey for the peer.
+ */
+ SP_HOSTKEY_CREATE,
+
+ /**
+ * Hostkey generated, wait for topology to be finished.
+ */
+ SP_HOSTKEY_CREATED,
+
+ /**
+ * Topology has been created, now start ARM.
+ */
+ SP_TOPOLOGY_SETUP,
+
+ /**
+ * ARM has been started, check that it has properly daemonized and
+ * then try to connect to the CORE service (which should be
+ * auto-started by ARM).
+ */
+ SP_START_ARMING,
+
+ /**
+ * We're waiting for CORE to start.
+ */
+ SP_START_CORE,
+
+ /**
+ * CORE is up, now make sure we get the HELLO for this peer.
+ */
+ SP_GET_HELLO,
+
+ /**
+ * Core has notified us that we've established a connection to the service.
+ * The main FSM halts here and waits to be moved to UPDATE or CLEANUP.
+ */
+ SP_START_DONE,
+
+ /**
+ * We've been asked to terminate the instance and are now waiting for
+ * the remote command to stop the gnunet-arm process and delete temporary
+ * files.
+ */
+ SP_SHUTDOWN_START,
+
+ /**
+ * We should shutdown a *single* service via gnunet-arm. Call the dead_cb
+ * upon notification from gnunet-arm that the service has been stopped.
+ */
+ SP_SERVICE_SHUTDOWN_START,
+
+ /**
+ * We should start a *single* service via gnunet-arm. Call the daemon cb
+ * upon notification from gnunet-arm that the service has been started.
+ */
+ SP_SERVICE_START,
+
+ /**
+ * We've received a configuration update and are currently waiting for
+ * the copy process for the update to complete. Once it is, we will
+ * return to "SP_START_DONE" (and rely on ARM to restart all affected
+ * services).
+ */
+ SP_CONFIG_UPDATE
+};
+
+/**
+ * Prototype of a function that will be called when a
+ * particular operation was completed the testing library.
+ *
+ * @param cls closure
+ * @param emsg NULL on success
+ */
+typedef void (*GNUNET_TESTING_NotifyCompletion) (void *cls, const char *emsg);
+
+/**
+ * Prototype of a function that will be called with the
+ * number of connections created for a particular topology.
+ *
+ * @param cls closure
+ * @param num_connections the number of connections created
+ */
+typedef void (*GNUNET_TESTING_NotifyConnections) (void *cls,
+ unsigned int num_connections);
+
+/**
+ * Handle for a GNUnet daemon (technically a set of
+ * daemons; the handle is really for the master ARM
+ * daemon) started by the testing library.
+ */
+struct GNUNET_TESTING_Daemon
+{
+ /**
+ * Our configuration.
+ */
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ /**
+ * At what time to give up starting the peer
+ */
+ struct GNUNET_TIME_Absolute max_timeout;
+
+ /**
+ * Host to run GNUnet on.
+ */
+ char *hostname;
+
+ /**
+ * Port to use for ssh, NULL to let system choose default.
+ */
+ char *ssh_port_str;
+
+ /**
+ * Result of GNUNET_i2s of this peer,
+ * for printing
+ */
+ char *shortname;
+
+ /**
+ * Username we are using.
+ */
+ char *username;
+
+ /**
+ * Name of the configuration file
+ */
+ char *cfgfile;
+
+ /**
+ * Callback to inform initiator that the peer's
+ * hostkey has been created.
+ */
+ GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback;
+
+ /**
+ * Closure for hostkey creation callback.
+ */
+ void *hostkey_cls;
+
+ /**
+ * Function to call when the peer is running.
+ */
+ GNUNET_TESTING_NotifyDaemonRunning cb;
+
+ /**
+ * Closure for cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Arguments from "daemon_stop" call.
+ */
+ GNUNET_TESTING_NotifyCompletion dead_cb;
+
+ /**
+ * Closure for 'dead_cb'.
+ */
+ void *dead_cb_cls;
+
+ /**
+ * Arguments from "daemon_stop" call.
+ */
+ GNUNET_TESTING_NotifyCompletion update_cb;
+
+ /**
+ * Closure for 'update_cb'.
+ */
+ void *update_cb_cls;
+
+ /**
+ * PID of the process we used to run gnunet-arm or SSH to start the peer.
+ */
+ struct GNUNET_OS_Process *proc_arm_start;
+
+ /**
+ * PID of the process we used to run gnunet-arm or SSH to stop the peer.
+ */
+ struct GNUNET_OS_Process *proc_arm_stop;
+
+ /**
+ * PID of the process we used to run gnunet-arm or SSH to manage services at the peer.
+ */
+ struct GNUNET_OS_Process *proc_arm_srv_start;
+
+ /**
+ * PID of the process we used to run gnunet-arm or SSH to manage services at the peer.
+ */
+ struct GNUNET_OS_Process *proc_arm_srv_stop;
+
+ /**
+ * PID of the process we used to run copy files
+ */
+ struct GNUNET_OS_Process *proc_arm_copying;
+
+ /**
+ * PID of the process we used to run gnunet-peerinfo.
+ */
+ struct GNUNET_OS_Process *proc_arm_peerinfo;
+
+ /**
+ * Handle to the server.
+ */
+ struct GNUNET_CORE_Handle *server;
+
+ /**
+ * Handle to the transport service of this peer
+ */
+ struct GNUNET_TRANSPORT_Handle *th;
+
+ /**
+ * Handle for getting HELLOs from transport
+ */
+ struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
+
+ /**
+ * HELLO message for this peer
+ */
+ struct GNUNET_HELLO_Message *hello;
+
+ /**
+ * Handle to a pipe for reading the hostkey.
+ */
+ struct GNUNET_DISK_PipeHandle *pipe_stdout;
+
+ /**
+ * Currently, a single char * pointing to a service
+ * that has been churned off.
+ *
+ * FIXME: make this a linked list of services that have been churned off!!!
+ */
+ char *churned_services;
+
+ /**
+ * ID of the current task.
+ */
+ GNUNET_SCHEDULER_TaskIdentifier task;
+
+ /**
+ * Identity of this peer (once started).
+ */
+ struct GNUNET_PeerIdentity id;
+
+ /**
+ * Flag to indicate that we've already been asked
+ * to terminate (but could not because some action
+ * was still pending).
+ */
+ int dead;
+
+ /**
+ * GNUNET_YES if the hostkey has been created
+ * for this peer, GNUNET_NO otherwise.
+ */
+ int have_hostkey;
+
+ /**
+ * In which phase are we during the start of
+ * this process?
+ */
+ enum GNUNET_TESTING_StartPhase phase;
+
+ /**
+ * Current position in 'hostkeybuf' (for reading from gnunet-peerinfo)
+ */
+ unsigned int hostkeybufpos;
+
+ /**
+ * Set to GNUNET_YES once the peer is up.
+ */
+ int running;
+
+ /**
+ * Used to tell shutdown not to remove configuration for the peer
+ * (if it's going to be restarted later)
+ */
+ int churn;
+
+ /**
+ * Output from gnunet-peerinfo is read into this buffer.
+ */
+ char hostkeybuf[105];
+
+};
+
+
+/**
+ * Handle to a group of GNUnet peers.
+ */
+struct GNUNET_TESTING_PeerGroup;
+
+
+/**
+ * Prototype of a function that will be called whenever
+ * two daemons are connected by the testing library.
+ *
+ * @param cls closure
+ * @param first peer id for first daemon
+ * @param second peer id for the second daemon
+ * @param distance distance between the connected peers
+ * @param first_cfg config for the first daemon
+ * @param second_cfg config for the second daemon
+ * @param first_daemon handle for the first daemon
+ * @param second_daemon handle for the second daemon
+ * @param emsg error message (NULL on success)
+ */
+typedef void (*GNUNET_TESTING_NotifyConnection) (void *cls,
+ const struct
+ GNUNET_PeerIdentity * first,
+ const struct
+ GNUNET_PeerIdentity * second,
+ uint32_t distance,
+ const struct
+ GNUNET_CONFIGURATION_Handle *
+ first_cfg,
+ const struct
+ GNUNET_CONFIGURATION_Handle *
+ second_cfg,
+ struct GNUNET_TESTING_Daemon *
+ first_daemon,
+ struct GNUNET_TESTING_Daemon *
+ second_daemon,
+ const char *emsg);
+
+
+/**
+ * Prototype of a callback function indicating that two peers
+ * are currently connected.
+ *
+ * @param cls closure
+ * @param first peer id for first daemon
+ * @param second peer id for the second daemon
+ * @param distance distance between the connected peers
+ * @param emsg error message (NULL on success)