rename the RST_STREAM frame to RESET_STREAM frame

This commit is contained in:
Marten Seemann 2018-11-04 12:26:02 +07:00
parent 7087a16c7f
commit 022189dfda
17 changed files with 75 additions and 77 deletions

View file

@ -14,7 +14,7 @@ var _ = Describe("retransmittable frames", func() {
&wire.BlockedFrame{}: true,
&wire.ConnectionCloseFrame{}: true,
&wire.PingFrame{}: true,
&wire.RstStreamFrame{}: true,
&wire.ResetStreamFrame{}: true,
&wire.StreamFrame{}: true,
&wire.MaxDataFrame{}: true,
&wire.MaxStreamDataFrame{}: true,

View file

@ -19,7 +19,7 @@ type StreamFlowController interface {
flowController
// for receiving
// UpdateHighestReceived should be called when a new highest offset is received
// final has to be to true if this is the final offset of the stream, as contained in a STREAM frame with FIN bit, and the RST_STREAM frame
// final has to be to true if this is the final offset of the stream, as contained in a STREAM frame with FIN bit, and the RESET_STREAM frame
UpdateHighestReceived(offset protocol.ByteCount, final bool) error
}

View file

@ -36,7 +36,7 @@ func parseFrame(r *bytes.Reader, typeByte byte, v protocol.VersionNumber) (Frame
// TODO: implement all IETF QUIC frame types
switch typeByte {
case 0x1:
frame, err = parseRstStreamFrame(r, v)
frame, err = parseResetStreamFrame(r, v)
if err != nil {
err = qerr.Error(qerr.InvalidRstStreamData, err.Error())
}

View file

@ -38,8 +38,8 @@ var _ = Describe("Frame parsing", func() {
Expect(r.Len()).To(BeZero())
})
It("unpacks RST_STREAM frames", func() {
f := &RstStreamFrame{
It("unpacks RESET_STREAM frames", func() {
f := &ResetStreamFrame{
StreamID: 0xdeadbeef,
ByteOffset: 0xdecafbad1234,
ErrorCode: 0x1337,

View file

@ -31,18 +31,18 @@ var _ = Describe("Frame logging", func() {
It("doesn't log when debug is disabled", func() {
logger.SetLogLevel(utils.LogLevelInfo)
LogFrame(logger, &RstStreamFrame{}, true)
LogFrame(logger, &ResetStreamFrame{}, true)
Expect(buf.Len()).To(BeZero())
})
It("logs sent frames", func() {
LogFrame(logger, &RstStreamFrame{}, true)
Expect(buf.Bytes()).To(ContainSubstring("\t-> &wire.RstStreamFrame{StreamID:0x0, ErrorCode:0x0, ByteOffset:0x0}\n"))
LogFrame(logger, &ResetStreamFrame{}, true)
Expect(buf.Bytes()).To(ContainSubstring("\t-> &wire.ResetStreamFrame{StreamID:0x0, ErrorCode:0x0, ByteOffset:0x0}\n"))
})
It("logs received frames", func() {
LogFrame(logger, &RstStreamFrame{}, false)
Expect(buf.Bytes()).To(ContainSubstring("\t<- &wire.RstStreamFrame{StreamID:0x0, ErrorCode:0x0, ByteOffset:0x0}\n"))
LogFrame(logger, &ResetStreamFrame{}, false)
Expect(buf.Bytes()).To(ContainSubstring("\t<- &wire.ResetStreamFrame{StreamID:0x0, ErrorCode:0x0, ByteOffset:0x0}\n"))
})
It("logs CRYPTO frames", func() {

View file

@ -7,15 +7,14 @@ import (
"github.com/lucas-clemente/quic-go/internal/utils"
)
// A RstStreamFrame is a RST_STREAM frame in QUIC
type RstStreamFrame struct {
// A ResetStreamFrame is a RESET_STREAM frame in QUIC
type ResetStreamFrame struct {
StreamID protocol.StreamID
ErrorCode protocol.ApplicationErrorCode
ByteOffset protocol.ByteCount
}
// parseRstStreamFrame parses a RST_STREAM frame
func parseRstStreamFrame(r *bytes.Reader, version protocol.VersionNumber) (*RstStreamFrame, error) {
func parseResetStreamFrame(r *bytes.Reader, version protocol.VersionNumber) (*ResetStreamFrame, error) {
if _, err := r.ReadByte(); err != nil { // read the TypeByte
return nil, err
}
@ -38,15 +37,14 @@ func parseRstStreamFrame(r *bytes.Reader, version protocol.VersionNumber) (*RstS
}
byteOffset = protocol.ByteCount(bo)
return &RstStreamFrame{
return &ResetStreamFrame{
StreamID: streamID,
ErrorCode: protocol.ApplicationErrorCode(errorCode),
ByteOffset: byteOffset,
}, nil
}
//Write writes a RST_STREAM frame
func (f *RstStreamFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) error {
func (f *ResetStreamFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) error {
b.WriteByte(0x01)
utils.WriteVarInt(b, uint64(f.StreamID))
utils.BigEndian.WriteUint16(b, uint16(f.ErrorCode))
@ -55,6 +53,6 @@ func (f *RstStreamFrame) Write(b *bytes.Buffer, version protocol.VersionNumber)
}
// Length of a written frame
func (f *RstStreamFrame) Length(version protocol.VersionNumber) protocol.ByteCount {
func (f *ResetStreamFrame) Length(version protocol.VersionNumber) protocol.ByteCount {
return 1 + utils.VarIntLen(uint64(f.StreamID)) + 2 + utils.VarIntLen(uint64(f.ByteOffset))
}

View file

@ -9,7 +9,7 @@ import (
. "github.com/onsi/gomega"
)
var _ = Describe("RST_STREAM frame", func() {
var _ = Describe("RESET_STREAM frame", func() {
Context("when parsing", func() {
It("accepts sample frame", func() {
data := []byte{0x1}
@ -17,7 +17,7 @@ var _ = Describe("RST_STREAM frame", func() {
data = append(data, []byte{0x13, 0x37}...) // error code
data = append(data, encodeVarInt(0x987654321)...) // byte offset
b := bytes.NewReader(data)
frame, err := parseRstStreamFrame(b, versionIETFFrames)
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)))
@ -29,10 +29,10 @@ var _ = Describe("RST_STREAM frame", func() {
data = append(data, encodeVarInt(0xdeadbeef)...) // stream ID
data = append(data, []byte{0x13, 0x37}...) // error code
data = append(data, encodeVarInt(0x987654321)...) // byte offset
_, err := parseRstStreamFrame(bytes.NewReader(data), versionIETFFrames)
_, err := parseResetStreamFrame(bytes.NewReader(data), versionIETFFrames)
Expect(err).NotTo(HaveOccurred())
for i := range data {
_, err := parseRstStreamFrame(bytes.NewReader(data[0:i]), versionIETFFrames)
_, err := parseResetStreamFrame(bytes.NewReader(data[0:i]), versionIETFFrames)
Expect(err).To(HaveOccurred())
}
})
@ -40,7 +40,7 @@ var _ = Describe("RST_STREAM frame", func() {
Context("when writing", func() {
It("writes a sample frame", func() {
frame := RstStreamFrame{
frame := ResetStreamFrame{
StreamID: 0x1337,
ByteOffset: 0x11223344decafbad,
ErrorCode: 0xcafe,
@ -56,7 +56,7 @@ var _ = Describe("RST_STREAM frame", func() {
})
It("has the correct min length", func() {
rst := RstStreamFrame{
rst := ResetStreamFrame{
StreamID: 0x1337,
ByteOffset: 0x1234567,
ErrorCode: 0xde,

View file

@ -107,16 +107,16 @@ func (mr *MockReceiveStreamIMockRecorder) getWindowUpdate() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "getWindowUpdate", reflect.TypeOf((*MockReceiveStreamI)(nil).getWindowUpdate))
}
// handleRstStreamFrame mocks base method
func (m *MockReceiveStreamI) handleRstStreamFrame(arg0 *wire.RstStreamFrame) error {
ret := m.ctrl.Call(m, "handleRstStreamFrame", arg0)
// handleResetStreamFrame mocks base method
func (m *MockReceiveStreamI) handleResetStreamFrame(arg0 *wire.ResetStreamFrame) error {
ret := m.ctrl.Call(m, "handleResetStreamFrame", arg0)
ret0, _ := ret[0].(error)
return ret0
}
// handleRstStreamFrame indicates an expected call of handleRstStreamFrame
func (mr *MockReceiveStreamIMockRecorder) handleRstStreamFrame(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "handleRstStreamFrame", reflect.TypeOf((*MockReceiveStreamI)(nil).handleRstStreamFrame), arg0)
// handleResetStreamFrame indicates an expected call of handleResetStreamFrame
func (mr *MockReceiveStreamIMockRecorder) handleResetStreamFrame(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "handleResetStreamFrame", reflect.TypeOf((*MockReceiveStreamI)(nil).handleResetStreamFrame), arg0)
}
// handleStreamFrame mocks base method

View file

@ -191,16 +191,16 @@ func (mr *MockStreamIMockRecorder) handleMaxStreamDataFrame(arg0 interface{}) *g
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "handleMaxStreamDataFrame", reflect.TypeOf((*MockStreamI)(nil).handleMaxStreamDataFrame), arg0)
}
// handleRstStreamFrame mocks base method
func (m *MockStreamI) handleRstStreamFrame(arg0 *wire.RstStreamFrame) error {
ret := m.ctrl.Call(m, "handleRstStreamFrame", arg0)
// handleResetStreamFrame mocks base method
func (m *MockStreamI) handleResetStreamFrame(arg0 *wire.ResetStreamFrame) error {
ret := m.ctrl.Call(m, "handleResetStreamFrame", arg0)
ret0, _ := ret[0].(error)
return ret0
}
// handleRstStreamFrame indicates an expected call of handleRstStreamFrame
func (mr *MockStreamIMockRecorder) handleRstStreamFrame(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "handleRstStreamFrame", reflect.TypeOf((*MockStreamI)(nil).handleRstStreamFrame), arg0)
// handleResetStreamFrame indicates an expected call of handleResetStreamFrame
func (mr *MockStreamIMockRecorder) handleResetStreamFrame(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "handleResetStreamFrame", reflect.TypeOf((*MockStreamI)(nil).handleResetStreamFrame), arg0)
}
// handleStopSendingFrame mocks base method

View file

@ -243,7 +243,7 @@ var _ = Describe("Packet packer", func() {
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
ackFramer.EXPECT().GetAckFrame()
frames := []wire.Frame{&wire.RstStreamFrame{}, &wire.MaxDataFrame{}}
frames := []wire.Frame{&wire.ResetStreamFrame{}, &wire.MaxDataFrame{}}
expectAppendControlFrames(frames...)
expectAppendStreamFrames()
p, err := packer.PackPacket()

View file

@ -15,7 +15,7 @@ type receiveStreamI interface {
ReceiveStream
handleStreamFrame(*wire.StreamFrame) error
handleRstStreamFrame(*wire.RstStreamFrame) error
handleResetStreamFrame(*wire.ResetStreamFrame) error
closeForShutdown(error)
getWindowUpdate() protocol.ByteCount
}
@ -41,7 +41,7 @@ type receiveStream struct {
closedForShutdown bool // set when CloseForShutdown() is called
finRead bool // set once we read a frame with a FinBit
canceledRead bool // set when CancelRead() is called
resetRemotely bool // set when HandleRstStreamFrame() is called
resetRemotely bool // set when HandleResetStreamFrame() is called
readChan chan struct{}
deadline time.Time
@ -159,7 +159,7 @@ func (s *receiveStream) readImpl(p []byte) (bool /*stream completed */, int, err
s.readOffset += protocol.ByteCount(m)
s.mutex.Lock()
// when a RST_STREAM was received, the was already informed about the final byteOffset for this stream
// when a RESET_STREAM was received, the was already informed about the final byteOffset for this stream
if !s.resetRemotely {
s.flowController.AddBytesRead(protocol.ByteCount(m))
}
@ -214,15 +214,15 @@ func (s *receiveStream) handleStreamFrame(frame *wire.StreamFrame) error {
return nil
}
func (s *receiveStream) handleRstStreamFrame(frame *wire.RstStreamFrame) error {
completed, err := s.handleRstStreamFrameImpl(frame)
func (s *receiveStream) handleResetStreamFrame(frame *wire.ResetStreamFrame) error {
completed, err := s.handleResetStreamFrameImpl(frame)
if completed {
s.sender.onStreamCompleted(s.streamID)
}
return err
}
func (s *receiveStream) handleRstStreamFrameImpl(frame *wire.RstStreamFrame) (bool /*completed */, error) {
func (s *receiveStream) handleResetStreamFrameImpl(frame *wire.ResetStreamFrame) (bool /*completed */, error) {
s.mutex.Lock()
defer s.mutex.Unlock()
@ -233,7 +233,7 @@ func (s *receiveStream) handleRstStreamFrameImpl(frame *wire.RstStreamFrame) (bo
return false, err
}
// ignore duplicate RST_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 {
return false, nil
}
@ -273,7 +273,7 @@ func (s *receiveStream) SetReadDeadline(t time.Time) error {
// CloseForShutdown closes a stream abruptly.
// It makes Read unblock (and return the error) immediately.
// The peer will NOT be informed about this: the stream is closed without sending a FIN or RST.
// The peer will NOT be informed about this: the stream is closed without sending a FIN or RESET.
func (s *receiveStream) closeForShutdown(err error) {
s.mutex.Lock()
s.closedForShutdown = true

View file

@ -467,7 +467,7 @@ var _ = Describe("Receive Stream", func() {
Expect(err).To(MatchError("Read on stream 1337 canceled with error code 1234"))
})
It("doesn't send a RST_STREAM frame, if the FIN was already read", func() {
It("doesn't send a RESET_STREAM frame, if the FIN was already read", func() {
mockFC.EXPECT().UpdateHighestReceived(protocol.ByteCount(6), true)
mockFC.EXPECT().AddBytesRead(protocol.ByteCount(6))
mockFC.EXPECT().MaybeQueueWindowUpdate()
@ -495,8 +495,8 @@ var _ = Describe("Receive Stream", func() {
})
})
Context("receiving RST_STREAM frames", func() {
rst := &wire.RstStreamFrame{
Context("receiving RESET_STREAM frames", func() {
rst := &wire.ResetStreamFrame{
StreamID: streamID,
ByteOffset: 42,
ErrorCode: 1234,
@ -516,14 +516,14 @@ var _ = Describe("Receive Stream", func() {
}()
Consistently(done).ShouldNot(BeClosed())
mockSender.EXPECT().onStreamCompleted(streamID)
str.handleRstStreamFrame(rst)
str.handleResetStreamFrame(rst)
Eventually(done).Should(BeClosed())
})
It("doesn't allow further calls to Read", func() {
mockSender.EXPECT().onStreamCompleted(streamID)
mockFC.EXPECT().UpdateHighestReceived(protocol.ByteCount(42), true)
err := str.handleRstStreamFrame(rst)
err := str.handleResetStreamFrame(rst)
Expect(err).ToNot(HaveOccurred())
_, err = strWithTimeout.Read([]byte{0})
Expect(err).To(MatchError("Stream 1337 was reset with error code 1234"))
@ -532,25 +532,25 @@ var _ = Describe("Receive Stream", func() {
Expect(err.(streamCanceledError).ErrorCode()).To(Equal(protocol.ApplicationErrorCode(1234)))
})
It("errors when receiving a RST_STREAM with an inconsistent offset", func() {
It("errors when receiving a RESET_STREAM with an inconsistent offset", func() {
testErr := errors.New("already received a different final offset before")
mockFC.EXPECT().UpdateHighestReceived(protocol.ByteCount(42), true).Return(testErr)
err := str.handleRstStreamFrame(rst)
err := str.handleResetStreamFrame(rst)
Expect(err).To(MatchError(testErr))
})
It("ignores duplicate RST_STREAM frames", func() {
It("ignores duplicate RESET_STREAM frames", func() {
mockSender.EXPECT().onStreamCompleted(streamID)
mockFC.EXPECT().UpdateHighestReceived(protocol.ByteCount(42), true).Times(2)
err := str.handleRstStreamFrame(rst)
err := str.handleResetStreamFrame(rst)
Expect(err).ToNot(HaveOccurred())
err = str.handleRstStreamFrame(rst)
err = str.handleResetStreamFrame(rst)
Expect(err).ToNot(HaveOccurred())
})
It("doesn't do anyting when it was closed for shutdown", func() {
str.closeForShutdown(nil)
err := str.handleRstStreamFrame(rst)
err := str.handleResetStreamFrame(rst)
Expect(err).ToNot(HaveOccurred())
})
})

View file

@ -249,7 +249,7 @@ func (s *sendStream) cancelWriteImpl(errorCode protocol.ApplicationErrorCode, wr
s.canceledWrite = true
s.cancelWriteErr = writeErr
s.signalWrite()
s.sender.queueControlFrame(&wire.RstStreamFrame{
s.sender.queueControlFrame(&wire.ResetStreamFrame{
StreamID: s.streamID,
ByteOffset: s.writeOffset,
ErrorCode: errorCode,

View file

@ -490,8 +490,8 @@ var _ = Describe("Send Stream", func() {
Context("stream cancelations", func() {
Context("canceling writing", func() {
It("queues a RST_STREAM frame", func() {
mockSender.EXPECT().queueControlFrame(&wire.RstStreamFrame{
It("queues a RESET_STREAM frame", func() {
mockSender.EXPECT().queueControlFrame(&wire.ResetStreamFrame{
StreamID: streamID,
ByteOffset: 1234,
ErrorCode: 9876,
@ -562,8 +562,8 @@ var _ = Describe("Send Stream", func() {
})
Context("receiving STOP_SENDING frames", func() {
It("queues a RST_STREAM frames with error code Stopping", func() {
mockSender.EXPECT().queueControlFrame(&wire.RstStreamFrame{
It("queues a RESET_STREAM frames with error code Stopping", func() {
mockSender.EXPECT().queueControlFrame(&wire.ResetStreamFrame{
StreamID: streamID,
ErrorCode: errorCodeStopping,
})

View file

@ -543,8 +543,8 @@ func (s *session) handleFrames(fs []wire.Frame, encLevel protocol.EncryptionLeve
err = s.handleAckFrame(frame, encLevel)
case *wire.ConnectionCloseFrame:
s.closeRemote(qerr.Error(frame.ErrorCode, frame.ReasonPhrase))
case *wire.RstStreamFrame:
err = s.handleRstStreamFrame(frame)
case *wire.ResetStreamFrame:
err = s.handleResetStreamFrame(frame)
case *wire.MaxDataFrame:
s.handleMaxDataFrame(frame)
case *wire.MaxStreamDataFrame:
@ -631,7 +631,7 @@ func (s *session) handleMaxStreamIDFrame(frame *wire.MaxStreamIDFrame) error {
return s.streamsMap.HandleMaxStreamIDFrame(frame)
}
func (s *session) handleRstStreamFrame(frame *wire.RstStreamFrame) error {
func (s *session) handleResetStreamFrame(frame *wire.ResetStreamFrame) error {
str, err := s.streamsMap.GetOrOpenReceiveStream(frame.StreamID)
if err != nil {
return err
@ -640,7 +640,7 @@ func (s *session) handleRstStreamFrame(frame *wire.RstStreamFrame) error {
// stream is closed and already garbage collected
return nil
}
return str.handleRstStreamFrame(frame)
return str.handleResetStreamFrame(frame)
}
func (s *session) handleStopSendingFrame(frame *wire.StopSendingFrame) error {

View file

@ -174,36 +174,36 @@ var _ = Describe("Session", func() {
})
})
Context("handling RST_STREAM frames", func() {
Context("handling RESET_STREAM frames", func() {
It("closes the streams for writing", func() {
f := &wire.RstStreamFrame{
f := &wire.ResetStreamFrame{
StreamID: 555,
ErrorCode: 42,
ByteOffset: 0x1337,
}
str := NewMockReceiveStreamI(mockCtrl)
streamManager.EXPECT().GetOrOpenReceiveStream(protocol.StreamID(555)).Return(str, nil)
str.EXPECT().handleRstStreamFrame(f)
err := sess.handleRstStreamFrame(f)
str.EXPECT().handleResetStreamFrame(f)
err := sess.handleResetStreamFrame(f)
Expect(err).ToNot(HaveOccurred())
})
It("returns errors", func() {
f := &wire.RstStreamFrame{
f := &wire.ResetStreamFrame{
StreamID: 7,
ByteOffset: 0x1337,
}
testErr := errors.New("flow control violation")
str := NewMockReceiveStreamI(mockCtrl)
streamManager.EXPECT().GetOrOpenReceiveStream(protocol.StreamID(7)).Return(str, nil)
str.EXPECT().handleRstStreamFrame(f).Return(testErr)
err := sess.handleRstStreamFrame(f)
str.EXPECT().handleResetStreamFrame(f).Return(testErr)
err := sess.handleResetStreamFrame(f)
Expect(err).To(MatchError(testErr))
})
It("ignores RST_STREAM frames for closed streams", func() {
It("ignores RESET_STREAM frames for closed streams", func() {
streamManager.EXPECT().GetOrOpenReceiveStream(protocol.StreamID(3)).Return(nil, nil)
err := sess.handleFrames([]wire.Frame{&wire.RstStreamFrame{
err := sess.handleFrames([]wire.Frame{&wire.ResetStreamFrame{
StreamID: 3,
ErrorCode: 42,
}}, protocol.EncryptionUnspecified)

View file

@ -46,7 +46,7 @@ type streamI interface {
closeForShutdown(error)
// for receiving
handleStreamFrame(*wire.StreamFrame) error
handleRstStreamFrame(*wire.RstStreamFrame) error
handleResetStreamFrame(*wire.ResetStreamFrame) error
getWindowUpdate() protocol.ByteCount
// for sending
hasData() bool
@ -150,8 +150,8 @@ func (s *stream) closeForShutdown(err error) {
s.receiveStream.closeForShutdown(err)
}
func (s *stream) handleRstStreamFrame(frame *wire.RstStreamFrame) error {
return s.receiveStream.handleRstStreamFrame(frame)
func (s *stream) handleResetStreamFrame(frame *wire.ResetStreamFrame) error {
return s.receiveStream.handleResetStreamFrame(frame)
}
// checkIfCompleted is called from the uniStreamSender, when one of the stream halves is completed.