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,8 +48,9 @@ proc isConnected*(p: PubSubPeer): bool =
|
|||
|
||||
proc `conn=`*(p: PubSubPeer, conn: Connection) =
|
||||
trace "attaching send connection for peer", peer = p.id
|
||||
p.sendConn = conn
|
||||
p.onConnect.fire()
|
||||
if not(isNil(conn)):
|
||||
p.sendConn = conn
|
||||
p.onConnect.fire()
|
||||
|
||||
proc recvObservers(p: PubSubPeer, msg: var RPCMsg) =
|
||||
# trigger hooks
|
||||
|
@ -113,10 +114,11 @@ proc send*(p: PubSubPeer, msgs: seq[RPCMsg]) {.async.} =
|
|||
trace "about to send message", peer = p.id,
|
||||
encoded = digest
|
||||
await p.onConnect.wait()
|
||||
trace "sending encoded msgs to peer", peer = p.id,
|
||||
encoded = encoded.buffer.shortLog
|
||||
await p.sendConn.writeLp(encoded.buffer)
|
||||
p.sentRpcCache.put(digest)
|
||||
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)
|
||||
p.sentRpcCache.put(digest)
|
||||
except CatchableError as exc:
|
||||
trace "unable to send to remote", exc = exc.msg
|
||||
p.sendConn = nil
|
||||
|
|
|
@ -45,7 +45,7 @@ proc newStandardSwitch*(privKey = none(PrivateKey),
|
|||
muxers = {MplexCodec: mplexProvider}.toTable
|
||||
identify = newIdentify(peerInfo)
|
||||
|
||||
var
|
||||
var
|
||||
secureManagerInstances: seq[Secure]
|
||||
for sec in secureManagers:
|
||||
case sec
|
||||
|
|
|
@ -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