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",
|
||||
"metrics",
|
||||
"secp256k1",
|
||||
"stew"
|
||||
"stew >= 0.1.0"
|
||||
|
||||
proc runTest(filename: string, verify: bool = true, sign: bool = true) =
|
||||
var excstr: string = "nim c -r --opt:speed -d:debug --verbosity:0 --hints:off"
|
||||
|
|
|
@ -48,6 +48,7 @@ proc isConnected*(p: PubSubPeer): bool =
|
|||
|
||||
proc `conn=`*(p: PubSubPeer, conn: Connection) =
|
||||
trace "attaching send connection for peer", peer = p.id
|
||||
if not(isNil(conn)):
|
||||
p.sendConn = conn
|
||||
p.onConnect.fire()
|
||||
|
||||
|
@ -113,6 +114,7 @@ proc send*(p: PubSubPeer, msgs: seq[RPCMsg]) {.async.} =
|
|||
trace "about to send message", peer = p.id,
|
||||
encoded = digest
|
||||
await p.onConnect.wait()
|
||||
if p.isConnected: # this can happen if the remote disconnected
|
||||
trace "sending encoded msgs to peer", peer = p.id,
|
||||
encoded = encoded.buffer.shortLog
|
||||
await p.sendConn.writeLp(encoded.buffer)
|
||||
|
|
|
@ -282,8 +282,7 @@ proc dial*(s: Switch,
|
|||
trace "Attempting to select remote", proto = proto
|
||||
|
||||
if not await s.ms.select(result, proto):
|
||||
warn "Unable to select sub-protocol", proto = proto
|
||||
return nil
|
||||
raise newException(CatchableError, "Unable to select sub-protocol " & proto)
|
||||
|
||||
proc mount*[T: LPProtocol](s: Switch, proto: T) {.gcsafe.} =
|
||||
if isNil(proto.handler):
|
||||
|
|
Loading…
Reference in New Issue