rename ResetStreamFrame.ByteOffset to FinalSize

This commit is contained in:
Marten Seemann 2020-07-02 16:20:44 +07:00
parent cc340b2887
commit 865332015c
13 changed files with 50 additions and 50 deletions

View file

@ -119,14 +119,14 @@ func getFrames() []wire.Frame {
}, },
&wire.PingFrame{}, &wire.PingFrame{},
&wire.ResetStreamFrame{ &wire.ResetStreamFrame{
StreamID: protocol.StreamID(getRandomNumber()), StreamID: protocol.StreamID(getRandomNumber()),
ErrorCode: quic.ErrorCode(getRandomNumber()), ErrorCode: quic.ErrorCode(getRandomNumber()),
ByteOffset: protocol.ByteCount(getRandomNumber()), FinalSize: protocol.ByteCount(getRandomNumber()),
}, },
&wire.ResetStreamFrame{ // at maximum offset &wire.ResetStreamFrame{ // at maximum offset
StreamID: protocol.StreamID(getRandomNumber()), StreamID: protocol.StreamID(getRandomNumber()),
ErrorCode: quic.ErrorCode(getRandomNumber()), ErrorCode: quic.ErrorCode(getRandomNumber()),
ByteOffset: protocol.MaxByteCount, FinalSize: protocol.MaxByteCount,
}, },
&wire.StopSendingFrame{ &wire.StopSendingFrame{
StreamID: protocol.StreamID(getRandomNumber()), StreamID: protocol.StreamID(getRandomNumber()),

View file

@ -82,9 +82,9 @@ var _ = Describe("Frame parsing", func() {
It("unpacks RESET_STREAM frames", func() { It("unpacks RESET_STREAM frames", func() {
f := &ResetStreamFrame{ f := &ResetStreamFrame{
StreamID: 0xdeadbeef, StreamID: 0xdeadbeef,
ByteOffset: 0xdecafbad1234, FinalSize: 0xdecafbad1234,
ErrorCode: 0x1337, ErrorCode: 0x1337,
} }
err := f.Write(buf, versionIETFFrames) err := f.Write(buf, versionIETFFrames)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())

View file

@ -24,7 +24,7 @@ func LogFrame(logger utils.Logger, frame Frame, sent bool) {
case *StreamFrame: case *StreamFrame:
logger.Debugf("\t%s &wire.StreamFrame{StreamID: %d, FinBit: %t, Offset: %d, Data length: %d, Offset + Data length: %d}", dir, f.StreamID, f.FinBit, f.Offset, f.DataLen(), f.Offset+f.DataLen()) logger.Debugf("\t%s &wire.StreamFrame{StreamID: %d, FinBit: %t, Offset: %d, Data length: %d, Offset + Data length: %d}", dir, f.StreamID, f.FinBit, f.Offset, f.DataLen(), f.Offset+f.DataLen())
case *ResetStreamFrame: case *ResetStreamFrame:
logger.Debugf("\t%s &wire.ResetStreamFrame{StreamID: %d, ErrorCode: %#x, ByteOffset: %d}", dir, f.StreamID, f.ErrorCode, f.ByteOffset) logger.Debugf("\t%s &wire.ResetStreamFrame{StreamID: %d, ErrorCode: %#x, FinalSize: %d}", dir, f.StreamID, f.ErrorCode, f.FinalSize)
case *AckFrame: case *AckFrame:
if len(f.AckRanges) > 1 { if len(f.AckRanges) > 1 {
ackRanges := make([]string, len(f.AckRanges)) ackRanges := make([]string, len(f.AckRanges))

View file

@ -38,12 +38,12 @@ var _ = Describe("Frame logging", func() {
It("logs sent frames", func() { It("logs sent frames", func() {
LogFrame(logger, &ResetStreamFrame{}, true) LogFrame(logger, &ResetStreamFrame{}, true)
Expect(buf.String()).To(ContainSubstring("\t-> &wire.ResetStreamFrame{StreamID: 0, ErrorCode: 0x0, ByteOffset: 0}\n")) Expect(buf.String()).To(ContainSubstring("\t-> &wire.ResetStreamFrame{StreamID: 0, ErrorCode: 0x0, FinalSize: 0}\n"))
}) })
It("logs received frames", func() { It("logs received frames", func() {
LogFrame(logger, &ResetStreamFrame{}, false) LogFrame(logger, &ResetStreamFrame{}, false)
Expect(buf.String()).To(ContainSubstring("\t<- &wire.ResetStreamFrame{StreamID: 0, ErrorCode: 0x0, ByteOffset: 0}\n")) Expect(buf.String()).To(ContainSubstring("\t<- &wire.ResetStreamFrame{StreamID: 0, ErrorCode: 0x0, FinalSize: 0}\n"))
}) })
It("logs CRYPTO frames", func() { It("logs CRYPTO frames", func() {

View file

@ -9,9 +9,9 @@ import (
// A ResetStreamFrame is a RESET_STREAM frame in QUIC // A ResetStreamFrame is a RESET_STREAM frame in QUIC
type ResetStreamFrame struct { type ResetStreamFrame struct {
StreamID protocol.StreamID StreamID protocol.StreamID
ErrorCode protocol.ApplicationErrorCode ErrorCode protocol.ApplicationErrorCode
ByteOffset protocol.ByteCount FinalSize protocol.ByteCount
} }
func parseResetStreamFrame(r *bytes.Reader, _ protocol.VersionNumber) (*ResetStreamFrame, error) { func parseResetStreamFrame(r *bytes.Reader, _ protocol.VersionNumber) (*ResetStreamFrame, error) {
@ -37,9 +37,9 @@ func parseResetStreamFrame(r *bytes.Reader, _ protocol.VersionNumber) (*ResetStr
byteOffset = protocol.ByteCount(bo) byteOffset = protocol.ByteCount(bo)
return &ResetStreamFrame{ return &ResetStreamFrame{
StreamID: streamID, StreamID: streamID,
ErrorCode: protocol.ApplicationErrorCode(errorCode), ErrorCode: protocol.ApplicationErrorCode(errorCode),
ByteOffset: byteOffset, FinalSize: byteOffset,
}, nil }, nil
} }
@ -47,11 +47,11 @@ func (f *ResetStreamFrame) Write(b *bytes.Buffer, _ protocol.VersionNumber) erro
b.WriteByte(0x4) b.WriteByte(0x4)
utils.WriteVarInt(b, uint64(f.StreamID)) utils.WriteVarInt(b, uint64(f.StreamID))
utils.WriteVarInt(b, uint64(f.ErrorCode)) utils.WriteVarInt(b, uint64(f.ErrorCode))
utils.WriteVarInt(b, uint64(f.ByteOffset)) utils.WriteVarInt(b, uint64(f.FinalSize))
return nil return nil
} }
// Length of a written frame // Length of a written frame
func (f *ResetStreamFrame) Length(version protocol.VersionNumber) protocol.ByteCount { func (f *ResetStreamFrame) Length(version protocol.VersionNumber) protocol.ByteCount {
return 1 + utils.VarIntLen(uint64(f.StreamID)) + utils.VarIntLen(uint64(f.ErrorCode)) + utils.VarIntLen(uint64(f.ByteOffset)) return 1 + utils.VarIntLen(uint64(f.StreamID)) + utils.VarIntLen(uint64(f.ErrorCode)) + utils.VarIntLen(uint64(f.FinalSize))
} }

View file

@ -20,7 +20,7 @@ var _ = Describe("RESET_STREAM frame", func() {
frame, err := parseResetStreamFrame(b, versionIETFFrames) frame, err := parseResetStreamFrame(b, versionIETFFrames)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(frame.StreamID).To(Equal(protocol.StreamID(0xdeadbeef))) Expect(frame.StreamID).To(Equal(protocol.StreamID(0xdeadbeef)))
Expect(frame.ByteOffset).To(Equal(protocol.ByteCount(0x987654321))) Expect(frame.FinalSize).To(Equal(protocol.ByteCount(0x987654321)))
Expect(frame.ErrorCode).To(Equal(protocol.ApplicationErrorCode(0x1337))) Expect(frame.ErrorCode).To(Equal(protocol.ApplicationErrorCode(0x1337)))
}) })
@ -41,9 +41,9 @@ var _ = Describe("RESET_STREAM frame", func() {
Context("when writing", func() { Context("when writing", func() {
It("writes a sample frame", func() { It("writes a sample frame", func() {
frame := ResetStreamFrame{ frame := ResetStreamFrame{
StreamID: 0x1337, StreamID: 0x1337,
ByteOffset: 0x11223344decafbad, FinalSize: 0x11223344decafbad,
ErrorCode: 0xcafe, ErrorCode: 0xcafe,
} }
b := &bytes.Buffer{} b := &bytes.Buffer{}
err := frame.Write(b, versionIETFFrames) err := frame.Write(b, versionIETFFrames)
@ -57,9 +57,9 @@ var _ = Describe("RESET_STREAM frame", func() {
It("has the correct min length", func() { It("has the correct min length", func() {
rst := ResetStreamFrame{ rst := ResetStreamFrame{
StreamID: 0x1337, StreamID: 0x1337,
ByteOffset: 0x1234567, FinalSize: 0x1234567,
ErrorCode: 0xde, ErrorCode: 0xde,
} }
expectedLen := 1 + utils.VarIntLen(0x1337) + utils.VarIntLen(0x1234567) + 2 expectedLen := 1 + utils.VarIntLen(0x1337) + utils.VarIntLen(0x1234567) + 2
Expect(rst.Length(versionIETFFrames)).To(Equal(expectedLen)) Expect(rst.Length(versionIETFFrames)).To(Equal(expectedLen))

View file

@ -142,7 +142,7 @@ func marshalResetStreamFrame(enc *gojay.Encoder, f *wire.ResetStreamFrame) {
enc.StringKey("frame_type", "reset_stream") enc.StringKey("frame_type", "reset_stream")
enc.Int64Key("stream_id", int64(f.StreamID)) enc.Int64Key("stream_id", int64(f.StreamID))
enc.Int64Key("error_code", int64(f.ErrorCode)) enc.Int64Key("error_code", int64(f.ErrorCode))
enc.Int64Key("final_size", int64(f.ByteOffset)) enc.Int64Key("final_size", int64(f.FinalSize))
} }
func marshalStopSendingFrame(enc *gojay.Encoder, f *wire.StopSendingFrame) { func marshalStopSendingFrame(enc *gojay.Encoder, f *wire.StopSendingFrame) {

View file

@ -84,9 +84,9 @@ var _ = Describe("Frames", func() {
It("marshals RESET_STREAM frames", func() { It("marshals RESET_STREAM frames", func() {
check( check(
&wire.ResetStreamFrame{ &wire.ResetStreamFrame{
StreamID: 987, StreamID: 987,
ByteOffset: 1234, FinalSize: 1234,
ErrorCode: 42, ErrorCode: 42,
}, },
map[string]interface{}{ map[string]interface{}{
"frame_type": "reset_stream", "frame_type": "reset_stream",

View file

@ -268,11 +268,11 @@ func (s *receiveStream) handleResetStreamFrameImpl(frame *wire.ResetStreamFrame)
if s.closedForShutdown { if s.closedForShutdown {
return false, nil return false, nil
} }
if err := s.flowController.UpdateHighestReceived(frame.ByteOffset, true); err != nil { if err := s.flowController.UpdateHighestReceived(frame.FinalSize, true); err != nil {
return false, err return false, err
} }
newlyRcvdFinalOffset := s.finalOffset == protocol.MaxByteCount newlyRcvdFinalOffset := s.finalOffset == protocol.MaxByteCount
s.finalOffset = frame.ByteOffset s.finalOffset = frame.FinalSize
// ignore duplicate RESET_STREAM frames for this stream (after checking their final offset) // ignore duplicate RESET_STREAM frames for this stream (after checking their final offset)
if s.resetRemotely { if s.resetRemotely {

View file

@ -507,8 +507,8 @@ var _ = Describe("Receive Stream", func() {
) )
mockSender.EXPECT().onStreamCompleted(streamID) mockSender.EXPECT().onStreamCompleted(streamID)
Expect(str.handleResetStreamFrame(&wire.ResetStreamFrame{ Expect(str.handleResetStreamFrame(&wire.ResetStreamFrame{
StreamID: streamID, StreamID: streamID,
ByteOffset: 42, FinalSize: 42,
})).To(Succeed()) })).To(Succeed())
str.CancelRead(1234) str.CancelRead(1234)
}) })
@ -561,9 +561,9 @@ var _ = Describe("Receive Stream", func() {
Context("receiving RESET_STREAM frames", func() { Context("receiving RESET_STREAM frames", func() {
rst := &wire.ResetStreamFrame{ rst := &wire.ResetStreamFrame{
StreamID: streamID, StreamID: streamID,
ByteOffset: 42, FinalSize: 42,
ErrorCode: 1234, ErrorCode: 1234,
} }
It("unblocks Read", func() { It("unblocks Read", func() {
@ -624,7 +624,7 @@ var _ = Describe("Receive Stream", func() {
mockFC.EXPECT().UpdateHighestReceived(protocol.ByteCount(42), true).Times(2) mockFC.EXPECT().UpdateHighestReceived(protocol.ByteCount(42), true).Times(2)
Expect(str.handleStreamFrame(&wire.StreamFrame{ Expect(str.handleStreamFrame(&wire.StreamFrame{
StreamID: streamID, StreamID: streamID,
Offset: rst.ByteOffset, Offset: rst.FinalSize,
FinBit: true, FinBit: true,
})).To(Succeed()) })).To(Succeed())
Expect(str.handleResetStreamFrame(rst)).To(Succeed()) Expect(str.handleResetStreamFrame(rst)).To(Succeed())

View file

@ -416,9 +416,9 @@ func (s *sendStream) cancelWriteImpl(errorCode protocol.ApplicationErrorCode, wr
s.signalWrite() s.signalWrite()
s.sender.queueControlFrame(&wire.ResetStreamFrame{ s.sender.queueControlFrame(&wire.ResetStreamFrame{
StreamID: s.streamID, StreamID: s.streamID,
ByteOffset: s.writeOffset, FinalSize: s.writeOffset,
ErrorCode: errorCode, ErrorCode: errorCode,
}) })
if newlyCompleted { if newlyCompleted {
s.sender.onStreamCompleted(s.streamID) s.sender.onStreamCompleted(s.streamID)

View file

@ -685,9 +685,9 @@ var _ = Describe("Send Stream", func() {
It("queues a RESET_STREAM frame", func() { It("queues a RESET_STREAM frame", func() {
gomock.InOrder( gomock.InOrder(
mockSender.EXPECT().queueControlFrame(&wire.ResetStreamFrame{ mockSender.EXPECT().queueControlFrame(&wire.ResetStreamFrame{
StreamID: streamID, StreamID: streamID,
ByteOffset: 1234, FinalSize: 1234,
ErrorCode: 9876, ErrorCode: 9876,
}), }),
mockSender.EXPECT().onStreamCompleted(streamID), mockSender.EXPECT().onStreamCompleted(streamID),
) )

View file

@ -169,9 +169,9 @@ var _ = Describe("Session", func() {
Context("handling RESET_STREAM frames", func() { Context("handling RESET_STREAM frames", func() {
It("closes the streams for writing", func() { It("closes the streams for writing", func() {
f := &wire.ResetStreamFrame{ f := &wire.ResetStreamFrame{
StreamID: 555, StreamID: 555,
ErrorCode: 42, ErrorCode: 42,
ByteOffset: 0x1337, FinalSize: 0x1337,
} }
str := NewMockReceiveStreamI(mockCtrl) str := NewMockReceiveStreamI(mockCtrl)
streamManager.EXPECT().GetOrOpenReceiveStream(protocol.StreamID(555)).Return(str, nil) streamManager.EXPECT().GetOrOpenReceiveStream(protocol.StreamID(555)).Return(str, nil)
@ -182,8 +182,8 @@ var _ = Describe("Session", func() {
It("returns errors", func() { It("returns errors", func() {
f := &wire.ResetStreamFrame{ f := &wire.ResetStreamFrame{
StreamID: 7, StreamID: 7,
ByteOffset: 0x1337, FinalSize: 0x1337,
} }
testErr := errors.New("flow control violation") testErr := errors.New("flow control violation")
str := NewMockReceiveStreamI(mockCtrl) str := NewMockReceiveStreamI(mockCtrl)