Revert "Merge branch 'master' into add-message"
This reverts commit8da14978d6
, reversing changes made to704ed2a523
.
This commit is contained in:
parent
8da14978d6
commit
055ecfd0ba
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +0,0 @@
|
|||||||
dazibao
|
|
||||||
*.o
|
|
||||||
debug.*
|
|
57
src/node.c
57
src/node.c
@ -21,10 +21,59 @@ static list *neighbour_list;
|
|||||||
|
|
||||||
/* ---- Fonctions utilitaires ---- */
|
/* ---- Fonctions utilitaires ---- */
|
||||||
|
|
||||||
void debug_print(char message_debug){
|
// Looks for more peers
|
||||||
if (debug_flag == 1) {
|
int ask_for_peers(int socket_num) {
|
||||||
printf("\x1b[33m\x1b[4m>> Debug :\x1b[0m\x1b[33m %s\x1b[0m\n", message_debug );
|
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
|
// Get list length
|
||||||
|
@ -121,8 +121,6 @@ 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
|
||||||
|
Loading…
Reference in New Issue
Block a user