diff --git a/waku/v2/peermanager/peer_manager.go b/waku/v2/peermanager/peer_manager.go index 72d2d293..69f665df 100644 --- a/waku/v2/peermanager/peer_manager.go +++ b/waku/v2/peermanager/peer_manager.go @@ -12,15 +12,12 @@ import ( ma "github.com/multiformats/go-multiaddr" "github.com/waku-org/go-waku/logging" wps "github.com/waku-org/go-waku/waku/v2/peerstore" + "github.com/waku-org/go-waku/waku/v2/protocol/relay" "github.com/waku-org/go-waku/waku/v2/utils" "go.uber.org/zap" ) -// WakuRelayIDv200 is protocol ID for Waku v2 relay protocol -// TODO: Move all the protocol IDs to a common location. -const WakuRelayIDv200 = protocol.ID("/vac/waku/relay/2.0.0") - // PeerManager applies various controls and manage connections towards peers. type PeerManager struct { peerConnector *PeerConnectionStrategy @@ -133,10 +130,10 @@ func (pm *PeerManager) getRelayPeers() (inRelayPeers peer.IDSlice, outRelayPeers //Need to filter peers to check if they support relay if inPeers.Len() != 0 { - inRelayPeers, _ = utils.FilterPeersByProto(pm.host, inPeers, WakuRelayIDv200) + inRelayPeers, _ = utils.FilterPeersByProto(pm.host, inPeers, relay.WakuRelayID_v200) } if outPeers.Len() != 0 { - outRelayPeers, _ = utils.FilterPeersByProto(pm.host, outPeers, WakuRelayIDv200) + outRelayPeers, _ = utils.FilterPeersByProto(pm.host, outPeers, relay.WakuRelayID_v200) } return } @@ -283,7 +280,7 @@ func (pm *PeerManager) RemovePeer(peerID peer.ID) { // Adding to peerStore is expected to be already done by caller. // If relay proto is passed, it is not added to serviceSlot. func (pm *PeerManager) addPeerToServiceSlot(proto protocol.ID, peerID peer.ID) { - if proto == WakuRelayIDv200 { + if proto == relay.WakuRelayID_v200 { pm.logger.Warn("Cannot add Relay peer to service peer slots") return } diff --git a/waku/v2/peermanager/peer_manager_test.go b/waku/v2/peermanager/peer_manager_test.go index a64bce9f..ac7c2b1c 100644 --- a/waku/v2/peermanager/peer_manager_test.go +++ b/waku/v2/peermanager/peer_manager_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/require" "github.com/waku-org/go-waku/tests" wps "github.com/waku-org/go-waku/waku/v2/peerstore" + "github.com/waku-org/go-waku/waku/v2/protocol/relay" "github.com/waku-org/go-waku/waku/v2/utils" ) @@ -110,7 +111,7 @@ func TestDefaultProtocol(t *testing.T) { // check peer for default protocol /////////////// //Test empty peer selection for relay protocol - _, err := pm.SelectPeer(WakuRelayIDv200, nil) + _, err := pm.SelectPeer(relay.WakuRelayID_v200, nil) require.Error(t, err, utils.ErrNoPeersAvailable) /////////////// @@ -121,11 +122,11 @@ func TestDefaultProtocol(t *testing.T) { defer h5.Close() //Test peer selection for relay protocol from peer store - _, err = pm.AddPeer(getAddr(h5), wps.Static, WakuRelayIDv200) + _, err = pm.AddPeer(getAddr(h5), wps.Static, relay.WakuRelayID_v200) require.NoError(t, err) // since we are not passing peerList, selectPeer fn using filterByProto checks in PeerStore for peers with same protocol. - peerID, err := pm.SelectPeer(WakuRelayIDv200, nil) + peerID, err := pm.SelectPeer(relay.WakuRelayID_v200, nil) require.NoError(t, err) require.Equal(t, peerID, h5.ID()) } diff --git a/waku/v2/peermanager/service_slot.go b/waku/v2/peermanager/service_slot.go index aff2d856..c88711e7 100644 --- a/waku/v2/peermanager/service_slot.go +++ b/waku/v2/peermanager/service_slot.go @@ -5,6 +5,7 @@ import ( "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/protocol" + "github.com/waku-org/go-waku/waku/v2/protocol/relay" "github.com/waku-org/go-waku/waku/v2/utils" ) @@ -57,7 +58,7 @@ func NewServiceSlot() *ServiceSlots { // getPeers for getting all the peers for a given protocol // since peerMap is only used in peerManager that's why it is unexported func (slots *ServiceSlots) getPeers(proto protocol.ID) *peerMap { - if proto == WakuRelayIDv200 { + if proto == relay.WakuRelayID_v200 { return nil } slots.mu.Lock()