Update to latest ngtcp2

This commit is contained in:
Mark Spanbroek 2020-11-09 14:29:14 +01:00 committed by markspanbroek
parent 384460024f
commit 871a3f4b91
5 changed files with 13 additions and 5 deletions

View File

@ -7,5 +7,5 @@ license = "MIT"
requires "nim >= 1.2.6" requires "nim >= 1.2.6"
requires "stew >= 0.1.0 & < 0.2.0" requires "stew >= 0.1.0 & < 0.2.0"
requires "chronos >= 2.5.2 & < 3.0.0" requires "chronos >= 2.5.2 & < 3.0.0"
requires "https://github.com/status-im/nim-ngtcp2.git >= 0.1.0 & < 0.2.0" requires "https://github.com/status-im/nim-ngtcp2.git >= 0.32.0 & < 0.33.0"
requires "sysrandom >= 1.1.0 & < 2.0.0" requires "sysrandom >= 1.1.0 & < 2.0.0"

View File

@ -13,7 +13,7 @@ import connection
import path import path
import streams import streams
let zeroKey = Key() var zeroKey = dummyKey()
proc clientInitial(connection: ptr ngtcp2_conn, user_data: pointer): cint {.cdecl.} = proc clientInitial(connection: ptr ngtcp2_conn, user_data: pointer): cint {.cdecl.} =
connection.install0RttKey(zeroKey) connection.install0RttKey(zeroKey)
@ -56,7 +56,7 @@ proc newClientConnection*(local, remote: TransportAddress): Connection =
unsafeAddr destination, unsafeAddr destination,
unsafeAddr source, unsafeAddr source,
path.toPathPtr, path.toPathPtr,
cast[uint32](NGTCP2_PROTO_VER), cast[uint32](NGTCP2_PROTO_VER_MAX),
addr callbacks, addr callbacks,
unsafeAddr settings, unsafeAddr settings,
nil, nil,

View File

@ -2,11 +2,15 @@ import ngtcp2
type type
Key* = object Key* = object
cryptoContext*: ngtcp2_crypto_ctx
aeadContext*: ngtcp2_crypto_aead_ctx aeadContext*: ngtcp2_crypto_aead_ctx
hpContext*: ngtcp2_crypto_cipher_ctx hpContext*: ngtcp2_crypto_cipher_ctx
iv*: array[16, uint8] iv*: array[16, uint8]
secret*: array[16, uint8] secret*: array[16, uint8]
proc dummyKey*: Key =
result.cryptoContext.max_encryption = 1000
proc install0RttKey*(connection: ptr ngtcp2_conn, key: Key) = proc install0RttKey*(connection: ptr ngtcp2_conn, key: Key) =
var key = key var key = key
doAssert 0 == connection.ngtcp2_conn_install_initial_key( doAssert 0 == connection.ngtcp2_conn_install_initial_key(
@ -18,6 +22,7 @@ proc install0RttKey*(connection: ptr ngtcp2_conn, key: Key) =
addr key.hpContext, addr key.hpContext,
key.iv.len.uint key.iv.len.uint
) )
connection.ngtcp2_conn_set_initial_crypto_ctx(addr key.cryptoContext)
proc installHandshakeKeys*(connection: ptr ngtcp2_conn, rx, tx: Key) = proc installHandshakeKeys*(connection: ptr ngtcp2_conn, rx, tx: Key) =
var rx = rx var rx = rx
@ -36,6 +41,7 @@ proc installHandshakeKeys*(connection: ptr ngtcp2_conn, rx, tx: Key) =
tx.iv.len.uint, tx.iv.len.uint,
addr tx.hpContext addr tx.hpContext
) )
connection.ngtcp2_conn_set_crypto_ctx(addr rx.cryptoContext)
proc install1RttKeys*(connection: ptr ngtcp2_conn, rx, tx: Key) = proc install1RttKeys*(connection: ptr ngtcp2_conn, rx, tx: Key) =
var rx = rx var rx = rx
@ -58,3 +64,4 @@ proc install1RttKeys*(connection: ptr ngtcp2_conn, rx, tx: Key) =
tx.iv.len.uint, tx.iv.len.uint,
addr tx.hpContext addr tx.hpContext
) )
connection.ngtcp2_conn_set_crypto_ctx(addr rx.cryptoContext)

View File

@ -14,7 +14,7 @@ import path
import errors import errors
import streams import streams
let zeroKey = Key() let zeroKey = dummyKey()
proc receiveClientInitial(connection: ptr ngtcp2_conn, dcid: ptr ngtcp2_cid, userData: pointer): cint {.cdecl.} = proc receiveClientInitial(connection: ptr ngtcp2_conn, dcid: ptr ngtcp2_cid, userData: pointer): cint {.cdecl.} =
connection.install0RttKey(zeroKey) connection.install0RttKey(zeroKey)
@ -57,7 +57,7 @@ proc newServerConnection(local, remote: TransportAddress, source, destination: n
unsafeAddr source, unsafeAddr source,
unsafeAddr id, unsafeAddr id,
path.toPathPtr, path.toPathPtr,
cast[uint32](NGTCP2_PROTO_VER), cast[uint32](NGTCP2_PROTO_VER_MAX),
addr callbacks, addr callbacks,
addr settings, addr settings,
nil, nil,

View File

@ -23,6 +23,7 @@ proc trySend(connection: Connection): Datagram =
0, 0,
getMonoTime().ticks.uint getMonoTime().ticks.uint
) )
checkResult length.cint
let data = connection.buffer[0..<length] let data = connection.buffer[0..<length]
let ecn = ECN(packetInfo.ecn) let ecn = ECN(packetInfo.ecn)
Datagram(data: data, ecn: ecn) Datagram(data: data, ecn: ecn)