diff options
Diffstat (limited to 'src/fs/fs_test_lib.c')
-rw-r--r-- | src/fs/fs_test_lib.c | 580 |
1 files changed, 268 insertions, 312 deletions
diff --git a/src/fs/fs_test_lib.c b/src/fs/fs_test_lib.c index 522967f13..334432232 100644 --- a/src/fs/fs_test_lib.c +++ b/src/fs/fs_test_lib.c | |||
@@ -77,7 +77,7 @@ struct GNUNET_FS_TestDaemon | |||
77 | * Function to call when upload is done. | 77 | * Function to call when upload is done. |
78 | */ | 78 | */ |
79 | GNUNET_FS_TEST_UriContinuation publish_cont; | 79 | GNUNET_FS_TEST_UriContinuation publish_cont; |
80 | 80 | ||
81 | /** | 81 | /** |
82 | * Closure for publish_cont. | 82 | * Closure for publish_cont. |
83 | */ | 83 | */ |
@@ -105,7 +105,7 @@ struct GNUNET_FS_TestDaemon | |||
105 | 105 | ||
106 | /** | 106 | /** |
107 | * Name of the temporary file used, or NULL for none. | 107 | * Name of the temporary file used, or NULL for none. |
108 | */ | 108 | */ |
109 | char *publish_tmp_file; | 109 | char *publish_tmp_file; |
110 | 110 | ||
111 | /** | 111 | /** |
@@ -130,7 +130,7 @@ struct GNUNET_FS_TestDaemon | |||
130 | 130 | ||
131 | /** | 131 | /** |
132 | * Context for current download operation. | 132 | * Context for current download operation. |
133 | */ | 133 | */ |
134 | struct GNUNET_FS_DownloadContext *download_context; | 134 | struct GNUNET_FS_DownloadContext *download_context; |
135 | 135 | ||
136 | /** | 136 | /** |
@@ -138,39 +138,35 @@ struct GNUNET_FS_TestDaemon | |||
138 | */ | 138 | */ |
139 | int verbose; | 139 | int verbose; |
140 | 140 | ||
141 | 141 | ||
142 | }; | 142 | }; |
143 | 143 | ||
144 | /** | 144 | /** |
145 | * Check whether peers successfully shut down. | 145 | * Check whether peers successfully shut down. |
146 | */ | 146 | */ |
147 | static void | 147 | static void |
148 | shutdown_callback (void *cls, | 148 | shutdown_callback (void *cls, const char *emsg) |
149 | const char *emsg) | ||
150 | { | 149 | { |
151 | struct GNUNET_CONFIGURATION_Handle *gcfg = cls; | 150 | struct GNUNET_CONFIGURATION_Handle *gcfg = cls; |
152 | 151 | ||
153 | if (emsg != NULL) | 152 | if (emsg != NULL) |
154 | { | 153 | { |
155 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 154 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
156 | "Shutdown of peers failed: %s\n", | 155 | "Shutdown of peers failed: %s\n", emsg); |
157 | emsg); | 156 | } |
158 | } | ||
159 | else | 157 | else |
160 | { | 158 | { |
161 | #if VERBOSE | 159 | #if VERBOSE |
162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 160 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n"); |
163 | "All peers successfully shut down!\n"); | ||
164 | #endif | 161 | #endif |
165 | } | 162 | } |
166 | if (gcfg != NULL) | 163 | if (gcfg != NULL) |
167 | GNUNET_CONFIGURATION_destroy (gcfg); | 164 | GNUNET_CONFIGURATION_destroy (gcfg); |
168 | } | 165 | } |
169 | 166 | ||
170 | 167 | ||
171 | static void | 168 | static void |
172 | report_uri (void *cls, | 169 | report_uri (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
173 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
174 | { | 170 | { |
175 | struct GNUNET_FS_TestDaemon *daemon = cls; | 171 | struct GNUNET_FS_TestDaemon *daemon = cls; |
176 | GNUNET_FS_TEST_UriContinuation cont; | 172 | GNUNET_FS_TEST_UriContinuation cont; |
@@ -181,73 +177,70 @@ report_uri (void *cls, | |||
181 | cont = daemon->publish_cont; | 177 | cont = daemon->publish_cont; |
182 | daemon->publish_cont = NULL; | 178 | daemon->publish_cont = NULL; |
183 | uri = daemon->publish_uri; | 179 | uri = daemon->publish_uri; |
184 | cont (daemon->publish_cont_cls, | 180 | cont (daemon->publish_cont_cls, uri); |
185 | uri); | ||
186 | GNUNET_FS_uri_destroy (uri); | 181 | GNUNET_FS_uri_destroy (uri); |
187 | } | 182 | } |
188 | 183 | ||
189 | 184 | ||
190 | static void | 185 | static void |
191 | report_success (void *cls, | 186 | report_success (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
192 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
193 | { | 187 | { |
194 | struct GNUNET_FS_TestDaemon *daemon = cls; | 188 | struct GNUNET_FS_TestDaemon *daemon = cls; |
195 | 189 | ||
196 | GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES); | 190 | GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES); |
197 | daemon->download_context = NULL; | 191 | daemon->download_context = NULL; |
198 | GNUNET_SCHEDULER_add_continuation (daemon->download_cont, | 192 | GNUNET_SCHEDULER_add_continuation (daemon->download_cont, |
199 | daemon->download_cont_cls, | 193 | daemon->download_cont_cls, |
200 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 194 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
201 | daemon->download_cont = NULL; | 195 | daemon->download_cont = NULL; |
202 | } | 196 | } |
203 | 197 | ||
204 | 198 | ||
205 | static void* | 199 | static void * |
206 | progress_cb (void *cls, | 200 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) |
207 | const struct GNUNET_FS_ProgressInfo *info) | ||
208 | { | 201 | { |
209 | struct GNUNET_FS_TestDaemon *daemon = cls; | 202 | struct GNUNET_FS_TestDaemon *daemon = cls; |
210 | 203 | ||
211 | switch (info->status) | 204 | switch (info->status) |
212 | { | 205 | { |
213 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 206 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
214 | GNUNET_SCHEDULER_cancel (daemon->publish_timeout_task); | 207 | GNUNET_SCHEDULER_cancel (daemon->publish_timeout_task); |
215 | daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK; | 208 | daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK; |
216 | daemon->publish_uri = GNUNET_FS_uri_dup (info->value.publish.specifics.completed.chk_uri); | 209 | daemon->publish_uri = |
217 | GNUNET_SCHEDULER_add_continuation (&report_uri, | 210 | GNUNET_FS_uri_dup (info->value.publish.specifics.completed.chk_uri); |
218 | daemon, | 211 | GNUNET_SCHEDULER_add_continuation (&report_uri, daemon, |
219 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 212 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
220 | break; | 213 | break; |
221 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 214 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
222 | if (daemon->verbose) | 215 | if (daemon->verbose) |
223 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 216 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
224 | "Publishing at %llu/%llu bytes\n", | 217 | "Publishing at %llu/%llu bytes\n", |
225 | (unsigned long long) info->value.publish.completed, | 218 | (unsigned long long) info->value.publish.completed, |
226 | (unsigned long long) info->value.publish.size); | 219 | (unsigned long long) info->value.publish.size); |
227 | break; | 220 | break; |
228 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | 221 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: |
229 | if (daemon->verbose) | 222 | if (daemon->verbose) |
230 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 223 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
231 | "Download at %llu/%llu bytes\n", | 224 | "Download at %llu/%llu bytes\n", |
232 | (unsigned long long) info->value.download.completed, | 225 | (unsigned long long) info->value.download.completed, |
233 | (unsigned long long) info->value.download.size); | 226 | (unsigned long long) info->value.download.size); |
234 | break; | 227 | break; |
235 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | 228 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: |
236 | GNUNET_SCHEDULER_cancel (daemon->download_timeout_task); | 229 | GNUNET_SCHEDULER_cancel (daemon->download_timeout_task); |
237 | daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK; | 230 | daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK; |
238 | GNUNET_SCHEDULER_add_continuation (&report_success, | 231 | GNUNET_SCHEDULER_add_continuation (&report_success, |
239 | daemon, | 232 | daemon, |
240 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 233 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
241 | break; | 234 | break; |
242 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | 235 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: |
243 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | 236 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: |
244 | break; | 237 | break; |
245 | /* FIXME: monitor data correctness during download progress */ | 238 | /* FIXME: monitor data correctness during download progress */ |
246 | /* FIXME: do performance reports given sufficient verbosity */ | 239 | /* FIXME: do performance reports given sufficient verbosity */ |
247 | /* FIXME: advance timeout task to "immediate" on error */ | 240 | /* FIXME: advance timeout task to "immediate" on error */ |
248 | default: | 241 | default: |
249 | break; | 242 | break; |
250 | } | 243 | } |
251 | return NULL; | 244 | return NULL; |
252 | } | 245 | } |
253 | 246 | ||
@@ -266,31 +259,28 @@ struct StartContext | |||
266 | }; | 259 | }; |
267 | 260 | ||
268 | 261 | ||
269 | static void | 262 | static void |
270 | notify_running (void *cls, | 263 | notify_running (void *cls, |
271 | const struct GNUNET_PeerIdentity *id, | 264 | const struct GNUNET_PeerIdentity *id, |
272 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 265 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
273 | struct GNUNET_TESTING_Daemon *d, | 266 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
274 | const char *emsg) | ||
275 | { | 267 | { |
276 | struct StartContext *sctx = cls; | 268 | struct StartContext *sctx = cls; |
277 | unsigned int i; | 269 | unsigned int i; |
278 | 270 | ||
279 | if (emsg != NULL) | 271 | if (emsg != NULL) |
280 | { | 272 | { |
281 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 273 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
282 | _("Failed to start daemon: %s\n"), | 274 | _("Failed to start daemon: %s\n"), emsg); |
283 | emsg); | 275 | return; |
284 | return; | 276 | } |
285 | } | ||
286 | i = 0; | 277 | i = 0; |
287 | while (i < sctx->total) | 278 | while (i < sctx->total) |
288 | { | 279 | { |
289 | if (GNUNET_TESTING_daemon_get (sctx->group, | 280 | if (GNUNET_TESTING_daemon_get (sctx->group, i) == d) |
290 | i) == d) | 281 | break; |
291 | break; | 282 | i++; |
292 | i++; | 283 | } |
293 | } | ||
294 | GNUNET_assert (i < sctx->total); | 284 | GNUNET_assert (i < sctx->total); |
295 | GNUNET_assert (sctx->have < sctx->total); | 285 | GNUNET_assert (sctx->have < sctx->total); |
296 | GNUNET_assert (sctx->daemons[i]->cfg == NULL); | 286 | GNUNET_assert (sctx->daemons[i]->cfg == NULL); |
@@ -300,50 +290,49 @@ notify_running (void *cls, | |||
300 | sctx->daemons[i]->id = *id; | 290 | sctx->daemons[i]->id = *id; |
301 | sctx->have++; | 291 | sctx->have++; |
302 | if (sctx->have == sctx->total) | 292 | if (sctx->have == sctx->total) |
293 | { | ||
294 | GNUNET_SCHEDULER_add_continuation (sctx->cont, | ||
295 | sctx->cont_cls, | ||
296 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
297 | sctx->daemons[0]->gcfg = sctx->cfg; | ||
298 | GNUNET_SCHEDULER_cancel (sctx->timeout_task); | ||
299 | for (i = 0; i < sctx->total; i++) | ||
303 | { | 300 | { |
304 | GNUNET_SCHEDULER_add_continuation (sctx->cont, | 301 | sctx->daemons[i]->fs = GNUNET_FS_start (sctx->daemons[i]->cfg, |
305 | sctx->cont_cls, | 302 | "<tester>", |
306 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 303 | &progress_cb, |
307 | sctx->daemons[0]->gcfg = sctx->cfg; | 304 | sctx->daemons[i], |
308 | GNUNET_SCHEDULER_cancel (sctx->timeout_task); | 305 | GNUNET_FS_FLAGS_NONE, |
309 | for (i=0;i<sctx->total;i++) | 306 | GNUNET_FS_OPTIONS_END); |
310 | { | ||
311 | sctx->daemons[i]->fs = GNUNET_FS_start (sctx->daemons[i]->cfg, | ||
312 | "<tester>", | ||
313 | &progress_cb, | ||
314 | sctx->daemons[i], | ||
315 | GNUNET_FS_FLAGS_NONE, | ||
316 | GNUNET_FS_OPTIONS_END); | ||
317 | } | ||
318 | GNUNET_free (sctx); | ||
319 | } | 307 | } |
308 | GNUNET_free (sctx); | ||
309 | } | ||
320 | } | 310 | } |
321 | 311 | ||
322 | 312 | ||
323 | static void | 313 | static void |
324 | start_timeout (void *cls, | 314 | start_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
325 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
326 | { | 315 | { |
327 | struct StartContext *sctx = cls; | 316 | struct StartContext *sctx = cls; |
328 | unsigned int i; | 317 | unsigned int i; |
329 | 318 | ||
330 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 319 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
331 | "Timeout while trying to start daemons\n"); | 320 | "Timeout while trying to start daemons\n"); |
332 | GNUNET_TESTING_daemons_stop (sctx->group, | 321 | GNUNET_TESTING_daemons_stop (sctx->group, |
333 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), | 322 | GNUNET_TIME_relative_multiply |
334 | &shutdown_callback, | 323 | (GNUNET_TIME_UNIT_SECONDS, 30), |
335 | NULL); | 324 | &shutdown_callback, NULL); |
336 | for (i=0;i<sctx->total;i++) | 325 | for (i = 0; i < sctx->total; i++) |
337 | { | 326 | { |
338 | if (i < sctx->have) | 327 | if (i < sctx->have) |
339 | GNUNET_CONFIGURATION_destroy (sctx->daemons[i]->cfg); | 328 | GNUNET_CONFIGURATION_destroy (sctx->daemons[i]->cfg); |
340 | GNUNET_free (sctx->daemons[i]); | 329 | GNUNET_free (sctx->daemons[i]); |
341 | sctx->daemons[i] = NULL; | 330 | sctx->daemons[i] = NULL; |
342 | } | 331 | } |
343 | GNUNET_CONFIGURATION_destroy (sctx->cfg); | 332 | GNUNET_CONFIGURATION_destroy (sctx->cfg); |
344 | GNUNET_SCHEDULER_add_continuation (sctx->cont, | 333 | GNUNET_SCHEDULER_add_continuation (sctx->cont, |
345 | sctx->cont_cls, | 334 | sctx->cont_cls, |
346 | GNUNET_SCHEDULER_REASON_TIMEOUT); | 335 | GNUNET_SCHEDULER_REASON_TIMEOUT); |
347 | GNUNET_free (sctx); | 336 | GNUNET_free (sctx); |
348 | } | 337 | } |
349 | 338 | ||
@@ -362,11 +351,10 @@ start_timeout (void *cls, | |||
362 | */ | 351 | */ |
363 | void | 352 | void |
364 | GNUNET_FS_TEST_daemons_start (const char *template_cfg_file, | 353 | GNUNET_FS_TEST_daemons_start (const char *template_cfg_file, |
365 | struct GNUNET_TIME_Relative timeout, | 354 | struct GNUNET_TIME_Relative timeout, |
366 | unsigned int total, | 355 | unsigned int total, |
367 | struct GNUNET_FS_TestDaemon **daemons, | 356 | struct GNUNET_FS_TestDaemon **daemons, |
368 | GNUNET_SCHEDULER_Task cont, | 357 | GNUNET_SCHEDULER_Task cont, void *cont_cls) |
369 | void *cont_cls) | ||
370 | { | 358 | { |
371 | struct StartContext *sctx; | 359 | struct StartContext *sctx; |
372 | unsigned int i; | 360 | unsigned int i; |
@@ -378,34 +366,27 @@ GNUNET_FS_TEST_daemons_start (const char *template_cfg_file, | |||
378 | sctx->cont = cont; | 366 | sctx->cont = cont; |
379 | sctx->cont_cls = cont_cls; | 367 | sctx->cont_cls = cont_cls; |
380 | sctx->cfg = GNUNET_CONFIGURATION_create (); | 368 | sctx->cfg = GNUNET_CONFIGURATION_create (); |
381 | if (GNUNET_OK != | 369 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (sctx->cfg, template_cfg_file)) |
382 | GNUNET_CONFIGURATION_load (sctx->cfg, | 370 | { |
383 | template_cfg_file)) | 371 | GNUNET_break (0); |
384 | { | 372 | GNUNET_CONFIGURATION_destroy (sctx->cfg); |
385 | GNUNET_break (0); | 373 | GNUNET_free (sctx); |
386 | GNUNET_CONFIGURATION_destroy (sctx->cfg); | 374 | GNUNET_SCHEDULER_add_continuation (cont, |
387 | GNUNET_free (sctx); | 375 | cont_cls, |
388 | GNUNET_SCHEDULER_add_continuation (cont, | 376 | GNUNET_SCHEDULER_REASON_TIMEOUT); |
389 | cont_cls, | 377 | return; |
390 | GNUNET_SCHEDULER_REASON_TIMEOUT); | 378 | } |
391 | return; | 379 | for (i = 0; i < total; i++) |
392 | } | ||
393 | for (i=0;i<total;i++) | ||
394 | daemons[i] = GNUNET_malloc (sizeof (struct GNUNET_FS_TestDaemon)); | 380 | daemons[i] = GNUNET_malloc (sizeof (struct GNUNET_FS_TestDaemon)); |
395 | sctx->group = GNUNET_TESTING_daemons_start (sctx->cfg, | 381 | sctx->group = GNUNET_TESTING_daemons_start (sctx->cfg, total, total, /* Outstanding connections */ |
396 | total, | 382 | total, /* Outstanding ssh connections */ |
397 | total, /* Outstanding connections */ | 383 | timeout, |
398 | total, /* Outstanding ssh connections */ | 384 | NULL, |
399 | timeout, | 385 | NULL, |
400 | NULL, | 386 | ¬ify_running, |
401 | NULL, | 387 | sctx, NULL, NULL, NULL); |
402 | ¬ify_running, | ||
403 | sctx, | ||
404 | NULL, NULL, | ||
405 | NULL); | ||
406 | sctx->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, | 388 | sctx->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, |
407 | &start_timeout, | 389 | &start_timeout, sctx); |
408 | sctx); | ||
409 | } | 390 | } |
410 | 391 | ||
411 | 392 | ||
@@ -432,26 +413,25 @@ struct ConnectContext | |||
432 | */ | 413 | */ |
433 | static void | 414 | static void |
434 | notify_connection (void *cls, | 415 | notify_connection (void *cls, |
435 | const struct GNUNET_PeerIdentity *first, | 416 | const struct GNUNET_PeerIdentity *first, |
436 | const struct GNUNET_PeerIdentity *second, | 417 | const struct GNUNET_PeerIdentity *second, |
437 | uint32_t distance, | 418 | uint32_t distance, |
438 | const struct GNUNET_CONFIGURATION_Handle *first_cfg, | 419 | const struct GNUNET_CONFIGURATION_Handle *first_cfg, |
439 | const struct GNUNET_CONFIGURATION_Handle *second_cfg, | 420 | const struct GNUNET_CONFIGURATION_Handle *second_cfg, |
440 | struct GNUNET_TESTING_Daemon *first_daemon, | 421 | struct GNUNET_TESTING_Daemon *first_daemon, |
441 | struct GNUNET_TESTING_Daemon *second_daemon, | 422 | struct GNUNET_TESTING_Daemon *second_daemon, |
442 | const char *emsg) | 423 | const char *emsg) |
443 | { | 424 | { |
444 | struct ConnectContext *cc = cls; | 425 | struct ConnectContext *cc = cls; |
445 | 426 | ||
446 | if (emsg != NULL) | 427 | if (emsg != NULL) |
447 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 428 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
448 | "Failed to connect peers: %s\n", | 429 | "Failed to connect peers: %s\n", emsg); |
449 | emsg); | ||
450 | GNUNET_SCHEDULER_add_continuation (cc->cont, | 430 | GNUNET_SCHEDULER_add_continuation (cc->cont, |
451 | cc->cont_cls, | 431 | cc->cont_cls, |
452 | (emsg != NULL) | 432 | (emsg != NULL) |
453 | ? GNUNET_SCHEDULER_REASON_TIMEOUT | 433 | ? GNUNET_SCHEDULER_REASON_TIMEOUT |
454 | : GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 434 | : GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
455 | GNUNET_free (cc); | 435 | GNUNET_free (cc); |
456 | } | 436 | } |
457 | 437 | ||
@@ -468,10 +448,9 @@ notify_connection (void *cls, | |||
468 | */ | 448 | */ |
469 | void | 449 | void |
470 | GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1, | 450 | GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1, |
471 | struct GNUNET_FS_TestDaemon *daemon2, | 451 | struct GNUNET_FS_TestDaemon *daemon2, |
472 | struct GNUNET_TIME_Relative timeout, | 452 | struct GNUNET_TIME_Relative timeout, |
473 | GNUNET_SCHEDULER_Task cont, | 453 | GNUNET_SCHEDULER_Task cont, void *cont_cls) |
474 | void *cont_cls) | ||
475 | { | 454 | { |
476 | struct ConnectContext *ncc; | 455 | struct ConnectContext *ncc; |
477 | 456 | ||
@@ -479,12 +458,10 @@ GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1, | |||
479 | ncc->cont = cont; | 458 | ncc->cont = cont; |
480 | ncc->cont_cls = cont_cls; | 459 | ncc->cont_cls = cont_cls; |
481 | GNUNET_TESTING_daemons_connect (daemon1->daemon, | 460 | GNUNET_TESTING_daemons_connect (daemon1->daemon, |
482 | daemon2->daemon, | 461 | daemon2->daemon, |
483 | timeout, | 462 | timeout, |
484 | CONNECT_ATTEMPTS, | 463 | CONNECT_ATTEMPTS, |
485 | GNUNET_YES, | 464 | GNUNET_YES, ¬ify_connection, ncc); |
486 | ¬ify_connection, | ||
487 | ncc); | ||
488 | } | 465 | } |
489 | 466 | ||
490 | 467 | ||
@@ -497,9 +474,9 @@ GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1, | |||
497 | */ | 474 | */ |
498 | const struct GNUNET_CONFIGURATION_Handle * | 475 | const struct GNUNET_CONFIGURATION_Handle * |
499 | GNUNET_FS_TEST_get_configuration (struct GNUNET_FS_TestDaemon **daemons, | 476 | GNUNET_FS_TEST_get_configuration (struct GNUNET_FS_TestDaemon **daemons, |
500 | unsigned int off) | 477 | unsigned int off) |
501 | { | 478 | { |
502 | return daemons[off]->cfg; | 479 | return daemons[off]->cfg; |
503 | } | 480 | } |
504 | 481 | ||
505 | /** | 482 | /** |
@@ -511,7 +488,7 @@ GNUNET_FS_TEST_get_configuration (struct GNUNET_FS_TestDaemon **daemons, | |||
511 | struct GNUNET_TESTING_PeerGroup * | 488 | struct GNUNET_TESTING_PeerGroup * |
512 | GNUNET_FS_TEST_get_group (struct GNUNET_FS_TestDaemon **daemons) | 489 | GNUNET_FS_TEST_get_group (struct GNUNET_FS_TestDaemon **daemons) |
513 | { | 490 | { |
514 | return daemons[0]->group; | 491 | return daemons[0]->group; |
515 | } | 492 | } |
516 | 493 | ||
517 | 494 | ||
@@ -523,7 +500,7 @@ GNUNET_FS_TEST_get_group (struct GNUNET_FS_TestDaemon **daemons) | |||
523 | */ | 500 | */ |
524 | void | 501 | void |
525 | GNUNET_FS_TEST_daemons_stop (unsigned int total, | 502 | GNUNET_FS_TEST_daemons_stop (unsigned int total, |
526 | struct GNUNET_FS_TestDaemon **daemons) | 503 | struct GNUNET_FS_TestDaemon **daemons) |
527 | { | 504 | { |
528 | unsigned int i; | 505 | unsigned int i; |
529 | struct GNUNET_TESTING_PeerGroup *pg; | 506 | struct GNUNET_TESTING_PeerGroup *pg; |
@@ -534,70 +511,64 @@ GNUNET_FS_TEST_daemons_stop (unsigned int total, | |||
534 | GNUNET_assert (daemons[0] != NULL); | 511 | GNUNET_assert (daemons[0] != NULL); |
535 | pg = daemons[0]->group; | 512 | pg = daemons[0]->group; |
536 | gcfg = daemons[0]->gcfg; | 513 | gcfg = daemons[0]->gcfg; |
537 | for (i=0;i<total;i++) | 514 | for (i = 0; i < total; i++) |
515 | { | ||
516 | daemon = daemons[i]; | ||
517 | if (daemon->download_timeout_task != GNUNET_SCHEDULER_NO_TASK) | ||
518 | { | ||
519 | GNUNET_SCHEDULER_cancel (daemon->download_timeout_task); | ||
520 | daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
521 | } | ||
522 | if (daemon->publish_timeout_task != GNUNET_SCHEDULER_NO_TASK) | ||
538 | { | 523 | { |
539 | daemon = daemons[i]; | 524 | GNUNET_SCHEDULER_cancel (daemon->publish_timeout_task); |
540 | if (daemon->download_timeout_task != GNUNET_SCHEDULER_NO_TASK) | 525 | daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK; |
541 | { | 526 | } |
542 | GNUNET_SCHEDULER_cancel (daemon->download_timeout_task); | 527 | if (NULL != daemon->download_context) |
543 | daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK; | 528 | { |
544 | } | 529 | GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES); |
545 | if (daemon->publish_timeout_task != GNUNET_SCHEDULER_NO_TASK) | 530 | daemon->download_context = NULL; |
546 | { | 531 | } |
547 | GNUNET_SCHEDULER_cancel (daemon->publish_timeout_task); | 532 | if (daemon->fs != NULL) |
548 | daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK; | 533 | GNUNET_FS_stop (daemon->fs); |
549 | } | 534 | if (daemon->cfg != NULL) |
550 | if (NULL != daemon->download_context) | 535 | GNUNET_CONFIGURATION_destroy (daemon->cfg); |
551 | { | 536 | if (NULL != daemon->publish_tmp_file) |
552 | GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES); | 537 | { |
553 | daemon->download_context = NULL; | 538 | GNUNET_break (GNUNET_OK == |
554 | } | 539 | GNUNET_DISK_directory_remove (daemon->publish_tmp_file)); |
555 | if (daemon->fs != NULL) | 540 | GNUNET_free (daemon->publish_tmp_file); |
556 | GNUNET_FS_stop (daemon->fs); | 541 | daemon->publish_tmp_file = NULL; |
557 | if (daemon->cfg != NULL) | 542 | } |
558 | GNUNET_CONFIGURATION_destroy (daemon->cfg); | 543 | GNUNET_free (daemon); |
559 | if (NULL != daemon->publish_tmp_file) | 544 | daemons[i] = NULL; |
560 | { | 545 | } |
561 | GNUNET_break (GNUNET_OK == | 546 | GNUNET_TESTING_daemons_stop (pg, |
562 | GNUNET_DISK_directory_remove (daemon->publish_tmp_file)); | 547 | GNUNET_TIME_relative_multiply |
563 | GNUNET_free (daemon->publish_tmp_file); | 548 | (GNUNET_TIME_UNIT_SECONDS, 30), |
564 | daemon->publish_tmp_file = NULL; | 549 | &shutdown_callback, gcfg); |
565 | } | ||
566 | GNUNET_free (daemon); | ||
567 | daemons[i] = NULL; | ||
568 | } | ||
569 | GNUNET_TESTING_daemons_stop (pg, | ||
570 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), | ||
571 | &shutdown_callback, | ||
572 | gcfg); | ||
573 | } | 550 | } |
574 | 551 | ||
575 | 552 | ||
576 | static void | 553 | static void |
577 | publish_timeout (void *cls, | 554 | publish_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
578 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
579 | { | 555 | { |
580 | struct GNUNET_FS_TestDaemon *daemon = cls; | 556 | struct GNUNET_FS_TestDaemon *daemon = cls; |
581 | GNUNET_FS_TEST_UriContinuation cont; | 557 | GNUNET_FS_TEST_UriContinuation cont; |
582 | 558 | ||
583 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 559 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
584 | "Timeout while trying to publish data\n"); | 560 | "Timeout while trying to publish data\n"); |
585 | cont = daemon->publish_cont; | 561 | cont = daemon->publish_cont; |
586 | daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK; | 562 | daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK; |
587 | daemon->publish_cont = NULL; | 563 | daemon->publish_cont = NULL; |
588 | GNUNET_FS_publish_stop (daemon->publish_context); | 564 | GNUNET_FS_publish_stop (daemon->publish_context); |
589 | daemon->publish_context = NULL; | 565 | daemon->publish_context = NULL; |
590 | cont (daemon->publish_cont_cls, | 566 | cont (daemon->publish_cont_cls, NULL); |
591 | NULL); | ||
592 | } | 567 | } |
593 | 568 | ||
594 | 569 | ||
595 | static size_t | 570 | static size_t |
596 | file_generator (void *cls, | 571 | file_generator (void *cls, uint64_t offset, size_t max, void *buf, char **emsg) |
597 | uint64_t offset, | ||
598 | size_t max, | ||
599 | void *buf, | ||
600 | char **emsg) | ||
601 | { | 572 | { |
602 | struct GNUNET_FS_TestDaemon *daemon = cls; | 573 | struct GNUNET_FS_TestDaemon *daemon = cls; |
603 | uint64_t pos; | 574 | uint64_t pos; |
@@ -608,15 +579,15 @@ file_generator (void *cls, | |||
608 | *emsg = NULL; | 579 | *emsg = NULL; |
609 | if (buf == NULL) | 580 | if (buf == NULL) |
610 | return 0; | 581 | return 0; |
611 | for (pos=0;pos<8;pos++) | 582 | for (pos = 0; pos < 8; pos++) |
612 | cbuf[pos] = (uint8_t) (offset >> pos*8); | 583 | cbuf[pos] = (uint8_t) (offset >> pos * 8); |
613 | for (pos=8;pos<max;pos++) | 584 | for (pos = 8; pos < max; pos++) |
614 | { | 585 | { |
615 | mod = (255 - (offset / 1024 / 32)); | 586 | mod = (255 - (offset / 1024 / 32)); |
616 | if (mod == 0) | 587 | if (mod == 0) |
617 | mod = 1; | 588 | mod = 1; |
618 | cbuf[pos] = (uint8_t) ((offset * daemon->publish_seed) % mod); | 589 | cbuf[pos] = (uint8_t) ((offset * daemon->publish_seed) % mod); |
619 | } | 590 | } |
620 | return max; | 591 | return max; |
621 | } | 592 | } |
622 | 593 | ||
@@ -639,14 +610,13 @@ file_generator (void *cls, | |||
639 | */ | 610 | */ |
640 | void | 611 | void |
641 | GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon, | 612 | GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon, |
642 | struct GNUNET_TIME_Relative timeout, | 613 | struct GNUNET_TIME_Relative timeout, |
643 | uint32_t anonymity, | 614 | uint32_t anonymity, |
644 | int do_index, | 615 | int do_index, |
645 | uint64_t size, | 616 | uint64_t size, |
646 | uint32_t seed, | 617 | uint32_t seed, |
647 | unsigned int verbose, | 618 | unsigned int verbose, |
648 | GNUNET_FS_TEST_UriContinuation cont, | 619 | GNUNET_FS_TEST_UriContinuation cont, void *cont_cls) |
649 | void *cont_cls) | ||
650 | { | 620 | { |
651 | struct GNUNET_FS_FileInformation *fi; | 621 | struct GNUNET_FS_FileInformation *fi; |
652 | struct GNUNET_DISK_FileHandle *fh; | 622 | struct GNUNET_DISK_FileHandle *fh; |
@@ -655,7 +625,7 @@ GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon, | |||
655 | char buf[DBLOCK_SIZE]; | 625 | char buf[DBLOCK_SIZE]; |
656 | size_t bsize; | 626 | size_t bsize; |
657 | struct GNUNET_FS_BlockOptions bo; | 627 | struct GNUNET_FS_BlockOptions bo; |
658 | 628 | ||
659 | GNUNET_assert (daemon->publish_cont == NULL); | 629 | GNUNET_assert (daemon->publish_cont == NULL); |
660 | daemon->publish_cont = cont; | 630 | daemon->publish_cont = cont; |
661 | daemon->publish_cont_cls = cont_cls; | 631 | daemon->publish_cont_cls = cont_cls; |
@@ -666,78 +636,66 @@ GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon, | |||
666 | bo.content_priority = 42; | 636 | bo.content_priority = 42; |
667 | bo.replication_level = 1; | 637 | bo.replication_level = 1; |
668 | if (GNUNET_YES == do_index) | 638 | if (GNUNET_YES == do_index) |
639 | { | ||
640 | GNUNET_assert (daemon->publish_tmp_file == NULL); | ||
641 | daemon->publish_tmp_file = GNUNET_DISK_mktemp ("fs-test-publish-index"); | ||
642 | GNUNET_assert (daemon->publish_tmp_file != NULL); | ||
643 | fh = GNUNET_DISK_file_open (daemon->publish_tmp_file, | ||
644 | GNUNET_DISK_OPEN_WRITE | | ||
645 | GNUNET_DISK_OPEN_CREATE, | ||
646 | GNUNET_DISK_PERM_USER_READ | | ||
647 | GNUNET_DISK_PERM_USER_WRITE); | ||
648 | GNUNET_assert (NULL != fh); | ||
649 | off = 0; | ||
650 | while (off < size) | ||
669 | { | 651 | { |
670 | GNUNET_assert (daemon->publish_tmp_file == NULL); | 652 | bsize = GNUNET_MIN (sizeof (buf), size - off); |
671 | daemon->publish_tmp_file = GNUNET_DISK_mktemp ("fs-test-publish-index"); | 653 | emsg = NULL; |
672 | GNUNET_assert (daemon->publish_tmp_file != NULL); | 654 | GNUNET_assert (bsize == file_generator (daemon, off, bsize, buf, &emsg)); |
673 | fh = GNUNET_DISK_file_open (daemon->publish_tmp_file, | 655 | GNUNET_assert (emsg == NULL); |
674 | GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, | 656 | GNUNET_assert (bsize == GNUNET_DISK_file_write (fh, buf, bsize)); |
675 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | 657 | off += bsize; |
676 | GNUNET_assert (NULL != fh); | ||
677 | off = 0; | ||
678 | while (off < size) | ||
679 | { | ||
680 | bsize = GNUNET_MIN (sizeof (buf), | ||
681 | size - off); | ||
682 | emsg = NULL; | ||
683 | GNUNET_assert (bsize == | ||
684 | file_generator (daemon, | ||
685 | off, | ||
686 | bsize, | ||
687 | buf, | ||
688 | &emsg)); | ||
689 | GNUNET_assert (emsg == NULL); | ||
690 | GNUNET_assert (bsize == | ||
691 | GNUNET_DISK_file_write (fh, | ||
692 | buf, | ||
693 | bsize)); | ||
694 | off += bsize; | ||
695 | } | ||
696 | GNUNET_assert (GNUNET_OK == | ||
697 | GNUNET_DISK_file_close (fh)); | ||
698 | fi = GNUNET_FS_file_information_create_from_file (daemon->fs, | ||
699 | daemon, | ||
700 | daemon->publish_tmp_file, | ||
701 | NULL, NULL, | ||
702 | do_index, | ||
703 | &bo); | ||
704 | } | 658 | } |
659 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); | ||
660 | fi = GNUNET_FS_file_information_create_from_file (daemon->fs, | ||
661 | daemon, | ||
662 | daemon->publish_tmp_file, | ||
663 | NULL, NULL, | ||
664 | do_index, &bo); | ||
665 | } | ||
705 | else | 666 | else |
706 | { | 667 | { |
707 | fi = GNUNET_FS_file_information_create_from_reader (daemon->fs, | 668 | fi = GNUNET_FS_file_information_create_from_reader (daemon->fs, |
708 | daemon, | 669 | daemon, |
709 | size, | 670 | size, |
710 | &file_generator, | 671 | &file_generator, |
711 | daemon, | 672 | daemon, |
712 | NULL, | 673 | NULL, |
713 | NULL, | 674 | NULL, do_index, &bo); |
714 | do_index, | 675 | } |
715 | &bo); | ||
716 | } | ||
717 | daemon->publish_context = GNUNET_FS_publish_start (daemon->fs, | 676 | daemon->publish_context = GNUNET_FS_publish_start (daemon->fs, |
718 | fi, | 677 | fi, |
719 | NULL, NULL, NULL, | 678 | NULL, NULL, NULL, |
720 | GNUNET_FS_PUBLISH_OPTION_NONE); | 679 | GNUNET_FS_PUBLISH_OPTION_NONE); |
721 | daemon->publish_timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, | 680 | daemon->publish_timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, |
722 | &publish_timeout, | 681 | &publish_timeout, |
723 | daemon); | 682 | daemon); |
724 | } | 683 | } |
725 | 684 | ||
726 | 685 | ||
727 | static void | 686 | static void |
728 | download_timeout (void *cls, | 687 | download_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
729 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
730 | { | 688 | { |
731 | struct GNUNET_FS_TestDaemon *daemon = cls; | 689 | struct GNUNET_FS_TestDaemon *daemon = cls; |
732 | 690 | ||
733 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 691 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
734 | "Timeout while trying to download file\n"); | 692 | "Timeout while trying to download file\n"); |
735 | daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK; | 693 | daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK; |
736 | GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES); | 694 | GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES); |
737 | daemon->download_context = NULL; | 695 | daemon->download_context = NULL; |
738 | GNUNET_SCHEDULER_add_continuation (daemon->download_cont, | 696 | GNUNET_SCHEDULER_add_continuation (daemon->download_cont, |
739 | daemon->download_cont_cls, | 697 | daemon->download_cont_cls, |
740 | GNUNET_SCHEDULER_REASON_TIMEOUT); | 698 | GNUNET_SCHEDULER_REASON_TIMEOUT); |
741 | daemon->download_cont = NULL; | 699 | daemon->download_cont = NULL; |
742 | } | 700 | } |
743 | 701 | ||
@@ -757,35 +715,33 @@ download_timeout (void *cls, | |||
757 | */ | 715 | */ |
758 | void | 716 | void |
759 | GNUNET_FS_TEST_download (struct GNUNET_FS_TestDaemon *daemon, | 717 | GNUNET_FS_TEST_download (struct GNUNET_FS_TestDaemon *daemon, |
760 | struct GNUNET_TIME_Relative timeout, | 718 | struct GNUNET_TIME_Relative timeout, |
761 | uint32_t anonymity, | 719 | uint32_t anonymity, |
762 | uint32_t seed, | 720 | uint32_t seed, |
763 | const struct GNUNET_FS_Uri *uri, | 721 | const struct GNUNET_FS_Uri *uri, |
764 | unsigned int verbose, | 722 | unsigned int verbose, |
765 | GNUNET_SCHEDULER_Task cont, | 723 | GNUNET_SCHEDULER_Task cont, void *cont_cls) |
766 | void *cont_cls) | ||
767 | { | 724 | { |
768 | uint64_t size; | 725 | uint64_t size; |
769 | 726 | ||
770 | GNUNET_assert (daemon->download_cont == NULL); | 727 | GNUNET_assert (daemon->download_cont == NULL); |
771 | size = GNUNET_FS_uri_chk_get_file_size (uri); | 728 | size = GNUNET_FS_uri_chk_get_file_size (uri); |
772 | daemon->verbose = verbose; | 729 | daemon->verbose = verbose; |
773 | daemon->download_cont = cont; | 730 | daemon->download_cont = cont; |
774 | daemon->download_cont_cls = cont_cls; | 731 | daemon->download_cont_cls = cont_cls; |
775 | daemon->download_seed = seed; | 732 | daemon->download_seed = seed; |
776 | daemon->download_context = GNUNET_FS_download_start (daemon->fs, | 733 | daemon->download_context = GNUNET_FS_download_start (daemon->fs, |
777 | uri, | 734 | uri, |
778 | NULL, NULL, | 735 | NULL, NULL, |
779 | NULL, | 736 | NULL, |
780 | 0, | 737 | 0, |
781 | size, | 738 | size, |
782 | anonymity, | 739 | anonymity, |
783 | GNUNET_FS_DOWNLOAD_OPTION_NONE, | 740 | GNUNET_FS_DOWNLOAD_OPTION_NONE, |
784 | NULL, | 741 | NULL, NULL); |
785 | NULL); | ||
786 | daemon->download_timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, | 742 | daemon->download_timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, |
787 | &download_timeout, | 743 | &download_timeout, |
788 | daemon); | 744 | daemon); |
789 | } | 745 | } |
790 | 746 | ||
791 | /* end of test_fs_lib.c */ | 747 | /* end of test_fs_lib.c */ |