Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gossip methods: renames and predicate adjustment #204

Merged
merged 4 commits into from
Oct 12, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions gossipsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ func (gs *GossipSubRouter) heartbeat() {
}
}

// 2nd arg are mesh peers excluded from gossip. We already push
// messages to them, so its redundant to gossip IHAVEs.
gs.emitGossip(topic, peers)
}

Expand Down Expand Up @@ -472,6 +474,8 @@ func (gs *GossipSubRouter) heartbeat() {
}
}

// 2nd arg are fanout peers excluded from gossip. We already push
// messages to them, so its redundant to gossip IHAVEs.
gs.emitGossip(topic, peers)
}

Expand Down Expand Up @@ -515,19 +519,23 @@ func (gs *GossipSubRouter) sendGraftPrune(tograft, toprune map[peer.ID][]string)

}

func (gs *GossipSubRouter) emitGossip(topic string, peers map[peer.ID]struct{}) {
// emitGossip emits IHAVE gossip advertising items in the message cache window
// of this topic.
func (gs *GossipSubRouter) emitGossip(topic string, exclude map[peer.ID]struct{}) {
mids := gs.mcache.GetGossipIDs(topic)
if len(mids) == 0 {
return
}

gpeers := gs.getPeers(topic, GossipSubD, func(peer.ID) bool { return true })
// Send gossip to D peers, skipping over the exclude set.
gpeers := gs.getPeers(topic, GossipSubD, func(p peer.ID) bool {
raulk marked this conversation as resolved.
Show resolved Hide resolved
_, ok := exclude[p]
return !ok
})

// Emit the IHAVE gossip to the selected peers.
for _, p := range gpeers {
// skip mesh peers
_, ok := peers[p]
if !ok {
gs.pushGossip(p, &pb.ControlIHave{TopicID: &topic, MessageIDs: mids})
}
gs.queueGossip(p, &pb.ControlIHave{TopicID: &topic, MessageIDs: mids})
}
}

Expand All @@ -547,7 +555,7 @@ func (gs *GossipSubRouter) flush() {
}
}

func (gs *GossipSubRouter) pushGossip(p peer.ID, ihave *pb.ControlIHave) {
func (gs *GossipSubRouter) queueGossip(p peer.ID, ihave *pb.ControlIHave) {
raulk marked this conversation as resolved.
Show resolved Hide resolved
gossip := gs.gossip[p]
gossip = append(gossip, ihave)
gs.gossip[p] = gossip
Expand Down