mirror of https://github.com/vacp2p/nim-quic.git
Supported version field for version negotation packets
This commit is contained in:
parent
f54f7a4f3b
commit
329513fdde
|
@ -88,9 +88,19 @@ proc `$`*(header: PacketHeader): string =
|
|||
|
||||
proc `==`*(x: ConnectionId, y: ConnectionId): bool {.borrow.}
|
||||
|
||||
proc supportedVersionSlice(header: PacketHeader): Slice[int] =
|
||||
let start = header.sourceSlice().b + 1
|
||||
result = start..<start+4
|
||||
|
||||
proc supportedVersion*(header: PacketHeader): uint32 =
|
||||
let versionBytes = header.bytes[header.supportedVersionSlice]
|
||||
result.bytes[0] = versionBytes[0]
|
||||
result.bytes[1] = versionBytes[1]
|
||||
result.bytes[2] = versionBytes[2]
|
||||
result.bytes[3] = versionBytes[3]
|
||||
proc packetLength*(header: PacketHeader): int =
|
||||
case header.kind:
|
||||
of packetVersionNegotiation:
|
||||
return header.sourceSlice.b + 1 + 4
|
||||
return header.supportedVersionSlice.b + 1
|
||||
else:
|
||||
return 0
|
||||
|
|
|
@ -121,6 +121,16 @@ suite "long headers":
|
|||
source.len + 1 +
|
||||
version1.len
|
||||
|
||||
test "has a supported version field":
|
||||
let header = newPacketHeader(
|
||||
type0 &
|
||||
version0 &
|
||||
destination.len.uint8 & destination &
|
||||
source.len.uint8 & source &
|
||||
version1
|
||||
)
|
||||
check header.supportedVersion == 1'u32
|
||||
|
||||
suite "packet numbers":
|
||||
|
||||
test "packet numbers are in the range 0 to 2^62-1":
|
||||
|
|
Loading…
Reference in New Issue