Revert "Merge branch 'master' into add-message"

This reverts commit 8da14978d6, reversing
changes made to 704ed2a523.
This commit is contained in:
n07070 2020-04-29 14:30:05 +02:00
parent 8da14978d6
commit 055ecfd0ba
3 changed files with 53 additions and 9 deletions

3
.gitignore vendored
View File

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

View File

@ -21,10 +21,59 @@ static list *neighbour_list;
/* ---- Fonctions utilitaires ---- */
void debug_print(char message_debug){
if (debug_flag == 1) {
printf("\x1b[33m\x1b[4m>> Debug :\x1b[0m\x1b[33m %s\x1b[0m\n", message_debug );
}
// Looks for more peers
int ask_for_peers(int socket_num) {
print_debug(">> Asking for more peers...");
// 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

View File

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