fix: fix relay peer calculation (#650)

This commit is contained in:
Prem Chaitanya Prathi 2023-08-17 18:26:20 +05:30 committed by GitHub
parent 770f41158f
commit 287d7a014e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 3 deletions

View File

@ -102,8 +102,9 @@ func (pm *PeerManager) connectivityLoop(ctx context.Context) {
// GroupPeersByDirection returns all the connected peers in peer store grouped by Inbound or outBound direction // GroupPeersByDirection returns all the connected peers in peer store grouped by Inbound or outBound direction
func (pm *PeerManager) GroupPeersByDirection() (inPeers peer.IDSlice, outPeers peer.IDSlice, err error) { func (pm *PeerManager) GroupPeersByDirection() (inPeers peer.IDSlice, outPeers peer.IDSlice, err error) {
peers := pm.host.Network().Peers()
for _, p := range pm.host.Network().Peers() { for _, p := range peers {
direction, err := pm.host.Peerstore().(wps.WakuPeerstore).Direction(p) direction, err := pm.host.Peerstore().(wps.WakuPeerstore).Direction(p)
if err == nil { if err == nil {
if direction == network.DirInbound { if direction == network.DirInbound {
@ -129,8 +130,12 @@ func (pm *PeerManager) getRelayPeers() (inRelayPeers peer.IDSlice, outRelayPeers
zap.Int("outPeers", outPeers.Len())) zap.Int("outPeers", outPeers.Len()))
//Need to filter peers to check if they support relay //Need to filter peers to check if they support relay
inRelayPeers, _ = utils.FilterPeersByProto(pm.host, inPeers, WakuRelayIDv200) if inPeers.Len() != 0 {
outRelayPeers, _ = utils.FilterPeersByProto(pm.host, outPeers, WakuRelayIDv200) inRelayPeers, _ = utils.FilterPeersByProto(pm.host, inPeers, WakuRelayIDv200)
}
if outPeers.Len() != 0 {
outRelayPeers, _ = utils.FilterPeersByProto(pm.host, outPeers, WakuRelayIDv200)
}
pm.logger.Info("Number of Relay peers connected", zap.Int("inRelayPeers", inRelayPeers.Len()), pm.logger.Info("Number of Relay peers connected", zap.Int("inRelayPeers", inRelayPeers.Len()),
zap.Int("outRelayPeers", outRelayPeers.Len())) zap.Int("outRelayPeers", outRelayPeers.Len()))
return return