don't use `switch.dial` in `subscribeToPeer` (#227)
* count published messages * don't call `switch.dial` in `subscribeToPeer`
This commit is contained in:
parent
fe828d87d8
commit
5f75e5adc6
|
@ -375,17 +375,24 @@ proc stop*(s: Switch) {.async.} =
|
|||
warn "error stopping switch", exc = exc.msg
|
||||
|
||||
proc subscribeToPeer*(s: Switch, peerInfo: PeerInfo) {.async, gcsafe.} =
|
||||
trace "about to subscribe to pubsub peer", peer = peerInfo.shortLog()
|
||||
## Subscribe to pub sub peer
|
||||
if s.pubSub.isSome and peerInfo.id notin s.dialedPubSubPeers:
|
||||
if s.pubSub.isSome and (peerInfo.id notin s.dialedPubSubPeers):
|
||||
let conn = await s.getMuxedStream(peerInfo)
|
||||
try:
|
||||
s.dialedPubSubPeers.incl(peerInfo.id)
|
||||
let conn = await s.dial(peerInfo, s.pubSub.get().codec)
|
||||
if isNil(conn):
|
||||
trace "unable to subscribe to peer"
|
||||
trace "unable to subscribe to peer", peer = peerInfo.shortLog
|
||||
return
|
||||
|
||||
s.dialedPubSubPeers.incl(peerInfo.id)
|
||||
if (await s.ms.select(conn, s.pubSub.get().codec)):
|
||||
await s.pubSub.get().subscribeToPeer(conn)
|
||||
else:
|
||||
await conn.close()
|
||||
|
||||
except CatchableError as exc:
|
||||
trace "exception in subscribe to peer", exc = exc.msg
|
||||
trace "exception in subscribe to peer", peer = peerInfo.shortLog, exc = exc.msg
|
||||
await conn.close()
|
||||
finally:
|
||||
s.dialedPubSubPeers.excl(peerInfo.id)
|
||||
|
||||
|
|
Loading…
Reference in New Issue