From: Saverio Proto Date: Thu, 24 Apr 2014 13:06:30 +0000 (+0200) Subject: Move pinginterval pingtimeout and maxtimeout to mesh X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=7dbb65e77ec5fd815c64e1484279d63279679e65;p=meshlink Move pinginterval pingtimeout and maxtimeout to mesh --- diff --git a/src/conf.c b/src/conf.c index 423afa1a..08467e50 100644 --- a/src/conf.c +++ b/src/conf.c @@ -30,9 +30,6 @@ #include "utils.h" /* for cp */ #include "xalloc.h" -int pinginterval = 0; /* seconds between pings */ -int pingtimeout = 0; /* seconds to wait for response */ - static int config_compare(const config_t *a, const config_t *b) { int result; diff --git a/src/conf.h b/src/conf.h index 27561ef7..39eb056c 100644 --- a/src/conf.h +++ b/src/conf.h @@ -30,9 +30,6 @@ typedef struct config_t { int line; } config_t; -extern int pinginterval; -extern int pingtimeout; -extern int maxtimeout; extern void init_configuration(struct splay_tree_t **); extern void exit_configuration(struct splay_tree_t **); diff --git a/src/meshlink_internal.h b/src/meshlink_internal.h index 1e496424..00f68e46 100644 --- a/src/meshlink_internal.h +++ b/src/meshlink_internal.h @@ -92,6 +92,9 @@ struct meshlink_handle { struct ecdsa *invitation_key; debug_t debug_level; + int pinginterval; /* seconds between pings */ + int pingtimeout; /* seconds to wait for response */ + int maxtimeout; }; /// A handle for a MeshLink node. diff --git a/src/net.c b/src/net.c index 29401423..a2cc3ed7 100644 --- a/src/net.c +++ b/src/net.c @@ -124,11 +124,11 @@ void terminate_connection(connection_t *c, bool report) { */ static void timeout_handler(void *data) { for list_each(connection_t, c, mesh->connections) { - if(c->last_ping_time + pingtimeout <= now.tv_sec) { + if(c->last_ping_time + mesh->pingtimeout <= now.tv_sec) { if(c->status.active) { 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); - } else if(c->last_ping_time + pinginterval <= now.tv_sec) { + } else if(c->last_ping_time + mesh->pinginterval <= now.tv_sec) { send_ping(c); continue; } else { @@ -144,7 +144,7 @@ static void timeout_handler(void *data) { } } - timeout_set(data, &(struct timeval){pingtimeout, rand() % 100000}); + timeout_set(data, &(struct timeval){mesh->pingtimeout, rand() % 100000}); } static void periodic_handler(void *data) { @@ -332,8 +332,8 @@ void retry(void) { this is where it all happens... */ int main_loop(void) { - timeout_add(&mesh->pingtimer, timeout_handler, &mesh->pingtimer, &(struct timeval){pingtimeout, rand() % 100000}); - timeout_add(&mesh->periodictimer, periodic_handler, &mesh->periodictimer, &(struct timeval){pingtimeout, rand() % 100000}); + timeout_add(&mesh->pingtimer, timeout_handler, &mesh->pingtimer, &(struct timeval){mesh->pingtimeout, rand() % 100000}); + timeout_add(&mesh->periodictimer, periodic_handler, &mesh->periodictimer, &(struct timeval){mesh->pingtimeout, rand() % 100000}); if(!event_loop()) { logger(DEBUG_ALWAYS, LOG_ERR, "Error while waiting for input: %s", strerror(errno)); diff --git a/src/net_packet.c b/src/net_packet.c index d9a73f6f..281fd973 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -75,7 +75,7 @@ static void send_mtu_probe_handler(void *data) { if(n->mtuprobes > 32) { if(!n->minmtu) { n->mtuprobes = 31; - timeout = pinginterval; + timeout = mesh->pinginterval; goto end; } @@ -102,10 +102,10 @@ static void send_mtu_probe_handler(void *data) { } if(n->mtuprobes == 31) { - timeout = pinginterval; + timeout = mesh->pinginterval; goto end; } else if(n->mtuprobes == 32) { - timeout = pingtimeout; + timeout = mesh->pingtimeout; } for(int i = 0; i < 4 + mesh->localdiscovery; i++) { diff --git a/src/net_setup.c b/src/net_setup.c index 7bee9d93..e168f6ac 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -176,7 +176,7 @@ char *get_name(void) { bool setup_myself_reloadable(void) { mesh->localdiscovery = true; keylifetime = 3600; // TODO: check if this can be removed as well - maxtimeout = 900; + mesh->maxtimeout = 900; autoconnect = 3; mesh->self->options |= OPTION_PMTU_DISCOVERY; @@ -370,8 +370,8 @@ bool setup_network(void) { init_edges(); init_requests(); - pinginterval = 60; - pingtimeout = 5; + mesh->pinginterval = 60; + mesh->pingtimeout = 5; maxoutbufsize = 10 * MTU; if(!setup_myself()) diff --git a/src/net_socket.c b/src/net_socket.c index fbafc22b..7f87d9c4 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -37,7 +37,6 @@ #endif int addressfamily = AF_UNSPEC; -int maxtimeout = 900; int seconds_till_retry = 5; int max_connection_burst = 100; @@ -240,8 +239,8 @@ static void retry_outgoing_handler(void *data) { void retry_outgoing(outgoing_t *outgoing) { outgoing->timeout += 5; - if(outgoing->timeout > maxtimeout) - outgoing->timeout = maxtimeout; + if(outgoing->timeout > mesh->maxtimeout) + outgoing->timeout = mesh->maxtimeout; timeout_add(&outgoing->ev, retry_outgoing_handler, outgoing, &(struct timeval){outgoing->timeout, rand() % 100000}); diff --git a/src/protocol.c b/src/protocol.c index aa434ee4..3e6db47e 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -167,7 +167,7 @@ static void age_past_requests(void *data) { int left = 0, deleted = 0; for splay_each(past_request_t, p, past_request_tree) { - if(p->firstseen + pinginterval <= now.tv_sec) + if(p->firstseen + mesh->pinginterval <= now.tv_sec) splay_delete_node(past_request_tree, node), deleted++; else left++;