Fixed adding a peer a bootstrap
This commit is contained in:
parent
12f8751ef8
commit
bda5108589
20
src/node.c
20
src/node.c
@ -338,7 +338,7 @@ int update_neighbours() {
|
||||
// from this peer then remove it from the list
|
||||
time(&curtime);
|
||||
|
||||
if(difftime(peer->last_seen, curtime) >= 70) {
|
||||
if(difftime(curtime, peer->last_seen) >= 70) {
|
||||
// increase the count of deleted nodes
|
||||
deleted++;
|
||||
|
||||
@ -1395,6 +1395,7 @@ int bootstrap_node(int * sock_fd, char * root_peer_ip, uint16_t root_peer_port){
|
||||
int rc = getaddrinfo(root_peer_ip, "http", &hints, &res);
|
||||
if(rc != 0) {
|
||||
print_error("Failed to resolve hostname, exiting...");
|
||||
printf(gai_strerror(rc));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -1404,9 +1405,7 @@ int bootstrap_node(int * sock_fd, char * root_peer_ip, uint16_t root_peer_port){
|
||||
// For every address given to us by getaddrinfo, we create a new peer.
|
||||
struct addrinfo *p;
|
||||
struct neighbour_peer *peer ;
|
||||
|
||||
list * tmp = neighbour_list;
|
||||
for(p = res; p != NULL; p = p->ai_next) {
|
||||
p = res;
|
||||
peer = (neighbour_peer*) malloc(sizeof(neighbour_peer));
|
||||
memcpy(&peer->ip, &((struct sockaddr_in6 *) p->ai_addr)->sin6_addr, sizeof(struct in6_addr));
|
||||
peer->port = root_peer_port;
|
||||
@ -1426,16 +1425,9 @@ int bootstrap_node(int * sock_fd, char * root_peer_ip, uint16_t root_peer_port){
|
||||
// Add new peer to the list.
|
||||
list *node = (list*) malloc(sizeof(list));
|
||||
node->data = (void*) peer;
|
||||
node->next = NULL;
|
||||
|
||||
// Goint to the end of the list
|
||||
while(tmp->next != NULL){
|
||||
tmp = tmp->next;
|
||||
}
|
||||
tmp->next = node;
|
||||
}
|
||||
|
||||
neighbour_list = tmp;
|
||||
node->next = neighbour_list;
|
||||
neighbour_list = node;
|
||||
neighbour_list->next = NULL;
|
||||
|
||||
print_peers(neighbour_list);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user