From f9ce661bda2c4d2dc15288f66788a06252244dc2 Mon Sep 17 00:00:00 2001 From: vyzo Date: Mon, 2 Mar 2020 15:13:15 +0200 Subject: [PATCH] filter peers with negative score in initial mesh on join --- gossipsub.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gossipsub.go b/gossipsub.go index fcf278d..d913ee8 100644 --- a/gossipsub.go +++ b/gossipsub.go @@ -511,9 +511,10 @@ func (gs *GossipSubRouter) Join(topic string) { if len(gmap) < GossipSubD { // we need more peers; eager, as this would get fixed in the next heartbeat more := gs.getPeers(topic, GossipSubD-len(gmap), func(p peer.ID) bool { - // filter our current peers + // filter our current peers and peers with negative scores _, ok := gmap[p] - return !ok + score := gs.score.Score(p) + return !ok && score >= 0 }) for _, p := range more { gmap[p] = struct{}{} @@ -523,7 +524,11 @@ func (gs *GossipSubRouter) Join(topic string) { delete(gs.fanout, topic) delete(gs.lastpub, topic) } else { - peers := gs.getPeers(topic, GossipSubD, func(peer.ID) bool { return true }) + peers := gs.getPeers(topic, GossipSubD, func(p peer.ID) bool { + // filter peers with negative score + score := gs.score.Score(p) + return score >= 0 + }) gmap = peerListToMap(peers) gs.mesh[topic] = gmap }