Merge branch 'master' into 'debug-fnc'

# Conflicts:
#   src/node.c
This commit is contained in:
PERDRIAU nelson 2020-04-29 14:18:58 +02:00
commit fa872ed625
3 changed files with 9 additions and 53 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
dazibao
*.o
debug.*

View File

@ -21,59 +21,10 @@ static list *neighbour_list;
/* ---- Fonctions utilitaires ---- */ /* ---- Fonctions utilitaires ---- */
// Looks for more peers void debug_print(char message_debug){
int ask_for_peers(int socket_num) { if (debug_flag == 1) {
print_debug(">> Asking for more peers..."); printf("\x1b[33m\x1b[4m>> Debug :\x1b[0m\x1b[33m %s\x1b[0m\n", message_debug );
// Only ask for more peers if the neighbour list is small enough }
int nbr_peers = len_list(neighbour_list);
if( nbr_peers >= 5){
return 0;
} else if (nbr_peers <= 0){
print_debug(">> No peers found in the peer list, something terrible happened.");
return -1;
} else {
// Get random peer
neighbour_peer *peer = get_random_neighbour();
struct in6_addr ip = peer->ip;
int16_t port = peer->port;
/*int ifindex = if_nametoindex("enp3s0");
if(ifindex == 0) {
int ifindex = if_nametoindex("eth0");
if(ifindex == 0) {
perror("if_nametoindex failed");
return -1;
}
}*/
int ifindex = 0;
// Initialize sockaddr
struct sockaddr_in6 dest;
memset(&dest, 0, sizeof(struct sockaddr_in6));
dest.sin6_family = AF_INET6;
memcpy(&dest.sin6_addr, &ip, 16);
dest.sin6_port = htons(port);
dest.sin6_scope_id = ifindex;
// Send neighbour request TLV
tlv neighbour_req;
neighbour_req.pad1 = NULL;
int rc = build_neighbour_req(&neighbour_req);
if (rc < 0) {
print_debug(">> Failed to build neighbour_req");
}
rc = send_single_tlv(&neighbour_req, &dest, socket_num);
if (rc < 0) {
print_debug(">> Error while sending a TLV.");
return -1;
} else {
print_debug(">> Send TLV.");
return 0;
}
}
} }
// Get list length // Get list length

View File

@ -121,6 +121,8 @@ int bootstrap_node(int * sock_fd);
// Helper functions // Helper functions
int len_list(list *l); int len_list(list *l);
void debug_print(char message_debug);
neighbour_peer *get_random_neighbour(); neighbour_peer *get_random_neighbour();
// Search for this peer in the neighbour table // Search for this peer in the neighbour table