rename the STREAM_BLOCKED frame to STREAM_DATA_BLOCKED

This commit is contained in:
Marten Seemann 2018-10-31 09:16:23 +07:00
parent 387613aa20
commit 05ecf9bc02
9 changed files with 74 additions and 74 deletions

View file

@ -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())
}

View file

@ -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)

View file

@ -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))
}

View file

@ -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))
}

View file

@ -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))
})
})

View file

@ -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
}

View file

@ -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())

View file

@ -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)

View file

@ -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())
})