diff options
author | Yorhel <git@yorhel.nl> | 2013-06-30 18:15:30 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2013-06-30 18:15:30 +0200 |
commit | ff60b679e99392bf791657b067c72dfb90e7516a (patch) | |
tree | 06e7c3e3a97adf4ab74abcfc6961d94f788c56db | |
parent | 2f9820ba2b70d254323c851e8c8ea2dee9aff181 (diff) |
share/hash: Perform database check before hashing
-rw-r--r-- | src/share/conf.h | 3 | ||||
-rw-r--r-- | src/share/hash.c | 46 |
2 files changed, 42 insertions, 7 deletions
diff --git a/src/share/conf.h b/src/share/conf.h index 8ae767b..dd02c47 100644 --- a/src/share/conf.h +++ b/src/share/conf.h @@ -43,7 +43,8 @@ struct share_path_t { }; -#define share_conf_pathid(p) ((((uint32_t)(p)->s->c.id)<<16) + (p)->id) +#define share_conf_pathid2(sid, pid) (((uint32_t)(sid)<<16) + (uint32_t)(pid)) +#define share_conf_pathid(p) share_conf_pathid2((p)->s->c.id, (p)->id) typedef vec_t(share_t *) share_conf_shares_t; diff --git a/src/share/hash.c b/src/share/hash.c index a1f1c50..35e6c40 100644 --- a/src/share/hash.c +++ b/src/share/hash.c @@ -76,8 +76,9 @@ typedef struct { t_res *chunks; uint64_t filesize; uint64_t chunksize; - int chunknum; - int jobnum; + uint16_t chunknum; + uint8_t jobnum; + uint8_t idx; int fd; share_hash_work_t work[HASH_JOBS_PER_FILE]; char fn[]; @@ -106,14 +107,47 @@ __KHASH_IMPL(hashfiles, static kh_inline, share_fl_t *, char, 0, share_hash_inde static obj_t obj[1]; -static share_hash_fn_t *share_hash_fn_create(share_t *s, share_fl_t *fl, const char *path) { +static void share_hash_fn_destroy(share_hash_fn_t *fn) { + obj->jobs -= fn->jobnum; + if(obj->fns[fn->idx] == fn) + obj->fns[fn->idx] = NULL; + free(fn); +} + + +static void share_hash_fn_db(void *data, const char *tth) { + share_hash_fn_t *fn = data; + + if(ylog_enabled(YLOG_TRACE)) { + char res[49] = {}; + if(tth) + base32_encode(tth, res, 24); + else + strcpy(res, "nothing"); + ytrace("Database check for '%s': %s", fn->fn, res); + } + + /* No need to hash, consider this one done. */ + if(tth) { + /* TODO: Tell share/share.c that this file has a hash */ + share_hash_fn_destroy(fn); + return; + } + + /* TODO: Open file and continue with hashing */ +} + + +static void share_hash_fn_create(size_t idx, share_t *s, share_fl_t *fl, const char *path) { share_hash_fn_t *fn = malloc(offsetof(share_hash_fn_t, fn) + strlen(path)+1); fn->s = s; fn->fl = fl; fn->chunks = NULL; fn->fd = -1; + fn->idx = idx; strcpy(fn->fn, path); fn->filesize = share_fl_size(fl); + obj->fns[idx] = fn; fn->chunksize = HASH_MIN_CHUNK; while((fn->chunksize * (((uint64_t)1)<<(HASH_KEEP_LEVEL-1))) < fn->filesize) @@ -149,8 +183,8 @@ static share_hash_fn_t *share_hash_fn_create(share_t *s, share_fl_t *fl, const c * many jobs have been scheduled. */ obj->jobs += fn->jobnum; - /* TODO: Queue database check */ - return fn; + share_db_exists(fn->fn, fl->lastmod, fn->filesize, + share_conf_pathid2(s->c.id, fl->pathid), share_hash_fn_db, fn); } @@ -181,7 +215,7 @@ static void share_hash_queue_process() { kstring_t path = {}; share_share_fl_path(s, fl, &path); - obj->fns[slot] = share_hash_fn_create(s, fl, path.s); + share_hash_fn_create(slot, s, fl, path.s); free(path.s); /* Process the next item in the queue while there's still some stuff to do */ |