From cd94989155c7d3b92d233b9e72ab357e173b33eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Sun, 6 Oct 2019 18:50:17 +0900 Subject: [PATCH 1/4] emitGossip: rename param name for clarity. --- gossipsub.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gossipsub.go b/gossipsub.go index f7e72a9a..090f41d1 100644 --- a/gossipsub.go +++ b/gossipsub.go @@ -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) } @@ -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) } @@ -515,7 +519,9 @@ 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 @@ -524,7 +530,7 @@ func (gs *GossipSubRouter) emitGossip(topic string, peers map[peer.ID]struct{}) gpeers := gs.getPeers(topic, GossipSubD, func(peer.ID) bool { return true }) for _, p := range gpeers { // skip mesh peers - _, ok := peers[p] + _, ok := exclude[p] if !ok { gs.pushGossip(p, &pb.ControlIHave{TopicID: &topic, MessageIDs: mids}) } From 9103afa349246a8c864e163dde5da4cd7c47f45b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Sun, 6 Oct 2019 18:52:11 +0900 Subject: [PATCH 2/4] emitGossip: gossip to D peers. --- gossipsub.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/gossipsub.go b/gossipsub.go index 090f41d1..3d2993e8 100644 --- a/gossipsub.go +++ b/gossipsub.go @@ -527,13 +527,15 @@ func (gs *GossipSubRouter) emitGossip(topic string, exclude map[peer.ID]struct{} return } - gpeers := gs.getPeers(topic, GossipSubD, func(peer.ID) bool { return true }) - for _, p := range gpeers { - // skip mesh peers + // Send gossip to D peers, skipping over the exclude set. + gpeers := gs.getPeers(topic, GossipSubD, func(p peer.ID) bool { _, ok := exclude[p] - if !ok { - gs.pushGossip(p, &pb.ControlIHave{TopicID: &topic, MessageIDs: mids}) - } + return !ok + }) + + // Emit the IHAVE gossip to the selected peers. + for _, p := range gpeers { + gs.pushGossip(p, &pb.ControlIHave{TopicID: &topic, MessageIDs: mids}) } } From 2a90debb89af4e47125211e32f54dab085846dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Sun, 6 Oct 2019 18:53:05 +0900 Subject: [PATCH 3/4] rename pushGossip to queueGossip for accuracy. --- gossipsub.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gossipsub.go b/gossipsub.go index 3d2993e8..e14146eb 100644 --- a/gossipsub.go +++ b/gossipsub.go @@ -535,7 +535,7 @@ func (gs *GossipSubRouter) emitGossip(topic string, exclude map[peer.ID]struct{} // Emit the IHAVE gossip to the selected peers. for _, p := range gpeers { - gs.pushGossip(p, &pb.ControlIHave{TopicID: &topic, MessageIDs: mids}) + gs.queueGossip(p, &pb.ControlIHave{TopicID: &topic, MessageIDs: mids}) } } @@ -555,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) { gossip := gs.gossip[p] gossip = append(gossip, ihave) gs.gossip[p] = gossip From 8d7838b031b6b47c3636dd07d933514ee67feec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Sat, 12 Oct 2019 21:50:20 +0900 Subject: [PATCH 4/4] rename queueGossip() to enqueueGossip(). --- gossipsub.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gossipsub.go b/gossipsub.go index e14146eb..9b8c3adf 100644 --- a/gossipsub.go +++ b/gossipsub.go @@ -535,7 +535,7 @@ func (gs *GossipSubRouter) emitGossip(topic string, exclude map[peer.ID]struct{} // Emit the IHAVE gossip to the selected peers. for _, p := range gpeers { - gs.queueGossip(p, &pb.ControlIHave{TopicID: &topic, MessageIDs: mids}) + gs.enqueueGossip(p, &pb.ControlIHave{TopicID: &topic, MessageIDs: mids}) } } @@ -555,7 +555,7 @@ func (gs *GossipSubRouter) flush() { } } -func (gs *GossipSubRouter) queueGossip(p peer.ID, ihave *pb.ControlIHave) { +func (gs *GossipSubRouter) enqueueGossip(p peer.ID, ihave *pb.ControlIHave) { gossip := gs.gossip[p] gossip = append(gossip, ihave) gs.gossip[p] = gossip