Skip to content

Commit

Permalink
implementing feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer committed Oct 30, 2024
1 parent 2beb1f4 commit 3982b8d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
14 changes: 9 additions & 5 deletions wakuv2/nwaku.go
Original file line number Diff line number Diff line change
Expand Up @@ -1918,9 +1918,13 @@ func (w *Waku) ClearEnvelopesCache() {
w.envelopeCache = newTTLCache()
}

func (w *Waku) PeerCount() int {
peerCount, _ := w.GetNumConnectedPeers()
return peerCount
func (w *Waku) PeerCount() (int, error) {
peerCount, err := w.GetNumConnectedPeers()
if err != nil {
return 0, err
}

return peerCount, nil
}

// TODO-nwaku
Expand Down Expand Up @@ -2176,11 +2180,11 @@ func (w *Waku) AddRelayPeer(address multiaddr.Multiaddr) (peer.ID, error) {
}

func (w *Waku) DialPeer(address multiaddr.Multiaddr) error {
return w.WakuDialPeer(address, "", 1000)
return w.WakuDialPeer(address, "", int(requestTimeout/time.Millisecond))
}

func (w *Waku) DialPeerByID(peerID peer.ID) error {
return w.WakuDialPeerById(peerID, "", 1000)
return w.WakuDialPeerById(peerID, "", int(requestTimeout/time.Millisecond))
}

func (self *Waku) DropPeer(peerId peer.ID) error {
Expand Down
17 changes: 9 additions & 8 deletions wakuv2/nwaku_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package wakuv2
import (
"context"
"errors"
"fmt"
"slices"
"testing"
"time"
Expand Down Expand Up @@ -601,10 +600,12 @@ func TestDial(t *testing.T) {
require.NotNil(t, receiverMultiaddr)

// Check that both nodes start with no connected peers
dialerPeerCount := dialerNode.PeerCount()
dialerPeerCount, err := dialerNode.PeerCount()
require.NoError(t, err)
require.True(t, dialerPeerCount == 0, "Dialer node should have no connected peers")

receiverPeerCount := receiverNode.PeerCount()
receiverPeerCount, err := receiverNode.PeerCount()
require.NoError(t, err)
require.True(t, receiverPeerCount == 0, "Receiver node should have no connected peers")

// Dial
Expand All @@ -614,13 +615,13 @@ func TestDial(t *testing.T) {
time.Sleep(1 * time.Second)

// Check that both nodes now have one connected peer
dialerPeerCount = dialerNode.PeerCount()
peerIds, _ := dialerNode.GetPeerIdsFromPeerStore()
fmt.Println("------------- dialerNode.GetPeerIdsFromPeerStore(): ", peerIds)
dialerPeerCount, err = dialerNode.PeerCount()
require.NoError(t, err)
require.True(t, dialerPeerCount == 1, "Dialer node should have 1 peer")

receiverPeerCount = receiverNode.PeerCount()
require.True(t, receiverPeerCount == 0, "Receiver node should have 1 peer")
receiverPeerCount, err = receiverNode.PeerCount()
require.NoError(t, err)
require.True(t, receiverPeerCount == 1, "Receiver node should have 1 peer")

// Stop nodes
require.NoError(t, dialerNode.Stop())
Expand Down

0 comments on commit 3982b8d

Please sign in to comment.