avoid triggering unsubscribeAll from unsubscribe (gossip)

This commit is contained in:
Giovanni Petrantoni 2020-12-20 17:08:03 +09:00
parent 4858e0ab15
commit 5e79d3ab9c
1 changed files with 4 additions and 2 deletions

View File

@ -1251,7 +1251,7 @@ method subscribe*(g: GossipSub,
g.rebalanceMesh(topic) g.rebalanceMesh(topic)
method unsubscribeAll*(g: GossipSub, topic: string) = proc unsubscribe*(g: GossipSub, topic: string) =
var var
msg = RPCMsg.withSubs(@[topic], subscribe = false) msg = RPCMsg.withSubs(@[topic], subscribe = false)
gpeers = g.gossipsub.getOrDefault(topic) gpeers = g.gossipsub.getOrDefault(topic)
@ -1281,6 +1281,8 @@ method unsubscribeAll*(g: GossipSub, topic: string) =
else: else:
g.broadcast(toSeq(gpeers), msg) g.broadcast(toSeq(gpeers), msg)
method unsubscribeAll*(g: GossipSub, topic: string) =
g.unsubscribe(topic)
# finally let's remove from g.topics, do that by calling PubSub # finally let's remove from g.topics, do that by calling PubSub
procCall PubSub(g).unsubscribeAll(topic) procCall PubSub(g).unsubscribeAll(topic)
@ -1292,7 +1294,7 @@ method unsubscribe*(g: GossipSub,
# delete from mesh only if no handlers are left # delete from mesh only if no handlers are left
# (handlers are removed in pubsub unsubscribe above) # (handlers are removed in pubsub unsubscribe above)
if topic notin g.topics: if topic notin g.topics:
g.unsubscribeAll(topic) g.unsubscribe(topic)
method publish*(g: GossipSub, method publish*(g: GossipSub,
topic: string, topic: string,