mirror of https://github.com/status-im/go-waku.git
feat: dont' filter out bootnodes (#860)
This commit is contained in:
parent
02f2800b04
commit
e0c6ab8ee1
|
@ -51,7 +51,7 @@ type DiscoveryV5 struct {
|
|||
type discV5Parameters struct {
|
||||
autoUpdate bool
|
||||
autoFindPeers bool
|
||||
bootnodes []*enode.Node
|
||||
bootnodes map[enode.ID]*enode.Node
|
||||
udpPort uint
|
||||
advertiseAddr []multiaddr.Multiaddr
|
||||
loopPredicate func(*enode.Node) bool
|
||||
|
@ -74,7 +74,10 @@ func WithAutoUpdate(autoUpdate bool) DiscoveryV5Option {
|
|||
// WithBootnodes is an option used to specify the bootstrap nodes to use with DiscV5
|
||||
func WithBootnodes(bootnodes []*enode.Node) DiscoveryV5Option {
|
||||
return func(params *discV5Parameters) {
|
||||
params.bootnodes = bootnodes
|
||||
params.bootnodes = make(map[enode.ID]*enode.Node)
|
||||
for _, b := range bootnodes {
|
||||
params.bootnodes[b.ID()] = b
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,6 +129,11 @@ func NewDiscoveryV5(priv *ecdsa.PrivateKey, localnode *enode.LocalNode, peerConn
|
|||
NAT = nat.Any()
|
||||
}
|
||||
|
||||
var bootnodes []*enode.Node
|
||||
for _, bootnode := range params.bootnodes {
|
||||
bootnodes = append(bootnodes, bootnode)
|
||||
}
|
||||
|
||||
return &DiscoveryV5{
|
||||
params: params,
|
||||
peerConnector: peerConnector,
|
||||
|
@ -135,7 +143,7 @@ func NewDiscoveryV5(priv *ecdsa.PrivateKey, localnode *enode.LocalNode, peerConn
|
|||
metrics: newMetrics(reg),
|
||||
config: discover.Config{
|
||||
PrivateKey: priv,
|
||||
Bootnodes: params.bootnodes,
|
||||
Bootnodes: bootnodes,
|
||||
V5Config: discover.V5Config{
|
||||
ProtocolID: &protocolID,
|
||||
},
|
||||
|
@ -379,7 +387,8 @@ func delayedHasNext(ctx context.Context, iterator enode.Iterator) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (d *DiscoveryV5) defaultPredicate() Predicate {
|
||||
// DefaultPredicate contains the conditions to be applied when filtering peers discovered via discv5
|
||||
func (d *DiscoveryV5) DefaultPredicate() Predicate {
|
||||
return FilterPredicate(func(n *enode.Node) bool {
|
||||
localRS, err := wenr.RelaySharding(d.localnode.Node().Record())
|
||||
if err != nil {
|
||||
|
@ -390,6 +399,10 @@ func (d *DiscoveryV5) defaultPredicate() Predicate {
|
|||
return true
|
||||
}
|
||||
|
||||
if _, ok := d.params.bootnodes[n.ID()]; ok {
|
||||
return true // The record is a bootnode. Assume it's valid and dont filter it out
|
||||
}
|
||||
|
||||
nodeRS, err := wenr.RelaySharding(n.Record())
|
||||
if err != nil {
|
||||
return false
|
||||
|
@ -417,7 +430,7 @@ func (d *DiscoveryV5) defaultPredicate() Predicate {
|
|||
|
||||
// Iterates over the nodes found via discv5 belonging to the node's current shard, and sends them to peerConnector
|
||||
func (d *DiscoveryV5) peerLoop(ctx context.Context) error {
|
||||
iterator, err := d.PeerIterator(d.defaultPredicate())
|
||||
iterator, err := d.PeerIterator(d.DefaultPredicate())
|
||||
if err != nil {
|
||||
d.metrics.RecordError(iteratorFailure)
|
||||
return fmt.Errorf("obtaining iterator: %w", err)
|
||||
|
@ -448,7 +461,7 @@ func (d *DiscoveryV5) runDiscoveryV5Loop(ctx context.Context) {
|
|||
if len(d.config.Bootnodes) > 0 {
|
||||
localRS, err := wenr.RelaySharding(d.localnode.Node().Record())
|
||||
if err == nil && localRS != nil {
|
||||
iterator := d.defaultPredicate()(enode.IterNodes(d.config.Bootnodes))
|
||||
iterator := d.DefaultPredicate()(enode.IterNodes(d.config.Bootnodes))
|
||||
validBootCount := 0
|
||||
for iterator.Next() {
|
||||
validBootCount++
|
||||
|
|
Loading…
Reference in New Issue