mirror of
https://github.com/logos-messaging/go-libp2p-pubsub.git
synced 2026-01-06 14:53:07 +00:00
refactor sendGraftPrune out of heartbeat
This commit is contained in:
parent
285c1f0aa7
commit
af061f5040
11
gossipsub.go
11
gossipsub.go
@ -338,6 +338,7 @@ func (gs *GossipSubRouter) heartbeat() {
|
|||||||
if len(peers) < GossipSubDlo {
|
if len(peers) < GossipSubDlo {
|
||||||
ineed := GossipSubD - len(peers)
|
ineed := GossipSubD - len(peers)
|
||||||
plst := gs.getPeers(topic, ineed, func(p peer.ID) bool {
|
plst := gs.getPeers(topic, ineed, func(p peer.ID) bool {
|
||||||
|
// filter our current peers
|
||||||
_, ok := peers[p]
|
_, ok := peers[p]
|
||||||
return !ok
|
return !ok
|
||||||
})
|
})
|
||||||
@ -379,6 +380,7 @@ func (gs *GossipSubRouter) heartbeat() {
|
|||||||
if len(peers) < GossipSubD {
|
if len(peers) < GossipSubD {
|
||||||
ineed := GossipSubD - len(peers)
|
ineed := GossipSubD - len(peers)
|
||||||
plst := gs.getPeers(topic, ineed, func(p peer.ID) bool {
|
plst := gs.getPeers(topic, ineed, func(p peer.ID) bool {
|
||||||
|
// filter our current peers
|
||||||
_, ok := peers[p]
|
_, ok := peers[p]
|
||||||
return !ok
|
return !ok
|
||||||
})
|
})
|
||||||
@ -392,6 +394,13 @@ func (gs *GossipSubRouter) heartbeat() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// send coalesced GRAFT/PRUNE messages (will piggyback gossip)
|
// send coalesced GRAFT/PRUNE messages (will piggyback gossip)
|
||||||
|
gs.sendGraftPrune(tograft, toprune)
|
||||||
|
|
||||||
|
// advance the message history window
|
||||||
|
gs.mcache.Shift()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gs *GossipSubRouter) sendGraftPrune(tograft, toprune map[peer.ID][]string) {
|
||||||
for p, topics := range tograft {
|
for p, topics := range tograft {
|
||||||
graft := make([]*pb.ControlGraft, 0, len(topics))
|
graft := make([]*pb.ControlGraft, 0, len(topics))
|
||||||
for _, topic := range topics {
|
for _, topic := range topics {
|
||||||
@ -422,8 +431,6 @@ func (gs *GossipSubRouter) heartbeat() {
|
|||||||
gs.sendRPC(p, out)
|
gs.sendRPC(p, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// advance the message history window
|
|
||||||
gs.mcache.Shift()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gs *GossipSubRouter) emitGossip(topic string, peers map[peer.ID]struct{}) {
|
func (gs *GossipSubRouter) emitGossip(topic string, peers map[peer.ID]struct{}) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user