chore:remove duplicate declaration of relay protocol const (#736)

This commit is contained in:
Prem Chaitanya Prathi 2023-09-14 14:06:08 +05:30 committed by GitHub
parent 4b1c188cf0
commit 8df69279ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 11 deletions

View File

@ -12,15 +12,12 @@ import (
ma "github.com/multiformats/go-multiaddr" ma "github.com/multiformats/go-multiaddr"
"github.com/waku-org/go-waku/logging" "github.com/waku-org/go-waku/logging"
wps "github.com/waku-org/go-waku/waku/v2/peerstore" 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" "github.com/waku-org/go-waku/waku/v2/utils"
"go.uber.org/zap" "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. // PeerManager applies various controls and manage connections towards peers.
type PeerManager struct { type PeerManager struct {
peerConnector *PeerConnectionStrategy peerConnector *PeerConnectionStrategy
@ -133,10 +130,10 @@ func (pm *PeerManager) getRelayPeers() (inRelayPeers peer.IDSlice, outRelayPeers
//Need to filter peers to check if they support relay //Need to filter peers to check if they support relay
if inPeers.Len() != 0 { if inPeers.Len() != 0 {
inRelayPeers, _ = utils.FilterPeersByProto(pm.host, inPeers, WakuRelayIDv200) inRelayPeers, _ = utils.FilterPeersByProto(pm.host, inPeers, relay.WakuRelayID_v200)
} }
if outPeers.Len() != 0 { if outPeers.Len() != 0 {
outRelayPeers, _ = utils.FilterPeersByProto(pm.host, outPeers, WakuRelayIDv200) outRelayPeers, _ = utils.FilterPeersByProto(pm.host, outPeers, relay.WakuRelayID_v200)
} }
return return
} }
@ -283,7 +280,7 @@ func (pm *PeerManager) RemovePeer(peerID peer.ID) {
// Adding to peerStore is expected to be already done by caller. // Adding to peerStore is expected to be already done by caller.
// If relay proto is passed, it is not added to serviceSlot. // If relay proto is passed, it is not added to serviceSlot.
func (pm *PeerManager) addPeerToServiceSlot(proto protocol.ID, peerID peer.ID) { 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") pm.logger.Warn("Cannot add Relay peer to service peer slots")
return return
} }

View File

@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/waku-org/go-waku/tests" "github.com/waku-org/go-waku/tests"
wps "github.com/waku-org/go-waku/waku/v2/peerstore" 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" "github.com/waku-org/go-waku/waku/v2/utils"
) )
@ -110,7 +111,7 @@ func TestDefaultProtocol(t *testing.T) {
// check peer for default protocol // check peer for default protocol
/////////////// ///////////////
//Test empty peer selection for relay 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) require.Error(t, err, utils.ErrNoPeersAvailable)
/////////////// ///////////////
@ -121,11 +122,11 @@ func TestDefaultProtocol(t *testing.T) {
defer h5.Close() defer h5.Close()
//Test peer selection for relay protocol from peer store //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) require.NoError(t, err)
// since we are not passing peerList, selectPeer fn using filterByProto checks in PeerStore for peers with same protocol. // 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.NoError(t, err)
require.Equal(t, peerID, h5.ID()) require.Equal(t, peerID, h5.ID())
} }

View File

@ -5,6 +5,7 @@ import (
"github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/protocol" "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" "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 // getPeers for getting all the peers for a given protocol
// since peerMap is only used in peerManager that's why it is unexported // since peerMap is only used in peerManager that's why it is unexported
func (slots *ServiceSlots) getPeers(proto protocol.ID) *peerMap { func (slots *ServiceSlots) getPeers(proto protocol.ID) *peerMap {
if proto == WakuRelayIDv200 { if proto == relay.WakuRelayID_v200 {
return nil return nil
} }
slots.mu.Lock() slots.mu.Lock()