Skip to content

ci: add lint check #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Lint

on:
pull_request:
merge_group:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
nph:
name: NPH
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2 # In PR, has extra merge commit: ^1 = PR, ^2 = base

- name: Check `nph` formatting
uses: arnetheduck/nph-action@v1
with:
version: 0.6.1
fail: true
suggest: true
2 changes: 1 addition & 1 deletion quic.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ requires "nimcrypto >= 0.6.0 & < 0.7.0"
requires "ngtcp2 >= 0.36.1"
requires "unittest2"
requires "chronicles >= 0.10.2"
requires "bearssl >= 0.2.5"
requires "bearssl >= 0.2.5"
14 changes: 7 additions & 7 deletions quic/transport/framesorter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import ../errors
import std/[strformat, tables]
import chronos

type
FrameSorter* = object
buffer: Table[uint64, byte] # sparse byte storage
readPos: uint64 # where to emit data from
incoming: AsyncQueue[seq[byte]]
lastPos: Opt[uint64] # contains the index for the last position for a stream once a FIN is received
type FrameSorter* = object
buffer: Table[uint64, byte] # sparse byte storage
readPos: uint64 # where to emit data from
incoming: AsyncQueue[seq[byte]]
lastPos: Opt[uint64]
# contains the index for the last position for a stream once a FIN is received

proc initFrameSorter*(incoming: AsyncQueue[seq[byte]]): FrameSorter =
result.incoming = incoming
Expand Down Expand Up @@ -49,4 +49,4 @@ proc isComplete*(fs: FrameSorter): bool =
if fs.lastPos.isNone:
return false

return fs.readPos > fs.lastPos.get()
return fs.readPos > fs.lastPos.get()
2 changes: 1 addition & 1 deletion quic/transport/ngtcp2/native.nim
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ export PicoTLSConnection
export init
export destroy
export newConnection
export certificateverifier
export certificateverifier
2 changes: 1 addition & 1 deletion quic/transport/ngtcp2/native/path.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ proc newPath*(local, remote: TransportAddress): Path =
addr_field: cast[ptr ngtcp2_sockaddr](p.remoteAddress.addr),
addr_len: p.remoteAddrLen,
),
user_data: nil
user_data: nil,
)
p
3 changes: 2 additions & 1 deletion quic/transport/version.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#from pkg/ngtcp2 import NGTCP2_PROTO_VER_V2

# V1
const CurrentQuicVersion* = cast[uint32](0x00000001u) # TODO: figure out how to export NGTCP2_PROTO_VER_V1 with futhark
const CurrentQuicVersion* = cast[uint32](0x00000001u)
# TODO: figure out how to export NGTCP2_PROTO_VER_V1 with futhark
3 changes: 2 additions & 1 deletion tests/helpers/simulation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ proc simulateLossyNetwork*(a, b: QuicConnection) {.async.} =

proc setupConnection*(): Future[tuple[client, server: QuicConnection]] {.async.} =
let rng = newRng()
let clientTLSBackend = newClientTLSBackend(@[], @[],toHashSet(@["test"]), Opt.none(CertificateVerifier))
let clientTLSBackend =
newClientTLSBackend(@[], @[], toHashSet(@["test"]), Opt.none(CertificateVerifier))
let client = newQuicClientConnection(clientTLSBackend, zeroAddress, zeroAddress, rng)

client.send() # Start Handshake
Expand Down
26 changes: 18 additions & 8 deletions tests/quic/testExample.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,27 @@ import random
suite "examples from Readme":
test "outgoing and incoming connections":
var message = newSeq[byte](50 * 1024) # 50kib
for i in 0..<message.len:
message[i] = rand(0'u8..255'u8)
for i in 0 ..< message.len:
message[i] = rand(0'u8 .. 255'u8)

let alpn = @["test"]
proc outgoing() {.async.} =
let cb = proc(serverName: string, derCertificates: seq[seq[byte]]): bool {.gcsafe.} =
let cb = proc(
serverName: string, derCertificates: seq[seq[byte]]
): bool {.gcsafe.} =
# TODO: implement custom certificate validation
return derCertificates.len > 0

let customCertVerif: CertificateVerifier = CustomCertificateVerifier.init(cb)
let tlsConfig =
TLSConfig.init(testCertificate(), testPrivateKey(), alpn, certificateVerifier = Opt.some(customCertVerif))
let tlsConfig = TLSConfig.init(
testCertificate(),
testPrivateKey(),
alpn,
certificateVerifier = Opt.some(customCertVerif),
)
let client = QuicClient.init(tlsConfig)
let connection = await client.dial(initTAddress("127.0.0.1:12345"))

check connection.certificates().len == 1

let stream = await connection.openStream()
Expand All @@ -33,10 +39,14 @@ suite "examples from Readme":
await connection.close()

proc incoming() {.async.} =
let cb = proc(serverName: string, derCertificates: seq[seq[byte]]): bool {.gcsafe.} =
let cb = proc(
serverName: string, derCertificates: seq[seq[byte]]
): bool {.gcsafe.} =
return derCertificates.len > 0
let customCertVerif: CertificateVerifier = CustomCertificateVerifier.init(cb)
let tlsConfig = TLSConfig.init(testCertificate(), testPrivateKey(), alpn, Opt.some(customCertVerif))
let tlsConfig = TLSConfig.init(
testCertificate(), testPrivateKey(), alpn, Opt.some(customCertVerif)
)
let server = QuicServer.init(tlsConfig)
let listener = server.listen(initTAddress("127.0.0.1:12345"))

Expand Down
13 changes: 6 additions & 7 deletions tests/quic/testPacketReading.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import pkg/quic/transport/packets
import pkg/quic/helpers/bits

suite "packet reading":

var datagram: seq[byte]

setup:
Expand Down Expand Up @@ -34,7 +33,7 @@ suite "packet reading":

test "reads version negotiation packet":
let length = datagram.write(versionNegotiationPacket())
check readPacket(datagram[0..<length]).kind == packetVersionNegotiation
check readPacket(datagram[0 ..< length]).kind == packetVersionNegotiation

test "reads version":
const version = 0xAABBCCDD'u32
Expand All @@ -58,22 +57,22 @@ suite "packet reading":
test "reads supported versions in version negotiation packet":
const versions = @[0xAABBCCDD'u32, 0x11223344'u32]
let length = datagram.write(versionNegotiationPacket(versions = versions))
let packet = readPacket(datagram[0..<length])
let packet = readPacket(datagram[0 ..< length])
check packet.negotiation.supportedVersions == versions

test "reads token from retry packet":
const token = @[1'u8, 2'u8, 3'u8]
var packet = retryPacket()
packet.retry.token = token
let length = datagram.write(packet)
check readPacket(datagram[0..<length]).retry.token == token
check readPacket(datagram[0 ..< length]).retry.token == token

test "reads integrity tag from retry packet":
const integrity = repeat(0xA'u8, 16)
var packet = retryPacket()
packet.retry.integrity[0..<16] = integrity
packet.retry.integrity[0 ..< 16] = integrity
let length = datagram.write(packet)
check readPacket(datagram[0..<length]).retry.integrity == integrity
check readPacket(datagram[0 ..< length]).retry.integrity == integrity

test "reads packet number from handshake packet":
const packetnumber = 0xABCD
Expand Down Expand Up @@ -163,4 +162,4 @@ suite "packet reading":
packet.short.payload = payload
packet.destination = ConnectionId(repeat(0'u8, DefaultConnectionIdLength))
let length = datagram.write(packet)
check readPacket(datagram[0..<length]).short.payload == payload
check readPacket(datagram[0 ..< length]).short.payload == payload