From: alex Date: Wed, 24 Nov 2021 06:07:20 +0000 (-0800) Subject: ... X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=1e0b3dfc6e24957bcf9c62fdeec5fe6c4afe2bca;p=seeder ... --- diff --git a/src/file.c b/src/file.c index e3fbf90..0fcc7a2 100644 --- a/src/file.c +++ b/src/file.c @@ -22,7 +22,7 @@ void file_free(struct file *p) { int file_hash(struct file *file_p, int piece_length) { uint8_t data[BLOCK_SIZE]; - struct block *p, *next, *layer_p; + struct block *p, *next; FILE *fp; if(NULL==file_p) { return -1; } @@ -81,13 +81,26 @@ clean: return -1; } -static int file_piece_layers(struct file *p, int piece_length) { +static int file_piece_layers(struct file *file_p, int piece_length) { + struct block *p, *last; + size_t blocks; int ratio; ratio = piece_length / BLOCK_SIZE; - return -1; + + blocks = 0; + p = file_p->piece_layers; + last = p; + while(p->next!=NULL) { + p = p->next; + blocks++; + if(blocks%ratio==0) { + last = p; + } + } + for(int i=1;i1) { diff --git a/test/unit/file.tests.c b/test/unit/file.tests.c index 3163cd7..8f1daba 100644 --- a/test/unit/file.tests.c +++ b/test/unit/file.tests.c @@ -117,6 +117,7 @@ static void file_hash_large_piece_test() { file_free(p); reset_env(); blocks >>= 1; + blocks++; } }