👼
This commit is contained in:
BIN
A3/src/cascade
BIN
A3/src/cascade
Binary file not shown.
@ -147,6 +147,8 @@ void download_only_peer(char *cascade_file)
|
|||||||
{
|
{
|
||||||
get_block(queue[i], peer, hash_buf, output_file);
|
get_block(queue[i], peer, hash_buf, output_file);
|
||||||
}
|
}
|
||||||
|
// TODO test if everything is all right
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
free_resources();
|
free_resources();
|
||||||
@ -414,14 +416,11 @@ void get_block(csc_block_t* block, csc_peer_t peer, unsigned char* hash, char* o
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char block_data[msglen];
|
|
||||||
memcpy(block_data,&rio_buf[PEER_RESPONSE_HEADER_SIZE],msglen);
|
|
||||||
|
|
||||||
uint8_t shabuffer[SHA256_HASH_SIZE];
|
uint8_t shabuffer[SHA256_HASH_SIZE];
|
||||||
|
|
||||||
SHA256_CTX shactx;
|
SHA256_CTX shactx;
|
||||||
sha256_init(&shactx);
|
sha256_init(&shactx);
|
||||||
sha256_update(&shactx, block_data, msglen);
|
sha256_update(&shactx, &rio_buf[PEER_RESPONSE_HEADER_SIZE], msglen);
|
||||||
sha256_final(&shactx, &shabuffer);
|
sha256_final(&shactx, &shabuffer);
|
||||||
|
|
||||||
if (memcmp(shabuffer, (&block->hash)->x, SHA256_HASH_SIZE) != 0) {
|
if (memcmp(shabuffer, (&block->hash)->x, SHA256_HASH_SIZE) != 0) {
|
||||||
@ -439,7 +438,7 @@ void get_block(csc_block_t* block, csc_peer_t peer, unsigned char* hash, char* o
|
|||||||
}
|
}
|
||||||
|
|
||||||
fseek(fp, block->offset, SEEK_SET);
|
fseek(fp, block->offset, SEEK_SET);
|
||||||
fputs(block_data,fp);
|
fputs(&rio_buf[0,PEER_RESPONSE_HEADER_SIZE],fp);
|
||||||
|
|
||||||
printf("Got block %d. Wrote from %d to %d\n", block->index, block->offset, block->offset+msglen-1);
|
printf("Got block %d. Wrote from %d to %d\n", block->index, block->offset, block->offset+msglen-1);
|
||||||
Close(peer_socket);
|
Close(peer_socket);
|
||||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user