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