From: Guus Sliepen Date: Sun, 21 Oct 2012 15:45:16 +0000 (+0200) Subject: Slightly randomize all timeouts. X-Git-Tag: release-1.1pre4~31 X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=commitdiff_plain;h=edc08b73a9e353bde6db4c73866a6a730a1a7cb4 Slightly randomize all timeouts. --- diff --git a/src/net.c b/src/net.c index b333c5b7..77ff1c8c 100644 --- a/src/net.c +++ b/src/net.c @@ -164,7 +164,7 @@ static void timeout_handler(int fd, short events, void *event) { } } - event_add(event, &(struct timeval){pingtimeout, 0}); + event_add(event, &(struct timeval){pingtimeout, rand() % 100000}); } static void periodic_handler(int fd, short events, void *event) { @@ -278,7 +278,7 @@ static void periodic_handler(int fd, short events, void *event) { } } - event_add(event, &(struct timeval){5, 0}); + event_add(event, &(struct timeval){5, rand() % 100000}); } void handle_meta_connection_data(int fd, short events, void *data) { @@ -449,10 +449,10 @@ int main_loop(void) { struct event periodic_event; timeout_set(&timeout_event, timeout_handler, &timeout_event); - event_add(&timeout_event, &(struct timeval){pingtimeout, 0}); + event_add(&timeout_event, &(struct timeval){pingtimeout, rand() % 100000}); timeout_set(&periodic_event, periodic_handler, &periodic_event); - event_add(&periodic_event, &(struct timeval){5, 0}); + event_add(&periodic_event, &(struct timeval){5, rand() % 100000}); #ifndef HAVE_MINGW struct event sighup_event; diff --git a/src/net_packet.c b/src/net_packet.c index 67ebc223..dc31fd7a 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -151,7 +151,7 @@ static void send_mtu_probe_handler(int fd, short events, void *data) { } end: - event_add(&n->mtuevent, &(struct timeval){timeout, 0}); + event_add(&n->mtuevent, &(struct timeval){timeout, rand() % 100000}); } void send_mtu_probe(node_t *n) { diff --git a/src/net_setup.c b/src/net_setup.c index 74c57c5d..d53aad00 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -285,7 +285,7 @@ void regenerate_key(void) { timeout_set(&keyexpire_event, keyexpire_handler, NULL); } - event_add(&keyexpire_event, &(struct timeval){keylifetime, 0}); + event_add(&keyexpire_event, &(struct timeval){keylifetime, rand() % 100000}); } /* diff --git a/src/net_socket.c b/src/net_socket.c index 09c52070..ce1e3aa3 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -282,7 +282,7 @@ void retry_outgoing(outgoing_t *outgoing) { outgoing->timeout = maxtimeout; timeout_set(&outgoing->ev, retry_outgoing_handler, outgoing); - event_add(&outgoing->ev, &(struct timeval){outgoing->timeout, 0}); + event_add(&outgoing->ev, &(struct timeval){outgoing->timeout, rand() % 100000}); logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Trying to re-establish outgoing connection in %d seconds", diff --git a/src/protocol.c b/src/protocol.c index 3c08d725..34c3f3bb 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -180,7 +180,7 @@ bool seen_request(const char *request) { new->request = xstrdup(request); new->firstseen = time(NULL); splay_insert(past_request_tree, new); - event_add(&past_request_event, &(struct timeval){10, 0}); + event_add(&past_request_event, &(struct timeval){10, rand() % 100000}); return false; } } @@ -201,7 +201,7 @@ static void age_past_requests(int fd, short events, void *data) { deleted, left); if(left) - event_add(&past_request_event, &(struct timeval){10, 0}); + event_add(&past_request_event, &(struct timeval){10, rand() % 100000}); } void init_requests(void) { diff --git a/src/route.c b/src/route.c index e874d892..e9d4ecec 100644 --- a/src/route.c +++ b/src/route.c @@ -209,7 +209,7 @@ static void age_subnets(int fd, short events, void *data) { } if(left) - event_add(&age_subnets_event, &(struct timeval){10, 0}); + event_add(&age_subnets_event, &(struct timeval){10, rand() % 100000}); } static void learn_mac(mac_t *address) { @@ -238,7 +238,7 @@ static void learn_mac(mac_t *address) { if(!timeout_initialized(&age_subnets_event)) timeout_set(&age_subnets_event, age_subnets, NULL); - event_add(&age_subnets_event, &(struct timeval){10, 0}); + event_add(&age_subnets_event, &(struct timeval){10, rand() % 100000}); } else { if(subnet->expires) subnet->expires = time(NULL) + macexpire;