add Join/Leave to PubSubRouter interface

advanced routers will want to know when they are subscribed to a topic as
they may want to send control messages.
This commit is contained in:
vyzo 2018-02-03 11:30:19 +02:00 committed by Steven Allen
parent 1c92f1a4f2
commit 8680a79d3a
2 changed files with 8 additions and 0 deletions

View File

@ -78,3 +78,7 @@ func (fs *FloodSubRouter) Publish(from peer.ID, msg *pb.Message) {
}
}
}
func (fs *FloodSubRouter) Join(topic string) {}
func (fs *FloodSubRouter) Leave(topic string) {}

View File

@ -96,6 +96,8 @@ type PubSubRouter interface {
RemovePeer(peer.ID)
HandleRPC(*RPC)
Publish(peer.ID, *pb.Message)
Join(topic string)
Leave(topic string)
}
type Message struct {
@ -276,6 +278,7 @@ func (p *PubSub) handleRemoveSubscription(sub *Subscription) {
if len(subs) == 0 {
delete(p.myTopics, sub.topic)
p.announce(sub.topic, false)
p.rt.Leave(sub.topic)
}
}
@ -290,6 +293,7 @@ func (p *PubSub) handleAddSubscription(req *addSubReq) {
// announce we want this topic
if len(subs) == 0 {
p.announce(sub.topic, true)
p.rt.Join(sub.topic)
}
// make new if not there