]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Wed, 24 Nov 2021 06:07:20 +0000 (22:07 -0800)
committeralex <[email protected]>
Wed, 24 Nov 2021 06:07:20 +0000 (22:07 -0800)
src/file.c
test/unit/file.tests.c

index e3fbf906dd0c3899c9e1bc6b4f1fc2fb95059f04..0fcc7a280f609f8f6b74d912745a5a5dab85ca78 100644 (file)
@@ -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;i<ratio;i<<=1) {
-               if(block_pad(layer_p)<0) { return -1; }
+               if(block_pad(last)<0) { return -1; }
        }
 
        while(ratio>1) {
index 3163cd77d0b8af9328090835060d7a9228934a58..8f1daba1baf8cfee1281935c86e2c8d68d0b6b6b 100644 (file)
@@ -117,6 +117,7 @@ static void file_hash_large_piece_test() {
                file_free(p);
                reset_env();
                blocks >>= 1;
+               blocks++;
        }
 }