Fixed adding to list of peers.

This commit is contained in:
n07070 2020-05-04 21:05:35 +02:00
parent 57d04eb1c3
commit 44cf00432b

View File

@ -1556,6 +1556,7 @@ int bootstrap_node(int * sock_fd, char * root_peer_ip, uint16_t root_peer_port){
struct addrinfo *p; struct addrinfo *p;
struct neighbour_peer *peer ; struct neighbour_peer *peer ;
list * tmp = neighbour_list;
for(p = res; p != NULL; p = p->ai_next) { for(p = res; p != NULL; p = p->ai_next) {
peer = (neighbour_peer*) malloc(sizeof(neighbour_peer)); peer = (neighbour_peer*) malloc(sizeof(neighbour_peer));
memcpy(&peer->ip, &((struct sockaddr_in6 *) p->ai_addr)->sin6_addr, sizeof(struct in6_addr)); memcpy(&peer->ip, &((struct sockaddr_in6 *) p->ai_addr)->sin6_addr, sizeof(struct in6_addr));
@ -1571,7 +1572,7 @@ int bootstrap_node(int * sock_fd, char * root_peer_ip, uint16_t root_peer_port){
printf("\x1b[31m[DEBUG]\x1b[0m >> Adding %s @ %i to peer list.\n", ip_str, root_peer_port ); printf("\x1b[31m[DEBUG]\x1b[0m >> Adding %s @ %i to peer list.\n", ip_str, root_peer_port );
} }
list * tmp = neighbour_list;
// Add new peer to the list. // Add new peer to the list.
list *node = (list*) malloc(sizeof(list)); list *node = (list*) malloc(sizeof(list));
@ -1579,14 +1580,16 @@ int bootstrap_node(int * sock_fd, char * root_peer_ip, uint16_t root_peer_port){
node->next = NULL; node->next = NULL;
// Goint to the end of the list // Goint to the end of the list
while(tmp->data != NULL){ while(tmp->next != NULL){
tmp = tmp->next; tmp = tmp->next;
} }
tmp->data = node; tmp->next = node;
tmp->next = NULL;
} }
neighbour_list = tmp;
print_peers(neighbour_list);
print_debug(">> Initializing data list..."); print_debug(">> Initializing data list...");
data_list = (list*) malloc(sizeof(list)); data_list = (list*) malloc(sizeof(list));