move `secure` to base as well
This commit is contained in:
parent
d1c6591b8a
commit
19095a0f85
|
@ -418,14 +418,6 @@ method init(s: Secio) {.gcsafe.} =
|
||||||
procCall Secure(s).init()
|
procCall Secure(s).init()
|
||||||
s.codec = SecioCodec
|
s.codec = SecioCodec
|
||||||
|
|
||||||
method secure*(s: Secio, conn: Connection): Future[Connection] {.async, gcsafe.} =
|
|
||||||
try:
|
|
||||||
result = await s.handleConn(conn)
|
|
||||||
except CatchableError as exc:
|
|
||||||
warn "securing connection failed", msg = exc.msg
|
|
||||||
if not conn.closed():
|
|
||||||
await conn.close()
|
|
||||||
|
|
||||||
proc newSecio*(localPrivateKey: PrivateKey): Secio =
|
proc newSecio*(localPrivateKey: PrivateKey): Secio =
|
||||||
new result
|
new result
|
||||||
result.localPrivateKey = localPrivateKey
|
result.localPrivateKey = localPrivateKey
|
||||||
|
|
|
@ -22,7 +22,7 @@ type
|
||||||
|
|
||||||
method handshake(s: Secure,
|
method handshake(s: Secure,
|
||||||
conn: Connection,
|
conn: Connection,
|
||||||
initiator: bool = true): Future[SecureConn] {.async, base.} =
|
initiator: bool = false): Future[SecureConn] {.async, base.} =
|
||||||
doAssert(false, "Not implemented!")
|
doAssert(false, "Not implemented!")
|
||||||
|
|
||||||
proc readLoop(sconn: SecureConn, stream: BufferStream) {.async.} =
|
proc readLoop(sconn: SecureConn, stream: BufferStream) {.async.} =
|
||||||
|
@ -41,8 +41,8 @@ proc readLoop(sconn: SecureConn, stream: BufferStream) {.async.} =
|
||||||
await sconn.close()
|
await sconn.close()
|
||||||
trace "ending secio readLoop", isclosed = sconn.closed()
|
trace "ending secio readLoop", isclosed = sconn.closed()
|
||||||
|
|
||||||
proc handleConn*(s: Secure, conn: Connection): Future[Connection] {.async, gcsafe.} =
|
proc handleConn*(s: Secure, conn: Connection, initiator: bool = false): Future[Connection] {.async, gcsafe.} =
|
||||||
var sconn = await s.handshake(conn)
|
var sconn = await s.handshake(conn, initiator)
|
||||||
proc writeHandler(data: seq[byte]) {.async, gcsafe.} =
|
proc writeHandler(data: seq[byte]) {.async, gcsafe.} =
|
||||||
trace "sending encrypted bytes", bytes = data.toHex()
|
trace "sending encrypted bytes", bytes = data.toHex()
|
||||||
await sconn.writeMessage(data)
|
await sconn.writeMessage(data)
|
||||||
|
@ -71,9 +71,10 @@ method init*(s: Secure) {.gcsafe.} =
|
||||||
|
|
||||||
s.handler = handle
|
s.handler = handle
|
||||||
|
|
||||||
method secure*(p: Secure, conn: Connection): Future[Connection]
|
method secure*(s: Secure, conn: Connection): Future[Connection] {.async, base, gcsafe.} =
|
||||||
{.base, async, gcsafe.} =
|
try:
|
||||||
## default implementation matches plaintext
|
result = await s.handleConn(conn, true)
|
||||||
var retFuture = newFuture[Connection]("secure.secure")
|
except CatchableError as exc:
|
||||||
retFuture.complete(conn)
|
warn "securing connection failed", msg = exc.msg
|
||||||
return retFuture
|
if not conn.closed():
|
||||||
|
await conn.close()
|
||||||
|
|
Loading…
Reference in New Issue