mirror of
https://github.com/logos-messaging/go-libp2p-pubsub.git
synced 2026-01-05 14:23:10 +00:00
maintain fanout peer lists on heartbeat
This commit is contained in:
parent
bc25116516
commit
78618fce23
24
gossipsub.go
24
gossipsub.go
@ -404,6 +404,30 @@ func (gs *GossipSubRouter) heartbeat() {
|
||||
out := rpcWithControl(nil, nil, nil, nil, prune)
|
||||
gs.sendControl(p, out)
|
||||
}
|
||||
|
||||
// maintain our fanout for topics we are publishing but we have not joined
|
||||
for topic, peers := range gs.fanout {
|
||||
// check whether our peers are still in the topic
|
||||
for p := range peers {
|
||||
_, ok := gs.p.topics[topic][p]
|
||||
if !ok {
|
||||
delete(peers, p)
|
||||
}
|
||||
}
|
||||
|
||||
// do we need more peers
|
||||
if len(peers) < GossipSubD {
|
||||
ineed := GossipSubD - len(peers)
|
||||
plst := gs.getPeers(topic, func(p peer.ID) bool {
|
||||
_, ok := peers[p]
|
||||
return !ok
|
||||
})
|
||||
|
||||
for _, p := range plst[:ineed] {
|
||||
peers[p] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func peerListToMap(peers []peer.ID) map[peer.ID]struct{} {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user