don't return nil in dial (#205)
* dont return nil in dial * don't crash on pubsub send
This commit is contained in:
parent
2aebae56c0
commit
130c64f33a
|
@ -14,7 +14,7 @@ requires "nim >= 1.2.0",
|
||||||
"chronos >= 2.3.8",
|
"chronos >= 2.3.8",
|
||||||
"metrics",
|
"metrics",
|
||||||
"secp256k1",
|
"secp256k1",
|
||||||
"stew"
|
"stew >= 0.1.0"
|
||||||
|
|
||||||
proc runTest(filename: string, verify: bool = true, sign: bool = true) =
|
proc runTest(filename: string, verify: bool = true, sign: bool = true) =
|
||||||
var excstr: string = "nim c -r --opt:speed -d:debug --verbosity:0 --hints:off"
|
var excstr: string = "nim c -r --opt:speed -d:debug --verbosity:0 --hints:off"
|
||||||
|
|
|
@ -48,8 +48,9 @@ proc isConnected*(p: PubSubPeer): bool =
|
||||||
|
|
||||||
proc `conn=`*(p: PubSubPeer, conn: Connection) =
|
proc `conn=`*(p: PubSubPeer, conn: Connection) =
|
||||||
trace "attaching send connection for peer", peer = p.id
|
trace "attaching send connection for peer", peer = p.id
|
||||||
p.sendConn = conn
|
if not(isNil(conn)):
|
||||||
p.onConnect.fire()
|
p.sendConn = conn
|
||||||
|
p.onConnect.fire()
|
||||||
|
|
||||||
proc recvObservers(p: PubSubPeer, msg: var RPCMsg) =
|
proc recvObservers(p: PubSubPeer, msg: var RPCMsg) =
|
||||||
# trigger hooks
|
# trigger hooks
|
||||||
|
@ -113,10 +114,11 @@ proc send*(p: PubSubPeer, msgs: seq[RPCMsg]) {.async.} =
|
||||||
trace "about to send message", peer = p.id,
|
trace "about to send message", peer = p.id,
|
||||||
encoded = digest
|
encoded = digest
|
||||||
await p.onConnect.wait()
|
await p.onConnect.wait()
|
||||||
trace "sending encoded msgs to peer", peer = p.id,
|
if p.isConnected: # this can happen if the remote disconnected
|
||||||
encoded = encoded.buffer.shortLog
|
trace "sending encoded msgs to peer", peer = p.id,
|
||||||
await p.sendConn.writeLp(encoded.buffer)
|
encoded = encoded.buffer.shortLog
|
||||||
p.sentRpcCache.put(digest)
|
await p.sendConn.writeLp(encoded.buffer)
|
||||||
|
p.sentRpcCache.put(digest)
|
||||||
except CatchableError as exc:
|
except CatchableError as exc:
|
||||||
trace "unable to send to remote", exc = exc.msg
|
trace "unable to send to remote", exc = exc.msg
|
||||||
p.sendConn = nil
|
p.sendConn = nil
|
||||||
|
|
|
@ -45,7 +45,7 @@ proc newStandardSwitch*(privKey = none(PrivateKey),
|
||||||
muxers = {MplexCodec: mplexProvider}.toTable
|
muxers = {MplexCodec: mplexProvider}.toTable
|
||||||
identify = newIdentify(peerInfo)
|
identify = newIdentify(peerInfo)
|
||||||
|
|
||||||
var
|
var
|
||||||
secureManagerInstances: seq[Secure]
|
secureManagerInstances: seq[Secure]
|
||||||
for sec in secureManagers:
|
for sec in secureManagers:
|
||||||
case sec
|
case sec
|
||||||
|
|
|
@ -282,8 +282,7 @@ proc dial*(s: Switch,
|
||||||
trace "Attempting to select remote", proto = proto
|
trace "Attempting to select remote", proto = proto
|
||||||
|
|
||||||
if not await s.ms.select(result, proto):
|
if not await s.ms.select(result, proto):
|
||||||
warn "Unable to select sub-protocol", proto = proto
|
raise newException(CatchableError, "Unable to select sub-protocol " & proto)
|
||||||
return nil
|
|
||||||
|
|
||||||
proc mount*[T: LPProtocol](s: Switch, proto: T) {.gcsafe.} =
|
proc mount*[T: LPProtocol](s: Switch, proto: T) {.gcsafe.} =
|
||||||
if isNil(proto.handler):
|
if isNil(proto.handler):
|
||||||
|
|
Loading…
Reference in New Issue