fix: check listener not nil (#437)

This commit is contained in:
Andrea Maria Piana 2023-02-07 22:27:22 +00:00 committed by GitHub
parent cce85913e6
commit 7508b08c74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,6 +20,9 @@ import (
"github.com/ethereum/go-ethereum/p2p/nat"
)
var ErrNoDiscV5Listener = errors.New("no discv5 listener")
type DiscoveryV5 struct {
sync.RWMutex
@ -180,6 +183,10 @@ func (d *DiscoveryV5) Start(ctx context.Context) error {
}
func (d *DiscoveryV5) SetBootnodes(nodes []*enode.Node) error {
if d.listener == nil {
return ErrNoDiscV5Listener
}
return d.listener.SetFallbackNodes(nodes)
}
@ -243,7 +250,7 @@ func evaluateNode(node *enode.Node) bool {
func (d *DiscoveryV5) Iterator() (enode.Iterator, error) {
if d.listener == nil {
return nil, errors.New("no discv5 listener")
return nil, ErrNoDiscV5Listener
}
iterator := d.listener.RandomNodes()