/**
* @file fs/fs_publish.c
* @brief publish a file or directory in GNUnet
- * @see http://gnunet.org/encoding.php3
+ * @see http://gnunet.org/encoding
* @author Krista Bennett
* @author Christian Grothoff
*
* TODO:
* - indexing cleanup: unindex on failure (can wait)
- * - persistence support (can wait)
* - datastore reservation support (optimization)
* - location URIs (publish with anonymity-level zero)
*/
/**
* Cleanup the publish context, we're done with it.
*
- * @param pc struct to clean up after
+ * @param cls struct to clean up after
+ * @param tc scheduler context
*/
static void
-publish_cleanup (struct GNUNET_FS_PublishContext *pc)
+publish_cleanup (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
+ struct GNUNET_FS_PublishContext *pc = cls;
+
GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
if (pc->namespace != NULL)
GNUNET_FS_namespace_delete (pc->namespace, GNUNET_NO);
GNUNET_free_non_null (pc->nid);
GNUNET_free_non_null (pc->nuid);
GNUNET_free_non_null (pc->serialization);
- GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
+ if (pc->dsh != NULL)
+ {
+ GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
+ pc->dsh = NULL;
+ }
if (pc->client != NULL)
GNUNET_CLIENT_disconnect (pc->client, GNUNET_NO);
GNUNET_free (pc);
if (GNUNET_SYSERR == pcc->sc->in_network_wait)
{
- /* we were aborted in the meantime,
- finish shutdown! */
- publish_cleanup (pcc->sc);
+ /* we were aborted in the meantime, finish shutdown! */
+ GNUNET_SCHEDULER_add_continuation (pcc->sc->h->sched,
+ &publish_cleanup,
+ pcc->sc,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ GNUNET_free (pcc);
return;
}
GNUNET_assert (GNUNET_YES == pcc->sc->in_network_wait);
pi.value.publish.eta = GNUNET_TIME_UNIT_ZERO;
pi.value.publish.specifics.completed.chk_uri = p->chk_uri;
p->client_info = GNUNET_FS_publish_make_status_ (&pi, sc, p,
- GNUNET_ntohll (p->chk_uri->data.chk.file_length));
+ GNUNET_ntohll (p->chk_uri->data.chk.file_length));
}
const struct GNUNET_FS_Uri *uri,
const char *emsg)
{
- struct GNUNET_FS_PublishContext *sc = cls;
+ struct GNUNET_FS_PublishContext *pc = cls;
if (NULL != emsg)
{
- signal_publish_error (sc->fi,
- sc,
+ signal_publish_error (pc->fi,
+ pc,
emsg);
+ GNUNET_FS_publish_sync_ (pc);
return;
}
// FIXME: release the datastore reserve here!
- signal_publish_completion (sc->fi, sc);
- sc->all_done = GNUNET_YES;
+ signal_publish_completion (pc->fi, pc);
+ pc->all_done = GNUNET_YES;
+ GNUNET_FS_publish_sync_ (pc);
}
const struct GNUNET_FS_Uri *uri,
const char *emsg)
{
- struct GNUNET_FS_PublishContext *sc = cls;
- struct GNUNET_FS_FileInformation *p = sc->fi_pos;
+ struct GNUNET_FS_PublishContext *pc = cls;
+ struct GNUNET_FS_FileInformation *p = pc->fi_pos;
if (NULL != emsg)
{
- signal_publish_error (p, sc, emsg);
- sc->upload_task
- = GNUNET_SCHEDULER_add_with_priority (sc->h->sched,
+ signal_publish_error (p, pc, emsg);
+ GNUNET_FS_file_information_sync_ (p);
+ GNUNET_FS_publish_sync_ (pc);
+ pc->upload_task
+ = GNUNET_SCHEDULER_add_with_priority (pc->h->sched,
GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
&GNUNET_FS_publish_main_,
- sc);
+ pc);
return;
}
if (NULL != p->dir)
- signal_publish_completion (p, sc);
+ signal_publish_completion (p, pc);
/* move on to next file */
if (NULL != p->next)
- sc->fi_pos = p->next;
+ pc->fi_pos = p->next;
else
- sc->fi_pos = p->dir;
- sc->upload_task
- = GNUNET_SCHEDULER_add_with_priority (sc->h->sched,
+ pc->fi_pos = p->dir;
+ GNUNET_FS_publish_sync_ (pc);
+ pc->upload_task
+ = GNUNET_SCHEDULER_add_with_priority (pc->h->sched,
GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
&GNUNET_FS_publish_main_,
- sc);
+ pc);
}
p->priority,
p->anonymity,
p->expirationTime,
+ -2, 1,
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
&ds_put_cont,
dpc_cls);
p->priority,
p->anonymity,
p->expirationTime,
+ -2, 1,
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
&ds_put_cont,
dpc_cls);
uint64_t size;
p = sc->fi_pos;
+ GNUNET_assert (p != NULL);
if (NULL == p->te)
{
if (p->is_directory)
GNUNET_FS_directory_builder_finish (db,
&p->data.dir.dir_size,
&p->data.dir.dir_data);
+ GNUNET_FS_file_information_sync_ (p);
}
size = (p->is_directory)
? p->data.dir.dir_size
p->filename,
_("timeout on index-start request to `fs' service"));
p->data.file.do_index = GNUNET_NO;
+ GNUNET_FS_file_information_sync_ (p);
publish_content (sc);
return;
}
p->filename,
gettext (emsg));
p->data.file.do_index = GNUNET_NO;
+ GNUNET_FS_file_information_sync_ (p);
publish_content (sc);
return;
}
p->data.file.index_start_confirmed = GNUNET_YES;
/* success! continue with indexing */
+ GNUNET_FS_file_information_sync_ (p);
publish_content (sc);
}
p->filename,
_("failed to compute hash"));
p->data.file.do_index = GNUNET_NO;
+ GNUNET_FS_file_information_sync_ (p);
publish_content (sc);
return;
}
_("filename too long"));
GNUNET_free (fn);
p->data.file.do_index = GNUNET_NO;
+ GNUNET_FS_file_information_sync_ (p);
publish_content (sc);
return;
}
GNUNET_free (fn);
return;
}
- p->data.file.file_id = *res;
- p->data.file.have_hash = GNUNET_YES;
+ if (p->data.file.have_hash != GNUNET_YES)
+ {
+ p->data.file.file_id = *res;
+ p->data.file.have_hash = GNUNET_YES;
+ GNUNET_FS_file_information_sync_ (p);
+ }
ism = GNUNET_malloc (sizeof(struct IndexStartMessage) +
slen);
ism->header.size = htons(sizeof(struct IndexStartMessage) +
GNUNET_FS_publish_main_ (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct GNUNET_FS_PublishContext *sc = cls;
+ struct GNUNET_FS_PublishContext *pc = cls;
struct GNUNET_FS_ProgressInfo pi;
struct GNUNET_FS_FileInformation *p;
char *fn;
- sc->upload_task = GNUNET_SCHEDULER_NO_TASK;
- p = sc->fi_pos;
+ pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
+ p = pc->fi_pos;
if (NULL == p)
{
/* upload of entire hierarchy complete,
publish namespace entries */
- publish_sblock (sc);
+ GNUNET_FS_publish_sync_ (pc);
+ publish_sblock (pc);
return;
}
/* find starting position */
(NULL == p->data.dir.entries->chk_uri) )
{
p = p->data.dir.entries;
- sc->fi_pos = p;
+ pc->fi_pos = p;
+ GNUNET_FS_publish_sync_ (pc);
}
/* abort on error */
if (NULL != p->emsg)
pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
pi.value.publish.specifics.error.message = p->emsg;
- p->client_info = GNUNET_FS_publish_make_status_ (&pi, sc, p, 0);
+ p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
}
- sc->all_done = GNUNET_YES;
+ pc->all_done = GNUNET_YES;
+ GNUNET_FS_publish_sync_ (pc);
return;
}
/* handle completion */
if (NULL != p->chk_uri)
{
+ GNUNET_FS_publish_sync_ (pc);
/* upload of "p" complete, publish KBlocks! */
if (p->keywords != NULL)
{
- GNUNET_FS_publish_ksk (sc->h,
+ GNUNET_FS_publish_ksk (pc->h,
p->keywords,
p->meta,
p->chk_uri,
p->expirationTime,
p->anonymity,
p->priority,
- sc->options,
+ pc->options,
&publish_kblocks_cont,
- sc);
+ pc);
}
else
{
- publish_kblocks_cont (sc,
+ publish_kblocks_cont (pc,
p->chk_uri,
NULL);
}
_("Can not index file `%s': %s. Will try to insert instead.\n"),
"<no-name>",
_("needs to be an actual file"));
- publish_content (sc);
+ GNUNET_FS_file_information_sync_ (p);
+ publish_content (pc);
return;
}
if (p->data.file.have_hash)
- hash_for_index_cb (sc,
- &p->data.file.file_id);
+ {
+ hash_for_index_cb (pc,
+ &p->data.file.file_id);
+ }
else
{
p->start_time = GNUNET_TIME_absolute_get ();
- GNUNET_CRYPTO_hash_file (sc->h->sched,
+ GNUNET_CRYPTO_hash_file (pc->h->sched,
GNUNET_SCHEDULER_PRIORITY_IDLE,
p->filename,
HASHING_BLOCKSIZE,
&hash_for_index_cb,
- sc);
+ pc);
}
return;
}
- publish_content (sc);
+ publish_content (pc);
}
pi.status = GNUNET_FS_STATUS_PUBLISH_START;
*client_info = GNUNET_FS_publish_make_status_ (&pi, sc, fi, 0);
+ GNUNET_FS_file_information_sync_ (fi);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Signal the FS's progress function that we are suspending
+ * an upload.
+ *
+ * @param cls closure (of type "struct GNUNET_FS_PublishContext*")
+ * @param fi the entry in the publish-structure
+ * @param length length of the file or directory
+ * @param meta metadata for the file or directory (can be modified)
+ * @param uri pointer to the keywords that will be used for this entry (can be modified)
+ * @param anonymity pointer to selected anonymity level (can be modified)
+ * @param priority pointer to selected priority (can be modified)
+ * @param expirationTime pointer to selected expiration time (can be modified)
+ * @param client_info pointer to client context set upon creation (can be modified)
+ * @return GNUNET_OK to continue (always)
+ */
+static int
+fip_signal_suspend(void *cls,
+ struct GNUNET_FS_FileInformation *fi,
+ uint64_t length,
+ struct GNUNET_CONTAINER_MetaData *meta,
+ struct GNUNET_FS_Uri **uri,
+ uint32_t *anonymity,
+ uint32_t *priority,
+ struct GNUNET_TIME_Absolute *expirationTime,
+ void **client_info)
+{
+ struct GNUNET_FS_PublishContext*sc = cls;
+ struct GNUNET_FS_ProgressInfo pi;
+ uint64_t off;
+
+ GNUNET_free_non_null (fi->serialization);
+ fi->serialization = NULL;
+ off = (fi->chk_uri == NULL) ? 0 : length;
+ pi.status = GNUNET_FS_STATUS_PUBLISH_SUSPEND;
+ GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, sc, fi, off));
+ *client_info = NULL;
+ if (NULL != sc->dsh)
+ {
+ GNUNET_DATASTORE_disconnect (sc->dsh, GNUNET_NO);
+ sc->dsh = NULL;
+ }
return GNUNET_OK;
}
*
* @param cls the 'struct GNUNET_FS_PublishContext' to signal for
*/
-static void
-publish_signal_suspend (void *cls)
+void
+GNUNET_FS_publish_signal_suspend_ (void *cls)
{
struct GNUNET_FS_PublishContext *pc = cls;
+ if (GNUNET_SCHEDULER_NO_TASK != pc->upload_task)
+ {
+ GNUNET_SCHEDULER_cancel (pc->h->sched, pc->upload_task);
+ pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ GNUNET_FS_file_information_inspect (pc->fi,
+ &fip_signal_suspend,
+ pc);
GNUNET_FS_end_top (pc->h, pc->top);
- /* FIXME: signal! */
- GNUNET_free (pc);
+ publish_cleanup (pc, NULL);
}
+
/**
* Publish a file or directory.
*
if (NULL != nuid)
ret->nuid = GNUNET_strdup (nuid);
}
- GNUNET_FS_publish_sync_ (ret);
/* signal start */
GNUNET_FS_file_information_inspect (ret->fi,
&fip_signal_start,
ret);
ret->fi_pos = ret->fi;
- ret->top = GNUNET_FS_make_top (h, &publish_signal_suspend, ret);
+ ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, ret);
+ GNUNET_FS_publish_sync_ (ret);
// FIXME: calculate space needed for "fi"
// and reserve as first task (then trigger
// "publish_main" from that continuation)!
if (fi->serialization != NULL)
{
- if (0 != UNLINK (fi->serialization))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "unlink",
- fi->serialization);
- }
+ GNUNET_FS_remove_sync_file_ (sc->h,
+ GNUNET_FS_SYNC_PATH_FILE_INFO,
+ fi->serialization);
GNUNET_free (fi->serialization);
fi->serialization = NULL;
}
GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc)
{
GNUNET_FS_end_top (pc->h, pc->top);
+ if (NULL != pc->dsh)
+ {
+ GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
+ pc->dsh = NULL;
+ }
if (GNUNET_SCHEDULER_NO_TASK != pc->upload_task)
- GNUNET_SCHEDULER_cancel (pc->h->sched, pc->upload_task);
+ {
+ 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, "publish", pc->serialization);
+ GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, pc->serialization);
GNUNET_free (pc->serialization);
pc->serialization = NULL;
}
pc->in_network_wait = GNUNET_SYSERR;
return;
}
- publish_cleanup (pc);
+ publish_cleanup (pc, NULL);
}
if (GNUNET_OK != success)
{
- GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
+ 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 == pkc->dsh) )
{
if (NULL != pkc->dsh)
- GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
+ {
+ GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
+ pkc->dsh = NULL;
+ }
GNUNET_free (pkc->cpy);
GNUNET_free (pkc->kb);
pkc->cont (pkc->cont_cls,
pkc->priority,
pkc->anonymity,
pkc->expirationTime,
+ -2, 1,
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
&kb_put_cont,
pkc);
GNUNET_break (0);
GNUNET_free (pkc->kb);
if (pkc->dsh != NULL)
- GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
+ {
+ GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
+ pkc->dsh = NULL;
+ }
cont (cont_cls, NULL, _("Internal error."));
GNUNET_free (pkc);
return;
struct PublishSksContext *psc = cls;
if (NULL != psc->dsh)
- GNUNET_DATASTORE_disconnect (psc->dsh, GNUNET_NO);
+ {
+ GNUNET_DATASTORE_disconnect (psc->dsh, GNUNET_NO);
+ psc->dsh = NULL;
+ }
if (GNUNET_OK != success)
psc->cont (psc->cont_cls,
NULL,
memcpy (dest, update, nidlen);
dest += nidlen;
memcpy (dest, uris, slen);
+ GNUNET_free (uris);
dest += slen;
mdsize = GNUNET_CONTAINER_meta_data_serialize (mmeta,
&dest,
if (mdsize == -1)
{
GNUNET_break (0);
- GNUNET_free (uris);
GNUNET_free (sb);
cont (cont_cls,
NULL,
priority,
anonymity,
expirationTime,
+ -2, 1,
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
&sb_put_cont,
psc);
-
GNUNET_free (sb);
GNUNET_free (sb_enc);
}