add support for i386
This commit is contained in:
parent
8a97eeeb80
commit
959086ca63
|
@ -9,18 +9,47 @@ on:
|
|||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ${{ matrix.os }}
|
||||
timeout-minutes: 30
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, macOS-latest, windows-latest]
|
||||
nim: [1.6.20, 2.0.8]
|
||||
platform:
|
||||
- os: linux
|
||||
runner: ubuntu-latest
|
||||
cpu: amd64
|
||||
shell: bash
|
||||
- os: linux
|
||||
runner: ubuntu-latest
|
||||
cpu: i386
|
||||
shell: bash
|
||||
- os: macos
|
||||
runner: macos-latest
|
||||
cpu: amd64
|
||||
shell: bash
|
||||
- os: windows
|
||||
runner: windows-latest
|
||||
cpu: amd64
|
||||
shell: msys2 {0}
|
||||
nim:
|
||||
- branch: version-1-6
|
||||
- branch: version-2-0
|
||||
|
||||
name: '${{ matrix.platform.os }}-${{ matrix.platform.cpu }} (Nim ${{ matrix.nim.branch }})'
|
||||
runs-on: ${{ matrix.platform.runner }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: iffy/install-nim@v3
|
||||
with:
|
||||
version: ${{ matrix.nim }}
|
||||
- name: Build
|
||||
run: nimble install -y
|
||||
- name: Test
|
||||
run: nimble test -y
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Nim
|
||||
uses: vacp2p/nim-libp2p/.github/actions/install_nim@master
|
||||
with:
|
||||
os: ${{ matrix.platform.os }}
|
||||
cpu: ${{ matrix.platform.cpu }}
|
||||
shell: ${{ matrix.platform.shell }}
|
||||
nim_branch: ${{ matrix.nim.branch }}
|
||||
|
||||
- name: Install dependencies
|
||||
run: nimble install -y
|
||||
|
||||
- name: Test
|
||||
run: nimble test -y
|
||||
|
|
|
@ -2,7 +2,7 @@ import std/math
|
|||
import pkg/stew/endians2
|
||||
|
||||
type
|
||||
PacketNumber* = range[0..2^62-1]
|
||||
PacketNumber* = range[0'i64..2'i64^62-1]
|
||||
|
||||
proc toMinimalBytes*(packetnumber: PacketNumber): seq[byte] =
|
||||
let bytes = packetnumber.uint64.toBytesBE
|
||||
|
|
|
@ -95,7 +95,7 @@ proc readPacketNumber(reader: var PacketReader, datagram: openArray[byte],
|
|||
padded[padded.len-bytes.len..<padded.len] = bytes
|
||||
except RangeError:
|
||||
doAssert false, "programmer error: assignment ranges do not match"
|
||||
reader.packet.packetnumber = fromBytesBE(uint32, padded)
|
||||
reader.packet.packetnumber = fromBytesBE(uint32, padded).int64
|
||||
|
||||
proc `payload=`(packet: var Packet, payload: seq[byte]) =
|
||||
case packet.form
|
||||
|
|
|
@ -2,7 +2,7 @@ import std/math
|
|||
import pkg/stew/endians2
|
||||
|
||||
type
|
||||
VarIntCompatible* = range[0..2^62-1]
|
||||
VarIntCompatible* = range[0'i64..2'i64^62-1]
|
||||
|
||||
proc toVarInt*(value: VarIntCompatible): seq[byte] =
|
||||
case value
|
||||
|
@ -22,7 +22,7 @@ proc varintlen*(varint: openArray[byte]): int =
|
|||
2^(varint[0] shr 6)
|
||||
|
||||
proc fromVarInt*(varint: openArray[byte]): VarIntCompatible =
|
||||
case varintlen(varint)
|
||||
let r = case varintlen(varint)
|
||||
of 1:
|
||||
varint[0].uint64
|
||||
of 2:
|
||||
|
@ -34,3 +34,4 @@ proc fromVarInt*(varint: openArray[byte]): VarIntCompatible =
|
|||
else:
|
||||
const mask = not(0b11'u64 shl 62)
|
||||
fromBytesBE(uint64, varint) and mask
|
||||
r.int64
|
||||
|
|
|
@ -29,7 +29,7 @@ suite "packet length":
|
|||
var packet = handshakePacket()
|
||||
packet.destination = destination
|
||||
packet.source = source
|
||||
packet.handshake.packetnumber = 0x00BBCCDD'u32
|
||||
packet.handshake.packetnumber = 0x00BBCCDD'u32.int64
|
||||
packet.handshake.payload = repeat(0xEE'u8, 1024)
|
||||
check packet.len == 7 +
|
||||
destination.len +
|
||||
|
@ -42,7 +42,7 @@ suite "packet length":
|
|||
var packet = zeroRttPacket()
|
||||
packet.destination = destination
|
||||
packet.source = source
|
||||
packet.rtt.packetnumber = 0x00BBCCDD'u32
|
||||
packet.rtt.packetnumber = 0x00BBCCDD'u32.int64
|
||||
packet.rtt.payload = repeat(0xEE'u8, 1024)
|
||||
check packet.len == 7 +
|
||||
destination.len +
|
||||
|
@ -56,7 +56,7 @@ suite "packet length":
|
|||
packet.destination = destination
|
||||
packet.source = source
|
||||
packet.initial.token = token
|
||||
packet.initial.packetnumber = 0x00BBCCDD'u32
|
||||
packet.initial.packetnumber = 0x00BBCCDD'u32.int64
|
||||
packet.initial.payload = repeat(0xEE'u8, 1024)
|
||||
check packet.len == 7 +
|
||||
destination.len +
|
||||
|
@ -70,7 +70,7 @@ suite "packet length":
|
|||
test "knows the length of a short packet":
|
||||
var packet = shortPacket()
|
||||
packet.destination = destination
|
||||
packet.short.packetnumber = 0x00BBCCDD'u32
|
||||
packet.short.packetnumber = 0x00BBCCDD'u32.int64
|
||||
packet.short.payload = repeat(0xEE'u8, 1024)
|
||||
check packet.len == 1 +
|
||||
destination.len +
|
||||
|
|
|
@ -6,7 +6,7 @@ suite "packet numbers":
|
|||
|
||||
test "packet numbers are in the range 0 to 2^62-1":
|
||||
check PacketNumber.low == 0
|
||||
check PacketNumber.high == 2 ^ 62 - 1
|
||||
check PacketNumber.high == 2'i64 ^ 62 - 1
|
||||
|
||||
test "conversion to bytes":
|
||||
check 0.toMinimalBytes == @[0'u8]
|
||||
|
|
|
@ -73,7 +73,7 @@ suite "packet writing":
|
|||
const packetnumber = 0xAABBCCDD'u32
|
||||
const payload = repeat(0xAB'u8, 1024)
|
||||
var packet = handshakePacket()
|
||||
packet.handshake.packetnumber = packetnumber
|
||||
packet.handshake.packetnumber = packetnumber.int64
|
||||
packet.handshake.payload = payload
|
||||
datagram.write(packet)
|
||||
check datagram[7..8] == (sizeof(packetnumber) + payload.len).toVarInt
|
||||
|
@ -81,7 +81,7 @@ suite "packet writing":
|
|||
test "writes handshake packet number":
|
||||
const packetnumber = 0xAABBCCDD'u32
|
||||
var packet = handshakePacket()
|
||||
packet.handshake.packetnumber = packetnumber
|
||||
packet.handshake.packetnumber = packetnumber.int64
|
||||
datagram.write(packet)
|
||||
check int(datagram[0] and 0b11'u8) + 1 == sizeof(packetnumber)
|
||||
check datagram[8..11] == @[0xAA'u8, 0xBB'u8, 0xCC'u8, 0xDD'u8]
|
||||
|
@ -97,7 +97,7 @@ suite "packet writing":
|
|||
const packetnumber = 0xAABBCCDD'u32
|
||||
const payload = repeat(0xAB'u8, 1024)
|
||||
var packet = zeroRttPacket()
|
||||
packet.rtt.packetnumber = packetnumber
|
||||
packet.rtt.packetnumber = packetnumber.int64
|
||||
packet.rtt.payload = payload
|
||||
datagram.write(packet)
|
||||
check datagram[7..8] == (sizeof(packetnumber) + payload.len).toVarInt
|
||||
|
@ -105,7 +105,7 @@ suite "packet writing":
|
|||
test "writes 0-RTT packet number":
|
||||
const packetnumber = 0xAABBCCDD'u32
|
||||
var packet = zeroRttPacket()
|
||||
packet.rtt.packetnumber = packetnumber
|
||||
packet.rtt.packetnumber = packetnumber.int64
|
||||
datagram.write(packet)
|
||||
check int(datagram[0] and 0b11'u8) + 1 == sizeof(packetnumber)
|
||||
check datagram[8..11] == @[0xAA'u8, 0xBB'u8, 0xCC'u8, 0xDD'u8]
|
||||
|
@ -129,7 +129,7 @@ suite "packet writing":
|
|||
const packetnumber = 0xAABBCCDD'u32
|
||||
const payload = repeat(0xAB'u8, 1024)
|
||||
var packet = initialPacket()
|
||||
packet.initial.packetnumber = packetnumber
|
||||
packet.initial.packetnumber = packetnumber.int64
|
||||
packet.initial.payload = payload
|
||||
datagram.write(packet)
|
||||
check datagram[8..9] == (sizeof(packetnumber) + payload.len).toVarInt
|
||||
|
@ -137,7 +137,7 @@ suite "packet writing":
|
|||
test "writes initial packet number":
|
||||
const packetnumber = 0xAABBCCDD'u32
|
||||
var packet = initialPacket()
|
||||
packet.initial.packetnumber = packetnumber
|
||||
packet.initial.packetnumber = packetnumber.int64
|
||||
datagram.write(packet)
|
||||
check int(datagram[0] and 0b11'u8) + 1 == sizeof(packetnumber)
|
||||
check datagram[9..12] == @[0xAA'u8, 0xBB'u8, 0xCC'u8, 0xDD'u8]
|
||||
|
@ -184,7 +184,7 @@ suite "packet writing":
|
|||
test "writes packet number for short packet":
|
||||
const packetnumber = 0xAABB'u16
|
||||
var packet = shortPacket()
|
||||
packet.short.packetnumber = packetnumber
|
||||
packet.short.packetnumber = packetnumber.int64
|
||||
datagram.write(packet)
|
||||
check int(datagram[0] and 0b11'u8) + 1 == sizeof(packetnumber)
|
||||
check datagram[1..2] == @[0xAA'u8, 0xBB'u8]
|
||||
|
|
|
@ -23,11 +23,11 @@ suite "variable length integer encoding":
|
|||
test "encodes 30-62 bit numbers as 8 bytes":
|
||||
check toVarInt(2^30) ==
|
||||
@[0b11000000'u8, 0'u8, 0'u8, 0'u8, 0b01000000'u8, 0'u8, 0'u8, 0'u8]
|
||||
check toVarInt(2^32) ==
|
||||
check toVarInt(2'i64^32) ==
|
||||
@[0b11000000'u8, 0'u8, 0'u8, 1'u8, 0'u8, 0'u8, 0'u8, 0'u8]
|
||||
check toVarInt(2^56) ==
|
||||
check toVarInt(2'i64^56) ==
|
||||
@[0b11000001'u8, 0'u8, 0'u8, 0'u8, 0'u8, 0'u8, 0'u8, 0'u8]
|
||||
check toVarInt(2^62-1) ==
|
||||
check toVarInt(2'i64^62-1) ==
|
||||
@[0xFF'u8, 0xFF'u8, 0xFF'u8, 0xFF'u8, 0xFF'u8, 0xFF'u8, 0xFF'u8, 0xFF'u8]
|
||||
|
||||
suite "variable length integer decoding":
|
||||
|
@ -53,10 +53,10 @@ suite "variable length integer decoding":
|
|||
]) == 0
|
||||
check fromVarInt(@[
|
||||
0b11000001'u8, 0'u8, 0'u8, 0'u8, 0'u8, 0'u8, 0'u8, 0'u8
|
||||
]) == 2^56
|
||||
]) == 2'i64^56
|
||||
check fromVarInt(@[
|
||||
0xFF'u8, 0xFF'u8, 0xFF'u8, 0xFF'u8, 0xFF'u8, 0xFF'u8, 0xFF'u8, 0xFF'u8
|
||||
]) == 2^62-1
|
||||
]) == 2'i64^62-1
|
||||
|
||||
suite "variable length":
|
||||
|
||||
|
|
Loading…
Reference in New Issue