Skip to content

Commit

Permalink
Merge branch 'master' into fix/filter-loop
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyaprem authored Oct 4, 2024
2 parents b74e4cc + 15b4aee commit 1cdb557
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
15 changes: 4 additions & 11 deletions waku/v2/discv5/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"go.uber.org/zap"

"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/enr"
"github.com/ethereum/go-ethereum/p2p/nat"
)

Expand Down Expand Up @@ -255,19 +254,13 @@ func (d *DiscoveryV5) Stop() {
}

func isWakuNode(node *enode.Node) bool {
enrField := new(wenr.WakuEnrBitfield)
if err := node.Record().Load(enr.WithEntry(wenr.WakuENRField, &enrField)); err != nil {
if !enr.IsNotFound(err) {
utils.Logger().Named("discv5").Error("could not retrieve waku2 ENR field for enr ", zap.Any("node", node))
}
enrField, err := wenr.GetWakuEnrBitField(node)
if err != nil {
utils.Logger().Named("discv5").Error("could not retrieve waku2 ENR field for enr ", zap.Error(err))
return false
}

if enrField != nil {
return *enrField != uint8(0) // #RFC 31 requirement
}

return false
return enrField != uint8(0) // #RFC 31 requirement
}

func (d *DiscoveryV5) evaluateNode() func(node *enode.Node) bool {
Expand Down
12 changes: 3 additions & 9 deletions waku/v2/discv5/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
wenr "github.com/waku-org/go-waku/waku/v2/protocol/enr"

"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/enr"
)

// FilterPredicate is to create a Predicate using a custom function
Expand Down Expand Up @@ -36,16 +35,11 @@ func FilterShard(cluster, index uint16) Predicate {
func FilterCapabilities(flags wenr.WakuEnrBitfield) Predicate {
return func(iterator enode.Iterator) enode.Iterator {
predicate := func(node *enode.Node) bool {
enrField := new(wenr.WakuEnrBitfield)
if err := node.Record().Load(enr.WithEntry(wenr.WakuENRField, &enrField)); err != nil {
enrField, err := wenr.GetWakuEnrBitField(node)
if err != nil {
return false
}

if enrField == nil {
return false
}

return *enrField&flags == flags
return enrField&flags == flags
}
return enode.Filter(iterator, predicate)
}
Expand Down
5 changes: 2 additions & 3 deletions waku/v2/peermanager/peer_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"sync"
"time"

"github.com/ethereum/go-ethereum/p2p/enr"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/libp2p/go-libp2p/core/event"
"github.com/libp2p/go-libp2p/core/host"
Expand Down Expand Up @@ -543,8 +542,8 @@ func (pm *PeerManager) processPeerENR(p *service.PeerData) []protocol.ID {
}
supportedProtos := []protocol.ID{}
//Identify and specify protocols supported by the peer based on the discovered peer's ENR
var enrField wenr.WakuEnrBitfield
if err := p.ENR.Record().Load(enr.WithEntry(wenr.WakuENRField, &enrField)); err == nil {
enrField, err := wenr.GetWakuEnrBitField(p.ENR)
if err == nil {
for proto, protoENR := range pm.wakuprotoToENRFieldMap {
protoENRField := protoENR.waku2ENRBitField
if protoENRField&enrField != 0 {
Expand Down
17 changes: 17 additions & 0 deletions waku/v2/protocol/enr/enr.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ const ShardingBitVectorEnrField = "rsv"
// WakuEnrBitfield is a8-bit flag field to indicate Waku capabilities. Only the 4 LSBs are currently defined according to RFC31 (https://rfc.vac.dev/spec/31/).
type WakuEnrBitfield = uint8

func GetWakuEnrBitField(node *enode.Node) (WakuEnrBitfield, error) {
enrField := []byte{}
err := node.Record().Load(enr.WithEntry(WakuENRField, &enrField))
if err != nil {
if enr.IsNotFound(err) {
return 0, nil
}
return 0, err
}

if len(enrField) == 0 {
return 0, err
}

return WakuEnrBitfield(enrField[0]), nil
}

// NewWakuEnrBitfield creates a WakuEnrBitField whose value will depend on which protocols are enabled in the node
func NewWakuEnrBitfield(lightpush, filter, store, relay bool) WakuEnrBitfield {
var v uint8
Expand Down

0 comments on commit 1cdb557

Please sign in to comment.