AtlatestRepositorysigil-quic

sigil-quic / tree / testtest-network-confirmation.sgl

1(import (sigil test)
2 (sigil quic bytes)
3 (sigil quic frame)
4 (sigil quic connection network))
5
6(define (nc-with-passive procedure)
7 (let ((network
8 (make-connection-network #u8(1) #u8(2) 'server #u8(10) 0
9 (list (cons 0 #u8(10 11 12 13 14 15 16 17)) (cons 15 #u8(1)))
10 (list (cons 15 #u8(2))) confirmed?: #f)))
11 (dynamic-wind
12 (lambda () #t)
13 (lambda () (procedure network))
14 (lambda () (network-close! network)))))
16(define (nc-advertisement)
17 (make-quic-frame 24
18 (list (cons 'sequence 1) (cons 'retire-prior-to 0)
19 (cons 'connection-id #u8(3)) (cons 'token (make-bytevector 16 0)))))
21(test-group "Passive CID ownership before handshake confirmation"
22 (test "network-confirmation: early CID metadata is retained while every path operation is refused"
23 (nc-with-passive
24 (lambda (network)
25 (assert-true (network-peer-id! network (nc-advertisement)))
26 (for-each
27 (lambda (procedure) (assert-error (procedure)))
28 (list
29 (lambda () (network-observe! network #u8(11) 1200 1 (list (make-quic-frame 1 '())) 0))
30 (lambda () (network-challenge! network #u8(11) 0))
31 (lambda () (network-reserve-send! network #u8(10) 1200 0))
32 (lambda () (network-response! network (make-bytevector 8 0) 0))
33 (lambda () (network-tick! network 0))))
34 (assert-true
35 (and (bytes=? #u8(10) (network-address network))
36 (not (network-candidate network)) (not (network-destination network #u8(11)))
37 (null? (network-take-events! network)))))))
38 (test "network-confirmation: confirmation seeds ordering once and preserves early CID ownership"
39 (nc-with-passive
40 (lambda (network)
41 (network-peer-id! network (nc-advertisement))
42 (network-confirm! network 100 10)
43 (assert-true
44 (and (not (network-observe! network #u8(11) 1200 9 (list (make-quic-frame 1 '())) 100))
45 (network-observe! network #u8(11) 1200 11 (list (make-quic-frame 1 '())) 100)
46 (let ((probe (network-challenge! network #u8(11) 100)))
47 (and probe (= 1 (vector-ref probe 1))
48 (bytes=? #u8(3) (vector-ref probe 2))
49 (network-response! network (vector-ref probe 3) 101)
50 (network-confirm! network 102 0)
51 (bytes=? #u8(11) (network-address network))
52 (not (network-observe! network #u8(12) 1200 10 (list (make-quic-frame 1 '())) 102)))))))))
53 (test "network-confirmation: close-route snapshots are owned and exclude uncommitted or retired IDs"
54 (nc-with-passive
55 (lambda (network)
56 (let ((frame (network-issue-id! network #u8(4) (make-bytevector 16 0))))
57 (assert-false (network-local-id network 1))
58 (network-commit-id! network frame)
59 (let ((copy (network-local-id network 1)))
60 (bytevector-u8-set! copy 0 5))
61 (assert-true
62 (and (bytes=? #u8(4) (network-local-id network 1))
63 (network-retire-local-id! network 1 #u8(1))
64 (not (network-local-id network 1))
65 (bytes=? #u8(1) (network-local-id network 0)))))))))