aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_test_lib.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-11-05 18:21:50 +0000
committerNathan S. Evans <evans@in.tum.de>2010-11-05 18:21:50 +0000
commit75a33a1499cf60ea4364c9aa673816629a6c1413 (patch)
tree0620da4312bb04de4d7b65074fdd3b0c3dd6cc0e /src/fs/fs_test_lib.c
parent7217c601ad30760872823193d62307e7a335d226 (diff)
downloadgnunet-75a33a1499cf60ea4364c9aa673816629a6c1413.tar.gz
gnunet-75a33a1499cf60ea4364c9aa673816629a6c1413.zip
big scheduler refactoring, expect some issues
Diffstat (limited to 'src/fs/fs_test_lib.c')
-rw-r--r--src/fs/fs_test_lib.c87
1 files changed, 21 insertions, 66 deletions
diff --git a/src/fs/fs_test_lib.c b/src/fs/fs_test_lib.c
index f91092c4e..b7f3cb55a 100644
--- a/src/fs/fs_test_lib.c
+++ b/src/fs/fs_test_lib.c
@@ -72,11 +72,6 @@ struct GNUNET_FS_TestDaemon
72 struct GNUNET_PeerIdentity id; 72 struct GNUNET_PeerIdentity id;
73 73
74 /** 74 /**
75 * Scheduler to use (for publish_cont).
76 */
77 struct GNUNET_SCHEDULER_Handle *publish_sched;
78
79 /**
80 * Function to call when upload is done. 75 * Function to call when upload is done.
81 */ 76 */
82 GNUNET_FS_TEST_UriContinuation publish_cont; 77 GNUNET_FS_TEST_UriContinuation publish_cont;
@@ -112,11 +107,6 @@ struct GNUNET_FS_TestDaemon
112 char *publish_tmp_file; 107 char *publish_tmp_file;
113 108
114 /** 109 /**
115 * Scheduler to use (for download_cont).
116 */
117 struct GNUNET_SCHEDULER_Handle *download_sched;
118
119 /**
120 * Function to call when download is done. 110 * Function to call when download is done.
121 */ 111 */
122 GNUNET_SCHEDULER_Task download_cont; 112 GNUNET_SCHEDULER_Task download_cont;
@@ -186,7 +176,6 @@ report_uri (void *cls,
186 176
187 GNUNET_FS_publish_stop (daemon->publish_context); 177 GNUNET_FS_publish_stop (daemon->publish_context);
188 daemon->publish_context = NULL; 178 daemon->publish_context = NULL;
189 daemon->publish_sched = NULL;
190 cont = daemon->publish_cont; 179 cont = daemon->publish_cont;
191 daemon->publish_cont = NULL; 180 daemon->publish_cont = NULL;
192 uri = daemon->publish_uri; 181 uri = daemon->publish_uri;
@@ -204,12 +193,10 @@ report_success (void *cls,
204 193
205 GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES); 194 GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES);
206 daemon->download_context = NULL; 195 daemon->download_context = NULL;
207 GNUNET_SCHEDULER_add_continuation (daemon->download_sched, 196 GNUNET_SCHEDULER_add_continuation (daemon->download_cont,
208 daemon->download_cont,
209 daemon->download_cont_cls, 197 daemon->download_cont_cls,
210 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 198 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
211 daemon->download_cont = NULL; 199 daemon->download_cont = NULL;
212 daemon->download_sched = NULL;
213} 200}
214 201
215 202
@@ -222,12 +209,10 @@ progress_cb (void *cls,
222 switch (info->status) 209 switch (info->status)
223 { 210 {
224 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 211 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
225 GNUNET_SCHEDULER_cancel (daemon->publish_sched, 212 GNUNET_SCHEDULER_cancel (daemon->publish_timeout_task);
226 daemon->publish_timeout_task);
227 daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK; 213 daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
228 daemon->publish_uri = GNUNET_FS_uri_dup (info->value.publish.specifics.completed.chk_uri); 214 daemon->publish_uri = GNUNET_FS_uri_dup (info->value.publish.specifics.completed.chk_uri);
229 GNUNET_SCHEDULER_add_continuation (daemon->publish_sched, 215 GNUNET_SCHEDULER_add_continuation (&report_uri,
230 &report_uri,
231 daemon, 216 daemon,
232 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 217 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
233 break; 218 break;
@@ -246,11 +231,9 @@ progress_cb (void *cls,
246 (unsigned long long) info->value.download.size); 231 (unsigned long long) info->value.download.size);
247 break; 232 break;
248 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: 233 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
249 GNUNET_SCHEDULER_cancel (daemon->download_sched, 234 GNUNET_SCHEDULER_cancel (daemon->download_timeout_task);
250 daemon->download_timeout_task);
251 daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK; 235 daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
252 GNUNET_SCHEDULER_add_continuation (daemon->download_sched, 236 GNUNET_SCHEDULER_add_continuation (&report_success,
253 &report_success,
254 daemon, 237 daemon,
255 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 238 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
256 break; 239 break;
@@ -269,7 +252,6 @@ progress_cb (void *cls,
269 252
270struct StartContext 253struct StartContext
271{ 254{
272 struct GNUNET_SCHEDULER_Handle *sched;
273 struct GNUNET_TIME_Relative timeout; 255 struct GNUNET_TIME_Relative timeout;
274 unsigned int total; 256 unsigned int total;
275 unsigned int have; 257 unsigned int have;
@@ -317,17 +299,14 @@ notify_running (void *cls,
317 sctx->have++; 299 sctx->have++;
318 if (sctx->have == sctx->total) 300 if (sctx->have == sctx->total)
319 { 301 {
320 GNUNET_SCHEDULER_add_continuation (sctx->sched, 302 GNUNET_SCHEDULER_add_continuation (sctx->cont,
321 sctx->cont,
322 sctx->cont_cls, 303 sctx->cont_cls,
323 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 304 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
324 sctx->daemons[0]->gcfg = sctx->cfg; 305 sctx->daemons[0]->gcfg = sctx->cfg;
325 GNUNET_SCHEDULER_cancel (sctx->sched, 306 GNUNET_SCHEDULER_cancel (sctx->timeout_task);
326 sctx->timeout_task);
327 for (i=0;i<sctx->total;i++) 307 for (i=0;i<sctx->total;i++)
328 { 308 {
329 sctx->daemons[i]->fs = GNUNET_FS_start (sctx->sched, 309 sctx->daemons[i]->fs = GNUNET_FS_start (sctx->daemons[i]->cfg,
330 sctx->daemons[i]->cfg,
331 "<tester>", 310 "<tester>",
332 &progress_cb, 311 &progress_cb,
333 sctx->daemons[i], 312 sctx->daemons[i],
@@ -360,8 +339,7 @@ start_timeout (void *cls,
360 sctx->daemons[i] = NULL; 339 sctx->daemons[i] = NULL;
361 } 340 }
362 GNUNET_CONFIGURATION_destroy (sctx->cfg); 341 GNUNET_CONFIGURATION_destroy (sctx->cfg);
363 GNUNET_SCHEDULER_add_continuation (sctx->sched, 342 GNUNET_SCHEDULER_add_continuation (sctx->cont,
364 sctx->cont,
365 sctx->cont_cls, 343 sctx->cont_cls,
366 GNUNET_SCHEDULER_REASON_TIMEOUT); 344 GNUNET_SCHEDULER_REASON_TIMEOUT);
367 GNUNET_free (sctx); 345 GNUNET_free (sctx);
@@ -371,7 +349,6 @@ start_timeout (void *cls,
371/** 349/**
372 * Start daemons for testing. 350 * Start daemons for testing.
373 * 351 *
374 * @param sched scheduler to use
375 * @param template_cfg_file configuration template to use 352 * @param template_cfg_file configuration template to use
376 * @param timeout if this operation cannot be completed within the 353 * @param timeout if this operation cannot be completed within the
377 * given period, call the continuation with an error code 354 * given period, call the continuation with an error code
@@ -382,8 +359,7 @@ start_timeout (void *cls,
382 * @param cont_cls closure for cont 359 * @param cont_cls closure for cont
383 */ 360 */
384void 361void
385GNUNET_FS_TEST_daemons_start (struct GNUNET_SCHEDULER_Handle *sched, 362GNUNET_FS_TEST_daemons_start (const char *template_cfg_file,
386 const char *template_cfg_file,
387 struct GNUNET_TIME_Relative timeout, 363 struct GNUNET_TIME_Relative timeout,
388 unsigned int total, 364 unsigned int total,
389 struct GNUNET_FS_TestDaemon **daemons, 365 struct GNUNET_FS_TestDaemon **daemons,
@@ -395,7 +371,6 @@ GNUNET_FS_TEST_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
395 371
396 GNUNET_assert (total > 0); 372 GNUNET_assert (total > 0);
397 sctx = GNUNET_malloc (sizeof (struct StartContext)); 373 sctx = GNUNET_malloc (sizeof (struct StartContext));
398 sctx->sched = sched;
399 sctx->daemons = daemons; 374 sctx->daemons = daemons;
400 sctx->total = total; 375 sctx->total = total;
401 sctx->cont = cont; 376 sctx->cont = cont;
@@ -408,16 +383,14 @@ GNUNET_FS_TEST_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
408 GNUNET_break (0); 383 GNUNET_break (0);
409 GNUNET_CONFIGURATION_destroy (sctx->cfg); 384 GNUNET_CONFIGURATION_destroy (sctx->cfg);
410 GNUNET_free (sctx); 385 GNUNET_free (sctx);
411 GNUNET_SCHEDULER_add_continuation (sched, 386 GNUNET_SCHEDULER_add_continuation (cont,
412 cont,
413 cont_cls, 387 cont_cls,
414 GNUNET_SCHEDULER_REASON_TIMEOUT); 388 GNUNET_SCHEDULER_REASON_TIMEOUT);
415 return; 389 return;
416 } 390 }
417 for (i=0;i<total;i++) 391 for (i=0;i<total;i++)
418 daemons[i] = GNUNET_malloc (sizeof (struct GNUNET_FS_TestDaemon)); 392 daemons[i] = GNUNET_malloc (sizeof (struct GNUNET_FS_TestDaemon));
419 sctx->group = GNUNET_TESTING_daemons_start (sched, 393 sctx->group = GNUNET_TESTING_daemons_start (sctx->cfg,
420 sctx->cfg,
421 total, 394 total,
422 timeout, 395 timeout,
423 NULL, 396 NULL,
@@ -426,8 +399,7 @@ GNUNET_FS_TEST_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
426 sctx, 399 sctx,
427 NULL, NULL, 400 NULL, NULL,
428 NULL); 401 NULL);
429 sctx->timeout_task = GNUNET_SCHEDULER_add_delayed (sched, 402 sctx->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
430 timeout,
431 &start_timeout, 403 &start_timeout,
432 sctx); 404 sctx);
433} 405}
@@ -435,7 +407,6 @@ GNUNET_FS_TEST_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
435 407
436struct ConnectContext 408struct ConnectContext
437{ 409{
438 struct GNUNET_SCHEDULER_Handle *sched;
439 GNUNET_SCHEDULER_Task cont; 410 GNUNET_SCHEDULER_Task cont;
440 void *cont_cls; 411 void *cont_cls;
441}; 412};
@@ -472,8 +443,7 @@ notify_connection (void *cls,
472 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 443 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
473 "Failed to connect peers: %s\n", 444 "Failed to connect peers: %s\n",
474 emsg); 445 emsg);
475 GNUNET_SCHEDULER_add_continuation (cc->sched, 446 GNUNET_SCHEDULER_add_continuation (cc->cont,
476 cc->cont,
477 cc->cont_cls, 447 cc->cont_cls,
478 (emsg != NULL) 448 (emsg != NULL)
479 ? GNUNET_SCHEDULER_REASON_TIMEOUT 449 ? GNUNET_SCHEDULER_REASON_TIMEOUT
@@ -485,7 +455,6 @@ notify_connection (void *cls,
485/** 455/**
486 * Connect two daemons for testing. 456 * Connect two daemons for testing.
487 * 457 *
488 * @param sched scheduler to use
489 * @param daemon1 first daemon to connect 458 * @param daemon1 first daemon to connect
490 * @param daemon2 second first daemon to connect 459 * @param daemon2 second first daemon to connect
491 * @param timeout if this operation cannot be completed within the 460 * @param timeout if this operation cannot be completed within the
@@ -494,8 +463,7 @@ notify_connection (void *cls,
494 * @param cont_cls closure for cont 463 * @param cont_cls closure for cont
495 */ 464 */
496void 465void
497GNUNET_FS_TEST_daemons_connect (struct GNUNET_SCHEDULER_Handle *sched, 466GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1,
498 struct GNUNET_FS_TestDaemon *daemon1,
499 struct GNUNET_FS_TestDaemon *daemon2, 467 struct GNUNET_FS_TestDaemon *daemon2,
500 struct GNUNET_TIME_Relative timeout, 468 struct GNUNET_TIME_Relative timeout,
501 GNUNET_SCHEDULER_Task cont, 469 GNUNET_SCHEDULER_Task cont,
@@ -504,7 +472,6 @@ GNUNET_FS_TEST_daemons_connect (struct GNUNET_SCHEDULER_Handle *sched,
504 struct ConnectContext *ncc; 472 struct ConnectContext *ncc;
505 473
506 ncc = GNUNET_malloc (sizeof (struct ConnectContext)); 474 ncc = GNUNET_malloc (sizeof (struct ConnectContext));
507 ncc->sched = sched;
508 ncc->cont = cont; 475 ncc->cont = cont;
509 ncc->cont_cls = cont_cls; 476 ncc->cont_cls = cont_cls;
510 GNUNET_TESTING_daemons_connect (daemon1->daemon, 477 GNUNET_TESTING_daemons_connect (daemon1->daemon,
@@ -546,13 +513,11 @@ GNUNET_FS_TEST_get_group (struct GNUNET_FS_TestDaemon **daemons)
546/** 513/**
547 * Stop daemons used for testing. 514 * Stop daemons used for testing.
548 * 515 *
549 * @param sched scheduler to use
550 * @param total number of daemons to stop 516 * @param total number of daemons to stop
551 * @param daemons array with the daemons (values will be clobbered) 517 * @param daemons array with the daemons (values will be clobbered)
552 */ 518 */
553void 519void
554GNUNET_FS_TEST_daemons_stop (struct GNUNET_SCHEDULER_Handle *sched, 520GNUNET_FS_TEST_daemons_stop (unsigned int total,
555 unsigned int total,
556 struct GNUNET_FS_TestDaemon **daemons) 521 struct GNUNET_FS_TestDaemon **daemons)
557{ 522{
558 unsigned int i; 523 unsigned int i;
@@ -633,7 +598,6 @@ file_generator (void *cls,
633/** 598/**
634 * Publish a file at the given daemon. 599 * Publish a file at the given daemon.
635 * 600 *
636 * @param sched scheduler to use
637 * @param daemon where to publish 601 * @param daemon where to publish
638 * @param timeout if this operation cannot be completed within the 602 * @param timeout if this operation cannot be completed within the
639 * given period, call the continuation with an error code 603 * given period, call the continuation with an error code
@@ -647,8 +611,7 @@ file_generator (void *cls,
647 * @param cont_cls closure for cont 611 * @param cont_cls closure for cont
648 */ 612 */
649void 613void
650GNUNET_FS_TEST_publish (struct GNUNET_SCHEDULER_Handle *sched, 614GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon,
651 struct GNUNET_FS_TestDaemon *daemon,
652 struct GNUNET_TIME_Relative timeout, 615 struct GNUNET_TIME_Relative timeout,
653 uint32_t anonymity, 616 uint32_t anonymity,
654 int do_index, 617 int do_index,
@@ -670,7 +633,6 @@ GNUNET_FS_TEST_publish (struct GNUNET_SCHEDULER_Handle *sched,
670 daemon->publish_cont_cls = cont_cls; 633 daemon->publish_cont_cls = cont_cls;
671 daemon->publish_seed = seed; 634 daemon->publish_seed = seed;
672 daemon->verbose = verbose; 635 daemon->verbose = verbose;
673 daemon->publish_sched = sched;
674 if (GNUNET_YES == do_index) 636 if (GNUNET_YES == do_index)
675 { 637 {
676 GNUNET_assert (daemon->publish_tmp_file == NULL); 638 GNUNET_assert (daemon->publish_tmp_file == NULL);
@@ -727,8 +689,7 @@ GNUNET_FS_TEST_publish (struct GNUNET_SCHEDULER_Handle *sched,
727 fi, 689 fi,
728 NULL, NULL, NULL, 690 NULL, NULL, NULL,
729 GNUNET_FS_PUBLISH_OPTION_NONE); 691 GNUNET_FS_PUBLISH_OPTION_NONE);
730 daemon->publish_timeout_task = GNUNET_SCHEDULER_add_delayed (sched, 692 daemon->publish_timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
731 timeout,
732 &publish_timeout, 693 &publish_timeout,
733 daemon); 694 daemon);
734} 695}
@@ -745,19 +706,16 @@ download_timeout (void *cls,
745 daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK; 706 daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
746 GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES); 707 GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES);
747 daemon->download_context = NULL; 708 daemon->download_context = NULL;
748 GNUNET_SCHEDULER_add_continuation (daemon->download_sched, 709 GNUNET_SCHEDULER_add_continuation (daemon->download_cont,
749 daemon->download_cont,
750 daemon->download_cont_cls, 710 daemon->download_cont_cls,
751 GNUNET_SCHEDULER_REASON_TIMEOUT); 711 GNUNET_SCHEDULER_REASON_TIMEOUT);
752 daemon->download_cont = NULL; 712 daemon->download_cont = NULL;
753 daemon->download_sched = NULL;
754} 713}
755 714
756 715
757/** 716/**
758 * Perform test download. 717 * Perform test download.
759 * 718 *
760 * @param sched scheduler to use
761 * @param daemon which peer to download from 719 * @param daemon which peer to download from
762 * @param timeout if this operation cannot be completed within the 720 * @param timeout if this operation cannot be completed within the
763 * given period, call the continuation with an error code 721 * given period, call the continuation with an error code
@@ -769,8 +727,7 @@ download_timeout (void *cls,
769 * @param cont_cls closure for cont 727 * @param cont_cls closure for cont
770 */ 728 */
771void 729void
772GNUNET_FS_TEST_download (struct GNUNET_SCHEDULER_Handle *sched, 730GNUNET_FS_TEST_download (struct GNUNET_FS_TestDaemon *daemon,
773 struct GNUNET_FS_TestDaemon *daemon,
774 struct GNUNET_TIME_Relative timeout, 731 struct GNUNET_TIME_Relative timeout,
775 uint32_t anonymity, 732 uint32_t anonymity,
776 uint32_t seed, 733 uint32_t seed,
@@ -784,7 +741,6 @@ GNUNET_FS_TEST_download (struct GNUNET_SCHEDULER_Handle *sched,
784 GNUNET_assert (daemon->download_cont == NULL); 741 GNUNET_assert (daemon->download_cont == NULL);
785 size = GNUNET_FS_uri_chk_get_file_size (uri); 742 size = GNUNET_FS_uri_chk_get_file_size (uri);
786 daemon->verbose = verbose; 743 daemon->verbose = verbose;
787 daemon->download_sched = sched;
788 daemon->download_cont = cont; 744 daemon->download_cont = cont;
789 daemon->download_cont_cls = cont_cls; 745 daemon->download_cont_cls = cont_cls;
790 daemon->download_seed = seed; 746 daemon->download_seed = seed;
@@ -798,8 +754,7 @@ GNUNET_FS_TEST_download (struct GNUNET_SCHEDULER_Handle *sched,
798 GNUNET_FS_DOWNLOAD_OPTION_NONE, 754 GNUNET_FS_DOWNLOAD_OPTION_NONE,
799 NULL, 755 NULL,
800 NULL); 756 NULL);
801 daemon->download_timeout_task = GNUNET_SCHEDULER_add_delayed (sched, 757 daemon->download_timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
802 timeout,
803 &download_timeout, 758 &download_timeout,
804 daemon); 759 daemon);
805} 760}