diff --git a/src/debug.o b/src/debug.o new file mode 100644 index 0000000..f402994 Binary files /dev/null and b/src/debug.o differ diff --git a/src/hash.o b/src/hash.o new file mode 100644 index 0000000..9de8247 Binary files /dev/null and b/src/hash.o differ diff --git a/src/node.c b/src/node.c index ef470d7..6dbea63 100644 --- a/src/node.c +++ b/src/node.c @@ -461,10 +461,11 @@ 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, .iov_base = packet_buff}; int error_while_sending = 0; @@ -472,7 +473,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. }; @@ -802,7 +803,6 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s new_neighbour.sin6_scope_id = ifindex; // Build network hash - // memset(&new_tlv,0,sizeof(struct network_hash)); build_network_hash(&new_tlv, data_list); send_single_tlv(&new_tlv, &new_neighbour, socket_num); @@ -820,13 +820,13 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s if (DEBUG_LEVEL > 1) { printf("\x1b[31m[DEBUG]\x1b[0m >> Our hash : "); - for(int x = 0; x < 16; x++){ + for(int x = 0; x < SHA256_DIGEST_LENGTH; x++){ printf("%02x", hash[x]); fflush(0); } printf("\n"); printf("\x1b[31m[DEBUG]\x1b[0m >> Received : "); - for(int x = 0; x < 16; x++){ + for(int x = 0; x < SHA256_DIGEST_LENGTH; x++){ printf("%02x", cur_tlv.network_hash->network_hash[x]); fflush(0); } @@ -924,7 +924,7 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s print_debug(">> Received message ! "); if (DEBUG_LEVEL > 0) { - printf("\nID : %li \nSeqno : %i\n ā€œ%sā€ \n", cur_tlv.node_state->node_id, cur_tlv.node_state->seqno, (char *) cur_tlv.node_state->data); + 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); @@ -939,7 +939,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 @@ -1049,7 +1049,7 @@ int run_node(int sock_fd){ t_ask_for_more_peers(sock_fd); t_update_neighbours(); t_get_network_state(sock_fd); - delay = time(NULL) + 20 + (rand() % 5); + delay = time(NULL) + 20 + (rand() % 10); } // This might be cool to add, but we need to find a way to write to stdin diff --git a/src/tlv.c b/src/tlv.c index 82de813..140a9fb 100644 --- a/src/tlv.c +++ b/src/tlv.c @@ -92,7 +92,7 @@ int build_neighbour(tlv *tlv, struct in6_addr ip, int16_t port) { new->type = 3; new->length = 18; new->ip = ip; - new->port = port; + new->port = htons(port); tlv->neighbour = new;