wip
[oweals/gnunet.git] / src / include / gnunet_testing_lib.h
index d0b5c781a1730013396e7e1c710c71b216ba7ade..8c76457e3f050abfbf5a29d69ba9208450f07f6e 100644 (file)
@@ -43,6 +43,8 @@ extern "C"
 #endif
 #endif
 
+#define HOSTKEYFILESIZE 914
+
 /**
  * Handle for a GNUnet daemon (technically a set of
  * daemons; the handle is really for the master ARM
@@ -155,6 +157,11 @@ enum GNUNET_TESTING_StartPhase
    */
   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.
@@ -204,11 +211,6 @@ typedef void (*GNUNET_TESTING_NotifyConnections)(void *cls,
  */
 struct GNUNET_TESTING_Daemon
 {
-  /**
-   * Our scheduler.
-   */
-  struct GNUNET_SCHEDULER_Handle *sched;
-
   /**
    * Our configuration.
    */
@@ -298,10 +300,16 @@ struct GNUNET_TESTING_Daemon
    */
   int dead;
 
+  /**
+   * GNUNET_YES if the hostkey has been created
+   * for this peer, GNUNET_NO otherwise.
+   */
+  int have_hostkey;
+
   /**
    * PID of the process that we started last.
    */
-  pid_t pid;
+  struct GNUNET_OS_Process *proc;
 
   /**
    * In which phase are we during the start of
@@ -400,8 +408,6 @@ typedef void (*GNUNET_TESTING_NotifyConnection)(void *cls,
 typedef void (*GNUNET_TESTING_NotifyTopology)(void *cls,
                                               const struct GNUNET_PeerIdentity *first,
                                               const struct GNUNET_PeerIdentity *second,
-                                              struct GNUNET_TIME_Relative latency,
-                                              uint32_t distance,
                                               const char *emsg);
 
 /**
@@ -410,13 +416,15 @@ typedef void (*GNUNET_TESTING_NotifyTopology)(void *cls,
  * reachable via "ssh" (unless the hostname is "NULL") without the
  * need to enter a password.
  *
- * @param sched scheduler to use
  * @param cfg configuration to use
  * @param timeout how long to wait starting up peers
+ * @param pretend GNUNET_YES to set up files but not start peer GNUNET_NO
+ *                to really start the peer (default)
  * @param hostname name of the machine where to run GNUnet
  *        (use NULL for localhost).
  * @param ssh_username ssh username to use when connecting to hostname
  * @param sshport port to pass to ssh process when connecting to hostname
+ * @param hostkey pointer to a hostkey to be written to disk (instead of being generated)
  * @param hostkey_callback function to call once the hostkey has been
  *        generated for this peer, but it hasn't yet been started
  *        (NULL to start immediately, otherwise waits on GNUNET_TESTING_daemon_continue_start)
@@ -426,14 +434,15 @@ typedef void (*GNUNET_TESTING_NotifyTopology)(void *cls,
  * @return handle to the daemon (actual start will be completed asynchronously)
  */
 struct GNUNET_TESTING_Daemon *
-GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
-                             const struct GNUNET_CONFIGURATION_Handle *cfg,
+GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
                              struct GNUNET_TIME_Relative timeout,
+                             int pretend,
                              const char *hostname,
                              const char *ssh_username,
                              uint16_t sshport,
-                             GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback,
-                             void *hostkey_cls,
+                             const char *hostkey,
+                             GNUNET_TESTING_NotifyHostkeyCreated
+                             hostkey_callback, void *hostkey_cls,
                              GNUNET_TESTING_NotifyDaemonRunning cb,
                              void *cb_cls);
 
@@ -550,28 +559,35 @@ void GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d,
  *        allowed to take?
  * @param max_connect_attempts how many times should we try to reconnect
  *        (within timeout)
+ * @param send_hello GNUNET_YES to send the HELLO, GNUNET_NO to assume
+ *                   the HELLO has already been exchanged
  * @param cb function to call at the end
  * @param cb_cls closure for cb
  */
-void GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
-                                    struct GNUNET_TESTING_Daemon *d2,
-                                    struct GNUNET_TIME_Relative timeout,
-                                    unsigned int max_connect_attempts,
-                                    GNUNET_TESTING_NotifyConnection cb,
-                                    void *cb_cls);
+void
+GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
+                                struct GNUNET_TESTING_Daemon *d2,
+                                struct GNUNET_TIME_Relative timeout,
+                                unsigned int max_connect_attempts,
+                                int send_hello,
+                                GNUNET_TESTING_NotifyConnection cb,
+                                void *cb_cls);
 
 
 
 
 /**
- * Start count gnunetd processes with the same set of transports and
+ * Start count gnunet instances with the same set of transports and
  * applications.  The port numbers (any option called "PORT") will be
  * adjusted to ensure that no two peers running on the same system
  * have the same port(s) in their respective configurations.
  *
- * @param sched scheduler to use
  * @param cfg configuration template to use
  * @param total number of daemons to start
+ * @param max_concurrent_connections for testing, how many peers can
+*                                   we connect to simultaneously
+ * @param max_concurrent_ssh when starting with ssh, how many ssh
+ *        connections will we allow at once (based on remote hosts allowed!)
  * @param timeout total time allowed for peers to start
  * @param hostkey_callback function to call on each peers hostkey generation
  *        if NULL, peers will be started by this call, if non-null,
@@ -582,17 +598,19 @@ void GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
  * @param cb_cls closure for cb
  * @param connect_callback function to call each time two hosts are connected
  * @param connect_callback_cls closure for connect_callback
- * @param hostnames linked list of hosts to use to start peers on (NULL to run on localhost only)
+ * @param hostnames linked list of host structs to use to start peers on
+ *                  (NULL to run on localhost only)
  *
  * @return NULL on error, otherwise handle to control peer group
  */
 struct GNUNET_TESTING_PeerGroup *
-GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
-                              const struct GNUNET_CONFIGURATION_Handle *cfg,
+GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
                               unsigned int total,
+                              unsigned int max_concurrent_connections,
+                              unsigned int max_concurrent_ssh,
                               struct GNUNET_TIME_Relative timeout,
-                              GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback,
-                              void *hostkey_cls,
+                              GNUNET_TESTING_NotifyHostkeyCreated
+                              hostkey_callback, void *hostkey_cls,
                               GNUNET_TESTING_NotifyDaemonRunning cb,
                               void *cb_cls,
                               GNUNET_TESTING_NotifyConnection
@@ -757,7 +775,12 @@ enum GNUNET_TESTING_Topology
   /**
    * All peers are disconnected.
    */
-  GNUNET_TESTING_TOPOLOGY_NONE
+  GNUNET_TESTING_TOPOLOGY_NONE,
+
+  /**
+   * Read a topology from a given file.
+   */
+  GNUNET_TESTING_TOPOLOGY_FROM_FILE
 };
 
 /**
@@ -850,9 +873,9 @@ GNUNET_TESTING_topology_option_get(enum GNUNET_TESTING_TopologyOption *topology_
  * sense to do this if restrict_topology is a subset of topology.
  *
  * For testing peer discovery, etc. it is generally better to
- * leave restrict_topology as "0" or ALL and then use the
- * connect_topology function to restrict the initial connection
- * set.
+ * leave restrict_topology as GNUNET_TESTING_TOPOLOGY_NONE and
+ * then use the connect_topology function to restrict the initial
+ * connection set.
  *
  * @param pg the peer group struct representing the running peers
  * @param topology which topology to connect the peers in
@@ -883,6 +906,20 @@ void
 GNUNET_TESTING_get_topology (struct GNUNET_TESTING_PeerGroup *pg,
                             GNUNET_TESTING_NotifyTopology cb, void *cls);
 
+/**
+ * Stop the connection process temporarily.
+ *
+ * @param pg the peer group to stop connecting
+ */
+void GNUNET_TESTING_stop_connections(struct GNUNET_TESTING_PeerGroup *pg);
+
+/**
+ * Resume the connection process.
+ *
+ * @param pg the peer group to resume connecting
+ */
+void GNUNET_TESTING_resume_connections(struct GNUNET_TESTING_PeerGroup *pg);
+
 /**
  * There are many ways to connect peers that are supported by this function.
  * To connect peers in the same topology that was created via the
@@ -896,20 +933,24 @@ GNUNET_TESTING_get_topology (struct GNUNET_TESTING_PeerGroup *pg,
  * @param topology which topology to connect the peers in
  * @param options options for connecting the topology
  * @param option_modifier modifier for options that take a parameter
+ * @param connect_timeout how long to wait before giving up on connecting
+ *                        two peers
+ * @param connect_attempts how many times to attempt to connect two peers
+ *                         over the connect_timeout duration
  * @param notify_callback notification to be called once all connections completed
  * @param notify_cls closure for notification callback
  *
- * @return the number of connections that will be attempted (multiple of two,
- *         each bidirectional connection counts twice!), GNUNET_SYSERR on error
- *
+ * @return the number of connections that will be attempted, GNUNET_SYSERR on error
  */
 int
 GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg,
                                  enum GNUNET_TESTING_Topology topology,
                                  enum GNUNET_TESTING_TopologyOption options,
                                  double option_modifier,
-                                 GNUNET_TESTING_NotifyCompletion notify_callback,
-                                 void *notify_cls);
+                                 struct GNUNET_TIME_Relative connect_timeout,
+                                 unsigned int connect_attempts,
+                                 GNUNET_TESTING_NotifyCompletion
+                                 notify_callback, void *notify_cls);
 
 /**
  * Start or stop an individual peer from the given group.
@@ -929,6 +970,33 @@ GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg,
                             GNUNET_TESTING_NotifyCompletion cb,
                             void *cb_cls);
 
+/**
+ * Start a peer group with a given number of peers.  Notify
+ * on completion of peer startup and connection based on given
+ * topological constraints.  Optionally notify on each
+ * established connection.
+ *
+ * @param cfg configuration template to use
+ * @param total number of daemons to start
+ * @param timeout total time allowed for peers to start
+ * @param connect_cb function to call each time two daemons are connected
+ * @param peergroup_cb function to call once all peers are up and connected
+ * @param peergroup_cls closure for peergroup callbacks
+ * @param hostnames linked list of host structs to use to start peers on
+ *                  (NULL to run on localhost only)
+ *
+ * @return NULL on error, otherwise handle to control peer group
+ */
+struct GNUNET_TESTING_PeerGroup *
+GNUNET_TESTING_peergroup_start(
+                               const struct GNUNET_CONFIGURATION_Handle *cfg,
+                               unsigned int total,
+                               struct GNUNET_TIME_Relative timeout,
+                               GNUNET_TESTING_NotifyConnection connect_cb,
+                               GNUNET_TESTING_NotifyCompletion peergroup_cb,
+                               void *peergroup_cls,
+                               const struct GNUNET_TESTING_Host *hostnames);
+
 
 #if 0                           /* keep Emacsens' auto-indent happy */
 {