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; }
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) {