From 44cf00432b5ae24c5d325b8b536e173d9326d416 Mon Sep 17 00:00:00 2001 From: n07070 Date: Mon, 4 May 2020 21:05:35 +0200 Subject: [PATCH] Fixed adding to list of peers. --- src/node.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/node.c b/src/node.c index acca9e8..54813e1 100644 --- a/src/node.c +++ b/src/node.c @@ -1556,6 +1556,7 @@ int bootstrap_node(int * sock_fd, char * root_peer_ip, uint16_t root_peer_port){ struct addrinfo *p; struct neighbour_peer *peer ; + list * tmp = neighbour_list; for(p = res; p != NULL; p = p->ai_next) { peer = (neighbour_peer*) malloc(sizeof(neighbour_peer)); 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 ); } - list * tmp = neighbour_list; + // Add new peer to the 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; // Goint to the end of the list - while(tmp->data != NULL){ + while(tmp->next != NULL){ tmp = tmp->next; } - tmp->data = node; - tmp->next = NULL; - + tmp->next = node; } + neighbour_list = tmp; + + + print_peers(neighbour_list); print_debug(">> Initializing data list..."); data_list = (list*) malloc(sizeof(list));