From: alex Date: Tue, 16 Nov 2021 06:17:45 +0000 (-0800) Subject: ... X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=063888f87ed492f6447a8f0f2bd1accdc32954bc;p=seeder ... --- diff --git a/src/block.c b/src/block.c index 14ac30f..6751864 100644 --- a/src/block.c +++ b/src/block.c @@ -113,3 +113,7 @@ int block_merkle_root(struct block *root) { return 1; } + +int block_pad(struct block *root) { + return -1; +} diff --git a/src/file.c b/src/file.c index f2780d2..2810dcb 100644 --- a/src/file.c +++ b/src/file.c @@ -24,6 +24,8 @@ int file_hash(struct file *file_p, int piece_length) { FILE *fp; if(NULL==file_p) { return -1; } + + // check that piece length is >=16kb and a power of 2 if((piece_length<16384)||(piece_length&&(piece_length&(piece_length-1)))) { return -1; } @@ -34,6 +36,11 @@ int file_hash(struct file *file_p, int piece_length) { return -1; } + /* generate piece_layers + * 1. grab all data and hash + * 2. generate piece layer merkle trees (padding to piece layer boundary) + * 3. generate merkle root from piece layer roots (balancing tree in process) + */ p = NULL; while(1) { size_t len = fread(data,sizeof(uint8_t),BLOCK_SIZE,fp); @@ -60,6 +67,9 @@ int file_hash(struct file *file_p, int piece_length) { fclose(fp); + // pad to appropiate piece layer size + // i.e. so each piece layer tree is balanced + int ratio = piece_length / BLOCK_SIZE; while(ratio>1) { if(block_merkle_layer(file_p->piece_layers)<0) { return -1; }