+ GNUNET_MQ_send (pc->mq,
+ env);
+}
+
+
+/**
+ * We've computed the CHK/LOC URI, now publish the KSKs (if applicable).
+ *
+ * @param pc publishing context to do this for
+ */
+static void
+publish_kblocks (struct GNUNET_FS_PublishContext *pc)
+{
+ struct GNUNET_FS_FileInformation *p;
+
+ p = pc->fi_pos;
+ /* upload of "p" complete, publish KBlocks! */
+ if (NULL != p->keywords)
+ {
+ pc->ksk_pc = GNUNET_FS_publish_ksk (pc->h,
+ p->keywords,
+ p->meta,
+ p->chk_uri,
+ &p->bo,
+ pc->options,
+ &publish_kblocks_cont,
+ pc);
+ }
+ else
+ {
+ publish_kblocks_cont (pc, p->chk_uri, NULL);
+ }
+}
+
+
+/**
+ * Process the response from the "fs" service to our LOC sign request.
+ *
+ * @param cls closure (of type `struct GNUNET_FS_PublishContext *`)
+ * @param sig the response we got
+ */
+static void
+handle_signature_response (void *cls,
+ const struct ResponseLocSignatureMessage *sig)
+{
+ struct GNUNET_FS_PublishContext *pc = cls;
+ struct GNUNET_FS_FileInformation *p;
+
+ p = pc->fi_pos;
+ p->chk_uri->type = GNUNET_FS_URI_LOC;
+ /* p->data.loc.fi kept from CHK before */
+ p->chk_uri->data.loc.peer = sig->peer;
+ p->chk_uri->data.loc.expirationTime
+ = GNUNET_TIME_absolute_ntoh (sig->expiration_time);
+ p->chk_uri->data.loc.contentSignature = sig->signature;
+ GNUNET_FS_file_information_sync_ (p);
+ GNUNET_FS_publish_sync_ (pc);
+ publish_kblocks (pc);
+}
+
+
+/**
+ * Generic error handler, called with the appropriate error code and
+ * the same closure specified at the creation of the message queue.
+ * Not every message queue implementation supports an error handler.
+ *
+ * @param cls closure with the `struct GNUNET_FS_PublishContext *`
+ * @param error error code
+ */
+static void
+loc_mq_error_handler (void *cls,
+ enum GNUNET_MQ_Error error)
+{
+ struct GNUNET_FS_PublishContext *pc = cls;
+
+ if (NULL != pc->mq)
+ {
+ GNUNET_MQ_destroy (pc->mq);
+ pc->mq = NULL;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Can not create LOC URI. Will continue with CHK instead.\n"));
+ publish_kblocks (pc);
+}
+
+
+/**
+ * We're publishing without anonymity. Contact the FS service
+ * to create a signed LOC URI for further processing, then
+ * continue with KSKs.
+ *
+ * @param pc the publishing context do to this for
+ */
+static void
+create_loc_uri (struct GNUNET_FS_PublishContext *pc)
+{
+ struct GNUNET_MQ_MessageHandler handlers[] = {
+ GNUNET_MQ_hd_fixed_size (signature_response,
+ GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE,
+ struct ResponseLocSignatureMessage,
+ pc),
+ GNUNET_MQ_handler_end ()
+ };
+ struct GNUNET_MQ_Envelope *env;
+ struct RequestLocSignatureMessage *req;
+ struct GNUNET_FS_FileInformation *p;
+
+ if (NULL != pc->mq)
+ GNUNET_MQ_destroy (pc->mq);
+ pc->mq = GNUNET_CLIENT_connect (pc->h->cfg,
+ "fs",
+ handlers,
+ &loc_mq_error_handler,
+ pc);
+ if (NULL == pc->mq)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Can not create LOC URI. Will continue with CHK instead.\n"));
+ publish_kblocks (pc);
+ return;
+ }
+ p = pc->fi_pos;
+ env = GNUNET_MQ_msg (req,
+ GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN);
+ req->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT);
+ req->expiration_time = GNUNET_TIME_absolute_hton (p->bo.expiration_time);
+ req->chk = p->chk_uri->data.chk.chk;
+ req->file_length = GNUNET_htonll (p->chk_uri->data.chk.file_length);
+ GNUNET_MQ_send (pc->mq,
+ env);