2020-09-10 15:36:53 +00:00
|
|
|
import ngtcp2
|
2020-09-16 12:19:58 +00:00
|
|
|
import sysrandom
|
2020-09-10 15:36:53 +00:00
|
|
|
|
2020-09-16 12:19:58 +00:00
|
|
|
proc connectionId*(bytes: ptr uint8, length: uint): ngtcp2_cid =
|
|
|
|
ngtcp2_cid_init(addr result, bytes, length)
|
|
|
|
|
|
|
|
proc randomConnectionId*(): ngtcp2_cid =
|
|
|
|
var bytes: array[18, uint8]
|
|
|
|
getRandomBytes(addr bytes[0], bytes.len)
|
2020-09-10 15:36:53 +00:00
|
|
|
ngtcp2_cid_init(addr result, addr bytes[0], bytes.len.uint)
|
|
|
|
|
2020-09-16 12:19:58 +00:00
|
|
|
var clientSourceId* = randomConnectionId()
|
|
|
|
var clientDestinationId* = randomConnectionId()
|
|
|
|
var serverSourceId* = randomConnectionId()
|
|
|
|
var serverDestinationId* = randomConnectionId()
|
2020-09-10 15:36:53 +00:00
|
|
|
|
|
|
|
var nextConnectionId = 1'u8
|
|
|
|
|
|
|
|
proc getNewConnectionId*(connection: ptr ngtcp2_conn, id: ptr ngtcp2_cid, token: ptr uint8, cidlen: uint, userData: pointer): cint {.cdecl.} =
|
|
|
|
zeroMem(addr id.data[0], cidlen)
|
|
|
|
id.data[0] = nextConnectionId
|
|
|
|
inc(nextConnectionId)
|
|
|
|
id.datalen = cidlen
|
|
|
|
zeroMem(token, NGTCP2_STATELESS_RESET_TOKENLEN)
|