AtlatestRepositorysigil-quic

sigil-quic / tree / testtest-random-ids.sgl

1(import (sigil test)
2 (sigil quic bytes)
3 (sigil quic frame)
4 (sigil quic connection ids))
5
6(define (ri-with-pool initial procedure (keys: (maximum 256)))
7 (let ((pool (make-local-id-pool initial maximum: maximum)))
8 (dynamic-wind
9 (lambda () #t)
10 (lambda () (procedure pool))
11 (lambda () (local-id-pool-close! pool)))))
13(test-group "Bounded random spare-CID reservations"
14 (test "random-ids: fresh reservation stays unroutable until its exact advertisement commits"
15 (ri-with-pool #u8(1 2 3 4 5 6 7 8)
16 (lambda (pool)
17 (let ((frame (local-id-pool-reserve-random! pool)))
18 (assert-true
19 (and frame (= 1 (frame-ref frame 'sequence))
20 (= 8 (bytevector-length (frame-ref frame 'connection-id)))
21 (= 16 (bytevector-length (frame-ref frame 'token)))
22 (not (bytes=? #u8(1 2 3 4 5 6 7 8) (frame-ref frame 'connection-id)))
23 (not (local-id-pool-route pool (frame-ref frame 'connection-id)))
24 (local-id-pool-check! pool frame)
25 (local-id-pool-commit! pool frame)
26 (= 1 (local-id-pool-route pool (frame-ref frame 'connection-id)))))))))
27 (test "random-ids: queued reservations consume peer capacity without making routes"
28 (ri-with-pool #u8(1)
29 (lambda (pool)
30 (let ((frame (local-id-pool-reserve-random! pool)))
31 (assert-true
32 (and frame (= 2 (local-id-pool-count pool))
33 (not (local-id-pool-route pool (frame-ref frame 'connection-id)))
34 (not (local-id-pool-reserve-random! pool))))))))
35 (test "random-ids: zero-length routing cannot acquire spare IDs"
36 (ri-with-pool #u8()
37 (lambda (pool)
38 (assert-true
39 (and (not (local-id-pool-reserve-random! pool)) (= 1 (local-id-pool-count pool)))))))
40 (test "random-ids: lifetime exhaustion preserves live routes and refuses sequence reuse"
41 (ri-with-pool #u8(1)
42 (lambda (pool)
43 (let ((frame (local-id-pool-reserve-random! pool)))
44 (assert-true
45 (and frame (local-id-pool-commit! pool frame)
46 (local-id-pool-retire! pool 1 #u8(1))
47 (= 1 (local-id-pool-count pool))
48 (not (local-id-pool-reserve-random! pool))
49 (= 0 (local-id-pool-route pool #u8(1))))))) maximum: 2)))