Merge branch 'fix-hash' into 'master'
Fix hash See merge request perdriau/dazibao!14
This commit is contained in:
commit
b5a6bb0475
@ -17,7 +17,10 @@ void hash_data(pub_data *data, unsigned char *buf) {
|
||||
|
||||
// Hash every data contained in data_list then return a network hash
|
||||
void hash_network(list *data_list, unsigned char *buf) {
|
||||
unsigned char *concat = (unsigned char*) malloc(0);
|
||||
// Get list length to initialize concat buffer
|
||||
int concat_len = len_list(data_list) * 16;
|
||||
unsigned char *concat = (unsigned char*) malloc(concat_len);
|
||||
|
||||
unsigned char hash[SHA256_DIGEST_LENGTH];
|
||||
int totlen = 0;
|
||||
list *tmp = data_list;
|
||||
@ -55,6 +58,5 @@ void concat_data(pub_data *data, unsigned char *buf) {
|
||||
|
||||
// Concat hash2 to hash1 (hash1 is modified)
|
||||
void concat_hash(unsigned char *hash1, unsigned char *hash2, size_t size) {
|
||||
hash1 = (unsigned char*) realloc(hash1, size + 16);
|
||||
memcpy(hash1+size, hash2, 16);
|
||||
}
|
||||
|
18
src/node.c
18
src/node.c
@ -143,7 +143,7 @@ pub_data *get_data(int64_t id) {
|
||||
|
||||
while(tmp != NULL) {
|
||||
data = (pub_data*) tmp->data;
|
||||
|
||||
tmp = tmp->next;
|
||||
if(data->id == id)
|
||||
return data;
|
||||
}
|
||||
@ -412,10 +412,12 @@ int add_tlv(packet *pack, tlv *tlv, struct sockaddr_in6 *dest, int socket_num) {
|
||||
|
||||
// Send length bytes from packet
|
||||
int send_packet(char *packet_buff, int16_t length, struct sockaddr_in6 *dest, int socket_num) {
|
||||
((packet*) packet_buff)->length = htons(((packet*) packet_buff)->length);
|
||||
((packet*) packet_buff)->length = htons(((packet*) packet_buff)->length);
|
||||
|
||||
// Vectorized buffer
|
||||
struct iovec vec_buff = {.iov_len = length + 4, .iov_base = packet_buff};
|
||||
struct iovec vec_buff[1];
|
||||
vec_buff[0].iov_len = length + 4;
|
||||
vec_buff[0].iov_base = packet_buff;
|
||||
|
||||
int error_while_sending = 0;
|
||||
|
||||
@ -423,7 +425,7 @@ int send_packet(char *packet_buff, int16_t length, struct sockaddr_in6 *dest, in
|
||||
struct msghdr packet_tlv_send_out = {
|
||||
.msg_name = dest,
|
||||
.msg_namelen = sizeof(struct sockaddr_in6),
|
||||
.msg_iov = &vec_buff,
|
||||
.msg_iov = vec_buff,
|
||||
.msg_iovlen = 1 // We have only one iovec buffer. But if we had 2, we would write 2.
|
||||
};
|
||||
|
||||
@ -783,7 +785,7 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if(memcmp(hash, cur_tlv.network_hash->network_hash, 16) == 0) {
|
||||
if(memcmp(hash, cur_tlv.network_hash->network_hash, 16) != 0) {
|
||||
print_debug(">> Sending out our network hash.");
|
||||
build_network_state_req(&new_tlv);
|
||||
send_single_tlv(&new_tlv, sender, socket_num);
|
||||
@ -872,6 +874,10 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s
|
||||
print_debug(">> Received node state, updating...");
|
||||
cur_tlv.node_state = (node_state*) (data + pos);
|
||||
|
||||
print_debug(">> Received message ! ");
|
||||
if (DEBUG_LEVEL > 0) {
|
||||
printf("\n\t %s \n", (char *) cur_tlv.node_state->data);
|
||||
}
|
||||
add_data(cur_tlv.node_state->length - 26, cur_tlv.node_state->node_id, cur_tlv.node_state->seqno, cur_tlv.node_state->data);
|
||||
|
||||
// The position is updated
|
||||
@ -885,7 +891,7 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s
|
||||
cur_tlv.warning = (warning*) (data + pos);
|
||||
|
||||
// Print exactly new_tlv.length characters from new_tlv.message
|
||||
sprintf(warn, "\x1b[31m>> WARNING:\n%%.%ds \x1b[0m", cur_tlv.warning->length + 1);
|
||||
sprintf(warn, ">> WARNING:\n%%.%ds", cur_tlv.warning->length + 1);
|
||||
printf(warn, cur_tlv.warning->message);
|
||||
|
||||
// The position is updated
|
||||
|
@ -62,7 +62,7 @@ typedef struct list {
|
||||
|
||||
// The adress of the main peer
|
||||
#define ROOT_PEER_ADDR "2001:660:3301:9200::51c2:1b9b"
|
||||
|
||||
|
||||
|
||||
// fonctions signatures
|
||||
int listen_for_packets(char * received_data_buffer, int received_data_len, struct sockaddr_in6 * sender, int sock_fd);
|
||||
|
Loading…
Reference in New Issue
Block a user