2 This file is part of GNUnet.
3 (C) 2009, 2010 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file fs/fs_publish.c
23 * @brief publish a file or directory in GNUnet
24 * @see https://gnunet.org/encoding
25 * @author Krista Bennett
26 * @author Christian Grothoff
30 #include "gnunet_constants.h"
31 #include "gnunet_signatures.h"
32 #include "gnunet_util_lib.h"
33 #include "gnunet_fs_service.h"
37 #define DEBUG_PUBLISH GNUNET_EXTRA_LOGGING
40 * Maximum legal size for a kblock.
42 #define MAX_KBLOCK_SIZE (60 * 1024)
46 * Fill in all of the generic fields for
47 * a publish event and call the callback.
49 * @param pi structure to fill in
50 * @param pc overall publishing context
51 * @param p file information for the file being published
52 * @param offset where in the file are we so far
53 * @return value returned from callback
56 GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
57 struct GNUNET_FS_PublishContext *pc,
58 const struct GNUNET_FS_FileInformation *p,
61 pi->value.publish.pc = pc;
62 pi->value.publish.fi = p;
63 pi->value.publish.cctx = p->client_info;
64 pi->value.publish.pctx = (NULL == p->dir) ? NULL : p->dir->client_info;
65 pi->value.publish.filename = p->filename;
66 pi->value.publish.size =
67 (p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size;
68 pi->value.publish.eta =
69 GNUNET_TIME_calculate_eta (p->start_time, offset, pi->value.publish.size);
70 pi->value.publish.completed = offset;
71 pi->value.publish.duration =
72 GNUNET_TIME_absolute_get_duration (p->start_time);
73 pi->value.publish.anonymity = p->bo.anonymity_level;
74 return pc->h->upcb (pc->h->upcb_cls, pi);
79 * Cleanup the publish context, we're done with it.
81 * @param cls struct to clean up after
82 * @param tc scheduler context
85 publish_cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
87 struct GNUNET_FS_PublishContext *pc = cls;
90 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up publish context (done!)\n");
94 GNUNET_CRYPTO_hash_file_cancel (pc->fhc);
97 GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
98 if (pc->namespace != NULL)
100 GNUNET_FS_namespace_delete (pc->namespace, GNUNET_NO);
101 pc->namespace = NULL;
103 GNUNET_free_non_null (pc->nid);
104 GNUNET_free_non_null (pc->nuid);
105 GNUNET_free_non_null (pc->serialization);
108 GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
111 if (pc->client != NULL)
113 GNUNET_CLIENT_disconnect (pc->client, GNUNET_NO);
116 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
122 * Function called by the datastore API with
123 * the result from the PUT request.
125 * @param cls the 'struct GNUNET_FS_PublishContext'
126 * @param success GNUNET_OK on success
127 * @param min_expiration minimum expiration time required for content to be stored
128 * @param msg error message (or NULL)
131 ds_put_cont (void *cls, int success,
132 struct GNUNET_TIME_Absolute min_expiration,
135 struct GNUNET_FS_PublishContext *pc = cls;
136 struct GNUNET_FS_ProgressInfo pi;
139 if (GNUNET_SYSERR == pc->in_network_wait)
141 /* we were aborted in the meantime, finish shutdown! */
142 GNUNET_SCHEDULER_add_continuation (&publish_cleanup, pc,
143 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
146 GNUNET_assert (GNUNET_YES == pc->in_network_wait);
147 pc->in_network_wait = GNUNET_NO;
148 if (GNUNET_SYSERR == success)
150 GNUNET_asprintf (&pc->fi_pos->emsg, _("Publishing failed: %s"), msg);
151 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
152 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
153 pi.value.publish.specifics.error.message = pc->fi_pos->emsg;
154 pc->fi_pos->client_info =
155 GNUNET_FS_publish_make_status_ (&pi, pc, pc->fi_pos, 0);
156 if ((pc->fi_pos->is_directory == GNUNET_NO) &&
157 (pc->fi_pos->filename != NULL) &&
158 (pc->fi_pos->data.file.do_index == GNUNET_YES))
160 /* run unindex to clean up */
161 GNUNET_FS_unindex_start (pc->h, pc->fi_pos->filename, NULL);
164 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
166 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
167 &GNUNET_FS_publish_main_, pc);
172 * Generate the callback that signals clients
173 * that a file (or directory) has been completely
176 * @param p the completed upload
177 * @param pc context of the publication
180 signal_publish_completion (struct GNUNET_FS_FileInformation *p,
181 struct GNUNET_FS_PublishContext *pc)
183 struct GNUNET_FS_ProgressInfo pi;
185 pi.status = GNUNET_FS_STATUS_PUBLISH_COMPLETED;
186 pi.value.publish.eta = GNUNET_TIME_UNIT_ZERO;
187 pi.value.publish.specifics.completed.chk_uri = p->chk_uri;
189 GNUNET_FS_publish_make_status_ (&pi, pc, p,
190 GNUNET_ntohll (p->chk_uri->data.
196 * Generate the callback that signals clients
197 * that a file (or directory) has encountered
198 * a problem during publication.
200 * @param p the upload that had trouble
201 * @param pc context of the publication
202 * @param emsg error message
205 signal_publish_error (struct GNUNET_FS_FileInformation *p,
206 struct GNUNET_FS_PublishContext *pc, const char *emsg)
208 struct GNUNET_FS_ProgressInfo pi;
210 p->emsg = GNUNET_strdup (emsg);
211 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
212 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
213 pi.value.publish.specifics.error.message = emsg;
214 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
215 if ((p->is_directory == GNUNET_NO) && (p->filename != NULL) &&
216 (p->data.file.do_index == GNUNET_YES))
218 /* run unindex to clean up */
219 GNUNET_FS_unindex_start (pc->h, p->filename, NULL);
226 * Datastore returns from reservation cancel request.
228 * @param cls the 'struct GNUNET_FS_PublishContext'
229 * @param success success code (not used)
230 * @param min_expiration minimum expiration time required for content to be stored
231 * @param msg error message (typically NULL, not used)
234 finish_release_reserve (void *cls, int success,
235 struct GNUNET_TIME_Absolute min_expiration,
238 struct GNUNET_FS_PublishContext *pc = cls;
242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Releasing reserve done!\n");
244 signal_publish_completion (pc->fi, pc);
245 pc->all_done = GNUNET_YES;
246 GNUNET_FS_publish_sync_ (pc);
251 * We've finished publishing the SBlock as part of a larger upload.
252 * Check the result and complete the larger upload.
254 * @param cls the "struct GNUNET_FS_PublishContext*" of the larger upload
255 * @param uri URI of the published SBlock
256 * @param emsg NULL on success, otherwise error message
259 publish_sblocks_cont (void *cls, const struct GNUNET_FS_Uri *uri,
262 struct GNUNET_FS_PublishContext *pc = cls;
266 signal_publish_error (pc->fi, pc, emsg);
267 GNUNET_FS_publish_sync_ (pc);
270 GNUNET_assert (pc->qre == NULL);
271 if ((pc->dsh != NULL) && (pc->rid != 0))
274 GNUNET_DATASTORE_release_reserve (pc->dsh, pc->rid, UINT_MAX, UINT_MAX,
275 GNUNET_TIME_UNIT_FOREVER_REL,
276 &finish_release_reserve, pc);
280 finish_release_reserve (pc, GNUNET_OK, GNUNET_TIME_UNIT_ZERO_ABS, NULL);
286 * We are almost done publishing the structure,
287 * add SBlocks (if needed).
289 * @param pc overall upload data
292 publish_sblock (struct GNUNET_FS_PublishContext *pc)
294 if (NULL != pc->namespace)
295 GNUNET_FS_publish_sks (pc->h, pc->namespace, pc->nid, pc->nuid,
296 pc->fi->meta, pc->fi->chk_uri, &pc->fi->bo,
297 pc->options, &publish_sblocks_cont, pc);
299 publish_sblocks_cont (pc, NULL, NULL);
304 * We've finished publishing a KBlock as part of a larger upload.
305 * Check the result and continue the larger upload.
307 * @param cls the "struct GNUNET_FS_PublishContext*"
308 * of the larger upload
309 * @param uri URI of the published blocks
310 * @param emsg NULL on success, otherwise error message
313 publish_kblocks_cont (void *cls, const struct GNUNET_FS_Uri *uri,
316 struct GNUNET_FS_PublishContext *pc = cls;
317 struct GNUNET_FS_FileInformation *p = pc->fi_pos;
322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error uploading KSK blocks: %s\n",
325 signal_publish_error (p, pc, emsg);
326 GNUNET_FS_file_information_sync_ (p);
327 GNUNET_FS_publish_sync_ (pc);
328 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
330 GNUNET_SCHEDULER_add_with_priority
331 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc);
335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
336 "KSK blocks published, moving on to next file\n");
339 signal_publish_completion (p, pc);
340 /* move on to next file */
342 pc->fi_pos = p->next;
345 GNUNET_FS_publish_sync_ (pc);
346 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
348 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
349 &GNUNET_FS_publish_main_, pc);
354 * Function called by the tree encoder to obtain
355 * a block of plaintext data (for the lowest level
358 * @param cls our publishing context
359 * @param offset identifies which block to get
360 * @param max (maximum) number of bytes to get; returning
361 * fewer will also cause errors
362 * @param buf where to copy the plaintext buffer
363 * @param emsg location to store an error message (on error)
364 * @return number of bytes copied to buf, 0 on error
367 block_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
369 struct GNUNET_FS_PublishContext *pc = cls;
370 struct GNUNET_FS_FileInformation *p;
377 pt_size = GNUNET_MIN (max, p->data.dir.dir_size - offset);
378 dd = p->data.dir.dir_data;
379 memcpy (buf, &dd[offset], pt_size);
383 pt_size = GNUNET_MIN (max, p->data.file.file_size - offset);
385 return 0; /* calling reader with pt_size==0
386 * might free buf, so don't! */
388 p->data.file.reader (p->data.file.reader_cls, offset, pt_size, buf,
397 * The tree encoder has finished processing a
398 * file. Call it's finish method and deal with
401 * @param cls our publishing context
402 * @param tc scheduler's task context (not used)
405 encode_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
407 struct GNUNET_FS_PublishContext *pc = cls;
408 struct GNUNET_FS_FileInformation *p;
409 struct GNUNET_FS_ProgressInfo pi;
414 GNUNET_FS_tree_encoder_finish (p->te, &p->chk_uri, &emsg);
419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error during tree walk: %s\n", emsg);
421 GNUNET_asprintf (&p->emsg, _("Publishing failed: %s"), emsg);
423 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
424 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
425 pi.value.publish.specifics.error.message = p->emsg;
426 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished with tree encoder\n");
431 /* final progress event */
432 flen = GNUNET_FS_uri_chk_get_file_size (p->chk_uri);
433 pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS;
434 pi.value.publish.specifics.progress.data = NULL;
435 pi.value.publish.specifics.progress.offset = flen;
436 pi.value.publish.specifics.progress.data_len = 0;
437 pi.value.publish.specifics.progress.depth = GNUNET_FS_compute_depth (flen);
438 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, flen);
440 /* continue with main */
441 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
443 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
444 &GNUNET_FS_publish_main_, pc);
449 * Function called asking for the current (encoded)
450 * block to be processed. After processing the
451 * client should either call "GNUNET_FS_tree_encode_next"
452 * or (on error) "GNUNET_FS_tree_encode_finish".
455 * @param chk content hash key for the block
456 * @param offset offset of the block in the file
457 * @param depth depth of the block in the file, 0 for DBLOCK
458 * @param type type of the block (IBLOCK or DBLOCK)
459 * @param block the (encrypted) block
460 * @param block_size size of block (in bytes)
463 block_proc (void *cls, const struct ContentHashKey *chk, uint64_t offset,
464 unsigned int depth, enum GNUNET_BLOCK_Type type, const void *block,
467 struct GNUNET_FS_PublishContext *pc = cls;
468 struct GNUNET_FS_FileInformation *p;
469 struct OnDemandBlock odb;
475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Waiting for datastore connection\n");
477 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
479 GNUNET_SCHEDULER_add_with_priority
480 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc);
484 GNUNET_assert (GNUNET_NO == pc->in_network_wait);
485 pc->in_network_wait = GNUNET_YES;
486 if ((!p->is_directory) && (GNUNET_YES == p->data.file.do_index) &&
487 (type == GNUNET_BLOCK_TYPE_FS_DBLOCK))
490 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
491 "Indexing block `%s' for offset %llu with index size %u\n",
492 GNUNET_h2s (&chk->query), (unsigned long long) offset,
493 sizeof (struct OnDemandBlock));
495 odb.offset = GNUNET_htonll (offset);
496 odb.file_id = p->data.file.file_id;
497 GNUNET_assert (pc->qre == NULL);
499 GNUNET_DATASTORE_put (pc->dsh, (p->is_directory) ? 0 : pc->rid,
500 &chk->query, sizeof (struct OnDemandBlock), &odb,
501 GNUNET_BLOCK_TYPE_FS_ONDEMAND,
502 p->bo.content_priority, p->bo.anonymity_level,
503 p->bo.replication_level, p->bo.expiration_time,
504 -2, 1, GNUNET_CONSTANTS_SERVICE_TIMEOUT,
509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
510 "Publishing block `%s' for offset %llu with size %u\n",
511 GNUNET_h2s (&chk->query), (unsigned long long) offset,
512 (unsigned int) block_size);
514 GNUNET_assert (pc->qre == NULL);
516 GNUNET_DATASTORE_put (pc->dsh, (p->is_directory) ? 0 : pc->rid,
517 &chk->query, block_size, block, type,
518 p->bo.content_priority, p->bo.anonymity_level,
519 p->bo.replication_level, p->bo.expiration_time, -2,
520 1, GNUNET_CONSTANTS_SERVICE_TIMEOUT, &ds_put_cont,
526 * Function called with information about our
527 * progress in computing the tree encoding.
530 * @param offset where are we in the file
531 * @param pt_block plaintext of the currently processed block
532 * @param pt_size size of pt_block
533 * @param depth depth of the block in the tree, 0 for DBLOCK
536 progress_proc (void *cls, uint64_t offset, const void *pt_block, size_t pt_size,
539 struct GNUNET_FS_PublishContext *pc = cls;
540 struct GNUNET_FS_FileInformation *p;
541 struct GNUNET_FS_ProgressInfo pi;
544 pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS;
545 pi.value.publish.specifics.progress.data = pt_block;
546 pi.value.publish.specifics.progress.offset = offset;
547 pi.value.publish.specifics.progress.data_len = pt_size;
548 pi.value.publish.specifics.progress.depth = depth;
549 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, offset);
554 * We are uploading a file or directory; load (if necessary) the next
555 * block into memory, encrypt it and send it to the FS service. Then
556 * continue with the main task.
558 * @param pc overall upload data
561 publish_content (struct GNUNET_FS_PublishContext *pc)
563 struct GNUNET_FS_FileInformation *p;
565 struct GNUNET_FS_DirectoryBuilder *db;
566 struct GNUNET_FS_FileInformation *dirpos;
571 GNUNET_assert (p != NULL);
577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating directory\n");
579 db = GNUNET_FS_directory_builder_create (p->meta);
580 dirpos = p->data.dir.entries;
581 while (NULL != dirpos)
583 if (dirpos->is_directory)
585 raw_data = dirpos->data.dir.dir_data;
586 dirpos->data.dir.dir_data = NULL;
591 if ((dirpos->data.file.file_size < MAX_INLINE_SIZE) &&
592 (dirpos->data.file.file_size > 0))
594 raw_data = GNUNET_malloc (dirpos->data.file.file_size);
596 if (dirpos->data.file.file_size !=
597 dirpos->data.file.reader (dirpos->data.file.reader_cls, 0,
598 dirpos->data.file.file_size, raw_data,
601 GNUNET_free_non_null (emsg);
602 GNUNET_free (raw_data);
607 GNUNET_FS_directory_builder_add (db, dirpos->chk_uri, dirpos->meta,
609 GNUNET_free_non_null (raw_data);
610 dirpos = dirpos->next;
612 GNUNET_free_non_null (p->data.dir.dir_data);
613 p->data.dir.dir_data = NULL;
614 p->data.dir.dir_size = 0;
615 GNUNET_FS_directory_builder_finish (db, &p->data.dir.dir_size,
616 &p->data.dir.dir_data);
617 GNUNET_FS_file_information_sync_ (p);
619 size = (p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size;
621 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating tree encoder\n");
624 GNUNET_FS_tree_encoder_create (pc->h, size, pc, &block_reader,
625 &block_proc, &progress_proc,
630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing next block from tree\n");
632 GNUNET_FS_tree_encoder_next (p->te);
637 * Process the response (or lack thereof) from
638 * the "fs" service to our 'start index' request.
640 * @param cls closure (of type "struct GNUNET_FS_PublishContext*"_)
641 * @param msg the response we got
644 process_index_start_response (void *cls, const struct GNUNET_MessageHeader *msg)
646 struct GNUNET_FS_PublishContext *pc = cls;
647 struct GNUNET_FS_FileInformation *p;
651 GNUNET_CLIENT_disconnect (pc->client, GNUNET_NO);
656 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
658 ("Can not index file `%s': %s. Will try to insert instead.\n"),
660 _("timeout on index-start request to `fs' service"));
661 p->data.file.do_index = GNUNET_NO;
662 GNUNET_FS_file_information_sync_ (p);
663 publish_content (pc);
666 if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK)
668 msize = ntohs (msg->size);
669 emsg = (const char *) &msg[1];
670 if ((msize <= sizeof (struct GNUNET_MessageHeader)) ||
671 (emsg[msize - sizeof (struct GNUNET_MessageHeader) - 1] != '\0'))
672 emsg = gettext_noop ("unknown error");
673 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
675 ("Can not index file `%s': %s. Will try to insert instead.\n"),
676 p->filename, gettext (emsg));
677 p->data.file.do_index = GNUNET_NO;
678 GNUNET_FS_file_information_sync_ (p);
679 publish_content (pc);
682 p->data.file.index_start_confirmed = GNUNET_YES;
683 /* success! continue with indexing */
684 GNUNET_FS_file_information_sync_ (p);
685 publish_content (pc);
690 * Function called once the hash computation over an
691 * indexed file has completed.
693 * @param cls closure, our publishing context
694 * @param res resulting hash, NULL on error
697 hash_for_index_cb (void *cls, const GNUNET_HashCode * res)
699 struct GNUNET_FS_PublishContext *pc = cls;
700 struct GNUNET_FS_FileInformation *p;
701 struct IndexStartMessage *ism;
703 struct GNUNET_CLIENT_Connection *client;
712 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
714 ("Can not index file `%s': %s. Will try to insert instead.\n"),
715 p->filename, _("failed to compute hash"));
716 p->data.file.do_index = GNUNET_NO;
717 GNUNET_FS_file_information_sync_ (p);
718 publish_content (pc);
721 if (GNUNET_YES == p->data.file.index_start_confirmed)
723 publish_content (pc);
726 fn = GNUNET_STRINGS_filename_expand (p->filename);
727 GNUNET_assert (fn != NULL);
728 slen = strlen (fn) + 1;
730 GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct IndexStartMessage))
732 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
734 ("Can not index file `%s': %s. Will try to insert instead.\n"),
735 fn, _("filename too long"));
737 p->data.file.do_index = GNUNET_NO;
738 GNUNET_FS_file_information_sync_ (p);
739 publish_content (pc);
743 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hash of indexed file `%s' is `%s'\n",
744 p->filename, GNUNET_h2s (res));
746 if (0 != (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
748 p->data.file.file_id = *res;
749 p->data.file.have_hash = GNUNET_YES;
750 p->data.file.index_start_confirmed = GNUNET_YES;
751 GNUNET_FS_file_information_sync_ (p);
752 publish_content (pc);
756 client = GNUNET_CLIENT_connect ("fs", pc->h->cfg);
759 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
761 ("Can not index file `%s': %s. Will try to insert instead.\n"),
762 p->filename, _("could not connect to `fs' service"));
763 p->data.file.do_index = GNUNET_NO;
764 publish_content (pc);
768 if (p->data.file.have_hash != GNUNET_YES)
770 p->data.file.file_id = *res;
771 p->data.file.have_hash = GNUNET_YES;
772 GNUNET_FS_file_information_sync_ (p);
774 ism = GNUNET_malloc (sizeof (struct IndexStartMessage) + slen);
775 ism->header.size = htons (sizeof (struct IndexStartMessage) + slen);
776 ism->header.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_START);
777 if (GNUNET_OK == GNUNET_DISK_file_get_identifiers (p->filename, &dev, &ino))
779 ism->device = GNUNET_htonll (dev);
780 ism->inode = GNUNET_htonll (ino);
785 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
786 _("Failed to get file identifiers for `%s'\n"), p->filename);
790 memcpy (&ism[1], fn, slen);
793 GNUNET_break (GNUNET_YES ==
794 GNUNET_CLIENT_transmit_and_get_response (client, &ism->header,
795 GNUNET_TIME_UNIT_FOREVER_REL,
797 &process_index_start_response,
804 * Main function that performs the upload.
806 * @param cls "struct GNUNET_FS_PublishContext" identifies the upload
807 * @param tc task context
810 GNUNET_FS_publish_main_ (void *cls,
811 const struct GNUNET_SCHEDULER_TaskContext *tc)
813 struct GNUNET_FS_PublishContext *pc = cls;
814 struct GNUNET_FS_ProgressInfo pi;
815 struct GNUNET_FS_FileInformation *p;
816 struct GNUNET_FS_Uri *loc;
819 pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
824 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
825 "Publishing complete, now publishing SKS and KSK blocks.\n");
827 /* upload of entire hierarchy complete,
828 * publish namespace entries */
829 GNUNET_FS_publish_sync_ (pc);
833 /* find starting position */
834 while ((p->is_directory) && (NULL != p->data.dir.entries) && (NULL == p->emsg)
835 && (NULL == p->data.dir.entries->chk_uri))
837 p = p->data.dir.entries;
839 GNUNET_FS_publish_sync_ (pc);
845 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error uploading: %s\n", p->emsg);
847 /* error with current file, abort all
848 * related files as well! */
849 while (NULL != p->dir)
851 fn = GNUNET_CONTAINER_meta_data_get_by_type (p->meta,
852 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
856 GNUNET_asprintf (&p->emsg, _("Recursive upload failed at `%s': %s"), fn,
862 GNUNET_asprintf (&p->emsg, _("Recursive upload failed: %s"), p->emsg);
864 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
865 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
866 pi.value.publish.specifics.error.message = p->emsg;
867 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
869 pc->all_done = GNUNET_YES;
870 GNUNET_FS_publish_sync_ (pc);
873 /* handle completion */
874 if (NULL != p->chk_uri)
877 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
878 "File upload complete, now publishing KSK blocks.\n");
880 if (0 == p->bo.anonymity_level)
882 /* zero anonymity, box CHK URI in LOC URI */
884 GNUNET_FS_uri_loc_create (p->chk_uri, pc->h->cfg,
885 p->bo.expiration_time);
886 GNUNET_FS_uri_destroy (p->chk_uri);
889 GNUNET_FS_publish_sync_ (pc);
890 /* upload of "p" complete, publish KBlocks! */
891 if (p->keywords != NULL)
893 GNUNET_FS_publish_ksk (pc->h, p->keywords, p->meta, p->chk_uri, &p->bo,
894 pc->options, &publish_kblocks_cont, pc);
898 publish_kblocks_cont (pc, p->chk_uri, NULL);
902 if ((!p->is_directory) && (p->data.file.do_index))
904 if (NULL == p->filename)
906 p->data.file.do_index = GNUNET_NO;
907 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
909 ("Can not index file `%s': %s. Will try to insert instead.\n"),
910 "<no-name>", _("needs to be an actual file"));
911 GNUNET_FS_file_information_sync_ (p);
912 publish_content (pc);
915 if (p->data.file.have_hash)
917 hash_for_index_cb (pc, &p->data.file.file_id);
921 p->start_time = GNUNET_TIME_absolute_get ();
923 GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, p->filename,
924 HASHING_BLOCKSIZE, &hash_for_index_cb, pc);
928 publish_content (pc);
933 * Signal the FS's progress function that we are starting
936 * @param cls closure (of type "struct GNUNET_FS_PublishContext*")
937 * @param fi the entry in the publish-structure
938 * @param length length of the file or directory
939 * @param meta metadata for the file or directory (can be modified)
940 * @param uri pointer to the keywords that will be used for this entry (can be modified)
941 * @param bo block options
942 * @param do_index should we index?
943 * @param client_info pointer to client context set upon creation (can be modified)
944 * @return GNUNET_OK to continue (always)
947 fip_signal_start (void *cls, struct GNUNET_FS_FileInformation *fi,
948 uint64_t length, struct GNUNET_CONTAINER_MetaData *meta,
949 struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo,
950 int *do_index, void **client_info)
952 struct GNUNET_FS_PublishContext *pc = cls;
953 struct GNUNET_FS_ProgressInfo pi;
958 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting publish operation\n");
962 /* space for on-demand blocks */
964 ((length + DBLOCK_SIZE -
965 1) / DBLOCK_SIZE) * sizeof (struct OnDemandBlock);
969 /* space for DBlocks */
970 pc->reserve_space += length;
972 /* entries for IBlocks and DBlocks, space for IBlocks */
976 left = (left + DBLOCK_SIZE - 1) / DBLOCK_SIZE;
977 pc->reserve_entries += left;
980 left = left * sizeof (struct ContentHashKey);
981 pc->reserve_space += left;
983 pc->reserve_entries++;
984 /* entries and space for keywords */
987 kc = GNUNET_FS_uri_ksk_get_keyword_count (*uri);
988 pc->reserve_entries += kc;
989 pc->reserve_space += GNUNET_SERVER_MAX_MESSAGE_SIZE * kc;
991 pi.status = GNUNET_FS_STATUS_PUBLISH_START;
992 *client_info = GNUNET_FS_publish_make_status_ (&pi, pc, fi, 0);
993 GNUNET_FS_file_information_sync_ (fi);
999 * Signal the FS's progress function that we are suspending
1002 * @param cls closure (of type "struct GNUNET_FS_PublishContext*")
1003 * @param fi the entry in the publish-structure
1004 * @param length length of the file or directory
1005 * @param meta metadata for the file or directory (can be modified)
1006 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1007 * @param bo block options
1008 * @param do_index should we index?
1009 * @param client_info pointer to client context set upon creation (can be modified)
1010 * @return GNUNET_OK to continue (always)
1013 fip_signal_suspend (void *cls, struct GNUNET_FS_FileInformation *fi,
1014 uint64_t length, struct GNUNET_CONTAINER_MetaData *meta,
1015 struct GNUNET_FS_Uri **uri,
1016 struct GNUNET_FS_BlockOptions *bo, int *do_index,
1019 struct GNUNET_FS_PublishContext *pc = cls;
1020 struct GNUNET_FS_ProgressInfo pi;
1024 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Suspending publish operation\n");
1026 GNUNET_free_non_null (fi->serialization);
1027 fi->serialization = NULL;
1028 off = (fi->chk_uri == NULL) ? 0 : length;
1029 pi.status = GNUNET_FS_STATUS_PUBLISH_SUSPEND;
1030 GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, fi, off));
1031 *client_info = NULL;
1032 if (NULL != pc->qre)
1034 GNUNET_DATASTORE_cancel (pc->qre);
1037 if (NULL != pc->dsh)
1039 GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
1048 * Create SUSPEND event for the given publish operation
1049 * and then clean up our state (without stop signal).
1051 * @param cls the 'struct GNUNET_FS_PublishContext' to signal for
1054 GNUNET_FS_publish_signal_suspend_ (void *cls)
1056 struct GNUNET_FS_PublishContext *pc = cls;
1058 if (GNUNET_SCHEDULER_NO_TASK != pc->upload_task)
1060 GNUNET_SCHEDULER_cancel (pc->upload_task);
1061 pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
1063 GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_suspend, pc);
1064 GNUNET_FS_end_top (pc->h, pc->top);
1066 publish_cleanup (pc, NULL);
1071 * We have gotten a reply for our space reservation request.
1072 * Either fail (insufficient space) or start publishing for good.
1074 * @param cls the 'struct GNUNET_FS_PublishContext*'
1075 * @param success positive reservation ID on success
1076 * @param min_expiration minimum expiration time required for content to be stored
1077 * @param msg error message on error, otherwise NULL
1080 finish_reserve (void *cls, int success,
1081 struct GNUNET_TIME_Absolute min_expiration,
1084 struct GNUNET_FS_PublishContext *pc = cls;
1088 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reservation complete (%d)!\n", success);
1090 if ((msg != NULL) || (success <= 0))
1092 GNUNET_asprintf (&pc->fi->emsg, _("Insufficient space for publishing: %s"),
1094 signal_publish_error (pc->fi, pc, pc->fi->emsg);
1098 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
1100 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
1101 &GNUNET_FS_publish_main_, pc);
1106 * Publish a file or directory.
1108 * @param h handle to the file sharing subsystem
1109 * @param fi information about the file or directory structure to publish
1110 * @param namespace namespace to publish the file in, NULL for no namespace
1111 * @param nid identifier to use for the publishd content in the namespace
1112 * (can be NULL, must be NULL if namespace is NULL)
1113 * @param nuid update-identifier that will be used for future updates
1114 * (can be NULL, must be NULL if namespace or nid is NULL)
1115 * @param options options for the publication
1116 * @return context that can be used to control the publish operation
1118 struct GNUNET_FS_PublishContext *
1119 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1120 struct GNUNET_FS_FileInformation *fi,
1121 struct GNUNET_FS_Namespace *namespace, const char *nid,
1123 enum GNUNET_FS_PublishOptions options)
1125 struct GNUNET_FS_PublishContext *ret;
1126 struct GNUNET_DATASTORE_Handle *dsh;
1128 GNUNET_assert (NULL != h);
1129 if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
1131 dsh = GNUNET_DATASTORE_connect (h->cfg);
1139 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_PublishContext));
1143 ret->namespace = namespace;
1144 ret->options = options;
1145 if (namespace != NULL)
1148 GNUNET_assert (NULL != nid);
1149 ret->nid = GNUNET_strdup (nid);
1151 ret->nuid = GNUNET_strdup (nuid);
1154 GNUNET_FS_file_information_inspect (ret->fi, &fip_signal_start, ret);
1155 ret->fi_pos = ret->fi;
1156 ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, ret);
1157 GNUNET_FS_publish_sync_ (ret);
1158 if (NULL != ret->dsh)
1160 GNUNET_assert (NULL == ret->qre);
1161 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1163 ("Reserving space for %u entries and %llu bytes for publication\n"),
1164 (unsigned int) ret->reserve_entries,
1165 (unsigned long long) ret->reserve_space);
1167 GNUNET_DATASTORE_reserve (ret->dsh, ret->reserve_space,
1168 ret->reserve_entries, UINT_MAX, UINT_MAX,
1169 GNUNET_TIME_UNIT_FOREVER_REL, &finish_reserve,
1174 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == ret->upload_task);
1176 GNUNET_SCHEDULER_add_with_priority
1177 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, ret);
1184 * Signal the FS's progress function that we are stopping
1187 * @param cls closure (of type "struct GNUNET_FS_PublishContext*")
1188 * @param fi the entry in the publish-structure
1189 * @param length length of the file or directory
1190 * @param meta metadata for the file or directory (can be modified)
1191 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1192 * @param bo block options (can be modified)
1193 * @param do_index should we index?
1194 * @param client_info pointer to client context set upon creation (can be modified)
1195 * @return GNUNET_OK to continue (always)
1198 fip_signal_stop (void *cls, struct GNUNET_FS_FileInformation *fi,
1199 uint64_t length, struct GNUNET_CONTAINER_MetaData *meta,
1200 struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo,
1201 int *do_index, void **client_info)
1203 struct GNUNET_FS_PublishContext *pc = cls;
1204 struct GNUNET_FS_ProgressInfo pi;
1207 if (fi->serialization != NULL)
1209 GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO,
1211 GNUNET_free (fi->serialization);
1212 fi->serialization = NULL;
1214 off = (fi->chk_uri == NULL) ? 0 : length;
1215 pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED;
1216 GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, fi, off));
1217 *client_info = NULL;
1223 * Stop an upload. Will abort incomplete uploads (but
1224 * not remove blocks that have already been publishd) or
1225 * simply clean up the state for completed uploads.
1226 * Must NOT be called from within the event callback!
1228 * @param pc context for the upload to stop
1231 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc)
1234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publish stop called\n");
1236 GNUNET_FS_end_top (pc->h, pc->top);
1237 if (NULL != pc->qre)
1239 GNUNET_DATASTORE_cancel (pc->qre);
1242 if (NULL != pc->dsh)
1244 GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
1247 if (GNUNET_SCHEDULER_NO_TASK != pc->upload_task)
1249 GNUNET_SCHEDULER_cancel (pc->upload_task);
1250 pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
1252 if (pc->serialization != NULL)
1254 GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
1256 GNUNET_free (pc->serialization);
1257 pc->serialization = NULL;
1259 GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_stop, pc);
1260 if (GNUNET_YES == pc->in_network_wait)
1262 pc->in_network_wait = GNUNET_SYSERR;
1265 publish_cleanup (pc, NULL);
1270 * Context for the KSK publication.
1272 struct PublishKskContext
1278 struct GNUNET_FS_Uri *ksk_uri;
1281 * Global FS context.
1283 struct GNUNET_FS_Handle *h;
1286 * The master block that we are sending
1287 * (in plaintext), has "mdsize+slen" more
1288 * bytes than the struct would suggest.
1293 * Buffer of the same size as "kb" for
1294 * the encrypted version.
1299 * Handle to the datastore, NULL if we are just
1302 struct GNUNET_DATASTORE_Handle *dsh;
1305 * Handle to datastore PUT request.
1307 struct GNUNET_DATASTORE_QueueEntry *qre;
1310 * Function to call once we're done.
1312 GNUNET_FS_PublishContinuation cont;
1320 * When should the KBlocks expire?
1322 struct GNUNET_FS_BlockOptions bo;
1325 * Size of the serialized metadata.
1330 * Size of the (CHK) URI as a string.
1335 * Keyword that we are currently processing.
1343 * Continuation of "GNUNET_FS_publish_ksk" that performs
1344 * the actual publishing operation (iterating over all
1347 * @param cls closure of type "struct PublishKskContext*"
1351 publish_ksk_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
1355 * Function called by the datastore API with
1356 * the result from the PUT request.
1358 * @param cls closure of type "struct PublishKskContext*"
1359 * @param success GNUNET_OK on success
1360 * @param min_expiration minimum expiration time required for content to be stored
1361 * @param msg error message (or NULL)
1364 kb_put_cont (void *cls, int success,
1365 struct GNUNET_TIME_Absolute min_expiration,
1368 struct PublishKskContext *pkc = cls;
1371 if (GNUNET_OK != success)
1374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "KB PUT operation complete\n");
1376 if (NULL != pkc->dsh)
1378 GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
1381 GNUNET_free (pkc->cpy);
1382 GNUNET_free (pkc->kb);
1383 pkc->cont (pkc->cont_cls, NULL, msg);
1384 GNUNET_FS_uri_destroy (pkc->ksk_uri);
1388 GNUNET_SCHEDULER_add_continuation (&publish_ksk_cont, pkc,
1389 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1394 * Continuation of "GNUNET_FS_publish_ksk" that performs the actual
1395 * publishing operation (iterating over all of the keywords).
1397 * @param cls closure of type "struct PublishKskContext*"
1401 publish_ksk_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1403 struct PublishKskContext *pkc = cls;
1404 const char *keyword;
1405 GNUNET_HashCode key;
1406 GNUNET_HashCode query;
1407 struct GNUNET_CRYPTO_AesSessionKey skey;
1408 struct GNUNET_CRYPTO_AesInitializationVector iv;
1409 struct GNUNET_CRYPTO_RsaPrivateKey *pk;
1412 if ((pkc->i == pkc->ksk_uri->data.ksk.keywordCount) || (NULL == pkc->dsh))
1415 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "KSK PUT operation complete\n");
1417 if (NULL != pkc->dsh)
1419 GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
1422 GNUNET_free (pkc->cpy);
1423 GNUNET_free (pkc->kb);
1424 pkc->cont (pkc->cont_cls, pkc->ksk_uri, NULL);
1425 GNUNET_FS_uri_destroy (pkc->ksk_uri);
1429 keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++];
1431 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing under keyword `%s'\n",
1434 /* first character of keyword indicates if it is
1435 * mandatory or not -- ignore for hashing */
1436 GNUNET_CRYPTO_hash (&keyword[1], strlen (&keyword[1]), &key);
1437 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
1438 GNUNET_CRYPTO_aes_encrypt (&pkc->kb[1], pkc->slen + pkc->mdsize, &skey, &iv,
1440 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key);
1441 GNUNET_assert (NULL != pk);
1442 GNUNET_CRYPTO_rsa_key_get_public (pk, &pkc->cpy->keyspace);
1443 GNUNET_CRYPTO_hash (&pkc->cpy->keyspace,
1444 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1446 GNUNET_assert (GNUNET_OK ==
1447 GNUNET_CRYPTO_rsa_sign (pk, &pkc->cpy->purpose,
1448 &pkc->cpy->signature));
1449 GNUNET_CRYPTO_rsa_key_free (pk);
1451 GNUNET_DATASTORE_put (pkc->dsh, 0, &query,
1452 pkc->mdsize + sizeof (struct KBlock) + pkc->slen,
1453 pkc->cpy, GNUNET_BLOCK_TYPE_FS_KBLOCK,
1454 pkc->bo.content_priority, pkc->bo.anonymity_level,
1455 pkc->bo.replication_level, pkc->bo.expiration_time,
1456 -2, 1, GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1462 * Publish a CHK under various keywords on GNUnet.
1464 * @param h handle to the file sharing subsystem
1465 * @param ksk_uri keywords to use
1466 * @param meta metadata to use
1467 * @param uri URI to refer to in the KBlock
1468 * @param bo per-block options
1469 * @param options publication options
1470 * @param cont continuation
1471 * @param cont_cls closure for cont
1474 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1475 const struct GNUNET_FS_Uri *ksk_uri,
1476 const struct GNUNET_CONTAINER_MetaData *meta,
1477 const struct GNUNET_FS_Uri *uri,
1478 const struct GNUNET_FS_BlockOptions *bo,
1479 enum GNUNET_FS_PublishOptions options,
1480 GNUNET_FS_PublishContinuation cont, void *cont_cls)
1482 struct PublishKskContext *pkc;
1488 GNUNET_assert (NULL != uri);
1489 pkc = GNUNET_malloc (sizeof (struct PublishKskContext));
1493 pkc->cont_cls = cont_cls;
1494 if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
1496 pkc->dsh = GNUNET_DATASTORE_connect (h->cfg);
1497 if (pkc->dsh == NULL)
1499 cont (cont_cls, NULL, _("Could not connect to datastore."));
1507 pkc->mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
1508 GNUNET_assert (pkc->mdsize >= 0);
1509 uris = GNUNET_FS_uri_to_string (uri);
1510 pkc->slen = strlen (uris) + 1;
1511 size = pkc->mdsize + sizeof (struct KBlock) + pkc->slen;
1512 if (size > MAX_KBLOCK_SIZE)
1514 size = MAX_KBLOCK_SIZE;
1515 pkc->mdsize = size - sizeof (struct KBlock) - pkc->slen;
1517 pkc->kb = GNUNET_malloc (size);
1518 kbe = (char *) &pkc->kb[1];
1519 memcpy (kbe, uris, pkc->slen);
1521 sptr = &kbe[pkc->slen];
1524 GNUNET_CONTAINER_meta_data_serialize (meta, &sptr, pkc->mdsize,
1525 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
1526 if (pkc->mdsize == -1)
1529 GNUNET_free (pkc->kb);
1530 if (pkc->dsh != NULL)
1532 GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
1535 cont (cont_cls, NULL, _("Internal error."));
1539 size = sizeof (struct KBlock) + pkc->slen + pkc->mdsize;
1541 pkc->cpy = GNUNET_malloc (size);
1542 pkc->cpy->purpose.size =
1543 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
1544 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
1545 pkc->mdsize + pkc->slen);
1546 pkc->cpy->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK);
1547 pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri);
1548 GNUNET_SCHEDULER_add_continuation (&publish_ksk_cont, pkc,
1549 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1553 /* end of fs_publish.c */