aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-09-09 13:28:48 +0000
committerChristian Grothoff <christian@grothoff.org>2012-09-09 13:28:48 +0000
commit9d732bb204de9177aad6ae70c910cbf2615d81a3 (patch)
tree44ddd6e9e1dad749db51003acfa46d7835593dc6
parenta1d7926951beb7466a1462e43b9933530e5825f7 (diff)
downloadgnunet-9d732bb204de9177aad6ae70c910cbf2615d81a3.tar.gz
gnunet-9d732bb204de9177aad6ae70c910cbf2615d81a3.zip
make fs tests build against new testbed library -- they do not pass yet
-rw-r--r--src/fs/Makefile.am17
-rw-r--r--src/fs/fs_test_lib.c892
-rw-r--r--src/fs/fs_test_lib.h106
-rw-r--r--src/fs/perf_gnunet_service_fs_p2p.c200
-rw-r--r--src/fs/perf_gnunet_service_fs_p2p_respect.c210
-rw-r--r--src/fs/test_fs_test_lib.c98
-rw-r--r--src/fs/test_gnunet_service_fs_migration.c101
-rw-r--r--src/fs/test_gnunet_service_fs_p2p.c81
8 files changed, 766 insertions, 939 deletions
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am
index de5bb8ac4..b4e493d2b 100644
--- a/src/fs/Makefile.am
+++ b/src/fs/Makefile.am
@@ -57,7 +57,8 @@ libgnunetfstest_a_SOURCES = \
57 fs_test_lib.c fs_test_lib.h 57 fs_test_lib.c fs_test_lib.h
58 58
59libgnunetfstest_a_LIBADD = \ 59libgnunetfstest_a_LIBADD = \
60 $(top_builddir)/src/testing_old/libgnunettesting_old.la 60 $(top_builddir)/src/testing/libgnunettesting.la \
61 $(top_builddir)/src/testbed/libgnunettestbed.la
61 62
62bin_PROGRAMS = \ 63bin_PROGRAMS = \
63 gnunet-auto-share \ 64 gnunet-auto-share \
@@ -406,7 +407,7 @@ test_fs_test_lib_SOURCES = \
406 test_fs_test_lib.c 407 test_fs_test_lib.c
407test_fs_test_lib_LDADD = \ 408test_fs_test_lib_LDADD = \
408 $(top_builddir)/src/fs/libgnunetfstest.a \ 409 $(top_builddir)/src/fs/libgnunetfstest.a \
409 $(top_builddir)/src/testing_old/libgnunettesting_old.la \ 410 $(top_builddir)/src/testbed/libgnunettestbed.la \
410 $(top_builddir)/src/fs/libgnunetfs.la \ 411 $(top_builddir)/src/fs/libgnunetfs.la \
411 $(top_builddir)/src/util/libgnunetutil.la 412 $(top_builddir)/src/util/libgnunetutil.la
412 413
@@ -414,7 +415,7 @@ test_gnunet_service_fs_p2p_SOURCES = \
414 test_gnunet_service_fs_p2p.c 415 test_gnunet_service_fs_p2p.c
415test_gnunet_service_fs_p2p_LDADD = \ 416test_gnunet_service_fs_p2p_LDADD = \
416 $(top_builddir)/src/fs/libgnunetfstest.a \ 417 $(top_builddir)/src/fs/libgnunetfstest.a \
417 $(top_builddir)/src/testing_old/libgnunettesting_old.la \ 418 $(top_builddir)/src/testbed/libgnunettestbed.la \
418 $(top_builddir)/src/fs/libgnunetfs.la \ 419 $(top_builddir)/src/fs/libgnunetfs.la \
419 $(top_builddir)/src/util/libgnunetutil.la 420 $(top_builddir)/src/util/libgnunetutil.la
420 421
@@ -422,7 +423,7 @@ test_gnunet_service_fs_migration_SOURCES = \
422 test_gnunet_service_fs_migration.c 423 test_gnunet_service_fs_migration.c
423test_gnunet_service_fs_migration_LDADD = \ 424test_gnunet_service_fs_migration_LDADD = \
424 $(top_builddir)/src/fs/libgnunetfstest.a \ 425 $(top_builddir)/src/fs/libgnunetfstest.a \
425 $(top_builddir)/src/testing_old/libgnunettesting_old.la \ 426 $(top_builddir)/src/testbed/libgnunettestbed.la \
426 $(top_builddir)/src/fs/libgnunetfs.la \ 427 $(top_builddir)/src/fs/libgnunetfs.la \
427 $(top_builddir)/src/util/libgnunetutil.la 428 $(top_builddir)/src/util/libgnunetutil.la
428 429
@@ -431,7 +432,7 @@ perf_gnunet_service_fs_p2p_SOURCES = \
431perf_gnunet_service_fs_p2p_LDADD = \ 432perf_gnunet_service_fs_p2p_LDADD = \
432 $(top_builddir)/src/fs/libgnunetfstest.a \ 433 $(top_builddir)/src/fs/libgnunetfstest.a \
433 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 434 $(top_builddir)/src/statistics/libgnunetstatistics.la \
434 $(top_builddir)/src/testing_old/libgnunettesting_old.la \ 435 $(top_builddir)/src/testbed/libgnunettestbed.la \
435 $(top_builddir)/src/fs/libgnunetfs.la \ 436 $(top_builddir)/src/fs/libgnunetfs.la \
436 $(top_builddir)/src/util/libgnunetutil.la 437 $(top_builddir)/src/util/libgnunetutil.la
437 438
@@ -440,7 +441,7 @@ perf_gnunet_service_fs_p2p_index_SOURCES = \
440perf_gnunet_service_fs_p2p_index_LDADD = \ 441perf_gnunet_service_fs_p2p_index_LDADD = \
441 $(top_builddir)/src/fs/libgnunetfstest.a \ 442 $(top_builddir)/src/fs/libgnunetfstest.a \
442 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 443 $(top_builddir)/src/statistics/libgnunetstatistics.la \
443 $(top_builddir)/src/testing_old/libgnunettesting_old.la \ 444 $(top_builddir)/src/testbed/libgnunettestbed.la \
444 $(top_builddir)/src/fs/libgnunetfs.la \ 445 $(top_builddir)/src/fs/libgnunetfs.la \
445 $(top_builddir)/src/util/libgnunetutil.la 446 $(top_builddir)/src/util/libgnunetutil.la
446 447
@@ -449,7 +450,7 @@ perf_gnunet_service_fs_p2p_dht_SOURCES = \
449perf_gnunet_service_fs_p2p_dht_LDADD = \ 450perf_gnunet_service_fs_p2p_dht_LDADD = \
450 $(top_builddir)/src/fs/libgnunetfstest.a \ 451 $(top_builddir)/src/fs/libgnunetfstest.a \
451 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 452 $(top_builddir)/src/statistics/libgnunetstatistics.la \
452 $(top_builddir)/src/testing_old/libgnunettesting_old.la \ 453 $(top_builddir)/src/testbed/libgnunettestbed.la \
453 $(top_builddir)/src/fs/libgnunetfs.la \ 454 $(top_builddir)/src/fs/libgnunetfs.la \
454 $(top_builddir)/src/util/libgnunetutil.la 455 $(top_builddir)/src/util/libgnunetutil.la
455 456
@@ -458,7 +459,7 @@ perf_gnunet_service_fs_p2p_respect_SOURCES = \
458perf_gnunet_service_fs_p2p_respect_LDADD = \ 459perf_gnunet_service_fs_p2p_respect_LDADD = \
459 $(top_builddir)/src/fs/libgnunetfstest.a \ 460 $(top_builddir)/src/fs/libgnunetfstest.a \
460 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 461 $(top_builddir)/src/statistics/libgnunetstatistics.la \
461 $(top_builddir)/src/testing_old/libgnunettesting_old.la \ 462 $(top_builddir)/src/testbed/libgnunettestbed.la \
462 $(top_builddir)/src/fs/libgnunetfs.la \ 463 $(top_builddir)/src/fs/libgnunetfs.la \
463 $(top_builddir)/src/util/libgnunetutil.la 464 $(top_builddir)/src/util/libgnunetutil.la
464 465
diff --git a/src/fs/fs_test_lib.c b/src/fs/fs_test_lib.c
index 06ab01f8d..bbed98249 100644
--- a/src/fs/fs_test_lib.c
+++ b/src/fs/fs_test_lib.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2010, 2011 Christian Grothoff (and other contributing authors) 3 (C) 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -20,8 +20,8 @@
20 20
21/** 21/**
22 * @file fs/fs_test_lib.c 22 * @file fs/fs_test_lib.c
23 * @brief library routines for testing FS publishing and downloading 23 * @brief library routines for testing FS publishing and downloading;
24 * with multiple peers; this code is limited to flat files 24 * this code is limited to flat files
25 * and no keywords (those functions can be tested with 25 * and no keywords (those functions can be tested with
26 * single-peer setups; this is for testing routing). 26 * single-peer setups; this is for testing routing).
27 * @author Christian Grothoff 27 * @author Christian Grothoff
@@ -29,23 +29,21 @@
29#include "platform.h" 29#include "platform.h"
30#include "fs_api.h" 30#include "fs_api.h"
31#include "fs_test_lib.h" 31#include "fs_test_lib.h"
32#include "gnunet_testing_lib.h"
33 32
34#define CONNECT_ATTEMPTS 4
35 33
36#define CONTENT_LIFETIME GNUNET_TIME_UNIT_HOURS 34#define CONTENT_LIFETIME GNUNET_TIME_UNIT_HOURS
37 35
36
38/** 37/**
39 * Handle for a daemon started for testing FS. 38 * Handle for a publishing operation started for testing FS.
40 */ 39 */
41struct GNUNET_FS_TestDaemon 40struct TestPublishOperation
42{ 41{
43 42
44 /** 43 /**
45 * Global configuration, only stored in first test daemon, 44 * Handle for the operation to connect to the peer's 'fs' service.
46 * otherwise NULL.
47 */ 45 */
48 struct GNUNET_CONFIGURATION_Handle *gcfg; 46 struct GNUNET_TESTBED_Operation *fs_op;
49 47
50 /** 48 /**
51 * Handle to the file sharing context using this daemon. 49 * Handle to the file sharing context using this daemon.
@@ -53,27 +51,6 @@ struct GNUNET_FS_TestDaemon
53 struct GNUNET_FS_Handle *fs; 51 struct GNUNET_FS_Handle *fs;
54 52
55 /** 53 /**
56 * Handle to the daemon via testing.
57 */
58 struct GNUNET_TESTING_Daemon *daemon;
59
60 /**
61 * Note that 'group' will be the same value for all of the
62 * daemons started jointly.
63 */
64 struct GNUNET_TESTING_PeerGroup *group;
65
66 /**
67 * Configuration for accessing this peer.
68 */
69 struct GNUNET_CONFIGURATION_Handle *cfg;
70
71 /**
72 * ID of this peer.
73 */
74 struct GNUNET_PeerIdentity id;
75
76 /**
77 * Function to call when upload is done. 54 * Function to call when upload is done.
78 */ 55 */
79 GNUNET_FS_TEST_UriContinuation publish_cont; 56 GNUNET_FS_TEST_UriContinuation publish_cont;
@@ -109,6 +86,49 @@ struct GNUNET_FS_TestDaemon
109 char *publish_tmp_file; 86 char *publish_tmp_file;
110 87
111 /** 88 /**
89 * Size of the file.
90 */
91 uint64_t size;
92
93 /**
94 * Anonymity level used.
95 */
96 uint32_t anonymity;
97
98 /**
99 * Verbosity level of the current operation.
100 */
101 unsigned int verbose;
102
103 /**
104 * Are we testing indexing? (YES: index, NO: insert, SYSERR: simulate)
105 */
106 int do_index;
107};
108
109
110/**
111 * Handle for a download operation started for testing FS.
112 */
113struct TestDownloadOperation
114{
115
116 /**
117 * Handle for the operation to connect to the peer's 'fs' service.
118 */
119 struct GNUNET_TESTBED_Operation *fs_op;
120
121 /**
122 * Handle to the file sharing context using this daemon.
123 */
124 struct GNUNET_FS_Handle *fs;
125
126 /**
127 * Handle to the daemon via testing.
128 */
129 struct GNUNET_TESTING_Daemon *daemon;
130
131 /**
112 * Function to call when download is done. 132 * Function to call when download is done.
113 */ 133 */
114 GNUNET_SCHEDULER_Task download_cont; 134 GNUNET_SCHEDULER_Task download_cont;
@@ -119,9 +139,9 @@ struct GNUNET_FS_TestDaemon
119 void *download_cont_cls; 139 void *download_cont_cls;
120 140
121 /** 141 /**
122 * Seed for download verification. 142 * URI to download.
123 */ 143 */
124 uint32_t download_seed; 144 struct GNUNET_FS_Uri *uri;
125 145
126 /** 146 /**
127 * Task to abort downloading (timeout). 147 * Task to abort downloading (timeout).
@@ -134,107 +154,108 @@ struct GNUNET_FS_TestDaemon
134 struct GNUNET_FS_DownloadContext *download_context; 154 struct GNUNET_FS_DownloadContext *download_context;
135 155
136 /** 156 /**
137 * Verbosity level of the current operation. 157 * Size of the file.
138 */ 158 */
139 int verbose; 159 uint64_t size;
140 160
161 /**
162 * Anonymity level used.
163 */
164 uint32_t anonymity;
141 165
142}; 166 /**
167 * Seed for download verification.
168 */
169 uint32_t download_seed;
143 170
144/** 171 /**
145 * Check whether peers successfully shut down. 172 * Verbosity level of the current operation.
146 */ 173 */
147static void 174 unsigned int verbose;
148shutdown_callback (void *cls, const char *emsg)
149{
150 struct GNUNET_CONFIGURATION_Handle *gcfg = cls;
151 175
152 if (emsg != NULL) 176};
153 {
154 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Shutdown of peers failed: %s\n",
155 emsg);
156 }
157 else
158 {
159#if VERBOSE
160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n");
161#endif
162 }
163 if (gcfg != NULL)
164 GNUNET_CONFIGURATION_destroy (gcfg);
165}
166 177
167 178
179/**
180 * Task scheduled to report on the completion of our publish operation.
181 *
182 * @param cls the publish operation context
183 * @param tc scheduler context (unused)
184 */
168static void 185static void
169report_uri (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 186report_uri (void *cls,
187 const struct GNUNET_SCHEDULER_TaskContext *tc)
170{ 188{
171 struct GNUNET_FS_TestDaemon *daemon = cls; 189 struct TestPublishOperation *po = cls;
172 GNUNET_FS_TEST_UriContinuation cont; 190
173 struct GNUNET_FS_Uri *uri; 191 GNUNET_FS_publish_stop (po->publish_context);
174 192 GNUNET_TESTBED_operation_done (po->fs_op);
175 GNUNET_FS_publish_stop (daemon->publish_context); 193 po->publish_cont (po->publish_cont_cls, po->publish_uri);
176 daemon->publish_context = NULL; 194 GNUNET_FS_uri_destroy (po->publish_uri);
177 cont = daemon->publish_cont; 195 GNUNET_free_non_null (po->publish_tmp_file);
178 daemon->publish_cont = NULL; 196 GNUNET_free (po);
179 uri = daemon->publish_uri;
180 cont (daemon->publish_cont_cls, uri);
181 GNUNET_FS_uri_destroy (uri);
182} 197}
183 198
184 199
200/**
201 * Task scheduled to run when publish operation times out.
202 *
203 * @param cls the publish operation context
204 * @param tc scheduler context (unused)
205 */
185static void 206static void
186report_success (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 207publish_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
187{ 208{
188 struct GNUNET_FS_TestDaemon *daemon = cls; 209 struct TestPublishOperation *po = cls;
189 210
190 GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES); 211 po->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
191 daemon->download_context = NULL; 212 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
192 GNUNET_SCHEDULER_add_continuation (daemon->download_cont, 213 "Timeout while trying to publish data\n");
193 daemon->download_cont_cls, 214 if (NULL == po->fs)
194 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 215 GNUNET_TESTBED_operation_cancel (po->fs_op);
195 daemon->download_cont = NULL; 216 else
217 GNUNET_TESTBED_operation_done (po->fs_op);
218 GNUNET_FS_publish_stop (po->publish_context);
219 GNUNET_TESTBED_operation_done (po->fs_op);
220 po->publish_cont (po->publish_cont_cls, NULL);
221 GNUNET_free_non_null (po->publish_tmp_file);
222 GNUNET_free (po);
196} 223}
197 224
198 225
226/**
227 * Progress callback for file-sharing events while publishing.
228 *
229 * @param cls the publish operation context
230 * @param info information about the event
231 */
199static void * 232static void *
200progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) 233publish_progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
201{ 234{
202 struct GNUNET_FS_TestDaemon *daemon = cls; 235 struct TestPublishOperation *po = cls;
203 236
204 switch (info->status) 237 switch (info->status)
205 { 238 {
206 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 239 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
207 GNUNET_SCHEDULER_cancel (daemon->publish_timeout_task); 240 GNUNET_SCHEDULER_cancel (po->publish_timeout_task);
208 daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK; 241 po->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
209 daemon->publish_uri = 242 po->publish_uri =
210 GNUNET_FS_uri_dup (info->value.publish.specifics.completed.chk_uri); 243 GNUNET_FS_uri_dup (info->value.publish.specifics.completed.chk_uri);
211 GNUNET_SCHEDULER_add_continuation (&report_uri, daemon, 244 GNUNET_SCHEDULER_add_continuation (&report_uri, po,
212 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 245 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
213 break; 246 break;
214 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 247 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
215 if (daemon->verbose) 248 if (po->verbose)
216 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Publishing at %llu/%llu bytes\n", 249 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Publishing at %llu/%llu bytes\n",
217 (unsigned long long) info->value.publish.completed, 250 (unsigned long long) info->value.publish.completed,
218 (unsigned long long) info->value.publish.size); 251 (unsigned long long) info->value.publish.size);
219 break; 252 break;
220 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: 253 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
221 if (daemon->verbose) 254 if (po->verbose)
222 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Download at %llu/%llu bytes\n", 255 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Download at %llu/%llu bytes\n",
223 (unsigned long long) info->value.download.completed, 256 (unsigned long long) info->value.download.completed,
224 (unsigned long long) info->value.download.size); 257 (unsigned long long) info->value.download.size);
225 break; 258 break;
226 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
227 GNUNET_SCHEDULER_cancel (daemon->download_timeout_task);
228 daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
229 GNUNET_SCHEDULER_add_continuation (&report_success, daemon,
230 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
231 break;
232 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
233 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
234 break;
235 /* FIXME: monitor data correctness during download progress */
236 /* FIXME: do performance reports given sufficient verbosity */
237 /* FIXME: advance timeout task to "immediate" on error */
238 default: 259 default:
239 break; 260 break;
240 } 261 }
@@ -242,460 +263,347 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
242} 263}
243 264
244 265
245struct StartContext 266/**
246{ 267 * Generate test data for publishing test.
247 struct GNUNET_TIME_Relative timeout; 268 *
248 unsigned int total; 269 * @param cls pointer to uint32_t with publishing seed
249 unsigned int have; 270 * @param offset offset to generate data for
250 struct GNUNET_FS_TestDaemon **daemons; 271 * @param max maximum number of bytes to generate
251 GNUNET_SCHEDULER_Task cont; 272 * @param buf where to write generated data
252 void *cont_cls; 273 * @param emsg where to store error message (unused)
253 struct GNUNET_TESTING_PeerGroup *group; 274 * @return number of bytes written to buf
254 struct GNUNET_CONFIGURATION_Handle *cfg; 275 */
255 GNUNET_SCHEDULER_TaskIdentifier timeout_task; 276static size_t
256}; 277file_generator (void *cls,
257 278 uint64_t offset,
258 279 size_t max,
259static void 280 void *buf,
260notify_running (void *cls, const struct GNUNET_PeerIdentity *id, 281 char **emsg)
261 const struct GNUNET_CONFIGURATION_Handle *cfg,
262 struct GNUNET_TESTING_Daemon *d, const char *emsg)
263{ 282{
264 struct StartContext *sctx = cls; 283 uint32_t *publish_seed = cls;
265 unsigned int i; 284 uint64_t pos;
285 uint8_t *cbuf = buf;
286 int mod;
266 287
267 if (emsg != NULL) 288 if (emsg != NULL)
289 *emsg = NULL;
290 if (buf == NULL)
291 return 0;
292 for (pos = 0; pos < 8; pos++)
293 cbuf[pos] = (uint8_t) (offset >> pos * 8);
294 for (pos = 8; pos < max; pos++)
268 { 295 {
269 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to start daemon: %s\n"), 296 mod = (255 - (offset / 1024 / 32));
270 emsg); 297 if (mod == 0)
271 return; 298 mod = 1;
272 } 299 cbuf[pos] = (uint8_t) ((offset * (*publish_seed)) % mod);
273 i = 0;
274 while (i < sctx->total)
275 {
276 if (GNUNET_TESTING_daemon_get (sctx->group, i) == d)
277 break;
278 i++;
279 }
280 GNUNET_assert (i < sctx->total);
281 GNUNET_assert (sctx->have < sctx->total);
282 GNUNET_assert (sctx->daemons[i]->cfg == NULL);
283 sctx->daemons[i]->cfg = GNUNET_CONFIGURATION_dup (cfg);
284 sctx->daemons[i]->group = sctx->group;
285 sctx->daemons[i]->daemon = d;
286 sctx->daemons[i]->id = *id;
287 sctx->have++;
288 if (sctx->have == sctx->total)
289 {
290 GNUNET_SCHEDULER_add_continuation (sctx->cont, sctx->cont_cls,
291 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
292 sctx->daemons[0]->gcfg = sctx->cfg;
293 GNUNET_SCHEDULER_cancel (sctx->timeout_task);
294 for (i = 0; i < sctx->total; i++)
295 {
296 sctx->daemons[i]->fs =
297 GNUNET_FS_start (sctx->daemons[i]->cfg, "<tester>", &progress_cb,
298 sctx->daemons[i], GNUNET_FS_FLAGS_NONE,
299 GNUNET_FS_OPTIONS_END);
300 }
301 GNUNET_free (sctx);
302 } 300 }
301 return max;
303} 302}
304 303
305 304
306static void 305/**
307start_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 306 * Connect adapter for publishing operation.
307 *
308 * @param cls the 'struct TestPublishOperation'
309 * @param cfg configuration of the peer to connect to; will be available until
310 * GNUNET_TESTBED_operation_done() is called on the operation returned
311 * from GNUNET_TESTBED_service_connect()
312 * @return service handle to return in 'op_result', NULL on error
313 */
314static void *
315publish_connect_adapter (void *cls,
316 const struct GNUNET_CONFIGURATION_Handle *cfg)
308{ 317{
309 struct StartContext *sctx = cls; 318 struct TestPublishOperation *po = cls;
310 unsigned int i; 319
311 320 return GNUNET_FS_start (cfg,
312 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 321 "fs-test-publish",
313 "Timeout while trying to start daemons\n"); 322 &publish_progress_cb, po,
314 GNUNET_TESTING_daemons_stop (sctx->group, 323 GNUNET_FS_OPTIONS_END);
315 GNUNET_TIME_relative_multiply
316 (GNUNET_TIME_UNIT_SECONDS, 30),
317 &shutdown_callback, NULL);
318 for (i = 0; i < sctx->total; i++)
319 {
320 if (i < sctx->have)
321 GNUNET_CONFIGURATION_destroy (sctx->daemons[i]->cfg);
322 GNUNET_free (sctx->daemons[i]);
323 sctx->daemons[i] = NULL;
324 }
325 GNUNET_CONFIGURATION_destroy (sctx->cfg);
326 GNUNET_SCHEDULER_add_continuation (sctx->cont, sctx->cont_cls,
327 GNUNET_SCHEDULER_REASON_TIMEOUT);
328 GNUNET_free (sctx);
329} 324}
330 325
331 326
332/** 327/**
333 * Start daemons for testing. 328 * Adapter function called to destroy connection to file-sharing service.
334 * 329 *
335 * @param template_cfg_file configuration template to use 330 * @param cls the 'struct GNUNET_FS_Handle'
336 * @param timeout if this operation cannot be completed within the 331 * @param op_result unused (different for publish/download!)
337 * given period, call the continuation with an error code
338 * @param total number of daemons to start
339 * @param daemons array of 'total' entries to be initialized
340 * (array must already be allocated, will be filled)
341 * @param cont function to call when done
342 * @param cont_cls closure for cont
343 */ 332 */
344void 333static void
345GNUNET_FS_TEST_daemons_start (const char *template_cfg_file, 334fs_disconnect_adapter (void *cls,
346 struct GNUNET_TIME_Relative timeout, 335 void *op_result)
347 unsigned int total,
348 struct GNUNET_FS_TestDaemon **daemons,
349 GNUNET_SCHEDULER_Task cont, void *cont_cls)
350{ 336{
351 struct StartContext *sctx; 337 struct GNUNET_FS_Handle *fs = op_result;
352 unsigned int i;
353
354 GNUNET_assert (total > 0);
355 sctx = GNUNET_malloc (sizeof (struct StartContext));
356 sctx->daemons = daemons;
357 sctx->total = total;
358 sctx->cont = cont;
359 sctx->cont_cls = cont_cls;
360 sctx->cfg = GNUNET_CONFIGURATION_create ();
361 if (GNUNET_OK != GNUNET_CONFIGURATION_load (sctx->cfg, template_cfg_file))
362 {
363 GNUNET_break (0);
364 GNUNET_CONFIGURATION_destroy (sctx->cfg);
365 GNUNET_free (sctx);
366 GNUNET_SCHEDULER_add_continuation (cont, cont_cls,
367 GNUNET_SCHEDULER_REASON_TIMEOUT);
368 return;
369 }
370 for (i = 0; i < total; i++)
371 daemons[i] = GNUNET_malloc (sizeof (struct GNUNET_FS_TestDaemon));
372 sctx->group = GNUNET_TESTING_daemons_start (sctx->cfg, total, total, /* Outstanding connections */
373 total, /* Outstanding ssh connections */
374 timeout, NULL, NULL,
375 &notify_running, sctx, NULL, NULL,
376 NULL);
377 sctx->timeout_task =
378 GNUNET_SCHEDULER_add_delayed (timeout, &start_timeout, sctx);
379}
380 338
381 339 GNUNET_FS_stop (fs);
382struct GNUNET_FS_TEST_ConnectContext 340}
383{
384 GNUNET_SCHEDULER_Task cont;
385 void *cont_cls;
386 struct GNUNET_TESTING_ConnectContext *cc;
387};
388 341
389 342
390/** 343/**
391 * Prototype of a function that will be called whenever 344 * Callback to be called when testbed has connected to the fs service
392 * two daemons are connected by the testing library.
393 * 345 *
394 * @param cls closure 346 * @param cls the 'struct TestPublishOperation'
395 * @param first peer id for first daemon 347 * @param op the operation that has been finished
396 * @param second peer id for the second daemon 348 * @param ca_result the 'struct GNUNET_FS_Handle ' (NULL on error)
397 * @param distance distance between the connected peers 349 * @param emsg error message in case the operation has failed; will be NULL if
398 * @param first_cfg config for the first daemon 350 * operation has executed successfully.
399 * @param second_cfg config for the second daemon
400 * @param first_daemon handle for the first daemon
401 * @param second_daemon handle for the second daemon
402 * @param emsg error message (NULL on success)
403 */ 351 */
404static void 352static void
405notify_connection (void *cls, const struct GNUNET_PeerIdentity *first, 353publish_fs_connect_complete_cb (void *cls,
406 const struct GNUNET_PeerIdentity *second, uint32_t distance, 354 struct GNUNET_TESTBED_Operation *op,
407 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 355 void *ca_result,
408 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 356 const char *emsg)
409 struct GNUNET_TESTING_Daemon *first_daemon,
410 struct GNUNET_TESTING_Daemon *second_daemon,
411 const char *emsg)
412{ 357{
413 struct GNUNET_FS_TEST_ConnectContext *cc = cls; 358 struct TestPublishOperation *po = cls;
359 struct GNUNET_FS_FileInformation *fi;
360 struct GNUNET_DISK_FileHandle *fh;
361 char *em;
362 uint64_t off;
363 char buf[DBLOCK_SIZE];
364 size_t bsize;
365 struct GNUNET_FS_BlockOptions bo;
414 366
415 cc->cc = NULL; 367 if (NULL == ca_result)
416 if (emsg != NULL) 368 {
417 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to connect peers: %s\n", 369 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to connect to FS for publishing: %s\n", emsg);
418 emsg); 370 po->publish_cont (po->publish_cont_cls,
419 GNUNET_SCHEDULER_add_continuation (cc->cont, cc->cont_cls, 371 NULL);
420 (emsg != 372 GNUNET_TESTBED_operation_done (po->fs_op);
421 NULL) ? GNUNET_SCHEDULER_REASON_TIMEOUT : 373 GNUNET_free (po);
422 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 374 return;
423 GNUNET_free (cc); 375 }
376 po->fs = ca_result;
377
378 bo.expiration_time = GNUNET_TIME_relative_to_absolute (CONTENT_LIFETIME);
379 bo.anonymity_level = po->anonymity;
380 bo.content_priority = 42;
381 bo.replication_level = 1;
382 if (GNUNET_YES == po->do_index)
383 {
384 po->publish_tmp_file = GNUNET_DISK_mktemp ("fs-test-publish-index");
385 GNUNET_assert (po->publish_tmp_file != NULL);
386 fh = GNUNET_DISK_file_open (po->publish_tmp_file,
387 GNUNET_DISK_OPEN_WRITE |
388 GNUNET_DISK_OPEN_CREATE,
389 GNUNET_DISK_PERM_USER_READ |
390 GNUNET_DISK_PERM_USER_WRITE);
391 GNUNET_assert (NULL != fh);
392 off = 0;
393 while (off < po->size)
394 {
395 bsize = GNUNET_MIN (sizeof (buf), po->size - off);
396 emsg = NULL;
397 GNUNET_assert (bsize == file_generator (&po->publish_seed, off, bsize, buf, &em));
398 GNUNET_assert (em == NULL);
399 GNUNET_assert (bsize == GNUNET_DISK_file_write (fh, buf, bsize));
400 off += bsize;
401 }
402 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
403 fi = GNUNET_FS_file_information_create_from_file (po->fs, po,
404 po->publish_tmp_file,
405 NULL, NULL, po->do_index,
406 &bo);
407 }
408 else
409 {
410 fi = GNUNET_FS_file_information_create_from_reader (po->fs, po,
411 po->size,
412 &file_generator, &po->publish_seed,
413 NULL, NULL,
414 po->do_index, &bo);
415 }
416 po->publish_context =
417 GNUNET_FS_publish_start (po->fs, fi, NULL, NULL, NULL,
418 GNUNET_FS_PUBLISH_OPTION_NONE);
424} 419}
425 420
426 421
427/** 422/**
428 * Connect two daemons for testing. 423 * Publish a file at the given peer.
429 * 424 *
430 * @param daemon1 first daemon to connect 425 * @param peer where to publish
431 * @param daemon2 second first daemon to connect
432 * @param timeout if this operation cannot be completed within the 426 * @param timeout if this operation cannot be completed within the
433 * given period, call the continuation with an error code 427 * given period, call the continuation with an error code
428 * @param anonymity option for publication
429 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
430 * GNUNET_SYSERR for simulation
431 * @param size size of the file to publish
432 * @param seed seed to use for file generation
433 * @param verbose how verbose to be in reporting
434 * @param cont function to call when done 434 * @param cont function to call when done
435 * @param cont_cls closure for cont 435 * @param cont_cls closure for cont
436 */ 436 */
437struct GNUNET_FS_TEST_ConnectContext * 437void
438GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1, 438GNUNET_FS_TEST_publish (struct GNUNET_TESTBED_Peer *peer,
439 struct GNUNET_FS_TestDaemon *daemon2, 439 struct GNUNET_TIME_Relative timeout, uint32_t anonymity,
440 struct GNUNET_TIME_Relative timeout, 440 int do_index, uint64_t size, uint32_t seed,
441 GNUNET_SCHEDULER_Task cont, void *cont_cls) 441 unsigned int verbose,
442 GNUNET_FS_TEST_UriContinuation cont, void *cont_cls)
442{ 443{
443 struct GNUNET_FS_TEST_ConnectContext *ncc; 444 struct TestPublishOperation *po;
444 445
445 ncc = GNUNET_malloc (sizeof (struct GNUNET_FS_TEST_ConnectContext)); 446 po = GNUNET_malloc (sizeof (struct TestPublishOperation));
446 ncc->cont = cont; 447 po->publish_cont = cont;
447 ncc->cont_cls = cont_cls; 448 po->publish_cont_cls = cont_cls;
448 ncc->cc = 449 po->publish_seed = seed;
449 GNUNET_TESTING_daemons_connect (daemon1->daemon, daemon2->daemon, timeout, 450 po->anonymity = anonymity;
450 CONNECT_ATTEMPTS, GNUNET_YES, 451 po->size = size;
451 &notify_connection, ncc); 452 po->verbose = verbose;
452 return ncc; 453 po->do_index = do_index;
454 po->fs_op = GNUNET_TESTBED_service_connect (po,
455 peer,
456 "fs",
457 &publish_fs_connect_complete_cb,
458 po,
459 &publish_connect_adapter,
460 &fs_disconnect_adapter,
461 po);
462 po->publish_timeout_task =
463 GNUNET_SCHEDULER_add_delayed (timeout, &publish_timeout, po);
453} 464}
454 465
455 466
456/** 467/* ************************** download ************************ */
457 * Cancel connect operation.
458 *
459 * @param cc operation to cancel
460 */
461void
462GNUNET_FS_TEST_daemons_connect_cancel (struct GNUNET_FS_TEST_ConnectContext *cc)
463{
464 GNUNET_TESTING_daemons_connect_cancel (cc->cc);
465 GNUNET_free (cc);
466}
467 468
468 469
469/** 470/**
470 * Obtain peer configuration used for testing. 471 * Task scheduled to run when download operation times out.
471 * 472 *
472 * @param daemons array with the daemons 473 * @param cls the download operation context
473 * @param off which configuration to get 474 * @param tc scheduler context (unused)
474 * @return peer configuration
475 */ 475 */
476const struct GNUNET_CONFIGURATION_Handle * 476static void
477GNUNET_FS_TEST_get_configuration (struct GNUNET_FS_TestDaemon **daemons, 477download_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
478 unsigned int off)
479{ 478{
480 return daemons[off]->cfg; 479 struct TestDownloadOperation *dop = cls;
481}
482 480
483/** 481 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
484 * Obtain peer group used for testing. 482 "Timeout while trying to download file\n");
485 * 483 dop->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
486 * @param daemons array with the daemons (must contain at least one) 484 GNUNET_FS_download_stop (dop->download_context, GNUNET_YES);
487 * @return peer group 485 GNUNET_SCHEDULER_add_continuation (dop->download_cont,
488 */ 486 dop->download_cont_cls,
489struct GNUNET_TESTING_PeerGroup * 487 GNUNET_SCHEDULER_REASON_TIMEOUT);
490GNUNET_FS_TEST_get_group (struct GNUNET_FS_TestDaemon **daemons) 488 if (NULL == dop->fs)
491{ 489 GNUNET_TESTBED_operation_cancel (dop->fs_op);
492 return daemons[0]->group; 490 else
491 GNUNET_TESTBED_operation_done (dop->fs_op);
492 GNUNET_FS_uri_destroy (dop->uri);
493 GNUNET_free (dop);
493} 494}
494 495
495 496
496/** 497/**
497 * Stop daemons used for testing. 498 * Task scheduled to report on the completion of our download operation.
498 * 499 *
499 * @param total number of daemons to stop 500 * @param cls the download operation context
500 * @param daemons array with the daemons (values will be clobbered) 501 * @param tc scheduler context (unused)
501 */ 502 */
502void
503GNUNET_FS_TEST_daemons_stop (unsigned int total,
504 struct GNUNET_FS_TestDaemon **daemons)
505{
506 unsigned int i;
507 struct GNUNET_TESTING_PeerGroup *pg;
508 struct GNUNET_CONFIGURATION_Handle *gcfg;
509 struct GNUNET_FS_TestDaemon *daemon;
510
511 GNUNET_assert (total > 0);
512 GNUNET_assert (daemons[0] != NULL);
513 pg = daemons[0]->group;
514 gcfg = daemons[0]->gcfg;
515 for (i = 0; i < total; i++)
516 {
517 daemon = daemons[i];
518 if (daemon->download_timeout_task != GNUNET_SCHEDULER_NO_TASK)
519 {
520 GNUNET_SCHEDULER_cancel (daemon->download_timeout_task);
521 daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
522 }
523 if (daemon->publish_timeout_task != GNUNET_SCHEDULER_NO_TASK)
524 {
525 GNUNET_SCHEDULER_cancel (daemon->publish_timeout_task);
526 daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
527 }
528 if (NULL != daemon->download_context)
529 {
530 GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES);
531 daemon->download_context = NULL;
532 }
533 if (daemon->fs != NULL)
534 GNUNET_FS_stop (daemon->fs);
535 if (daemon->cfg != NULL)
536 GNUNET_CONFIGURATION_destroy (daemon->cfg);
537 if (NULL != daemon->publish_tmp_file)
538 {
539 GNUNET_break (GNUNET_OK ==
540 GNUNET_DISK_directory_remove (daemon->publish_tmp_file));
541 GNUNET_free (daemon->publish_tmp_file);
542 daemon->publish_tmp_file = NULL;
543 }
544 GNUNET_free (daemon);
545 daemons[i] = NULL;
546 }
547 GNUNET_TESTING_daemons_stop (pg,
548 GNUNET_TIME_relative_multiply
549 (GNUNET_TIME_UNIT_SECONDS, 30),
550 &shutdown_callback, gcfg);
551}
552
553
554static void 503static void
555publish_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 504report_success (void *cls,
505 const struct GNUNET_SCHEDULER_TaskContext *tc)
556{ 506{
557 struct GNUNET_FS_TestDaemon *daemon = cls; 507 struct TestDownloadOperation *dop = cls;
558 GNUNET_FS_TEST_UriContinuation cont;
559 508
560 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 509 GNUNET_FS_download_stop (dop->download_context, GNUNET_YES);
561 "Timeout while trying to publish data\n"); 510 GNUNET_SCHEDULER_add_continuation (dop->download_cont,
562 cont = daemon->publish_cont; 511 dop->download_cont_cls,
563 daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK; 512 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
564 daemon->publish_cont = NULL; 513 GNUNET_TESTBED_operation_done (dop->fs_op);
565 GNUNET_FS_publish_stop (daemon->publish_context); 514 GNUNET_FS_uri_destroy (dop->uri);
566 daemon->publish_context = NULL; 515 GNUNET_free (dop);
567 cont (daemon->publish_cont_cls, NULL);
568} 516}
569 517
570 518
571static size_t 519/**
572file_generator (void *cls, uint64_t offset, size_t max, void *buf, char **emsg) 520 * Progress callback for file-sharing events while downloading.
521 *
522 * @param cls the download operation context
523 * @param info information about the event
524 */
525static void *
526download_progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
573{ 527{
574 struct GNUNET_FS_TestDaemon *daemon = cls; 528 struct TestDownloadOperation *dop = cls;
575 uint64_t pos;
576 uint8_t *cbuf = buf;
577 int mod;
578 529
579 if (emsg != NULL) 530 switch (info->status)
580 *emsg = NULL;
581 if (buf == NULL)
582 return 0;
583 for (pos = 0; pos < 8; pos++)
584 cbuf[pos] = (uint8_t) (offset >> pos * 8);
585 for (pos = 8; pos < max; pos++)
586 { 531 {
587 mod = (255 - (offset / 1024 / 32)); 532 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
588 if (mod == 0) 533 if (dop->verbose)
589 mod = 1; 534 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Download at %llu/%llu bytes\n",
590 cbuf[pos] = (uint8_t) ((offset * daemon->publish_seed) % mod); 535 (unsigned long long) info->value.download.completed,
536 (unsigned long long) info->value.download.size);
537 break;
538 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
539 GNUNET_SCHEDULER_cancel (dop->download_timeout_task);
540 dop->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
541 GNUNET_SCHEDULER_add_continuation (&report_success, dop,
542 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
543 break;
544 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
545 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
546 break;
547 /* FIXME: monitor data correctness during download progress */
548 /* FIXME: do performance reports given sufficient verbosity */
549 /* FIXME: advance timeout task to "immediate" on error */
550 default:
551 break;
591 } 552 }
592 return max; 553 return NULL;
593} 554}
594 555
595 556
596
597/** 557/**
598 * Publish a file at the given daemon. 558 * Connect adapter for download operation.
599 * 559 *
600 * @param daemon where to publish 560 * @param cls the 'struct TestDownloadOperation'
601 * @param timeout if this operation cannot be completed within the 561 * @param cfg configuration of the peer to connect to; will be available until
602 * given period, call the continuation with an error code 562 * GNUNET_TESTBED_operation_done() is called on the operation returned
603 * @param anonymity option for publication 563 * from GNUNET_TESTBED_service_connect()
604 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion, 564 * @return service handle to return in 'op_result', NULL on error
605 * GNUNET_SYSERR for simulation
606 * @param size size of the file to publish
607 * @param seed seed to use for file generation
608 * @param verbose how verbose to be in reporting
609 * @param cont function to call when done
610 * @param cont_cls closure for cont
611 */ 565 */
612void 566static void *
613GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon, 567download_connect_adapter (void *cls,
614 struct GNUNET_TIME_Relative timeout, uint32_t anonymity, 568 const struct GNUNET_CONFIGURATION_Handle *cfg)
615 int do_index, uint64_t size, uint32_t seed,
616 unsigned int verbose,
617 GNUNET_FS_TEST_UriContinuation cont, void *cont_cls)
618{ 569{
619 struct GNUNET_FS_FileInformation *fi; 570 struct TestPublishOperation *po = cls;
620 struct GNUNET_DISK_FileHandle *fh; 571
621 char *emsg; 572 return GNUNET_FS_start (cfg,
622 uint64_t off; 573 "fs-test-download",
623 char buf[DBLOCK_SIZE]; 574 &download_progress_cb, po,
624 size_t bsize; 575 GNUNET_FS_OPTIONS_END);
625 struct GNUNET_FS_BlockOptions bo;
626
627 GNUNET_assert (daemon->publish_cont == NULL);
628 daemon->publish_cont = cont;
629 daemon->publish_cont_cls = cont_cls;
630 daemon->publish_seed = seed;
631 daemon->verbose = verbose;
632 bo.expiration_time = GNUNET_TIME_relative_to_absolute (CONTENT_LIFETIME);
633 bo.anonymity_level = anonymity;
634 bo.content_priority = 42;
635 bo.replication_level = 1;
636 if (GNUNET_YES == do_index)
637 {
638 GNUNET_assert (daemon->publish_tmp_file == NULL);
639 daemon->publish_tmp_file = GNUNET_DISK_mktemp ("fs-test-publish-index");
640 GNUNET_assert (daemon->publish_tmp_file != NULL);
641 fh = GNUNET_DISK_file_open (daemon->publish_tmp_file,
642 GNUNET_DISK_OPEN_WRITE |
643 GNUNET_DISK_OPEN_CREATE,
644 GNUNET_DISK_PERM_USER_READ |
645 GNUNET_DISK_PERM_USER_WRITE);
646 GNUNET_assert (NULL != fh);
647 off = 0;
648 while (off < size)
649 {
650 bsize = GNUNET_MIN (sizeof (buf), size - off);
651 emsg = NULL;
652 GNUNET_assert (bsize == file_generator (daemon, off, bsize, buf, &emsg));
653 GNUNET_assert (emsg == NULL);
654 GNUNET_assert (bsize == GNUNET_DISK_file_write (fh, buf, bsize));
655 off += bsize;
656 }
657 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
658 fi = GNUNET_FS_file_information_create_from_file (daemon->fs, daemon,
659 daemon->publish_tmp_file,
660 NULL, NULL, do_index,
661 &bo);
662 }
663 else
664 {
665 fi = GNUNET_FS_file_information_create_from_reader (daemon->fs, daemon,
666 size, &file_generator,
667 daemon, NULL, NULL,
668 do_index, &bo);
669 }
670 daemon->publish_context =
671 GNUNET_FS_publish_start (daemon->fs, fi, NULL, NULL, NULL,
672 GNUNET_FS_PUBLISH_OPTION_NONE);
673 daemon->publish_timeout_task =
674 GNUNET_SCHEDULER_add_delayed (timeout, &publish_timeout, daemon);
675} 576}
676 577
677 578
579/**
580 * Callback to be called when testbed has connected to the fs service
581 *
582 * @param cls the 'struct TestPublishOperation'
583 * @param op the operation that has been finished
584 * @param ca_result the 'struct GNUNET_FS_Handle ' (NULL on error)
585 * @param emsg error message in case the operation has failed; will be NULL if
586 * operation has executed successfully.
587 */
678static void 588static void
679download_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 589download_fs_connect_complete_cb (void *cls,
590 struct GNUNET_TESTBED_Operation *op,
591 void *ca_result,
592 const char *emsg)
680{ 593{
681 struct GNUNET_FS_TestDaemon *daemon = cls; 594 struct TestDownloadOperation *dop = cls;
682 595
683 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 596 dop->download_context =
684 "Timeout while trying to download file\n"); 597 GNUNET_FS_download_start (dop->fs, dop->uri, NULL, NULL, NULL, 0, dop->size,
685 daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK; 598 dop->anonymity, GNUNET_FS_DOWNLOAD_OPTION_NONE,
686 GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES); 599 NULL, NULL);
687 daemon->download_context = NULL;
688 GNUNET_SCHEDULER_add_continuation (daemon->download_cont,
689 daemon->download_cont_cls,
690 GNUNET_SCHEDULER_REASON_TIMEOUT);
691 daemon->download_cont = NULL;
692} 600}
693 601
694 602
695/** 603/**
696 * Perform test download. 604 * Perform test download.
697 * 605 *
698 * @param daemon which peer to download from 606 * @param peer which peer to download from
699 * @param timeout if this operation cannot be completed within the 607 * @param timeout if this operation cannot be completed within the
700 * given period, call the continuation with an error code 608 * given period, call the continuation with an error code
701 * @param anonymity option for download 609 * @param anonymity option for download
@@ -706,26 +614,34 @@ download_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
706 * @param cont_cls closure for cont 614 * @param cont_cls closure for cont
707 */ 615 */
708void 616void
709GNUNET_FS_TEST_download (struct GNUNET_FS_TestDaemon *daemon, 617GNUNET_FS_TEST_download (struct GNUNET_TESTBED_Peer *peer,
710 struct GNUNET_TIME_Relative timeout, 618 struct GNUNET_TIME_Relative timeout,
711 uint32_t anonymity, uint32_t seed, 619 uint32_t anonymity, uint32_t seed,
712 const struct GNUNET_FS_Uri *uri, unsigned int verbose, 620 const struct GNUNET_FS_Uri *uri, unsigned int verbose,
713 GNUNET_SCHEDULER_Task cont, void *cont_cls) 621 GNUNET_SCHEDULER_Task cont, void *cont_cls)
714{ 622{
715 uint64_t size; 623 struct TestDownloadOperation *dop;
716 624
717 GNUNET_assert (daemon->download_cont == NULL); 625 dop = GNUNET_malloc (sizeof (struct TestDownloadOperation));
718 size = GNUNET_FS_uri_chk_get_file_size (uri); 626 dop->uri = GNUNET_FS_uri_dup (uri);
719 daemon->verbose = verbose; 627 dop->size = GNUNET_FS_uri_chk_get_file_size (uri);
720 daemon->download_cont = cont; 628 dop->verbose = verbose;
721 daemon->download_cont_cls = cont_cls; 629 dop->anonymity = anonymity;
722 daemon->download_seed = seed; 630 dop->download_cont = cont;
723 daemon->download_context = 631 dop->download_cont_cls = cont_cls;
724 GNUNET_FS_download_start (daemon->fs, uri, NULL, NULL, NULL, 0, size, 632 dop->download_seed = seed;
725 anonymity, GNUNET_FS_DOWNLOAD_OPTION_NONE, NULL, 633
726 NULL); 634 dop->fs_op = GNUNET_TESTBED_service_connect (dop,
727 daemon->download_timeout_task = 635 peer,
728 GNUNET_SCHEDULER_add_delayed (timeout, &download_timeout, daemon); 636 "fs",
637 &download_fs_connect_complete_cb,
638 dop,
639 &download_connect_adapter,
640 &fs_disconnect_adapter,
641 dop);
642 dop->download_timeout_task =
643 GNUNET_SCHEDULER_add_delayed (timeout, &download_timeout, dop);
729} 644}
730 645
731/* end of test_fs_lib.c */ 646
647/* end of fs_test_lib.c */
diff --git a/src/fs/fs_test_lib.h b/src/fs/fs_test_lib.h
index 81125cafc..d00c21b1e 100644
--- a/src/fs/fs_test_lib.h
+++ b/src/fs/fs_test_lib.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff (and other contributing authors) 3 (C) 2010, 2012 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -20,8 +20,8 @@
20 20
21/** 21/**
22 * @file fs/fs_test_lib.h 22 * @file fs/fs_test_lib.h
23 * @brief library routines for testing FS publishing and downloading 23 * @brief library routines for testing FS publishing and downloading;
24 * with multiple peers; this code is limited to flat files 24 * this code is limited to flat files
25 * and no keywords (those functions can be tested with 25 * and no keywords (those functions can be tested with
26 * single-peer setups; this is for testing routing). 26 * single-peer setups; this is for testing routing).
27 * @author Christian Grothoff 27 * @author Christian Grothoff
@@ -31,97 +31,7 @@
31 31
32#include "gnunet_util_lib.h" 32#include "gnunet_util_lib.h"
33#include "gnunet_fs_service.h" 33#include "gnunet_fs_service.h"
34 34#include "gnunet_testbed_service.h"
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 template_cfg_file configuration template 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; note that if 'cont'
51 * is called with reason "TIMEOUT", then starting the
52 * daemons has failed and the client MUST NOT call
53 * 'GNUNET_FS_TEST_daemons_stop'!
54 * @param cont_cls closure for cont
55 */
56void
57GNUNET_FS_TEST_daemons_start (const char *template_cfg_file,
58 struct GNUNET_TIME_Relative timeout,
59 unsigned int total,
60 struct GNUNET_FS_TestDaemon **daemons,
61 GNUNET_SCHEDULER_Task cont, void *cont_cls);
62
63
64struct GNUNET_FS_TEST_ConnectContext;
65
66
67/**
68 * Connect two daemons for testing.
69 *
70 * @param daemon1 first daemon to connect
71 * @param daemon2 second first daemon to connect
72 * @param timeout if this operation cannot be completed within the
73 * given period, call the continuation with an error code
74 * @param cont function to call when done
75 * @param cont_cls closure for cont
76 */
77struct GNUNET_FS_TEST_ConnectContext *
78GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1,
79 struct GNUNET_FS_TestDaemon *daemon2,
80 struct GNUNET_TIME_Relative timeout,
81 GNUNET_SCHEDULER_Task cont, void *cont_cls);
82
83
84/**
85 * Cancel connect operation.
86 *
87 * @param cc operation to cancel
88 */
89void
90GNUNET_FS_TEST_daemons_connect_cancel (struct GNUNET_FS_TEST_ConnectContext
91 *cc);
92
93
94/**
95 * Obtain peer group used for testing.
96 *
97 * @param daemons array with the daemons (must contain at least one)
98 * @return peer group
99 */
100struct GNUNET_TESTING_PeerGroup *
101GNUNET_FS_TEST_get_group (struct GNUNET_FS_TestDaemon **daemons);
102
103
104
105/**
106 * Obtain peer configuration used for testing.
107 *
108 * @param daemons array with the daemons
109 * @param off which configuration to get
110 * @return peer configuration
111 */
112const struct GNUNET_CONFIGURATION_Handle *
113GNUNET_FS_TEST_get_configuration (struct GNUNET_FS_TestDaemon **daemons,
114 unsigned int off);
115
116/**
117 * Stop daemons used for testing.
118 *
119 * @param total number of daemons to stop
120 * @param daemons array with the daemons (values will be clobbered)
121 */
122void
123GNUNET_FS_TEST_daemons_stop (unsigned int total,
124 struct GNUNET_FS_TestDaemon **daemons);
125 35
126 36
127/** 37/**
@@ -138,7 +48,7 @@ typedef void (*GNUNET_FS_TEST_UriContinuation) (void *cls,
138/** 48/**
139 * Publish a file at the given daemon. 49 * Publish a file at the given daemon.
140 * 50 *
141 * @param daemon where to publish 51 * @param peer where to publish
142 * @param timeout if this operation cannot be completed within the 52 * @param timeout if this operation cannot be completed within the
143 * given period, call the continuation with an error code 53 * given period, call the continuation with an error code
144 * @param anonymity option for publication 54 * @param anonymity option for publication
@@ -151,7 +61,7 @@ typedef void (*GNUNET_FS_TEST_UriContinuation) (void *cls,
151 * @param cont_cls closure for cont 61 * @param cont_cls closure for cont
152 */ 62 */
153void 63void
154GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon, 64GNUNET_FS_TEST_publish (struct GNUNET_TESTBED_Peer *peer,
155 struct GNUNET_TIME_Relative timeout, uint32_t anonymity, 65 struct GNUNET_TIME_Relative timeout, uint32_t anonymity,
156 int do_index, uint64_t size, uint32_t seed, 66 int do_index, uint64_t size, uint32_t seed,
157 unsigned int verbose, 67 unsigned int verbose,
@@ -161,7 +71,7 @@ GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon,
161/** 71/**
162 * Perform test download. 72 * Perform test download.
163 * 73 *
164 * @param daemon which peer to download from 74 * @param peer which peer to download from
165 * @param timeout if this operation cannot be completed within the 75 * @param timeout if this operation cannot be completed within the
166 * given period, call the continuation with an error code 76 * given period, call the continuation with an error code
167 * @param anonymity option for download 77 * @param anonymity option for download
@@ -172,7 +82,7 @@ GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon,
172 * @param cont_cls closure for cont 82 * @param cont_cls closure for cont
173 */ 83 */
174void 84void
175GNUNET_FS_TEST_download (struct GNUNET_FS_TestDaemon *daemon, 85GNUNET_FS_TEST_download (struct GNUNET_TESTBED_Peer *peer,
176 struct GNUNET_TIME_Relative timeout, 86 struct GNUNET_TIME_Relative timeout,
177 uint32_t anonymity, uint32_t seed, 87 uint32_t anonymity, uint32_t seed,
178 const struct GNUNET_FS_Uri *uri, unsigned int verbose, 88 const struct GNUNET_FS_Uri *uri, unsigned int verbose,
diff --git a/src/fs/perf_gnunet_service_fs_p2p.c b/src/fs/perf_gnunet_service_fs_p2p.c
index 22068732d..a7eb5ad16 100644
--- a/src/fs/perf_gnunet_service_fs_p2p.c
+++ b/src/fs/perf_gnunet_service_fs_p2p.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff (and other contributing authors) 3 (C) 2010, 2012 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -25,7 +25,7 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "fs_test_lib.h" 27#include "fs_test_lib.h"
28#include "gnunet_testing_lib.h" 28#include "gnunet_testbed_service.h"
29 29
30#define VERBOSE GNUNET_NO 30#define VERBOSE GNUNET_NO
31 31
@@ -43,7 +43,7 @@
43 43
44#define SEED 42 44#define SEED 42
45 45
46static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS]; 46static struct GNUNET_TESTBED_Peer *daemons[NUM_DAEMONS];
47 47
48static int ok; 48static int ok;
49 49
@@ -51,12 +51,6 @@ static struct GNUNET_TIME_Absolute start_time;
51 51
52static const char *progname; 52static const char *progname;
53 53
54static void
55do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
56{
57 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
58}
59
60 54
61/** 55/**
62 * Master context for 'stat_run'. 56 * Master context for 'stat_run'.
@@ -64,6 +58,7 @@ do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
64struct StatMaster 58struct StatMaster
65{ 59{
66 struct GNUNET_STATISTICS_Handle *stat; 60 struct GNUNET_STATISTICS_Handle *stat;
61 struct GNUNET_TESTBED_Operation *op;
67 unsigned int daemon; 62 unsigned int daemon;
68 unsigned int value; 63 unsigned int value;
69}; 64};
@@ -130,7 +125,10 @@ print_stat (void *cls, const char *subsystem, const char *name, uint64_t value,
130 * Function that gathers stats from all daemons. 125 * Function that gathers stats from all daemons.
131 */ 126 */
132static void 127static void
133stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 128stat_run (void *cls,
129 struct GNUNET_TESTBED_Operation *op,
130 void *ca_result,
131 const char *emsg);
134 132
135 133
136/** 134/**
@@ -143,7 +141,41 @@ get_done (void *cls, int success)
143 141
144 GNUNET_break (GNUNET_OK == success); 142 GNUNET_break (GNUNET_OK == success);
145 sm->value++; 143 sm->value++;
146 GNUNET_SCHEDULER_add_now (&stat_run, sm); 144 stat_run (sm, sm->op, sm->stat, NULL);
145}
146
147
148/**
149 * Adapter function called to establish a connection to
150 * statistics service.
151 *
152 * @param cls closure
153 * @param cfg configuration of the peer to connect to; will be available until
154 * GNUNET_TESTBED_operation_done() is called on the operation returned
155 * from GNUNET_TESTBED_service_connect()
156 * @return service handle to return in 'op_result', NULL on error
157 */
158static void *
159statistics_connect_adapter (void *cls,
160 const struct GNUNET_CONFIGURATION_Handle *cfg)
161{
162 return GNUNET_STATISTICS_create ("<driver>",
163 cfg);
164}
165
166
167/**
168 * Adapter function called to destroy a connection to
169 * statistics service.
170 *
171 * @param cls closure
172 * @param op_result service handle returned from the connect adapter
173 */
174static void
175statistics_disconnect_adapter (void *cls,
176 void *op_result)
177{
178 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
147} 179}
148 180
149 181
@@ -151,10 +183,23 @@ get_done (void *cls, int success)
151 * Function that gathers stats from all daemons. 183 * Function that gathers stats from all daemons.
152 */ 184 */
153static void 185static void
154stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 186stat_run (void *cls,
187 struct GNUNET_TESTBED_Operation *op,
188 void *ca_result,
189 const char *emsg)
155{ 190{
156 struct StatMaster *sm = cls; 191 struct StatMaster *sm = cls;
157 192
193 if (NULL != emsg)
194 {
195 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
196 "Failed to statistics service: %s\n",
197 emsg);
198 GNUNET_SCHEDULER_shutdown ();
199 return;
200 }
201 sm->stat = ca_result;
202
158 if (stats[sm->value].name != NULL) 203 if (stats[sm->value].name != NULL)
159 { 204 {
160 GNUNET_STATISTICS_get (sm->stat, 205 GNUNET_STATISTICS_get (sm->stat,
@@ -167,20 +212,23 @@ stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
167 sm); 212 sm);
168 return; 213 return;
169 } 214 }
170 GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO); 215 GNUNET_TESTBED_operation_done (sm->op);
171 sm->value = 0; 216 sm->value = 0;
172 sm->daemon++; 217 sm->daemon++;
173 if (sm->daemon == NUM_DAEMONS) 218 if (NUM_DAEMONS == sm->daemon)
174 { 219 {
175 GNUNET_free (sm); 220 GNUNET_free (sm);
176 GNUNET_SCHEDULER_add_now (&do_stop, NULL); 221 GNUNET_SCHEDULER_shutdown ();
177 return; 222 return;
178 } 223 }
179 sm->stat = 224 sm->op =
180 GNUNET_STATISTICS_create ("<driver>", 225 GNUNET_TESTBED_service_connect (NULL,
181 GNUNET_FS_TEST_get_configuration (daemons, 226 daemons[sm->daemon],
182 sm->daemon)); 227 "statistics",
183 GNUNET_SCHEDULER_add_now (&stat_run, sm); 228 &stat_run, sm,
229 &statistics_connect_adapter,
230 &statistics_disconnect_adapter,
231 NULL);
184} 232}
185 233
186 234
@@ -191,32 +239,33 @@ do_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
191 char *fancy; 239 char *fancy;
192 struct StatMaster *sm; 240 struct StatMaster *sm;
193 241
194 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) 242 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
195 {
196 del = GNUNET_TIME_absolute_get_duration (start_time);
197 if (del.rel_value == 0)
198 del.rel_value = 1;
199 fancy =
200 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
201 1000LL / del.rel_value);
202 FPRINTF (stdout, "Download speed was %s/s\n", fancy);
203 GNUNET_free (fancy);
204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished download, shutting down\n",
205 (unsigned long long) FILESIZE);
206 sm = GNUNET_malloc (sizeof (struct StatMaster));
207 sm->stat =
208 GNUNET_STATISTICS_create ("<driver>",
209 GNUNET_FS_TEST_get_configuration (daemons,
210 sm->daemon));
211 GNUNET_SCHEDULER_add_now (&stat_run, sm);
212 }
213 else
214 { 243 {
215 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 244 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
216 "Timeout during download, shutting down with error\n"); 245 "Timeout during download, shutting down with error\n");
217 ok = 1; 246 ok = 1;
218 GNUNET_SCHEDULER_add_now (&do_stop, NULL); 247 GNUNET_SCHEDULER_shutdown ();
248 return;
219 } 249 }
250 del = GNUNET_TIME_absolute_get_duration (start_time);
251 if (del.rel_value == 0)
252 del.rel_value = 1;
253 fancy =
254 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
255 1000LL / del.rel_value);
256 FPRINTF (stdout, "Download speed was %s/s\n", fancy);
257 GNUNET_free (fancy);
258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished download, shutting down\n",
259 (unsigned long long) FILESIZE);
260 sm = GNUNET_malloc (sizeof (struct StatMaster));
261 sm->op =
262 GNUNET_TESTBED_service_connect (NULL,
263 daemons[sm->daemon],
264 "statistics",
265 &stat_run, sm,
266 &statistics_connect_adapter,
267 &statistics_disconnect_adapter,
268 NULL);
220} 269}
221 270
222 271
@@ -226,8 +275,8 @@ do_download (void *cls, const struct GNUNET_FS_Uri *uri)
226 int anonymity; 275 int anonymity;
227 276
228 if (NULL == uri) 277 if (NULL == uri)
229 { 278 {
230 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons); 279 GNUNET_SCHEDULER_shutdown ();
231 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 280 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
232 "Timeout during upload attempt, shutting down with error\n"); 281 "Timeout during upload attempt, shutting down with error\n");
233 ok = 1; 282 ok = 1;
@@ -246,14 +295,16 @@ do_download (void *cls, const struct GNUNET_FS_Uri *uri)
246 295
247 296
248static void 297static void
249do_publish (void *cls, const char *emsg) 298do_publish (void *cls,
299 struct GNUNET_TESTBED_Operation *op,
300 const char *emsg)
250{ 301{
251 int do_index; 302 int do_index;
252 int anonymity; 303 int anonymity;
253 304
254 if (NULL != emsg) 305 if (NULL != emsg)
255 { 306 {
256 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons); 307 GNUNET_SCHEDULER_shutdown ();
257 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg); 308 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg);
258 ok = 1; 309 ok = 1;
259 return; 310 return;
@@ -276,53 +327,32 @@ do_publish (void *cls, const char *emsg)
276 327
277 328
278static void 329static void
279do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 330do_connect (void *cls,
331 unsigned int num_peers,
332 struct GNUNET_TESTBED_Peer **peers)
280{ 333{
281 struct GNUNET_TESTING_PeerGroup *pg; 334 unsigned int i;
282 335
283 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)); 336 GNUNET_assert (NUM_DAEMONS == num_peers);
284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 337 for (i=0;i<num_peers;i++)
285 "Daemons started, will now try to connect them\n"); 338 daemons[i] = peers[i];
286 pg = GNUNET_FS_TEST_get_group (daemons); 339 GNUNET_TESTBED_overlay_connect (NULL,
287 GNUNET_break ((NUM_DAEMONS - 1) * 2 == 340 &do_publish,
288 (GNUNET_TESTING_create_topology 341 NULL,
289 (pg, GNUNET_TESTING_TOPOLOGY_LINE, 342 peers[0],
290 GNUNET_TESTING_TOPOLOGY_NONE, NULL))); 343 peers[1]);
291 GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_LINE, 344 // FIXME: was supposed to connect in line...
292 GNUNET_TESTING_TOPOLOGY_OPTION_NONE, 0.0,
293 TIMEOUT, NUM_DAEMONS, &do_publish, NULL);
294}
295
296
297static void
298run (void *cls, char *const *args, const char *cfgfile,
299 const struct GNUNET_CONFIGURATION_Handle *cfg)
300{
301 GNUNET_FS_TEST_daemons_start ("perf_gnunet_service_fs_p2p.conf", TIMEOUT, NUM_DAEMONS,
302 daemons, &do_connect, NULL);
303} 345}
304 346
305 347
306int 348int
307main (int argc, char *argv[]) 349main (int argc, char *argv[])
308{ 350{
309 char *const argvx[] = { 351 GNUNET_TESTBED_test_run ("perf-gnunet-service-fs-p2p",
310 "perf-gnunet-service-fs-p2p", 352 "perf_gnunet_service_fs_p2p.conf",
311 "-c", 353 NUM_DAEMONS,
312 "perf_gnunet_service_fs_p2p.conf", 354 0, NULL, NULL,
313 NULL 355 &do_connect, NULL);
314 };
315 struct GNUNET_GETOPT_CommandLineOption options[] = {
316 GNUNET_GETOPT_OPTION_END
317 };
318 progname = argv[0];
319 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
320 GNUNET_log_setup ("perf_gnunet_service_fs_p2p_index",
321 "WARNING",
322 NULL);
323 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
324 "perf-gnunet-service-fs-p2p-index", "nohelp", options,
325 &run, NULL);
326 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 356 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
327 return ok; 357 return ok;
328} 358}
diff --git a/src/fs/perf_gnunet_service_fs_p2p_respect.c b/src/fs/perf_gnunet_service_fs_p2p_respect.c
index 58fe34eef..3030749e2 100644
--- a/src/fs/perf_gnunet_service_fs_p2p_respect.c
+++ b/src/fs/perf_gnunet_service_fs_p2p_respect.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2010, 2011 Christian Grothoff (and other contributing authors) 3 (C) 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -45,7 +45,7 @@
45 */ 45 */
46#include "platform.h" 46#include "platform.h"
47#include "fs_test_lib.h" 47#include "fs_test_lib.h"
48#include "gnunet_testing_lib.h" 48#include "gnunet_testbed_service.h"
49 49
50#define VERBOSE GNUNET_NO 50#define VERBOSE GNUNET_NO
51 51
@@ -74,7 +74,7 @@
74 */ 74 */
75#define SEED2 43 75#define SEED2 43
76 76
77static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS]; 77static struct GNUNET_TESTBED_Peer *daemons[NUM_DAEMONS];
78 78
79static int ok; 79static int ok;
80 80
@@ -86,12 +86,6 @@ static struct GNUNET_FS_Uri *uri1;
86 86
87static struct GNUNET_FS_Uri *uri2; 87static struct GNUNET_FS_Uri *uri2;
88 88
89static void
90do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
91{
92 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
93}
94
95 89
96/** 90/**
97 * Master context for 'stat_run'. 91 * Master context for 'stat_run'.
@@ -99,6 +93,7 @@ do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
99struct StatMaster 93struct StatMaster
100{ 94{
101 struct GNUNET_STATISTICS_Handle *stat; 95 struct GNUNET_STATISTICS_Handle *stat;
96 struct GNUNET_TESTBED_Operation *op;
102 unsigned int daemon; 97 unsigned int daemon;
103 unsigned int value; 98 unsigned int value;
104}; 99};
@@ -163,7 +158,10 @@ print_stat (void *cls, const char *subsystem, const char *name, uint64_t value,
163 * Function that gathers stats from all daemons. 158 * Function that gathers stats from all daemons.
164 */ 159 */
165static void 160static void
166stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 161stat_run (void *cls,
162 struct GNUNET_TESTBED_Operation *op,
163 void *ca_result,
164 const char *emsg);
167 165
168 166
169/** 167/**
@@ -176,7 +174,42 @@ get_done (void *cls, int success)
176 174
177 GNUNET_break (GNUNET_OK == success); 175 GNUNET_break (GNUNET_OK == success);
178 sm->value++; 176 sm->value++;
179 GNUNET_SCHEDULER_add_now (&stat_run, sm); 177 stat_run (sm, sm->op, sm->stat, NULL);
178}
179
180
181
182/**
183 * Adapter function called to establish a connection to
184 * statistics service.
185 *
186 * @param cls closure
187 * @param cfg configuration of the peer to connect to; will be available until
188 * GNUNET_TESTBED_operation_done() is called on the operation returned
189 * from GNUNET_TESTBED_service_connect()
190 * @return service handle to return in 'op_result', NULL on error
191 */
192static void *
193statistics_connect_adapter (void *cls,
194 const struct GNUNET_CONFIGURATION_Handle *cfg)
195{
196 return GNUNET_STATISTICS_create ("<driver>",
197 cfg);
198}
199
200
201/**
202 * Adapter function called to destroy a connection to
203 * statistics service.
204 *
205 * @param cls closure
206 * @param op_result service handle returned from the connect adapter
207 */
208static void
209statistics_disconnect_adapter (void *cls,
210 void *op_result)
211{
212 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
180} 213}
181 214
182 215
@@ -184,7 +217,10 @@ get_done (void *cls, int success)
184 * Function that gathers stats from all daemons. 217 * Function that gathers stats from all daemons.
185 */ 218 */
186static void 219static void
187stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 220stat_run (void *cls,
221 struct GNUNET_TESTBED_Operation *op,
222 void *ca_result,
223 const char *emsg)
188{ 224{
189 struct StatMaster *sm = cls; 225 struct StatMaster *sm = cls;
190 226
@@ -200,20 +236,23 @@ stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
200 sm); 236 sm);
201 return; 237 return;
202 } 238 }
203 GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO); 239 GNUNET_TESTBED_operation_done (sm->op);
204 sm->value = 0; 240 sm->value = 0;
205 sm->daemon++; 241 sm->daemon++;
206 if (sm->daemon == NUM_DAEMONS) 242 if (NUM_DAEMONS == sm->daemon)
207 { 243 {
208 GNUNET_free (sm); 244 GNUNET_free (sm);
209 GNUNET_SCHEDULER_add_now (&do_stop, NULL); 245 GNUNET_SCHEDULER_shutdown ();
210 return; 246 return;
211 } 247 }
212 sm->stat = 248 sm->op =
213 GNUNET_STATISTICS_create ("<driver>", 249 GNUNET_TESTBED_service_connect (NULL,
214 GNUNET_FS_TEST_get_configuration (daemons, 250 daemons[sm->daemon],
215 sm->daemon)); 251 "statistics",
216 GNUNET_SCHEDULER_add_now (&stat_run, sm); 252 &stat_run, sm,
253 &statistics_connect_adapter,
254 &statistics_disconnect_adapter,
255 NULL);
217} 256}
218 257
219 258
@@ -226,36 +265,37 @@ do_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
226 char *fancy; 265 char *fancy;
227 struct StatMaster *sm; 266 struct StatMaster *sm;
228 267
229 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 268 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
230 {
231 del = GNUNET_TIME_absolute_get_duration (start_time);
232 if (del.rel_value == 0)
233 del.rel_value = 1;
234 fancy =
235 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
236 1000LL / del.rel_value);
237 FPRINTF (stderr, "Download speed of type `%s' was %s/s\n", type, fancy);
238 GNUNET_free (fancy);
239 if (NUM_DAEMONS != ++download_counter)
240 return; /* more downloads to come */
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
242 "Finished all downloads, shutting down\n",
243 (unsigned long long) FILESIZE);
244 sm = GNUNET_malloc (sizeof (struct StatMaster));
245 sm->stat =
246 GNUNET_STATISTICS_create ("<driver>",
247 GNUNET_FS_TEST_get_configuration (daemons,
248 sm->daemon));
249 GNUNET_SCHEDULER_add_now (&stat_run, sm);
250 }
251 else
252 { 269 {
253 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 270 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
254 "Timeout during download for type `%s', shutting down with error\n", 271 "Timeout during download for type `%s', shutting down with error\n",
255 type); 272 type);
256 ok = 1; 273 ok = 1;
257 GNUNET_SCHEDULER_add_now (&do_stop, NULL); 274 GNUNET_SCHEDULER_shutdown ();
275 return;
258 } 276 }
277 del = GNUNET_TIME_absolute_get_duration (start_time);
278 if (del.rel_value == 0)
279 del.rel_value = 1;
280 fancy =
281 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
282 1000LL / del.rel_value);
283 FPRINTF (stderr, "Download speed of type `%s' was %s/s\n", type, fancy);
284 GNUNET_free (fancy);
285 if (NUM_DAEMONS != ++download_counter)
286 return; /* more downloads to come */
287 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
288 "Finished all downloads, shutting down\n",
289 (unsigned long long) FILESIZE);
290 sm = GNUNET_malloc (sizeof (struct StatMaster));
291 sm->op =
292 GNUNET_TESTBED_service_connect (NULL,
293 daemons[sm->daemon],
294 "statistics",
295 &stat_run, sm,
296 &statistics_connect_adapter,
297 &statistics_disconnect_adapter,
298 NULL);
259} 299}
260 300
261 301
@@ -267,7 +307,7 @@ do_downloads (void *cls, const struct GNUNET_FS_Uri *u2)
267 307
268 if (NULL == u2) 308 if (NULL == u2)
269 { 309 {
270 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons); 310 GNUNET_SCHEDULER_shutdown ();
271 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 311 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
272 "Timeout during upload attempt, shutting down with error\n"); 312 "Timeout during upload attempt, shutting down with error\n");
273 ok = 1; 313 ok = 1;
@@ -298,14 +338,15 @@ do_downloads (void *cls, const struct GNUNET_FS_Uri *u2)
298 338
299 339
300static void 340static void
301do_publish2 (void *cls, const struct GNUNET_FS_Uri *u1) 341do_publish2 (void *cls,
342 const struct GNUNET_FS_Uri *u1)
302{ 343{
303 int do_index; 344 int do_index;
304 int anonymity; 345 int anonymity;
305 346
306 if (NULL == u1) 347 if (NULL == u1)
307 { 348 {
308 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons); 349 GNUNET_SCHEDULER_shutdown ();
309 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 350 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
310 "Timeout during upload attempt, shutting down with error\n"); 351 "Timeout during upload attempt, shutting down with error\n");
311 ok = 1; 352 ok = 1;
@@ -329,18 +370,23 @@ do_publish2 (void *cls, const struct GNUNET_FS_Uri *u1)
329} 370}
330 371
331static void 372static void
332do_publish1 (void *cls, const char *emsg) 373do_publish1 (void *cls,
374 struct GNUNET_TESTBED_Operation *op,
375 const char *emsg)
333{ 376{
377 unsigned int *coco = cls;
334 int do_index; 378 int do_index;
335 int anonymity; 379 int anonymity;
336 380
337 if (NULL != emsg) 381 if (NULL != emsg)
338 { 382 {
339 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons); 383 GNUNET_SCHEDULER_shutdown ();
340 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg); 384 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg);
341 ok = 1; 385 ok = 1;
342 return; 386 return;
343 } 387 }
388 if (0 != (--(*coco)))
389 return; /* more connections to be created */
344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", 390 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
345 (unsigned long long) FILESIZE); 391 (unsigned long long) FILESIZE);
346 if (NULL != strstr (progname, "index")) 392 if (NULL != strstr (progname, "index"))
@@ -351,7 +397,6 @@ do_publish1 (void *cls, const char *emsg)
351 anonymity = 0; 397 anonymity = 0;
352 else 398 else
353 anonymity = 1; 399 anonymity = 1;
354
355 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, 400 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity,
356 do_index, FILESIZE, SEED1, VERBOSE, &do_publish2, 401 do_index, FILESIZE, SEED1, VERBOSE, &do_publish2,
357 NULL); 402 NULL);
@@ -359,51 +404,38 @@ do_publish1 (void *cls, const char *emsg)
359 404
360 405
361static void 406static void
362do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 407do_connect (void *cls,
408 unsigned int num_peers,
409 struct GNUNET_TESTBED_Peer **peers)
363{ 410{
364 struct GNUNET_TESTING_PeerGroup *pg; 411 static unsigned int coco;
365 412 unsigned int i;
366 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)); 413 unsigned int j;
367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 414
368 "Daemons started, will now try to connect them\n"); 415 GNUNET_assert (NUM_DAEMONS == num_peers);
369 pg = GNUNET_FS_TEST_get_group (daemons); 416 for (i=0;i<num_peers;i++)
370 GNUNET_TESTING_create_topology (pg, GNUNET_TESTING_TOPOLOGY_CLIQUE, 417 daemons[i] = peers[i];
371 GNUNET_TESTING_TOPOLOGY_NONE, NULL); 418 for (i=0;i<NUM_DAEMONS;i++)
372 GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_CLIQUE, 419 for (j=i+1;j<NUM_DAEMONS;j++)
373 GNUNET_TESTING_TOPOLOGY_OPTION_NONE, 0.0, 420 {
374 TIMEOUT, NUM_DAEMONS, &do_publish1, NULL); 421 coco++;
375} 422 GNUNET_TESTBED_overlay_connect (NULL,
376 423 &do_publish1,
377 424 &coco,
378static void 425 peers[i],
379run (void *cls, char *const *args, const char *cfgfile, 426 peers[j]);
380 const struct GNUNET_CONFIGURATION_Handle *cfg) 427 }
381{
382 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", TIMEOUT, NUM_DAEMONS,
383 daemons, &do_connect, NULL);
384} 428}
385 429
386 430
387int 431int
388main (int argc, char *argv[]) 432main (int argc, char *argv[])
389{ 433{
390 char *const argvx[] = { 434 GNUNET_TESTBED_test_run ("perf-gnunet-service-fs-p2p-respect",
391 "perf-gnunet-service-fs-p2p", 435 "perf_gnunet_service_fs_p2p.conf",
392 "-c", 436 NUM_DAEMONS,
393 "fs_test_lib_data.conf", 437 0, NULL, NULL,
394 NULL 438 &do_connect, NULL);
395 };
396 struct GNUNET_GETOPT_CommandLineOption options[] = {
397 GNUNET_GETOPT_OPTION_END
398 };
399 progname = argv[0];
400 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
401 GNUNET_log_setup ("perf_gnunet_service_fs_p2p_respect",
402 "WARNING",
403 NULL);
404 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
405 "perf-gnunet-service-fs-p2p-respect", "nohelp", options,
406 &run, NULL);
407 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 439 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
408 return ok; 440 return ok;
409} 441}
diff --git a/src/fs/test_fs_test_lib.c b/src/fs/test_fs_test_lib.c
index 29d5fe47f..bee7909a9 100644
--- a/src/fs/test_fs_test_lib.c
+++ b/src/fs/test_fs_test_lib.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff (and other contributing authors) 3 (C) 2010, 2012 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -42,20 +42,14 @@
42 42
43#define SEED 42 43#define SEED 42
44 44
45static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS]; 45static struct GNUNET_TESTBED_Peer *the_peers[NUM_DAEMONS];
46
47static struct GNUNET_FS_TEST_ConnectContext *cc;
48 46
49static int ret; 47static int ret;
50 48
49
51static void 50static void
52do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 51do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
53{ 52{
54 if (NULL != cc)
55 {
56 GNUNET_FS_TEST_daemons_connect_cancel (cc);
57 cc = NULL;
58 }
59 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 53 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
60 { 54 {
61 GNUNET_break (0); 55 GNUNET_break (0);
@@ -66,7 +60,7 @@ do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
66 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished download, shutting down\n", 60 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished download, shutting down\n",
67 (unsigned long long) FILESIZE); 61 (unsigned long long) FILESIZE);
68 } 62 }
69 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons); 63 GNUNET_SCHEDULER_shutdown ();
70} 64}
71 65
72 66
@@ -76,80 +70,80 @@ do_download (void *cls, const struct GNUNET_FS_Uri *uri)
76 if (NULL == uri) 70 if (NULL == uri)
77 { 71 {
78 GNUNET_break (0); 72 GNUNET_break (0);
79 GNUNET_SCHEDULER_add_now (&do_stop, NULL); 73 GNUNET_SCHEDULER_shutdown ();
80 ret = 1; 74 ret = 1;
81 return; 75 return;
82 } 76 }
83 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", 77 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
84 (unsigned long long) FILESIZE); 78 (unsigned long long) FILESIZE);
85 GNUNET_FS_TEST_download (daemons[0], TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop, 79 GNUNET_FS_TEST_download (the_peers[0], TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop,
86 NULL); 80 NULL);
87} 81}
88 82
89 83
90static void 84static void
91do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 85do_publish (void *cls,
86 struct GNUNET_TESTBED_Operation *op,
87 const char *emsg)
92{ 88{
93 cc = NULL; 89 if (NULL != emsg)
94 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
95 { 90 {
91 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to connect peers: %s\n", emsg);
96 GNUNET_break (0); 92 GNUNET_break (0);
97 ret = 1; 93 ret = 1;
98 GNUNET_SCHEDULER_add_now (&do_stop, NULL); 94 GNUNET_SCHEDULER_shutdown ();
99 return; 95 return;
100 } 96 }
97 GNUNET_TESTBED_operation_done (op);
101 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", 98 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
102 (unsigned long long) FILESIZE); 99 (unsigned long long) FILESIZE);
103 GNUNET_FS_TEST_publish (daemons[0], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED, 100 GNUNET_FS_TEST_publish (the_peers[0], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED,
104 VERBOSE, &do_download, NULL); 101 VERBOSE, &do_download, NULL);
105}
106
107 102
108static void
109do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
110{
111 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
112 {
113 GNUNET_break (0);
114 ret = 1;
115 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
116 return;
117 }
118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
119 "Daemons started, will now try to connect them\n");
120 cc = GNUNET_FS_TEST_daemons_connect (daemons[0], daemons[1], TIMEOUT,
121 &do_publish, NULL);
122} 103}
123 104
124 105
106/**
107 * Actual main function for the test.
108 *
109 * @param cls closure
110 * @param num_peers number of peers in 'peers'
111 * @param peers handle to peers run in the testbed
112 */
125static void 113static void
126run (void *cls, char *const *args, const char *cfgfile, 114run (void *cls,
127 const struct GNUNET_CONFIGURATION_Handle *cfg) 115 unsigned int num_peers,
116 struct GNUNET_TESTBED_Peer **peers)
128{ 117{
129 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", TIMEOUT, NUM_DAEMONS, 118 unsigned int i;
130 daemons, &do_connect, NULL); 119
120 GNUNET_assert (NUM_DAEMONS == num_peers);
121 for (i=0;i<num_peers;i++)
122 the_peers[i] = peers[i];
123 GNUNET_TESTBED_overlay_connect (NULL,
124 &do_publish,
125 NULL,
126 peers[0],
127 peers[1]);
131} 128}
132 129
133 130
131/**
132 * Main function that initializes the testbed.
133 *
134 * @param argc ignored
135 * @param argv ignored
136 * @return 0 on success
137 */
134int 138int
135main (int argc, char *argv[]) 139main (int argc, char *argv[])
136{ 140{
137 char *const argvx[] = {
138 "test-fs-test-lib",
139 "-c",
140 "fs_test_lib_data.conf",
141 NULL
142 };
143 struct GNUNET_GETOPT_CommandLineOption options[] = {
144 GNUNET_GETOPT_OPTION_END
145 };
146
147 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 141 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
148 GNUNET_log_setup ("test_fs_test_lib", 142 GNUNET_TESTBED_test_run ("test_fs_test_lib",
149 "WARNING", 143 "fs_test_lib_data.conf",
150 NULL); 144 NUM_DAEMONS,
151 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, 145 0, NULL, NULL,
152 "test-fs-test-lib", "nohelp", options, &run, NULL); 146 &run, NULL);
153 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 147 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
154 return ret; 148 return ret;
155} 149}
diff --git a/src/fs/test_gnunet_service_fs_migration.c b/src/fs/test_gnunet_service_fs_migration.c
index 00aab4f42..f1f2084f9 100644
--- a/src/fs/test_gnunet_service_fs_migration.c
+++ b/src/fs/test_gnunet_service_fs_migration.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff (and other contributing authors) 3 (C) 2010, 2012 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -25,7 +25,7 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "fs_test_lib.h" 27#include "fs_test_lib.h"
28#include "gnunet_testing_lib.h" 28#include "gnunet_testbed_service.h"
29 29
30#define VERBOSE GNUNET_NO 30#define VERBOSE GNUNET_NO
31 31
@@ -46,13 +46,12 @@
46 46
47#define SEED 42 47#define SEED 42
48 48
49static struct GNUNET_FS_TestDaemon *daemons[2]; 49static struct GNUNET_TESTBED_Peer *daemons[2];
50 50
51static int ok; 51static int ok;
52 52
53static struct GNUNET_TIME_Absolute start_time; 53static struct GNUNET_TIME_Absolute start_time;
54 54
55static struct GNUNET_FS_TEST_ConnectContext *cc;
56 55
57static void 56static void
58do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 57do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -60,12 +59,7 @@ do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
60 struct GNUNET_TIME_Relative del; 59 struct GNUNET_TIME_Relative del;
61 char *fancy; 60 char *fancy;
62 61
63 if (NULL != cc) 62 GNUNET_SCHEDULER_shutdown ();
64 {
65 GNUNET_FS_TEST_daemons_connect_cancel (cc);
66 cc = NULL;
67 }
68 GNUNET_FS_TEST_daemons_stop (2, daemons);
69 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) 63 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
70 { 64 {
71 del = GNUNET_TIME_absolute_get_duration (start_time); 65 del = GNUNET_TIME_absolute_get_duration (start_time);
@@ -89,13 +83,14 @@ do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
89 83
90 84
91static void 85static void
92do_download (void *cls, const char *emsg) 86do_download (void *cls,
87 const char *emsg)
93{ 88{
94 struct GNUNET_FS_Uri *uri = cls; 89 struct GNUNET_FS_Uri *uri = cls;
95 90
96 if (emsg != NULL) 91 if (NULL != emsg)
97 { 92 {
98 GNUNET_FS_TEST_daemons_stop (2, daemons); 93 GNUNET_SCHEDULER_shutdown ();
99 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to stop source daemon: %s\n", 94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to stop source daemon: %s\n",
100 emsg); 95 emsg);
101 GNUNET_FS_uri_destroy (uri); 96 GNUNET_FS_uri_destroy (uri);
@@ -115,11 +110,9 @@ static void
115stop_source_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 110stop_source_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
116{ 111{
117 struct GNUNET_FS_Uri *uri = cls; 112 struct GNUNET_FS_Uri *uri = cls;
118 struct GNUNET_TESTING_PeerGroup *pg;
119 113
120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping source peer\n"); 114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping source peer\n");
121 pg = GNUNET_FS_TEST_get_group (daemons); 115 GNUNET_TESTBED_peer_stop (daemons[1], &do_download, uri);
122 GNUNET_TESTING_daemons_vary (pg, 1, GNUNET_NO, TIMEOUT, &do_download, uri);
123} 116}
124 117
125 118
@@ -130,7 +123,7 @@ do_wait (void *cls, const struct GNUNET_FS_Uri *uri)
130 123
131 if (NULL == uri) 124 if (NULL == uri)
132 { 125 {
133 GNUNET_FS_TEST_daemons_stop (2, daemons); 126 GNUNET_SCHEDULER_shutdown ();
134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
135 "Timeout during upload attempt, shutting down with error\n"); 128 "Timeout during upload attempt, shutting down with error\n");
136 ok = 1; 129 ok = 1;
@@ -143,14 +136,16 @@ do_wait (void *cls, const struct GNUNET_FS_Uri *uri)
143 136
144 137
145static void 138static void
146do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 139do_publish (void *cls,
140 struct GNUNET_TESTBED_Operation *op,
141 const char *emsg)
147{ 142{
148 cc = NULL; 143 if (NULL != emsg)
149 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
150 { 144 {
151 GNUNET_FS_TEST_daemons_stop (2, daemons); 145 GNUNET_SCHEDULER_shutdown ();
152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 146 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
153 "Timeout during connect attempt, shutting down with error\n"); 147 "Error connecting peers: %s\n",
148 emsg);
154 ok = 1; 149 ok = 1;
155 return; 150 return;
156 } 151 }
@@ -162,58 +157,32 @@ do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
162 157
163 158
164static void 159static void
165do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 160do_connect (void *cls,
161 unsigned int num_peers,
162 struct GNUNET_TESTBED_Peer **peers)
166{ 163{
167 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 164 unsigned int i;
168 { 165
169 FPRINTF (stderr, "%s", "Daemons failed to start!\n"); 166 GNUNET_assert (2 == num_peers);
170 GNUNET_break (0); 167 for (i=0;i<num_peers;i++)
171 ok = 1; 168 daemons[i] = peers[i];
172 return;
173 }
174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
175 "Daemons started, will now try to connect them\n"); 170 "Daemons started, will now try to connect them\n");
176 cc = GNUNET_FS_TEST_daemons_connect (daemons[0], daemons[1], TIMEOUT, 171 GNUNET_TESTBED_overlay_connect (NULL,
177 &do_publish, NULL); 172 &do_publish, NULL,
178} 173 daemons[0], daemons[1]);
179
180
181static void
182run (void *cls, char *const *args, const char *cfgfile,
183 const struct GNUNET_CONFIGURATION_Handle *cfg)
184{
185 GNUNET_FS_TEST_daemons_start ("test_gnunet_service_fs_migration_data.conf",
186 TIMEOUT, 2, daemons, &do_connect, NULL);
187} 174}
188 175
189 176
190int 177int
191main (int argc, char *argv[]) 178main (int argc, char *argv[])
192{ 179{
193 char *const argvx[] = { 180 GNUNET_TESTBED_test_run ("test-gnunet-service-fs-migration",
194 "test-gnunet-service-fs-migration", 181 "fs_test_lib_data.conf",
195 "-c", 182 2,
196 "fs_test_lib_data.conf", 183 0, NULL, NULL,
197#if VERBOSE 184 &do_connect,
198 "-L", "DEBUG", 185 NULL);
199#endif
200 NULL
201 };
202 struct GNUNET_GETOPT_CommandLineOption options[] = {
203 GNUNET_GETOPT_OPTION_END
204 };
205
206 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
207 GNUNET_log_setup ("test_gnunet_service_fs_migration",
208#if VERBOSE
209 "DEBUG",
210#else
211 "WARNING",
212#endif
213 NULL);
214 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
215 "test-gnunet-service-fs-migration", "nohelp", options,
216 &run, NULL);
217 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/"); 186 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
218 return ok; 187 return ok;
219} 188}
diff --git a/src/fs/test_gnunet_service_fs_p2p.c b/src/fs/test_gnunet_service_fs_p2p.c
index 7ca786ed2..df7b9604b 100644
--- a/src/fs/test_gnunet_service_fs_p2p.c
+++ b/src/fs/test_gnunet_service_fs_p2p.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff (and other contributing authors) 3 (C) 2010, 2012 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -42,13 +42,12 @@
42 42
43#define SEED 42 43#define SEED 42
44 44
45static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS]; 45static struct GNUNET_TESTBED_Peer *daemons[NUM_DAEMONS];
46 46
47static int ok; 47static int ok;
48 48
49static struct GNUNET_TIME_Absolute start_time; 49static struct GNUNET_TIME_Absolute start_time;
50 50
51static struct GNUNET_FS_TEST_ConnectContext *cc;
52 51
53static void 52static void
54do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 53do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -56,12 +55,7 @@ do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
56 struct GNUNET_TIME_Relative del; 55 struct GNUNET_TIME_Relative del;
57 char *fancy; 56 char *fancy;
58 57
59 if (NULL != cc) 58 GNUNET_SCHEDULER_shutdown ();
60 {
61 GNUNET_FS_TEST_daemons_connect_cancel (cc);
62 cc = NULL;
63 }
64 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
65 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) 59 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
66 { 60 {
67 del = GNUNET_TIME_absolute_get_duration (start_time); 61 del = GNUNET_TIME_absolute_get_duration (start_time);
@@ -89,7 +83,7 @@ do_download (void *cls, const struct GNUNET_FS_Uri *uri)
89{ 83{
90 if (NULL == uri) 84 if (NULL == uri)
91 { 85 {
92 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons); 86 GNUNET_SCHEDULER_shutdown ();
93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 87 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
94 "Timeout during upload attempt, shutting down with error\n"); 88 "Timeout during upload attempt, shutting down with error\n");
95 ok = 1; 89 ok = 1;
@@ -104,14 +98,16 @@ do_download (void *cls, const struct GNUNET_FS_Uri *uri)
104 98
105 99
106static void 100static void
107do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 101do_publish (void *cls,
102 struct GNUNET_TESTBED_Operation *op,
103 const char *emsg)
108{ 104{
109 cc = NULL; 105 if (NULL != emsg)
110 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
111 { 106 {
112 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons); 107 GNUNET_SCHEDULER_shutdown ();
113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 108 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
114 "Timeout during connect attempt, shutting down with error\n"); 109 "Timeout during connect attempt, shutting down with error: %s\n",
110 emsg);
115 ok = 1; 111 ok = 1;
116 return; 112 return;
117 } 113 }
@@ -123,52 +119,31 @@ do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
123 119
124 120
125static void 121static void
126do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 122do_connect (void *cls,
123 unsigned int num_peers,
124 struct GNUNET_TESTBED_Peer **peers)
127{ 125{
128 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)); 126 unsigned int i;
127
128 GNUNET_assert (NUM_DAEMONS == num_peers);
129 for (i=0;i<num_peers;i++)
130 daemons[i] = peers[i];
129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
130 "Daemons started, will now try to connect them\n"); 132 "Daemons started, will now try to connect them\n");
131 cc = GNUNET_FS_TEST_daemons_connect (daemons[0], daemons[1], TIMEOUT, 133 GNUNET_TESTBED_overlay_connect (NULL,
132 &do_publish, NULL); 134 &do_publish, NULL,
133} 135 daemons[0], daemons[1]);
134
135
136static void
137run (void *cls, char *const *args, const char *cfgfile,
138 const struct GNUNET_CONFIGURATION_Handle *cfg)
139{
140 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", TIMEOUT, NUM_DAEMONS,
141 daemons, &do_connect, NULL);
142} 136}
143 137
144 138
145int 139int
146main (int argc, char *argv[]) 140main (int argc, char *argv[])
147{ 141{
148 char *const argvx[] = { 142 GNUNET_TESTBED_test_run ("test-gnunet-service-fs-p2p",
149 "test-gnunet-service-fs-p2p", 143 "fs_test_lib_data.conf",
150 "-c", 144 NUM_DAEMONS,
151 "fs_test_lib_data.conf", 145 0, NULL, NULL,
152#if VERBOSE 146 &do_connect, NULL);
153 "-L", "DEBUG",
154#endif
155 NULL
156 };
157 struct GNUNET_GETOPT_CommandLineOption options[] = {
158 GNUNET_GETOPT_OPTION_END
159 };
160
161 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
162 GNUNET_log_setup ("test_gnunet_service_fs_p2p",
163#if VERBOSE
164 "DEBUG",
165#else
166 "WARNING",
167#endif
168 NULL);
169 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
170 "test-gnunet-service-fs-p2p", "nohelp", options, &run,
171 NULL);
172 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 147 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
173 return ok; 148 return ok;
174} 149}