From af061f5040a8e0dd4ba172bb08bc35b2c2836e8b Mon Sep 17 00:00:00 2001 From: vyzo Date: Thu, 22 Feb 2018 10:18:48 +0200 Subject: [PATCH] refactor sendGraftPrune out of heartbeat --- gossipsub.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gossipsub.go b/gossipsub.go index 8793977..b50de38 100644 --- a/gossipsub.go +++ b/gossipsub.go @@ -338,6 +338,7 @@ func (gs *GossipSubRouter) heartbeat() { if len(peers) < GossipSubDlo { ineed := GossipSubD - len(peers) plst := gs.getPeers(topic, ineed, func(p peer.ID) bool { + // filter our current peers _, ok := peers[p] return !ok }) @@ -379,6 +380,7 @@ func (gs *GossipSubRouter) heartbeat() { if len(peers) < GossipSubD { ineed := GossipSubD - len(peers) plst := gs.getPeers(topic, ineed, func(p peer.ID) bool { + // filter our current peers _, ok := peers[p] return !ok }) @@ -392,6 +394,13 @@ func (gs *GossipSubRouter) heartbeat() { } // 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 { graft := make([]*pb.ControlGraft, 0, len(topics)) for _, topic := range topics { @@ -422,8 +431,6 @@ func (gs *GossipSubRouter) heartbeat() { gs.sendRPC(p, out) } - // advance the message history window - gs.mcache.Shift() } func (gs *GossipSubRouter) emitGossip(topic string, peers map[peer.ID]struct{}) {