Introduce sequence of outgoing datagrams

This commit is contained in:
Mark Spanbroek 2020-11-02 14:56:28 +01:00 committed by markspanbroek
parent ddd874b6d1
commit 6a54952c8b
4 changed files with 16 additions and 6 deletions

View File

@ -1,4 +1,5 @@
import ngtcp2 import ngtcp2
import ../datagram
import path import path
type type
@ -7,6 +8,7 @@ type
conn*: ptr ngtcp2_conn conn*: ptr ngtcp2_conn
path*: Path path*: Path
buffer*: array[4096, byte] buffer*: array[4096, byte]
outgoing*: seq[Datagram]
proc `=destroy`*(connection: var ConnectionObj) = proc `=destroy`*(connection: var ConnectionObj) =
if connection.conn != nil: if connection.conn != nil:

View File

@ -7,7 +7,7 @@ import connection
import path import path
import errors import errors
proc write*(connection: Connection): Datagram = proc write*(connection: Connection) =
var packetInfo: ngtcp2_pkt_info var packetInfo: ngtcp2_pkt_info
let length = ngtcp2_conn_write_stream( let length = ngtcp2_conn_write_stream(
connection.conn, connection.conn,
@ -22,8 +22,10 @@ proc write*(connection: Connection): Datagram =
0, 0,
getMonoTime().ticks.uint getMonoTime().ticks.uint
) )
var result: Datagram
result.data = connection.buffer[0..<length] result.data = connection.buffer[0..<length]
result.ecn = ECN(packetInfo.ecn) result.ecn = ECN(packetInfo.ecn)
connection.outgoing.insert(result)
proc read*(connection: Connection, datagram: DatagramBuffer, ecn = ecnNonCapable) = proc read*(connection: Connection, datagram: DatagramBuffer, ecn = ecnNonCapable) =
var packetInfo: ngtcp2_pkt_info var packetInfo: ngtcp2_pkt_info

View File

@ -6,15 +6,18 @@ proc performHandshake*: tuple[client, server: Connection] =
var datagram: Datagram var datagram: Datagram
let client = newClientConnection(zeroAddress, zeroAddress) let client = newClientConnection(zeroAddress, zeroAddress)
datagram = client.write() client.write()
datagram = client.outgoing.pop()
let server = newServerConnection(zeroAddress, zeroAddress, datagram.data) let server = newServerConnection(zeroAddress, zeroAddress, datagram.data)
server.read(datagram) server.read(datagram)
datagram = server.write() server.write()
datagram = server.outgoing.pop()
client.read(datagram) client.read(datagram)
datagram = client.write() client.write()
datagram = client.outgoing.pop()
server.read(datagram) server.read(datagram)
(client, server) (client, server)

View File

@ -7,11 +7,14 @@ suite "udp":
test "writes packets to datagrams": test "writes packets to datagrams":
let client = newClientConnection(zeroAddress, zeroAddress) let client = newClientConnection(zeroAddress, zeroAddress)
check client.write().len > 0 client.write()
let datagram = client.outgoing.pop()
check datagram.len > 0
test "reads packets from datagram": test "reads packets from datagram":
let client = newClientConnection(zeroAddress, zeroAddress) let client = newClientConnection(zeroAddress, zeroAddress)
let datagram = client.write() client.write()
let datagram = client.outgoing.pop()
let server = newServerConnection(zeroAddress, zeroAddress, datagram.data) let server = newServerConnection(zeroAddress, zeroAddress, datagram.data)
server.read(datagram) server.read(datagram)