From 02442ecbaef9445b0ddbf7657c7f11f83e99d12c Mon Sep 17 00:00:00 2001 From: Igor Cota Date: Thu, 4 Oct 2018 17:55:37 +0200 Subject: [PATCH] Server: make maximum backoff configurable --- config.go | 7 +++++-- server.go | 8 ++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/config.go b/config.go index 10729f47..afef1993 100644 --- a/config.go +++ b/config.go @@ -53,6 +53,7 @@ const ( defaultInactiveChanTimeout = 20 * time.Minute defaultMaxLogFiles = 3 defaultMaxLogFileSize = 10 + defaultMaxBackoff = time.Hour defaultTorSOCKSPort = 9050 defaultTorDNSHost = "soa.nodes.lightning.directory" @@ -194,8 +195,9 @@ type config struct { RESTListeners []net.Addr Listeners []net.Addr ExternalIPs []net.Addr - DisableListen bool `long:"nolisten" description:"Disable listening for incoming peer connections"` - NAT bool `long:"nat" description:"Toggle NAT traversal support (using either UPnP or NAT-PMP) to automatically advertise your external IP address to the network -- NOTE this does not support devices behind multiple NATs"` + DisableListen bool `long:"nolisten" description:"Disable listening for incoming peer connections"` + NAT bool `long:"nat" description:"Toggle NAT traversal support (using either UPnP or NAT-PMP) to automatically advertise your external IP address to the network -- NOTE this does not support devices behind multiple NATs"` + MaxBackoff time.Duration `long:"maxbackoff" description:"Longest backoff when reconnecting to persistent peers. Valid time units are {s, m, h}."` DebugLevel string `short:"d" long:"debuglevel" description:"Logging level for all subsystems {trace, debug, info, warn, error, critical} -- You may also specify =,=,... to set the log level for individual subsystems -- Use show to list available subsystems"` @@ -298,6 +300,7 @@ func loadConfig() (*config, error) { }, MaxPendingChannels: defaultMaxPendingChannels, NoSeedBackup: defaultNoSeedBackup, + MaxBackoff: defaultMaxBackoff, SubRPCServers: &subRPCServerConfigs{ SignRPC: &signrpc.Config{}, }, diff --git a/server.go b/server.go index 05984385..fbc6c02c 100644 --- a/server.go +++ b/server.go @@ -52,10 +52,6 @@ const ( // reconnecting to persistent peers. defaultBackoff = time.Second - // maximumBackoff is the largest backoff we will permit when - // reattempting connections to persistent peers. - maximumBackoff = time.Hour - // defaultStableConnDuration is a floor under which all reconnection // attempts will apply exponential randomized backoff. Connections // durations exceeding this value will be eligible to have their @@ -2853,8 +2849,8 @@ func parseHexColor(colorStr string) (color.RGBA, error) { func computeNextBackoff(currBackoff time.Duration) time.Duration { // Double the current backoff, truncating if it exceeds our maximum. nextBackoff := 2 * currBackoff - if nextBackoff > maximumBackoff { - nextBackoff = maximumBackoff + if nextBackoff > cfg.MaxBackoff { + nextBackoff = cfg.MaxBackoff } // Using 1/10 of our duration as a margin, compute a random offset to