Speed up AutoConnect at startup.
[tinc] / src / net.c
index 9094d61..8328db9 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -152,7 +152,7 @@ static void timeout_handler(void *data) {
                        if(c->edge) {
                                try_tx(c->node, false);
                                if(c->status.pinged) {
-                                       logger(DEBUG_CONNECTIONS, LOG_INFO, "%s (%s) didn't respond to PING in %ld seconds", c->name, c->hostname, (long)now.tv_sec - c->last_ping_time);
+                                       logger(DEBUG_CONNECTIONS, LOG_INFO, "%s (%s) didn't respond to PING in %ld seconds", c->name, c->hostname, (long)(now.tv_sec - c->last_ping_time));
                                } else if(c->last_ping_time + pinginterval <= now.tv_sec) {
                                        send_ping(c);
                                        continue;
@@ -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};