diff --git a/libp2p.nimble b/libp2p.nimble index e6a685d..73ebfa3 100644 --- a/libp2p.nimble +++ b/libp2p.nimble @@ -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" diff --git a/libp2p/protocols/pubsub/pubsubpeer.nim b/libp2p/protocols/pubsub/pubsubpeer.nim index 73324e1..95688e0 100644 --- a/libp2p/protocols/pubsub/pubsubpeer.nim +++ b/libp2p/protocols/pubsub/pubsubpeer.nim @@ -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 diff --git a/libp2p/standard_setup.nim b/libp2p/standard_setup.nim index 240bf33..9d16780 100644 --- a/libp2p/standard_setup.nim +++ b/libp2p/standard_setup.nim @@ -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 diff --git a/libp2p/switch.nim b/libp2p/switch.nim index 5d0281b..7f317a4 100644 --- a/libp2p/switch.nim +++ b/libp2p/switch.nim @@ -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):