From: Christian Grothoff Date: Sat, 1 May 2010 11:11:18 +0000 (+0000) Subject: deserialization of unindex operations X-Git-Tag: initial-import-from-subversion-38251~21934 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=a049ae12c49803acf2f1b5615527d604d6cc0e19;p=oweals%2Fgnunet.git deserialization of unindex operations --- diff --git a/src/fs/fs.c b/src/fs/fs.c index df0bf881a..417461404 100644 --- a/src/fs/fs.c +++ b/src/fs/fs.c @@ -1190,6 +1190,21 @@ 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) +{ + /* FIXME */ +} + + /** * Deserialize information about pending publish operations. * @@ -1225,7 +1240,9 @@ deserialize_unindex_file (void *cls, 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; @@ -1233,33 +1250,70 @@ deserialize_unindex_file (void *cls, 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; } @@ -1271,18 +1325,10 @@ deserialize_unindex_file (void *cls, 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)) ) @@ -1301,8 +1347,6 @@ deserialize_unindex_file (void *cls, } - - /** * Deserialize information about pending publish operations. * diff --git a/src/fs/fs.h b/src/fs/fs.h index 7100b1657..9441b76e0 100644 --- a/src/fs/fs.h +++ b/src/fs/fs.h @@ -657,6 +657,18 @@ GNUNET_FS_publish_main_ (void *cls, 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. @@ -673,6 +685,27 @@ GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi, 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. @@ -711,6 +744,18 @@ void 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. @@ -982,6 +1027,11 @@ struct GNUNET_FS_UnindexContext */ struct GNUNET_DISK_FileHandle *fh; + /** + * Error message, NULL on success. + */ + char *emsg; + /** * Overall size of the file. */ diff --git a/src/fs/fs_tree.c b/src/fs/fs_tree.c index 15e13be21..c8cb8bab0 100644 --- a/src/fs/fs_tree.c +++ b/src/fs/fs_tree.c @@ -173,7 +173,7 @@ GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h, 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; diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c index acb3a2068..4b4e526dd 100644 --- a/src/fs/fs_unindex.c +++ b/src/fs/fs_unindex.c @@ -77,16 +77,16 @@ unindex_reader (void *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; @@ -98,6 +98,10 @@ make_unindex_status (struct GNUNET_FS_ProgressInfo *pi, 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); + } @@ -122,14 +126,11 @@ unindex_progress (void *cls, 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); } @@ -147,12 +148,9 @@ signal_unindex_error (struct GNUNET_FS_UnindexContext *uc, 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); } @@ -262,11 +260,8 @@ unindex_finish (void *cls, 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); } } @@ -284,8 +279,11 @@ process_fs_response (void *cls, { 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); @@ -306,6 +304,18 @@ process_fs_response (void *cls, 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) @@ -345,9 +355,9 @@ process_fs_response (void *cls, * @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; @@ -414,16 +424,13 @@ GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, // 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; } @@ -450,14 +457,11 @@ GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc) 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);