aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-02-18 22:19:30 +0000
committerChristian Grothoff <christian@grothoff.org>2010-02-18 22:19:30 +0000
commit370a327990af109e75cd510c99b8e2843041a690 (patch)
treea2230a08844d553cc404b75993e4b52de0d36696 /src
parente4370ebaad64a2649fc56090a4151b3cca05d0c4 (diff)
downloadgnunet-370a327990af109e75cd510c99b8e2843041a690.tar.gz
gnunet-370a327990af109e75cd510c99b8e2843041a690.zip
starting library for FS multipeer testing
Diffstat (limited to 'src')
-rw-r--r--src/fs/Makefile.am9
-rw-r--r--src/fs/test_fs_lib.c474
-rw-r--r--src/fs/test_fs_lib.h161
3 files changed, 644 insertions, 0 deletions
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am
index a43c8340d..2e994b95a 100644
--- a/src/fs/Makefile.am
+++ b/src/fs/Makefile.am
@@ -13,6 +13,8 @@ endif
13 13
14lib_LTLIBRARIES = libgnunetfs.la 14lib_LTLIBRARIES = libgnunetfs.la
15 15
16noinst_LIBRARIES = libgnunetfstest.a
17
16libgnunetfs_la_SOURCES = \ 18libgnunetfs_la_SOURCES = \
17 fs.c \ 19 fs.c \
18 fs_collection.c \ 20 fs_collection.c \
@@ -39,6 +41,13 @@ libgnunetfs_la_LDFLAGS = \
39 -version-info 0:0:0 41 -version-info 0:0:0
40 42
41 43
44libgnunetfstest_a_SOURCES = \
45 test_fs_lib.c test_fs_lib.h
46
47libgnunetfstest_a_LIBADD = \
48 $(top_builddir)/src/fs/libgnunetfs.la \
49 $(top_builddir)/src/testing/libgnunettesting.la
50
42bin_PROGRAMS = \ 51bin_PROGRAMS = \
43 gnunet-directory \ 52 gnunet-directory \
44 gnunet-download \ 53 gnunet-download \
diff --git a/src/fs/test_fs_lib.c b/src/fs/test_fs_lib.c
new file mode 100644
index 000000000..f49dd85a5
--- /dev/null
+++ b/src/fs/test_fs_lib.c
@@ -0,0 +1,474 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19*/
20
21/**
22 * @file fs/test_fs_lib.c
23 * @brief library routines for testing FS publishing and downloading
24 * with multiple peers; this code is limited to flat files
25 * and no keywords (those functions can be tested with
26 * single-peer setups; this is for testing routing).
27 * @author Christian Grothoff
28 */
29#include "platform.h"
30#include "test_fs_lib.h"
31#include "gnunet_testing_lib.h"
32
33
34/**
35 * Handle for a daemon started for testing FS.
36 */
37struct GNUNET_FS_TestDaemon
38{
39
40 /**
41 * Handle to the file sharing context using this daemon.
42 */
43 struct GNUNET_FS_Handle *fs;
44
45 /**
46 * Handle to the daemon via testing.
47 */
48 struct GNUNET_TESTING_Daemon *daemon;
49
50 /**
51 * Note that 'group' will be the same value for all of the
52 * daemons started jointly.
53 */
54 struct GNUNET_TESTING_PeerGroup *group;
55
56 /**
57 * Configuration for accessing this peer.
58 */
59 struct GNUNET_CONFIGURATION_Handle *cfg;
60
61 /**
62 * ID of this peer.
63 */
64 struct GNUNET_PeerIdentity id;
65
66 /**
67 * Function to call when upload is done.
68 */
69 GNUNET_FS_TEST_UriContinuation publish_cont;
70
71 /**
72 * Closure for publish_cont.
73 */
74 void *publish_cont_cls;
75
76 /**
77 * Task to abort publishing (timeout).
78 */
79 GNUNET_SCHEDULER_TaskIdentifier publish_timeout_task;
80
81 /**
82 * Scheduler to use (for download_cont).
83 */
84 struct GNUNET_SCHEDULER_Handle *download_sched;
85
86 /**
87 * Function to call when download is done.
88 */
89 GNUNET_SCHEDULER_Task download_cont;
90
91 /**
92 * Closure for download_cont.
93 */
94 void *download_cont_cls;
95
96 /**
97 * Seed for download verification.
98 */
99 uint32_t download_seed;
100
101 /**
102 * Task to abort downloading (timeout).
103 */
104 GNUNET_SCHEDULER_TaskIdentifier download_timeout_task;
105
106 /**
107 * Verbosity level of the current operation.
108 */
109 int verbose;
110
111
112};
113
114
115static void*
116progress_cb (void *cls,
117 const struct GNUNET_FS_ProgressInfo *info)
118{
119 struct GNUNET_FS_TestDaemon *daemon = cls;
120
121 if (daemon->verbose > 2)
122 {
123
124 }
125 return NULL;
126}
127
128
129
130struct StartContext
131{
132 struct GNUNET_SCHEDULER_Handle *sched;
133 struct GNUNET_TIME_Relative timeout;
134 unsigned int total;
135 unsigned int have;
136 struct GNUNET_FS_TestDaemon **daemons;
137 GNUNET_SCHEDULER_Task cont;
138 void *cont_cls;
139 struct GNUNET_TESTING_PeerGroup *group;
140 struct GNUNET_CONFIGURATION_Handle *cfg;
141 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
142};
143
144
145static void
146notify_running (void *cls,
147 const struct GNUNET_PeerIdentity *id,
148 const struct GNUNET_CONFIGURATION_Handle *cfg,
149 struct GNUNET_TESTING_Daemon *d,
150 const char *emsg)
151{
152 struct StartContext *sctx = cls;
153 unsigned int i;
154
155 if (emsg != NULL)
156 {
157 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
158 _("Failed to start daemon: %s\n"),
159 emsg);
160 return;
161 }
162 GNUNET_assert (sctx->have < sctx->total);
163 sctx->daemons[sctx->have]->cfg = GNUNET_CONFIGURATION_dup (cfg);
164 sctx->daemons[sctx->have]->group = sctx->group;
165 sctx->daemons[sctx->have]->daemon = d;
166 sctx->daemons[sctx->have]->id = *id;
167 sctx->have++;
168 if (sctx->have == sctx->total)
169 {
170 GNUNET_SCHEDULER_add_continuation (sctx->sched,
171 sctx->cont,
172 sctx->cont_cls,
173 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
174 GNUNET_CONFIGURATION_destroy (sctx->cfg);
175 GNUNET_SCHEDULER_cancel (sctx->sched,
176 sctx->timeout_task);
177 for (i=0;i<sctx->total;i++)
178 sctx->daemons[i]->fs = GNUNET_FS_start (sctx->sched,
179 sctx->daemons[i]->cfg,
180 "<tester>",
181 &progress_cb,
182 sctx->daemons[i],
183 GNUNET_FS_FLAGS_NONE,
184 GNUNET_FS_OPTIONS_END);
185 GNUNET_free (sctx);
186 }
187}
188
189
190static void
191start_timeout (void *cls,
192 const struct GNUNET_SCHEDULER_TaskContext *tc)
193{
194 struct StartContext *sctx = cls;
195 unsigned int i;
196
197 GNUNET_TESTING_daemons_stop (sctx->group);
198 for (i=0;i<sctx->total;i++)
199 {
200 if (i < sctx->have)
201 GNUNET_CONFIGURATION_destroy (sctx->daemons[i]->cfg);
202 GNUNET_free (sctx->daemons[i]);
203 }
204 GNUNET_CONFIGURATION_destroy (sctx->cfg);
205 GNUNET_SCHEDULER_add_continuation (sctx->sched,
206 sctx->cont,
207 sctx->cont_cls,
208 GNUNET_SCHEDULER_REASON_TIMEOUT);
209 GNUNET_free (sctx);
210}
211
212
213/**
214 * Start daemons for testing.
215 *
216 * @param sched scheduler to use
217 * @param timeout if this operation cannot be completed within the
218 * given period, call the continuation with an error code
219 * @param total number of daemons to start
220 * @param daemons array of 'total' entries to be initialized
221 * (array must already be allocated, will be filled)
222 * @param cont function to call when done
223 * @param cont_cls closure for cont
224 */
225void
226GNUNET_FS_TEST_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
227 struct GNUNET_TIME_Relative timeout,
228 unsigned int total,
229 struct GNUNET_FS_TestDaemon **daemons,
230 GNUNET_SCHEDULER_Task cont,
231 void *cont_cls)
232{
233 struct StartContext *sctx;
234 unsigned int i;
235
236 GNUNET_assert (total > 0);
237 sctx = GNUNET_malloc (sizeof (struct StartContext));
238 sctx->sched = sched;
239 sctx->daemons = daemons;
240 sctx->total = total;
241 sctx->cont = cont;
242 sctx->cont_cls = cont_cls;
243 sctx->cfg = GNUNET_CONFIGURATION_create ();
244 if (GNUNET_OK !=
245 GNUNET_CONFIGURATION_load (sctx->cfg,
246 "test_fs_lib_data.conf"))
247 {
248 GNUNET_break (0);
249 GNUNET_CONFIGURATION_destroy (sctx->cfg);
250 GNUNET_free (sctx);
251 GNUNET_SCHEDULER_add_continuation (sched,
252 cont,
253 cont_cls,
254 GNUNET_SCHEDULER_REASON_TIMEOUT);
255 return;
256 }
257 for (i=0;i<total;i++)
258 daemons[i] = GNUNET_malloc (sizeof (struct GNUNET_FS_TestDaemon));
259 sctx->group = GNUNET_TESTING_daemons_start (sched,
260 sctx->cfg,
261 total,
262 &notify_running,
263 sctx,
264 NULL, NULL,
265 NULL);
266 sctx->timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
267 timeout,
268 &start_timeout,
269 sctx);
270}
271
272
273struct ConnectContext
274{
275 struct GNUNET_SCHEDULER_Handle *sched;
276 GNUNET_SCHEDULER_Task cont;
277 void *cont_cls;
278};
279
280
281static void
282notify_connection (void *cls,
283 const struct GNUNET_PeerIdentity *first,
284 const struct GNUNET_PeerIdentity *second,
285 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
286 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
287 struct GNUNET_TESTING_Daemon *first_daemon,
288 struct GNUNET_TESTING_Daemon *second_daemon,
289 const char *emsg)
290{
291 struct ConnectContext *cc = cls;
292
293 if (emsg != NULL)
294 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
295 _("Failed to connect peers: %s\n"),
296 emsg);
297 GNUNET_SCHEDULER_add_continuation (cc->sched,
298 cc->cont,
299 cc->cont_cls,
300 (emsg != NULL)
301 ? GNUNET_SCHEDULER_REASON_TIMEOUT
302 : GNUNET_SCHEDULER_REASON_PREREQ_DONE);
303 GNUNET_free (cc);
304}
305
306
307/**
308 * Connect two daemons for testing.
309 *
310 * @param sched scheduler to use
311 * @param daemon1 first daemon to connect
312 * @param daemon2 second first daemon to connect
313 * @param timeout if this operation cannot be completed within the
314 * given period, call the continuation with an error code
315 * @param cont function to call when done
316 * @param cont_cls closure for cont
317 */
318void
319GNUNET_FS_TEST_daemons_connect (struct GNUNET_SCHEDULER_Handle *sched,
320 struct GNUNET_FS_TestDaemon *daemon1,
321 struct GNUNET_FS_TestDaemon *daemon2,
322 struct GNUNET_TIME_Relative timeout,
323 GNUNET_SCHEDULER_Task cont,
324 void *cont_cls)
325{
326 struct ConnectContext *ncc;
327
328 ncc = GNUNET_malloc (sizeof (struct ConnectContext));
329 ncc->sched = sched;
330 ncc->cont = cont;
331 ncc->cont_cls = cont_cls;
332 GNUNET_TESTING_daemons_connect (daemon1->daemon,
333 daemon2->daemon,
334 timeout,
335 &notify_connection,
336 ncc);
337}
338
339
340/**
341 * Stop daemons used for testing.
342 *
343 * @param sched scheduler to use
344 * @param timeout if this operation cannot be completed within the
345 * given period, call the continuation with an error code
346 * @param total number of daemons to stop
347 * @param daemons array with the daemons (values will be clobbered)
348 * @param cont function to call when done
349 * @param cont_cls closure for cont
350 */
351void
352GNUNET_FS_TEST_daemons_stop (struct GNUNET_SCHEDULER_Handle *sched,
353 unsigned int total,
354 struct GNUNET_FS_TestDaemon **daemons)
355{
356 unsigned int i;
357
358 GNUNET_assert (total > 0);
359 GNUNET_TESTING_daemons_stop (daemons[0]->group);
360 for (i=0;i<total;i++)
361 {
362 GNUNET_CONFIGURATION_destroy (daemons[i]->cfg);
363 GNUNET_free (daemons[i]);
364 daemons[i] = NULL;
365 }
366}
367
368
369static void
370publish_timeout (void *cls,
371 const struct GNUNET_SCHEDULER_TaskContext *tc)
372{
373 struct GNUNET_FS_TestDaemon *daemon = cls;
374 GNUNET_FS_TEST_UriContinuation cont;
375
376 cont = daemon->publish_cont;
377 daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
378 daemon->publish_cont = NULL;
379 cont (daemon->publish_cont_cls,
380 NULL);
381}
382
383
384/**
385 * Publish a file at the given daemon.
386 *
387 * @param sched scheduler to use
388 * @param daemon where to publish
389 * @param timeout if this operation cannot be completed within the
390 * given period, call the continuation with an error code
391 * @param anonymity option for publication
392 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
393 * GNUNET_SYSERR for simulation
394 * @param size size of the file to publish
395 * @param seed seed to use for file generation
396 * @param verbose how verbose to be in reporting
397 * @param cont function to call when done
398 * @param cont_cls closure for cont
399 */
400void
401GNUNET_FS_TEST_publish (struct GNUNET_SCHEDULER_Handle *sched,
402 struct GNUNET_FS_TestDaemon *daemon,
403 struct GNUNET_TIME_Relative timeout,
404 uint32_t anonymity,
405 int do_index,
406 uint64_t size,
407 uint32_t seed,
408 unsigned int verbose,
409 GNUNET_FS_TEST_UriContinuation cont,
410 void *cont_cls)
411{
412 GNUNET_assert (daemon->publish_cont == NULL);
413
414 daemon->publish_cont = cont;
415 daemon->publish_cont_cls = cont_cls;
416 daemon->download_timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
417 timeout,
418 &publish_timeout,
419 daemon);
420}
421
422
423static void
424download_timeout (void *cls,
425 const struct GNUNET_SCHEDULER_TaskContext *tc)
426{
427 struct GNUNET_FS_TestDaemon *daemon = cls;
428
429 daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
430 GNUNET_SCHEDULER_add_continuation (daemon->download_sched,
431 daemon->download_cont,
432 daemon->download_cont_cls,
433 GNUNET_SCHEDULER_REASON_TIMEOUT);
434 daemon->download_cont = NULL;
435 daemon->download_sched = NULL;
436}
437
438
439/**
440 * Perform test download.
441 *
442 * @param sched scheduler to use
443 * @param daemon which peer to download from
444 * @param timeout if this operation cannot be completed within the
445 * given period, call the continuation with an error code
446 * @param anonymity option for download
447 * @param seed used for file validation
448 * @param verbose how verbose to be in reporting
449 * @param cont function to call when done
450 * @param cont_cls closure for cont
451 */
452void
453GNUNET_FS_TEST_download (struct GNUNET_SCHEDULER_Handle *sched,
454 struct GNUNET_FS_TestDaemon *daemon,
455 struct GNUNET_TIME_Relative timeout,
456 uint32_t anonymity,
457 uint32_t seed,
458 const struct GNUNET_FS_Uri *uri,
459 unsigned int verbose,
460 GNUNET_SCHEDULER_Task cont,
461 void *cont_cls)
462{
463 GNUNET_assert (daemon->download_cont == NULL);
464 daemon->download_sched = sched;
465 daemon->download_cont = cont;
466 daemon->download_cont_cls = cont_cls;
467 daemon->download_seed = seed;
468 daemon->download_timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
469 timeout,
470 &download_timeout,
471 daemon);
472}
473
474/* end of test_fs_lib.c */
diff --git a/src/fs/test_fs_lib.h b/src/fs/test_fs_lib.h
new file mode 100644
index 000000000..b9bbf7480
--- /dev/null
+++ b/src/fs/test_fs_lib.h
@@ -0,0 +1,161 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19*/
20
21/**
22 * @file fs/test_fs_lib.h
23 * @brief library routines for testing FS publishing and downloading
24 * with multiple peers; this code is limited to flat files
25 * and no keywords (those functions can be tested with
26 * single-peer setups; this is for testing routing).
27 * @author Christian Grothoff
28 */
29#ifndef TEST_FS_LIB_H
30#define TEST_FS_LIB_H
31
32#include "gnunet_util_lib.h"
33#include "gnunet_fs_service.h"
34
35/**
36 * Handle for a daemon started for testing FS.
37 */
38struct GNUNET_FS_TestDaemon;
39
40
41/**
42 * Start daemons for testing.
43 *
44 * @param sched scheduler to use
45 * @param timeout if this operation cannot be completed within the
46 * given period, call the continuation with an error code
47 * @param total number of daemons to start
48 * @param daemons array of 'total' entries to be initialized
49 * (array must already be allocated, will be filled)
50 * @param cont function to call when done
51 * @param cont_cls closure for cont
52 */
53void
54GNUNET_FS_TEST_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
55 struct GNUNET_TIME_Relative timeout,
56 unsigned int total,
57 struct GNUNET_FS_TestDaemon **daemons,
58 GNUNET_SCHEDULER_Task cont,
59 void *cont_cls);
60
61
62/**
63 * Connect two daemons for testing.
64 *
65 * @param sched scheduler to use
66 * @param daemon1 first daemon to connect
67 * @param daemon2 second first daemon to connect
68 * @param timeout if this operation cannot be completed within the
69 * given period, call the continuation with an error code
70 * @param cont function to call when done
71 * @param cont_cls closure for cont
72 */
73void
74GNUNET_FS_TEST_daemons_connect (struct GNUNET_SCHEDULER_Handle *sched,
75 struct GNUNET_FS_TestDaemon *daemon1,
76 struct GNUNET_FS_TestDaemon *daemon2,
77 struct GNUNET_TIME_Relative timeout,
78 GNUNET_SCHEDULER_Task cont,
79 void *cont_cls);
80
81
82/**
83 * Stop daemons used for testing.
84 *
85 * @param sched scheduler to use
86 * @param total number of daemons to stop
87 * @param daemons array with the daemons (values will be clobbered)
88 */
89void
90GNUNET_FS_TEST_daemons_stop (struct GNUNET_SCHEDULER_Handle *sched,
91 unsigned int total,
92 struct GNUNET_FS_TestDaemon **daemons);
93
94
95/**
96 * Function signature.
97 *
98 * @param cls closure (user defined)
99 * @param uri a URI, NULL for errors
100 */
101typedef void
102(*GNUNET_FS_TEST_UriContinuation)(void *cls,
103 const struct GNUNET_FS_Uri *uri);
104
105
106/**
107 * Publish a file at the given daemon.
108 *
109 * @param sched scheduler to use
110 * @param daemon where to publish
111 * @param timeout if this operation cannot be completed within the
112 * given period, call the continuation with an error code
113 * @param anonymity option for publication
114 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
115 * GNUNET_SYSERR for simulation
116 * @param size size of the file to publish
117 * @param seed seed to use for file generation
118 * @param verbose how verbose to be in reporting
119 * @param cont function to call when done
120 * @param cont_cls closure for cont
121 */
122void
123GNUNET_FS_TEST_publish (struct GNUNET_SCHEDULER_Handle *sched,
124 struct GNUNET_FS_TestDaemon *daemon,
125 struct GNUNET_TIME_Relative timeout,
126 uint32_t anonymity,
127 int do_index,
128 uint64_t size,
129 uint32_t seed,
130 unsigned int verbose,
131 GNUNET_FS_TEST_UriContinuation cont,
132 void *cont_cls);
133
134
135/**
136 * Perform test download.
137 *
138 * @param sched scheduler to use
139 * @param daemon which peer to download from
140 * @param timeout if this operation cannot be completed within the
141 * given period, call the continuation with an error code
142 * @param anonymity option for download
143 * @param seed used for file validation
144 * @param verbose how verbose to be in reporting
145 * @param cont function to call when done
146 * @param cont_cls closure for cont
147 */
148void
149GNUNET_FS_TEST_download (struct GNUNET_SCHEDULER_Handle *sched,
150 struct GNUNET_FS_TestDaemon *daemon,
151 struct GNUNET_TIME_Relative timeout,
152 uint32_t anonymity,
153 uint32_t seed,
154 const struct GNUNET_FS_Uri *uri,
155 unsigned int verbose,
156 GNUNET_SCHEDULER_Task cont,
157 void *cont_cls);
158
159
160
161#endif