diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-03 12:05:57 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-03 12:05:57 +0000 |
commit | 82d0757e1908c04f76dd69016fbb7d538318f003 (patch) | |
tree | 243464194f9e2148adc905f811d46831dea55001 /src/fs/fs_api.c | |
parent | 8b46e74546fb643a5d272bb1edd8c909a4ee978d (diff) | |
download | gnunet-82d0757e1908c04f76dd69016fbb7d538318f003.tar.gz gnunet-82d0757e1908c04f76dd69016fbb7d538318f003.zip |
convert download API to MQ
Diffstat (limited to 'src/fs/fs_api.c')
-rw-r--r-- | src/fs/fs_api.c | 62 |
1 files changed, 37 insertions, 25 deletions
diff --git a/src/fs/fs_api.c b/src/fs/fs_api.c index 2db475528..0bc07183e 100644 --- a/src/fs/fs_api.c +++ b/src/fs/fs_api.c | |||
@@ -49,14 +49,8 @@ | |||
49 | static void | 49 | static void |
50 | start_job (struct GNUNET_FS_QueueEntry *qe) | 50 | start_job (struct GNUNET_FS_QueueEntry *qe) |
51 | { | 51 | { |
52 | GNUNET_assert (NULL == qe->client); | 52 | qe->active = GNUNET_YES; |
53 | qe->client = GNUNET_CLIENT_connect ("fs", qe->h->cfg); | 53 | qe->start (qe->cls); |
54 | if (NULL == qe->client) | ||
55 | { | ||
56 | GNUNET_break (0); | ||
57 | return; | ||
58 | } | ||
59 | qe->start (qe->cls, qe->client); | ||
60 | qe->start_times++; | 54 | qe->start_times++; |
61 | qe->h->active_blocks += qe->blocks; | 55 | qe->h->active_blocks += qe->blocks; |
62 | qe->h->active_downloads++; | 56 | qe->h->active_downloads++; |
@@ -84,7 +78,7 @@ start_job (struct GNUNET_FS_QueueEntry *qe) | |||
84 | static void | 78 | static void |
85 | stop_job (struct GNUNET_FS_QueueEntry *qe) | 79 | stop_job (struct GNUNET_FS_QueueEntry *qe) |
86 | { | 80 | { |
87 | qe->client = NULL; | 81 | qe->active = GNUNET_NO; |
88 | qe->stop (qe->cls); | 82 | qe->stop (qe->cls); |
89 | GNUNET_assert (0 < qe->h->active_downloads); | 83 | GNUNET_assert (0 < qe->h->active_downloads); |
90 | qe->h->active_downloads--; | 84 | qe->h->active_downloads--; |
@@ -97,9 +91,13 @@ stop_job (struct GNUNET_FS_QueueEntry *qe) | |||
97 | "Stopping job %p (%u active)\n", | 91 | "Stopping job %p (%u active)\n", |
98 | qe, | 92 | qe, |
99 | qe->h->active_downloads); | 93 | qe->h->active_downloads); |
100 | GNUNET_CONTAINER_DLL_remove (qe->h->running_head, qe->h->running_tail, qe); | 94 | GNUNET_CONTAINER_DLL_remove (qe->h->running_head, |
101 | GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head, qe->h->pending_tail, | 95 | qe->h->running_tail, |
102 | qe->h->pending_tail, qe); | 96 | qe); |
97 | GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head, | ||
98 | qe->h->pending_tail, | ||
99 | qe->h->pending_tail, | ||
100 | qe); | ||
103 | } | 101 | } |
104 | 102 | ||
105 | 103 | ||
@@ -328,8 +326,9 @@ process_job_queue (void *cls) | |||
328 | */ | 326 | */ |
329 | struct GNUNET_FS_QueueEntry * | 327 | struct GNUNET_FS_QueueEntry * |
330 | GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, | 328 | GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, |
331 | GNUNET_FS_QueueStart start, | 329 | GNUNET_SCHEDULER_TaskCallback start, |
332 | GNUNET_FS_QueueStop stop, void *cls, | 330 | GNUNET_SCHEDULER_TaskCallback stop, |
331 | void *cls, | ||
333 | unsigned int blocks, | 332 | unsigned int blocks, |
334 | enum GNUNET_FS_QueuePriority priority) | 333 | enum GNUNET_FS_QueuePriority priority) |
335 | { | 334 | { |
@@ -369,13 +368,16 @@ GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe) | |||
369 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 368 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
370 | "Dequeueing job %p\n", | 369 | "Dequeueing job %p\n", |
371 | qe); | 370 | qe); |
372 | if (NULL != qe->client) | 371 | if (GNUNET_YES == qe->active) |
373 | stop_job (qe); | 372 | stop_job (qe); |
374 | GNUNET_CONTAINER_DLL_remove (h->pending_head, h->pending_tail, qe); | 373 | GNUNET_CONTAINER_DLL_remove (h->pending_head, |
374 | h->pending_tail, | ||
375 | qe); | ||
375 | GNUNET_free (qe); | 376 | GNUNET_free (qe); |
376 | if (NULL != h->queue_job) | 377 | if (NULL != h->queue_job) |
377 | GNUNET_SCHEDULER_cancel (h->queue_job); | 378 | GNUNET_SCHEDULER_cancel (h->queue_job); |
378 | h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h); | 379 | h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, |
380 | h); | ||
379 | } | 381 | } |
380 | 382 | ||
381 | 383 | ||
@@ -397,7 +399,9 @@ GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, | |||
397 | ret = GNUNET_new (struct TopLevelActivity); | 399 | ret = GNUNET_new (struct TopLevelActivity); |
398 | ret->ssf = ssf; | 400 | ret->ssf = ssf; |
399 | ret->ssf_cls = ssf_cls; | 401 | ret->ssf_cls = ssf_cls; |
400 | GNUNET_CONTAINER_DLL_insert (h->top_head, h->top_tail, ret); | 402 | GNUNET_CONTAINER_DLL_insert (h->top_head, |
403 | h->top_tail, | ||
404 | ret); | ||
401 | return ret; | 405 | return ret; |
402 | } | 406 | } |
403 | 407 | ||
@@ -412,7 +416,9 @@ void | |||
412 | GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, | 416 | GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, |
413 | struct TopLevelActivity *top) | 417 | struct TopLevelActivity *top) |
414 | { | 418 | { |
415 | GNUNET_CONTAINER_DLL_remove (h->top_head, h->top_tail, top); | 419 | GNUNET_CONTAINER_DLL_remove (h->top_head, |
420 | h->top_tail, | ||
421 | top); | ||
416 | GNUNET_free (top); | 422 | GNUNET_free (top); |
417 | } | 423 | } |
418 | 424 | ||
@@ -2531,8 +2537,7 @@ signal_download_resume (struct GNUNET_FS_DownloadContext *dc) | |||
2531 | signal_download_resume (dcc); | 2537 | signal_download_resume (dcc); |
2532 | dcc = dcc->next; | 2538 | dcc = dcc->next; |
2533 | } | 2539 | } |
2534 | if (NULL != dc->pending_head) | 2540 | GNUNET_FS_download_start_downloading_ (dc); |
2535 | GNUNET_FS_download_start_downloading_ (dc); | ||
2536 | } | 2541 | } |
2537 | 2542 | ||
2538 | 2543 | ||
@@ -2815,12 +2820,16 @@ deserialize_download (struct GNUNET_FS_Handle *h, | |||
2815 | if (NULL != dn) | 2820 | if (NULL != dn) |
2816 | { | 2821 | { |
2817 | if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) | 2822 | if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) |
2818 | GNUNET_DISK_directory_scan (dn, &deserialize_subdownload, dc); | 2823 | GNUNET_DISK_directory_scan (dn, |
2824 | &deserialize_subdownload, | ||
2825 | dc); | ||
2819 | GNUNET_free (dn); | 2826 | GNUNET_free (dn); |
2820 | } | 2827 | } |
2821 | if (NULL != parent) | 2828 | if (NULL != parent) |
2822 | { | 2829 | { |
2823 | GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc); | 2830 | GNUNET_CONTAINER_DLL_insert (parent->child_head, |
2831 | parent->child_tail, | ||
2832 | dc); | ||
2824 | } | 2833 | } |
2825 | if (NULL != search) | 2834 | if (NULL != search) |
2826 | { | 2835 | { |
@@ -2830,11 +2839,14 @@ deserialize_download (struct GNUNET_FS_Handle *h, | |||
2830 | if ((NULL == parent) && (NULL == search)) | 2839 | if ((NULL == parent) && (NULL == search)) |
2831 | { | 2840 | { |
2832 | dc->top = | 2841 | dc->top = |
2833 | GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc); | 2842 | GNUNET_FS_make_top (dc->h, |
2843 | &GNUNET_FS_download_signal_suspend_, | ||
2844 | dc); | ||
2834 | signal_download_resume (dc); | 2845 | signal_download_resume (dc); |
2835 | } | 2846 | } |
2836 | GNUNET_free (uris); | 2847 | GNUNET_free (uris); |
2837 | dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc); | 2848 | dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, |
2849 | dc); | ||
2838 | return; | 2850 | return; |
2839 | cleanup: | 2851 | cleanup: |
2840 | GNUNET_free_non_null (uris); | 2852 | GNUNET_free_non_null (uris); |