Add support for building tinc with MSVC
[tinc] / src / net.c
index 97ca2db..7f84421 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -26,6 +26,7 @@
 #include "conf_net.h"
 #include "conf.h"
 #include "connection.h"
+#include "crypto.h"
 #include "graph.h"
 #include "logger.h"
 #include "meta.h"
@@ -256,7 +257,7 @@ static void timeout_handler(void *data) {
        }
 
        timeout_set(data, &(struct timeval) {
-               1, rand() % 100000
+               1, jitter()
        });
 }
 
@@ -268,9 +269,7 @@ static void periodic_handler(void *data) {
 
        if(contradicting_del_edge > 100 && contradicting_add_edge > 100) {
                logger(DEBUG_ALWAYS, LOG_WARNING, "Possible node with same Name as us! Sleeping %d seconds.", sleeptime);
-               nanosleep(&(struct timespec) {
-                       sleeptime, 0
-               }, NULL);
+               sleep_millis(sleeptime * 1000);
                sleeptime *= 2;
 
                if(sleeptime < 0) {
@@ -294,7 +293,7 @@ static void periodic_handler(void *data) {
        }
 
        timeout_set(data, &(struct timeval) {
-               5, rand() % 100000
+               5, jitter()
        });
 }
 
@@ -482,7 +481,7 @@ void retry(void) {
 int main_loop(void) {
        last_periodic_run_time = now;
        timeout_add(&pingtimer, timeout_handler, &pingtimer, &(struct timeval) {
-               pingtimeout, rand() % 100000
+               pingtimeout, jitter()
        });
        timeout_add(&periodictimer, periodic_handler, &periodictimer, &(struct timeval) {
                0, 0