@@ -2,7 +2,8 @@ package quic
22
33import (
44 "bytes"
5- "math/rand"
5+
6+ "golang.org/x/exp/rand"
67
78 "github.com/quic-go/quic-go/internal/ackhandler"
89 "github.com/quic-go/quic-go/internal/protocol"
@@ -111,6 +112,55 @@ var _ = Describe("Framer", func() {
111112 })
112113 })
113114
115+ Context ("handling PATH_RESPONSE frames" , func () {
116+ It ("packs a single PATH_RESPONSE per packet" , func () {
117+ f1 := & wire.PathResponseFrame {Data : [8 ]byte {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 }}
118+ f2 := & wire.PathResponseFrame {Data : [8 ]byte {2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 }}
119+ cf1 := & wire.DataBlockedFrame {MaximumData : 1337 }
120+ cf2 := & wire.HandshakeDoneFrame {}
121+ framer .QueueControlFrame (f1 )
122+ framer .QueueControlFrame (f2 )
123+ framer .QueueControlFrame (cf1 )
124+ framer .QueueControlFrame (cf2 )
125+ // the first packet should contain a single PATH_RESPONSE frame, but all the other control frames
126+ Expect (framer .HasData ()).To (BeTrue ())
127+ frames , length := framer .AppendControlFrames (nil , protocol .MaxByteCount , protocol .Version1 )
128+ Expect (frames ).To (HaveLen (3 ))
129+ Expect (frames [0 ].Frame ).To (Equal (f1 ))
130+ Expect ([]wire.Frame {frames [1 ].Frame , frames [2 ].Frame }).To (ContainElement (cf1 ))
131+ Expect ([]wire.Frame {frames [1 ].Frame , frames [2 ].Frame }).To (ContainElement (cf2 ))
132+ Expect (length ).To (Equal (f1 .Length (protocol .Version1 ) + cf1 .Length (protocol .Version1 ) + cf2 .Length (protocol .Version1 )))
133+ // the second packet should contain the other PATH_RESPONSE frame
134+ Expect (framer .HasData ()).To (BeTrue ())
135+ frames , length = framer .AppendControlFrames (nil , protocol .MaxByteCount , protocol .Version1 )
136+ Expect (frames ).To (HaveLen (1 ))
137+ Expect (frames [0 ].Frame ).To (Equal (f2 ))
138+ Expect (length ).To (Equal (f2 .Length (protocol .Version1 )))
139+ Expect (framer .HasData ()).To (BeFalse ())
140+ })
141+
142+ It ("limits the number of queued PATH_RESPONSE frames" , func () {
143+ var pathResponses []* wire.PathResponseFrame
144+ for i := 0 ; i < 2 * maxPathResponses ; i ++ {
145+ var f wire.PathResponseFrame
146+ rand .Read (f .Data [:])
147+ pathResponses = append (pathResponses , & f )
148+ framer .QueueControlFrame (& f )
149+ }
150+ for i := 0 ; i < maxPathResponses ; i ++ {
151+ Expect (framer .HasData ()).To (BeTrue ())
152+ frames , length := framer .AppendControlFrames (nil , protocol .MaxByteCount , protocol .Version1 )
153+ Expect (frames ).To (HaveLen (1 ))
154+ Expect (frames [0 ].Frame ).To (Equal (pathResponses [i ]))
155+ Expect (length ).To (Equal (pathResponses [i ].Length (protocol .Version1 )))
156+ }
157+ Expect (framer .HasData ()).To (BeFalse ())
158+ frames , length := framer .AppendControlFrames (nil , protocol .MaxByteCount , protocol .Version1 )
159+ Expect (frames ).To (BeEmpty ())
160+ Expect (length ).To (BeZero ())
161+ })
162+ })
163+
114164 Context ("popping STREAM frames" , func () {
115165 It ("returns nil when popping an empty framer" , func () {
116166 Expect (framer .AppendStreamFrames (nil , 1000 , protocol .Version1 )).To (BeEmpty ())
0 commit comments