diff --git a/tests/quic/helpers/udp.nim b/tests/quic/helpers/udp.nim new file mode 100644 index 0000000..9ec0a7a --- /dev/null +++ b/tests/quic/helpers/udp.nim @@ -0,0 +1,32 @@ +import std/monotimes +import quic +import ngtcp2 +import path + +proc write*(connection: ptr ngtcp2_conn, datagram: var Datagram, datagramInfo: var ngtcp2_pkt_info): int = + var offset = 0 + var length = 1 + while length > 0 and offset < datagram.len: + length = connection.ngtcp2_conn_write_stream( + addr zeroPath, + addr datagramInfo, + addr datagram[offset], + (datagram.len - offset).uint, + nil, + NGTCP2_WRITE_STREAM_FLAG_MORE.uint32, + -1, + nil, + 0, + getMonoTime().ticks.uint + ) + offset = offset + length + offset + +proc read*(connection: ptr ngtcp2_conn, datagram: Datagram, datagramInfo: ngtcp2_pkt_info) = + assert 0 == connection.ngtcp2_conn_read_pkt( + addr zeroPath, + unsafeAddr datagramInfo, + unsafeAddr datagram[0], + datagram.len.uint, + getMonoTime().ticks.uint + ) diff --git a/tests/quic/testNgtcp2.nim b/tests/quic/testNgtcp2.nim index 4b3b146..fa85b20 100644 --- a/tests/quic/testNgtcp2.nim +++ b/tests/quic/testNgtcp2.nim @@ -1,10 +1,10 @@ import unittest -import std/monotimes import ngtcp2 import helpers/server import helpers/client import helpers/ids import helpers/path +import helpers/udp suite "ngtcp2": @@ -22,36 +22,31 @@ suite "ngtcp2": var datagram: array[16348, uint8] var datagramInfo: ngtcp2_pkt_info + var datagramLength = 0 # handshake client -> server echo "--- CLIENT 1>>> SERVER" - check datagram.len == client.ngtcp2_conn_write_stream(addr zeroPath, addr datagramInfo, addr datagram[0], datagram.len.uint, nil, NGTCP2_WRITE_STREAM_FLAG_MORE.uint32, -1, nil, 0, getMonoTime().ticks.uint) + datagramLength = client.write(datagram, datagramInfo) # setup server connection using received datagram let server = setupServer(zeroPath, serverId, datagram) defer: ngtcp2_conn_del(server) echo "--- CLIENT >>>1 SERVER" - check 0 == server.ngtcp2_conn_read_pkt(addr zeroPath, addr datagramInfo, addr datagram[0], datagram.len.uint, getMonoTime().ticks.uint) + server.read(datagram[0.. 0: - length = server.ngtcp2_conn_write_stream(addr zeroPath, addr datagramInfo, addr datagram[offset], (datagram.len - offset).uint, nil, NGTCP2_WRITE_STREAM_FLAG_MORE.uint32, -1, nil, 0, getMonoTime().ticks.uint) - offset = offset + length + datagramLength = server.write(datagram, datagramInfo) echo "--- CLIENT 2<<< SERVER" - check 0 == client.ngtcp2_conn_read_pkt(addr zeroPath, addr datagramInfo, addr datagram[0], offset.uint, getMonoTime().ticks.uint) + client.read(datagram[0..>> SERVER" - check datagram.len == client.ngtcp2_conn_write_pkt(addr zeroPath, addr datagramInfo, addr datagram[0], datagram.len.uint, getMonoTime().ticks.uint) + datagramLength = client.write(datagram, datagramInfo) check client.ngtcp2_conn_get_handshake_completed().bool echo "--- CLIENT >>>3 SERVER" - check 0 == server.ngtcp2_conn_read_pkt(addr zeroPath, addr datagramInfo, addr datagram[0], datagram.len.uint, getMonoTime().ticks.uint) + server.read(datagram[0..