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.ResetStreamFrame{
StreamID: protocol.StreamID(getRandomNumber()),
ErrorCode: quic.ErrorCode(getRandomNumber()),
ByteOffset: protocol.ByteCount(getRandomNumber()),
StreamID: protocol.StreamID(getRandomNumber()),
ErrorCode: quic.ErrorCode(getRandomNumber()),
FinalSize: protocol.ByteCount(getRandomNumber()),
},
&wire.ResetStreamFrame{ // at maximum offset
StreamID: protocol.StreamID(getRandomNumber()),
ErrorCode: quic.ErrorCode(getRandomNumber()),
ByteOffset: protocol.MaxByteCount,
StreamID: protocol.StreamID(getRandomNumber()),
ErrorCode: quic.ErrorCode(getRandomNumber()),
FinalSize: protocol.MaxByteCount,
},
&wire.StopSendingFrame{
StreamID: protocol.StreamID(getRandomNumber()),

View file

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

View file

@ -24,7 +24,7 @@ func LogFrame(logger utils.Logger, frame Frame, sent bool) {
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())
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:
if len(f.AckRanges) > 1 {
ackRanges := make([]string, len(f.AckRanges))

View file

@ -38,12 +38,12 @@ var _ = Describe("Frame logging", func() {
It("logs sent frames", func() {
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() {
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() {

View file

@ -9,9 +9,9 @@ import (
// A ResetStreamFrame is a RESET_STREAM frame in QUIC
type ResetStreamFrame struct {
StreamID protocol.StreamID
ErrorCode protocol.ApplicationErrorCode
ByteOffset protocol.ByteCount
StreamID protocol.StreamID
ErrorCode protocol.ApplicationErrorCode
FinalSize protocol.ByteCount
}
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)
return &ResetStreamFrame{
StreamID: streamID,
ErrorCode: protocol.ApplicationErrorCode(errorCode),
ByteOffset: byteOffset,
StreamID: streamID,
ErrorCode: protocol.ApplicationErrorCode(errorCode),
FinalSize: byteOffset,
}, nil
}
@ -47,11 +47,11 @@ func (f *ResetStreamFrame) Write(b *bytes.Buffer, _ protocol.VersionNumber) erro
b.WriteByte(0x4)
utils.WriteVarInt(b, uint64(f.StreamID))
utils.WriteVarInt(b, uint64(f.ErrorCode))
utils.WriteVarInt(b, uint64(f.ByteOffset))
utils.WriteVarInt(b, uint64(f.FinalSize))
return nil
}
// Length of a written frame
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)
Expect(err).ToNot(HaveOccurred())
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)))
})
@ -41,9 +41,9 @@ var _ = Describe("RESET_STREAM frame", func() {
Context("when writing", func() {
It("writes a sample frame", func() {
frame := ResetStreamFrame{
StreamID: 0x1337,
ByteOffset: 0x11223344decafbad,
ErrorCode: 0xcafe,
StreamID: 0x1337,
FinalSize: 0x11223344decafbad,
ErrorCode: 0xcafe,
}
b := &bytes.Buffer{}
err := frame.Write(b, versionIETFFrames)
@ -57,9 +57,9 @@ var _ = Describe("RESET_STREAM frame", func() {
It("has the correct min length", func() {
rst := ResetStreamFrame{
StreamID: 0x1337,
ByteOffset: 0x1234567,
ErrorCode: 0xde,
StreamID: 0x1337,
FinalSize: 0x1234567,
ErrorCode: 0xde,
}
expectedLen := 1 + utils.VarIntLen(0x1337) + utils.VarIntLen(0x1234567) + 2
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.Int64Key("stream_id", int64(f.StreamID))
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) {

View file

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

View file

@ -268,11 +268,11 @@ func (s *receiveStream) handleResetStreamFrameImpl(frame *wire.ResetStreamFrame)
if s.closedForShutdown {
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
}
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)
if s.resetRemotely {

View file

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

View file

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

View file

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