Changed debug print,
Added memcmp in get_neibourgh Found bug with port number conversion
This commit is contained in:
parent
e757389e32
commit
e1364bc58e
@ -55,7 +55,7 @@ void print_data(list * l){
|
|||||||
print_debug(">> Printing messages we know of so far :");
|
print_debug(">> Printing messages we know of so far :");
|
||||||
int nbr_msg = 0;
|
int nbr_msg = 0;
|
||||||
setlocale(LC_ALL, "en_US.utf8");
|
setlocale(LC_ALL, "en_US.utf8");
|
||||||
print_debug(">> Peer ID | Seqno | Length | Message ");
|
print_debug(">> Peer ID | Seqno | Length | Message ");
|
||||||
while(l != NULL){
|
while(l != NULL){
|
||||||
pub_data * message = l->data;
|
pub_data * message = l->data;
|
||||||
printf("\x1b[31m[DEBUG]\x1b[0m >> %li | %i | %i | “%s” \n", message->id, message->seqno, message->length, message->data);
|
printf("\x1b[31m[DEBUG]\x1b[0m >> %li | %i | %i | “%s” \n", message->id, message->seqno, message->length, message->data);
|
||||||
|
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
|
// check for same ip and same port
|
||||||
peer = (neighbour_peer*) tmp->data;
|
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;
|
return peer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,10 +152,12 @@ int add_n_update_neighbour(struct in6_addr *ip, int16_t port) {
|
|||||||
time(&curtime);
|
time(&curtime);
|
||||||
peer->last_seen = curtime;
|
peer->last_seen = curtime;
|
||||||
|
|
||||||
|
list * tmp = neighbour_list;
|
||||||
|
|
||||||
// set new peer as head of list
|
// set new peer as head of list
|
||||||
list *node = (list*) malloc(sizeof(list));
|
list *node = (list*) malloc(sizeof(list));
|
||||||
node->data = (void*) peer;
|
node->data = (void*) peer;
|
||||||
node->next = neighbour_list;
|
node->next = tmp;
|
||||||
neighbour_list = node;
|
neighbour_list = node;
|
||||||
return 1;
|
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) {
|
if (error_while_sending == 1) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} 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;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1468,7 +1473,7 @@ int run_node(int sock_fd){
|
|||||||
// Treat incoming packets.
|
// Treat incoming packets.
|
||||||
int work_tlv_status = listen_for_packets(output_buffer, bytes, &sender, sock_fd);
|
int work_tlv_status = listen_for_packets(output_buffer, bytes, &sender, sock_fd);
|
||||||
if (work_tlv_status < 0) {
|
if (work_tlv_status < 0) {
|
||||||
print_debug(">> Error while treating the incoming packet.");
|
print_error("Error while treating the incoming packet.");
|
||||||
}
|
}
|
||||||
// Reset buffer
|
// Reset buffer
|
||||||
memset(output_buffer, 0, sizeof(output_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;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
root_peer->port = root_peer_port;
|
root_peer->port = (int16_t) root_peer_port;
|
||||||
root_peer->is_temporary = 0;
|
root_peer->is_temporary = 0;
|
||||||
root_peer->last_seen = root_peer_seen;
|
root_peer->last_seen = root_peer_seen;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user