fix: only use discv5 functions if enabled
This commit is contained in:
parent
002cb10847
commit
2f49117061
|
@ -90,6 +90,7 @@ type settings struct {
|
||||||
PeerExchange bool // Enable peer exchange
|
PeerExchange bool // Enable peer exchange
|
||||||
DiscoveryLimit int // Indicates the number of nodes to discover
|
DiscoveryLimit int // Indicates the number of nodes to discover
|
||||||
Nameserver string // Optional nameserver to use for dns discovery
|
Nameserver string // Optional nameserver to use for dns discovery
|
||||||
|
EnableDiscV5 bool // Indicates whether discv5 is enabled or not
|
||||||
}
|
}
|
||||||
|
|
||||||
// Waku represents a dark communication interface through the Ethereum
|
// Waku represents a dark communication interface through the Ethereum
|
||||||
|
@ -218,6 +219,7 @@ func New(nodeKey string, fleet string, cfg *Config, logger *zap.Logger, appDB *s
|
||||||
PeerExchange: cfg.PeerExchange,
|
PeerExchange: cfg.PeerExchange,
|
||||||
DiscoveryLimit: cfg.DiscoveryLimit,
|
DiscoveryLimit: cfg.DiscoveryLimit,
|
||||||
Nameserver: cfg.Nameserver,
|
Nameserver: cfg.Nameserver,
|
||||||
|
EnableDiscV5: cfg.EnableDiscV5,
|
||||||
}
|
}
|
||||||
|
|
||||||
waku.filters = common.NewFilters()
|
waku.filters = common.NewFilters()
|
||||||
|
@ -351,18 +353,20 @@ func New(nodeKey string, fleet string, cfg *Config, logger *zap.Logger, appDB *s
|
||||||
waku.connStatusMu.Unlock()
|
waku.connStatusMu.Unlock()
|
||||||
signal.SendPeerStats(latestConnStatus)
|
signal.SendPeerStats(latestConnStatus)
|
||||||
|
|
||||||
// Restarting DiscV5
|
if cfg.EnableDiscV5 {
|
||||||
if !latestConnStatus.IsOnline && isConnected {
|
// Restarting DiscV5
|
||||||
waku.logger.Debug("Restarting DiscV5: offline and is connected")
|
if !latestConnStatus.IsOnline && isConnected {
|
||||||
isConnected = false
|
waku.logger.Debug("Restarting DiscV5: offline and is connected")
|
||||||
waku.node.DiscV5().Stop()
|
isConnected = false
|
||||||
} else if latestConnStatus.IsOnline && !isConnected {
|
waku.node.DiscV5().Stop()
|
||||||
waku.logger.Debug("Restarting DiscV5: online and is not connected")
|
} else if latestConnStatus.IsOnline && !isConnected {
|
||||||
isConnected = true
|
waku.logger.Debug("Restarting DiscV5: online and is not connected")
|
||||||
if !waku.node.DiscV5().IsStarted() {
|
isConnected = true
|
||||||
err := waku.node.DiscV5().Start(ctx)
|
if !waku.node.DiscV5().IsStarted() {
|
||||||
if err != nil {
|
err := waku.node.DiscV5().Start(ctx)
|
||||||
waku.logger.Error("Could not start DiscV5", zap.Error(err))
|
if err != nil {
|
||||||
|
waku.logger.Error("Could not start DiscV5", zap.Error(err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1406,6 +1410,10 @@ func (w *Waku) ConnectionChanged(state connection.State) {
|
||||||
// It backs off exponentially until maxRetries, at which point it restarts from 0
|
// It backs off exponentially until maxRetries, at which point it restarts from 0
|
||||||
// It also restarts if there's a connection change signalled from the client
|
// It also restarts if there's a connection change signalled from the client
|
||||||
func (w *Waku) seedBootnodesForDiscV5() {
|
func (w *Waku) seedBootnodesForDiscV5() {
|
||||||
|
if !w.settings.EnableDiscV5 || w.node.DiscV5() == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ticker := time.NewTicker(200 * time.Millisecond)
|
ticker := time.NewTicker(200 * time.Millisecond)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
var lastTry = time.Now().UnixNano() / int64(time.Millisecond)
|
var lastTry = time.Now().UnixNano() / int64(time.Millisecond)
|
||||||
|
|
Loading…
Reference in New Issue