diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-05-04 11:14:25 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-05-04 11:14:25 +0000 |
commit | 6276a671135e01b119f198d0ae3092bfeb14903e (patch) | |
tree | be184253d3c14e2b9ea6b2f4dd335b4c935d68b1 /src/fs/fs_publish.c | |
parent | 6aefa4ac85435c8e7afb86e4e6daef77da69709a (diff) | |
download | gnunet-6276a671135e01b119f198d0ae3092bfeb14903e.tar.gz gnunet-6276a671135e01b119f198d0ae3092bfeb14903e.zip |
calling sync, cleaning up files
Diffstat (limited to 'src/fs/fs_publish.c')
-rw-r--r-- | src/fs/fs_publish.c | 72 |
1 files changed, 47 insertions, 25 deletions
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c index 0c4ebba7b..8d2dacb14 100644 --- a/src/fs/fs_publish.c +++ b/src/fs/fs_publish.c | |||
@@ -21,13 +21,12 @@ | |||
21 | /** | 21 | /** |
22 | * @file fs/fs_publish.c | 22 | * @file fs/fs_publish.c |
23 | * @brief publish a file or directory in GNUnet | 23 | * @brief publish a file or directory in GNUnet |
24 | * @see http://gnunet.org/encoding.php3 | 24 | * @see http://gnunet.org/encoding |
25 | * @author Krista Bennett | 25 | * @author Krista Bennett |
26 | * @author Christian Grothoff | 26 | * @author Christian Grothoff |
27 | * | 27 | * |
28 | * TODO: | 28 | * TODO: |
29 | * - indexing cleanup: unindex on failure (can wait) | 29 | * - indexing cleanup: unindex on failure (can wait) |
30 | * - persistence support (can wait) | ||
31 | * - datastore reservation support (optimization) | 30 | * - datastore reservation support (optimization) |
32 | * - location URIs (publish with anonymity-level zero) | 31 | * - location URIs (publish with anonymity-level zero) |
33 | */ | 32 | */ |
@@ -191,7 +190,7 @@ signal_publish_completion (struct GNUNET_FS_FileInformation *p, | |||
191 | pi.value.publish.eta = GNUNET_TIME_UNIT_ZERO; | 190 | pi.value.publish.eta = GNUNET_TIME_UNIT_ZERO; |
192 | pi.value.publish.specifics.completed.chk_uri = p->chk_uri; | 191 | pi.value.publish.specifics.completed.chk_uri = p->chk_uri; |
193 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, sc, p, | 192 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, sc, p, |
194 | GNUNET_ntohll (p->chk_uri->data.chk.file_length)); | 193 | GNUNET_ntohll (p->chk_uri->data.chk.file_length)); |
195 | } | 194 | } |
196 | 195 | ||
197 | 196 | ||
@@ -232,17 +231,19 @@ publish_sblocks_cont (void *cls, | |||
232 | const struct GNUNET_FS_Uri *uri, | 231 | const struct GNUNET_FS_Uri *uri, |
233 | const char *emsg) | 232 | const char *emsg) |
234 | { | 233 | { |
235 | struct GNUNET_FS_PublishContext *sc = cls; | 234 | struct GNUNET_FS_PublishContext *pc = cls; |
236 | if (NULL != emsg) | 235 | if (NULL != emsg) |
237 | { | 236 | { |
238 | signal_publish_error (sc->fi, | 237 | signal_publish_error (pc->fi, |
239 | sc, | 238 | pc, |
240 | emsg); | 239 | emsg); |
240 | GNUNET_FS_publish_sync_ (pc); | ||
241 | return; | 241 | return; |
242 | } | 242 | } |
243 | // FIXME: release the datastore reserve here! | 243 | // FIXME: release the datastore reserve here! |
244 | signal_publish_completion (sc->fi, sc); | 244 | signal_publish_completion (pc->fi, pc); |
245 | sc->all_done = GNUNET_YES; | 245 | pc->all_done = GNUNET_YES; |
246 | GNUNET_FS_publish_sync_ (pc); | ||
246 | } | 247 | } |
247 | 248 | ||
248 | 249 | ||
@@ -287,31 +288,34 @@ publish_kblocks_cont (void *cls, | |||
287 | const struct GNUNET_FS_Uri *uri, | 288 | const struct GNUNET_FS_Uri *uri, |
288 | const char *emsg) | 289 | const char *emsg) |
289 | { | 290 | { |
290 | struct GNUNET_FS_PublishContext *sc = cls; | 291 | struct GNUNET_FS_PublishContext *pc = cls; |
291 | struct GNUNET_FS_FileInformation *p = sc->fi_pos; | 292 | struct GNUNET_FS_FileInformation *p = pc->fi_pos; |
292 | 293 | ||
293 | if (NULL != emsg) | 294 | if (NULL != emsg) |
294 | { | 295 | { |
295 | signal_publish_error (p, sc, emsg); | 296 | signal_publish_error (p, pc, emsg); |
296 | sc->upload_task | 297 | GNUNET_FS_file_information_sync_ (p); |
297 | = GNUNET_SCHEDULER_add_with_priority (sc->h->sched, | 298 | GNUNET_FS_publish_sync_ (pc); |
299 | pc->upload_task | ||
300 | = GNUNET_SCHEDULER_add_with_priority (pc->h->sched, | ||
298 | GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 301 | GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
299 | &GNUNET_FS_publish_main_, | 302 | &GNUNET_FS_publish_main_, |
300 | sc); | 303 | pc); |
301 | return; | 304 | return; |
302 | } | 305 | } |
303 | if (NULL != p->dir) | 306 | if (NULL != p->dir) |
304 | signal_publish_completion (p, sc); | 307 | signal_publish_completion (p, pc); |
305 | /* move on to next file */ | 308 | /* move on to next file */ |
306 | if (NULL != p->next) | 309 | if (NULL != p->next) |
307 | sc->fi_pos = p->next; | 310 | pc->fi_pos = p->next; |
308 | else | 311 | else |
309 | sc->fi_pos = p->dir; | 312 | pc->fi_pos = p->dir; |
310 | sc->upload_task | 313 | GNUNET_FS_publish_sync_ (pc); |
311 | = GNUNET_SCHEDULER_add_with_priority (sc->h->sched, | 314 | pc->upload_task |
315 | = GNUNET_SCHEDULER_add_with_priority (pc->h->sched, | ||
312 | GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 316 | GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
313 | &GNUNET_FS_publish_main_, | 317 | &GNUNET_FS_publish_main_, |
314 | sc); | 318 | pc); |
315 | } | 319 | } |
316 | 320 | ||
317 | 321 | ||
@@ -597,6 +601,7 @@ publish_content (struct GNUNET_FS_PublishContext *sc) | |||
597 | GNUNET_FS_directory_builder_finish (db, | 601 | GNUNET_FS_directory_builder_finish (db, |
598 | &p->data.dir.dir_size, | 602 | &p->data.dir.dir_size, |
599 | &p->data.dir.dir_data); | 603 | &p->data.dir.dir_data); |
604 | GNUNET_FS_file_information_sync_ (p); | ||
600 | } | 605 | } |
601 | size = (p->is_directory) | 606 | size = (p->is_directory) |
602 | ? p->data.dir.dir_size | 607 | ? p->data.dir.dir_size |
@@ -640,6 +645,7 @@ process_index_start_response (void *cls, | |||
640 | p->filename, | 645 | p->filename, |
641 | _("timeout on index-start request to `fs' service")); | 646 | _("timeout on index-start request to `fs' service")); |
642 | p->data.file.do_index = GNUNET_NO; | 647 | p->data.file.do_index = GNUNET_NO; |
648 | GNUNET_FS_file_information_sync_ (p); | ||
643 | publish_content (sc); | 649 | publish_content (sc); |
644 | return; | 650 | return; |
645 | } | 651 | } |
@@ -655,11 +661,13 @@ process_index_start_response (void *cls, | |||
655 | p->filename, | 661 | p->filename, |
656 | gettext (emsg)); | 662 | gettext (emsg)); |
657 | p->data.file.do_index = GNUNET_NO; | 663 | p->data.file.do_index = GNUNET_NO; |
664 | GNUNET_FS_file_information_sync_ (p); | ||
658 | publish_content (sc); | 665 | publish_content (sc); |
659 | return; | 666 | return; |
660 | } | 667 | } |
661 | p->data.file.index_start_confirmed = GNUNET_YES; | 668 | p->data.file.index_start_confirmed = GNUNET_YES; |
662 | /* success! continue with indexing */ | 669 | /* success! continue with indexing */ |
670 | GNUNET_FS_file_information_sync_ (p); | ||
663 | publish_content (sc); | 671 | publish_content (sc); |
664 | } | 672 | } |
665 | 673 | ||
@@ -693,6 +701,7 @@ hash_for_index_cb (void *cls, | |||
693 | p->filename, | 701 | p->filename, |
694 | _("failed to compute hash")); | 702 | _("failed to compute hash")); |
695 | p->data.file.do_index = GNUNET_NO; | 703 | p->data.file.do_index = GNUNET_NO; |
704 | GNUNET_FS_file_information_sync_ (p); | ||
696 | publish_content (sc); | 705 | publish_content (sc); |
697 | return; | 706 | return; |
698 | } | 707 | } |
@@ -711,6 +720,7 @@ hash_for_index_cb (void *cls, | |||
711 | _("filename too long")); | 720 | _("filename too long")); |
712 | GNUNET_free (fn); | 721 | GNUNET_free (fn); |
713 | p->data.file.do_index = GNUNET_NO; | 722 | p->data.file.do_index = GNUNET_NO; |
723 | GNUNET_FS_file_information_sync_ (p); | ||
714 | publish_content (sc); | 724 | publish_content (sc); |
715 | return; | 725 | return; |
716 | } | 726 | } |
@@ -734,8 +744,12 @@ hash_for_index_cb (void *cls, | |||
734 | GNUNET_free (fn); | 744 | GNUNET_free (fn); |
735 | return; | 745 | return; |
736 | } | 746 | } |
737 | p->data.file.file_id = *res; | 747 | if (p->data.file.have_hash != GNUNET_YES) |
738 | p->data.file.have_hash = GNUNET_YES; | 748 | { |
749 | p->data.file.file_id = *res; | ||
750 | p->data.file.have_hash = GNUNET_YES; | ||
751 | GNUNET_FS_file_information_sync_ (p); | ||
752 | } | ||
739 | ism = GNUNET_malloc (sizeof(struct IndexStartMessage) + | 753 | ism = GNUNET_malloc (sizeof(struct IndexStartMessage) + |
740 | slen); | 754 | slen); |
741 | ism->header.size = htons(sizeof(struct IndexStartMessage) + | 755 | ism->header.size = htons(sizeof(struct IndexStartMessage) + |
@@ -793,6 +807,7 @@ GNUNET_FS_publish_main_ (void *cls, | |||
793 | { | 807 | { |
794 | /* upload of entire hierarchy complete, | 808 | /* upload of entire hierarchy complete, |
795 | publish namespace entries */ | 809 | publish namespace entries */ |
810 | GNUNET_FS_publish_sync_ (sc); | ||
796 | publish_sblock (sc); | 811 | publish_sblock (sc); |
797 | return; | 812 | return; |
798 | } | 813 | } |
@@ -804,6 +819,7 @@ GNUNET_FS_publish_main_ (void *cls, | |||
804 | { | 819 | { |
805 | p = p->data.dir.entries; | 820 | p = p->data.dir.entries; |
806 | sc->fi_pos = p; | 821 | sc->fi_pos = p; |
822 | GNUNET_FS_publish_sync_ (sc); | ||
807 | } | 823 | } |
808 | /* abort on error */ | 824 | /* abort on error */ |
809 | if (NULL != p->emsg) | 825 | if (NULL != p->emsg) |
@@ -835,11 +851,13 @@ GNUNET_FS_publish_main_ (void *cls, | |||
835 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, sc, p, 0); | 851 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, sc, p, 0); |
836 | } | 852 | } |
837 | sc->all_done = GNUNET_YES; | 853 | sc->all_done = GNUNET_YES; |
854 | GNUNET_FS_publish_sync_ (sc); | ||
838 | return; | 855 | return; |
839 | } | 856 | } |
840 | /* handle completion */ | 857 | /* handle completion */ |
841 | if (NULL != p->chk_uri) | 858 | if (NULL != p->chk_uri) |
842 | { | 859 | { |
860 | GNUNET_FS_publish_sync_ (sc); | ||
843 | /* upload of "p" complete, publish KBlocks! */ | 861 | /* upload of "p" complete, publish KBlocks! */ |
844 | if (p->keywords != NULL) | 862 | if (p->keywords != NULL) |
845 | { | 863 | { |
@@ -872,12 +890,15 @@ GNUNET_FS_publish_main_ (void *cls, | |||
872 | _("Can not index file `%s': %s. Will try to insert instead.\n"), | 890 | _("Can not index file `%s': %s. Will try to insert instead.\n"), |
873 | "<no-name>", | 891 | "<no-name>", |
874 | _("needs to be an actual file")); | 892 | _("needs to be an actual file")); |
893 | GNUNET_FS_file_information_sync_ (p); | ||
875 | publish_content (sc); | 894 | publish_content (sc); |
876 | return; | 895 | return; |
877 | } | 896 | } |
878 | if (p->data.file.have_hash) | 897 | if (p->data.file.have_hash) |
879 | hash_for_index_cb (sc, | 898 | { |
880 | &p->data.file.file_id); | 899 | hash_for_index_cb (sc, |
900 | &p->data.file.file_id); | ||
901 | } | ||
881 | else | 902 | else |
882 | { | 903 | { |
883 | p->start_time = GNUNET_TIME_absolute_get (); | 904 | p->start_time = GNUNET_TIME_absolute_get (); |
@@ -925,6 +946,7 @@ fip_signal_start(void *cls, | |||
925 | 946 | ||
926 | pi.status = GNUNET_FS_STATUS_PUBLISH_START; | 947 | pi.status = GNUNET_FS_STATUS_PUBLISH_START; |
927 | *client_info = GNUNET_FS_publish_make_status_ (&pi, sc, fi, 0); | 948 | *client_info = GNUNET_FS_publish_make_status_ (&pi, sc, fi, 0); |
949 | GNUNET_FS_file_information_sync_ (fi); | ||
928 | return GNUNET_OK; | 950 | return GNUNET_OK; |
929 | } | 951 | } |
930 | 952 | ||
@@ -962,7 +984,7 @@ fip_signal_suspend(void *cls, | |||
962 | GNUNET_free_non_null (fi->serialization); | 984 | GNUNET_free_non_null (fi->serialization); |
963 | fi->serialization = NULL; | 985 | fi->serialization = NULL; |
964 | off = (fi->chk_uri == NULL) ? 0 : length; | 986 | off = (fi->chk_uri == NULL) ? 0 : length; |
965 | pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED; | 987 | pi.status = GNUNET_FS_STATUS_PUBLISH_SUSPEND; |
966 | GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, sc, fi, off)); | 988 | GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, sc, fi, off)); |
967 | *client_info = NULL; | 989 | *client_info = NULL; |
968 | return GNUNET_OK; | 990 | return GNUNET_OK; |