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.writeShortDestination(datagram)
|
||||
writer.writePacketNumber(datagram)
|
||||
writer.writePayload(datagram)
|
||||
of formLong:
|
||||
writer.writeKind(datagram)
|
||||
writer.writeVersion(datagram)
|
||||
|
|
|
@ -19,6 +19,7 @@ type
|
|||
spinBit*: bool
|
||||
keyPhase*: bool
|
||||
packetnumber*: PacketNumber
|
||||
payload*: seq[byte]
|
||||
PacketInitial* = object
|
||||
version*: uint32
|
||||
token*: seq[byte]
|
||||
|
|
|
@ -55,11 +55,15 @@ proc writeIntegrity*(writer: var PacketWriter, datagram: var Datagram) =
|
|||
writer.write(datagram, writer.packet.retry.integrity)
|
||||
|
||||
proc payload(packet: Packet): seq[byte] =
|
||||
case packet.kind
|
||||
of packetHandshake: packet.handshake.payload
|
||||
of packet0RTT: packet.rtt.payload
|
||||
of packetInitial: packet.initial.payload
|
||||
else: @[]
|
||||
case packet.form
|
||||
of formShort:
|
||||
packet.short.payload
|
||||
of formLong:
|
||||
case packet.kind
|
||||
of packetHandshake: packet.handshake.payload
|
||||
of packet0RTT: packet.rtt.payload
|
||||
of packetInitial: packet.initial.payload
|
||||
else: @[]
|
||||
|
||||
proc packetNumber(packet: Packet): PacketNumber =
|
||||
case packet.form
|
||||
|
|
|
@ -158,6 +158,12 @@ suite "packet writing":
|
|||
check int(datagram[0] and 0b11'u8) + 1 == sizeof(packetnumber)
|
||||
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":
|
||||
|
||||
var datagram: seq[byte]
|
||||
|
|
Loading…
Reference in New Issue