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 2, 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"
40 #if 0 /* keep Emacsens' auto-indent happy */
48 * Handle for a GNUnet daemon (technically a set of
49 * daemons; the handle is really for the master ARM
50 * daemon) started by the testing library.
52 struct GNUNET_TESTING_Daemon;
56 * Prototype of a function that will be called whenever
57 * a daemon was started by the testing library.
60 * @param id identifier for the daemon, NULL on error
61 * @param cfg configuration used by this daemon
62 * @param d handle for the daemon
63 * @param emsg error message (NULL on success)
65 typedef void (*GNUNET_TESTING_NotifyDaemonRunning)(void *cls,
66 const struct GNUNET_PeerIdentity *id,
67 const struct GNUNET_CONFIGURATION_Handle *cfg,
68 struct GNUNET_TESTING_Daemon *d,
73 * Starts a GNUnet daemon.
75 * @param sched scheduler to use
76 * @param cfg configuration to use
77 * @param service_home directory to use as the service home directory
78 * @param transports transport services that should be loaded
79 * @param applications application services and daemons that should be started
80 * @param port_offset offset to add to all ports for all services
81 * @param hostname name of the machine where to run GNUnet
82 * (use NULL for localhost).
83 * @param cb function to call with the result
84 * @param cb_cls closure for cb
85 * @return handle to the daemon (actual start will be completed asynchronously)
87 struct GNUNET_TESTING_Daemon *
88 GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
89 struct GNUNET_CONFIGURATION_Handle *cfg,
90 const char *service_home,
91 const char *transports,
92 const char *applications,
95 GNUNET_TESTING_NotifyDaemonRunning cb,
100 * Prototype of a function that will be called when a
101 * particular operation was completed the testing library.
104 * @param emsg NULL on success
106 typedef void (*GNUNET_TESTING_NotifyCompletion)(void *cls,
111 * Stops a GNUnet daemon.
113 * @param d the daemon that should be stopped
114 * @param cb function called once the daemon was stopped
115 * @param cb_cls closure for cb
117 void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
118 GNUNET_TESTING_NotifyCompletion cb,
123 * Changes the configuration of a GNUnet daemon.
125 * @param d the daemon that should be modified
126 * @param cfg the new configuration for the daemon
127 * @param cb function called once the configuration was changed
128 * @param cb_cls closure for cb
130 void GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d,
131 const struct GNUNET_CONFIGURATION_Handle *cfg,
132 GNUNET_TESTING_NotifyCompletion cb,
138 * Establish a connection between two GNUnet daemons.
140 * @param d1 handle for the first daemon
141 * @param d2 handle for the second daemon
142 * @param timeout how long is the connection attempt
144 * @param cb function to call at the end
145 * @param cb_cls closure for cb
147 void GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
148 struct GNUNET_TESTING_Daemon *d2,
149 struct GNUNET_TIME_Relative timeout,
150 GNUNET_TESTING_NotifyCompletion cb,
155 * Start count gnunetd processes with the same set of transports and
156 * applications. The port numbers (any option called "PORT") will be
157 * adjusted to ensure that no two peers running on the same system
158 * have the same port(s) in their respective configurations.
160 * @param sched scheduler to use
161 * @param cfg configuration template to use
162 * @param total number of daemons to start
163 * @param cb function to call on each daemon that was started
164 * @param cb_cls closure for cb
165 * @param cbe function to call at the end
166 * @param cbe_cls closure for cbe
167 * @param hostname where to run the peers; can be NULL (to run
168 * everything on localhost).
169 * @param va Additional hosts can be specified using a NULL-terminated list of
170 * varargs, hosts will then be used round-robin from that
171 * list; va only contains anything if hostname != NULL.
174 GNUNET_TESTING_daemons_start_va (struct GNUNET_SCHEDULER_Handle *sched,
175 const struct GNUNET_CONFIGURATION_Handle *cfg,
177 GNUNET_TESTING_NotifyDaemonRunning cb,
179 GNUNET_TESTING_NotifyCompletion cbe,
181 const char *hostname,
186 * Start count gnunetd processes with the same set of
187 * transports and applications. The port numbers will
188 * be computed by adding delta each time (zero
189 * times for the first peer).
191 * @param total number of daemons to start
192 * @param service_home_prefix path to use as the prefix for the home of the services
193 * @param transports which transports should all peers use
194 * @param applications which applications should be used?
195 * @param timeout how long is this allowed to take?
196 * @param cb function to call on each daemon that was started
197 * @param cb_cls closure for cb
198 * @param cbe function to call at the end
199 * @param cbe_cls closure for cbe
200 * @param hostname where to run the peers; can be NULL (to run
201 * everything on localhost). Additional
202 * hosts can be specified using a NULL-terminated list of
203 * varargs, hosts will then be used round-robin from that
207 GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
208 struct GNUNET_CONFIGURATION_Handle *cfg,
210 const char *service_home_prefix,
211 const char *transports,
212 const char *applications,
213 GNUNET_TESTING_NotifyDaemonRunning cb,
215 GNUNET_TESTING_NotifyCompletion cbe,
217 const char *hostname,
222 * Handle to an entire testbed of GNUnet peers.
224 struct GNUNET_TESTING_Testbed;
227 * Prototype of a function that will be called when
228 * a testbed is being created.
231 * @param tb NULL on error
233 typedef void (*GNUNET_TESTING_NotifyTestbedRunning)(void *cls,
234 struct GNUNET_TESTING_Testbed *tb);
238 * Topologies supported for testbeds.
240 enum GNUNET_TESTING_Topology
243 * A clique (everyone connected to everyone else).
245 GNUNET_TESTING_TOPOLOGY_CLIQUE,
248 * Small-world network (2d torus plus random links).
250 GNUNET_TESTING_TOPOLOGY_SMALL_WORLD,
255 GNUNET_TESTING_TOPOLOGY_RING,
260 GNUNET_TESTING_TOPOLOGY_2D_TORUS,
265 GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI,
268 * All peers are disconnected.
270 GNUNET_TESTING_TOPOLOGY_NONE
276 * Start count GNUnet daemons with a particular
279 * @param size number of peers the testbed should have
280 * @param topology desired topology (enforced via F2F)
281 * @param service_home_prefix path to use as the prefix for the home of the services
282 * @param transports which transports should all peers use
283 * @param applications which applications should be used?
284 * @param timeout how long is this allowed to take?
285 * @param cb function to call on each daemon that was started
286 * @param cb_cls closure for cb
287 * @param cte function to call at the end
288 * @param cte_cls closure for cbe
289 * @param hostname where to run the peers; can be NULL (to run
290 * everything on localhost). Additional
291 * hosts can be specified using a NULL-terminated list of
292 * varargs, hosts will then be used round-robin from that
296 GNUNET_TESTING_testbed_start (struct GNUNET_SCHEDULER_Handle *sched,
297 struct GNUNET_CONFIGURATION_Handle *cfg,
299 enum GNUNET_TESTING_Topology topology,
300 const char *service_home_prefix,
301 const char *transports,
302 const char *applications,
303 GNUNET_TESTING_NotifyDaemonRunning cb,
305 GNUNET_TESTING_NotifyTestbedRunning cte,
307 const char *hostname,
314 * Stop all of the daemons started with the start function.
316 * @param tb handle for the testbed
317 * @param cb function to call at the end
318 * @param cb_cls closure for cb
321 GNUNET_TESTING_testbed_stop (struct GNUNET_TESTING_Testbed *tb,
322 GNUNET_TESTING_NotifyCompletion cb,
328 * Simulate churn in the testbed by stopping some peers (and possibly
329 * re-starting others if churn is called multiple times). This
330 * function can only be used to create leave-join churn (peers "never"
331 * leave for good). First "voff" random peers that are currently
332 * online will be taken offline; then "von" random peers that are then
333 * offline will be put back online. No notifications will be
334 * generated for any of these operations except for the callback upon
335 * completion. Note that the implementation is at liberty to keep
336 * the ARM service itself (but none of the other services or daemons)
337 * running even though the "peer" is being varied offline.
339 * @param tb handle for the testbed
340 * @param voff number of peers that should go offline
341 * @param von number of peers that should come back online;
342 * must be zero on first call (since "testbed_start"
343 * always starts all of the peers)
344 * @param cb function to call at the end
345 * @param cb_cls closure for cb
348 GNUNET_TESTING_testbed_churn (struct GNUNET_TESTING_Testbed *tb,
351 GNUNET_TESTING_NotifyCompletion cb,
356 #if 0 /* keep Emacsens' auto-indent happy */