From 63c977c8157a90c84a96b883a496b4a7ae96a9a0 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Fri, 1 Sep 2017 21:16:41 -0400 Subject: [PATCH 1/2] Return false when we haven't subscribed to anything --- floodsub.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/floodsub.go b/floodsub.go index adefd5f..cb98445 100644 --- a/floodsub.go +++ b/floodsub.go @@ -259,6 +259,10 @@ func (p *PubSub) markSeen(id string) { // subscribedToMessage returns whether we are subscribed to one of the topics // of a given message func (p *PubSub) subscribedToMsg(msg *pb.Message) bool { + if len(p.myTopics) == 0 { + return false + } + for _, t := range msg.GetTopicIDs() { if _, ok := p.myTopics[t]; ok { return true From 2ac19f2157e77cb632dc02bf63cecb6840d7bf67 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Fri, 1 Sep 2017 23:10:06 -0400 Subject: [PATCH 2/2] Drop announce messages to peers when their buffer is full --- floodsub.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/floodsub.go b/floodsub.go index cb98445..c6f67c1 100644 --- a/floodsub.go +++ b/floodsub.go @@ -230,8 +230,12 @@ func (p *PubSub) announce(topic string, sub bool) { } out := rpcWithSubs(subopt) - for _, peer := range p.peers { - peer <- out + for pid, peer := range p.peers { + select { + case peer <- out: + default: + log.Infof("dropping announce message to peer %s: queue full", pid) + } } }