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 http://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_NO
41 * Context for "ds_put_cont".
46 * Current publishing context.
48 struct GNUNET_FS_PublishContext *sc;
51 * Specific file with the block.
53 struct GNUNET_FS_FileInformation *p;
56 * Function to run next, if any (can be NULL).
58 GNUNET_SCHEDULER_Task cont;
68 * Fill in all of the generic fields for
69 * a publish event and call the callback.
71 * @param pi structure to fill in
72 * @param sc overall publishing context
73 * @param p file information for the file being published
74 * @param offset where in the file are we so far
75 * @return value returned from callback
78 GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
79 struct GNUNET_FS_PublishContext *sc,
80 const struct GNUNET_FS_FileInformation *p,
83 pi->value.publish.pc = sc;
84 pi->value.publish.fi = p;
85 pi->value.publish.cctx
87 pi->value.publish.pctx
88 = (NULL == p->dir) ? NULL : p->dir->client_info;
89 pi->value.publish.filename = p->filename;
90 pi->value.publish.size
91 = (p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size;
93 = GNUNET_TIME_calculate_eta (p->start_time,
95 pi->value.publish.size);
96 pi->value.publish.completed = offset;
97 pi->value.publish.duration = GNUNET_TIME_absolute_get_duration (p->start_time);
98 pi->value.publish.anonymity = p->anonymity;
99 return sc->h->upcb (sc->h->upcb_cls,
105 * Cleanup the publish context, we're done with it.
107 * @param cls struct to clean up after
108 * @param tc scheduler context
111 publish_cleanup (void *cls,
112 const struct GNUNET_SCHEDULER_TaskContext *tc)
114 struct GNUNET_FS_PublishContext *pc = cls;
118 GNUNET_CRYPTO_hash_file_cancel (pc->fhc);
121 GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
122 if (pc->namespace != NULL)
123 GNUNET_FS_namespace_delete (pc->namespace, GNUNET_NO);
124 GNUNET_free_non_null (pc->nid);
125 GNUNET_free_non_null (pc->nuid);
126 GNUNET_free_non_null (pc->serialization);
129 GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
132 if (pc->client != NULL)
133 GNUNET_CLIENT_disconnect (pc->client, GNUNET_NO);
139 * Function called by the datastore API with
140 * the result from the PUT request.
142 * @param cls our closure
143 * @param success GNUNET_OK on success
144 * @param msg error message (or NULL)
147 ds_put_cont (void *cls,
151 struct PutContCtx *pcc = cls;
152 struct GNUNET_FS_ProgressInfo pi;
154 if (GNUNET_SYSERR == pcc->sc->in_network_wait)
156 /* we were aborted in the meantime, finish shutdown! */
157 GNUNET_SCHEDULER_add_continuation (pcc->sc->h->sched,
160 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
164 GNUNET_assert (GNUNET_YES == pcc->sc->in_network_wait);
165 pcc->sc->in_network_wait = GNUNET_NO;
166 if (GNUNET_OK != success)
168 GNUNET_asprintf (&pcc->p->emsg,
169 _("Publishing failed: %s"),
171 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
172 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
173 pi.value.publish.specifics.error.message = pcc->p->emsg;
174 pcc->p->client_info = GNUNET_FS_publish_make_status_ (&pi, pcc->sc, pcc->p, 0);
175 if ( (pcc->p->is_directory == GNUNET_NO) &&
176 (pcc->p->filename != NULL) &&
177 (pcc->p->data.file.do_index == GNUNET_YES) )
179 /* run unindex to clean up */
180 GNUNET_FS_unindex_start (pcc->sc->h,
185 if (NULL != pcc->cont)
187 = GNUNET_SCHEDULER_add_with_priority (pcc->sc->h->sched,
188 GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
196 * Generate the callback that signals clients
197 * that a file (or directory) has been completely
200 * @param p the completed upload
201 * @param sc context of the publication
204 signal_publish_completion (struct GNUNET_FS_FileInformation *p,
205 struct GNUNET_FS_PublishContext *sc)
207 struct GNUNET_FS_ProgressInfo pi;
209 pi.status = GNUNET_FS_STATUS_PUBLISH_COMPLETED;
210 pi.value.publish.eta = GNUNET_TIME_UNIT_ZERO;
211 pi.value.publish.specifics.completed.chk_uri = p->chk_uri;
212 p->client_info = GNUNET_FS_publish_make_status_ (&pi, sc, p,
213 GNUNET_ntohll (p->chk_uri->data.chk.file_length));
218 * Generate the callback that signals clients
219 * that a file (or directory) has encountered
220 * a problem during publication.
222 * @param p the upload that had trouble
223 * @param sc context of the publication
224 * @param emsg error message
227 signal_publish_error (struct GNUNET_FS_FileInformation *p,
228 struct GNUNET_FS_PublishContext *sc,
231 struct GNUNET_FS_ProgressInfo pi;
233 p->emsg = GNUNET_strdup (emsg);
234 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
235 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
236 pi.value.publish.specifics.error.message =emsg;
237 p->client_info = GNUNET_FS_publish_make_status_ (&pi, sc, p, 0);
238 if ( (p->is_directory == GNUNET_NO) &&
239 (p->filename != NULL) &&
240 (p->data.file.do_index == GNUNET_YES) )
242 /* run unindex to clean up */
243 GNUNET_FS_unindex_start (sc->h,
252 * Datastore returns from reservation cancel request.
254 * @param cls the 'struct GNUNET_FS_PublishContext'
255 * @param success success code (not used)
256 * @param msg error message (typically NULL, not used)
259 finish_release_reserve (void *cls,
263 struct GNUNET_FS_PublishContext *pc = cls;
266 signal_publish_completion (pc->fi, pc);
267 pc->all_done = GNUNET_YES;
268 GNUNET_FS_publish_sync_ (pc);
273 * We've finished publishing the SBlock as part of a larger upload.
274 * Check the result and complete the larger upload.
276 * @param cls the "struct GNUNET_FS_PublishContext*" of the larger upload
277 * @param uri URI of the published SBlock
278 * @param emsg NULL on success, otherwise error message
281 publish_sblocks_cont (void *cls,
282 const struct GNUNET_FS_Uri *uri,
285 struct GNUNET_FS_PublishContext *pc = cls;
288 signal_publish_error (pc->fi,
291 GNUNET_FS_publish_sync_ (pc);
294 GNUNET_assert (pc->qre == NULL);
295 if ( (pc->dsh != NULL) &&
298 pc->qre = GNUNET_DATASTORE_release_reserve (pc->dsh,
302 GNUNET_TIME_UNIT_FOREVER_REL,
303 &finish_release_reserve,
308 finish_release_reserve (pc, GNUNET_OK, NULL);
314 * We are almost done publishing the structure,
315 * add SBlocks (if needed).
317 * @param sc overall upload data
320 publish_sblock (struct GNUNET_FS_PublishContext *sc)
322 if (NULL != sc->namespace)
323 GNUNET_FS_publish_sks (sc->h,
329 sc->fi->expirationTime,
333 &publish_sblocks_cont,
336 publish_sblocks_cont (sc, NULL, NULL);
341 * We've finished publishing a KBlock as part of a larger upload.
342 * Check the result and continue the larger upload.
344 * @param cls the "struct GNUNET_FS_PublishContext*"
345 * of the larger upload
346 * @param uri URI of the published blocks
347 * @param emsg NULL on success, otherwise error message
350 publish_kblocks_cont (void *cls,
351 const struct GNUNET_FS_Uri *uri,
354 struct GNUNET_FS_PublishContext *pc = cls;
355 struct GNUNET_FS_FileInformation *p = pc->fi_pos;
360 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
361 "Error uploading KSK blocks: %s\n",
364 signal_publish_error (p, pc, emsg);
365 GNUNET_FS_file_information_sync_ (p);
366 GNUNET_FS_publish_sync_ (pc);
368 = GNUNET_SCHEDULER_add_with_priority (pc->h->sched,
369 GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
370 &GNUNET_FS_publish_main_,
375 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
376 "KSK blocks published, moving on to next file\n");
379 signal_publish_completion (p, pc);
380 /* move on to next file */
382 pc->fi_pos = p->next;
385 GNUNET_FS_publish_sync_ (pc);
387 = GNUNET_SCHEDULER_add_with_priority (pc->h->sched,
388 GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
389 &GNUNET_FS_publish_main_,
395 * Function called by the tree encoder to obtain
396 * a block of plaintext data (for the lowest level
399 * @param cls our publishing context
400 * @param offset identifies which block to get
401 * @param max (maximum) number of bytes to get; returning
402 * fewer will also cause errors
403 * @param buf where to copy the plaintext buffer
404 * @param emsg location to store an error message (on error)
405 * @return number of bytes copied to buf, 0 on error
408 block_reader (void *cls,
414 struct GNUNET_FS_PublishContext *sc = cls;
415 struct GNUNET_FS_FileInformation *p;
422 pt_size = GNUNET_MIN(max,
423 p->data.dir.dir_size - offset);
424 dd = p->data.dir.dir_data;
431 pt_size = GNUNET_MIN(max,
432 p->data.file.file_size - offset);
434 return 0; /* calling reader with pt_size==0
435 might free buf, so don't! */
437 p->data.file.reader (p->data.file.reader_cls,
449 * The tree encoder has finished processing a
450 * file. Call it's finish method and deal with
453 * @param cls our publishing context
454 * @param tc scheduler's task context (not used)
457 encode_cont (void *cls,
458 const struct GNUNET_SCHEDULER_TaskContext *tc)
460 struct GNUNET_FS_PublishContext *sc = cls;
461 struct GNUNET_FS_FileInformation *p;
462 struct GNUNET_FS_ProgressInfo pi;
466 GNUNET_FS_tree_encoder_finish (p->te,
473 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
474 "Error during tree walk: %s\n",
477 GNUNET_asprintf (&p->emsg,
478 _("Publishing failed: %s"),
481 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
482 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
483 pi.value.publish.specifics.error.message = p->emsg;
484 p->client_info = GNUNET_FS_publish_make_status_ (&pi, sc, p, 0);
487 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
488 "Finished with tree encoder\n");
490 /* continue with main */
492 = GNUNET_SCHEDULER_add_with_priority (sc->h->sched,
493 GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
494 &GNUNET_FS_publish_main_,
500 * Function called asking for the current (encoded)
501 * block to be processed. After processing the
502 * client should either call "GNUNET_FS_tree_encode_next"
503 * or (on error) "GNUNET_FS_tree_encode_finish".
506 * @param query the query for the block (key for lookup in the datastore)
507 * @param offset offset of the block in the file
508 * @param type type of the block (IBLOCK or DBLOCK)
509 * @param block the (encrypted) block
510 * @param block_size size of block (in bytes)
513 block_proc (void *cls,
514 const GNUNET_HashCode *query,
516 enum GNUNET_BLOCK_Type type,
520 struct GNUNET_FS_PublishContext *sc = cls;
521 struct GNUNET_FS_FileInformation *p;
522 struct PutContCtx * dpc_cls;
523 struct OnDemandBlock odb;
529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
530 "Waiting for datastore connection\n");
533 = GNUNET_SCHEDULER_add_with_priority (sc->h->sched,
534 GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
535 &GNUNET_FS_publish_main_,
540 GNUNET_assert (GNUNET_NO == sc->in_network_wait);
541 sc->in_network_wait = GNUNET_YES;
542 dpc_cls = GNUNET_malloc(sizeof(struct PutContCtx));
543 dpc_cls->cont = &GNUNET_FS_publish_main_;
544 dpc_cls->cont_cls = sc;
547 if ( (! p->is_directory) &&
548 (GNUNET_YES == p->data.file.do_index) &&
549 (type == GNUNET_BLOCK_TYPE_DBLOCK) )
552 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
553 "Indexing block `%s' for offset %llu with index size %u\n",
555 (unsigned long long) offset,
556 sizeof (struct OnDemandBlock));
558 odb.offset = GNUNET_htonll (offset);
559 odb.file_id = p->data.file.file_id;
560 GNUNET_DATASTORE_put (sc->dsh,
563 sizeof(struct OnDemandBlock),
565 GNUNET_BLOCK_TYPE_ONDEMAND,
570 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
576 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
577 "Publishing block `%s' for offset %llu with size %u\n",
579 (unsigned long long) offset,
580 (unsigned int) block_size);
582 GNUNET_DATASTORE_put (sc->dsh,
592 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
599 * Function called with information about our
600 * progress in computing the tree encoding.
603 * @param offset where are we in the file
604 * @param pt_block plaintext of the currently processed block
605 * @param pt_size size of pt_block
606 * @param depth depth of the block in the tree
609 progress_proc (void *cls,
611 const void *pt_block,
615 struct GNUNET_FS_PublishContext *sc = cls;
616 struct GNUNET_FS_FileInformation *p;
617 struct GNUNET_FS_ProgressInfo pi;
620 pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS;
621 pi.value.publish.specifics.progress.data = pt_block;
622 pi.value.publish.specifics.progress.offset = offset;
623 pi.value.publish.specifics.progress.data_len = pt_size;
624 pi.value.publish.specifics.progress.depth = depth;
625 p->client_info = GNUNET_FS_publish_make_status_ (&pi, sc, p, offset);
630 * We are uploading a file or directory; load (if necessary) the next
631 * block into memory, encrypt it and send it to the FS service. Then
632 * continue with the main task.
634 * @param sc overall upload data
637 publish_content (struct GNUNET_FS_PublishContext *sc)
639 struct GNUNET_FS_FileInformation *p;
641 struct GNUNET_FS_DirectoryBuilder *db;
642 struct GNUNET_FS_FileInformation *dirpos;
647 GNUNET_assert (p != NULL);
653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
654 "Creating directory\n");
656 db = GNUNET_FS_directory_builder_create (p->meta);
657 dirpos = p->data.dir.entries;
658 while (NULL != dirpos)
660 if (dirpos->is_directory)
662 raw_data = dirpos->data.dir.dir_data;
663 dirpos->data.dir.dir_data = NULL;
668 if ( (dirpos->data.file.file_size < MAX_INLINE_SIZE) &&
669 (dirpos->data.file.file_size > 0) )
671 raw_data = GNUNET_malloc (dirpos->data.file.file_size);
673 if (dirpos->data.file.file_size !=
674 dirpos->data.file.reader (dirpos->data.file.reader_cls,
676 dirpos->data.file.file_size,
680 GNUNET_free_non_null (emsg);
681 GNUNET_free (raw_data);
686 GNUNET_FS_directory_builder_add (db,
690 GNUNET_free_non_null (raw_data);
691 dirpos = dirpos->next;
693 GNUNET_FS_directory_builder_finish (db,
694 &p->data.dir.dir_size,
695 &p->data.dir.dir_data);
696 GNUNET_FS_file_information_sync_ (p);
698 size = (p->is_directory)
699 ? p->data.dir.dir_size
700 : p->data.file.file_size;
702 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
703 "Creating tree encoder\n");
705 p->te = GNUNET_FS_tree_encoder_create (sc->h,
715 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
716 "Processing next block from tree\n");
718 GNUNET_FS_tree_encoder_next (p->te);
723 * Process the response (or lack thereof) from
724 * the "fs" service to our 'start index' request.
726 * @param cls closure (of type "struct GNUNET_FS_PublishContext*"_)
727 * @param msg the response we got
730 process_index_start_response (void *cls,
731 const struct GNUNET_MessageHeader *msg)
733 struct GNUNET_FS_PublishContext *sc = cls;
734 struct GNUNET_FS_FileInformation *p;
738 GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
743 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
744 _("Can not index file `%s': %s. Will try to insert instead.\n"),
746 _("timeout on index-start request to `fs' service"));
747 p->data.file.do_index = GNUNET_NO;
748 GNUNET_FS_file_information_sync_ (p);
749 publish_content (sc);
752 if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK)
754 msize = ntohs (msg->size);
755 emsg = (const char *) &msg[1];
756 if ( (msize <= sizeof (struct GNUNET_MessageHeader)) ||
757 (emsg[msize - sizeof(struct GNUNET_MessageHeader) - 1] != '\0') )
758 emsg = gettext_noop ("unknown error");
759 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
760 _("Can not index file `%s': %s. Will try to insert instead.\n"),
763 p->data.file.do_index = GNUNET_NO;
764 GNUNET_FS_file_information_sync_ (p);
765 publish_content (sc);
768 p->data.file.index_start_confirmed = GNUNET_YES;
769 /* success! continue with indexing */
770 GNUNET_FS_file_information_sync_ (p);
771 publish_content (sc);
776 * Function called once the hash computation over an
777 * indexed file has completed.
779 * @param cls closure, our publishing context
780 * @param res resulting hash, NULL on error
783 hash_for_index_cb (void *cls,
784 const GNUNET_HashCode *
787 struct GNUNET_FS_PublishContext *sc = cls;
788 struct GNUNET_FS_FileInformation *p;
789 struct IndexStartMessage *ism;
791 struct GNUNET_CLIENT_Connection *client;
800 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
801 _("Can not index file `%s': %s. Will try to insert instead.\n"),
803 _("failed to compute hash"));
804 p->data.file.do_index = GNUNET_NO;
805 GNUNET_FS_file_information_sync_ (p);
806 publish_content (sc);
809 if (GNUNET_YES == p->data.file.index_start_confirmed)
811 publish_content (sc);
814 fn = GNUNET_STRINGS_filename_expand (p->filename);
815 GNUNET_assert (fn != NULL);
816 slen = strlen (fn) + 1;
817 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof(struct IndexStartMessage))
819 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
820 _("Can not index file `%s': %s. Will try to insert instead.\n"),
822 _("filename too long"));
824 p->data.file.do_index = GNUNET_NO;
825 GNUNET_FS_file_information_sync_ (p);
826 publish_content (sc);
830 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
831 "Hash of indexed file `%s' is `%s'\n",
835 client = GNUNET_CLIENT_connect (sc->h->sched,
840 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
841 _("Can not index file `%s': %s. Will try to insert instead.\n"),
843 _("could not connect to `fs' service"));
844 p->data.file.do_index = GNUNET_NO;
845 publish_content (sc);
849 if (p->data.file.have_hash != GNUNET_YES)
851 p->data.file.file_id = *res;
852 p->data.file.have_hash = GNUNET_YES;
853 GNUNET_FS_file_information_sync_ (p);
855 ism = GNUNET_malloc (sizeof(struct IndexStartMessage) +
857 ism->header.size = htons(sizeof(struct IndexStartMessage) +
859 ism->header.type = htons(GNUNET_MESSAGE_TYPE_FS_INDEX_START);
861 GNUNET_DISK_file_get_identifiers (p->filename,
865 ism->device = GNUNET_htonll (dev);
866 ism->inode = GNUNET_htonll(ino);
871 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
872 _("Failed to get file identifiers for `%s'\n"),
882 GNUNET_break (GNUNET_YES ==
883 GNUNET_CLIENT_transmit_and_get_response (client,
885 GNUNET_TIME_UNIT_FOREVER_REL,
887 &process_index_start_response,
894 * Main function that performs the upload.
896 * @param cls "struct GNUNET_FS_PublishContext" identifies the upload
897 * @param tc task context
900 GNUNET_FS_publish_main_ (void *cls,
901 const struct GNUNET_SCHEDULER_TaskContext *tc)
903 struct GNUNET_FS_PublishContext *pc = cls;
904 struct GNUNET_FS_ProgressInfo pi;
905 struct GNUNET_FS_FileInformation *p;
906 struct GNUNET_FS_Uri *loc;
909 pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
915 "Publishing complete, now publishing SKS and KSK blocks.\n");
917 /* upload of entire hierarchy complete,
918 publish namespace entries */
919 GNUNET_FS_publish_sync_ (pc);
923 /* find starting position */
924 while ( (p->is_directory) &&
925 (NULL != p->data.dir.entries) &&
927 (NULL == p->data.dir.entries->chk_uri) )
929 p = p->data.dir.entries;
931 GNUNET_FS_publish_sync_ (pc);
937 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
938 "Error uploading: %s\n",
941 /* error with current file, abort all
942 related files as well! */
943 while (NULL != p->dir)
945 fn = GNUNET_CONTAINER_meta_data_get_by_type (p->meta,
946 EXTRACTOR_METATYPE_FILENAME);
950 GNUNET_asprintf (&p->emsg,
951 _("Recursive upload failed at `%s': %s"),
958 GNUNET_asprintf (&p->emsg,
959 _("Recursive upload failed: %s"),
962 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
963 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
964 pi.value.publish.specifics.error.message = p->emsg;
965 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
967 pc->all_done = GNUNET_YES;
968 GNUNET_FS_publish_sync_ (pc);
971 /* handle completion */
972 if (NULL != p->chk_uri)
975 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
976 "File upload complete, now publishing KSK blocks.\n");
978 if (0 == p->anonymity)
980 /* zero anonymity, box CHK URI in LOC URI */
981 loc = GNUNET_FS_uri_loc_create (p->chk_uri,
984 GNUNET_FS_uri_destroy (p->chk_uri);
987 GNUNET_FS_publish_sync_ (pc);
988 /* upload of "p" complete, publish KBlocks! */
989 if (p->keywords != NULL)
991 GNUNET_FS_publish_ksk (pc->h,
999 &publish_kblocks_cont,
1004 publish_kblocks_cont (pc,
1010 if ( (!p->is_directory) &&
1011 (p->data.file.do_index) )
1013 if (NULL == p->filename)
1015 p->data.file.do_index = GNUNET_NO;
1016 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1017 _("Can not index file `%s': %s. Will try to insert instead.\n"),
1019 _("needs to be an actual file"));
1020 GNUNET_FS_file_information_sync_ (p);
1021 publish_content (pc);
1024 if (p->data.file.have_hash)
1026 hash_for_index_cb (pc,
1027 &p->data.file.file_id);
1031 p->start_time = GNUNET_TIME_absolute_get ();
1032 pc->fhc = GNUNET_CRYPTO_hash_file (pc->h->sched,
1033 GNUNET_SCHEDULER_PRIORITY_IDLE,
1041 publish_content (pc);
1046 * Signal the FS's progress function that we are starting
1049 * @param cls closure (of type "struct GNUNET_FS_PublishContext*")
1050 * @param fi the entry in the publish-structure
1051 * @param length length of the file or directory
1052 * @param meta metadata for the file or directory (can be modified)
1053 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1054 * @param anonymity pointer to selected anonymity level (can be modified)
1055 * @param priority pointer to selected priority (can be modified)
1056 * @param do_index should we index?
1057 * @param expirationTime pointer to selected expiration time (can be modified)
1058 * @param client_info pointer to client context set upon creation (can be modified)
1059 * @return GNUNET_OK to continue (always)
1062 fip_signal_start(void *cls,
1063 struct GNUNET_FS_FileInformation *fi,
1065 struct GNUNET_CONTAINER_MetaData *meta,
1066 struct GNUNET_FS_Uri **uri,
1067 uint32_t *anonymity,
1070 struct GNUNET_TIME_Absolute *expirationTime,
1073 struct GNUNET_FS_PublishContext *sc = cls;
1074 struct GNUNET_FS_ProgressInfo pi;
1080 /* space for on-demand blocks */
1081 sc->reserve_space += ((length + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * sizeof (struct OnDemandBlock);
1085 /* space for DBlocks */
1086 sc->reserve_space += length;
1088 /* entries for IBlocks and DBlocks, space for IBlocks */
1092 left = (left + DBLOCK_SIZE - 1) / DBLOCK_SIZE;
1093 sc->reserve_entries += left;
1096 left = left * sizeof (struct ContentHashKey);
1097 sc->reserve_space += left;
1099 /* entries and space for keywords */
1102 kc = GNUNET_FS_uri_ksk_get_keyword_count (*uri);
1103 sc->reserve_entries += kc;
1104 sc->reserve_space += GNUNET_SERVER_MAX_MESSAGE_SIZE * kc;
1106 pi.status = GNUNET_FS_STATUS_PUBLISH_START;
1107 *client_info = GNUNET_FS_publish_make_status_ (&pi, sc, fi, 0);
1108 GNUNET_FS_file_information_sync_ (fi);
1114 * Signal the FS's progress function that we are suspending
1117 * @param cls closure (of type "struct GNUNET_FS_PublishContext*")
1118 * @param fi the entry in the publish-structure
1119 * @param length length of the file or directory
1120 * @param meta metadata for the file or directory (can be modified)
1121 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1122 * @param anonymity pointer to selected anonymity level (can be modified)
1123 * @param priority pointer to selected priority (can be modified)
1124 * @param do_index should we index?
1125 * @param expirationTime pointer to selected expiration time (can be modified)
1126 * @param client_info pointer to client context set upon creation (can be modified)
1127 * @return GNUNET_OK to continue (always)
1130 fip_signal_suspend(void *cls,
1131 struct GNUNET_FS_FileInformation *fi,
1133 struct GNUNET_CONTAINER_MetaData *meta,
1134 struct GNUNET_FS_Uri **uri,
1135 uint32_t *anonymity,
1138 struct GNUNET_TIME_Absolute *expirationTime,
1141 struct GNUNET_FS_PublishContext*sc = cls;
1142 struct GNUNET_FS_ProgressInfo pi;
1145 GNUNET_free_non_null (fi->serialization);
1146 fi->serialization = NULL;
1147 off = (fi->chk_uri == NULL) ? 0 : length;
1148 pi.status = GNUNET_FS_STATUS_PUBLISH_SUSPEND;
1149 GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, sc, fi, off));
1150 *client_info = NULL;
1151 if (NULL != sc->dsh)
1153 GNUNET_DATASTORE_disconnect (sc->dsh, GNUNET_NO);
1161 * Create SUSPEND event for the given publish operation
1162 * and then clean up our state (without stop signal).
1164 * @param cls the 'struct GNUNET_FS_PublishContext' to signal for
1167 GNUNET_FS_publish_signal_suspend_ (void *cls)
1169 struct GNUNET_FS_PublishContext *pc = cls;
1171 if (GNUNET_SCHEDULER_NO_TASK != pc->upload_task)
1173 GNUNET_SCHEDULER_cancel (pc->h->sched, pc->upload_task);
1174 pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
1176 GNUNET_FS_file_information_inspect (pc->fi,
1177 &fip_signal_suspend,
1179 GNUNET_FS_end_top (pc->h, pc->top);
1180 publish_cleanup (pc, NULL);
1185 * We have gotten a reply for our space reservation request.
1186 * Either fail (insufficient space) or start publishing for good.
1188 * @param cls the 'struct GNUNET_FS_PublishContext*'
1189 * @param success positive reservation ID on success
1190 * @param msg error message on error, otherwise NULL
1193 finish_reserve (void *cls,
1197 struct GNUNET_FS_PublishContext *pc = cls;
1200 if ( (msg != NULL) ||
1203 GNUNET_asprintf (&pc->fi->emsg,
1204 _("Insufficient space for publishing: %s"),
1206 signal_publish_error (pc->fi,
1213 = GNUNET_SCHEDULER_add_with_priority (pc->h->sched,
1214 GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
1215 &GNUNET_FS_publish_main_,
1221 * Publish a file or directory.
1223 * @param h handle to the file sharing subsystem
1224 * @param fi information about the file or directory structure to publish
1225 * @param namespace namespace to publish the file in, NULL for no namespace
1226 * @param nid identifier to use for the publishd content in the namespace
1227 * (can be NULL, must be NULL if namespace is NULL)
1228 * @param nuid update-identifier that will be used for future updates
1229 * (can be NULL, must be NULL if namespace or nid is NULL)
1230 * @param options options for the publication
1231 * @return context that can be used to control the publish operation
1233 struct GNUNET_FS_PublishContext *
1234 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1235 struct GNUNET_FS_FileInformation *fi,
1236 struct GNUNET_FS_Namespace *namespace,
1239 enum GNUNET_FS_PublishOptions options)
1241 struct GNUNET_FS_PublishContext *ret;
1242 struct GNUNET_DATASTORE_Handle *dsh;
1244 GNUNET_assert (NULL != h);
1245 if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
1247 dsh = GNUNET_DATASTORE_connect (h->cfg,
1256 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_PublishContext));
1260 ret->namespace = namespace;
1261 if (namespace != NULL)
1264 GNUNET_assert (NULL != nid);
1265 ret->nid = GNUNET_strdup (nid);
1267 ret->nuid = GNUNET_strdup (nuid);
1270 GNUNET_FS_file_information_inspect (ret->fi,
1273 ret->fi_pos = ret->fi;
1274 ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, ret);
1275 GNUNET_FS_publish_sync_ (ret);
1276 if (NULL != ret->dsh)
1278 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1279 _("Reserving space for %u entries and %llu bytes for publication\n"),
1280 (unsigned int) ret->reserve_entries,
1281 (unsigned long long) ret->reserve_space);
1282 ret->qre = GNUNET_DATASTORE_reserve (ret->dsh,
1284 ret->reserve_entries,
1287 GNUNET_TIME_UNIT_FOREVER_REL,
1294 = GNUNET_SCHEDULER_add_with_priority (h->sched,
1295 GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
1296 &GNUNET_FS_publish_main_,
1304 * Signal the FS's progress function that we are stopping
1307 * @param cls closure (of type "struct GNUNET_FS_PublishContext*")
1308 * @param fi the entry in the publish-structure
1309 * @param length length of the file or directory
1310 * @param meta metadata for the file or directory (can be modified)
1311 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1312 * @param anonymity pointer to selected anonymity level (can be modified)
1313 * @param priority pointer to selected priority (can be modified)
1314 * @param do_index should we index?
1315 * @param expirationTime pointer to selected expiration time (can be modified)
1316 * @param client_info pointer to client context set upon creation (can be modified)
1317 * @return GNUNET_OK to continue (always)
1320 fip_signal_stop(void *cls,
1321 struct GNUNET_FS_FileInformation *fi,
1323 struct GNUNET_CONTAINER_MetaData *meta,
1324 struct GNUNET_FS_Uri **uri,
1325 uint32_t *anonymity,
1328 struct GNUNET_TIME_Absolute *expirationTime,
1331 struct GNUNET_FS_PublishContext*sc = cls;
1332 struct GNUNET_FS_ProgressInfo pi;
1335 if (fi->serialization != NULL)
1337 GNUNET_FS_remove_sync_file_ (sc->h,
1338 GNUNET_FS_SYNC_PATH_FILE_INFO,
1340 GNUNET_free (fi->serialization);
1341 fi->serialization = NULL;
1343 off = (fi->chk_uri == NULL) ? 0 : length;
1344 pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED;
1345 GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, sc, fi, off));
1346 *client_info = NULL;
1352 * Stop an upload. Will abort incomplete uploads (but
1353 * not remove blocks that have already been publishd) or
1354 * simply clean up the state for completed uploads.
1355 * Must NOT be called from within the event callback!
1357 * @param pc context for the upload to stop
1360 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc)
1362 GNUNET_FS_end_top (pc->h, pc->top);
1363 if (NULL != pc->qre)
1365 GNUNET_DATASTORE_cancel (pc->qre);
1368 if (NULL != pc->dsh)
1370 GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
1373 if (GNUNET_SCHEDULER_NO_TASK != pc->upload_task)
1375 GNUNET_SCHEDULER_cancel (pc->h->sched, pc->upload_task);
1376 pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
1378 if (pc->serialization != NULL)
1380 GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, pc->serialization);
1381 GNUNET_free (pc->serialization);
1382 pc->serialization = NULL;
1384 GNUNET_FS_file_information_inspect (pc->fi,
1387 if (GNUNET_YES == pc->in_network_wait)
1389 pc->in_network_wait = GNUNET_SYSERR;
1392 publish_cleanup (pc, NULL);
1397 * Context for the KSK publication.
1399 struct PublishKskContext
1405 struct GNUNET_FS_Uri *ksk_uri;
1408 * Global FS context.
1410 struct GNUNET_FS_Handle *h;
1413 * The master block that we are sending
1414 * (in plaintext), has "mdsize+slen" more
1415 * bytes than the struct would suggest.
1420 * Buffer of the same size as "kb" for
1421 * the encrypted version.
1426 * Handle to the datastore, NULL if we are just
1429 struct GNUNET_DATASTORE_Handle *dsh;
1432 * Function to call once we're done.
1434 GNUNET_FS_PublishContinuation cont;
1442 * When should the KBlocks expire?
1444 struct GNUNET_TIME_Absolute expirationTime;
1447 * Size of the serialized metadata.
1452 * Size of the (CHK) URI as a string.
1457 * Keyword that we are currently processing.
1462 * Anonymity level for the KBlocks.
1467 * Priority for the KBlocks.
1474 * Continuation of "GNUNET_FS_publish_ksk" that performs
1475 * the actual publishing operation (iterating over all
1478 * @param cls closure of type "struct PublishKskContext*"
1482 publish_ksk_cont (void *cls,
1483 const struct GNUNET_SCHEDULER_TaskContext *tc);
1487 * Function called by the datastore API with
1488 * the result from the PUT request.
1490 * @param cls closure of type "struct PublishKskContext*"
1491 * @param success GNUNET_OK on success
1492 * @param msg error message (or NULL)
1495 kb_put_cont (void *cls,
1499 struct PublishKskContext *pkc = cls;
1501 if (GNUNET_OK != success)
1503 if (NULL != pkc->dsh)
1505 GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
1508 GNUNET_free (pkc->cpy);
1509 GNUNET_free (pkc->kb);
1510 pkc->cont (pkc->cont_cls,
1513 GNUNET_FS_uri_destroy (pkc->ksk_uri);
1517 GNUNET_SCHEDULER_add_continuation (pkc->h->sched,
1520 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1525 * Continuation of "GNUNET_FS_publish_ksk" that performs the actual
1526 * publishing operation (iterating over all of the keywords).
1528 * @param cls closure of type "struct PublishKskContext*"
1532 publish_ksk_cont (void *cls,
1533 const struct GNUNET_SCHEDULER_TaskContext *tc)
1535 struct PublishKskContext *pkc = cls;
1536 const char *keyword;
1537 GNUNET_HashCode key;
1538 GNUNET_HashCode query;
1539 struct GNUNET_CRYPTO_AesSessionKey skey;
1540 struct GNUNET_CRYPTO_AesInitializationVector iv;
1541 struct GNUNET_CRYPTO_RsaPrivateKey *pk;
1544 if ( (pkc->i == pkc->ksk_uri->data.ksk.keywordCount) ||
1545 (NULL == pkc->dsh) )
1547 if (NULL != pkc->dsh)
1549 GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
1552 GNUNET_free (pkc->cpy);
1553 GNUNET_free (pkc->kb);
1554 pkc->cont (pkc->cont_cls,
1557 GNUNET_FS_uri_destroy (pkc->ksk_uri);
1561 keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++];
1562 /* first character of keyword indicates if it is
1563 mandatory or not -- ignore for hashing */
1564 GNUNET_CRYPTO_hash (&keyword[1], strlen (&keyword[1]), &key);
1565 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
1566 GNUNET_CRYPTO_aes_encrypt (&pkc->kb[1],
1567 pkc->slen + pkc->mdsize,
1571 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key);
1572 GNUNET_assert (NULL != pk);
1573 GNUNET_CRYPTO_rsa_key_get_public (pk, &pkc->cpy->keyspace);
1574 GNUNET_CRYPTO_hash (&pkc->cpy->keyspace,
1575 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1577 GNUNET_assert (GNUNET_OK ==
1578 GNUNET_CRYPTO_rsa_sign (pk,
1580 &pkc->cpy->signature));
1581 GNUNET_CRYPTO_rsa_key_free (pk);
1582 GNUNET_DATASTORE_put (pkc->dsh,
1586 sizeof (struct KBlock) +
1589 GNUNET_BLOCK_TYPE_KBLOCK,
1592 pkc->expirationTime,
1594 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1601 * Publish a CHK under various keywords on GNUnet.
1603 * @param h handle to the file sharing subsystem
1604 * @param ksk_uri keywords to use
1605 * @param meta metadata to use
1606 * @param uri URI to refer to in the KBlock
1607 * @param expirationTime when the KBlock expires
1608 * @param anonymity anonymity level for the KBlock
1609 * @param priority priority for the KBlock
1610 * @param options publication options
1611 * @param cont continuation
1612 * @param cont_cls closure for cont
1615 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1616 const struct GNUNET_FS_Uri *ksk_uri,
1617 const struct GNUNET_CONTAINER_MetaData *meta,
1618 const struct GNUNET_FS_Uri *uri,
1619 struct GNUNET_TIME_Absolute expirationTime,
1622 enum GNUNET_FS_PublishOptions options,
1623 GNUNET_FS_PublishContinuation cont,
1626 struct PublishKskContext *pkc;
1632 pkc = GNUNET_malloc (sizeof (struct PublishKskContext));
1634 pkc->expirationTime = expirationTime;
1635 pkc->anonymity = anonymity;
1636 pkc->priority = priority;
1638 pkc->cont_cls = cont_cls;
1639 if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
1641 pkc->dsh = GNUNET_DATASTORE_connect (h->cfg,
1643 if (pkc->dsh == NULL)
1645 cont (cont_cls, NULL, _("Could not connect to datastore."));
1653 pkc->mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
1654 GNUNET_assert (pkc->mdsize >= 0);
1655 uris = GNUNET_FS_uri_to_string (uri);
1656 pkc->slen = strlen (uris) + 1;
1657 size = pkc->mdsize + sizeof (struct KBlock) + pkc->slen;
1658 if (size > MAX_KBLOCK_SIZE)
1660 size = MAX_KBLOCK_SIZE;
1661 pkc->mdsize = size - sizeof (struct KBlock) - pkc->slen;
1663 pkc->kb = GNUNET_malloc (size);
1664 kbe = (char *) &pkc->kb[1];
1665 memcpy (kbe, uris, pkc->slen);
1667 sptr = &kbe[pkc->slen];
1669 pkc->mdsize = GNUNET_CONTAINER_meta_data_serialize (meta,
1672 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
1673 if (pkc->mdsize == -1)
1676 GNUNET_free (pkc->kb);
1677 if (pkc->dsh != NULL)
1679 GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
1682 cont (cont_cls, NULL, _("Internal error."));
1686 size = sizeof (struct KBlock) + pkc->slen + pkc->mdsize;
1688 pkc->cpy = GNUNET_malloc (size);
1689 pkc->cpy->purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
1690 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
1693 pkc->cpy->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK);
1694 pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri);
1695 GNUNET_SCHEDULER_add_continuation (h->sched,
1698 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1703 * Context for the SKS publication.
1705 struct PublishSksContext
1709 * Global FS context.
1711 struct GNUNET_FS_Uri *uri;
1714 * Handle to the datastore.
1716 struct GNUNET_DATASTORE_Handle *dsh;
1719 * Function to call once we're done.
1721 GNUNET_FS_PublishContinuation cont;
1732 * Function called by the datastore API with
1733 * the result from the PUT (SBlock) request.
1735 * @param cls closure of type "struct PublishSksContext*"
1736 * @param success GNUNET_OK on success
1737 * @param msg error message (or NULL)
1740 sb_put_cont (void *cls,
1744 struct PublishSksContext *psc = cls;
1746 if (NULL != psc->dsh)
1748 GNUNET_DATASTORE_disconnect (psc->dsh, GNUNET_NO);
1751 if (GNUNET_OK != success)
1752 psc->cont (psc->cont_cls,
1756 psc->cont (psc->cont_cls,
1759 GNUNET_FS_uri_destroy (psc->uri);
1765 * Publish an SBlock on GNUnet.
1767 * @param h handle to the file sharing subsystem
1768 * @param namespace namespace to publish in
1769 * @param identifier identifier to use
1770 * @param update update identifier to use
1771 * @param meta metadata to use
1772 * @param uri URI to refer to in the SBlock
1773 * @param expirationTime when the SBlock expires
1774 * @param anonymity anonymity level for the SBlock
1775 * @param priority priority for the SBlock
1776 * @param options publication options
1777 * @param cont continuation
1778 * @param cont_cls closure for cont
1781 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
1782 struct GNUNET_FS_Namespace *namespace,
1783 const char *identifier,
1785 const struct GNUNET_CONTAINER_MetaData *meta,
1786 const struct GNUNET_FS_Uri *uri,
1787 struct GNUNET_TIME_Absolute expirationTime,
1790 enum GNUNET_FS_PublishOptions options,
1791 GNUNET_FS_PublishContinuation cont,
1794 struct PublishSksContext *psc;
1795 struct GNUNET_CRYPTO_AesSessionKey sk;
1796 struct GNUNET_CRYPTO_AesInitializationVector iv;
1797 struct GNUNET_FS_Uri *sks_uri;
1805 struct SBlock *sb_enc;
1807 struct GNUNET_CONTAINER_MetaData *mmeta;
1808 GNUNET_HashCode key; /* hash of thisId = key */
1809 GNUNET_HashCode id; /* hash of hc = identifier */
1810 GNUNET_HashCode query; /* id ^ nsid = DB query */
1813 mmeta = GNUNET_CONTAINER_meta_data_create ();
1815 mmeta = GNUNET_CONTAINER_meta_data_duplicate (meta);
1816 uris = GNUNET_FS_uri_to_string (uri);
1817 slen = strlen (uris) + 1;
1818 idlen = strlen (identifier);
1821 nidlen = strlen (update) + 1;
1822 mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (mmeta);
1823 size = sizeof (struct SBlock) + slen + nidlen + mdsize;
1824 if (size > MAX_SBLOCK_SIZE)
1826 size = MAX_SBLOCK_SIZE;
1827 mdsize = size - (sizeof (struct SBlock) + slen + nidlen);
1829 sb = GNUNET_malloc (sizeof (struct SBlock) + size);
1830 dest = (char *) &sb[1];
1831 memcpy (dest, update, nidlen);
1833 memcpy (dest, uris, slen);
1836 mdsize = GNUNET_CONTAINER_meta_data_serialize (mmeta,
1839 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
1840 GNUNET_CONTAINER_meta_data_destroy (mmeta);
1847 _("Internal error."));
1850 size = sizeof (struct SBlock) + mdsize + slen + nidlen;
1851 sb_enc = GNUNET_malloc (size);
1852 GNUNET_CRYPTO_hash (identifier, idlen, &key);
1853 GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &id);
1854 sks_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
1855 sks_uri->type = sks;
1856 GNUNET_CRYPTO_rsa_key_get_public (namespace->key, &sb_enc->subspace);
1857 GNUNET_CRYPTO_hash (&sb_enc->subspace,
1858 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1859 &sks_uri->data.sks.namespace);
1860 sks_uri->data.sks.identifier = GNUNET_strdup (identifier);
1861 GNUNET_CRYPTO_hash_xor (&id,
1862 &sks_uri->data.sks.namespace,
1863 &sb_enc->identifier);
1864 GNUNET_CRYPTO_hash_to_aes_key (&key, &sk, &iv);
1865 GNUNET_CRYPTO_aes_encrypt (&sb[1],
1866 size - sizeof (struct SBlock),
1870 sb_enc->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK);
1871 sb_enc->purpose.size = htonl(slen + mdsize + nidlen
1872 + sizeof(struct SBlock)
1873 - sizeof(struct GNUNET_CRYPTO_RsaSignature));
1874 GNUNET_assert (GNUNET_OK ==
1875 GNUNET_CRYPTO_rsa_sign (namespace->key,
1877 &sb_enc->signature));
1878 psc = GNUNET_malloc (sizeof(struct PublishSksContext));
1881 psc->cont_cls = cont_cls;
1882 if (0 != (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
1884 GNUNET_free (sb_enc);
1891 psc->dsh = GNUNET_DATASTORE_connect (h->cfg, h->sched);
1892 if (NULL == psc->dsh)
1894 GNUNET_free (sb_enc);
1898 _("Failed to connect to datastore."));
1901 GNUNET_CRYPTO_hash_xor (&sks_uri->data.sks.namespace,
1904 GNUNET_DATASTORE_put (psc->dsh,
1906 &sb_enc->identifier,
1909 GNUNET_BLOCK_TYPE_SBLOCK,
1914 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1918 GNUNET_free (sb_enc);
1921 /* end of fs_publish.c */