refactor sendGraftPrune out of heartbeat

This commit is contained in:
vyzo 2018-02-22 10:18:48 +02:00 committed by Steven Allen
parent 285c1f0aa7
commit af061f5040

View File

@ -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{}) {