- {
- GNUNET_SCHEDULER_cancel (pc->h->sched, pc->upload_task);
- pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
- }
- if (pc->serialization != NULL)
- {
- GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, pc->serialization);
- GNUNET_free (pc->serialization);
- pc->serialization = NULL;
- }
- GNUNET_FS_file_information_inspect (pc->fi,
- &fip_signal_stop,
- pc);
- if (GNUNET_YES == pc->in_network_wait)
- {
- pc->in_network_wait = GNUNET_SYSERR;
- return;
- }
- publish_cleanup (pc, NULL);
-}
-
-
-/**
- * Context for the KSK publication.
- */
-struct PublishKskContext
-{
-
- /**
- * Keywords to use.
- */
- struct GNUNET_FS_Uri *ksk_uri;
-
- /**
- * Global FS context.
- */
- struct GNUNET_FS_Handle *h;
-
- /**
- * The master block that we are sending
- * (in plaintext), has "mdsize+slen" more
- * bytes than the struct would suggest.
- */
- struct KBlock *kb;
-
- /**
- * Buffer of the same size as "kb" for
- * the encrypted version.
- */
- struct KBlock *cpy;
-
- /**
- * Handle to the datastore, NULL if we are just
- * simulating.
- */
- struct GNUNET_DATASTORE_Handle *dsh;
-
- /**
- * Function to call once we're done.
- */
- GNUNET_FS_PublishContinuation cont;
-
- /**
- * Closure for cont.
- */
- void *cont_cls;
-
- /**
- * When should the KBlocks expire?
- */
- struct GNUNET_TIME_Absolute expirationTime;
-
- /**
- * Size of the serialized metadata.
- */
- ssize_t mdsize;
-
- /**
- * Size of the (CHK) URI as a string.
- */
- size_t slen;
-
- /**
- * Keyword that we are currently processing.
- */
- unsigned int i;
-
- /**
- * Anonymity level for the KBlocks.
- */
- uint32_t anonymity;
-
- /**
- * Priority for the KBlocks.
- */
- uint32_t priority;
-};
-
-
-/**
- * Continuation of "GNUNET_FS_publish_ksk" that performs
- * the actual publishing operation (iterating over all
- * of the keywords).
- *
- * @param cls closure of type "struct PublishKskContext*"
- * @param tc unused
- */
-static void
-publish_ksk_cont (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
-
-
-/**
- * Function called by the datastore API with
- * the result from the PUT request.
- *
- * @param cls closure of type "struct PublishKskContext*"
- * @param success GNUNET_OK on success
- * @param msg error message (or NULL)
- */
-static void
-kb_put_cont (void *cls,
- int success,
- const char *msg)
-{
- struct PublishKskContext *pkc = cls;
-
- if (GNUNET_OK != success)
- {
- if (NULL != pkc->dsh)
- {
- GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
- pkc->dsh = NULL;
- }
- GNUNET_free (pkc->cpy);
- GNUNET_free (pkc->kb);
- pkc->cont (pkc->cont_cls,
- NULL,
- msg);
- GNUNET_FS_uri_destroy (pkc->ksk_uri);
- GNUNET_free (pkc);
- return;
- }
- GNUNET_SCHEDULER_add_continuation (pkc->h->sched,
- &publish_ksk_cont,
- pkc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
-}
-
-
-/**
- * Continuation of "GNUNET_FS_publish_ksk" that performs the actual
- * publishing operation (iterating over all of the keywords).
- *
- * @param cls closure of type "struct PublishKskContext*"
- * @param tc unused
- */
-static void
-publish_ksk_cont (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- struct PublishKskContext *pkc = cls;
- const char *keyword;
- GNUNET_HashCode key;
- GNUNET_HashCode query;
- struct GNUNET_CRYPTO_AesSessionKey skey;
- struct GNUNET_CRYPTO_AesInitializationVector iv;
- struct GNUNET_CRYPTO_RsaPrivateKey *pk;
-
-
- if ( (pkc->i == pkc->ksk_uri->data.ksk.keywordCount) ||
- (NULL == pkc->dsh) )
- {
- if (NULL != pkc->dsh)
- {
- GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
- pkc->dsh = NULL;
- }
- GNUNET_free (pkc->cpy);
- GNUNET_free (pkc->kb);
- pkc->cont (pkc->cont_cls,
- pkc->ksk_uri,
- NULL);
- GNUNET_FS_uri_destroy (pkc->ksk_uri);
- GNUNET_free (pkc);
- return;
- }
- keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++];
- /* first character of keyword indicates if it is
- mandatory or not -- ignore for hashing */
- GNUNET_CRYPTO_hash (&keyword[1], strlen (&keyword[1]), &key);
- GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
- GNUNET_CRYPTO_aes_encrypt (&pkc->kb[1],
- pkc->slen + pkc->mdsize,
- &skey,
- &iv,
- &pkc->cpy[1]);
- pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key);
- GNUNET_assert (NULL != pk);
- GNUNET_CRYPTO_rsa_key_get_public (pk, &pkc->cpy->keyspace);
- GNUNET_CRYPTO_hash (&pkc->cpy->keyspace,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &query);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_rsa_sign (pk,
- &pkc->cpy->purpose,
- &pkc->cpy->signature));
- GNUNET_CRYPTO_rsa_key_free (pk);
- GNUNET_DATASTORE_put (pkc->dsh,
- 0,
- &query,
- pkc->mdsize +
- sizeof (struct KBlock) +
- pkc->slen,
- pkc->cpy,
- GNUNET_BLOCK_TYPE_KBLOCK,
- pkc->priority,
- pkc->anonymity,
- pkc->expirationTime,
- -2, 1,
- GNUNET_CONSTANTS_SERVICE_TIMEOUT,
- &kb_put_cont,
- pkc);
+ {
+ GNUNET_SCHEDULER_cancel (pc->upload_task);
+ pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ pc->skip_next_fi_callback = GNUNET_YES;
+ GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_stop, pc);
+
+ if (pc->fi->serialization != NULL)
+ {
+ GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO,
+ pc->fi->serialization);
+ GNUNET_free (pc->fi->serialization);
+ pc->fi->serialization = NULL;
+ }
+ off = (pc->fi->chk_uri == NULL) ? 0 : GNUNET_ntohll (pc->fi->chk_uri->data.chk.file_length);
+
+ if (pc->serialization != NULL)
+ {
+ GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
+ pc->serialization);
+ GNUNET_free (pc->serialization);
+ pc->serialization = NULL;
+ }
+ if (NULL != pc->qre)
+ {
+ GNUNET_DATASTORE_cancel (pc->qre);
+ pc->qre = NULL;
+ }
+ pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED;
+ GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, pc->fi, off));
+ publish_cleanup (pc);