From b1498f07c564c18cd928dd5e0c8608a7b6a35c88 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 25 Apr 2018 22:05:38 +0930 Subject: [PATCH] gossipd: exponential backoff for reconnect (5 minute ceiling). Signed-off-by: Rusty Russell --- gossipd/gossip.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/gossipd/gossip.c b/gossipd/gossip.c index d795da262..a2f56da83 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -1584,10 +1584,17 @@ static void connect_failed(struct io_conn *conn, struct reaching *reach) NULL, &reach->id, diff, reach->attempts, false))); tal_free(reach); } else { - status_trace("Failed connected out for %s, will try again", - type_to_string(tmpctx, struct pubkey, &reach->id)); - /* FIXME: Configurable timer! */ - new_reltimer(&reach->daemon->timers, reach, time_from_sec(5), + unsigned int secs; + + /* Exponential backoff, then every 5 minutes */ + if (reach->attempts < 9) + secs = 1 << reach->attempts; + else + secs = 300; + status_trace("Failed connected out for %s, will try again in %u seconds", + type_to_string(tmpctx, struct pubkey, &reach->id), + secs); + new_reltimer(&reach->daemon->timers, reach, time_from_sec(secs), try_connect, reach); } }