add base upgrade method

This commit is contained in:
Dmitriy Ryajov 2019-08-30 16:16:37 -06:00
parent 71282fa442
commit 3d74a4c82a
2 changed files with 11 additions and 4 deletions

View File

@ -17,8 +17,8 @@ type TcpTransport* = ref object of Transport
proc connHandler*(t: Transport,
server: StreamServer,
client: StreamTransport): Future[Connection]
{.async, gcsafe.} =
client: StreamTransport):
Future[Connection] {.async, gcsafe.} =
let conn: Connection = newConnection(newChronosStream(server, client))
let handlerFut = if t.handler == nil: nil else: t.handler(conn)
let connHolder: ConnHolder = ConnHolder(connection: conn,
@ -43,7 +43,8 @@ method close*(t: TcpTransport): Future[void] {.async, gcsafe.} =
method listen*(t: TcpTransport,
ma: MultiAddress,
handler: ConnHandler): Future[void] {.async, gcsafe.} =
handler: ConnHandler):
Future[void] {.async, gcsafe.} =
await procCall Transport(t).listen(ma, handler) # call base
## listen on the transport
@ -56,7 +57,8 @@ method listen*(t: TcpTransport,
listenFuture.complete()
method dial*(t: TcpTransport,
address: MultiAddress): Future[Connection] {.async, gcsafe.} =
address: MultiAddress):
Future[Connection] {.async, gcsafe.} =
## dial a peer
let client: StreamTransport = await connect(address)
result = await t.connHandler(t.server, client)

View File

@ -50,6 +50,11 @@ method dial*(t: Transport,
## dial a peer
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.} =
## check if transport supportes the multiaddress
# TODO: this should implement generic logic that would use the multicodec