From: Guus Sliepen Date: Sun, 17 Apr 2016 15:06:11 +0000 (+0200) Subject: Speed up AutoConnect at startup. X-Git-Tag: release-1.1pre12~8 X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=b6b302cee9de92d157f73d7739cc259d269c0ca0;p=tinc Speed up AutoConnect at startup. Call periodic_handler() immediately at startup. Also, don't try to connect to ourself. --- diff --git a/src/net.c b/src/net.c index c2c5d198..8328db91 100644 --- a/src/net.c +++ b/src/net.c @@ -210,10 +210,13 @@ 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 r = rand() % (node_tree->count - 1); int i = 0; for splay_each(node_t, n, node_tree) { + if(n == myself) + continue; + if(i++ != r) continue; @@ -442,7 +445,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};