diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-06-23 09:08:06 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-06-23 09:08:06 +0000 |
commit | 15bec1f951708a370e2c6cc2ffd48286ca68015b (patch) | |
tree | bd15e673e26c7f05da5c33370e4d1c131aba6a3e /src/fs/fs_publish.c | |
parent | fdc3349eb0fb3ad4aa0554deb84ebd94f55793cd (diff) | |
download | gnunet-15bec1f951708a370e2c6cc2ffd48286ca68015b.tar.gz gnunet-15bec1f951708a370e2c6cc2ffd48286ca68015b.zip |
-fix URI test to handle new encoder, print both SKS and CHK URIs when publishing to namespace
Diffstat (limited to 'src/fs/fs_publish.c')
-rw-r--r-- | src/fs/fs_publish.c | 102 |
1 files changed, 65 insertions, 37 deletions
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c index 2075c5f2b..c9e2b0e6a 100644 --- a/src/fs/fs_publish.c +++ b/src/fs/fs_publish.c | |||
@@ -17,7 +17,6 @@ | |||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | |||
21 | /** | 20 | /** |
22 | * @file fs/fs_publish.c | 21 | * @file fs/fs_publish.c |
23 | * @brief publish a file or directory in GNUnet | 22 | * @brief publish a file or directory in GNUnet |
@@ -25,7 +24,6 @@ | |||
25 | * @author Krista Bennett | 24 | * @author Krista Bennett |
26 | * @author Christian Grothoff | 25 | * @author Christian Grothoff |
27 | */ | 26 | */ |
28 | |||
29 | #include "platform.h" | 27 | #include "platform.h" |
30 | #include "gnunet_constants.h" | 28 | #include "gnunet_constants.h" |
31 | #include "gnunet_signatures.h" | 29 | #include "gnunet_signatures.h" |
@@ -57,9 +55,10 @@ GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi, | |||
57 | pi->value.publish.pctx = (NULL == p->dir) ? NULL : p->dir->client_info; | 55 | pi->value.publish.pctx = (NULL == p->dir) ? NULL : p->dir->client_info; |
58 | pi->value.publish.filename = p->filename; | 56 | pi->value.publish.filename = p->filename; |
59 | pi->value.publish.size = | 57 | pi->value.publish.size = |
60 | (p->is_directory == GNUNET_YES) ? p->data.dir.dir_size : p->data.file.file_size; | 58 | (GNUNET_YES == p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size; |
61 | pi->value.publish.eta = | 59 | pi->value.publish.eta = |
62 | GNUNET_TIME_calculate_eta (p->start_time, offset, pi->value.publish.size); | 60 | GNUNET_TIME_calculate_eta (p->start_time, offset, |
61 | pi->value.publish.size); | ||
63 | pi->value.publish.completed = offset; | 62 | pi->value.publish.completed = offset; |
64 | pi->value.publish.duration = | 63 | pi->value.publish.duration = |
65 | GNUNET_TIME_absolute_get_duration (p->start_time); | 64 | GNUNET_TIME_absolute_get_duration (p->start_time); |
@@ -77,8 +76,9 @@ GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi, | |||
77 | static void | 76 | static void |
78 | publish_cleanup (struct GNUNET_FS_PublishContext *pc) | 77 | publish_cleanup (struct GNUNET_FS_PublishContext *pc) |
79 | { | 78 | { |
80 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up publish context (done!)\n"); | 79 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
81 | if (pc->fhc != NULL) | 80 | "Cleaning up publish context (done!)\n"); |
81 | if (NULL != pc->fhc) | ||
82 | { | 82 | { |
83 | GNUNET_CRYPTO_hash_file_cancel (pc->fhc); | 83 | GNUNET_CRYPTO_hash_file_cancel (pc->fhc); |
84 | pc->fhc = NULL; | 84 | pc->fhc = NULL; |
@@ -87,12 +87,12 @@ publish_cleanup (struct GNUNET_FS_PublishContext *pc) | |||
87 | GNUNET_free_non_null (pc->nid); | 87 | GNUNET_free_non_null (pc->nid); |
88 | GNUNET_free_non_null (pc->nuid); | 88 | GNUNET_free_non_null (pc->nuid); |
89 | GNUNET_free_non_null (pc->serialization); | 89 | GNUNET_free_non_null (pc->serialization); |
90 | if (pc->dsh != NULL) | 90 | if (NULL != pc->dsh) |
91 | { | 91 | { |
92 | GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO); | 92 | GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO); |
93 | pc->dsh = NULL; | 93 | pc->dsh = NULL; |
94 | } | 94 | } |
95 | if (pc->client != NULL) | 95 | if (NULL != pc->client) |
96 | { | 96 | { |
97 | GNUNET_CLIENT_disconnect (pc->client); | 97 | GNUNET_CLIENT_disconnect (pc->client); |
98 | pc->client = NULL; | 98 | pc->client = NULL; |
@@ -122,7 +122,9 @@ ds_put_cont (void *cls, int success, | |||
122 | pc->qre = NULL; | 122 | pc->qre = NULL; |
123 | if (GNUNET_SYSERR == success) | 123 | if (GNUNET_SYSERR == success) |
124 | { | 124 | { |
125 | GNUNET_asprintf (&pc->fi_pos->emsg, _("Publishing failed: %s"), msg); | 125 | GNUNET_asprintf (&pc->fi_pos->emsg, |
126 | _("Publishing failed: %s"), | ||
127 | msg); | ||
126 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; | 128 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; |
127 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; | 129 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; |
128 | pi.value.publish.specifics.error.message = pc->fi_pos->emsg; | 130 | pi.value.publish.specifics.error.message = pc->fi_pos->emsg; |
@@ -160,10 +162,10 @@ signal_publish_completion (struct GNUNET_FS_FileInformation *p, | |||
160 | pi.status = GNUNET_FS_STATUS_PUBLISH_COMPLETED; | 162 | pi.status = GNUNET_FS_STATUS_PUBLISH_COMPLETED; |
161 | pi.value.publish.eta = GNUNET_TIME_UNIT_ZERO; | 163 | pi.value.publish.eta = GNUNET_TIME_UNIT_ZERO; |
162 | pi.value.publish.specifics.completed.chk_uri = p->chk_uri; | 164 | pi.value.publish.specifics.completed.chk_uri = p->chk_uri; |
165 | pi.value.publish.specifics.completed.sks_uri = p->sks_uri; | ||
163 | p->client_info = | 166 | p->client_info = |
164 | GNUNET_FS_publish_make_status_ (&pi, pc, p, | 167 | GNUNET_FS_publish_make_status_ (&pi, pc, p, |
165 | GNUNET_ntohll (p->chk_uri->data. | 168 | p->data.file.file_size); |
166 | chk.file_length)); | ||
167 | } | 169 | } |
168 | 170 | ||
169 | 171 | ||
@@ -178,7 +180,8 @@ signal_publish_completion (struct GNUNET_FS_FileInformation *p, | |||
178 | */ | 180 | */ |
179 | static void | 181 | static void |
180 | signal_publish_error (struct GNUNET_FS_FileInformation *p, | 182 | signal_publish_error (struct GNUNET_FS_FileInformation *p, |
181 | struct GNUNET_FS_PublishContext *pc, const char *emsg) | 183 | struct GNUNET_FS_PublishContext *pc, |
184 | const char *emsg) | ||
182 | { | 185 | { |
183 | struct GNUNET_FS_ProgressInfo pi; | 186 | struct GNUNET_FS_ProgressInfo pi; |
184 | 187 | ||
@@ -225,12 +228,13 @@ finish_release_reserve (void *cls, int success, | |||
225 | * We've finished publishing the SBlock as part of a larger upload. | 228 | * We've finished publishing the SBlock as part of a larger upload. |
226 | * Check the result and complete the larger upload. | 229 | * Check the result and complete the larger upload. |
227 | * | 230 | * |
228 | * @param cls the "struct GNUNET_FS_PublishContext*" of the larger upload | 231 | * @param cls the `struct GNUNET_FS_PublishContext *` of the larger upload |
229 | * @param uri URI of the published SBlock | 232 | * @param uri URI of the published SBlock |
230 | * @param emsg NULL on success, otherwise error message | 233 | * @param emsg NULL on success, otherwise error message |
231 | */ | 234 | */ |
232 | static void | 235 | static void |
233 | publish_sblocks_cont (void *cls, const struct GNUNET_FS_Uri *uri, | 236 | publish_sblocks_cont (void *cls, |
237 | const struct GNUNET_FS_Uri *uri, | ||
234 | const char *emsg) | 238 | const char *emsg) |
235 | { | 239 | { |
236 | struct GNUNET_FS_PublishContext *pc = cls; | 240 | struct GNUNET_FS_PublishContext *pc = cls; |
@@ -242,6 +246,11 @@ publish_sblocks_cont (void *cls, const struct GNUNET_FS_Uri *uri, | |||
242 | GNUNET_FS_publish_sync_ (pc); | 246 | GNUNET_FS_publish_sync_ (pc); |
243 | return; | 247 | return; |
244 | } | 248 | } |
249 | if (NULL != uri) | ||
250 | { | ||
251 | /* sks publication, remember namespace URI */ | ||
252 | pc->fi->sks_uri = GNUNET_FS_uri_dup (uri); | ||
253 | } | ||
245 | GNUNET_assert (pc->qre == NULL); | 254 | GNUNET_assert (pc->qre == NULL); |
246 | if ((pc->dsh != NULL) && (pc->rid != 0)) | 255 | if ((pc->dsh != NULL) && (pc->rid != 0)) |
247 | { | 256 | { |
@@ -291,7 +300,8 @@ publish_sblock (struct GNUNET_FS_PublishContext *pc) | |||
291 | * @param emsg NULL on success, otherwise error message | 300 | * @param emsg NULL on success, otherwise error message |
292 | */ | 301 | */ |
293 | static void | 302 | static void |
294 | publish_kblocks_cont (void *cls, const struct GNUNET_FS_Uri *uri, | 303 | publish_kblocks_cont (void *cls, |
304 | const struct GNUNET_FS_Uri *uri, | ||
295 | const char *emsg) | 305 | const char *emsg) |
296 | { | 306 | { |
297 | struct GNUNET_FS_PublishContext *pc = cls; | 307 | struct GNUNET_FS_PublishContext *pc = cls; |
@@ -309,7 +319,9 @@ publish_kblocks_cont (void *cls, const struct GNUNET_FS_Uri *uri, | |||
309 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); | 319 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); |
310 | pc->upload_task = | 320 | pc->upload_task = |
311 | GNUNET_SCHEDULER_add_with_priority | 321 | GNUNET_SCHEDULER_add_with_priority |
312 | (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc); | 322 | (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
323 | &GNUNET_FS_publish_main_, | ||
324 | pc); | ||
313 | return; | 325 | return; |
314 | } | 326 | } |
315 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 327 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -343,7 +355,11 @@ publish_kblocks_cont (void *cls, const struct GNUNET_FS_Uri *uri, | |||
343 | * @return number of bytes copied to buf, 0 on error | 355 | * @return number of bytes copied to buf, 0 on error |
344 | */ | 356 | */ |
345 | static size_t | 357 | static size_t |
346 | block_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg) | 358 | block_reader (void *cls, |
359 | uint64_t offset, | ||
360 | size_t max, | ||
361 | void *buf, | ||
362 | char **emsg) | ||
347 | { | 363 | { |
348 | struct GNUNET_FS_PublishContext *pc = cls; | 364 | struct GNUNET_FS_PublishContext *pc = cls; |
349 | struct GNUNET_FS_FileInformation *p; | 365 | struct GNUNET_FS_FileInformation *p; |
@@ -884,9 +900,9 @@ GNUNET_FS_publish_main_ (void *cls, | |||
884 | if (0 == p->bo.anonymity_level) | 900 | if (0 == p->bo.anonymity_level) |
885 | { | 901 | { |
886 | /* zero anonymity, box CHK URI in LOC URI */ | 902 | /* zero anonymity, box CHK URI in LOC URI */ |
887 | loc = | 903 | loc = GNUNET_FS_uri_loc_create (p->chk_uri, |
888 | GNUNET_FS_uri_loc_create (p->chk_uri, pc->h->cfg, | 904 | pc->h->cfg, |
889 | p->bo.expiration_time); | 905 | p->bo.expiration_time); |
890 | GNUNET_FS_uri_destroy (p->chk_uri); | 906 | GNUNET_FS_uri_destroy (p->chk_uri); |
891 | p->chk_uri = loc; | 907 | p->chk_uri = loc; |
892 | GNUNET_FS_file_information_sync_ (p); | 908 | GNUNET_FS_file_information_sync_ (p); |
@@ -895,8 +911,13 @@ GNUNET_FS_publish_main_ (void *cls, | |||
895 | /* upload of "p" complete, publish KBlocks! */ | 911 | /* upload of "p" complete, publish KBlocks! */ |
896 | if (NULL != p->keywords) | 912 | if (NULL != p->keywords) |
897 | { | 913 | { |
898 | pc->ksk_pc = GNUNET_FS_publish_ksk (pc->h, p->keywords, p->meta, p->chk_uri, &p->bo, | 914 | pc->ksk_pc = GNUNET_FS_publish_ksk (pc->h, |
899 | pc->options, &publish_kblocks_cont, pc); | 915 | p->keywords, |
916 | p->meta, | ||
917 | p->chk_uri, | ||
918 | &p->bo, | ||
919 | pc->options, | ||
920 | &publish_kblocks_cont, pc); | ||
900 | } | 921 | } |
901 | else | 922 | else |
902 | { | 923 | { |
@@ -910,9 +931,9 @@ GNUNET_FS_publish_main_ (void *cls, | |||
910 | { | 931 | { |
911 | p->data.file.do_index = GNUNET_NO; | 932 | p->data.file.do_index = GNUNET_NO; |
912 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 933 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
913 | _ | 934 | _("Can not index file `%s': %s. Will try to insert instead.\n"), |
914 | ("Can not index file `%s': %s. Will try to insert instead.\n"), | 935 | "<no-name>", |
915 | "<no-name>", _("needs to be an actual file")); | 936 | _("needs to be an actual file")); |
916 | GNUNET_FS_file_information_sync_ (p); | 937 | GNUNET_FS_file_information_sync_ (p); |
917 | publish_content (pc); | 938 | publish_content (pc); |
918 | return; | 939 | return; |
@@ -1239,14 +1260,15 @@ GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h, | |||
1239 | { | 1260 | { |
1240 | GNUNET_assert (NULL == ret->qre); | 1261 | GNUNET_assert (NULL == ret->qre); |
1241 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1262 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1242 | _ | 1263 | _("Reserving space for %u entries and %llu bytes for publication\n"), |
1243 | ("Reserving space for %u entries and %llu bytes for publication\n"), | ||
1244 | (unsigned int) ret->reserve_entries, | 1264 | (unsigned int) ret->reserve_entries, |
1245 | (unsigned long long) ret->reserve_space); | 1265 | (unsigned long long) ret->reserve_space); |
1246 | ret->qre = | 1266 | ret->qre = |
1247 | GNUNET_DATASTORE_reserve (ret->dsh, ret->reserve_space, | 1267 | GNUNET_DATASTORE_reserve (ret->dsh, ret->reserve_space, |
1248 | ret->reserve_entries, UINT_MAX, UINT_MAX, | 1268 | ret->reserve_entries, |
1249 | GNUNET_TIME_UNIT_FOREVER_REL, &finish_reserve, | 1269 | UINT_MAX, UINT_MAX, |
1270 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1271 | &finish_reserve, | ||
1250 | ret); | 1272 | ret); |
1251 | } | 1273 | } |
1252 | else | 1274 | else |
@@ -1275,9 +1297,12 @@ GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h, | |||
1275 | * @return #GNUNET_OK to continue (always) | 1297 | * @return #GNUNET_OK to continue (always) |
1276 | */ | 1298 | */ |
1277 | static int | 1299 | static int |
1278 | fip_signal_stop (void *cls, struct GNUNET_FS_FileInformation *fi, | 1300 | fip_signal_stop (void *cls, |
1279 | uint64_t length, struct GNUNET_CONTAINER_MetaData *meta, | 1301 | struct GNUNET_FS_FileInformation *fi, |
1280 | struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo, | 1302 | uint64_t length, |
1303 | struct GNUNET_CONTAINER_MetaData *meta, | ||
1304 | struct GNUNET_FS_Uri **uri, | ||
1305 | struct GNUNET_FS_BlockOptions *bo, | ||
1281 | int *do_index, void **client_info) | 1306 | int *do_index, void **client_info) |
1282 | { | 1307 | { |
1283 | struct GNUNET_FS_PublishContext *pc = cls; | 1308 | struct GNUNET_FS_PublishContext *pc = cls; |
@@ -1324,7 +1349,8 @@ GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc) | |||
1324 | struct GNUNET_FS_ProgressInfo pi; | 1349 | struct GNUNET_FS_ProgressInfo pi; |
1325 | uint64_t off; | 1350 | uint64_t off; |
1326 | 1351 | ||
1327 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publish stop called\n"); | 1352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1353 | "Publish stop called\n"); | ||
1328 | GNUNET_FS_end_top (pc->h, pc->top); | 1354 | GNUNET_FS_end_top (pc->h, pc->top); |
1329 | if (NULL != pc->ksk_pc) | 1355 | if (NULL != pc->ksk_pc) |
1330 | { | 1356 | { |
@@ -1344,16 +1370,19 @@ GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc) | |||
1344 | pc->skip_next_fi_callback = GNUNET_YES; | 1370 | pc->skip_next_fi_callback = GNUNET_YES; |
1345 | GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_stop, pc); | 1371 | GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_stop, pc); |
1346 | 1372 | ||
1347 | if (pc->fi->serialization != NULL) | 1373 | if (NULL != pc->fi->serialization) |
1348 | { | 1374 | { |
1349 | GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO, | 1375 | GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO, |
1350 | pc->fi->serialization); | 1376 | pc->fi->serialization); |
1351 | GNUNET_free (pc->fi->serialization); | 1377 | GNUNET_free (pc->fi->serialization); |
1352 | pc->fi->serialization = NULL; | 1378 | pc->fi->serialization = NULL; |
1353 | } | 1379 | } |
1354 | off = (pc->fi->chk_uri == NULL) ? 0 : GNUNET_ntohll (pc->fi->chk_uri->data.chk.file_length); | 1380 | if (NULL == pc->fi->chk_uri) |
1381 | off = 0; /* won't be completed anymore */ | ||
1382 | else | ||
1383 | off = pc->fi->is_directory ? pc->fi->data.dir.contents_completed : pc->fi->data.file.file_size; /* we were done */ | ||
1355 | 1384 | ||
1356 | if (pc->serialization != NULL) | 1385 | if (NULL != pc->serialization) |
1357 | { | 1386 | { |
1358 | GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, | 1387 | GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, |
1359 | pc->serialization); | 1388 | pc->serialization); |
@@ -1371,5 +1400,4 @@ GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc) | |||
1371 | } | 1400 | } |
1372 | 1401 | ||
1373 | 1402 | ||
1374 | |||
1375 | /* end of fs_publish.c */ | 1403 | /* end of fs_publish.c */ |