Merge branch 'master' into '16-update_neighbours'
# Conflicts: # src/node.c
This commit is contained in:
commit
28700a1609
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
dazibao
|
||||
*.o
|
||||
debug.*
|
54
src/node.c
54
src/node.c
@ -20,57 +20,9 @@ static list *neighbour_list;
|
||||
|
||||
/* ---- Fonctions utilitaires ---- */
|
||||
|
||||
// Looks for more peers
|
||||
int ask_for_peers(int socket_num) {
|
||||
// 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){
|
||||
printf(">> No peers found in the peer list, something terrible happened.\n");
|
||||
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) {
|
||||
printf(">> Failed to build neighbour_req\n");
|
||||
}
|
||||
|
||||
rc = send_single_tlv(&neighbour_req, &dest, socket_num);
|
||||
if (rc < 0) {
|
||||
printf(">> Error while sending a TLV.\n");
|
||||
return -1;
|
||||
} else {
|
||||
printf(">> Send TLV.\n");
|
||||
return 0;
|
||||
}
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,6 +121,8 @@ 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
|
||||
|
Loading…
Reference in New Issue
Block a user