mirror of https://github.com/vacp2p/nim-libp2p.git
getMuxedStream to more appropriate getStream (#448)
This commit is contained in:
parent
69ae24dc8d
commit
351489bfa9
|
@ -367,7 +367,7 @@ proc storeMuxer*(c: ConnManager,
|
||||||
|
|
||||||
asyncSpawn c.peerStartup(muxer.connection)
|
asyncSpawn c.peerStartup(muxer.connection)
|
||||||
|
|
||||||
proc getMuxedStream*(c: ConnManager,
|
proc getStream*(c: ConnManager,
|
||||||
peerId: PeerID,
|
peerId: PeerID,
|
||||||
dir: Direction): Future[Connection] {.async, gcsafe.} =
|
dir: Direction): Future[Connection] {.async, gcsafe.} =
|
||||||
## get a muxed stream for the provided peer
|
## get a muxed stream for the provided peer
|
||||||
|
@ -378,7 +378,7 @@ proc getMuxedStream*(c: ConnManager,
|
||||||
if not(isNil(muxer)):
|
if not(isNil(muxer)):
|
||||||
return await muxer.newStream()
|
return await muxer.newStream()
|
||||||
|
|
||||||
proc getMuxedStream*(c: ConnManager,
|
proc getStream*(c: ConnManager,
|
||||||
peerId: PeerID): Future[Connection] {.async, gcsafe.} =
|
peerId: PeerID): Future[Connection] {.async, gcsafe.} =
|
||||||
## get a muxed stream for the passed peer from any connection
|
## get a muxed stream for the passed peer from any connection
|
||||||
##
|
##
|
||||||
|
@ -387,7 +387,7 @@ proc getMuxedStream*(c: ConnManager,
|
||||||
if not(isNil(muxer)):
|
if not(isNil(muxer)):
|
||||||
return await muxer.newStream()
|
return await muxer.newStream()
|
||||||
|
|
||||||
proc getMuxedStream*(c: ConnManager,
|
proc getStream*(c: ConnManager,
|
||||||
conn: Connection): Future[Connection] {.async, gcsafe.} =
|
conn: Connection): Future[Connection] {.async, gcsafe.} =
|
||||||
## get a muxed stream for the passed connection
|
## get a muxed stream for the passed connection
|
||||||
##
|
##
|
||||||
|
|
|
@ -352,7 +352,7 @@ proc dial*(s: Switch,
|
||||||
peerId: PeerID,
|
peerId: PeerID,
|
||||||
protos: seq[string]): Future[Connection] {.async.} =
|
protos: seq[string]): Future[Connection] {.async.} =
|
||||||
trace "Dialing (existing)", peerId, protos
|
trace "Dialing (existing)", peerId, protos
|
||||||
let stream = await s.connManager.getMuxedStream(peerId)
|
let stream = await s.connManager.getStream(peerId)
|
||||||
if stream.isNil:
|
if stream.isNil:
|
||||||
raise newException(DialFailedError, "Couldn't get muxed stream")
|
raise newException(DialFailedError, "Couldn't get muxed stream")
|
||||||
|
|
||||||
|
@ -370,7 +370,7 @@ proc dial*(s: Switch,
|
||||||
trace "Dialing (new)", peerId, protos
|
trace "Dialing (new)", peerId, protos
|
||||||
let conn = await s.internalConnect(peerId, addrs)
|
let conn = await s.internalConnect(peerId, addrs)
|
||||||
trace "Opening stream", conn
|
trace "Opening stream", conn
|
||||||
let stream = await s.connManager.getMuxedStream(conn)
|
let stream = await s.connManager.getStream(conn)
|
||||||
|
|
||||||
proc cleanup() {.async.} =
|
proc cleanup() {.async.} =
|
||||||
if not(isNil(stream)):
|
if not(isNil(stream)):
|
||||||
|
|
|
@ -87,7 +87,7 @@ suite "Connection Manager":
|
||||||
connMngr.storeMuxer(muxer)
|
connMngr.storeMuxer(muxer)
|
||||||
check muxer in connMngr
|
check muxer in connMngr
|
||||||
|
|
||||||
let stream = await connMngr.getMuxedStream(peer.peerId)
|
let stream = await connMngr.getStream(peer.peerId)
|
||||||
check not(isNil(stream))
|
check not(isNil(stream))
|
||||||
check stream.peerInfo == peer
|
check stream.peerInfo == peer
|
||||||
|
|
||||||
|
@ -107,9 +107,9 @@ suite "Connection Manager":
|
||||||
connMngr.storeMuxer(muxer)
|
connMngr.storeMuxer(muxer)
|
||||||
check muxer in connMngr
|
check muxer in connMngr
|
||||||
|
|
||||||
let stream1 = await connMngr.getMuxedStream(peer.peerId, Direction.In)
|
let stream1 = await connMngr.getStream(peer.peerId, Direction.In)
|
||||||
check not(isNil(stream1))
|
check not(isNil(stream1))
|
||||||
let stream2 = await connMngr.getMuxedStream(peer.peerId, Direction.Out)
|
let stream2 = await connMngr.getStream(peer.peerId, Direction.Out)
|
||||||
check isNil(stream2)
|
check isNil(stream2)
|
||||||
|
|
||||||
await connMngr.close()
|
await connMngr.close()
|
||||||
|
@ -128,7 +128,7 @@ suite "Connection Manager":
|
||||||
connMngr.storeMuxer(muxer)
|
connMngr.storeMuxer(muxer)
|
||||||
check muxer in connMngr
|
check muxer in connMngr
|
||||||
|
|
||||||
let stream = await connMngr.getMuxedStream(conn)
|
let stream = await connMngr.getStream(conn)
|
||||||
check not(isNil(stream))
|
check not(isNil(stream))
|
||||||
|
|
||||||
await connMngr.close()
|
await connMngr.close()
|
||||||
|
|
Loading…
Reference in New Issue