Changed debug print,
Added memcmp in get_neibourgh Found bug with port number conversion
This commit is contained in:
parent
e757389e32
commit
e1364bc58e
15
src/node.c
15
src/node.c
@ -113,7 +113,8 @@ neighbour_peer *get_neighbour(struct in6_addr *ip, int16_t port) {
|
||||
// check for same ip and same port
|
||||
peer = (neighbour_peer*) tmp->data;
|
||||
|
||||
if(memcmp(&peer->ip, ip, sizeof(struct in6_addr)) == 0 && peer->port == port) {
|
||||
if(memcmp(&peer->ip, ip, sizeof(struct in6_addr)) == 0
|
||||
&& memcmp(&peer->port, &port, sizeof(int16_t)) == 0) {
|
||||
return peer;
|
||||
}
|
||||
|
||||
@ -151,10 +152,12 @@ int add_n_update_neighbour(struct in6_addr *ip, int16_t port) {
|
||||
time(&curtime);
|
||||
peer->last_seen = curtime;
|
||||
|
||||
list * tmp = neighbour_list;
|
||||
|
||||
// set new peer as head of list
|
||||
list *node = (list*) malloc(sizeof(list));
|
||||
node->data = (void*) peer;
|
||||
node->next = neighbour_list;
|
||||
node->next = tmp;
|
||||
neighbour_list = node;
|
||||
return 1;
|
||||
}
|
||||
@ -540,7 +543,9 @@ int send_packet(char *packet_buff, uint16_t length, struct sockaddr_in6 *dest, i
|
||||
if (error_while_sending == 1) {
|
||||
return -1;
|
||||
} else {
|
||||
printf(">> Packet successfully sent to peer. %d bytes sent.\n", response_code);
|
||||
if (DEBUG_LEVEL > 0) {
|
||||
printf("\x1b[31m[DEBUG]\x1b[0m >> Packet successfully sent to peer. %d bytes sent.\n", response_code);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -1468,7 +1473,7 @@ int run_node(int sock_fd){
|
||||
// Treat incoming packets.
|
||||
int work_tlv_status = listen_for_packets(output_buffer, bytes, &sender, sock_fd);
|
||||
if (work_tlv_status < 0) {
|
||||
print_debug(">> Error while treating the incoming packet.");
|
||||
print_error("Error while treating the incoming packet.");
|
||||
}
|
||||
// Reset buffer
|
||||
memset(output_buffer, 0, sizeof(output_buffer));
|
||||
@ -1522,7 +1527,7 @@ int bootstrap_node(int * sock_fd, char * root_peer_ip, uint16_t root_peer_port){
|
||||
return -3;
|
||||
}
|
||||
|
||||
root_peer->port = root_peer_port;
|
||||
root_peer->port = (int16_t) root_peer_port;
|
||||
root_peer->is_temporary = 0;
|
||||
root_peer->last_seen = root_peer_seen;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user