mirror of https://github.com/vacp2p/nim-quic.git
Write payload of short packets
This commit is contained in:
parent
c9534fcd61
commit
10b69064ee
|
@ -46,6 +46,7 @@ proc write*(datagram: var Datagram, packet: Packet) =
|
||||||
writer.writeKeyPhase(datagram)
|
writer.writeKeyPhase(datagram)
|
||||||
writer.writeShortDestination(datagram)
|
writer.writeShortDestination(datagram)
|
||||||
writer.writePacketNumber(datagram)
|
writer.writePacketNumber(datagram)
|
||||||
|
writer.writePayload(datagram)
|
||||||
of formLong:
|
of formLong:
|
||||||
writer.writeKind(datagram)
|
writer.writeKind(datagram)
|
||||||
writer.writeVersion(datagram)
|
writer.writeVersion(datagram)
|
||||||
|
|
|
@ -19,6 +19,7 @@ type
|
||||||
spinBit*: bool
|
spinBit*: bool
|
||||||
keyPhase*: bool
|
keyPhase*: bool
|
||||||
packetnumber*: PacketNumber
|
packetnumber*: PacketNumber
|
||||||
|
payload*: seq[byte]
|
||||||
PacketInitial* = object
|
PacketInitial* = object
|
||||||
version*: uint32
|
version*: uint32
|
||||||
token*: seq[byte]
|
token*: seq[byte]
|
||||||
|
|
|
@ -55,11 +55,15 @@ proc writeIntegrity*(writer: var PacketWriter, datagram: var Datagram) =
|
||||||
writer.write(datagram, writer.packet.retry.integrity)
|
writer.write(datagram, writer.packet.retry.integrity)
|
||||||
|
|
||||||
proc payload(packet: Packet): seq[byte] =
|
proc payload(packet: Packet): seq[byte] =
|
||||||
case packet.kind
|
case packet.form
|
||||||
of packetHandshake: packet.handshake.payload
|
of formShort:
|
||||||
of packet0RTT: packet.rtt.payload
|
packet.short.payload
|
||||||
of packetInitial: packet.initial.payload
|
of formLong:
|
||||||
else: @[]
|
case packet.kind
|
||||||
|
of packetHandshake: packet.handshake.payload
|
||||||
|
of packet0RTT: packet.rtt.payload
|
||||||
|
of packetInitial: packet.initial.payload
|
||||||
|
else: @[]
|
||||||
|
|
||||||
proc packetNumber(packet: Packet): PacketNumber =
|
proc packetNumber(packet: Packet): PacketNumber =
|
||||||
case packet.form
|
case packet.form
|
||||||
|
|
|
@ -158,6 +158,12 @@ suite "packet writing":
|
||||||
check int(datagram[0] and 0b11'u8) + 1 == sizeof(packetnumber)
|
check int(datagram[0] and 0b11'u8) + 1 == sizeof(packetnumber)
|
||||||
check datagram[1..2] == @[0xAA'u8, 0xBB'u8]
|
check datagram[1..2] == @[0xAA'u8, 0xBB'u8]
|
||||||
|
|
||||||
|
test "writes payload for short packet":
|
||||||
|
const payload = repeat(0xAB'u8, 1024)
|
||||||
|
var packet = Packet(form: formShort, short: PacketShort(payload: payload))
|
||||||
|
datagram.write(packet)
|
||||||
|
check datagram[2..1025] == payload
|
||||||
|
|
||||||
suite "packet reading":
|
suite "packet reading":
|
||||||
|
|
||||||
var datagram: seq[byte]
|
var datagram: seq[byte]
|
||||||
|
|
Loading…
Reference in New Issue