short-circuit score computation in peer selection filters
This commit is contained in:
parent
98671566a2
commit
ff89a0e619
15
gossipsub.go
15
gossipsub.go
@ -611,8 +611,7 @@ func (gs *GossipSubRouter) Join(topic string) {
|
|||||||
more := gs.getPeers(topic, GossipSubD-len(gmap), func(p peer.ID) bool {
|
more := gs.getPeers(topic, GossipSubD-len(gmap), func(p peer.ID) bool {
|
||||||
// filter our current peers and peers with negative scores
|
// filter our current peers and peers with negative scores
|
||||||
_, ok := gmap[p]
|
_, ok := gmap[p]
|
||||||
score := gs.score.Score(p)
|
return !ok && gs.score.Score(p) >= 0
|
||||||
return !ok && score >= 0
|
|
||||||
})
|
})
|
||||||
for _, p := range more {
|
for _, p := range more {
|
||||||
gmap[p] = struct{}{}
|
gmap[p] = struct{}{}
|
||||||
@ -624,8 +623,7 @@ func (gs *GossipSubRouter) Join(topic string) {
|
|||||||
} else {
|
} else {
|
||||||
peers := gs.getPeers(topic, GossipSubD, func(p peer.ID) bool {
|
peers := gs.getPeers(topic, GossipSubD, func(p peer.ID) bool {
|
||||||
// filter peers with negative score
|
// filter peers with negative score
|
||||||
score := gs.score.Score(p)
|
return gs.score.Score(p) >= 0
|
||||||
return score >= 0
|
|
||||||
})
|
})
|
||||||
gmap = peerListToMap(peers)
|
gmap = peerListToMap(peers)
|
||||||
gs.mesh[topic] = gmap
|
gs.mesh[topic] = gmap
|
||||||
@ -786,8 +784,7 @@ func (gs *GossipSubRouter) heartbeat() {
|
|||||||
// filter our current peers, peers we are backing off, and peers with negative score
|
// filter our current peers, peers we are backing off, and peers with negative score
|
||||||
_, inMesh := peers[p]
|
_, inMesh := peers[p]
|
||||||
_, doBackoff := backoff[p]
|
_, doBackoff := backoff[p]
|
||||||
score := gs.score.Score(p)
|
return !inMesh && !doBackoff && gs.score.Score(p) >= 0
|
||||||
return !inMesh && !doBackoff && score >= 0
|
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, p := range plst {
|
for _, p := range plst {
|
||||||
@ -837,8 +834,7 @@ func (gs *GossipSubRouter) heartbeat() {
|
|||||||
// check whether our peers are still in the topic and have a score above the publish threshold
|
// check whether our peers are still in the topic and have a score above the publish threshold
|
||||||
for p := range peers {
|
for p := range peers {
|
||||||
_, ok := gs.p.topics[topic][p]
|
_, ok := gs.p.topics[topic][p]
|
||||||
score := gs.score.Score(p)
|
if !ok || gs.score.Score(p) < gs.publishThreshold {
|
||||||
if !ok || score < gs.publishThreshold {
|
|
||||||
delete(peers, p)
|
delete(peers, p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -849,8 +845,7 @@ func (gs *GossipSubRouter) heartbeat() {
|
|||||||
plst := gs.getPeers(topic, ineed, func(p peer.ID) bool {
|
plst := gs.getPeers(topic, ineed, func(p peer.ID) bool {
|
||||||
// filter our current peers and peers with score above the publish threshold
|
// filter our current peers and peers with score above the publish threshold
|
||||||
_, ok := peers[p]
|
_, ok := peers[p]
|
||||||
score := gs.score.Score(p)
|
return !ok && gs.score.Score(p) >= gs.publishThreshold
|
||||||
return !ok && score >= gs.publishThreshold
|
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, p := range plst {
|
for _, p := range plst {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user