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;
116 GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
117 if (pc->namespace != NULL)
118 GNUNET_FS_namespace_delete (pc->namespace, GNUNET_NO);
119 GNUNET_free_non_null (pc->nid);
120 GNUNET_free_non_null (pc->nuid);
121 GNUNET_free_non_null (pc->serialization);
124 GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
127 if (pc->client != NULL)
128 GNUNET_CLIENT_disconnect (pc->client, GNUNET_NO);
134 * Function called by the datastore API with
135 * the result from the PUT request.
137 * @param cls our closure
138 * @param success GNUNET_OK on success
139 * @param msg error message (or NULL)
142 ds_put_cont (void *cls,
146 struct PutContCtx *pcc = cls;
147 struct GNUNET_FS_ProgressInfo pi;
149 if (GNUNET_SYSERR == pcc->sc->in_network_wait)
151 /* we were aborted in the meantime, finish shutdown! */
152 GNUNET_SCHEDULER_add_continuation (pcc->sc->h->sched,
155 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
159 GNUNET_assert (GNUNET_YES == pcc->sc->in_network_wait);
160 pcc->sc->in_network_wait = GNUNET_NO;
161 if (GNUNET_OK != success)
163 GNUNET_asprintf (&pcc->p->emsg,
164 _("Publishing failed: %s"),
166 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
167 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
168 pi.value.publish.specifics.error.message = pcc->p->emsg;
169 pcc->p->client_info = GNUNET_FS_publish_make_status_ (&pi, pcc->sc, pcc->p, 0);
170 if ( (pcc->p->is_directory == GNUNET_NO) &&
171 (pcc->p->filename != NULL) &&
172 (pcc->p->data.file.do_index == GNUNET_YES) )
174 /* run unindex to clean up */
175 GNUNET_FS_unindex_start (pcc->sc->h,
180 if (NULL != pcc->cont)
182 = GNUNET_SCHEDULER_add_with_priority (pcc->sc->h->sched,
183 GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
191 * Generate the callback that signals clients
192 * that a file (or directory) has been completely
195 * @param p the completed upload
196 * @param sc context of the publication
199 signal_publish_completion (struct GNUNET_FS_FileInformation *p,
200 struct GNUNET_FS_PublishContext *sc)
202 struct GNUNET_FS_ProgressInfo pi;
204 pi.status = GNUNET_FS_STATUS_PUBLISH_COMPLETED;
205 pi.value.publish.eta = GNUNET_TIME_UNIT_ZERO;
206 pi.value.publish.specifics.completed.chk_uri = p->chk_uri;
207 p->client_info = GNUNET_FS_publish_make_status_ (&pi, sc, p,
208 GNUNET_ntohll (p->chk_uri->data.chk.file_length));
213 * Generate the callback that signals clients
214 * that a file (or directory) has encountered
215 * a problem during publication.
217 * @param p the upload that had trouble
218 * @param sc context of the publication
219 * @param emsg error message
222 signal_publish_error (struct GNUNET_FS_FileInformation *p,
223 struct GNUNET_FS_PublishContext *sc,
226 struct GNUNET_FS_ProgressInfo pi;
228 p->emsg = GNUNET_strdup (emsg);
229 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
230 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
231 pi.value.publish.specifics.error.message =emsg;
232 p->client_info = GNUNET_FS_publish_make_status_ (&pi, sc, p, 0);
233 if ( (p->is_directory == GNUNET_NO) &&
234 (p->filename != NULL) &&
235 (p->data.file.do_index == GNUNET_YES) )
237 /* run unindex to clean up */
238 GNUNET_FS_unindex_start (sc->h,
247 * Datastore returns from reservation cancel request.
249 * @param cls the 'struct GNUNET_FS_PublishContext'
250 * @param success success code (not used)
251 * @param msg error message (typically NULL, not used)
254 finish_release_reserve (void *cls,
258 struct GNUNET_FS_PublishContext *pc = cls;
261 signal_publish_completion (pc->fi, pc);
262 pc->all_done = GNUNET_YES;
263 GNUNET_FS_publish_sync_ (pc);
268 * We've finished publishing the SBlock as part of a larger upload.
269 * Check the result and complete the larger upload.
271 * @param cls the "struct GNUNET_FS_PublishContext*" of the larger upload
272 * @param uri URI of the published SBlock
273 * @param emsg NULL on success, otherwise error message
276 publish_sblocks_cont (void *cls,
277 const struct GNUNET_FS_Uri *uri,
280 struct GNUNET_FS_PublishContext *pc = cls;
283 signal_publish_error (pc->fi,
286 GNUNET_FS_publish_sync_ (pc);
289 GNUNET_assert (pc->qre == NULL);
290 if ( (pc->dsh != NULL) &&
293 pc->qre = GNUNET_DATASTORE_release_reserve (pc->dsh,
297 GNUNET_TIME_UNIT_FOREVER_REL,
298 &finish_release_reserve,
303 finish_release_reserve (pc, GNUNET_OK, NULL);
309 * We are almost done publishing the structure,
310 * add SBlocks (if needed).
312 * @param sc overall upload data
315 publish_sblock (struct GNUNET_FS_PublishContext *sc)
317 if (NULL != sc->namespace)
318 GNUNET_FS_publish_sks (sc->h,
324 sc->fi->expirationTime,
328 &publish_sblocks_cont,
331 publish_sblocks_cont (sc, NULL, NULL);
336 * We've finished publishing a KBlock as part of a larger upload.
337 * Check the result and continue the larger upload.
339 * @param cls the "struct GNUNET_FS_PublishContext*"
340 * of the larger upload
341 * @param uri URI of the published blocks
342 * @param emsg NULL on success, otherwise error message
345 publish_kblocks_cont (void *cls,
346 const struct GNUNET_FS_Uri *uri,
349 struct GNUNET_FS_PublishContext *pc = cls;
350 struct GNUNET_FS_FileInformation *p = pc->fi_pos;
355 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
356 "Error uploading KSK blocks: %s\n",
359 signal_publish_error (p, pc, emsg);
360 GNUNET_FS_file_information_sync_ (p);
361 GNUNET_FS_publish_sync_ (pc);
363 = GNUNET_SCHEDULER_add_with_priority (pc->h->sched,
364 GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
365 &GNUNET_FS_publish_main_,
370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
371 "KSK blocks published, moving on to next file\n");
374 signal_publish_completion (p, pc);
375 /* move on to next file */
377 pc->fi_pos = p->next;
380 GNUNET_FS_publish_sync_ (pc);
382 = GNUNET_SCHEDULER_add_with_priority (pc->h->sched,
383 GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
384 &GNUNET_FS_publish_main_,
390 * Function called by the tree encoder to obtain
391 * a block of plaintext data (for the lowest level
394 * @param cls our publishing context
395 * @param offset identifies which block to get
396 * @param max (maximum) number of bytes to get; returning
397 * fewer will also cause errors
398 * @param buf where to copy the plaintext buffer
399 * @param emsg location to store an error message (on error)
400 * @return number of bytes copied to buf, 0 on error
403 block_reader (void *cls,
409 struct GNUNET_FS_PublishContext *sc = cls;
410 struct GNUNET_FS_FileInformation *p;
417 pt_size = GNUNET_MIN(max,
418 p->data.dir.dir_size - offset);
419 dd = p->data.dir.dir_data;
426 pt_size = GNUNET_MIN(max,
427 p->data.file.file_size - offset);
429 return 0; /* calling reader with pt_size==0
430 might free buf, so don't! */
432 p->data.file.reader (p->data.file.reader_cls,
444 * The tree encoder has finished processing a
445 * file. Call it's finish method and deal with
448 * @param cls our publishing context
449 * @param tc scheduler's task context (not used)
452 encode_cont (void *cls,
453 const struct GNUNET_SCHEDULER_TaskContext *tc)
455 struct GNUNET_FS_PublishContext *sc = cls;
456 struct GNUNET_FS_FileInformation *p;
457 struct GNUNET_FS_ProgressInfo pi;
461 GNUNET_FS_tree_encoder_finish (p->te,
468 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
469 "Error during tree walk: %s\n",
472 GNUNET_asprintf (&p->emsg,
473 _("Publishing failed: %s"),
476 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
477 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
478 pi.value.publish.specifics.error.message = p->emsg;
479 p->client_info = GNUNET_FS_publish_make_status_ (&pi, sc, p, 0);
482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
483 "Finished with tree encoder\n");
485 /* continue with main */
487 = GNUNET_SCHEDULER_add_with_priority (sc->h->sched,
488 GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
489 &GNUNET_FS_publish_main_,
495 * Function called asking for the current (encoded)
496 * block to be processed. After processing the
497 * client should either call "GNUNET_FS_tree_encode_next"
498 * or (on error) "GNUNET_FS_tree_encode_finish".
501 * @param query the query for the block (key for lookup in the datastore)
502 * @param offset offset of the block in the file
503 * @param type type of the block (IBLOCK or DBLOCK)
504 * @param block the (encrypted) block
505 * @param block_size size of block (in bytes)
508 block_proc (void *cls,
509 const GNUNET_HashCode *query,
511 enum GNUNET_BLOCK_Type type,
515 struct GNUNET_FS_PublishContext *sc = cls;
516 struct GNUNET_FS_FileInformation *p;
517 struct PutContCtx * dpc_cls;
518 struct OnDemandBlock odb;
524 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
525 "Waiting for datastore connection\n");
528 = GNUNET_SCHEDULER_add_with_priority (sc->h->sched,
529 GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
530 &GNUNET_FS_publish_main_,
535 GNUNET_assert (GNUNET_NO == sc->in_network_wait);
536 sc->in_network_wait = GNUNET_YES;
537 dpc_cls = GNUNET_malloc(sizeof(struct PutContCtx));
538 dpc_cls->cont = &GNUNET_FS_publish_main_;
539 dpc_cls->cont_cls = sc;
542 if ( (! p->is_directory) &&
543 (GNUNET_YES == p->data.file.do_index) &&
544 (type == GNUNET_BLOCK_TYPE_DBLOCK) )
547 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
548 "Indexing block `%s' for offset %llu with index size %u\n",
550 (unsigned long long) offset,
551 sizeof (struct OnDemandBlock));
553 odb.offset = GNUNET_htonll (offset);
554 odb.file_id = p->data.file.file_id;
555 GNUNET_DATASTORE_put (sc->dsh,
558 sizeof(struct OnDemandBlock),
560 GNUNET_BLOCK_TYPE_ONDEMAND,
565 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
572 "Publishing block `%s' for offset %llu with size %u\n",
574 (unsigned long long) offset,
575 (unsigned int) block_size);
577 GNUNET_DATASTORE_put (sc->dsh,
587 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
594 * Function called with information about our
595 * progress in computing the tree encoding.
598 * @param offset where are we in the file
599 * @param pt_block plaintext of the currently processed block
600 * @param pt_size size of pt_block
601 * @param depth depth of the block in the tree
604 progress_proc (void *cls,
606 const void *pt_block,
610 struct GNUNET_FS_PublishContext *sc = cls;
611 struct GNUNET_FS_FileInformation *p;
612 struct GNUNET_FS_ProgressInfo pi;
615 pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS;
616 pi.value.publish.specifics.progress.data = pt_block;
617 pi.value.publish.specifics.progress.offset = offset;
618 pi.value.publish.specifics.progress.data_len = pt_size;
619 pi.value.publish.specifics.progress.depth = depth;
620 p->client_info = GNUNET_FS_publish_make_status_ (&pi, sc, p, offset);
625 * We are uploading a file or directory; load (if necessary) the next
626 * block into memory, encrypt it and send it to the FS service. Then
627 * continue with the main task.
629 * @param sc overall upload data
632 publish_content (struct GNUNET_FS_PublishContext *sc)
634 struct GNUNET_FS_FileInformation *p;
636 struct GNUNET_FS_DirectoryBuilder *db;
637 struct GNUNET_FS_FileInformation *dirpos;
642 GNUNET_assert (p != NULL);
648 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
649 "Creating directory\n");
651 db = GNUNET_FS_directory_builder_create (p->meta);
652 dirpos = p->data.dir.entries;
653 while (NULL != dirpos)
655 if (dirpos->is_directory)
657 raw_data = dirpos->data.dir.dir_data;
658 dirpos->data.dir.dir_data = NULL;
663 if ( (dirpos->data.file.file_size < MAX_INLINE_SIZE) &&
664 (dirpos->data.file.file_size > 0) )
666 raw_data = GNUNET_malloc (dirpos->data.file.file_size);
668 if (dirpos->data.file.file_size !=
669 dirpos->data.file.reader (dirpos->data.file.reader_cls,
671 dirpos->data.file.file_size,
675 GNUNET_free_non_null (emsg);
676 GNUNET_free (raw_data);
681 GNUNET_FS_directory_builder_add (db,
685 GNUNET_free_non_null (raw_data);
686 dirpos = dirpos->next;
688 GNUNET_FS_directory_builder_finish (db,
689 &p->data.dir.dir_size,
690 &p->data.dir.dir_data);
691 GNUNET_FS_file_information_sync_ (p);
693 size = (p->is_directory)
694 ? p->data.dir.dir_size
695 : p->data.file.file_size;
697 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
698 "Creating tree encoder\n");
700 p->te = GNUNET_FS_tree_encoder_create (sc->h,
710 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
711 "Processing next block from tree\n");
713 GNUNET_FS_tree_encoder_next (p->te);
718 * Process the response (or lack thereof) from
719 * the "fs" service to our 'start index' request.
721 * @param cls closure (of type "struct GNUNET_FS_PublishContext*"_)
722 * @param msg the response we got
725 process_index_start_response (void *cls,
726 const struct GNUNET_MessageHeader *msg)
728 struct GNUNET_FS_PublishContext *sc = cls;
729 struct GNUNET_FS_FileInformation *p;
733 GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
738 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
739 _("Can not index file `%s': %s. Will try to insert instead.\n"),
741 _("timeout on index-start request to `fs' service"));
742 p->data.file.do_index = GNUNET_NO;
743 GNUNET_FS_file_information_sync_ (p);
744 publish_content (sc);
747 if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK)
749 msize = ntohs (msg->size);
750 emsg = (const char *) &msg[1];
751 if ( (msize <= sizeof (struct GNUNET_MessageHeader)) ||
752 (emsg[msize - sizeof(struct GNUNET_MessageHeader) - 1] != '\0') )
753 emsg = gettext_noop ("unknown error");
754 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
755 _("Can not index file `%s': %s. Will try to insert instead.\n"),
758 p->data.file.do_index = GNUNET_NO;
759 GNUNET_FS_file_information_sync_ (p);
760 publish_content (sc);
763 p->data.file.index_start_confirmed = GNUNET_YES;
764 /* success! continue with indexing */
765 GNUNET_FS_file_information_sync_ (p);
766 publish_content (sc);
771 * Function called once the hash computation over an
772 * indexed file has completed.
774 * @param cls closure, our publishing context
775 * @param res resulting hash, NULL on error
778 hash_for_index_cb (void *cls,
779 const GNUNET_HashCode *
782 struct GNUNET_FS_PublishContext *sc = cls;
783 struct GNUNET_FS_FileInformation *p;
784 struct IndexStartMessage *ism;
786 struct GNUNET_CLIENT_Connection *client;
794 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
795 _("Can not index file `%s': %s. Will try to insert instead.\n"),
797 _("failed to compute hash"));
798 p->data.file.do_index = GNUNET_NO;
799 GNUNET_FS_file_information_sync_ (p);
800 publish_content (sc);
803 if (GNUNET_YES == p->data.file.index_start_confirmed)
805 publish_content (sc);
808 fn = GNUNET_STRINGS_filename_expand (p->filename);
809 GNUNET_assert (fn != NULL);
810 slen = strlen (fn) + 1;
811 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof(struct IndexStartMessage))
813 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
814 _("Can not index file `%s': %s. Will try to insert instead.\n"),
816 _("filename too long"));
818 p->data.file.do_index = GNUNET_NO;
819 GNUNET_FS_file_information_sync_ (p);
820 publish_content (sc);
824 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
825 "Hash of indexed file `%s' is `%s'\n",
829 client = GNUNET_CLIENT_connect (sc->h->sched,
834 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
835 _("Can not index file `%s': %s. Will try to insert instead.\n"),
837 _("could not connect to `fs' service"));
838 p->data.file.do_index = GNUNET_NO;
839 publish_content (sc);
843 if (p->data.file.have_hash != GNUNET_YES)
845 p->data.file.file_id = *res;
846 p->data.file.have_hash = GNUNET_YES;
847 GNUNET_FS_file_information_sync_ (p);
849 ism = GNUNET_malloc (sizeof(struct IndexStartMessage) +
851 ism->header.size = htons(sizeof(struct IndexStartMessage) +
853 ism->header.type = htons(GNUNET_MESSAGE_TYPE_FS_INDEX_START);
855 GNUNET_DISK_file_get_identifiers (p->filename,
859 ism->device = GNUNET_htonll (dev);
860 ism->inode = GNUNET_htonll(ino);
865 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
866 _("Failed to get file identifiers for `%s'\n"),
876 GNUNET_break (GNUNET_YES ==
877 GNUNET_CLIENT_transmit_and_get_response (client,
879 GNUNET_TIME_UNIT_FOREVER_REL,
881 &process_index_start_response,
888 * Main function that performs the upload.
890 * @param cls "struct GNUNET_FS_PublishContext" identifies the upload
891 * @param tc task context
894 GNUNET_FS_publish_main_ (void *cls,
895 const struct GNUNET_SCHEDULER_TaskContext *tc)
897 struct GNUNET_FS_PublishContext *pc = cls;
898 struct GNUNET_FS_ProgressInfo pi;
899 struct GNUNET_FS_FileInformation *p;
900 struct GNUNET_FS_Uri *loc;
903 pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
908 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
909 "Publishing complete, now publishing SKS and KSK blocks.\n");
911 /* upload of entire hierarchy complete,
912 publish namespace entries */
913 GNUNET_FS_publish_sync_ (pc);
917 /* find starting position */
918 while ( (p->is_directory) &&
919 (NULL != p->data.dir.entries) &&
921 (NULL == p->data.dir.entries->chk_uri) )
923 p = p->data.dir.entries;
925 GNUNET_FS_publish_sync_ (pc);
931 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
932 "Error uploading: %s\n",
935 /* error with current file, abort all
936 related files as well! */
937 while (NULL != p->dir)
939 fn = GNUNET_CONTAINER_meta_data_get_by_type (p->meta,
940 EXTRACTOR_METATYPE_FILENAME);
944 GNUNET_asprintf (&p->emsg,
945 _("Recursive upload failed at `%s': %s"),
952 GNUNET_asprintf (&p->emsg,
953 _("Recursive upload failed: %s"),
956 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
957 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
958 pi.value.publish.specifics.error.message = p->emsg;
959 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
961 pc->all_done = GNUNET_YES;
962 GNUNET_FS_publish_sync_ (pc);
965 /* handle completion */
966 if (NULL != p->chk_uri)
969 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
970 "File upload complete, now publishing KSK blocks.\n");
972 if (0 == p->anonymity)
974 /* zero anonymity, box CHK URI in LOC URI */
975 loc = GNUNET_FS_uri_loc_create (p->chk_uri,
978 GNUNET_FS_uri_destroy (p->chk_uri);
981 GNUNET_FS_publish_sync_ (pc);
982 /* upload of "p" complete, publish KBlocks! */
983 if (p->keywords != NULL)
985 GNUNET_FS_publish_ksk (pc->h,
993 &publish_kblocks_cont,
998 publish_kblocks_cont (pc,
1004 if ( (!p->is_directory) &&
1005 (p->data.file.do_index) )
1007 if (NULL == p->filename)
1009 p->data.file.do_index = GNUNET_NO;
1010 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1011 _("Can not index file `%s': %s. Will try to insert instead.\n"),
1013 _("needs to be an actual file"));
1014 GNUNET_FS_file_information_sync_ (p);
1015 publish_content (pc);
1018 if (p->data.file.have_hash)
1020 hash_for_index_cb (pc,
1021 &p->data.file.file_id);
1025 p->start_time = GNUNET_TIME_absolute_get ();
1026 GNUNET_CRYPTO_hash_file (pc->h->sched,
1027 GNUNET_SCHEDULER_PRIORITY_IDLE,
1035 publish_content (pc);
1040 * Signal the FS's progress function that we are starting
1043 * @param cls closure (of type "struct GNUNET_FS_PublishContext*")
1044 * @param fi the entry in the publish-structure
1045 * @param length length of the file or directory
1046 * @param meta metadata for the file or directory (can be modified)
1047 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1048 * @param anonymity pointer to selected anonymity level (can be modified)
1049 * @param priority pointer to selected priority (can be modified)
1050 * @param do_index should we index?
1051 * @param expirationTime pointer to selected expiration time (can be modified)
1052 * @param client_info pointer to client context set upon creation (can be modified)
1053 * @return GNUNET_OK to continue (always)
1056 fip_signal_start(void *cls,
1057 struct GNUNET_FS_FileInformation *fi,
1059 struct GNUNET_CONTAINER_MetaData *meta,
1060 struct GNUNET_FS_Uri **uri,
1061 uint32_t *anonymity,
1064 struct GNUNET_TIME_Absolute *expirationTime,
1067 struct GNUNET_FS_PublishContext *sc = cls;
1068 struct GNUNET_FS_ProgressInfo pi;
1074 /* space for on-demand blocks */
1075 sc->reserve_space += ((length + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * sizeof (struct OnDemandBlock);
1079 /* space for DBlocks */
1080 sc->reserve_space += length;
1082 /* entries for IBlocks and DBlocks, space for IBlocks */
1086 left = (left + DBLOCK_SIZE - 1) / DBLOCK_SIZE;
1087 sc->reserve_entries += left;
1090 left = left * sizeof (struct ContentHashKey);
1091 sc->reserve_space += left;
1093 /* entries and space for keywords */
1096 kc = GNUNET_FS_uri_ksk_get_keyword_count (*uri);
1097 sc->reserve_entries += kc;
1098 sc->reserve_space += GNUNET_SERVER_MAX_MESSAGE_SIZE * kc;
1100 pi.status = GNUNET_FS_STATUS_PUBLISH_START;
1101 *client_info = GNUNET_FS_publish_make_status_ (&pi, sc, fi, 0);
1102 GNUNET_FS_file_information_sync_ (fi);
1108 * Signal the FS's progress function that we are suspending
1111 * @param cls closure (of type "struct GNUNET_FS_PublishContext*")
1112 * @param fi the entry in the publish-structure
1113 * @param length length of the file or directory
1114 * @param meta metadata for the file or directory (can be modified)
1115 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1116 * @param anonymity pointer to selected anonymity level (can be modified)
1117 * @param priority pointer to selected priority (can be modified)
1118 * @param do_index should we index?
1119 * @param expirationTime pointer to selected expiration time (can be modified)
1120 * @param client_info pointer to client context set upon creation (can be modified)
1121 * @return GNUNET_OK to continue (always)
1124 fip_signal_suspend(void *cls,
1125 struct GNUNET_FS_FileInformation *fi,
1127 struct GNUNET_CONTAINER_MetaData *meta,
1128 struct GNUNET_FS_Uri **uri,
1129 uint32_t *anonymity,
1132 struct GNUNET_TIME_Absolute *expirationTime,
1135 struct GNUNET_FS_PublishContext*sc = cls;
1136 struct GNUNET_FS_ProgressInfo pi;
1139 GNUNET_free_non_null (fi->serialization);
1140 fi->serialization = NULL;
1141 off = (fi->chk_uri == NULL) ? 0 : length;
1142 pi.status = GNUNET_FS_STATUS_PUBLISH_SUSPEND;
1143 GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, sc, fi, off));
1144 *client_info = NULL;
1145 if (NULL != sc->dsh)
1147 GNUNET_DATASTORE_disconnect (sc->dsh, GNUNET_NO);
1155 * Create SUSPEND event for the given publish operation
1156 * and then clean up our state (without stop signal).
1158 * @param cls the 'struct GNUNET_FS_PublishContext' to signal for
1161 GNUNET_FS_publish_signal_suspend_ (void *cls)
1163 struct GNUNET_FS_PublishContext *pc = cls;
1165 if (GNUNET_SCHEDULER_NO_TASK != pc->upload_task)
1167 GNUNET_SCHEDULER_cancel (pc->h->sched, pc->upload_task);
1168 pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
1170 GNUNET_FS_file_information_inspect (pc->fi,
1171 &fip_signal_suspend,
1173 GNUNET_FS_end_top (pc->h, pc->top);
1174 publish_cleanup (pc, NULL);
1179 * We have gotten a reply for our space reservation request.
1180 * Either fail (insufficient space) or start publishing for good.
1182 * @param cls the 'struct GNUNET_FS_PublishContext*'
1183 * @param success positive reservation ID on success
1184 * @param msg error message on error, otherwise NULL
1187 finish_reserve (void *cls,
1191 struct GNUNET_FS_PublishContext *pc = cls;
1194 if ( (msg != NULL) ||
1197 GNUNET_asprintf (&pc->fi->emsg,
1198 _("Insufficient space for publishing: %s"),
1200 signal_publish_error (pc->fi,
1207 = GNUNET_SCHEDULER_add_with_priority (pc->h->sched,
1208 GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
1209 &GNUNET_FS_publish_main_,
1215 * Publish a file or directory.
1217 * @param h handle to the file sharing subsystem
1218 * @param fi information about the file or directory structure to publish
1219 * @param namespace namespace to publish the file in, NULL for no namespace
1220 * @param nid identifier to use for the publishd content in the namespace
1221 * (can be NULL, must be NULL if namespace is NULL)
1222 * @param nuid update-identifier that will be used for future updates
1223 * (can be NULL, must be NULL if namespace or nid is NULL)
1224 * @param options options for the publication
1225 * @return context that can be used to control the publish operation
1227 struct GNUNET_FS_PublishContext *
1228 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1229 struct GNUNET_FS_FileInformation *fi,
1230 struct GNUNET_FS_Namespace *namespace,
1233 enum GNUNET_FS_PublishOptions options)
1235 struct GNUNET_FS_PublishContext *ret;
1236 struct GNUNET_DATASTORE_Handle *dsh;
1238 if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
1240 dsh = GNUNET_DATASTORE_connect (h->cfg,
1249 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_PublishContext));
1253 ret->namespace = namespace;
1254 if (namespace != NULL)
1257 GNUNET_assert (NULL != nid);
1258 ret->nid = GNUNET_strdup (nid);
1260 ret->nuid = GNUNET_strdup (nuid);
1263 GNUNET_FS_file_information_inspect (ret->fi,
1266 ret->fi_pos = ret->fi;
1267 ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, ret);
1268 GNUNET_FS_publish_sync_ (ret);
1269 if (NULL != ret->dsh)
1271 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1272 _("Reserving space for %u entries and %llu bytes for publication\n"),
1273 (unsigned int) ret->reserve_entries,
1274 (unsigned long long) ret->reserve_space);
1275 ret->qre = GNUNET_DATASTORE_reserve (ret->dsh,
1277 ret->reserve_entries,
1280 GNUNET_TIME_UNIT_FOREVER_REL,
1287 = GNUNET_SCHEDULER_add_with_priority (h->sched,
1288 GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
1289 &GNUNET_FS_publish_main_,
1297 * Signal the FS's progress function that we are stopping
1300 * @param cls closure (of type "struct GNUNET_FS_PublishContext*")
1301 * @param fi the entry in the publish-structure
1302 * @param length length of the file or directory
1303 * @param meta metadata for the file or directory (can be modified)
1304 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1305 * @param anonymity pointer to selected anonymity level (can be modified)
1306 * @param priority pointer to selected priority (can be modified)
1307 * @param do_index should we index?
1308 * @param expirationTime pointer to selected expiration time (can be modified)
1309 * @param client_info pointer to client context set upon creation (can be modified)
1310 * @return GNUNET_OK to continue (always)
1313 fip_signal_stop(void *cls,
1314 struct GNUNET_FS_FileInformation *fi,
1316 struct GNUNET_CONTAINER_MetaData *meta,
1317 struct GNUNET_FS_Uri **uri,
1318 uint32_t *anonymity,
1321 struct GNUNET_TIME_Absolute *expirationTime,
1324 struct GNUNET_FS_PublishContext*sc = cls;
1325 struct GNUNET_FS_ProgressInfo pi;
1328 if (fi->serialization != NULL)
1330 GNUNET_FS_remove_sync_file_ (sc->h,
1331 GNUNET_FS_SYNC_PATH_FILE_INFO,
1333 GNUNET_free (fi->serialization);
1334 fi->serialization = NULL;
1336 off = (fi->chk_uri == NULL) ? 0 : length;
1337 pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED;
1338 GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, sc, fi, off));
1339 *client_info = NULL;
1345 * Stop an upload. Will abort incomplete uploads (but
1346 * not remove blocks that have already been publishd) or
1347 * simply clean up the state for completed uploads.
1348 * Must NOT be called from within the event callback!
1350 * @param pc context for the upload to stop
1353 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc)
1355 GNUNET_FS_end_top (pc->h, pc->top);
1356 if (NULL != pc->qre)
1358 GNUNET_DATASTORE_cancel (pc->qre);
1361 if (NULL != pc->dsh)
1363 GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
1366 if (GNUNET_SCHEDULER_NO_TASK != pc->upload_task)
1368 GNUNET_SCHEDULER_cancel (pc->h->sched, pc->upload_task);
1369 pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
1371 if (pc->serialization != NULL)
1373 GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, pc->serialization);
1374 GNUNET_free (pc->serialization);
1375 pc->serialization = NULL;
1377 GNUNET_FS_file_information_inspect (pc->fi,
1380 if (GNUNET_YES == pc->in_network_wait)
1382 pc->in_network_wait = GNUNET_SYSERR;
1385 publish_cleanup (pc, NULL);
1390 * Context for the KSK publication.
1392 struct PublishKskContext
1398 struct GNUNET_FS_Uri *ksk_uri;
1401 * Global FS context.
1403 struct GNUNET_FS_Handle *h;
1406 * The master block that we are sending
1407 * (in plaintext), has "mdsize+slen" more
1408 * bytes than the struct would suggest.
1413 * Buffer of the same size as "kb" for
1414 * the encrypted version.
1419 * Handle to the datastore, NULL if we are just
1422 struct GNUNET_DATASTORE_Handle *dsh;
1425 * Function to call once we're done.
1427 GNUNET_FS_PublishContinuation cont;
1435 * When should the KBlocks expire?
1437 struct GNUNET_TIME_Absolute expirationTime;
1440 * Size of the serialized metadata.
1445 * Size of the (CHK) URI as a string.
1450 * Keyword that we are currently processing.
1455 * Anonymity level for the KBlocks.
1460 * Priority for the KBlocks.
1467 * Continuation of "GNUNET_FS_publish_ksk" that performs
1468 * the actual publishing operation (iterating over all
1471 * @param cls closure of type "struct PublishKskContext*"
1475 publish_ksk_cont (void *cls,
1476 const struct GNUNET_SCHEDULER_TaskContext *tc);
1480 * Function called by the datastore API with
1481 * the result from the PUT request.
1483 * @param cls closure of type "struct PublishKskContext*"
1484 * @param success GNUNET_OK on success
1485 * @param msg error message (or NULL)
1488 kb_put_cont (void *cls,
1492 struct PublishKskContext *pkc = cls;
1494 if (GNUNET_OK != success)
1496 if (NULL != pkc->dsh)
1498 GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
1501 GNUNET_free (pkc->cpy);
1502 GNUNET_free (pkc->kb);
1503 pkc->cont (pkc->cont_cls,
1506 GNUNET_FS_uri_destroy (pkc->ksk_uri);
1510 GNUNET_SCHEDULER_add_continuation (pkc->h->sched,
1513 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1518 * Continuation of "GNUNET_FS_publish_ksk" that performs the actual
1519 * publishing operation (iterating over all of the keywords).
1521 * @param cls closure of type "struct PublishKskContext*"
1525 publish_ksk_cont (void *cls,
1526 const struct GNUNET_SCHEDULER_TaskContext *tc)
1528 struct PublishKskContext *pkc = cls;
1529 const char *keyword;
1530 GNUNET_HashCode key;
1531 GNUNET_HashCode query;
1532 struct GNUNET_CRYPTO_AesSessionKey skey;
1533 struct GNUNET_CRYPTO_AesInitializationVector iv;
1534 struct GNUNET_CRYPTO_RsaPrivateKey *pk;
1537 if ( (pkc->i == pkc->ksk_uri->data.ksk.keywordCount) ||
1538 (NULL == pkc->dsh) )
1540 if (NULL != pkc->dsh)
1542 GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
1545 GNUNET_free (pkc->cpy);
1546 GNUNET_free (pkc->kb);
1547 pkc->cont (pkc->cont_cls,
1550 GNUNET_FS_uri_destroy (pkc->ksk_uri);
1554 keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++];
1555 /* first character of keyword indicates if it is
1556 mandatory or not -- ignore for hashing */
1557 GNUNET_CRYPTO_hash (&keyword[1], strlen (&keyword[1]), &key);
1558 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
1559 GNUNET_CRYPTO_aes_encrypt (&pkc->kb[1],
1560 pkc->slen + pkc->mdsize,
1564 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key);
1565 GNUNET_assert (NULL != pk);
1566 GNUNET_CRYPTO_rsa_key_get_public (pk, &pkc->cpy->keyspace);
1567 GNUNET_CRYPTO_hash (&pkc->cpy->keyspace,
1568 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1570 GNUNET_assert (GNUNET_OK ==
1571 GNUNET_CRYPTO_rsa_sign (pk,
1573 &pkc->cpy->signature));
1574 GNUNET_CRYPTO_rsa_key_free (pk);
1575 GNUNET_DATASTORE_put (pkc->dsh,
1579 sizeof (struct KBlock) +
1582 GNUNET_BLOCK_TYPE_KBLOCK,
1585 pkc->expirationTime,
1587 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1594 * Publish a CHK under various keywords on GNUnet.
1596 * @param h handle to the file sharing subsystem
1597 * @param ksk_uri keywords to use
1598 * @param meta metadata to use
1599 * @param uri URI to refer to in the KBlock
1600 * @param expirationTime when the KBlock expires
1601 * @param anonymity anonymity level for the KBlock
1602 * @param priority priority for the KBlock
1603 * @param options publication options
1604 * @param cont continuation
1605 * @param cont_cls closure for cont
1608 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1609 const struct GNUNET_FS_Uri *ksk_uri,
1610 const struct GNUNET_CONTAINER_MetaData *meta,
1611 const struct GNUNET_FS_Uri *uri,
1612 struct GNUNET_TIME_Absolute expirationTime,
1615 enum GNUNET_FS_PublishOptions options,
1616 GNUNET_FS_PublishContinuation cont,
1619 struct PublishKskContext *pkc;
1625 pkc = GNUNET_malloc (sizeof (struct PublishKskContext));
1627 pkc->expirationTime = expirationTime;
1628 pkc->anonymity = anonymity;
1629 pkc->priority = priority;
1631 pkc->cont_cls = cont_cls;
1632 if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
1634 pkc->dsh = GNUNET_DATASTORE_connect (h->cfg,
1636 if (pkc->dsh == NULL)
1638 cont (cont_cls, NULL, _("Could not connect to datastore."));
1646 pkc->mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
1647 GNUNET_assert (pkc->mdsize >= 0);
1648 uris = GNUNET_FS_uri_to_string (uri);
1649 pkc->slen = strlen (uris) + 1;
1650 size = pkc->mdsize + sizeof (struct KBlock) + pkc->slen;
1651 if (size > MAX_KBLOCK_SIZE)
1653 size = MAX_KBLOCK_SIZE;
1654 pkc->mdsize = size - sizeof (struct KBlock) - pkc->slen;
1656 pkc->kb = GNUNET_malloc (size);
1657 kbe = (char *) &pkc->kb[1];
1658 memcpy (kbe, uris, pkc->slen);
1660 sptr = &kbe[pkc->slen];
1662 pkc->mdsize = GNUNET_CONTAINER_meta_data_serialize (meta,
1665 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
1666 if (pkc->mdsize == -1)
1669 GNUNET_free (pkc->kb);
1670 if (pkc->dsh != NULL)
1672 GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
1675 cont (cont_cls, NULL, _("Internal error."));
1679 size = sizeof (struct KBlock) + pkc->slen + pkc->mdsize;
1681 pkc->cpy = GNUNET_malloc (size);
1682 pkc->cpy->purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
1683 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
1686 pkc->cpy->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK);
1687 pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri);
1688 GNUNET_SCHEDULER_add_continuation (h->sched,
1691 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1696 * Context for the SKS publication.
1698 struct PublishSksContext
1702 * Global FS context.
1704 struct GNUNET_FS_Uri *uri;
1707 * Handle to the datastore.
1709 struct GNUNET_DATASTORE_Handle *dsh;
1712 * Function to call once we're done.
1714 GNUNET_FS_PublishContinuation cont;
1725 * Function called by the datastore API with
1726 * the result from the PUT (SBlock) request.
1728 * @param cls closure of type "struct PublishSksContext*"
1729 * @param success GNUNET_OK on success
1730 * @param msg error message (or NULL)
1733 sb_put_cont (void *cls,
1737 struct PublishSksContext *psc = cls;
1739 if (NULL != psc->dsh)
1741 GNUNET_DATASTORE_disconnect (psc->dsh, GNUNET_NO);
1744 if (GNUNET_OK != success)
1745 psc->cont (psc->cont_cls,
1749 psc->cont (psc->cont_cls,
1752 GNUNET_FS_uri_destroy (psc->uri);
1758 * Publish an SBlock on GNUnet.
1760 * @param h handle to the file sharing subsystem
1761 * @param namespace namespace to publish in
1762 * @param identifier identifier to use
1763 * @param update update identifier to use
1764 * @param meta metadata to use
1765 * @param uri URI to refer to in the SBlock
1766 * @param expirationTime when the SBlock expires
1767 * @param anonymity anonymity level for the SBlock
1768 * @param priority priority for the SBlock
1769 * @param options publication options
1770 * @param cont continuation
1771 * @param cont_cls closure for cont
1774 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
1775 struct GNUNET_FS_Namespace *namespace,
1776 const char *identifier,
1778 const struct GNUNET_CONTAINER_MetaData *meta,
1779 const struct GNUNET_FS_Uri *uri,
1780 struct GNUNET_TIME_Absolute expirationTime,
1783 enum GNUNET_FS_PublishOptions options,
1784 GNUNET_FS_PublishContinuation cont,
1787 struct PublishSksContext *psc;
1788 struct GNUNET_CRYPTO_AesSessionKey sk;
1789 struct GNUNET_CRYPTO_AesInitializationVector iv;
1790 struct GNUNET_FS_Uri *sks_uri;
1798 struct SBlock *sb_enc;
1800 struct GNUNET_CONTAINER_MetaData *mmeta;
1801 GNUNET_HashCode key; /* hash of thisId = key */
1802 GNUNET_HashCode id; /* hash of hc = identifier */
1803 GNUNET_HashCode query; /* id ^ nsid = DB query */
1806 mmeta = GNUNET_CONTAINER_meta_data_create ();
1808 mmeta = GNUNET_CONTAINER_meta_data_duplicate (meta);
1809 uris = GNUNET_FS_uri_to_string (uri);
1810 slen = strlen (uris) + 1;
1811 idlen = strlen (identifier);
1814 nidlen = strlen (update) + 1;
1815 mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (mmeta);
1816 size = sizeof (struct SBlock) + slen + nidlen + mdsize;
1817 if (size > MAX_SBLOCK_SIZE)
1819 size = MAX_SBLOCK_SIZE;
1820 mdsize = size - (sizeof (struct SBlock) + slen + nidlen);
1822 sb = GNUNET_malloc (sizeof (struct SBlock) + size);
1823 dest = (char *) &sb[1];
1824 memcpy (dest, update, nidlen);
1826 memcpy (dest, uris, slen);
1829 mdsize = GNUNET_CONTAINER_meta_data_serialize (mmeta,
1832 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
1833 GNUNET_CONTAINER_meta_data_destroy (mmeta);
1840 _("Internal error."));
1843 size = sizeof (struct SBlock) + mdsize + slen + nidlen;
1844 sb_enc = GNUNET_malloc (size);
1845 GNUNET_CRYPTO_hash (identifier, idlen, &key);
1846 GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &id);
1847 sks_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
1848 sks_uri->type = sks;
1849 GNUNET_CRYPTO_rsa_key_get_public (namespace->key, &sb_enc->subspace);
1850 GNUNET_CRYPTO_hash (&sb_enc->subspace,
1851 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1852 &sks_uri->data.sks.namespace);
1853 sks_uri->data.sks.identifier = GNUNET_strdup (identifier);
1854 GNUNET_CRYPTO_hash_xor (&id,
1855 &sks_uri->data.sks.namespace,
1856 &sb_enc->identifier);
1857 GNUNET_CRYPTO_hash_to_aes_key (&key, &sk, &iv);
1858 GNUNET_CRYPTO_aes_encrypt (&sb[1],
1859 size - sizeof (struct SBlock),
1863 sb_enc->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK);
1864 sb_enc->purpose.size = htonl(slen + mdsize + nidlen
1865 + sizeof(struct SBlock)
1866 - sizeof(struct GNUNET_CRYPTO_RsaSignature));
1867 GNUNET_assert (GNUNET_OK ==
1868 GNUNET_CRYPTO_rsa_sign (namespace->key,
1870 &sb_enc->signature));
1871 psc = GNUNET_malloc (sizeof(struct PublishSksContext));
1874 psc->cont_cls = cont_cls;
1875 if (0 != (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
1877 GNUNET_free (sb_enc);
1884 psc->dsh = GNUNET_DATASTORE_connect (h->cfg, h->sched);
1885 if (NULL == psc->dsh)
1887 GNUNET_free (sb_enc);
1891 _("Failed to connect to datastore."));
1894 GNUNET_CRYPTO_hash_xor (&sks_uri->data.sks.namespace,
1897 GNUNET_DATASTORE_put (psc->dsh,
1899 &sb_enc->identifier,
1902 GNUNET_BLOCK_TYPE_SBLOCK,
1907 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1911 GNUNET_free (sb_enc);
1914 /* end of fs_publish.c */