aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_testing_lib.h
blob: 459e433148f32e8b70045b911d6d1d804db97a30 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/*
      This file is part of GNUnet
      (C) 2008, 2009 Christian Grothoff (and other contributing authors)

      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
      by the Free Software Foundation; either version 2, or (at your
      option) any later version.

      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      General Public License for more details.

      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      Boston, MA 02111-1307, USA.
 */

/**
 * @file include/gnunet_testing_lib.h
 * @brief convenience API for writing testcases for GNUnet
 *        Many testcases need to start and stop gnunetd,
 *        and this library is supposed to make that easier
 *        for TESTCASES.  Normal programs should always
 *        use functions from gnunet_{util,arm}_lib.h.  This API is
 *        ONLY for writing testcases!
 * @author Christian Grothoff
 */

#ifndef GNUNET_TESTING_LIB_H
#define GNUNET_TESTING_LIB_H

#include "gnunet_util_lib.h"

#ifdef __cplusplus
extern "C"
{
#if 0                           /* keep Emacsens' auto-indent happy */
}
#endif
#endif



/**
 * 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;


/**
 * Prototype of a function that will be called whenever
 * a daemon was started by the testing library.
 *
 * @param cls closure
 * @param id identifier for the daemon, NULL on error
 * @param d handle to the daemon, NULL if starting the daemon failed
 */
typedef void (*GNUNET_TESTING_NotifyDaemonRunning)(void *cls,
						   const struct GNUNET_PeerIdentity *id,
						   struct GNUNET_TESTING_Daemon *d);


/**
 * Starts a GNUnet daemon.
 *
 * @param service_home directory to use as the service home directory
 * @param transports transport services that should be loaded
 * @param applications application services and daemons that should be started
 * @param port_offset offset to add to all ports for all services
 * @param hostname name of the machine where to run GNUnet
 *        (use NULL for localhost).
 * @param cb function to call with the result
 * @param cb_cls closure for cb
 */
void
GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
			     struct GNUNET_CONFIGURATION_Handle *cfg,
			     const char *service_home,
			     const char *transports,
			     const char *applications,
			     uint16_t port_offset,
			     const char *hostname,
			     GNUNET_TESTING_NotifyDaemonRunning cb,
			     void *cb_cls);


/**
 * Prototype of a function that will be called when a
 * particular operation was completed the testing library.
 *
 * @param cls closure
 * @param success GNUNET_YES on success
 */
typedef void (*GNUNET_TESTING_NotifyCompletion)(void *cls,
						int success);


/**
 * Stops a GNUnet daemon.
 *
 * @param d the daemon that should be stopped
 * @param cb function called once the daemon was stopped
 * @param cb_cls closure for cb
 */
void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
				 GNUNET_TESTING_NotifyCompletion cb,
				 void * cb_cls);



/**
 * Establish a connection between two GNUnet daemons.
 *
 * @param d1 handle for the first daemon
 * @param d2 handle for the second daemon
 * @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,
				     GNUNET_TESTING_NotifyCompletion cb,
				     void *cb_cls);



/**
 * Start count gnunetd processes with the same set of
 * transports and applications.  The port numbers will
 * be computed by adding delta each time (zero
 * times for the first peer).
 *
 * @param total number of daemons to start
 * @param service_home_prefix path to use as the prefix for the home of the services
 * @param transports which transports should all peers use
 * @param applications which applications should be used?
 * @param timeout how long is this allowed to take?
 * @param cb function to call on each daemon that was started
 * @param cb_cls closure for cb
 * @param cbe function to call at the end
 * @param cbe_cls closure for cbe
 * @param hostname where to run the peers; can be NULL (to run
 *        everything on localhost).
 * @param va Additional hosts can be specified using a NULL-terminated list of
 *        varargs, hosts will then be used round-robin from that
 *        list; va only contains anything if hostname != NULL.
 */
void
GNUNET_TESTING_daemons_start_Va (struct GNUNET_SCHEDULER_Handle *sched,
				 struct GNUNET_CONFIGURATION_Handle *cfg,
				 unsigned int total,
				 const char *service_home_prefix,
				 const char *transports,
				 const char *applications,
				 GNUNET_TESTING_NotifyDaemonRunning cb,
				 void *cb_cls,
				 GNUNET_TESTING_NotifyCompletion cbe,
				 void *cbe_cls,
				 const char *hostname,
				 va_list va);

/**
 * Start count gnunetd processes with the same set of
 * transports and applications.  The port numbers will
 * be computed by adding delta each time (zero
 * times for the first peer).
 *
 * @param total number of daemons to start
 * @param service_home_prefix path to use as the prefix for the home of the services
 * @param transports which transports should all peers use
 * @param applications which applications should be used?
 * @param timeout how long is this allowed to take?
 * @param cb function to call on each daemon that was started
 * @param cb_cls closure for cb
 * @param cbe function to call at the end
 * @param cbe_cls closure for cbe
 * @param hostname where to run the peers; can be NULL (to run
 *        everything on localhost). Additional
 *        hosts can be specified using a NULL-terminated list of
 *        varargs, hosts will then be used round-robin from that
 *        list.
 */
void
GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
			      struct GNUNET_CONFIGURATION_Handle *cfg,
			      unsigned int total,
			      const char *service_home_prefix,
			      const char *transports,
			      const char *applications,
			      GNUNET_TESTING_NotifyDaemonRunning cb,
			      void *cb_cls,
			      GNUNET_TESTING_NotifyCompletion cbe,
			      void *cbe_cls,
			      const char *hostname,
			      ...);


/**
 * Handle to an entire testbed of GNUnet peers.
 */
struct GNUNET_TESTING_Testbed;

/**
 * Prototype of a function that will be called when 
 * a testbed is being created.
 *
 * @param cls closure
 * @param tb NULL on error
 */
typedef void (*GNUNET_TESTING_NotifyTestbedRunning)(void *cls,
						    struct GNUNET_TESTING_Testbed *tb);


/**
 * Topologies supported for testbeds.
 */
enum GNUNET_TESTING_Topology
{
  /**
   * A clique (everyone connected to everyone else).
   */
  GNUNET_TESTING_TOPOLOGY_CLIQUE,

  /**
   * Small-world network (2d torus plus random links).
   */
  GNUNET_TESTING_TOPOLOGY_SMALL_WORLD,

  /**
   * Ring topology.
   */
  GNUNET_TESTING_TOPOLOGY_RING,

  /**
   * 2-d torus.
   */
  GNUNET_TESTING_TOPOLOGY_2D_TORUS,

  /**
   * Random graph.
   */
  GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI,

  /**
   * All peers are disconnected.
   */
  GNUNET_TESTING_TOPOLOGY_NONE
};



/**
 * Start count GNUnet daemons with a particular
 * topology.
 *
 * @param size number of peers the testbed should have
 * @param topology desired topology (enforced via F2F)
 * @param service_home_prefix path to use as the prefix for the home of the services
 * @param transports which transports should all peers use
 * @param applications which applications should be used?
 * @param timeout how long is this allowed to take?
 * @param cb function to call on each daemon that was started
 * @param cb_cls closure for cb
 * @param cte function to call at the end
 * @param cte_cls closure for cbe
 * @param hostname where to run the peers; can be NULL (to run
 *        everything on localhost). Additional
 *        hosts can be specified using a NULL-terminated list of
 *        varargs, hosts will then be used round-robin from that
 *        list.
 */
void
GNUNET_TESTING_testbed_start (struct GNUNET_SCHEDULER_Handle *sched,
			      struct GNUNET_CONFIGURATION_Handle *cfg,
			      unsigned int size,
			      enum GNUNET_TESTING_Topology topology,
			      const char *service_home_prefix,
			      const char *transports,
			      const char *applications,
			      GNUNET_TESTING_NotifyDaemonRunning cb,
			      void *cb_cls,
			      GNUNET_TESTING_NotifyTestbedRunning cte,
			      void *cte_cls,
			      const char *hostname,
			      ...);




/**
 * Stop all of the daemons started with the start function.
 *
 * @param tb handle for the testbed
 * @param cb function to call at the end
 * @param cb_cls closure for cb
 */
void
GNUNET_TESTING_testbed_stop (struct GNUNET_TESTING_Testbed *tb,
			     GNUNET_TESTING_NotifyCompletion cb,
			     void *cb_cls );



/**
 * Simulate churn in the testbed by stopping some peers (and possibly
 * re-starting others if churn is called multiple times).  This
 * function can only be used to create leave-join churn (peers "never"
 * leave for good).  First "voff" random peers that are currently
 * online will be taken offline; then "von" random peers that are then
 * offline will be put back online.  No notifications will be
 * generated for any of these operations except for the callback upon
 * completion.  Note that the implementation is at liberty to keep
 * the ARM service itself (but none of the other services or daemons)
 * running even though the "peer" is being varied offline.
 *
 * @param tb handle for the testbed
 * @param voff number of peers that should go offline
 * @param von number of peers that should come back online;
 *            must be zero on first call (since "testbed_start"
 *            always starts all of the peers)
 * @param cb function to call at the end
 * @param cb_cls closure for cb
 */
void
GNUNET_TESTING_testbed_churn (struct GNUNET_TESTING_Testbed *tb,
			      unsigned int voff,
			      unsigned int von,
			      GNUNET_TESTING_NotifyCompletion cb,
			      void *cb_cls);



#if 0                           /* keep Emacsens' auto-indent happy */
{
#endif
#ifdef __cplusplus
}
#endif

#endif