diff --git a/internal/wire/frame_parser.go b/internal/wire/frame_parser.go index ec67dbbd..131c425e 100644 --- a/internal/wire/frame_parser.go +++ b/internal/wire/frame_parser.go @@ -68,7 +68,7 @@ func parseFrame(r *bytes.Reader, typeByte byte, v protocol.VersionNumber) (Frame err = qerr.Error(qerr.InvalidBlockedData, err.Error()) } case 0x9: - frame, err = parseStreamBlockedFrame(r, v) + frame, err = parseStreamDataBlockedFrame(r, v) if err != nil { err = qerr.Error(qerr.InvalidBlockedData, err.Error()) } diff --git a/internal/wire/frame_parser_test.go b/internal/wire/frame_parser_test.go index ec75f459..92e96408 100644 --- a/internal/wire/frame_parser_test.go +++ b/internal/wire/frame_parser_test.go @@ -117,10 +117,10 @@ var _ = Describe("Frame parsing", func() { Expect(frame).To(Equal(f)) }) - It("unpacks stream-level BLOCKED frames", func() { - f := &StreamBlockedFrame{ - StreamID: 0xdeadbeef, - Offset: 0xdead, + It("unpacks STREAM_DATA_BLOCKED frames", func() { + f := &StreamDataBlockedFrame{ + StreamID: 0xdeadbeef, + DataLimit: 0xdead, } buf := &bytes.Buffer{} err := f.Write(buf, versionIETFFrames) diff --git a/internal/wire/stream_blocked_frame.go b/internal/wire/stream_blocked_frame.go deleted file mode 100644 index cb92a13f..00000000 --- a/internal/wire/stream_blocked_frame.go +++ /dev/null @@ -1,46 +0,0 @@ -package wire - -import ( - "bytes" - - "github.com/lucas-clemente/quic-go/internal/protocol" - "github.com/lucas-clemente/quic-go/internal/utils" -) - -// A StreamBlockedFrame in QUIC -type StreamBlockedFrame struct { - StreamID protocol.StreamID - Offset protocol.ByteCount -} - -// parseStreamBlockedFrame parses a STREAM_BLOCKED frame -func parseStreamBlockedFrame(r *bytes.Reader, _ protocol.VersionNumber) (*StreamBlockedFrame, error) { - if _, err := r.ReadByte(); err != nil { // read the TypeByte - return nil, err - } - sid, err := utils.ReadVarInt(r) - if err != nil { - return nil, err - } - offset, err := utils.ReadVarInt(r) - if err != nil { - return nil, err - } - return &StreamBlockedFrame{ - StreamID: protocol.StreamID(sid), - Offset: protocol.ByteCount(offset), - }, nil -} - -// Write writes a STREAM_BLOCKED frame -func (f *StreamBlockedFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) error { - b.WriteByte(0x09) - utils.WriteVarInt(b, uint64(f.StreamID)) - utils.WriteVarInt(b, uint64(f.Offset)) - return nil -} - -// Length of a written frame -func (f *StreamBlockedFrame) Length(version protocol.VersionNumber) protocol.ByteCount { - return 1 + utils.VarIntLen(uint64(f.StreamID)) + utils.VarIntLen(uint64(f.Offset)) -} diff --git a/internal/wire/stream_data_blocked_frame.go b/internal/wire/stream_data_blocked_frame.go new file mode 100644 index 00000000..d2d5c173 --- /dev/null +++ b/internal/wire/stream_data_blocked_frame.go @@ -0,0 +1,46 @@ +package wire + +import ( + "bytes" + + "github.com/lucas-clemente/quic-go/internal/protocol" + "github.com/lucas-clemente/quic-go/internal/utils" +) + +// A StreamDataBlockedFrame is a STREAM_DATA_BLOCKED frame +type StreamDataBlockedFrame struct { + StreamID protocol.StreamID + DataLimit protocol.ByteCount +} + +func parseStreamDataBlockedFrame(r *bytes.Reader, _ protocol.VersionNumber) (*StreamDataBlockedFrame, error) { + if _, err := r.ReadByte(); err != nil { + return nil, err + } + + sid, err := utils.ReadVarInt(r) + if err != nil { + return nil, err + } + offset, err := utils.ReadVarInt(r) + if err != nil { + return nil, err + } + + return &StreamDataBlockedFrame{ + StreamID: protocol.StreamID(sid), + DataLimit: protocol.ByteCount(offset), + }, nil +} + +func (f *StreamDataBlockedFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) error { + b.WriteByte(0x09) + utils.WriteVarInt(b, uint64(f.StreamID)) + utils.WriteVarInt(b, uint64(f.DataLimit)) + return nil +} + +// Length of a written frame +func (f *StreamDataBlockedFrame) Length(version protocol.VersionNumber) protocol.ByteCount { + return 1 + utils.VarIntLen(uint64(f.StreamID)) + utils.VarIntLen(uint64(f.DataLimit)) +} diff --git a/internal/wire/stream_blocked_frame_test.go b/internal/wire/stream_data_blocked_frame_test.go similarity index 68% rename from internal/wire/stream_blocked_frame_test.go rename to internal/wire/stream_data_blocked_frame_test.go index d72f4bda..e39d7569 100644 --- a/internal/wire/stream_blocked_frame_test.go +++ b/internal/wire/stream_data_blocked_frame_test.go @@ -10,17 +10,17 @@ import ( . "github.com/onsi/gomega" ) -var _ = Describe("STREAM_BLOCKED frame", func() { +var _ = Describe("STREAM_DATA_BLOCKED frame", func() { Context("parsing", func() { It("accepts sample frame", func() { data := []byte{0x9} data = append(data, encodeVarInt(0xdeadbeef)...) // stream ID data = append(data, encodeVarInt(0xdecafbad)...) // offset b := bytes.NewReader(data) - frame, err := parseStreamBlockedFrame(b, versionIETFFrames) + frame, err := parseStreamDataBlockedFrame(b, versionIETFFrames) Expect(err).ToNot(HaveOccurred()) Expect(frame.StreamID).To(Equal(protocol.StreamID(0xdeadbeef))) - Expect(frame.Offset).To(Equal(protocol.ByteCount(0xdecafbad))) + Expect(frame.DataLimit).To(Equal(protocol.ByteCount(0xdecafbad))) Expect(b.Len()).To(BeZero()) }) @@ -28,10 +28,10 @@ var _ = Describe("STREAM_BLOCKED frame", func() { data := []byte{0x9} data = append(data, encodeVarInt(0xdeadbeef)...) data = append(data, encodeVarInt(0xc0010ff)...) - _, err := parseStreamBlockedFrame(bytes.NewReader(data), versionIETFFrames) + _, err := parseStreamDataBlockedFrame(bytes.NewReader(data), versionIETFFrames) Expect(err).NotTo(HaveOccurred()) for i := range data { - _, err := parseStreamBlockedFrame(bytes.NewReader(data[0:i]), versionIETFFrames) + _, err := parseStreamDataBlockedFrame(bytes.NewReader(data[0:i]), versionIETFFrames) Expect(err).To(HaveOccurred()) } }) @@ -39,24 +39,24 @@ var _ = Describe("STREAM_BLOCKED frame", func() { Context("writing", func() { It("has proper min length", func() { - f := &StreamBlockedFrame{ - StreamID: 0x1337, - Offset: 0xdeadbeef, + f := &StreamDataBlockedFrame{ + StreamID: 0x1337, + DataLimit: 0xdeadbeef, } Expect(f.Length(0)).To(Equal(1 + utils.VarIntLen(0x1337) + utils.VarIntLen(0xdeadbeef))) }) It("writes a sample frame", func() { b := &bytes.Buffer{} - f := &StreamBlockedFrame{ - StreamID: 0xdecafbad, - Offset: 0x1337, + f := &StreamDataBlockedFrame{ + StreamID: 0xdecafbad, + DataLimit: 0x1337, } err := f.Write(b, versionIETFFrames) Expect(err).ToNot(HaveOccurred()) expected := []byte{0x9} expected = append(expected, encodeVarInt(uint64(f.StreamID))...) - expected = append(expected, encodeVarInt(uint64(f.Offset))...) + expected = append(expected, encodeVarInt(uint64(f.DataLimit))...) Expect(b.Bytes()).To(Equal(expected)) }) }) diff --git a/send_stream.go b/send_stream.go index fc96fcc7..f3848008 100644 --- a/send_stream.go +++ b/send_stream.go @@ -169,9 +169,9 @@ func (s *sendStream) popStreamFrameImpl(maxBytes protocol.ByteCount) (bool /* co return false, nil, false } if isBlocked, offset := s.flowController.IsNewlyBlocked(); isBlocked { - s.sender.queueControlFrame(&wire.StreamBlockedFrame{ - StreamID: s.streamID, - Offset: offset, + s.sender.queueControlFrame(&wire.StreamDataBlockedFrame{ + StreamID: s.streamID, + DataLimit: offset, }) return false, nil, false } diff --git a/send_stream_test.go b/send_stream_test.go index 924f76bc..62a8bf43 100644 --- a/send_stream_test.go +++ b/send_stream_test.go @@ -179,9 +179,9 @@ var _ = Describe("Send Stream", func() { It("queues a BLOCKED frame if the stream is flow control blocked", func() { mockFC.EXPECT().SendWindowSize().Return(protocol.ByteCount(0)) mockFC.EXPECT().IsNewlyBlocked().Return(true, protocol.ByteCount(12)) - mockSender.EXPECT().queueControlFrame(&wire.StreamBlockedFrame{ - StreamID: streamID, - Offset: 12, + mockSender.EXPECT().queueControlFrame(&wire.StreamDataBlockedFrame{ + StreamID: streamID, + DataLimit: 12, }) mockSender.EXPECT().onHasStreamData(streamID) done := make(chan struct{}) @@ -224,9 +224,9 @@ var _ = Describe("Send Stream", func() { mockFC.EXPECT().SendWindowSize() // don't use offset 3 here, to make sure the BLOCKED frame contains the number returned by the flow controller mockFC.EXPECT().IsNewlyBlocked().Return(true, protocol.ByteCount(10)) - mockSender.EXPECT().queueControlFrame(&wire.StreamBlockedFrame{ - StreamID: streamID, - Offset: 10, + mockSender.EXPECT().queueControlFrame(&wire.StreamDataBlockedFrame{ + StreamID: streamID, + DataLimit: 10, }) f, hasMoreData = str.popStreamFrame(1000) Expect(f).To(BeNil()) diff --git a/session.go b/session.go index e306a7d4..125e3615 100644 --- a/session.go +++ b/session.go @@ -552,7 +552,7 @@ func (s *session) handleFrames(fs []wire.Frame, encLevel protocol.EncryptionLeve case *wire.MaxStreamIDFrame: err = s.handleMaxStreamIDFrame(frame) case *wire.DataBlockedFrame: - case *wire.StreamBlockedFrame: + case *wire.StreamDataBlockedFrame: case *wire.StreamIDBlockedFrame: case *wire.StopSendingFrame: err = s.handleStopSendingFrame(frame) diff --git a/session_test.go b/session_test.go index 56f47ffd..ddc3d827 100644 --- a/session_test.go +++ b/session_test.go @@ -311,7 +311,7 @@ var _ = Describe("Session", func() { }) It("handles STREAM_BLOCKED frames", func() { - err := sess.handleFrames([]wire.Frame{&wire.StreamBlockedFrame{}}, protocol.EncryptionUnspecified) + err := sess.handleFrames([]wire.Frame{&wire.StreamDataBlockedFrame{}}, protocol.EncryptionUnspecified) Expect(err).NotTo(HaveOccurred()) })