X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnet.c;h=52c7fe3e8e096fc90d1de588ccbfdc14256c3346;hb=2055c3e21d5b3f4217883d52d5e5b0fbad504785;hp=c2c5d198ddb08f829d2a3b751156add7d314470c;hpb=0037ec7cb38994dda6ab5e4fa85ce595b9a59f6b;p=tinc diff --git a/src/net.c b/src/net.c index c2c5d198..52c7fe3e 100644 --- a/src/net.c +++ b/src/net.c @@ -210,15 +210,24 @@ static void periodic_handler(void *data) { and we are not already trying to make one, create an outgoing connection to this node. */ - int r = rand() % node_tree->count; - int i = 0; + int count = 0; + for splay_each(node_t, n, node_tree) { + if(n == myself || n->connection || !(n->status.has_address || n->status.reachable)) + continue; + count++; + } + + if(!count) + goto end; + + int r = rand() % count; for splay_each(node_t, n, node_tree) { - if(i++ != r) + if(n == myself || n->connection || !(n->status.has_address || n->status.reachable)) continue; - if(n->connection) - break; + if(r--) + continue; bool found = false; @@ -236,6 +245,7 @@ static void periodic_handler(void *data) { list_insert_tail(outgoing_list, outgoing); setup_outgoing_connection(outgoing); } + break; } } else if(nc > 3) { @@ -284,6 +294,7 @@ static void periodic_handler(void *data) { } } +end: timeout_set(data, &(struct timeval){5, rand() % 100000}); } @@ -341,9 +352,14 @@ int reload_configuration(void) { for splay_each(subnet_t, subnet, subnet_tree) if (subnet->owner) subnet->expires = 1; + } + + for splay_each(node_t, n, node_tree) + n->status.has_address = false; - load_all_subnets(); + load_all_nodes(); + if(strictsubnets) { for splay_each(subnet_t, subnet, subnet_tree) { if (!subnet->owner) continue; @@ -442,7 +458,7 @@ void retry(void) { */ int main_loop(void) { timeout_add(&pingtimer, timeout_handler, &pingtimer, &(struct timeval){pingtimeout, rand() % 100000}); - timeout_add(&periodictimer, periodic_handler, &periodictimer, &(struct timeval){pingtimeout, rand() % 100000}); + timeout_add(&periodictimer, periodic_handler, &periodictimer, &(struct timeval){0, 0}); #ifndef HAVE_MINGW signal_t sighup = {0};