fix breaking test

This commit is contained in:
Dmitriy Ryajov 2019-09-13 14:04:46 -06:00
parent 393d82d4b1
commit 27e4516796
2 changed files with 9 additions and 2 deletions

View File

@ -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:

View File

@ -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)