Merge pull request #35 from film42/gt/slow_announce

Drop announce messages to slow peers
This commit is contained in:
Steven Allen 2017-09-04 16:23:44 -07:00 committed by GitHub
commit d884976a41
1 changed files with 10 additions and 2 deletions

View File

@ -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)
}
}
}
@ -259,6 +263,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