mirror of
https://github.com/vacp2p/nim-libp2p.git
synced 2025-01-14 10:44:45 +00:00
add base upgrade method
This commit is contained in:
parent
71282fa442
commit
3d74a4c82a
@ -17,8 +17,8 @@ type TcpTransport* = ref object of Transport
|
|||||||
|
|
||||||
proc connHandler*(t: Transport,
|
proc connHandler*(t: Transport,
|
||||||
server: StreamServer,
|
server: StreamServer,
|
||||||
client: StreamTransport): Future[Connection]
|
client: StreamTransport):
|
||||||
{.async, gcsafe.} =
|
Future[Connection] {.async, gcsafe.} =
|
||||||
let conn: Connection = newConnection(newChronosStream(server, client))
|
let conn: Connection = newConnection(newChronosStream(server, client))
|
||||||
let handlerFut = if t.handler == nil: nil else: t.handler(conn)
|
let handlerFut = if t.handler == nil: nil else: t.handler(conn)
|
||||||
let connHolder: ConnHolder = ConnHolder(connection: conn,
|
let connHolder: ConnHolder = ConnHolder(connection: conn,
|
||||||
@ -43,7 +43,8 @@ method close*(t: TcpTransport): Future[void] {.async, gcsafe.} =
|
|||||||
|
|
||||||
method listen*(t: TcpTransport,
|
method listen*(t: TcpTransport,
|
||||||
ma: MultiAddress,
|
ma: MultiAddress,
|
||||||
handler: ConnHandler): Future[void] {.async, gcsafe.} =
|
handler: ConnHandler):
|
||||||
|
Future[void] {.async, gcsafe.} =
|
||||||
await procCall Transport(t).listen(ma, handler) # call base
|
await procCall Transport(t).listen(ma, handler) # call base
|
||||||
|
|
||||||
## listen on the transport
|
## listen on the transport
|
||||||
@ -56,7 +57,8 @@ method listen*(t: TcpTransport,
|
|||||||
listenFuture.complete()
|
listenFuture.complete()
|
||||||
|
|
||||||
method dial*(t: TcpTransport,
|
method dial*(t: TcpTransport,
|
||||||
address: MultiAddress): Future[Connection] {.async, gcsafe.} =
|
address: MultiAddress):
|
||||||
|
Future[Connection] {.async, gcsafe.} =
|
||||||
## dial a peer
|
## dial a peer
|
||||||
let client: StreamTransport = await connect(address)
|
let client: StreamTransport = await connect(address)
|
||||||
result = await t.connHandler(t.server, client)
|
result = await t.connHandler(t.server, client)
|
||||||
|
@ -50,6 +50,11 @@ method dial*(t: Transport,
|
|||||||
## dial a peer
|
## dial a peer
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
method upgrade*(t: Transport) {.base, async, gcsafe.} =
|
||||||
|
## base upgrade method that the transport uses to perform
|
||||||
|
## transport specific upgrades
|
||||||
|
discard
|
||||||
|
|
||||||
method handles*(t: Transport, address: MultiAddress): bool {.base, gcsafe.} =
|
method handles*(t: Transport, address: MultiAddress): bool {.base, gcsafe.} =
|
||||||
## check if transport supportes the multiaddress
|
## check if transport supportes the multiaddress
|
||||||
# TODO: this should implement generic logic that would use the multicodec
|
# TODO: this should implement generic logic that would use the multicodec
|
||||||
|
Loading…
x
Reference in New Issue
Block a user