Merge pull request #2417 from cfromknecht/min-backoff
server: configurable min backoff
This commit is contained in:
commit
3ab01898fb
10
config.go
10
config.go
@ -53,6 +53,7 @@ const (
|
|||||||
defaultInactiveChanTimeout = 20 * time.Minute
|
defaultInactiveChanTimeout = 20 * time.Minute
|
||||||
defaultMaxLogFiles = 3
|
defaultMaxLogFiles = 3
|
||||||
defaultMaxLogFileSize = 10
|
defaultMaxLogFileSize = 10
|
||||||
|
defaultMinBackoff = time.Second
|
||||||
defaultMaxBackoff = time.Hour
|
defaultMaxBackoff = time.Hour
|
||||||
|
|
||||||
defaultTorSOCKSPort = 9050
|
defaultTorSOCKSPort = 9050
|
||||||
@ -197,6 +198,7 @@ type config struct {
|
|||||||
ExternalIPs []net.Addr
|
ExternalIPs []net.Addr
|
||||||
DisableListen bool `long:"nolisten" description:"Disable listening for incoming peer connections"`
|
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"`
|
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"`
|
||||||
|
MinBackoff time.Duration `long:"minbackoff" description:"Shortest backoff when reconnecting to persistent peers. Valid time units are {s, m, h}."`
|
||||||
MaxBackoff time.Duration `long:"maxbackoff" description:"Longest backoff when reconnecting to persistent peers. Valid time units are {s, m, h}."`
|
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 <subsystem>=<level>,<subsystem2>=<level>,... to set the log level for individual subsystems -- Use show to list available subsystems"`
|
DebugLevel string `short:"d" long:"debuglevel" description:"Logging level for all subsystems {trace, debug, info, warn, error, critical} -- You may also specify <subsystem>=<level>,<subsystem2>=<level>,... to set the log level for individual subsystems -- Use show to list available subsystems"`
|
||||||
@ -300,6 +302,7 @@ func loadConfig() (*config, error) {
|
|||||||
},
|
},
|
||||||
MaxPendingChannels: defaultMaxPendingChannels,
|
MaxPendingChannels: defaultMaxPendingChannels,
|
||||||
NoSeedBackup: defaultNoSeedBackup,
|
NoSeedBackup: defaultNoSeedBackup,
|
||||||
|
MinBackoff: defaultMinBackoff,
|
||||||
MaxBackoff: defaultMaxBackoff,
|
MaxBackoff: defaultMaxBackoff,
|
||||||
SubRPCServers: &subRPCServerConfigs{
|
SubRPCServers: &subRPCServerConfigs{
|
||||||
SignRPC: &signrpc.Config{},
|
SignRPC: &signrpc.Config{},
|
||||||
@ -959,6 +962,13 @@ func loadConfig() (*config, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure that the specified minimum backoff is below or equal to the
|
||||||
|
// maximum backoff.
|
||||||
|
if cfg.MinBackoff > cfg.MaxBackoff {
|
||||||
|
return nil, fmt.Errorf("maxbackoff must be greater than " +
|
||||||
|
"minbackoff")
|
||||||
|
}
|
||||||
|
|
||||||
// Finally, ensure that the user's color is correctly formatted,
|
// Finally, ensure that the user's color is correctly formatted,
|
||||||
// otherwise the server will not be able to start after the unlocking
|
// otherwise the server will not be able to start after the unlocking
|
||||||
// the wallet.
|
// the wallet.
|
||||||
|
18
server.go
18
server.go
@ -49,10 +49,6 @@ const (
|
|||||||
// connected to.
|
// connected to.
|
||||||
defaultMinPeers = 3
|
defaultMinPeers = 3
|
||||||
|
|
||||||
// defaultBackoff is the starting point for exponential backoff for
|
|
||||||
// reconnecting to persistent peers.
|
|
||||||
defaultBackoff = time.Second
|
|
||||||
|
|
||||||
// defaultStableConnDuration is a floor under which all reconnection
|
// defaultStableConnDuration is a floor under which all reconnection
|
||||||
// attempts will apply exponential randomized backoff. Connections
|
// attempts will apply exponential randomized backoff. Connections
|
||||||
// durations exceeding this value will be eligible to have their
|
// durations exceeding this value will be eligible to have their
|
||||||
@ -1752,7 +1748,7 @@ func (s *server) establishPersistentConnections() error {
|
|||||||
// persistent connection with.
|
// persistent connection with.
|
||||||
s.persistentPeers[pubStr] = struct{}{}
|
s.persistentPeers[pubStr] = struct{}{}
|
||||||
if _, ok := s.persistentPeersBackoff[pubStr]; !ok {
|
if _, ok := s.persistentPeersBackoff[pubStr]; !ok {
|
||||||
s.persistentPeersBackoff[pubStr] = defaultBackoff
|
s.persistentPeersBackoff[pubStr] = cfg.MinBackoff
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, address := range nodeAddr.addresses {
|
for _, address := range nodeAddr.addresses {
|
||||||
@ -2023,7 +2019,7 @@ func (s *server) nextPeerBackoff(pubStr string,
|
|||||||
backoff, ok := s.persistentPeersBackoff[pubStr]
|
backoff, ok := s.persistentPeersBackoff[pubStr]
|
||||||
if !ok {
|
if !ok {
|
||||||
// If an existing backoff was unknown, use the default.
|
// If an existing backoff was unknown, use the default.
|
||||||
return defaultBackoff
|
return cfg.MinBackoff
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the peer failed to start properly, we'll just use the previous
|
// If the peer failed to start properly, we'll just use the previous
|
||||||
@ -2045,17 +2041,17 @@ func (s *server) nextPeerBackoff(pubStr string,
|
|||||||
// reduce the timeout duration by the length of the connection after
|
// reduce the timeout duration by the length of the connection after
|
||||||
// applying randomized exponential backoff. We'll only apply this in the
|
// applying randomized exponential backoff. We'll only apply this in the
|
||||||
// case that:
|
// case that:
|
||||||
// reb(curBackoff) - connDuration > defaultBackoff
|
// reb(curBackoff) - connDuration > cfg.MinBackoff
|
||||||
relaxedBackoff := computeNextBackoff(backoff) - connDuration
|
relaxedBackoff := computeNextBackoff(backoff) - connDuration
|
||||||
if relaxedBackoff > defaultBackoff {
|
if relaxedBackoff > cfg.MinBackoff {
|
||||||
return relaxedBackoff
|
return relaxedBackoff
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lastly, if reb(currBackoff) - connDuration <= defaultBackoff, meaning
|
// Lastly, if reb(currBackoff) - connDuration <= cfg.MinBackoff, meaning
|
||||||
// the stable connection lasted much longer than our previous backoff.
|
// the stable connection lasted much longer than our previous backoff.
|
||||||
// To reward such good behavior, we'll reconnect after the default
|
// To reward such good behavior, we'll reconnect after the default
|
||||||
// timeout.
|
// timeout.
|
||||||
return defaultBackoff
|
return cfg.MinBackoff
|
||||||
}
|
}
|
||||||
|
|
||||||
// shouldDropConnection determines if our local connection to a remote peer
|
// shouldDropConnection determines if our local connection to a remote peer
|
||||||
@ -2711,7 +2707,7 @@ func (s *server) ConnectToPeer(addr *lnwire.NetAddress, perm bool) error {
|
|||||||
|
|
||||||
s.persistentPeers[targetPub] = struct{}{}
|
s.persistentPeers[targetPub] = struct{}{}
|
||||||
if _, ok := s.persistentPeersBackoff[targetPub]; !ok {
|
if _, ok := s.persistentPeersBackoff[targetPub]; !ok {
|
||||||
s.persistentPeersBackoff[targetPub] = defaultBackoff
|
s.persistentPeersBackoff[targetPub] = cfg.MinBackoff
|
||||||
}
|
}
|
||||||
s.persistentConnReqs[targetPub] = append(
|
s.persistentConnReqs[targetPub] = append(
|
||||||
s.persistentConnReqs[targetPub], connReq)
|
s.persistentConnReqs[targetPub], connReq)
|
||||||
|
Loading…
Reference in New Issue
Block a user