Remove ngtcp_pkt_info from public API

Replaced by type ExplicitCongestionNotification (ECN).
This commit is contained in:
Mark Spanbroek 2020-10-07 15:03:14 +02:00 committed by markspanbroek
parent ee2e02f7be
commit 5209a18476
4 changed files with 25 additions and 12 deletions

View File

@ -1,6 +1,8 @@
import quic/version
import quic/packets
import quic/connection
import quic/congestion
export version
export packets
export connection
export congestion

7
quic/congestion.nim Normal file
View File

@ -0,0 +1,7 @@
type
ExplicitCongestionNotification {.size: 1.} = enum
ecnNonCapable = 0b00
ecnCapable1 = 0b01
ecnCapable0 = 0b10
ecnCongestion = 0b11
ECN* = ExplicitCongestionNotification

View File

@ -1,16 +1,18 @@
import std/monotimes
import ../packets
import ../congestion
import ngtcp2
import connection
proc write*(connection: Connection, datagram: var Datagram, datagramInfo: var ngtcp2_pkt_info): int =
proc write*(connection: Connection, datagram: var Datagram, ecn: var ECN): int =
var offset = 0
var length = 1
while length > 0 and offset < datagram.len:
var packetInfo: ngtcp2_pkt_info
length = ngtcp2_conn_write_stream(
connection.conn,
nil,
addr datagramInfo,
addr packetInfo,
addr datagram[offset],
(datagram.len - offset).uint,
nil,
@ -20,14 +22,17 @@ proc write*(connection: Connection, datagram: var Datagram, datagramInfo: var ng
0,
getMonoTime().ticks.uint
)
ecn = ECN(packetInfo.ecn)
offset = offset + length
offset
proc read*(connection: Connection, datagram: Datagram, datagramInfo: ngtcp2_pkt_info) =
proc read*(connection: Connection, datagram: Datagram, ecn: ECN) =
var packetInfo: ngtcp2_pkt_info
packetInfo.ecn = ecn.uint32
assert 0 == ngtcp2_conn_read_pkt(
connection.conn,
unsafeAddr connection.path,
unsafeAddr datagramInfo,
unsafeAddr packetInfo,
unsafeAddr datagram[0],
datagram.len.uint,
getMonoTime().ticks.uint

View File

@ -1,26 +1,25 @@
import unittest
import quic
import ngtcp2
import helpers/path
suite "connection":
test "performs handshake":
var datagram: array[16348, uint8]
var datagramInfo: ngtcp2_pkt_info
var datagramLength = 0
var ecn: ECN
let client = newClientConnection(zeroPath)
datagramLength = client.write(datagram, datagramInfo)
datagramLength = client.write(datagram, ecn)
let server = newServerConnection(zeroPath, datagram)
server.read(datagram[0..<datagramLength], datagramInfo)
server.read(datagram[0..<datagramLength], ecn)
datagramLength = server.write(datagram, datagramInfo)
client.read(datagram[0..<datagramLength], datagramInfo)
datagramLength = server.write(datagram, ecn)
client.read(datagram[0..<datagramLength], ecn)
datagramLength = client.write(datagram, datagramInfo)
server.read(datagram[0..<datagramLength], datagramInfo)
datagramLength = client.write(datagram, ecn)
server.read(datagram[0..<datagramLength], ecn)
check client.isHandshakeCompleted
check server.isHandshakeCompleted