aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-10-18 20:23:21 +0000
committerChristian Grothoff <christian@grothoff.org>2009-10-18 20:23:21 +0000
commit38d63ac3806899f5eb4d9ff9dca8581a72e3fb9a (patch)
treec22c8f5dd7ba72a8f84b2ed0456aa7d6427b36b0
parentc246b8bf6b1879c8ea584295e208928aec686dfe (diff)
downloadgnunet-38d63ac3806899f5eb4d9ff9dca8581a72e3fb9a.tar.gz
gnunet-38d63ac3806899f5eb4d9ff9dca8581a72e3fb9a.zip
more work on bugs and testing of fs service
-rw-r--r--src/fs/fs.h5
-rw-r--r--src/fs/fs_file_information.c45
-rw-r--r--src/fs/fs_publish.c13
-rw-r--r--src/fs/fs_tree.c1
-rw-r--r--src/fs/test_fs_download.c68
-rw-r--r--src/fs/test_fs_download_data.conf1
-rw-r--r--src/include/gnunet_fs_service.h1
7 files changed, 83 insertions, 51 deletions
diff --git a/src/fs/fs.h b/src/fs/fs.h
index a9fa712c6..f335888ef 100644
--- a/src/fs/fs.h
+++ b/src/fs/fs.h
@@ -552,6 +552,11 @@ struct GNUNET_FS_PublishContext
552 * for this upload. 552 * for this upload.
553 */ 553 */
554 int rid; 554 int rid;
555
556 /**
557 * Set to GNUNET_YES if all processing has completed.
558 */
559 int all_done;
555}; 560};
556 561
557 562
diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c
index 9bdc30262..6d6a83ffe 100644
--- a/src/fs/fs_file_information.c
+++ b/src/fs/fs_file_information.c
@@ -249,6 +249,7 @@ data_reader_copy(void *cls,
249 char **emsg) 249 char **emsg)
250{ 250{
251 char *data = cls; 251 char *data = cls;
252
252 if (max == 0) 253 if (max == 0)
253 { 254 {
254 GNUNET_free (data); 255 GNUNET_free (data);
@@ -343,6 +344,7 @@ GNUNET_FS_file_information_create_from_reader (void *client_info,
343 ret->data.file.reader = reader; 344 ret->data.file.reader = reader;
344 ret->data.file.reader_cls = reader_cls; 345 ret->data.file.reader_cls = reader_cls;
345 ret->data.file.do_index = do_index; 346 ret->data.file.do_index = do_index;
347 ret->data.file.file_size = length;
346 ret->anonymity = anonymity; 348 ret->anonymity = anonymity;
347 ret->priority = priority; 349 ret->priority = priority;
348 GNUNET_FS_file_information_sync (ret); 350 GNUNET_FS_file_information_sync (ret);
@@ -803,15 +805,16 @@ GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
803 GNUNET_FS_file_information_destroy (pos, cleaner, cleaner_cls); 805 GNUNET_FS_file_information_destroy (pos, cleaner, cleaner_cls);
804 } 806 }
805 /* clean up client-info */ 807 /* clean up client-info */
806 cleaner (cleaner_cls, 808 if (NULL != cleaner)
807 fi, 809 cleaner (cleaner_cls,
808 fi->data.dir.dir_size, 810 fi,
809 fi->meta, 811 fi->data.dir.dir_size,
810 &fi->keywords, 812 fi->meta,
811 &fi->anonymity, 813 &fi->keywords,
812 &fi->priority, 814 &fi->anonymity,
813 &fi->expirationTime, 815 &fi->priority,
814 &fi->client_info); 816 &fi->expirationTime,
817 &fi->client_info);
815 GNUNET_free_non_null (fi->data.dir.dir_data); 818 GNUNET_free_non_null (fi->data.dir.dir_data);
816 GNUNET_free (fi->data.dir.dirname); 819 GNUNET_free (fi->data.dir.dirname);
817 } 820 }
@@ -820,25 +823,27 @@ GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
820 /* call clean-up function of the reader */ 823 /* call clean-up function of the reader */
821 fi->data.file.reader (fi->data.file.reader_cls, 0, 0, NULL, NULL); 824 fi->data.file.reader (fi->data.file.reader_cls, 0, 0, NULL, NULL);
822 /* clean up client-info */ 825 /* clean up client-info */
823 cleaner (cleaner_cls, 826 if (NULL != cleaner)
824 fi, 827 cleaner (cleaner_cls,
825 fi->data.file.file_size, 828 fi,
826 fi->meta, 829 fi->data.file.file_size,
827 &fi->keywords, 830 fi->meta,
828 &fi->anonymity, 831 &fi->keywords,
829 &fi->priority, 832 &fi->anonymity,
830 &fi->expirationTime, 833 &fi->priority,
831 &fi->client_info); 834 &fi->expirationTime,
835 &fi->client_info);
832 } 836 }
833 GNUNET_free_non_null (fi->emsg); 837 GNUNET_free_non_null (fi->emsg);
834 /* clean up serialization */ 838 /* clean up serialization */
835 if (0 != UNLINK (fi->serialization)) 839 if ( (NULL != fi->serialization) &&
840 (0 != UNLINK (fi->serialization)) )
836 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 841 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
837 "unlink", 842 "unlink",
838 fi->serialization); 843 fi->serialization);
839 GNUNET_FS_uri_destroy (fi->keywords); 844 GNUNET_FS_uri_destroy (fi->keywords);
840 GNUNET_CONTAINER_meta_data_destroy (fi->meta); 845 GNUNET_CONTAINER_meta_data_destroy (fi->meta);
841 GNUNET_free (fi->serialization); 846 GNUNET_free_non_null (fi->serialization);
842 GNUNET_free (fi); 847 GNUNET_free (fi);
843} 848}
844 849
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c
index 3ccc3c97a..f8c76c36b 100644
--- a/src/fs/fs_publish.c
+++ b/src/fs/fs_publish.c
@@ -135,7 +135,8 @@ static void
135publish_cleanup (struct GNUNET_FS_PublishContext *sc) 135publish_cleanup (struct GNUNET_FS_PublishContext *sc)
136{ 136{
137 GNUNET_FS_file_information_destroy (sc->fi, NULL, NULL); 137 GNUNET_FS_file_information_destroy (sc->fi, NULL, NULL);
138 GNUNET_FS_namespace_delete (sc->namespace, GNUNET_NO); 138 if (sc->namespace != NULL)
139 GNUNET_FS_namespace_delete (sc->namespace, GNUNET_NO);
139 GNUNET_free_non_null (sc->nid); 140 GNUNET_free_non_null (sc->nid);
140 GNUNET_free_non_null (sc->nuid); 141 GNUNET_free_non_null (sc->nuid);
141 GNUNET_DATASTORE_disconnect (sc->dsh, GNUNET_NO); 142 GNUNET_DATASTORE_disconnect (sc->dsh, GNUNET_NO);
@@ -181,7 +182,6 @@ ds_put_cont (void *cls,
181 pcc->p->client_info 182 pcc->p->client_info
182 = pcc->sc->h->upcb (pcc->sc->h->upcb_cls, 183 = pcc->sc->h->upcb (pcc->sc->h->upcb_cls,
183 &pi); 184 &pi);
184 return;
185 } 185 }
186 GNUNET_FS_file_information_sync (pcc->p); 186 GNUNET_FS_file_information_sync (pcc->p);
187 if (NULL != pcc->cont) 187 if (NULL != pcc->cont)
@@ -272,6 +272,7 @@ publish_sblocks_cont (void *cls,
272 } 272 }
273 // FIXME: release the datastore reserve here! 273 // FIXME: release the datastore reserve here!
274 signal_publish_completion (sc->fi, sc); 274 signal_publish_completion (sc->fi, sc);
275 sc->all_done = GNUNET_YES;
275} 276}
276 277
277 278
@@ -392,6 +393,9 @@ block_reader (void *cls,
392 { 393 {
393 pt_size = GNUNET_MIN(max, 394 pt_size = GNUNET_MIN(max,
394 p->data.file.file_size - offset); 395 p->data.file.file_size - offset);
396 if (pt_size == 0)
397 return 0; /* calling reader with pt_size==0
398 might free buf, so don't! */
395 if (pt_size != 399 if (pt_size !=
396 p->data.file.reader (p->data.file.reader_cls, 400 p->data.file.reader (p->data.file.reader_cls,
397 offset, 401 offset,
@@ -498,6 +502,7 @@ block_proc (void *cls,
498 dpc_cls = GNUNET_malloc(sizeof(struct PutContCtx)); 502 dpc_cls = GNUNET_malloc(sizeof(struct PutContCtx));
499 dpc_cls->cont = &do_upload; 503 dpc_cls->cont = &do_upload;
500 dpc_cls->cont_cls = sc; 504 dpc_cls->cont_cls = sc;
505 dpc_cls->sc = sc;
501 dpc_cls->p = p; 506 dpc_cls->p = p;
502 if ( (p->is_directory) && 507 if ( (p->is_directory) &&
503 (p->data.file.do_index) && 508 (p->data.file.do_index) &&
@@ -833,6 +838,7 @@ do_upload (void *cls,
833 = sc->h->upcb (sc->h->upcb_cls, 838 = sc->h->upcb (sc->h->upcb_cls,
834 &pi); 839 &pi);
835 } 840 }
841 sc->all_done = GNUNET_YES;
836 return; 842 return;
837 } 843 }
838 /* handle completion */ 844 /* handle completion */
@@ -1034,6 +1040,7 @@ fip_signal_stop(void *cls,
1034 * Stop an upload. Will abort incomplete uploads (but 1040 * Stop an upload. Will abort incomplete uploads (but
1035 * not remove blocks that have already been publishd) or 1041 * not remove blocks that have already been publishd) or
1036 * simply clean up the state for completed uploads. 1042 * simply clean up the state for completed uploads.
1043 * Must NOT be called from within the event callback!
1037 * 1044 *
1038 * @param sc context for the upload to stop 1045 * @param sc context for the upload to stop
1039 */ 1046 */
@@ -1042,6 +1049,8 @@ GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *sc)
1042{ 1049{
1043 if (GNUNET_SCHEDULER_NO_TASK != sc->upload_task) 1050 if (GNUNET_SCHEDULER_NO_TASK != sc->upload_task)
1044 GNUNET_SCHEDULER_cancel (sc->h->sched, sc->upload_task); 1051 GNUNET_SCHEDULER_cancel (sc->h->sched, sc->upload_task);
1052 else
1053 GNUNET_assert (sc->all_done == GNUNET_YES);
1045 // FIXME: remove from persistence DB (?) --- think more about 1054 // FIXME: remove from persistence DB (?) --- think more about
1046 // shutdown / persistent-resume APIs!!! 1055 // shutdown / persistent-resume APIs!!!
1047 GNUNET_FS_file_information_inspect (sc->fi, 1056 GNUNET_FS_file_information_inspect (sc->fi,
diff --git a/src/fs/fs_tree.c b/src/fs/fs_tree.c
index d151eb086..b409080db 100644
--- a/src/fs/fs_tree.c
+++ b/src/fs/fs_tree.c
@@ -171,6 +171,7 @@ GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h,
171{ 171{
172 struct GNUNET_FS_TreeEncoder *te; 172 struct GNUNET_FS_TreeEncoder *te;
173 173
174 GNUNET_assert (size > 0);
174 te = GNUNET_malloc (sizeof (struct GNUNET_FS_TreeEncoder)); 175 te = GNUNET_malloc (sizeof (struct GNUNET_FS_TreeEncoder));
175 te->h = h; 176 te->h = h;
176 te->size = size; 177 te->size = size;
diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c
index dbdc12fec..ffb90d678 100644
--- a/src/fs/test_fs_download.c
+++ b/src/fs/test_fs_download.c
@@ -69,6 +69,24 @@ static struct GNUNET_FS_PublishContext *publish;
69static char *fn; 69static char *fn;
70 70
71 71
72static void
73abort_download_task (void *cls,
74 const struct GNUNET_SCHEDULER_TaskContext *tc)
75{
76 GNUNET_FS_download_stop (download, GNUNET_YES);
77 download = NULL;
78}
79
80
81static void
82abort_publish_task (void *cls,
83 const struct GNUNET_SCHEDULER_TaskContext *tc)
84{
85 GNUNET_FS_publish_stop (publish);
86 publish = NULL;
87}
88
89
72static void * 90static void *
73progress_cb (void *cls, 91progress_cb (void *cls,
74 const struct GNUNET_FS_ProgressInfo *event) 92 const struct GNUNET_FS_ProgressInfo *event)
@@ -76,14 +94,8 @@ progress_cb (void *cls,
76 94
77 switch (event->status) 95 switch (event->status)
78 { 96 {
79 case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND:
80 GNUNET_break (0);
81 break;
82 case GNUNET_FS_STATUS_DOWNLOAD_RESUME:
83 GNUNET_break (0);
84 break;
85 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 97 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
86#if DEBUG_VERBOSE > 1 98#if DEBUG_VERBOSE
87 printf ("Publish is progressing (%llu/%llu)...\n", 99 printf ("Publish is progressing (%llu/%llu)...\n",
88 (unsigned long long) event->value.publish.completed, 100 (unsigned long long) event->value.publish.completed,
89 (unsigned long long) event->value.publish.size); 101 (unsigned long long) event->value.publish.size);
@@ -115,35 +127,39 @@ progress_cb (void *cls,
115 download = NULL; 127 download = NULL;
116 break; 128 break;
117 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: 129 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
118#if DEBUG_VERBOSE > 1 130#if DEBUG_VERBOSE
119 printf ("Download is progressing (%llu/%llu)...\n", 131 printf ("Download is progressing (%llu/%llu)...\n",
120 (unsigned long long) event->value.download.completed, 132 (unsigned long long) event->value.download.completed,
121 (unsigned long long) event->value.download.size); 133 (unsigned long long) event->value.download.size);
122#endif 134#endif
123 break; 135 break;
124 case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
125 GNUNET_break (0);
126 break;
127 case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
128 GNUNET_break (0);
129 break;
130 case GNUNET_FS_STATUS_UNINDEX_ERROR:
131 GNUNET_break (0);
132 case GNUNET_FS_STATUS_PUBLISH_ERROR: 136 case GNUNET_FS_STATUS_PUBLISH_ERROR:
137 fprintf (stderr,
138 "Error publishing file: %s\n",
139 event->value.publish.specifics.error.message);
133 GNUNET_break (0); 140 GNUNET_break (0);
134 case GNUNET_FS_STATUS_DOWNLOAD_ERROR: 141 GNUNET_SCHEDULER_add_continuation (sched,
135 GNUNET_break (0); 142 GNUNET_NO,
136 break; 143 &abort_publish_task,
137 case GNUNET_FS_STATUS_UNINDEX_SUSPEND: 144 NULL,
138 GNUNET_break (0); 145 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
139 break; 146 break;
140 case GNUNET_FS_STATUS_PUBLISH_SUSPEND: 147 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
141 GNUNET_break (0); 148 fprintf (stderr,
149 "Error downloading file: %s\n",
150 event->value.download.specifics.error.message);
151 GNUNET_SCHEDULER_add_continuation (sched,
152 GNUNET_NO,
153 &abort_download_task,
154 NULL,
155 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
142 break; 156 break;
143 case GNUNET_FS_STATUS_PUBLISH_START: 157 case GNUNET_FS_STATUS_PUBLISH_START:
144 /* FIXME: add checks here... */ 158 /* FIXME: add checks here... */
159 break;
145 case GNUNET_FS_STATUS_PUBLISH_STOPPED: 160 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
146 /* FIXME: add checks here... */ 161 /* FIXME: add checks here... */
162 break;
147 case GNUNET_FS_STATUS_DOWNLOAD_START: 163 case GNUNET_FS_STATUS_DOWNLOAD_START:
148 /* FIXME: add checks here... */ 164 /* FIXME: add checks here... */
149 break; 165 break;
@@ -152,12 +168,6 @@ progress_cb (void *cls,
152 GNUNET_FS_stop (fs); 168 GNUNET_FS_stop (fs);
153 fs = NULL; 169 fs = NULL;
154 break; 170 break;
155 case GNUNET_FS_STATUS_UNINDEX_START:
156 GNUNET_break (0);
157 break;
158 case GNUNET_FS_STATUS_UNINDEX_STOPPED:
159 GNUNET_break (0);
160 break;
161 default: 171 default:
162 printf ("Unexpected event: %d\n", 172 printf ("Unexpected event: %d\n",
163 event->status); 173 event->status);
diff --git a/src/fs/test_fs_download_data.conf b/src/fs/test_fs_download_data.conf
index 6cc9c23a8..ac90b3203 100644
--- a/src/fs/test_fs_download_data.conf
+++ b/src/fs/test_fs_download_data.conf
@@ -16,6 +16,7 @@ PLUGINS =
16[arm] 16[arm]
17PORT = 42466 17PORT = 42466
18HOSTNAME = localhost 18HOSTNAME = localhost
19DEFAULTSERVICES = resolver datastore transport core fs
19 20
20[statistics] 21[statistics]
21PORT = 42467 22PORT = 42467
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h
index 21ffe299a..7c15358e8 100644
--- a/src/include/gnunet_fs_service.h
+++ b/src/include/gnunet_fs_service.h
@@ -1902,6 +1902,7 @@ GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1902 * Stop an upload. Will abort incomplete uploads (but 1902 * Stop an upload. Will abort incomplete uploads (but
1903 * not remove blocks that have already been publishd) or 1903 * not remove blocks that have already been publishd) or
1904 * simply clean up the state for completed uploads. 1904 * simply clean up the state for completed uploads.
1905 * Must NOT be called from within the event callback!
1905 * 1906 *
1906 * @param sc context for the upload to stop 1907 * @param sc context for the upload to stop
1907 */ 1908 */