merge 1.0
This commit is contained in:
parent
2f39cf6f42
commit
69a92aebe6
|
@ -242,6 +242,7 @@ proc getGossipPeers(g: GossipSub): Table[string, ControlMessage] {.gcsafe.} =
|
|||
|
||||
proc heartbeat(g: GossipSub) {.async.} =
|
||||
while g.heartbeatRunning:
|
||||
withLock g.heartbeatLock:
|
||||
try:
|
||||
trace "running heartbeat"
|
||||
|
||||
|
@ -275,6 +276,7 @@ method handleDisconnect*(g: GossipSub, peer: PubSubPeer) {.async.} =
|
|||
|
||||
await procCall FloodSub(g).handleDisconnect(peer)
|
||||
|
||||
withLock g.heartbeatLock:
|
||||
for t in toSeq(g.gossipsub.keys):
|
||||
if t in g.gossipsub:
|
||||
g.gossipsub[t].excl(peer.id)
|
||||
|
@ -310,6 +312,7 @@ method subscribeTopic*(g: GossipSub,
|
|||
peerId: string) {.gcsafe, async.} =
|
||||
await procCall PubSub(g).subscribeTopic(topic, subscribe, peerId)
|
||||
|
||||
withLock g.heartbeatLock:
|
||||
if topic notin g.gossipsub:
|
||||
g.gossipsub[topic] = initHashSet[string]()
|
||||
|
||||
|
@ -555,14 +558,11 @@ method publish*(g: GossipSub,
|
|||
trace "publish: sending message to peer", peer = p
|
||||
sent.add(peer.send(@[RPCMsg(messages: @[msg])]))
|
||||
else:
|
||||
# Notice this needs a better fix! for now it's a hack
|
||||
error "publish: peer or peerInfo was nil", missing = p
|
||||
if topic in g.mesh:
|
||||
g.mesh[topic].excl(p)
|
||||
if topic in g.fanout:
|
||||
g.fanout[topic].excl(p)
|
||||
if topic in g.gossipsub:
|
||||
g.gossipsub[topic].excl(p)
|
||||
# this absolutely should not happen
|
||||
# if it happens there is a bug that needs fixing asap
|
||||
# this ain't no place to manage connections
|
||||
fatal "publish: peer or peerInfo was nil", missing = p
|
||||
doAssert(false, "publish: peer or peerInfo was nil")
|
||||
|
||||
sent = await allFinished(sent)
|
||||
checkFutures(sent)
|
||||
|
@ -580,31 +580,24 @@ method start*(g: GossipSub) {.async.} =
|
|||
## start pubsub
|
||||
## start long running/repeating procedures
|
||||
|
||||
# interlock start to to avoid overlapping to stops
|
||||
await g.heartbeatLock.acquire()
|
||||
|
||||
withLock g.heartbeatLock:
|
||||
# setup the heartbeat interval
|
||||
g.heartbeatRunning = true
|
||||
g.heartbeatFut = g.heartbeat()
|
||||
|
||||
g.heartbeatLock.release()
|
||||
|
||||
method stop*(g: GossipSub) {.async.} =
|
||||
trace "gossipsub stop"
|
||||
|
||||
## stop pubsub
|
||||
## stop long running tasks
|
||||
|
||||
await g.heartbeatLock.acquire()
|
||||
|
||||
withLock g.heartbeatLock:
|
||||
# stop heartbeat interval
|
||||
g.heartbeatRunning = false
|
||||
if not g.heartbeatFut.finished:
|
||||
trace "awaiting last heartbeat"
|
||||
await g.heartbeatFut
|
||||
|
||||
g.heartbeatLock.release()
|
||||
|
||||
method initPubSub*(g: GossipSub) =
|
||||
procCall FloodSub(g).initPubSub()
|
||||
|
||||
|
|
Loading…
Reference in New Issue