Skip to content

Commit

Permalink
Merge branch 'master' into fix/relay-rest-unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyaprem authored Nov 7, 2023
2 parents b154233 + 9315de8 commit 8fd4d0f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
17 changes: 8 additions & 9 deletions waku/v2/discv5/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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 @@ -250,34 +251,32 @@ func (d *DiscoveryV5) Stop() {
})
}

/*
func isWakuNode(node *enode.Node) bool {
enrField := new(utils.WakuEnrBitfield)
if err := node.Record().Load(enr.WithEntry(utils.WakuENRField, &enrField)); err != nil {
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 port for enr ", zap.Any("node", node))
utils.Logger().Named("discv5").Error("could not retrieve waku2 ENR field for enr ", zap.Any("node", node))
}
return false
}

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

return false
}
*/

func (d *DiscoveryV5) evaluateNode() func(node *enode.Node) bool {
return func(node *enode.Node) bool {
if node == nil {
return false
}

// TODO: consider node filtering based on ENR; we do not filter based on ENR in the first waku discv5 beta stage
/*if !isWakuNode(node) {
// node filtering based on ENR; we do not filter based on ENR in the first waku discv5 beta stage
if !isWakuNode(node) {
return false
}*/
}

_, err := wenr.EnodeToPeerInfo(node)

Expand Down
20 changes: 20 additions & 0 deletions waku/v2/discv5/discover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func extractIP(addr multiaddr.Multiaddr) (*net.TCPAddr, error) {

func TestDiscV5(t *testing.T) {
// Host1 <-> Host2 <-> Host3
// Host4(No waku capabilities) <-> Host2

// H1
host1, _, prvKey1 := createHost(t)
Expand Down Expand Up @@ -138,9 +139,22 @@ func TestDiscV5(t *testing.T) {
require.NoError(t, err)
d3.SetHost(host3)

// H4 doesn't have any Waku capabilities
host4, _, prvKey4 := createHost(t)
ip4, _ := extractIP(host2.Addrs()[0])
udpPort4, err := tests.FindFreeUDPPort(t, "127.0.0.1", 3)
require.NoError(t, err)
l4, err := newLocalnode(prvKey4, ip4, udpPort4, 0, nil, utils.Logger())
require.NoError(t, err)
peerconn4 := peermanager.NewTestPeerDiscoverer()
d4, err := NewDiscoveryV5(prvKey4, l4, peerconn4, prometheus.DefaultRegisterer, utils.Logger(), WithUDPPort(uint(udpPort4)), WithBootnodes([]*enode.Node{d2.localnode.Node()}))
require.NoError(t, err)
d2.SetHost(host2)

defer d1.Stop()
defer d2.Stop()
defer d3.Stop()
defer d4.Stop()

err = d1.Start(context.Background())
require.NoError(t, err)
Expand All @@ -151,9 +165,13 @@ func TestDiscV5(t *testing.T) {
err = d3.Start(context.Background())
require.NoError(t, err)

err = d4.Start(context.Background())
require.NoError(t, err)

time.Sleep(2 * time.Second) // Wait for nodes to be discovered

require.True(t, peerconn3.HasPeer(host1.ID()) && peerconn3.HasPeer(host2.ID()))
require.False(t, peerconn3.HasPeer(host4.ID())) //host4 should not be discoverable, rather filtered out.

d3.Stop()
peerconn3.Clear()
Expand All @@ -165,4 +183,6 @@ func TestDiscV5(t *testing.T) {
time.Sleep(2 * time.Second) // Wait for nodes to be discovered

require.True(t, peerconn3.HasPeer(host1.ID()) && peerconn3.HasPeer(host2.ID()))
require.False(t, peerconn3.HasPeer(host4.ID())) //host4 should not be discoverable, rather filtered out.

}

0 comments on commit 8fd4d0f

Please sign in to comment.