This commit is contained in:
Nikolaj
2021-11-05 13:49:35 +01:00
parent 57c3e9f626
commit 84fbccb94d
7 changed files with 373372 additions and 5 deletions

View File

@ -367,7 +367,6 @@ void get_block(csc_block_t* block, csc_peer_t peer, unsigned char* hash, char* o
} else {
buffer_size = MAX_LINE;
}
printf("%i\n", buffer_size);
rio_t rio;
char rio_buf[buffer_size];
int peer_socket;
@ -380,7 +379,7 @@ void get_block(csc_block_t* block, csc_peer_t peer, unsigned char* hash, char* o
request.reserved[i] = 0;
}
request.block_num = be64toh(block->index);
strncpy(request.hash, hash, 32);
memcpy(request.hash, hash, 32);
memcpy(rio_buf, &request, PEER_REQUEST_HEADER_SIZE);
Rio_writen(peer_socket, rio_buf, PEER_REQUEST_HEADER_SIZE);
@ -453,6 +452,7 @@ void get_block(csc_block_t* block, csc_peer_t peer, unsigned char* hash, char* o
*/
int get_peers_list(csc_peer_t** peers, uint8_t hash[32])
{
rio_t rio;
uint8_t rio_buf[MAX_LINE];
@ -469,7 +469,8 @@ int get_peers_list(csc_peer_t** peers, uint8_t hash[32])
memcpy(rio_buf, &request_header, HEADER_SIZE);
struct RequestBody request_body;
strncpy(request_body.hash, hash, 32);
memcpy(request_body.hash, hash, 32);
inet_aton(my_ip, &request_body.ip);
request_body.port = be16toh(atol(my_port));
memcpy(&rio_buf[HEADER_SIZE], &request_body, BODY_SIZE);