From edc08b73a9e353bde6db4c73866a6a730a1a7cb4 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sun, 21 Oct 2012 17:45:16 +0200 Subject: [PATCH] Slightly randomize all timeouts. --- src/net.c | 8 ++++---- src/net_packet.c | 2 +- src/net_setup.c | 2 +- src/net_socket.c | 2 +- src/protocol.c | 4 ++-- src/route.c | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/net.c b/src/net.c index b333c5b..77ff1c8 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 67ebc22..dc31fd7 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 74c57c5..d53aad0 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 09c5207..ce1e3aa 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 3c08d72..34c3f3b 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 e874d89..e9d4ece 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; -- 2.25.1