diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-12-17 07:40:54 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-12-17 07:40:54 +0000 |
commit | 19b03a205ed83f6a1d4d9178b20969032d569212 (patch) | |
tree | db0219f2e106d29fe5cb5c18e39df6782dd82e9a /src/fs | |
parent | 5cb2c469b505215e9cdd36c8e152e6db49f03c61 (diff) | |
download | gnunet-19b03a205ed83f6a1d4d9178b20969032d569212.tar.gz gnunet-19b03a205ed83f6a1d4d9178b20969032d569212.zip |
fixing block reconstruction start/shutdown code
Diffstat (limited to 'src/fs')
-rw-r--r-- | src/fs/fs.h | 11 | ||||
-rw-r--r-- | src/fs/fs_download.c | 68 | ||||
-rw-r--r-- | src/fs/test_fs_download.c | 1 | ||||
-rw-r--r-- | src/fs/test_fs_download_indexed.c | 1 |
4 files changed, 56 insertions, 25 deletions
diff --git a/src/fs/fs.h b/src/fs/fs.h index 6e6d0dd8e..e655a3e57 100644 --- a/src/fs/fs.h +++ b/src/fs/fs.h | |||
@@ -1683,6 +1683,12 @@ struct DownloadRequest | |||
1683 | 1683 | ||
1684 | 1684 | ||
1685 | /** | 1685 | /** |
1686 | * Closure for 'reconstruct_cont' and 'reconstruct_cb'. | ||
1687 | */ | ||
1688 | struct ReconstructContext; | ||
1689 | |||
1690 | |||
1691 | /** | ||
1686 | * Context for controlling a download. | 1692 | * Context for controlling a download. |
1687 | */ | 1693 | */ |
1688 | struct GNUNET_FS_DownloadContext | 1694 | struct GNUNET_FS_DownloadContext |
@@ -1726,6 +1732,11 @@ struct GNUNET_FS_DownloadContext | |||
1726 | struct GNUNET_FS_DownloadContext *child_tail; | 1732 | struct GNUNET_FS_DownloadContext *child_tail; |
1727 | 1733 | ||
1728 | /** | 1734 | /** |
1735 | * State for block reconstruction. | ||
1736 | */ | ||
1737 | struct ReconstructContext *rcc; | ||
1738 | |||
1739 | /** | ||
1729 | * Previous download belonging to the same parent. | 1740 | * Previous download belonging to the same parent. |
1730 | */ | 1741 | */ |
1731 | struct GNUNET_FS_DownloadContext *prev; | 1742 | struct GNUNET_FS_DownloadContext *prev; |
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index 942a77eee..d7693a93f 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c | |||
@@ -446,6 +446,11 @@ struct ReconstructContext | |||
446 | struct DownloadRequest *sm; | 446 | struct DownloadRequest *sm; |
447 | 447 | ||
448 | /** | 448 | /** |
449 | * Helper task. | ||
450 | */ | ||
451 | GNUNET_SCHEDULER_TaskIdentifier task; | ||
452 | |||
453 | /** | ||
449 | * Offset of block we are trying to reconstruct. | 454 | * Offset of block we are trying to reconstruct. |
450 | */ | 455 | */ |
451 | uint64_t offset; | 456 | uint64_t offset; |
@@ -472,8 +477,11 @@ reconstruct_cont (void *cls, | |||
472 | struct ReconstructContext *rcc = cls; | 477 | struct ReconstructContext *rcc = cls; |
473 | 478 | ||
474 | if (rcc->te != NULL) | 479 | if (rcc->te != NULL) |
475 | GNUNET_FS_tree_encoder_finish (rcc->te, NULL, NULL); | 480 | { |
481 | GNUNET_FS_tree_encoder_finish (rcc->te, NULL, NULL); | ||
482 | } | ||
476 | rcc->dc->reconstruct_failed = GNUNET_YES; | 483 | rcc->dc->reconstruct_failed = GNUNET_YES; |
484 | rcc->dc->rcc = NULL; | ||
477 | if (rcc->fh != NULL) | 485 | if (rcc->fh != NULL) |
478 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (rcc->fh)); | 486 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (rcc->fh)); |
479 | if ( (rcc->dc->th == NULL) && | 487 | if ( (rcc->dc->th == NULL) && |
@@ -508,6 +516,8 @@ get_next_block (void *cls, | |||
508 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 516 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
509 | { | 517 | { |
510 | struct ReconstructContext *rcc = cls; | 518 | struct ReconstructContext *rcc = cls; |
519 | |||
520 | rcc->task = GNUNET_SCHEDULER_NO_TASK; | ||
511 | GNUNET_FS_tree_encoder_next (rcc->te); | 521 | GNUNET_FS_tree_encoder_next (rcc->te); |
512 | } | 522 | } |
513 | 523 | ||
@@ -582,9 +592,8 @@ reconstruct_cb (void *cls, | |||
582 | GNUNET_free (rcc); | 592 | GNUNET_free (rcc); |
583 | return; | 593 | return; |
584 | } | 594 | } |
585 | GNUNET_SCHEDULER_add_continuation (&get_next_block, | 595 | rcc->task = GNUNET_SCHEDULER_add_now (&get_next_block, |
586 | rcc, | 596 | rcc); |
587 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
588 | } | 597 | } |
589 | 598 | ||
590 | 599 | ||
@@ -744,6 +753,7 @@ schedule_block_download (struct GNUNET_FS_DownloadContext *dc, | |||
744 | rcc->chk = *chk; | 753 | rcc->chk = *chk; |
745 | rcc->offset = off; | 754 | rcc->offset = off; |
746 | rcc->depth = depth; | 755 | rcc->depth = depth; |
756 | dc->rcc = rcc; | ||
747 | if ( (depth < dc->treedepth) && | 757 | if ( (depth < dc->treedepth) && |
748 | (dc->reconstruct_failed == GNUNET_NO) && | 758 | (dc->reconstruct_failed == GNUNET_NO) && |
749 | (fh != NULL) ) | 759 | (fh != NULL) ) |
@@ -1874,6 +1884,11 @@ GNUNET_FS_download_start_task_ (void *cls, | |||
1874 | : &dc->uri->data.loc.fi.chk, | 1884 | : &dc->uri->data.loc.fi.chk, |
1875 | 0, | 1885 | 0, |
1876 | 1 /* 0 == CHK, 1 == top */); | 1886 | 1 /* 0 == CHK, 1 == top */); |
1887 | GNUNET_FS_download_sync_ (dc); | ||
1888 | GNUNET_FS_download_start_downloading_ (dc); | ||
1889 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_START; | ||
1890 | pi.value.download.specifics.start.meta = dc->meta; | ||
1891 | GNUNET_FS_download_make_status_ (&pi, dc); | ||
1877 | } | 1892 | } |
1878 | 1893 | ||
1879 | 1894 | ||
@@ -1889,11 +1904,6 @@ GNUNET_FS_download_signal_suspend_ (void *cls) | |||
1889 | struct GNUNET_FS_DownloadContext *dc = cls; | 1904 | struct GNUNET_FS_DownloadContext *dc = cls; |
1890 | struct GNUNET_FS_ProgressInfo pi; | 1905 | struct GNUNET_FS_ProgressInfo pi; |
1891 | 1906 | ||
1892 | if (dc->start_task != GNUNET_SCHEDULER_NO_TASK) | ||
1893 | { | ||
1894 | GNUNET_SCHEDULER_cancel (dc->start_task); | ||
1895 | dc->start_task = GNUNET_SCHEDULER_NO_TASK; | ||
1896 | } | ||
1897 | if (dc->top != NULL) | 1907 | if (dc->top != NULL) |
1898 | GNUNET_FS_end_top (dc->h, dc->top); | 1908 | GNUNET_FS_end_top (dc->h, dc->top); |
1899 | while (NULL != dc->child_head) | 1909 | while (NULL != dc->child_head) |
@@ -1912,10 +1922,26 @@ GNUNET_FS_download_signal_suspend_ (void *cls) | |||
1912 | GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, | 1922 | GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, |
1913 | dc->parent->child_tail, | 1923 | dc->parent->child_tail, |
1914 | dc); | 1924 | dc); |
1915 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_SUSPEND; | ||
1916 | GNUNET_FS_download_make_status_ (&pi, dc); | ||
1917 | if (GNUNET_SCHEDULER_NO_TASK != dc->task) | 1925 | if (GNUNET_SCHEDULER_NO_TASK != dc->task) |
1918 | GNUNET_SCHEDULER_cancel (dc->task); | 1926 | GNUNET_SCHEDULER_cancel (dc->task); |
1927 | if (dc->start_task != GNUNET_SCHEDULER_NO_TASK) | ||
1928 | { | ||
1929 | GNUNET_SCHEDULER_cancel (dc->start_task); | ||
1930 | dc->start_task = GNUNET_SCHEDULER_NO_TASK; | ||
1931 | } | ||
1932 | else | ||
1933 | { | ||
1934 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_SUSPEND; | ||
1935 | GNUNET_FS_download_make_status_ (&pi, dc); | ||
1936 | } | ||
1937 | if (dc->rcc != NULL) | ||
1938 | { | ||
1939 | if (dc->rcc->task != GNUNET_SCHEDULER_NO_TASK) | ||
1940 | GNUNET_SCHEDULER_cancel (dc->rcc->task); | ||
1941 | if (dc->rcc->te != NULL) | ||
1942 | GNUNET_FS_tree_encoder_finish (dc->rcc->te, NULL, NULL); | ||
1943 | dc->rcc = NULL; | ||
1944 | } | ||
1919 | GNUNET_CONTAINER_multihashmap_iterate (dc->active, | 1945 | GNUNET_CONTAINER_multihashmap_iterate (dc->active, |
1920 | &free_entry, | 1946 | &free_entry, |
1921 | NULL); | 1947 | NULL); |
@@ -1972,7 +1998,6 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h, | |||
1972 | void *cctx, | 1998 | void *cctx, |
1973 | struct GNUNET_FS_DownloadContext *parent) | 1999 | struct GNUNET_FS_DownloadContext *parent) |
1974 | { | 2000 | { |
1975 | struct GNUNET_FS_ProgressInfo pi; | ||
1976 | struct GNUNET_FS_DownloadContext *dc; | 2001 | struct GNUNET_FS_DownloadContext *dc; |
1977 | 2002 | ||
1978 | GNUNET_assert (GNUNET_FS_uri_test_chk (uri) || | 2003 | GNUNET_assert (GNUNET_FS_uri_test_chk (uri) || |
@@ -2041,12 +2066,7 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h, | |||
2041 | &GNUNET_FS_download_signal_suspend_, | 2066 | &GNUNET_FS_download_signal_suspend_, |
2042 | dc); | 2067 | dc); |
2043 | } | 2068 | } |
2044 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_START; | ||
2045 | pi.value.download.specifics.start.meta = meta; | ||
2046 | GNUNET_FS_download_make_status_ (&pi, dc); | ||
2047 | dc->start_task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc); | 2069 | dc->start_task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc); |
2048 | GNUNET_FS_download_sync_ (dc); | ||
2049 | GNUNET_FS_download_start_downloading_ (dc); | ||
2050 | return dc; | 2070 | return dc; |
2051 | } | 2071 | } |
2052 | 2072 | ||
@@ -2096,7 +2116,6 @@ GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h, | |||
2096 | enum GNUNET_FS_DownloadOptions options, | 2116 | enum GNUNET_FS_DownloadOptions options, |
2097 | void *cctx) | 2117 | void *cctx) |
2098 | { | 2118 | { |
2099 | struct GNUNET_FS_ProgressInfo pi; | ||
2100 | struct GNUNET_FS_DownloadContext *dc; | 2119 | struct GNUNET_FS_DownloadContext *dc; |
2101 | 2120 | ||
2102 | if ( (sr == NULL) || | 2121 | if ( (sr == NULL) || |
@@ -2164,12 +2183,7 @@ GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h, | |||
2164 | "Download tree has depth %u\n", | 2183 | "Download tree has depth %u\n", |
2165 | dc->treedepth); | 2184 | dc->treedepth); |
2166 | #endif | 2185 | #endif |
2167 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_START; | ||
2168 | pi.value.download.specifics.start.meta = dc->meta; | ||
2169 | GNUNET_FS_download_make_status_ (&pi, dc); | ||
2170 | dc->start_task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc); | 2186 | dc->start_task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc); |
2171 | GNUNET_FS_download_sync_ (dc); | ||
2172 | GNUNET_FS_download_start_downloading_ (dc); | ||
2173 | return dc; | 2187 | return dc; |
2174 | } | 2188 | } |
2175 | 2189 | ||
@@ -2222,6 +2236,14 @@ GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, | |||
2222 | GNUNET_FS_dequeue_ (dc->job_queue); | 2236 | GNUNET_FS_dequeue_ (dc->job_queue); |
2223 | dc->job_queue = NULL; | 2237 | dc->job_queue = NULL; |
2224 | } | 2238 | } |
2239 | if (dc->rcc != NULL) | ||
2240 | { | ||
2241 | if (dc->rcc->task != GNUNET_SCHEDULER_NO_TASK) | ||
2242 | GNUNET_SCHEDULER_cancel (dc->rcc->task); | ||
2243 | if (dc->rcc->te != NULL) | ||
2244 | GNUNET_FS_tree_encoder_finish (dc->rcc->te, NULL, NULL); | ||
2245 | dc->rcc = NULL; | ||
2246 | } | ||
2225 | have_children = (NULL != dc->child_head) ? GNUNET_YES : GNUNET_NO; | 2247 | have_children = (NULL != dc->child_head) ? GNUNET_YES : GNUNET_NO; |
2226 | while (NULL != dc->child_head) | 2248 | while (NULL != dc->child_head) |
2227 | GNUNET_FS_download_stop (dc->child_head, | 2249 | GNUNET_FS_download_stop (dc->child_head, |
diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c index 549a2eeed..a06054f6d 100644 --- a/src/fs/test_fs_download.c +++ b/src/fs/test_fs_download.c | |||
@@ -213,7 +213,6 @@ progress_cb (void *cls, | |||
213 | NULL); | 213 | NULL); |
214 | break; | 214 | break; |
215 | case GNUNET_FS_STATUS_DOWNLOAD_START: | 215 | case GNUNET_FS_STATUS_DOWNLOAD_START: |
216 | GNUNET_assert (download == NULL); | ||
217 | GNUNET_assert (0 == strcmp ("download", event->value.download.cctx)); | 216 | GNUNET_assert (0 == strcmp ("download", event->value.download.cctx)); |
218 | GNUNET_assert (NULL == event->value.download.pctx); | 217 | GNUNET_assert (NULL == event->value.download.pctx); |
219 | GNUNET_assert (NULL != event->value.download.uri); | 218 | GNUNET_assert (NULL != event->value.download.uri); |
diff --git a/src/fs/test_fs_download_indexed.c b/src/fs/test_fs_download_indexed.c index 6e59f97cd..6d1465cd1 100644 --- a/src/fs/test_fs_download_indexed.c +++ b/src/fs/test_fs_download_indexed.c | |||
@@ -215,7 +215,6 @@ progress_cb (void *cls, | |||
215 | NULL); | 215 | NULL); |
216 | break; | 216 | break; |
217 | case GNUNET_FS_STATUS_DOWNLOAD_START: | 217 | case GNUNET_FS_STATUS_DOWNLOAD_START: |
218 | GNUNET_assert (download == NULL); | ||
219 | GNUNET_assert (0 == strcmp ("download", event->value.download.cctx)); | 218 | GNUNET_assert (0 == strcmp ("download", event->value.download.cctx)); |
220 | GNUNET_assert (NULL == event->value.download.pctx); | 219 | GNUNET_assert (NULL == event->value.download.pctx); |
221 | GNUNET_assert (NULL != event->value.download.uri); | 220 | GNUNET_assert (NULL != event->value.download.uri); |