X-Git-Url: http://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnet.c;h=52c7fe3e8e096fc90d1de588ccbfdc14256c3346;hb=2055c3e21d5b3f4217883d52d5e5b0fbad504785;hp=8328db914d824e316de5c708a27baf30f4b10bb8;hpb=0b6f84f96eeed20a0d771fedb72c0e19941adb7e;p=tinc diff --git a/src/net.c b/src/net.c index 8328db91..52c7fe3e 100644 --- a/src/net.c +++ b/src/net.c @@ -210,18 +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 - 1); - int i = 0; - + int count = 0; for splay_each(node_t, n, node_tree) { - if(n == myself) + if(n == myself || n->connection || !(n->status.has_address || n->status.reachable)) continue; + count++; + } - if(i++ != r) + if(!count) + goto end; + + int r = rand() % count; + + for splay_each(node_t, n, node_tree) { + if(n == myself || n->connection || !(n->status.has_address || n->status.reachable)) continue; - if(n->connection) - break; + if(r--) + continue; bool found = false; @@ -239,6 +245,7 @@ static void periodic_handler(void *data) { list_insert_tail(outgoing_list, outgoing); setup_outgoing_connection(outgoing); } + break; } } else if(nc > 3) { @@ -287,6 +294,7 @@ static void periodic_handler(void *data) { } } +end: timeout_set(data, &(struct timeval){5, rand() % 100000}); } @@ -344,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;