mirror of
https://github.com/logos-messaging/go-libp2p-pubsub.git
synced 2026-01-08 15:53:07 +00:00
adaptive gossip dissemination
This commit is contained in:
parent
8fb6924f7c
commit
f9d29c47b6
34
gossipsub.go
34
gossipsub.go
@ -34,6 +34,9 @@ var (
|
|||||||
GossipSubHistoryLength = 5
|
GossipSubHistoryLength = 5
|
||||||
GossipSubHistoryGossip = 3
|
GossipSubHistoryGossip = 3
|
||||||
|
|
||||||
|
GossipSubDlazy = 6
|
||||||
|
GossipSubGossipFactor = 0.25
|
||||||
|
|
||||||
// heartbeat interval
|
// heartbeat interval
|
||||||
GossipSubHeartbeatInitialDelay = 100 * time.Millisecond
|
GossipSubHeartbeatInitialDelay = 100 * time.Millisecond
|
||||||
GossipSubHeartbeatInterval = 1 * time.Second
|
GossipSubHeartbeatInterval = 1 * time.Second
|
||||||
@ -900,15 +903,32 @@ func (gs *GossipSubRouter) emitGossip(topic string, exclude map[peer.ID]struct{}
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send gossip to D peers, skipping over the exclude set and peers with score below the threshold
|
// Send gossip to GossipFactor peers above threshold, with a minimum of D_lazy.
|
||||||
gpeers := gs.getPeers(topic, GossipSubD, func(p peer.ID) bool {
|
// First we collect the peers above gossipThreshold that are not in the exclude set
|
||||||
_, ok := exclude[p]
|
// and then randomly select from that set.
|
||||||
score := gs.score.Score(p)
|
peers := make([]peer.ID, 0, len(gs.p.topics[topic]))
|
||||||
return !ok && score >= gs.gossipThreshold
|
for p := range gs.p.topics[topic] {
|
||||||
})
|
_, inExclude := exclude[p]
|
||||||
|
if !inExclude && (gs.peers[p] == GossipSubID_v10 || gs.peers[p] == GossipSubID_v11) && gs.score.Score(p) >= gs.gossipThreshold {
|
||||||
|
peers = append(peers, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
target := GossipSubDlazy
|
||||||
|
factor := int(GossipSubGossipFactor * float64(len(peers)))
|
||||||
|
if factor > target {
|
||||||
|
target = factor
|
||||||
|
}
|
||||||
|
|
||||||
|
if target > len(peers) {
|
||||||
|
target = len(peers)
|
||||||
|
} else {
|
||||||
|
shufflePeers(peers)
|
||||||
|
}
|
||||||
|
peers = peers[:target]
|
||||||
|
|
||||||
// Emit the IHAVE gossip to the selected peers.
|
// Emit the IHAVE gossip to the selected peers.
|
||||||
for _, p := range gpeers {
|
for _, p := range peers {
|
||||||
gs.enqueueGossip(p, &pb.ControlIHave{TopicID: &topic, MessageIDs: mids})
|
gs.enqueueGossip(p, &pb.ControlIHave{TopicID: &topic, MessageIDs: mids})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user