diff --git a/libp2p/switch.nim b/libp2p/switch.nim index 7dcfb945e..d43ee8e90 100644 --- a/libp2p/switch.nim +++ b/libp2p/switch.nim @@ -93,6 +93,9 @@ proc mux(s: Switch, conn: Connection): Future[void] {.async, gcsafe.} = debug "muxing connection" ## mux incoming connection let muxers = toSeq(s.muxers.keys) + if muxers.len == 0: + return + let muxerName = await s.ms.select(conn, muxers) if muxerName.len == 0 or muxerName == "na": return @@ -252,7 +255,7 @@ proc newSwitch*(peerInfo: PeerInfo, transports: seq[Transport], identity: Identify, muxers: Table[string, MuxerProvider], - secureManagers: Table[string, Secure], + secureManagers: Table[string, Secure] = initTable[string, Secure](), pubSub: Option[PubSub] = none(PubSub)): Switch = new result result.peerInfo = peerInfo @@ -283,6 +286,7 @@ proc newSwitch*(peerInfo: PeerInfo, if result.secureManagers.len == 0: # use plain text if no secure managers are provided + debug "no secure managers, falling back to palin text", codec = PlainTextCodec result.secureManagers[PlainTextCodec] = Secure(newPlainText()) if pubSub.isSome: diff --git a/tests/testswitch.nim b/tests/testswitch.nim index 116c69a36..f94f40e34 100644 --- a/tests/testswitch.nim +++ b/tests/testswitch.nim @@ -12,7 +12,9 @@ import ../libp2p/switch, ../libp2p/protocols/protocol, ../libp2p/muxers/muxer, ../libp2p/muxers/mplex/mplex, - ../libp2p/muxers/mplex/types + ../libp2p/muxers/mplex/types, + ../libp2p/protocols/secure/secio, + ../libp2p/protocols/secure/secure const TestCodec = "/test/proto/1.0.0" @@ -44,6 +46,7 @@ suite "Switch": let mplexProvider = newMuxerProvider(createMplex, MplexCodec) let transports = @[Transport(newTransport(TcpTransport))] let muxers = [(MplexCodec, mplexProvider)].toTable() + # let secureManagers = [(SecioCodec, Secure(newSecio(seckey)))].toTable() let switch = newSwitch(peerInfo, transports, identify, muxers) result = (switch, peerInfo)