Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decouple boot node reachability interval from peer discovery interval
Browse files Browse the repository at this point in the history
Maelkum committed Jul 12, 2024

Verified

This commit was signed with the committer’s verified signature.
x5a Zak Lee
1 parent 6ccb948 commit 51b9b88
Showing 2 changed files with 18 additions and 9 deletions.
23 changes: 16 additions & 7 deletions host/config.go
Original file line number Diff line number Diff line change
@@ -10,12 +10,13 @@ import (

// defaultConfig used to create Host.
var defaultConfig = Config{
PrivateKey: "",
ConnectionThreshold: 20,
DialBackPeersLimit: 100,
DiscoveryInterval: 10 * time.Second,
Websocket: false,
MustReachBootNodes: defaultMustReachBootNodes,
PrivateKey: "",
ConnectionThreshold: 20,
DialBackPeersLimit: 100,
DiscoveryInterval: 10 * time.Second,
Websocket: false,
BootNodesReachabilityCheckInterval: 1 * time.Minute,
MustReachBootNodes: defaultMustReachBootNodes,
}

// Config represents the Host configuration.
@@ -35,7 +36,8 @@ type Config struct {
DialBackPort uint
DialBackWebsocketPort uint

MustReachBootNodes bool
BootNodesReachabilityCheckInterval time.Duration
MustReachBootNodes bool
}

// WithPrivateKey specifies the private key for the Host.
@@ -118,3 +120,10 @@ func WithMustReachBootNodes(b bool) func(*Config) {
cfg.MustReachBootNodes = b
}
}

// WithBootNodesReachabilityInterval specifies how often should we recheck and reconnect to boot nodes.
func WithBootNodesReachabilityInterval(d time.Duration) func(cfg *Config) {
return func(cfg *Config) {
cfg.BootNodesReachabilityCheckInterval = d
}
}
4 changes: 2 additions & 2 deletions host/discovery.go
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ func (h *Host) ConnectToKnownPeers(ctx context.Context) error {
// Spin up a goroutine to maintain connections to boot nodes in the background.
// In case boot nodes drops out, we want to connect back to it.
go func(ctx context.Context) {
ticker := time.NewTicker(h.cfg.DiscoveryInterval)
ticker := time.NewTicker(h.cfg.BootNodesReachabilityCheckInterval)
for {
select {
case <-ticker.C:
@@ -41,7 +41,7 @@ func (h *Host) ConnectToKnownPeers(ctx context.Context) error {

case <-ctx.Done():
ticker.Stop()
h.log.Info().Msg("stopping boot node monitoring")
h.log.Debug().Msg("stopping boot node reachability monitoring")
}
}
}(ctx)

0 comments on commit 51b9b88

Please sign in to comment.