}
+/**
+ * Synchronize this unindex struct with its mirror
+ * on disk. Note that all internal FS-operations that change
+ * publishing structs should already call "sync" internally,
+ * so this function is likely not useful for clients.
+ *
+ * @param uc the struct to sync
+ */
+void
+GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc)
+{
+ /* FIXME */
+}
+
+
/**
* Deserialize information about pending publish operations.
*
struct GNUNET_FS_Handle *h = cls;
struct GNUNET_BIO_ReadHandle *rh;
struct GNUNET_FS_UnindexContext *uc;
+ struct GNUNET_FS_ProgressInfo pi;
char *emsg;
+ uint32_t state;
uc = GNUNET_malloc (sizeof (struct GNUNET_FS_UnindexContext));
uc->h = h;
rh = GNUNET_BIO_read_open (filename);
if (rh == NULL)
goto cleanup;
- /* FIXME: do unindex state here! */
-#if 0
if ( (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) ||
+ GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10*1024)) ||
(GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) ||
+ GNUNET_BIO_read_int64 (rh, &uc->file_size)) ||
(GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &options)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &all_done)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) ||
+ GNUNET_BIO_read_int64 (rh, &uc->start_time.value)) ||
(GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "publish-ns", &ns, 1024)) )
+ GNUNET_BIO_read_int32 (rh, &state)) )
goto cleanup;
- pc->options = options;
- pc->all_done = all_done;
- pc->fi = deserialize_file_information (h, fi_root);
- if (pc->fi == NULL)
- goto cleanup;
-#endif
- /* FIXME: generate RESUME event */
- /* FIXME: re-start unindexing (if needed)... */
+ uc->state = (enum UnindexState) state;
+ switch (state)
+ {
+ case UNINDEX_STATE_HASHING:
+ break;
+ case UNINDEX_STATE_FS_NOTIFY:
+ if (GNUNET_OK !=
+ GNUNET_BIO_read (rh, "unindex-hash", &uc->file_id, sizeof (GNUNET_HashCode)))
+ goto cleanup;
+ break;
+ case UNINDEX_STATE_DS_REMOVE:
+ break;
+ case UNINDEX_STATE_COMPLETE:
+ break;
+ case UNINDEX_STATE_ERROR:
+ if (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "unindex-emsg", &uc->emsg, 10*1024))
+ goto cleanup;
+ break;
+ case UNINDEX_STATE_ABORTED:
+ GNUNET_break (0);
+ goto cleanup;
+ default:
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME;
+ pi.value.unindex.specifics.resume.message = uc->emsg;
+ GNUNET_FS_unindex_make_status_ (&pi,
+ uc,
+ (uc->state == UNINDEX_STATE_COMPLETE)
+ ? uc->file_size
+ : 0);
switch (uc->state)
{
+ case UNINDEX_STATE_HASHING:
+ GNUNET_CRYPTO_hash_file (uc->h->sched,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ uc->filename,
+ HASHING_BLOCKSIZE,
+ &GNUNET_FS_unindex_process_hash_,
+ uc);
+ break;
+ case UNINDEX_STATE_FS_NOTIFY:
+ uc->state = UNINDEX_STATE_HASHING;
+ GNUNET_FS_unindex_process_hash_ (uc,
+ &uc->file_id);
+ break;
+ case UNINDEX_STATE_DS_REMOVE:
+ GNUNET_FS_unindex_do_remove_ (uc);
+ break;
+ case UNINDEX_STATE_COMPLETE:
+ case UNINDEX_STATE_ERROR:
+ /* no need to resume any operation, we were done */
+ break;
default:
break;
}
filename,
emsg);
GNUNET_free (emsg);
- rh = NULL;
- goto cleanup;
}
return GNUNET_OK;
cleanup:
- /* FIXME: clean unindex state here! */
-#if 0
- GNUNET_free_non_null (pc->nid);
- GNUNET_free_non_null (pc->nuid);
- GNUNET_free_non_null (fi_root);
- GNUNET_free_non_null (ns);
-#endif
+ GNUNET_free_non_null (uc->filename);
if ( (rh != NULL) &&
(GNUNET_OK !=
GNUNET_BIO_read_close (rh, &emsg)) )
}
-
-
/**
* Deserialize information about pending publish operations.
*
const struct GNUNET_SCHEDULER_TaskContext *tc);
+/**
+ * Function called once the hash of the file
+ * that is being unindexed has been computed.
+ *
+ * @param cls closure, unindex context
+ * @param file_id computed hash, NULL on error
+ */
+void
+GNUNET_FS_unindex_process_hash_ (void *cls,
+ const GNUNET_HashCode *file_id);
+
+
/**
* Fill in all of the generic fields for a publish event and call the
* callback.
const struct GNUNET_FS_FileInformation *p,
uint64_t offset);
+/**
+ * Fill in all of the generic fields for
+ * an unindex event and call the callback.
+ *
+ * @param pi structure to fill in
+ * @param uc overall unindex context
+ * @param offset where we are in the file (for progress)
+ */
+void
+GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
+ struct GNUNET_FS_UnindexContext *uc,
+ uint64_t offset);
+
+/**
+ * Connect to the datastore and remove the blocks.
+ *
+ * @param uc context for the unindex operation.
+ */
+void
+GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
+
/**
* Remove serialization/deserialization file from disk.
GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
+/**
+ * Synchronize this unindex struct with its mirror
+ * on disk. Note that all internal FS-operations that change
+ * publishing structs should already call "sync" internally,
+ * so this function is likely not useful for clients.
+ *
+ * @param uc the struct to sync
+ */
+void
+GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
+
+
/**
* Master context for most FS operations.
*/
struct GNUNET_DISK_FileHandle *fh;
+ /**
+ * Error message, NULL on success.
+ */
+ char *emsg;
+
/**
* Overall size of the file.
*/
struct GNUNET_FS_TreeEncoder *te;
GNUNET_assert (size > 0);
- te = GNUNET_malloc (sizeof (struct GNUNET_FS_TreeEncoder));
+ te = GNUNET_malloc (sizeof (struct GNUNET_FS_TreeEncoder));
te->h = h;
te->size = size;
te->cls = cls;
/**
* Fill in all of the generic fields for
- * an unindex event.
+ * an unindex event and call the callback.
*
* @param pi structure to fill in
* @param uc overall unindex context
* @param offset where we are in the file (for progress)
*/
-static void
-make_unindex_status (struct GNUNET_FS_ProgressInfo *pi,
- struct GNUNET_FS_UnindexContext *uc,
- uint64_t offset)
+void
+GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
+ struct GNUNET_FS_UnindexContext *uc,
+ uint64_t offset)
{
pi->value.unindex.uc = uc;
pi->value.unindex.cctx = uc->client_info;
uc->file_size);
pi->value.unindex.duration = GNUNET_TIME_absolute_get_duration (uc->start_time);
pi->value.unindex.completed = offset;
+ uc->client_info
+ = uc->h->upcb (uc->h->upcb_cls,
+ pi);
+
}
struct GNUNET_FS_ProgressInfo pi;
pi.status = GNUNET_FS_STATUS_UNINDEX_PROGRESS;
- make_unindex_status (&pi, uc, offset);
pi.value.unindex.specifics.progress.data = pt_block;
pi.value.unindex.specifics.progress.offset = offset;
pi.value.unindex.specifics.progress.data_len = pt_size;
pi.value.unindex.specifics.progress.depth = depth;
- uc->client_info
- = uc->h->upcb (uc->h->upcb_cls,
- &pi);
+ GNUNET_FS_unindex_make_status_ (&pi, uc, offset);
}
struct GNUNET_FS_ProgressInfo pi;
pi.status = GNUNET_FS_STATUS_UNINDEX_ERROR;
- make_unindex_status (&pi, uc, 0);
pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL;
pi.value.unindex.specifics.error.message = emsg;
- uc->client_info
- = uc->h->upcb (uc->h->upcb_cls,
- &pi);
+ GNUNET_FS_unindex_make_status_ (&pi, uc, 0);
}
else
{
pi.status = GNUNET_FS_STATUS_UNINDEX_COMPLETED;
- make_unindex_status (&pi, uc, uc->file_size);
pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO;
- uc->client_info
- = uc->h->upcb (uc->h->upcb_cls,
- &pi);
+ GNUNET_FS_unindex_make_status_ (&pi, uc, uc->file_size);
}
}
{
struct GNUNET_FS_UnindexContext *uc = cls;
- GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO);
- uc->client = NULL;
+ if (uc->client != NULL)
+ {
+ GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO);
+ uc->client = NULL;
+ }
if (uc->state != UNINDEX_STATE_FS_NOTIFY)
{
GNUNET_FS_unindex_stop (uc);
return;
}
uc->state = UNINDEX_STATE_DS_REMOVE;
+ GNUNET_FS_unindex_do_remove_ (uc);
+}
+
+
+/**
+ * Connect to the datastore and remove the blocks.
+ *
+ * @param uc context for the unindex operation.
+ */
+void
+GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc)
+{
uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg,
uc->h->sched);
if (NULL == uc->dsh)
* @param cls closure, unindex context
* @param file_id computed hash, NULL on error
*/
-static void
-process_hash (void *cls,
- const GNUNET_HashCode *file_id)
+void
+GNUNET_FS_unindex_process_hash_ (void *cls,
+ const GNUNET_HashCode *file_id)
{
struct GNUNET_FS_UnindexContext *uc = cls;
struct UnindexMessage req;
// FIXME: make persistent!
pi.status = GNUNET_FS_STATUS_UNINDEX_START;
- make_unindex_status (&pi, ret, 0);
pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL;
- ret->client_info
- = h->upcb (h->upcb_cls,
- &pi);
+ GNUNET_FS_unindex_make_status_ (&pi, ret, 0);
GNUNET_CRYPTO_hash_file (h->sched,
GNUNET_SCHEDULER_PRIORITY_IDLE,
filename,
HASHING_BLOCKSIZE,
- &process_hash,
+ &GNUNET_FS_unindex_process_hash_,
ret);
return ret;
}
GNUNET_FS_remove_sync_file_ (uc->h, "unindex", uc->serialization);
uc->serialization = NULL;
}
- make_unindex_status (&pi, uc,
- (uc->state == UNINDEX_STATE_COMPLETE)
- ? uc->file_size : 0);
pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED;
pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO;
- uc->client_info
- = uc->h->upcb (uc->h->upcb_cls,
- &pi);
+ GNUNET_FS_unindex_make_status_ (&pi, uc,
+ (uc->state == UNINDEX_STATE_COMPLETE)
+ ? uc->file_size : 0);
GNUNET_break (NULL == uc->client_info);
GNUNET_free (uc->filename);
GNUNET_free_non_null (uc->serialization);