Update to latest ngtcp2
This commit is contained in:
parent
384460024f
commit
871a3f4b91
|
@ -7,5 +7,5 @@ license = "MIT"
|
|||
requires "nim >= 1.2.6"
|
||||
requires "stew >= 0.1.0 & < 0.2.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"
|
||||
|
|
|
@ -13,7 +13,7 @@ import connection
|
|||
import path
|
||||
import streams
|
||||
|
||||
let zeroKey = Key()
|
||||
var zeroKey = dummyKey()
|
||||
|
||||
proc clientInitial(connection: ptr ngtcp2_conn, user_data: pointer): cint {.cdecl.} =
|
||||
connection.install0RttKey(zeroKey)
|
||||
|
@ -56,7 +56,7 @@ proc newClientConnection*(local, remote: TransportAddress): Connection =
|
|||
unsafeAddr destination,
|
||||
unsafeAddr source,
|
||||
path.toPathPtr,
|
||||
cast[uint32](NGTCP2_PROTO_VER),
|
||||
cast[uint32](NGTCP2_PROTO_VER_MAX),
|
||||
addr callbacks,
|
||||
unsafeAddr settings,
|
||||
nil,
|
||||
|
|
|
@ -2,11 +2,15 @@ import ngtcp2
|
|||
|
||||
type
|
||||
Key* = object
|
||||
cryptoContext*: ngtcp2_crypto_ctx
|
||||
aeadContext*: ngtcp2_crypto_aead_ctx
|
||||
hpContext*: ngtcp2_crypto_cipher_ctx
|
||||
iv*: array[16, uint8]
|
||||
secret*: array[16, uint8]
|
||||
|
||||
proc dummyKey*: Key =
|
||||
result.cryptoContext.max_encryption = 1000
|
||||
|
||||
proc install0RttKey*(connection: ptr ngtcp2_conn, key: Key) =
|
||||
var key = key
|
||||
doAssert 0 == connection.ngtcp2_conn_install_initial_key(
|
||||
|
@ -18,6 +22,7 @@ proc install0RttKey*(connection: ptr ngtcp2_conn, key: Key) =
|
|||
addr key.hpContext,
|
||||
key.iv.len.uint
|
||||
)
|
||||
connection.ngtcp2_conn_set_initial_crypto_ctx(addr key.cryptoContext)
|
||||
|
||||
proc installHandshakeKeys*(connection: ptr ngtcp2_conn, rx, tx: Key) =
|
||||
var rx = rx
|
||||
|
@ -36,6 +41,7 @@ proc installHandshakeKeys*(connection: ptr ngtcp2_conn, rx, tx: Key) =
|
|||
tx.iv.len.uint,
|
||||
addr tx.hpContext
|
||||
)
|
||||
connection.ngtcp2_conn_set_crypto_ctx(addr rx.cryptoContext)
|
||||
|
||||
proc install1RttKeys*(connection: ptr ngtcp2_conn, rx, tx: Key) =
|
||||
var rx = rx
|
||||
|
@ -58,3 +64,4 @@ proc install1RttKeys*(connection: ptr ngtcp2_conn, rx, tx: Key) =
|
|||
tx.iv.len.uint,
|
||||
addr tx.hpContext
|
||||
)
|
||||
connection.ngtcp2_conn_set_crypto_ctx(addr rx.cryptoContext)
|
||||
|
|
|
@ -14,7 +14,7 @@ import path
|
|||
import errors
|
||||
import streams
|
||||
|
||||
let zeroKey = Key()
|
||||
let zeroKey = dummyKey()
|
||||
|
||||
proc receiveClientInitial(connection: ptr ngtcp2_conn, dcid: ptr ngtcp2_cid, userData: pointer): cint {.cdecl.} =
|
||||
connection.install0RttKey(zeroKey)
|
||||
|
@ -57,7 +57,7 @@ proc newServerConnection(local, remote: TransportAddress, source, destination: n
|
|||
unsafeAddr source,
|
||||
unsafeAddr id,
|
||||
path.toPathPtr,
|
||||
cast[uint32](NGTCP2_PROTO_VER),
|
||||
cast[uint32](NGTCP2_PROTO_VER_MAX),
|
||||
addr callbacks,
|
||||
addr settings,
|
||||
nil,
|
||||
|
|
|
@ -23,6 +23,7 @@ proc trySend(connection: Connection): Datagram =
|
|||
0,
|
||||
getMonoTime().ticks.uint
|
||||
)
|
||||
checkResult length.cint
|
||||
let data = connection.buffer[0..<length]
|
||||
let ecn = ECN(packetInfo.ecn)
|
||||
Datagram(data: data, ecn: ecn)
|
||||
|
|
Loading…
Reference in New Issue