aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_publish.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a /src/fs/fs_publish.c
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/fs/fs_publish.c')
-rw-r--r--src/fs/fs_publish.c297
1 files changed, 119 insertions, 178 deletions
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c
index 87161501b..746f4f099 100644
--- a/src/fs/fs_publish.c
+++ b/src/fs/fs_publish.c
@@ -58,11 +58,10 @@ GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
58 pi->value.publish.cctx = p->client_info; 58 pi->value.publish.cctx = p->client_info;
59 pi->value.publish.pctx = (NULL == p->dir) ? NULL : p->dir->client_info; 59 pi->value.publish.pctx = (NULL == p->dir) ? NULL : p->dir->client_info;
60 pi->value.publish.filename = p->filename; 60 pi->value.publish.filename = p->filename;
61 pi->value.publish.size 61 pi->value.publish.size =
62 = (p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size; 62 (p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size;
63 pi->value.publish.eta 63 pi->value.publish.eta =
64 = GNUNET_TIME_calculate_eta (p->start_time, 64 GNUNET_TIME_calculate_eta (p->start_time, offset, pi->value.publish.size);
65 offset, pi->value.publish.size);
66 pi->value.publish.completed = offset; 65 pi->value.publish.completed = offset;
67 pi->value.publish.duration = 66 pi->value.publish.duration =
68 GNUNET_TIME_absolute_get_duration (p->start_time); 67 GNUNET_TIME_absolute_get_duration (p->start_time);
@@ -132,8 +131,8 @@ ds_put_cont (void *cls, int success, const char *msg)
132 if (GNUNET_SYSERR == pc->in_network_wait) 131 if (GNUNET_SYSERR == pc->in_network_wait)
133 { 132 {
134 /* we were aborted in the meantime, finish shutdown! */ 133 /* we were aborted in the meantime, finish shutdown! */
135 GNUNET_SCHEDULER_add_continuation (&publish_cleanup, 134 GNUNET_SCHEDULER_add_continuation (&publish_cleanup, pc,
136 pc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 135 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
137 return; 136 return;
138 } 137 }
139 GNUNET_assert (GNUNET_YES == pc->in_network_wait); 138 GNUNET_assert (GNUNET_YES == pc->in_network_wait);
@@ -155,8 +154,7 @@ ds_put_cont (void *cls, int success, const char *msg)
155 } 154 }
156 } 155 }
157 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 156 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
158 pc->upload_task 157 pc->upload_task =
159 =
160 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 158 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
161 &GNUNET_FS_publish_main_, pc); 159 &GNUNET_FS_publish_main_, pc);
162} 160}
@@ -179,10 +177,10 @@ signal_publish_completion (struct GNUNET_FS_FileInformation *p,
179 pi.status = GNUNET_FS_STATUS_PUBLISH_COMPLETED; 177 pi.status = GNUNET_FS_STATUS_PUBLISH_COMPLETED;
180 pi.value.publish.eta = GNUNET_TIME_UNIT_ZERO; 178 pi.value.publish.eta = GNUNET_TIME_UNIT_ZERO;
181 pi.value.publish.specifics.completed.chk_uri = p->chk_uri; 179 pi.value.publish.specifics.completed.chk_uri = p->chk_uri;
182 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 180 p->client_info =
183 GNUNET_ntohll (p-> 181 GNUNET_FS_publish_make_status_ (&pi, pc, p,
184 chk_uri->data. 182 GNUNET_ntohll (p->chk_uri->data.chk.
185 chk.file_length)); 183 file_length));
186} 184}
187 185
188 186
@@ -206,8 +204,8 @@ signal_publish_error (struct GNUNET_FS_FileInformation *p,
206 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; 204 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
207 pi.value.publish.specifics.error.message = emsg; 205 pi.value.publish.specifics.error.message = emsg;
208 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0); 206 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
209 if ((p->is_directory == GNUNET_NO) && 207 if ((p->is_directory == GNUNET_NO) && (p->filename != NULL) &&
210 (p->filename != NULL) && (p->data.file.do_index == GNUNET_YES)) 208 (p->data.file.do_index == GNUNET_YES))
211 { 209 {
212 /* run unindex to clean up */ 210 /* run unindex to clean up */
213 GNUNET_FS_unindex_start (pc->h, p->filename, NULL); 211 GNUNET_FS_unindex_start (pc->h, p->filename, NULL);
@@ -247,8 +245,8 @@ finish_release_reserve (void *cls, int success, const char *msg)
247 * @param emsg NULL on success, otherwise error message 245 * @param emsg NULL on success, otherwise error message
248 */ 246 */
249static void 247static void
250publish_sblocks_cont (void *cls, 248publish_sblocks_cont (void *cls, const struct GNUNET_FS_Uri *uri,
251 const struct GNUNET_FS_Uri *uri, const char *emsg) 249 const char *emsg)
252{ 250{
253 struct GNUNET_FS_PublishContext *pc = cls; 251 struct GNUNET_FS_PublishContext *pc = cls;
254 252
@@ -261,12 +259,10 @@ publish_sblocks_cont (void *cls,
261 GNUNET_assert (pc->qre == NULL); 259 GNUNET_assert (pc->qre == NULL);
262 if ((pc->dsh != NULL) && (pc->rid != 0)) 260 if ((pc->dsh != NULL) && (pc->rid != 0))
263 { 261 {
264 pc->qre = GNUNET_DATASTORE_release_reserve (pc->dsh, 262 pc->qre =
265 pc->rid, 263 GNUNET_DATASTORE_release_reserve (pc->dsh, pc->rid, UINT_MAX, UINT_MAX,
266 UINT_MAX, 264 GNUNET_TIME_UNIT_FOREVER_REL,
267 UINT_MAX, 265 &finish_release_reserve, pc);
268 GNUNET_TIME_UNIT_FOREVER_REL,
269 &finish_release_reserve, pc);
270 } 266 }
271 else 267 else
272 { 268 {
@@ -285,13 +281,9 @@ static void
285publish_sblock (struct GNUNET_FS_PublishContext *pc) 281publish_sblock (struct GNUNET_FS_PublishContext *pc)
286{ 282{
287 if (NULL != pc->namespace) 283 if (NULL != pc->namespace)
288 GNUNET_FS_publish_sks (pc->h, 284 GNUNET_FS_publish_sks (pc->h, pc->namespace, pc->nid, pc->nuid,
289 pc->namespace, 285 pc->fi->meta, pc->fi->chk_uri, &pc->fi->bo,
290 pc->nid, 286 pc->options, &publish_sblocks_cont, pc);
291 pc->nuid,
292 pc->fi->meta,
293 pc->fi->chk_uri,
294 &pc->fi->bo, pc->options, &publish_sblocks_cont, pc);
295 else 287 else
296 publish_sblocks_cont (pc, NULL, NULL); 288 publish_sblocks_cont (pc, NULL, NULL);
297} 289}
@@ -307,8 +299,8 @@ publish_sblock (struct GNUNET_FS_PublishContext *pc)
307 * @param emsg NULL on success, otherwise error message 299 * @param emsg NULL on success, otherwise error message
308 */ 300 */
309static void 301static void
310publish_kblocks_cont (void *cls, 302publish_kblocks_cont (void *cls, const struct GNUNET_FS_Uri *uri,
311 const struct GNUNET_FS_Uri *uri, const char *emsg) 303 const char *emsg)
312{ 304{
313 struct GNUNET_FS_PublishContext *pc = cls; 305 struct GNUNET_FS_PublishContext *pc = cls;
314 struct GNUNET_FS_FileInformation *p = pc->fi_pos; 306 struct GNUNET_FS_FileInformation *p = pc->fi_pos;
@@ -316,15 +308,14 @@ publish_kblocks_cont (void *cls,
316 if (NULL != emsg) 308 if (NULL != emsg)
317 { 309 {
318#if DEBUG_PUBLISH 310#if DEBUG_PUBLISH
319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error uploading KSK blocks: %s\n",
320 "Error uploading KSK blocks: %s\n", emsg); 312 emsg);
321#endif 313#endif
322 signal_publish_error (p, pc, emsg); 314 signal_publish_error (p, pc, emsg);
323 GNUNET_FS_file_information_sync_ (p); 315 GNUNET_FS_file_information_sync_ (p);
324 GNUNET_FS_publish_sync_ (pc); 316 GNUNET_FS_publish_sync_ (pc);
325 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 317 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
326 pc->upload_task 318 pc->upload_task =
327 =
328 GNUNET_SCHEDULER_add_with_priority 319 GNUNET_SCHEDULER_add_with_priority
329 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc); 320 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc);
330 return; 321 return;
@@ -342,8 +333,7 @@ publish_kblocks_cont (void *cls,
342 pc->fi_pos = p->dir; 333 pc->fi_pos = p->dir;
343 GNUNET_FS_publish_sync_ (pc); 334 GNUNET_FS_publish_sync_ (pc);
344 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 335 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
345 pc->upload_task 336 pc->upload_task =
346 =
347 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 337 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
348 &GNUNET_FS_publish_main_, pc); 338 &GNUNET_FS_publish_main_, pc);
349} 339}
@@ -384,8 +374,8 @@ block_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
384 return 0; /* calling reader with pt_size==0 374 return 0; /* calling reader with pt_size==0
385 * might free buf, so don't! */ 375 * might free buf, so don't! */
386 if (pt_size != 376 if (pt_size !=
387 p->data.file.reader (p->data.file.reader_cls, 377 p->data.file.reader (p->data.file.reader_cls, offset, pt_size, buf,
388 offset, pt_size, buf, emsg)) 378 emsg))
389 return 0; 379 return 0;
390 } 380 }
391 return pt_size; 381 return pt_size;
@@ -438,8 +428,7 @@ encode_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
438 428
439 /* continue with main */ 429 /* continue with main */
440 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 430 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
441 pc->upload_task 431 pc->upload_task =
442 =
443 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 432 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
444 &GNUNET_FS_publish_main_, pc); 433 &GNUNET_FS_publish_main_, pc);
445} 434}
@@ -460,11 +449,9 @@ encode_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
460 * @param block_size size of block (in bytes) 449 * @param block_size size of block (in bytes)
461 */ 450 */
462static void 451static void
463block_proc (void *cls, 452block_proc (void *cls, const struct ContentHashKey *chk, uint64_t offset,
464 const struct ContentHashKey *chk, 453 unsigned int depth, enum GNUNET_BLOCK_Type type, const void *block,
465 uint64_t offset, 454 uint16_t block_size)
466 unsigned int depth,
467 enum GNUNET_BLOCK_Type type, const void *block, uint16_t block_size)
468{ 455{
469 struct GNUNET_FS_PublishContext *pc = cls; 456 struct GNUNET_FS_PublishContext *pc = cls;
470 struct GNUNET_FS_FileInformation *p; 457 struct GNUNET_FS_FileInformation *p;
@@ -477,8 +464,7 @@ block_proc (void *cls,
477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Waiting for datastore connection\n"); 464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Waiting for datastore connection\n");
478#endif 465#endif
479 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 466 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
480 pc->upload_task 467 pc->upload_task =
481 =
482 GNUNET_SCHEDULER_add_with_priority 468 GNUNET_SCHEDULER_add_with_priority
483 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc); 469 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc);
484 return; 470 return;
@@ -486,54 +472,42 @@ block_proc (void *cls,
486 472
487 GNUNET_assert (GNUNET_NO == pc->in_network_wait); 473 GNUNET_assert (GNUNET_NO == pc->in_network_wait);
488 pc->in_network_wait = GNUNET_YES; 474 pc->in_network_wait = GNUNET_YES;
489 if ((!p->is_directory) && 475 if ((!p->is_directory) && (GNUNET_YES == p->data.file.do_index) &&
490 (GNUNET_YES == p->data.file.do_index) &&
491 (type == GNUNET_BLOCK_TYPE_FS_DBLOCK)) 476 (type == GNUNET_BLOCK_TYPE_FS_DBLOCK))
492 { 477 {
493#if DEBUG_PUBLISH 478#if DEBUG_PUBLISH
494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 479 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
495 "Indexing block `%s' for offset %llu with index size %u\n", 480 "Indexing block `%s' for offset %llu with index size %u\n",
496 GNUNET_h2s (&chk->query), 481 GNUNET_h2s (&chk->query), (unsigned long long) offset,
497 (unsigned long long) offset, sizeof (struct OnDemandBlock)); 482 sizeof (struct OnDemandBlock));
498#endif 483#endif
499 odb.offset = GNUNET_htonll (offset); 484 odb.offset = GNUNET_htonll (offset);
500 odb.file_id = p->data.file.file_id; 485 odb.file_id = p->data.file.file_id;
501 GNUNET_assert (pc->qre == NULL); 486 GNUNET_assert (pc->qre == NULL);
502 pc->qre = GNUNET_DATASTORE_put (pc->dsh, 487 pc->qre =
503 (p->is_directory) ? 0 : pc->rid, 488 GNUNET_DATASTORE_put (pc->dsh, (p->is_directory) ? 0 : pc->rid,
504 &chk->query, 489 &chk->query, sizeof (struct OnDemandBlock), &odb,
505 sizeof (struct OnDemandBlock), 490 GNUNET_BLOCK_TYPE_FS_ONDEMAND,
506 &odb, 491 p->bo.content_priority, p->bo.anonymity_level,
507 GNUNET_BLOCK_TYPE_FS_ONDEMAND, 492 p->bo.replication_level, p->bo.expiration_time,
508 p->bo.content_priority, 493 -2, 1, GNUNET_CONSTANTS_SERVICE_TIMEOUT,
509 p->bo.anonymity_level, 494 &ds_put_cont, pc);
510 p->bo.replication_level,
511 p->bo.expiration_time,
512 -2, 1,
513 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
514 &ds_put_cont, pc);
515 return; 495 return;
516 } 496 }
517#if DEBUG_PUBLISH 497#if DEBUG_PUBLISH
518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 498 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
519 "Publishing block `%s' for offset %llu with size %u\n", 499 "Publishing block `%s' for offset %llu with size %u\n",
520 GNUNET_h2s (&chk->query), 500 GNUNET_h2s (&chk->query), (unsigned long long) offset,
521 (unsigned long long) offset, (unsigned int) block_size); 501 (unsigned int) block_size);
522#endif 502#endif
523 GNUNET_assert (pc->qre == NULL); 503 GNUNET_assert (pc->qre == NULL);
524 pc->qre = GNUNET_DATASTORE_put (pc->dsh, 504 pc->qre =
525 (p->is_directory) ? 0 : pc->rid, 505 GNUNET_DATASTORE_put (pc->dsh, (p->is_directory) ? 0 : pc->rid,
526 &chk->query, 506 &chk->query, block_size, block, type,
527 block_size, 507 p->bo.content_priority, p->bo.anonymity_level,
528 block, 508 p->bo.replication_level, p->bo.expiration_time, -2,
529 type, 509 1, GNUNET_CONSTANTS_SERVICE_TIMEOUT, &ds_put_cont,
530 p->bo.content_priority, 510 pc);
531 p->bo.anonymity_level,
532 p->bo.replication_level,
533 p->bo.expiration_time,
534 -2, 1,
535 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
536 &ds_put_cont, pc);
537} 511}
538 512
539 513
@@ -548,9 +522,8 @@ block_proc (void *cls,
548 * @param depth depth of the block in the tree, 0 for DBLOCK 522 * @param depth depth of the block in the tree, 0 for DBLOCK
549 */ 523 */
550static void 524static void
551progress_proc (void *cls, 525progress_proc (void *cls, uint64_t offset, const void *pt_block, size_t pt_size,
552 uint64_t offset, 526 unsigned int depth)
553 const void *pt_block, size_t pt_size, unsigned int depth)
554{ 527{
555 struct GNUNET_FS_PublishContext *pc = cls; 528 struct GNUNET_FS_PublishContext *pc = cls;
556 struct GNUNET_FS_FileInformation *p; 529 struct GNUNET_FS_FileInformation *p;
@@ -610,10 +583,9 @@ publish_content (struct GNUNET_FS_PublishContext *pc)
610 raw_data = GNUNET_malloc (dirpos->data.file.file_size); 583 raw_data = GNUNET_malloc (dirpos->data.file.file_size);
611 emsg = NULL; 584 emsg = NULL;
612 if (dirpos->data.file.file_size != 585 if (dirpos->data.file.file_size !=
613 dirpos->data.file.reader (dirpos->data.file.reader_cls, 586 dirpos->data.file.reader (dirpos->data.file.reader_cls, 0,
614 0, 587 dirpos->data.file.file_size, raw_data,
615 dirpos->data.file.file_size, 588 &emsg))
616 raw_data, &emsg))
617 { 589 {
618 GNUNET_free_non_null (emsg); 590 GNUNET_free_non_null (emsg);
619 GNUNET_free (raw_data); 591 GNUNET_free (raw_data);
@@ -621,17 +593,15 @@ publish_content (struct GNUNET_FS_PublishContext *pc)
621 } 593 }
622 } 594 }
623 } 595 }
624 GNUNET_FS_directory_builder_add (db, 596 GNUNET_FS_directory_builder_add (db, dirpos->chk_uri, dirpos->meta,
625 dirpos->chk_uri, 597 raw_data);
626 dirpos->meta, raw_data);
627 GNUNET_free_non_null (raw_data); 598 GNUNET_free_non_null (raw_data);
628 dirpos = dirpos->next; 599 dirpos = dirpos->next;
629 } 600 }
630 GNUNET_free_non_null (p->data.dir.dir_data); 601 GNUNET_free_non_null (p->data.dir.dir_data);
631 p->data.dir.dir_data = NULL; 602 p->data.dir.dir_data = NULL;
632 p->data.dir.dir_size = 0; 603 p->data.dir.dir_size = 0;
633 GNUNET_FS_directory_builder_finish (db, 604 GNUNET_FS_directory_builder_finish (db, &p->data.dir.dir_size,
634 &p->data.dir.dir_size,
635 &p->data.dir.dir_data); 605 &p->data.dir.dir_data);
636 GNUNET_FS_file_information_sync_ (p); 606 GNUNET_FS_file_information_sync_ (p);
637 } 607 }
@@ -639,12 +609,10 @@ publish_content (struct GNUNET_FS_PublishContext *pc)
639#if DEBUG_PUBLISH 609#if DEBUG_PUBLISH
640 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating tree encoder\n"); 610 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating tree encoder\n");
641#endif 611#endif
642 p->te = GNUNET_FS_tree_encoder_create (pc->h, 612 p->te =
643 size, 613 GNUNET_FS_tree_encoder_create (pc->h, size, pc, &block_reader,
644 pc, 614 &block_proc, &progress_proc,
645 &block_reader, 615 &encode_cont);
646 &block_proc,
647 &progress_proc, &encode_cont);
648 616
649 } 617 }
650#if DEBUG_PUBLISH 618#if DEBUG_PUBLISH
@@ -761,8 +729,7 @@ hash_for_index_cb (void *cls, const GNUNET_HashCode * res)
761 return; 729 return;
762 } 730 }
763#if DEBUG_PUBLISH 731#if DEBUG_PUBLISH
764 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 732 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hash of indexed file `%s' is `%s'\n",
765 "Hash of indexed file `%s' is `%s'\n",
766 p->filename, GNUNET_h2s (res)); 733 p->filename, GNUNET_h2s (res));
767#endif 734#endif
768 if (0 != (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) 735 if (0 != (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
@@ -813,8 +780,7 @@ hash_for_index_cb (void *cls, const GNUNET_HashCode * res)
813 GNUNET_free (fn); 780 GNUNET_free (fn);
814 pc->client = client; 781 pc->client = client;
815 GNUNET_break (GNUNET_YES == 782 GNUNET_break (GNUNET_YES ==
816 GNUNET_CLIENT_transmit_and_get_response (client, 783 GNUNET_CLIENT_transmit_and_get_response (client, &ism->header,
817 &ism->header,
818 GNUNET_TIME_UNIT_FOREVER_REL, 784 GNUNET_TIME_UNIT_FOREVER_REL,
819 GNUNET_YES, 785 GNUNET_YES,
820 &process_index_start_response, 786 &process_index_start_response,
@@ -854,9 +820,8 @@ GNUNET_FS_publish_main_ (void *cls,
854 return; 820 return;
855 } 821 }
856 /* find starting position */ 822 /* find starting position */
857 while ((p->is_directory) && 823 while ((p->is_directory) && (NULL != p->data.dir.entries) && (NULL == p->emsg)
858 (NULL != p->data.dir.entries) && 824 && (NULL == p->data.dir.entries->chk_uri))
859 (NULL == p->emsg) && (NULL == p->data.dir.entries->chk_uri))
860 { 825 {
861 p = p->data.dir.entries; 826 p = p->data.dir.entries;
862 pc->fi_pos = p; 827 pc->fi_pos = p;
@@ -877,8 +842,8 @@ GNUNET_FS_publish_main_ (void *cls,
877 p = p->dir; 842 p = p->dir;
878 if (fn != NULL) 843 if (fn != NULL)
879 { 844 {
880 GNUNET_asprintf (&p->emsg, 845 GNUNET_asprintf (&p->emsg, _("Recursive upload failed at `%s': %s"), fn,
881 _("Recursive upload failed at `%s': %s"), fn, p->emsg); 846 p->emsg);
882 GNUNET_free (fn); 847 GNUNET_free (fn);
883 } 848 }
884 else 849 else
@@ -904,8 +869,9 @@ GNUNET_FS_publish_main_ (void *cls,
904 if (0 == p->bo.anonymity_level) 869 if (0 == p->bo.anonymity_level)
905 { 870 {
906 /* zero anonymity, box CHK URI in LOC URI */ 871 /* zero anonymity, box CHK URI in LOC URI */
907 loc = GNUNET_FS_uri_loc_create (p->chk_uri, 872 loc =
908 pc->h->cfg, p->bo.expiration_time); 873 GNUNET_FS_uri_loc_create (p->chk_uri, pc->h->cfg,
874 p->bo.expiration_time);
909 GNUNET_FS_uri_destroy (p->chk_uri); 875 GNUNET_FS_uri_destroy (p->chk_uri);
910 p->chk_uri = loc; 876 p->chk_uri = loc;
911 } 877 }
@@ -913,11 +879,8 @@ GNUNET_FS_publish_main_ (void *cls,
913 /* upload of "p" complete, publish KBlocks! */ 879 /* upload of "p" complete, publish KBlocks! */
914 if (p->keywords != NULL) 880 if (p->keywords != NULL)
915 { 881 {
916 GNUNET_FS_publish_ksk (pc->h, 882 GNUNET_FS_publish_ksk (pc->h, p->keywords, p->meta, p->chk_uri, &p->bo,
917 p->keywords, 883 pc->options, &publish_kblocks_cont, pc);
918 p->meta,
919 p->chk_uri,
920 &p->bo, pc->options, &publish_kblocks_cont, pc);
921 } 884 }
922 else 885 else
923 { 886 {
@@ -945,10 +908,9 @@ GNUNET_FS_publish_main_ (void *cls,
945 else 908 else
946 { 909 {
947 p->start_time = GNUNET_TIME_absolute_get (); 910 p->start_time = GNUNET_TIME_absolute_get ();
948 pc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, 911 pc->fhc =
949 p->filename, 912 GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, p->filename,
950 HASHING_BLOCKSIZE, 913 HASHING_BLOCKSIZE, &hash_for_index_cb, pc);
951 &hash_for_index_cb, pc);
952 } 914 }
953 return; 915 return;
954 } 916 }
@@ -971,12 +933,9 @@ GNUNET_FS_publish_main_ (void *cls,
971 * @return GNUNET_OK to continue (always) 933 * @return GNUNET_OK to continue (always)
972 */ 934 */
973static int 935static int
974fip_signal_start (void *cls, 936fip_signal_start (void *cls, struct GNUNET_FS_FileInformation *fi,
975 struct GNUNET_FS_FileInformation *fi, 937 uint64_t length, struct GNUNET_CONTAINER_MetaData *meta,
976 uint64_t length, 938 struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo,
977 struct GNUNET_CONTAINER_MetaData *meta,
978 struct GNUNET_FS_Uri **uri,
979 struct GNUNET_FS_BlockOptions *bo,
980 int *do_index, void **client_info) 939 int *do_index, void **client_info)
981{ 940{
982 struct GNUNET_FS_PublishContext *pc = cls; 941 struct GNUNET_FS_PublishContext *pc = cls;
@@ -1040,13 +999,11 @@ fip_signal_start (void *cls,
1040 * @return GNUNET_OK to continue (always) 999 * @return GNUNET_OK to continue (always)
1041 */ 1000 */
1042static int 1001static int
1043fip_signal_suspend (void *cls, 1002fip_signal_suspend (void *cls, struct GNUNET_FS_FileInformation *fi,
1044 struct GNUNET_FS_FileInformation *fi, 1003 uint64_t length, struct GNUNET_CONTAINER_MetaData *meta,
1045 uint64_t length,
1046 struct GNUNET_CONTAINER_MetaData *meta,
1047 struct GNUNET_FS_Uri **uri, 1004 struct GNUNET_FS_Uri **uri,
1048 struct GNUNET_FS_BlockOptions *bo, 1005 struct GNUNET_FS_BlockOptions *bo, int *do_index,
1049 int *do_index, void **client_info) 1006 void **client_info)
1050{ 1007{
1051 struct GNUNET_FS_PublishContext *pc = cls; 1008 struct GNUNET_FS_PublishContext *pc = cls;
1052 struct GNUNET_FS_ProgressInfo pi; 1009 struct GNUNET_FS_ProgressInfo pi;
@@ -1118,15 +1075,14 @@ finish_reserve (void *cls, int success, const char *msg)
1118#endif 1075#endif
1119 if ((msg != NULL) || (success <= 0)) 1076 if ((msg != NULL) || (success <= 0))
1120 { 1077 {
1121 GNUNET_asprintf (&pc->fi->emsg, 1078 GNUNET_asprintf (&pc->fi->emsg, _("Insufficient space for publishing: %s"),
1122 _("Insufficient space for publishing: %s"), msg); 1079 msg);
1123 signal_publish_error (pc->fi, pc, pc->fi->emsg); 1080 signal_publish_error (pc->fi, pc, pc->fi->emsg);
1124 return; 1081 return;
1125 } 1082 }
1126 pc->rid = success; 1083 pc->rid = success;
1127 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 1084 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
1128 pc->upload_task 1085 pc->upload_task =
1129 =
1130 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 1086 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
1131 &GNUNET_FS_publish_main_, pc); 1087 &GNUNET_FS_publish_main_, pc);
1132} 1088}
@@ -1148,8 +1104,7 @@ finish_reserve (void *cls, int success, const char *msg)
1148struct GNUNET_FS_PublishContext * 1104struct GNUNET_FS_PublishContext *
1149GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h, 1105GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1150 struct GNUNET_FS_FileInformation *fi, 1106 struct GNUNET_FS_FileInformation *fi,
1151 struct GNUNET_FS_Namespace *namespace, 1107 struct GNUNET_FS_Namespace *namespace, const char *nid,
1152 const char *nid,
1153 const char *nuid, 1108 const char *nuid,
1154 enum GNUNET_FS_PublishOptions options) 1109 enum GNUNET_FS_PublishOptions options)
1155{ 1110{
@@ -1203,8 +1158,7 @@ GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1203 else 1158 else
1204 { 1159 {
1205 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == ret->upload_task); 1160 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == ret->upload_task);
1206 ret->upload_task 1161 ret->upload_task =
1207 =
1208 GNUNET_SCHEDULER_add_with_priority 1162 GNUNET_SCHEDULER_add_with_priority
1209 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, ret); 1163 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, ret);
1210 } 1164 }
@@ -1227,12 +1181,9 @@ GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1227 * @return GNUNET_OK to continue (always) 1181 * @return GNUNET_OK to continue (always)
1228 */ 1182 */
1229static int 1183static int
1230fip_signal_stop (void *cls, 1184fip_signal_stop (void *cls, struct GNUNET_FS_FileInformation *fi,
1231 struct GNUNET_FS_FileInformation *fi, 1185 uint64_t length, struct GNUNET_CONTAINER_MetaData *meta,
1232 uint64_t length, 1186 struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo,
1233 struct GNUNET_CONTAINER_MetaData *meta,
1234 struct GNUNET_FS_Uri **uri,
1235 struct GNUNET_FS_BlockOptions *bo,
1236 int *do_index, void **client_info) 1187 int *do_index, void **client_info)
1237{ 1188{
1238 struct GNUNET_FS_PublishContext *pc = cls; 1189 struct GNUNET_FS_PublishContext *pc = cls;
@@ -1241,8 +1192,7 @@ fip_signal_stop (void *cls,
1241 1192
1242 if (fi->serialization != NULL) 1193 if (fi->serialization != NULL)
1243 { 1194 {
1244 GNUNET_FS_remove_sync_file_ (pc->h, 1195 GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO,
1245 GNUNET_FS_SYNC_PATH_FILE_INFO,
1246 fi->serialization); 1196 fi->serialization);
1247 GNUNET_free (fi->serialization); 1197 GNUNET_free (fi->serialization);
1248 fi->serialization = NULL; 1198 fi->serialization = NULL;
@@ -1383,8 +1333,8 @@ struct PublishKskContext
1383 * @param cls closure of type "struct PublishKskContext*" 1333 * @param cls closure of type "struct PublishKskContext*"
1384 * @param tc unused 1334 * @param tc unused
1385 */ 1335 */
1386static void 1336static void publish_ksk_cont (void *cls,
1387publish_ksk_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 1337 const struct GNUNET_SCHEDULER_TaskContext *tc);
1388 1338
1389 1339
1390/** 1340/**
@@ -1418,8 +1368,8 @@ kb_put_cont (void *cls, int success, const char *msg)
1418 GNUNET_free (pkc); 1368 GNUNET_free (pkc);
1419 return; 1369 return;
1420 } 1370 }
1421 GNUNET_SCHEDULER_add_continuation (&publish_ksk_cont, 1371 GNUNET_SCHEDULER_add_continuation (&publish_ksk_cont, pkc,
1422 pkc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 1372 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1423} 1373}
1424 1374
1425 1375
@@ -1461,15 +1411,15 @@ publish_ksk_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1461 } 1411 }
1462 keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++]; 1412 keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++];
1463#if DEBUG_PUBLISH 1413#if DEBUG_PUBLISH
1464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1414 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing under keyword `%s'\n",
1465 "Publishing under keyword `%s'\n", keyword); 1415 keyword);
1466#endif 1416#endif
1467 /* first character of keyword indicates if it is 1417 /* first character of keyword indicates if it is
1468 * mandatory or not -- ignore for hashing */ 1418 * mandatory or not -- ignore for hashing */
1469 GNUNET_CRYPTO_hash (&keyword[1], strlen (&keyword[1]), &key); 1419 GNUNET_CRYPTO_hash (&keyword[1], strlen (&keyword[1]), &key);
1470 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv); 1420 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
1471 GNUNET_CRYPTO_aes_encrypt (&pkc->kb[1], 1421 GNUNET_CRYPTO_aes_encrypt (&pkc->kb[1], pkc->slen + pkc->mdsize, &skey, &iv,
1472 pkc->slen + pkc->mdsize, &skey, &iv, &pkc->cpy[1]); 1422 &pkc->cpy[1]);
1473 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key); 1423 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key);
1474 GNUNET_assert (NULL != pk); 1424 GNUNET_assert (NULL != pk);
1475 GNUNET_CRYPTO_rsa_key_get_public (pk, &pkc->cpy->keyspace); 1425 GNUNET_CRYPTO_rsa_key_get_public (pk, &pkc->cpy->keyspace);
@@ -1477,25 +1427,17 @@ publish_ksk_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1477 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 1427 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1478 &query); 1428 &query);
1479 GNUNET_assert (GNUNET_OK == 1429 GNUNET_assert (GNUNET_OK ==
1480 GNUNET_CRYPTO_rsa_sign (pk, 1430 GNUNET_CRYPTO_rsa_sign (pk, &pkc->cpy->purpose,
1481 &pkc->cpy->purpose,
1482 &pkc->cpy->signature)); 1431 &pkc->cpy->signature));
1483 GNUNET_CRYPTO_rsa_key_free (pk); 1432 GNUNET_CRYPTO_rsa_key_free (pk);
1484 pkc->qre = GNUNET_DATASTORE_put (pkc->dsh, 1433 pkc->qre =
1485 0, 1434 GNUNET_DATASTORE_put (pkc->dsh, 0, &query,
1486 &query, 1435 pkc->mdsize + sizeof (struct KBlock) + pkc->slen,
1487 pkc->mdsize + 1436 pkc->cpy, GNUNET_BLOCK_TYPE_FS_KBLOCK,
1488 sizeof (struct KBlock) + 1437 pkc->bo.content_priority, pkc->bo.anonymity_level,
1489 pkc->slen, 1438 pkc->bo.replication_level, pkc->bo.expiration_time,
1490 pkc->cpy, 1439 -2, 1, GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1491 GNUNET_BLOCK_TYPE_FS_KBLOCK, 1440 &kb_put_cont, pkc);
1492 pkc->bo.content_priority,
1493 pkc->bo.anonymity_level,
1494 pkc->bo.replication_level,
1495 pkc->bo.expiration_time,
1496 -2, 1,
1497 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1498 &kb_put_cont, pkc);
1499} 1441}
1500 1442
1501 1443
@@ -1561,10 +1503,9 @@ GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1561 GNUNET_free (uris); 1503 GNUNET_free (uris);
1562 sptr = &kbe[pkc->slen]; 1504 sptr = &kbe[pkc->slen];
1563 if (meta != NULL) 1505 if (meta != NULL)
1564 pkc->mdsize = GNUNET_CONTAINER_meta_data_serialize (meta, 1506 pkc->mdsize =
1565 &sptr, 1507 GNUNET_CONTAINER_meta_data_serialize (meta, &sptr, pkc->mdsize,
1566 pkc->mdsize, 1508 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
1567 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
1568 if (pkc->mdsize == -1) 1509 if (pkc->mdsize == -1)
1569 { 1510 {
1570 GNUNET_break (0); 1511 GNUNET_break (0);
@@ -1587,8 +1528,8 @@ GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1587 pkc->mdsize + pkc->slen); 1528 pkc->mdsize + pkc->slen);
1588 pkc->cpy->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK); 1529 pkc->cpy->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK);
1589 pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri); 1530 pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri);
1590 GNUNET_SCHEDULER_add_continuation (&publish_ksk_cont, 1531 GNUNET_SCHEDULER_add_continuation (&publish_ksk_cont, pkc,
1591 pkc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 1532 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1592} 1533}
1593 1534
1594 1535