Merge branch 'fix-hash' into add-message

This commit is contained in:
n07070 2020-04-28 19:36:49 +02:00
commit fd623ee484
3 changed files with 12 additions and 8 deletions

View File

@ -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 // Hash every data contained in data_list then return a network hash
void hash_network(list *data_list, unsigned char *buf) { 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]; unsigned char hash[SHA256_DIGEST_LENGTH];
int totlen = 0; int totlen = 0;
list *tmp = data_list; list *tmp = data_list;
@ -55,6 +58,5 @@ void concat_data(pub_data *data, unsigned char *buf) {
// Concat hash2 to hash1 (hash1 is modified) // Concat hash2 to hash1 (hash1 is modified)
void concat_hash(unsigned char *hash1, unsigned char *hash2, size_t size) { void concat_hash(unsigned char *hash1, unsigned char *hash2, size_t size) {
hash1 = (unsigned char*) realloc(hash1, size + 16);
memcpy(hash1+size, hash2, 16); memcpy(hash1+size, hash2, 16);
} }

View File

@ -192,7 +192,7 @@ pub_data *get_data(int64_t id) {
while(tmp != NULL) { while(tmp != NULL) {
data = (pub_data*) tmp->data; data = (pub_data*) tmp->data;
tmp = tmp->next;
if(data->id == id) if(data->id == id)
return data; return data;
} }
@ -484,10 +484,12 @@ int add_tlv(packet *pack, tlv *tlv, struct sockaddr_in6 *dest, int socket_num) {
// Send length bytes from packet // Send length bytes from packet
int send_packet(char *packet_buff, int16_t length, struct sockaddr_in6 *dest, int socket_num) { 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 // 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; int error_while_sending = 0;
@ -495,7 +497,7 @@ int send_packet(char *packet_buff, int16_t length, struct sockaddr_in6 *dest, in
struct msghdr packet_tlv_send_out = { struct msghdr packet_tlv_send_out = {
.msg_name = dest, .msg_name = dest,
.msg_namelen = sizeof(struct sockaddr_in6), .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. .msg_iovlen = 1 // We have only one iovec buffer. But if we had 2, we would write 2.
}; };
@ -970,7 +972,7 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s
cur_tlv.warning = (warning*) (data + pos); cur_tlv.warning = (warning*) (data + pos);
// Print exactly new_tlv.length characters from new_tlv.message // 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); printf(warn, cur_tlv.warning->message);
// The position is updated // The position is updated

View File

@ -92,7 +92,7 @@ int build_neighbour(tlv *tlv, struct in6_addr ip, int16_t port) {
new->type = 3; new->type = 3;
new->length = 18; new->length = 18;
new->ip = ip; new->ip = ip;
new->port = port; new->port = htons(port);
tlv->neighbour = new; tlv->neighbour = new;