mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
generate the streamI mock in the quic package
By doing so, we can mock private methods of the stream, so they cannot be type-asserted by users of quic-go.
This commit is contained in:
parent
54ac21fbef
commit
d2e31c04ab
19 changed files with 301 additions and 301 deletions
|
@ -11,14 +11,14 @@ import (
|
|||
type cryptoStreamI interface {
|
||||
io.Reader
|
||||
io.Writer
|
||||
HandleStreamFrame(*wire.StreamFrame) error
|
||||
PopStreamFrame(protocol.ByteCount) *wire.StreamFrame
|
||||
CloseForShutdown(error)
|
||||
HasDataForWriting() bool
|
||||
SetReadOffset(protocol.ByteCount)
|
||||
handleStreamFrame(*wire.StreamFrame) error
|
||||
popStreamFrame(protocol.ByteCount) *wire.StreamFrame
|
||||
closeForShutdown(error)
|
||||
hasDataForWriting() bool
|
||||
setReadOffset(protocol.ByteCount)
|
||||
// methods needed for flow control
|
||||
GetWindowUpdate() protocol.ByteCount
|
||||
HandleMaxStreamDataFrame(*wire.MaxStreamDataFrame)
|
||||
getWindowUpdate() protocol.ByteCount
|
||||
handleMaxStreamDataFrame(*wire.MaxStreamDataFrame)
|
||||
}
|
||||
|
||||
type cryptoStream struct {
|
||||
|
@ -35,12 +35,12 @@ func newCryptoStream(onData func(), flowController flowcontrol.StreamFlowControl
|
|||
// SetReadOffset sets the read offset.
|
||||
// It is only needed for the crypto stream.
|
||||
// It must not be called concurrently with any other stream methods, especially Read and Write.
|
||||
func (s *cryptoStream) SetReadOffset(offset protocol.ByteCount) {
|
||||
func (s *cryptoStream) setReadOffset(offset protocol.ByteCount) {
|
||||
s.receiveStream.readOffset = offset
|
||||
s.receiveStream.frameQueue.readPosition = offset
|
||||
}
|
||||
|
||||
func (s *cryptoStream) HasDataForWriting() bool {
|
||||
func (s *cryptoStream) hasDataForWriting() bool {
|
||||
s.sendStream.mutex.Lock()
|
||||
hasData := s.sendStream.dataForWriting != nil
|
||||
s.sendStream.mutex.Unlock()
|
||||
|
|
|
@ -13,13 +13,13 @@ var _ = Describe("Stream", func() {
|
|||
str = newCryptoStream(func() {}, nil, protocol.VersionWhatever).(*cryptoStream)
|
||||
|
||||
It("sets the read offset", func() {
|
||||
str.SetReadOffset(0x42)
|
||||
str.setReadOffset(0x42)
|
||||
Expect(str.receiveStream.readOffset).To(Equal(protocol.ByteCount(0x42)))
|
||||
Expect(str.receiveStream.frameQueue.readPosition).To(Equal(protocol.ByteCount(0x42)))
|
||||
})
|
||||
|
||||
It("says if it has data for writing", func() {
|
||||
Expect(str.HasDataForWriting()).To(BeFalse())
|
||||
Expect(str.hasDataForWriting()).To(BeFalse())
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer GinkgoRecover()
|
||||
|
@ -27,6 +27,6 @@ var _ = Describe("Stream", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
close(done)
|
||||
}()
|
||||
Eventually(str.HasDataForWriting).Should(BeTrue())
|
||||
Eventually(str.hasDataForWriting).Should(BeTrue())
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Mockgen refuses to generate mocks for internal packages.
|
||||
# This script copies the internal directory and renames it to internalpackage.
|
||||
# That way, mockgen can generate the mock.
|
||||
# Afterwards, it corrects the import paths (replaces internalpackage back to internal).
|
||||
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
mkdir -p $TEMP_DIR/src/github.com/lucas-clemente/quic-go/
|
||||
|
||||
cp -r $GOPATH/src/github.com/lucas-clemente/quic-go/ $TEMP_DIR/src/github.com/lucas-clemente/quic-go/
|
||||
echo "type StreamI = streamI" >> $TEMP_DIR/src/github.com/lucas-clemente/quic-go/stream.go
|
||||
|
||||
export GOPATH="$TEMP_DIR:$GOPATH"
|
||||
|
||||
mockgen -package $1 -self_package $1 -destination $2 $3 $4
|
||||
|
||||
rm -r "$TEMP_DIR"
|
|
@ -1,16 +1,15 @@
|
|||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: github.com/lucas-clemente/quic-go (interfaces: StreamI)
|
||||
|
||||
package mocks
|
||||
package quic
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
time "time"
|
||||
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
protocol "github.com/lucas-clemente/quic-go/internal/protocol"
|
||||
wire "github.com/lucas-clemente/quic-go/internal/wire"
|
||||
reflect "reflect"
|
||||
time "time"
|
||||
)
|
||||
|
||||
// MockStreamI is a mock of StreamI interface
|
||||
|
@ -72,16 +71,6 @@ func (_mr *MockStreamIMockRecorder) Close() *gomock.Call {
|
|||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "Close", reflect.TypeOf((*MockStreamI)(nil).Close))
|
||||
}
|
||||
|
||||
// CloseForShutdown mocks base method
|
||||
func (_m *MockStreamI) CloseForShutdown(_param0 error) {
|
||||
_m.ctrl.Call(_m, "CloseForShutdown", _param0)
|
||||
}
|
||||
|
||||
// CloseForShutdown indicates an expected call of CloseForShutdown
|
||||
func (_mr *MockStreamIMockRecorder) CloseForShutdown(arg0 interface{}) *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "CloseForShutdown", reflect.TypeOf((*MockStreamI)(nil).CloseForShutdown), arg0)
|
||||
}
|
||||
|
||||
// Context mocks base method
|
||||
func (_m *MockStreamI) Context() context.Context {
|
||||
ret := _m.ctrl.Call(_m, "Context")
|
||||
|
@ -94,86 +83,6 @@ func (_mr *MockStreamIMockRecorder) Context() *gomock.Call {
|
|||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "Context", reflect.TypeOf((*MockStreamI)(nil).Context))
|
||||
}
|
||||
|
||||
// Finished mocks base method
|
||||
func (_m *MockStreamI) Finished() bool {
|
||||
ret := _m.ctrl.Call(_m, "Finished")
|
||||
ret0, _ := ret[0].(bool)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Finished indicates an expected call of Finished
|
||||
func (_mr *MockStreamIMockRecorder) Finished() *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "Finished", reflect.TypeOf((*MockStreamI)(nil).Finished))
|
||||
}
|
||||
|
||||
// GetWindowUpdate mocks base method
|
||||
func (_m *MockStreamI) GetWindowUpdate() protocol.ByteCount {
|
||||
ret := _m.ctrl.Call(_m, "GetWindowUpdate")
|
||||
ret0, _ := ret[0].(protocol.ByteCount)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetWindowUpdate indicates an expected call of GetWindowUpdate
|
||||
func (_mr *MockStreamIMockRecorder) GetWindowUpdate() *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "GetWindowUpdate", reflect.TypeOf((*MockStreamI)(nil).GetWindowUpdate))
|
||||
}
|
||||
|
||||
// HandleMaxStreamDataFrame mocks base method
|
||||
func (_m *MockStreamI) HandleMaxStreamDataFrame(_param0 *wire.MaxStreamDataFrame) {
|
||||
_m.ctrl.Call(_m, "HandleMaxStreamDataFrame", _param0)
|
||||
}
|
||||
|
||||
// HandleMaxStreamDataFrame indicates an expected call of HandleMaxStreamDataFrame
|
||||
func (_mr *MockStreamIMockRecorder) HandleMaxStreamDataFrame(arg0 interface{}) *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "HandleMaxStreamDataFrame", reflect.TypeOf((*MockStreamI)(nil).HandleMaxStreamDataFrame), arg0)
|
||||
}
|
||||
|
||||
// HandleRstStreamFrame mocks base method
|
||||
func (_m *MockStreamI) HandleRstStreamFrame(_param0 *wire.RstStreamFrame) error {
|
||||
ret := _m.ctrl.Call(_m, "HandleRstStreamFrame", _param0)
|
||||
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)
|
||||
}
|
||||
|
||||
// HandleStopSendingFrame mocks base method
|
||||
func (_m *MockStreamI) HandleStopSendingFrame(_param0 *wire.StopSendingFrame) {
|
||||
_m.ctrl.Call(_m, "HandleStopSendingFrame", _param0)
|
||||
}
|
||||
|
||||
// HandleStopSendingFrame indicates an expected call of HandleStopSendingFrame
|
||||
func (_mr *MockStreamIMockRecorder) HandleStopSendingFrame(arg0 interface{}) *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "HandleStopSendingFrame", reflect.TypeOf((*MockStreamI)(nil).HandleStopSendingFrame), arg0)
|
||||
}
|
||||
|
||||
// HandleStreamFrame mocks base method
|
||||
func (_m *MockStreamI) HandleStreamFrame(_param0 *wire.StreamFrame) error {
|
||||
ret := _m.ctrl.Call(_m, "HandleStreamFrame", _param0)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// HandleStreamFrame indicates an expected call of HandleStreamFrame
|
||||
func (_mr *MockStreamIMockRecorder) HandleStreamFrame(arg0 interface{}) *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "HandleStreamFrame", reflect.TypeOf((*MockStreamI)(nil).HandleStreamFrame), arg0)
|
||||
}
|
||||
|
||||
// PopStreamFrame mocks base method
|
||||
func (_m *MockStreamI) PopStreamFrame(_param0 protocol.ByteCount) *wire.StreamFrame {
|
||||
ret := _m.ctrl.Call(_m, "PopStreamFrame", _param0)
|
||||
ret0, _ := ret[0].(*wire.StreamFrame)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// PopStreamFrame indicates an expected call of PopStreamFrame
|
||||
func (_mr *MockStreamIMockRecorder) PopStreamFrame(arg0 interface{}) *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "PopStreamFrame", reflect.TypeOf((*MockStreamI)(nil).PopStreamFrame), arg0)
|
||||
}
|
||||
|
||||
// Read mocks base method
|
||||
func (_m *MockStreamI) Read(_param0 []byte) (int, error) {
|
||||
ret := _m.ctrl.Call(_m, "Read", _param0)
|
||||
|
@ -247,3 +156,93 @@ func (_m *MockStreamI) Write(_param0 []byte) (int, error) {
|
|||
func (_mr *MockStreamIMockRecorder) Write(arg0 interface{}) *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "Write", reflect.TypeOf((*MockStreamI)(nil).Write), arg0)
|
||||
}
|
||||
|
||||
// closeForShutdown mocks base method
|
||||
func (_m *MockStreamI) closeForShutdown(_param0 error) {
|
||||
_m.ctrl.Call(_m, "closeForShutdown", _param0)
|
||||
}
|
||||
|
||||
// closeForShutdown indicates an expected call of closeForShutdown
|
||||
func (_mr *MockStreamIMockRecorder) closeForShutdown(arg0 interface{}) *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "closeForShutdown", reflect.TypeOf((*MockStreamI)(nil).closeForShutdown), arg0)
|
||||
}
|
||||
|
||||
// finished mocks base method
|
||||
func (_m *MockStreamI) finished() bool {
|
||||
ret := _m.ctrl.Call(_m, "finished")
|
||||
ret0, _ := ret[0].(bool)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// finished indicates an expected call of finished
|
||||
func (_mr *MockStreamIMockRecorder) finished() *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "finished", reflect.TypeOf((*MockStreamI)(nil).finished))
|
||||
}
|
||||
|
||||
// getWindowUpdate mocks base method
|
||||
func (_m *MockStreamI) getWindowUpdate() protocol.ByteCount {
|
||||
ret := _m.ctrl.Call(_m, "getWindowUpdate")
|
||||
ret0, _ := ret[0].(protocol.ByteCount)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// getWindowUpdate indicates an expected call of getWindowUpdate
|
||||
func (_mr *MockStreamIMockRecorder) getWindowUpdate() *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "getWindowUpdate", reflect.TypeOf((*MockStreamI)(nil).getWindowUpdate))
|
||||
}
|
||||
|
||||
// handleMaxStreamDataFrame mocks base method
|
||||
func (_m *MockStreamI) handleMaxStreamDataFrame(_param0 *wire.MaxStreamDataFrame) {
|
||||
_m.ctrl.Call(_m, "handleMaxStreamDataFrame", _param0)
|
||||
}
|
||||
|
||||
// handleMaxStreamDataFrame indicates an expected call of handleMaxStreamDataFrame
|
||||
func (_mr *MockStreamIMockRecorder) handleMaxStreamDataFrame(arg0 interface{}) *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "handleMaxStreamDataFrame", reflect.TypeOf((*MockStreamI)(nil).handleMaxStreamDataFrame), arg0)
|
||||
}
|
||||
|
||||
// handleRstStreamFrame mocks base method
|
||||
func (_m *MockStreamI) handleRstStreamFrame(_param0 *wire.RstStreamFrame) error {
|
||||
ret := _m.ctrl.Call(_m, "handleRstStreamFrame", _param0)
|
||||
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)
|
||||
}
|
||||
|
||||
// handleStopSendingFrame mocks base method
|
||||
func (_m *MockStreamI) handleStopSendingFrame(_param0 *wire.StopSendingFrame) {
|
||||
_m.ctrl.Call(_m, "handleStopSendingFrame", _param0)
|
||||
}
|
||||
|
||||
// handleStopSendingFrame indicates an expected call of handleStopSendingFrame
|
||||
func (_mr *MockStreamIMockRecorder) handleStopSendingFrame(arg0 interface{}) *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "handleStopSendingFrame", reflect.TypeOf((*MockStreamI)(nil).handleStopSendingFrame), arg0)
|
||||
}
|
||||
|
||||
// handleStreamFrame mocks base method
|
||||
func (_m *MockStreamI) handleStreamFrame(_param0 *wire.StreamFrame) error {
|
||||
ret := _m.ctrl.Call(_m, "handleStreamFrame", _param0)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// handleStreamFrame indicates an expected call of handleStreamFrame
|
||||
func (_mr *MockStreamIMockRecorder) handleStreamFrame(arg0 interface{}) *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "handleStreamFrame", reflect.TypeOf((*MockStreamI)(nil).handleStreamFrame), arg0)
|
||||
}
|
||||
|
||||
// popStreamFrame mocks base method
|
||||
func (_m *MockStreamI) popStreamFrame(_param0 protocol.ByteCount) *wire.StreamFrame {
|
||||
ret := _m.ctrl.Call(_m, "popStreamFrame", _param0)
|
||||
ret0, _ := ret[0].(*wire.StreamFrame)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// popStreamFrame indicates an expected call of popStreamFrame
|
||||
func (_mr *MockStreamIMockRecorder) popStreamFrame(arg0 interface{}) *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "popStreamFrame", reflect.TypeOf((*MockStreamI)(nil).popStreamFrame), arg0)
|
||||
}
|
3
mockgen.go
Normal file
3
mockgen.go
Normal file
|
@ -0,0 +1,3 @@
|
|||
package quic
|
||||
|
||||
//go:generate sh -c "./mockgen_private.sh quic mock_stream_internal_test.go github.com/lucas-clemente/quic-go streamI StreamI"
|
18
mockgen_private.sh
Executable file
18
mockgen_private.sh
Executable file
|
@ -0,0 +1,18 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Mockgen refuses to generate mocks private types.
|
||||
# This script copies the quic package to a temporary directory, and adds an public alias for the private type.
|
||||
# It then creates a mock for this public (alias) type.
|
||||
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
mkdir -p $TEMP_DIR/src/github.com/lucas-clemente/quic-go/
|
||||
|
||||
# copy all .go files to a temporary directory
|
||||
rsync -r --include='*.go' --include '*/' --exclude '*' $GOPATH/src/github.com/lucas-clemente/quic-go/ $TEMP_DIR/src/github.com/lucas-clemente/quic-go/
|
||||
echo "type $5 = $4" >> $TEMP_DIR/src/github.com/lucas-clemente/quic-go/interface.go
|
||||
|
||||
export GOPATH="$TEMP_DIR:$GOPATH"
|
||||
|
||||
mockgen -package $1 -self_package $1 -destination $2 $3 $5
|
||||
|
||||
rm -r "$TEMP_DIR"
|
|
@ -180,7 +180,7 @@ func (s *receiveStream) CancelRead(errorCode protocol.ApplicationErrorCode) erro
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *receiveStream) HandleStreamFrame(frame *wire.StreamFrame) error {
|
||||
func (s *receiveStream) handleStreamFrame(frame *wire.StreamFrame) error {
|
||||
maxOffset := frame.Offset + frame.DataLen()
|
||||
if err := s.flowController.UpdateHighestReceived(maxOffset, frame.FinBit); err != nil {
|
||||
return err
|
||||
|
@ -195,7 +195,7 @@ func (s *receiveStream) HandleStreamFrame(frame *wire.StreamFrame) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *receiveStream) HandleRstStreamFrame(frame *wire.RstStreamFrame) error {
|
||||
func (s *receiveStream) handleRstStreamFrame(frame *wire.RstStreamFrame) error {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
|
||||
|
@ -226,7 +226,7 @@ func (s *receiveStream) HandleRstStreamFrame(frame *wire.RstStreamFrame) error {
|
|||
}
|
||||
|
||||
func (s *receiveStream) CloseRemote(offset protocol.ByteCount) {
|
||||
s.HandleStreamFrame(&wire.StreamFrame{FinBit: true, Offset: offset})
|
||||
s.handleStreamFrame(&wire.StreamFrame{FinBit: true, Offset: offset})
|
||||
}
|
||||
|
||||
func (s *receiveStream) onClose(offset protocol.ByteCount) {
|
||||
|
@ -255,7 +255,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.
|
||||
func (s *receiveStream) CloseForShutdown(err error) {
|
||||
func (s *receiveStream) closeForShutdown(err error) {
|
||||
s.mutex.Lock()
|
||||
s.closedForShutdown = true
|
||||
s.closeForShutdownErr = err
|
||||
|
@ -263,7 +263,7 @@ func (s *receiveStream) CloseForShutdown(err error) {
|
|||
s.signalRead()
|
||||
}
|
||||
|
||||
func (s *receiveStream) Finished() bool {
|
||||
func (s *receiveStream) finished() bool {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
|
||||
|
@ -271,7 +271,7 @@ func (s *receiveStream) Finished() bool {
|
|||
s.finRead || s.resetRemotely
|
||||
}
|
||||
|
||||
func (s *receiveStream) GetWindowUpdate() protocol.ByteCount {
|
||||
func (s *receiveStream) getWindowUpdate() protocol.ByteCount {
|
||||
return s.flowController.GetWindowUpdate()
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ var _ = Describe("Receive Stream", func() {
|
|||
Offset: 0,
|
||||
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF},
|
||||
}
|
||||
err := str.HandleStreamFrame(&frame)
|
||||
err := str.handleStreamFrame(&frame)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
b := make([]byte, 4)
|
||||
n, err := strWithTimeout.Read(b)
|
||||
|
@ -68,7 +68,7 @@ var _ = Describe("Receive Stream", func() {
|
|||
Offset: 0,
|
||||
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF},
|
||||
}
|
||||
err := str.HandleStreamFrame(&frame)
|
||||
err := str.handleStreamFrame(&frame)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
b := make([]byte, 2)
|
||||
n, err := strWithTimeout.Read(b)
|
||||
|
@ -93,9 +93,9 @@ var _ = Describe("Receive Stream", func() {
|
|||
Offset: 2,
|
||||
Data: []byte{0xBE, 0xEF},
|
||||
}
|
||||
err := str.HandleStreamFrame(&frame1)
|
||||
err := str.handleStreamFrame(&frame1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = str.HandleStreamFrame(&frame2)
|
||||
err = str.handleStreamFrame(&frame2)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
b := make([]byte, 6)
|
||||
n, err := strWithTimeout.Read(b)
|
||||
|
@ -116,9 +116,9 @@ var _ = Describe("Receive Stream", func() {
|
|||
Offset: 2,
|
||||
Data: []byte{0xBE, 0xEF},
|
||||
}
|
||||
err := str.HandleStreamFrame(&frame1)
|
||||
err := str.handleStreamFrame(&frame1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = str.HandleStreamFrame(&frame2)
|
||||
err = str.handleStreamFrame(&frame2)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
b := make([]byte, 4)
|
||||
n, err := strWithTimeout.Read(b)
|
||||
|
@ -134,7 +134,7 @@ var _ = Describe("Receive Stream", func() {
|
|||
defer GinkgoRecover()
|
||||
frame := wire.StreamFrame{Data: []byte{0xDE, 0xAD}}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
err := str.HandleStreamFrame(&frame)
|
||||
err := str.handleStreamFrame(&frame)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}()
|
||||
b := make([]byte, 2)
|
||||
|
@ -155,9 +155,9 @@ var _ = Describe("Receive Stream", func() {
|
|||
Offset: 0,
|
||||
Data: []byte{0xDE, 0xAD},
|
||||
}
|
||||
err := str.HandleStreamFrame(&frame1)
|
||||
err := str.handleStreamFrame(&frame1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = str.HandleStreamFrame(&frame2)
|
||||
err = str.handleStreamFrame(&frame2)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
b := make([]byte, 4)
|
||||
n, err := strWithTimeout.Read(b)
|
||||
|
@ -183,11 +183,11 @@ var _ = Describe("Receive Stream", func() {
|
|||
Offset: 2,
|
||||
Data: []byte{0xBE, 0xEF},
|
||||
}
|
||||
err := str.HandleStreamFrame(&frame1)
|
||||
err := str.handleStreamFrame(&frame1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = str.HandleStreamFrame(&frame2)
|
||||
err = str.handleStreamFrame(&frame2)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = str.HandleStreamFrame(&frame3)
|
||||
err = str.handleStreamFrame(&frame3)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
b := make([]byte, 4)
|
||||
n, err := strWithTimeout.Read(b)
|
||||
|
@ -209,9 +209,9 @@ var _ = Describe("Receive Stream", func() {
|
|||
Offset: 2,
|
||||
Data: []byte("obar"),
|
||||
}
|
||||
err := str.HandleStreamFrame(&frame1)
|
||||
err := str.handleStreamFrame(&frame1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = str.HandleStreamFrame(&frame2)
|
||||
err = str.handleStreamFrame(&frame2)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
b := make([]byte, 6)
|
||||
n, err := strWithTimeout.Read(b)
|
||||
|
@ -227,7 +227,7 @@ var _ = Describe("Receive Stream", func() {
|
|||
Offset: 0,
|
||||
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF},
|
||||
}
|
||||
err := str.HandleStreamFrame(&frame)
|
||||
err := str.handleStreamFrame(&frame)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
b := make([]byte, 4)
|
||||
_, err = strWithTimeout.Read(b)
|
||||
|
@ -237,7 +237,7 @@ var _ = Describe("Receive Stream", func() {
|
|||
|
||||
It("passes on errors from the streamFrameSorter", func() {
|
||||
mockFC.EXPECT().UpdateHighestReceived(protocol.ByteCount(0), false)
|
||||
err := str.HandleStreamFrame(&wire.StreamFrame{StreamID: streamID}) // STREAM frame without data
|
||||
err := str.handleStreamFrame(&wire.StreamFrame{StreamID: streamID}) // STREAM frame without data
|
||||
Expect(err).To(MatchError(errEmptyStreamData))
|
||||
})
|
||||
|
||||
|
@ -251,7 +251,7 @@ var _ = Describe("Receive Stream", func() {
|
|||
It("returns an error when Read is called after the deadline", func() {
|
||||
mockFC.EXPECT().UpdateHighestReceived(protocol.ByteCount(6), false).AnyTimes()
|
||||
f := &wire.StreamFrame{Data: []byte("foobar")}
|
||||
err := str.HandleStreamFrame(f)
|
||||
err := str.handleStreamFrame(f)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
str.SetReadDeadline(time.Now().Add(-time.Second))
|
||||
b := make([]byte, 6)
|
||||
|
@ -318,7 +318,7 @@ var _ = Describe("Receive Stream", func() {
|
|||
Data: []byte{0xDE, 0xAD, 0xBE, 0xEF},
|
||||
FinBit: true,
|
||||
}
|
||||
str.HandleStreamFrame(&frame)
|
||||
str.handleStreamFrame(&frame)
|
||||
b := make([]byte, 4)
|
||||
n, err := strWithTimeout.Read(b)
|
||||
Expect(err).To(MatchError(io.EOF))
|
||||
|
@ -342,9 +342,9 @@ var _ = Describe("Receive Stream", func() {
|
|||
Offset: 0,
|
||||
Data: []byte{0xDE, 0xAD},
|
||||
}
|
||||
err := str.HandleStreamFrame(&frame1)
|
||||
err := str.handleStreamFrame(&frame1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = str.HandleStreamFrame(&frame2)
|
||||
err = str.handleStreamFrame(&frame2)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
b := make([]byte, 4)
|
||||
n, err := strWithTimeout.Read(b)
|
||||
|
@ -364,7 +364,7 @@ var _ = Describe("Receive Stream", func() {
|
|||
Data: []byte{0xDE, 0xAD},
|
||||
FinBit: true,
|
||||
}
|
||||
err := str.HandleStreamFrame(&frame)
|
||||
err := str.handleStreamFrame(&frame)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
b := make([]byte, 4)
|
||||
n, err := strWithTimeout.Read(b)
|
||||
|
@ -381,7 +381,7 @@ var _ = Describe("Receive Stream", func() {
|
|||
Data: []byte{},
|
||||
FinBit: true,
|
||||
}
|
||||
err := str.HandleStreamFrame(&frame)
|
||||
err := str.handleStreamFrame(&frame)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
b := make([]byte, 4)
|
||||
n, err := strWithTimeout.Read(b)
|
||||
|
@ -415,12 +415,12 @@ var _ = Describe("Receive Stream", func() {
|
|||
close(done)
|
||||
}()
|
||||
Consistently(done).ShouldNot(BeClosed())
|
||||
str.CloseForShutdown(testErr)
|
||||
str.closeForShutdown(testErr)
|
||||
Eventually(done).Should(BeClosed())
|
||||
})
|
||||
|
||||
It("errors for all following reads", func() {
|
||||
str.CloseForShutdown(testErr)
|
||||
str.closeForShutdown(testErr)
|
||||
b := make([]byte, 1)
|
||||
n, err := strWithTimeout.Read(b)
|
||||
Expect(n).To(BeZero())
|
||||
|
@ -464,7 +464,7 @@ var _ = Describe("Receive Stream", func() {
|
|||
It("doesn't send a RST_STREAM frame, if the FIN was already read", func() {
|
||||
mockFC.EXPECT().UpdateHighestReceived(protocol.ByteCount(6), true)
|
||||
mockFC.EXPECT().AddBytesRead(protocol.ByteCount(6))
|
||||
err := str.HandleStreamFrame(&wire.StreamFrame{
|
||||
err := str.handleStreamFrame(&wire.StreamFrame{
|
||||
StreamID: streamID,
|
||||
Data: []byte("foobar"),
|
||||
FinBit: true,
|
||||
|
@ -511,13 +511,13 @@ var _ = Describe("Receive Stream", func() {
|
|||
close(done)
|
||||
}()
|
||||
Consistently(done).ShouldNot(BeClosed())
|
||||
str.HandleRstStreamFrame(rst)
|
||||
str.handleRstStreamFrame(rst)
|
||||
Eventually(done).Should(BeClosed())
|
||||
})
|
||||
|
||||
It("doesn't allow further calls to Read", func() {
|
||||
mockFC.EXPECT().UpdateHighestReceived(protocol.ByteCount(42), true)
|
||||
err := str.HandleRstStreamFrame(rst)
|
||||
err := str.handleRstStreamFrame(rst)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
_, err = strWithTimeout.Read([]byte{0})
|
||||
Expect(err).To(MatchError("Stream 1337 was reset with error code 1234"))
|
||||
|
@ -529,21 +529,21 @@ var _ = Describe("Receive Stream", func() {
|
|||
It("errors when receiving a RST_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.handleRstStreamFrame(rst)
|
||||
Expect(err).To(MatchError(testErr))
|
||||
})
|
||||
|
||||
It("ignores duplicate RST_STREAM frames", func() {
|
||||
mockFC.EXPECT().UpdateHighestReceived(protocol.ByteCount(42), true).Times(2)
|
||||
err := str.HandleRstStreamFrame(rst)
|
||||
err := str.handleRstStreamFrame(rst)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = str.HandleRstStreamFrame(rst)
|
||||
err = str.handleRstStreamFrame(rst)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
It("doesn't do anyting when it was closed for shutdown", func() {
|
||||
str.CloseForShutdown(nil)
|
||||
err := str.HandleRstStreamFrame(rst)
|
||||
str.closeForShutdown(nil)
|
||||
err := str.handleRstStreamFrame(rst)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
|
@ -565,7 +565,7 @@ var _ = Describe("Receive Stream", func() {
|
|||
close(readReturned)
|
||||
}()
|
||||
Consistently(readReturned).ShouldNot(BeClosed())
|
||||
err := str.HandleRstStreamFrame(rst)
|
||||
err := str.handleRstStreamFrame(rst)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Eventually(readReturned).Should(BeClosed())
|
||||
})
|
||||
|
@ -586,13 +586,13 @@ var _ = Describe("Receive Stream", func() {
|
|||
close(readReturned)
|
||||
}()
|
||||
Consistently(readReturned).ShouldNot(BeClosed())
|
||||
err := str.HandleStreamFrame(&wire.StreamFrame{
|
||||
err := str.handleStreamFrame(&wire.StreamFrame{
|
||||
StreamID: streamID,
|
||||
Data: []byte("foobar"),
|
||||
FinBit: true,
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = str.HandleRstStreamFrame(&wire.RstStreamFrame{
|
||||
err = str.handleRstStreamFrame(&wire.RstStreamFrame{
|
||||
StreamID: streamID,
|
||||
ByteOffset: 6,
|
||||
ErrorCode: 0,
|
||||
|
@ -613,20 +613,20 @@ var _ = Describe("Receive Stream", func() {
|
|||
Offset: 2,
|
||||
Data: []byte("foobar"),
|
||||
}
|
||||
err := str.HandleStreamFrame(&frame)
|
||||
err := str.handleStreamFrame(&frame)
|
||||
Expect(err).To(MatchError(testErr))
|
||||
})
|
||||
|
||||
It("gets a window update", func() {
|
||||
mockFC.EXPECT().GetWindowUpdate().Return(protocol.ByteCount(0x100))
|
||||
Expect(str.GetWindowUpdate()).To(Equal(protocol.ByteCount(0x100)))
|
||||
Expect(str.getWindowUpdate()).To(Equal(protocol.ByteCount(0x100)))
|
||||
})
|
||||
})
|
||||
|
||||
Context("saying if it is finished", func() {
|
||||
finishReading := func() {
|
||||
mockFC.EXPECT().UpdateHighestReceived(protocol.ByteCount(0), true)
|
||||
err := str.HandleStreamFrame(&wire.StreamFrame{FinBit: true})
|
||||
err := str.handleStreamFrame(&wire.StreamFrame{FinBit: true})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
b := make([]byte, 100)
|
||||
_, err = strWithTimeout.Read(b)
|
||||
|
@ -634,14 +634,14 @@ var _ = Describe("Receive Stream", func() {
|
|||
}
|
||||
|
||||
It("is finished after it is closed for shutdown", func() {
|
||||
str.CloseForShutdown(errors.New("testErr"))
|
||||
Expect(str.Finished()).To(BeTrue())
|
||||
str.closeForShutdown(errors.New("testErr"))
|
||||
Expect(str.finished()).To(BeTrue())
|
||||
})
|
||||
|
||||
It("is finished if it is only closed for reading", func() {
|
||||
mockFC.EXPECT().AddBytesRead(protocol.ByteCount(0))
|
||||
finishReading()
|
||||
Expect(str.Finished()).To(BeTrue())
|
||||
Expect(str.finished()).To(BeTrue())
|
||||
})
|
||||
|
||||
// the stream still needs to stay alive until we receive the final offset
|
||||
|
@ -649,14 +649,14 @@ var _ = Describe("Receive Stream", func() {
|
|||
It("is not finished after CancelRead", func() {
|
||||
err := str.CancelRead(123)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(str.Finished()).To(BeFalse())
|
||||
Expect(str.finished()).To(BeFalse())
|
||||
})
|
||||
|
||||
It("is finished after receiving a RST_STREAM frame", func() {
|
||||
mockFC.EXPECT().UpdateHighestReceived(protocol.ByteCount(3), true)
|
||||
err := str.HandleRstStreamFrame(&wire.RstStreamFrame{ByteOffset: 3})
|
||||
err := str.handleRstStreamFrame(&wire.RstStreamFrame{ByteOffset: 3})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(str.Finished()).To(BeTrue())
|
||||
Expect(str.finished()).To(BeTrue())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -120,9 +120,9 @@ func (s *sendStream) Write(p []byte) (int, error) {
|
|||
return len(p) - len(s.dataForWriting), err
|
||||
}
|
||||
|
||||
// PopStreamFrame returns the next STREAM frame that is supposed to be sent on this stream
|
||||
// popStreamFrame returns the next STREAM frame that is supposed to be sent on this stream
|
||||
// maxBytes is the maximum length this frame (including frame header) will have.
|
||||
func (s *sendStream) PopStreamFrame(maxBytes protocol.ByteCount) *wire.StreamFrame {
|
||||
func (s *sendStream) popStreamFrame(maxBytes protocol.ByteCount) *wire.StreamFrame {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
|
||||
|
@ -226,13 +226,13 @@ func (s *sendStream) cancelWriteImpl(errorCode protocol.ApplicationErrorCode, wr
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *sendStream) HandleStopSendingFrame(frame *wire.StopSendingFrame) {
|
||||
func (s *sendStream) handleStopSendingFrame(frame *wire.StopSendingFrame) {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
s.handleStopSendingFrameImpl(frame)
|
||||
}
|
||||
|
||||
func (s *sendStream) HandleMaxStreamDataFrame(frame *wire.MaxStreamDataFrame) {
|
||||
func (s *sendStream) handleMaxStreamDataFrame(frame *wire.MaxStreamDataFrame) {
|
||||
s.flowController.UpdateSendWindow(frame.ByteOffset)
|
||||
}
|
||||
|
||||
|
@ -267,7 +267,7 @@ func (s *sendStream) SetWriteDeadline(t time.Time) error {
|
|||
// CloseForShutdown closes a stream abruptly.
|
||||
// It makes Write unblock (and return the error) immediately.
|
||||
// The peer will NOT be informed about this: the stream is closed without sending a FIN or RST.
|
||||
func (s *sendStream) CloseForShutdown(err error) {
|
||||
func (s *sendStream) closeForShutdown(err error) {
|
||||
s.mutex.Lock()
|
||||
s.closedForShutdown = true
|
||||
s.closeForShutdownErr = err
|
||||
|
@ -276,7 +276,7 @@ func (s *sendStream) CloseForShutdown(err error) {
|
|||
s.ctxCancel()
|
||||
}
|
||||
|
||||
func (s *sendStream) Finished() bool {
|
||||
func (s *sendStream) finished() bool {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ var _ = Describe("Send Stream", func() {
|
|||
Consistently(done).ShouldNot(BeClosed())
|
||||
var f *wire.StreamFrame
|
||||
Eventually(func() *wire.StreamFrame {
|
||||
f = str.PopStreamFrame(1000)
|
||||
f = str.popStreamFrame(1000)
|
||||
return f
|
||||
}).ShouldNot(BeNil())
|
||||
Expect(onDataCalled).To(BeTrue())
|
||||
|
@ -90,24 +90,24 @@ var _ = Describe("Send Stream", func() {
|
|||
Consistently(done).ShouldNot(BeClosed())
|
||||
var f *wire.StreamFrame
|
||||
Eventually(func() *wire.StreamFrame {
|
||||
f = str.PopStreamFrame(3 + frameHeaderLen)
|
||||
f = str.popStreamFrame(3 + frameHeaderLen)
|
||||
return f
|
||||
}).ShouldNot(BeNil())
|
||||
Expect(f.Data).To(Equal([]byte("foo")))
|
||||
Expect(f.FinBit).To(BeFalse())
|
||||
Expect(f.Offset).To(BeZero())
|
||||
Expect(f.DataLenPresent).To(BeTrue())
|
||||
f = str.PopStreamFrame(100)
|
||||
f = str.popStreamFrame(100)
|
||||
Expect(f.Data).To(Equal([]byte("bar")))
|
||||
Expect(f.FinBit).To(BeFalse())
|
||||
Expect(f.Offset).To(Equal(protocol.ByteCount(3)))
|
||||
Expect(f.DataLenPresent).To(BeTrue())
|
||||
Expect(str.PopStreamFrame(1000)).To(BeNil())
|
||||
Expect(str.popStreamFrame(1000)).To(BeNil())
|
||||
Eventually(done).Should(BeClosed())
|
||||
})
|
||||
|
||||
It("PopStreamFrame returns nil if no data is available", func() {
|
||||
Expect(str.PopStreamFrame(1000)).To(BeNil())
|
||||
It("popStreamFrame returns nil if no data is available", func() {
|
||||
Expect(str.popStreamFrame(1000)).To(BeNil())
|
||||
})
|
||||
|
||||
It("copies the slice while writing", func() {
|
||||
|
@ -124,10 +124,10 @@ var _ = Describe("Send Stream", func() {
|
|||
Expect(n).To(Equal(3))
|
||||
}()
|
||||
var frame *wire.StreamFrame
|
||||
Eventually(func() *wire.StreamFrame { frame = str.PopStreamFrame(frameHeaderSize + 1); return frame }).ShouldNot(BeNil())
|
||||
Eventually(func() *wire.StreamFrame { frame = str.popStreamFrame(frameHeaderSize + 1); return frame }).ShouldNot(BeNil())
|
||||
Expect(frame.Data).To(Equal([]byte("f")))
|
||||
s[1] = 'e'
|
||||
f := str.PopStreamFrame(100)
|
||||
f := str.popStreamFrame(100)
|
||||
Expect(f).ToNot(BeNil())
|
||||
Expect(f.Data).To(Equal([]byte("oo")))
|
||||
})
|
||||
|
@ -165,7 +165,7 @@ var _ = Describe("Send Stream", func() {
|
|||
}()
|
||||
var f *wire.StreamFrame
|
||||
Eventually(func() *wire.StreamFrame {
|
||||
f = str.PopStreamFrame(1000)
|
||||
f = str.popStreamFrame(1000)
|
||||
return f
|
||||
}).ShouldNot(BeNil())
|
||||
Expect(queuedControlFrames).To(Equal([]wire.Frame{
|
||||
|
@ -193,7 +193,7 @@ var _ = Describe("Send Stream", func() {
|
|||
Expect(str.Close()).To(Succeed())
|
||||
var f *wire.StreamFrame
|
||||
Eventually(func() *wire.StreamFrame {
|
||||
f = str.PopStreamFrame(1000)
|
||||
f = str.popStreamFrame(1000)
|
||||
return f
|
||||
}).ShouldNot(BeNil())
|
||||
Expect(f.FinBit).To(BeTrue())
|
||||
|
@ -237,7 +237,7 @@ var _ = Describe("Send Stream", func() {
|
|||
}()
|
||||
var frame *wire.StreamFrame
|
||||
Eventually(func() *wire.StreamFrame {
|
||||
frame = str.PopStreamFrame(50)
|
||||
frame = str.popStreamFrame(50)
|
||||
return frame
|
||||
}).ShouldNot(BeNil())
|
||||
Eventually(writeReturned, scaleDuration(80*time.Millisecond)).Should(BeClosed())
|
||||
|
@ -289,7 +289,7 @@ var _ = Describe("Send Stream", func() {
|
|||
|
||||
It("allows FIN", func() {
|
||||
str.Close()
|
||||
f := str.PopStreamFrame(1000)
|
||||
f := str.popStreamFrame(1000)
|
||||
Expect(f).ToNot(BeNil())
|
||||
Expect(f.Data).To(BeEmpty())
|
||||
Expect(f.FinBit).To(BeTrue())
|
||||
|
@ -302,28 +302,28 @@ var _ = Describe("Send Stream", func() {
|
|||
mockFC.EXPECT().IsNewlyBlocked()
|
||||
str.dataForWriting = []byte("foobar")
|
||||
str.Close()
|
||||
f := str.PopStreamFrame(3 + frameHeaderLen)
|
||||
f := str.popStreamFrame(3 + frameHeaderLen)
|
||||
Expect(f).ToNot(BeNil())
|
||||
Expect(f.Data).To(Equal([]byte("foo")))
|
||||
Expect(f.FinBit).To(BeFalse())
|
||||
f = str.PopStreamFrame(100)
|
||||
f = str.popStreamFrame(100)
|
||||
Expect(f.Data).To(Equal([]byte("bar")))
|
||||
Expect(f.FinBit).To(BeTrue())
|
||||
})
|
||||
|
||||
It("doesn't allow FIN after an error", func() {
|
||||
str.CloseForShutdown(errors.New("test"))
|
||||
f := str.PopStreamFrame(1000)
|
||||
str.closeForShutdown(errors.New("test"))
|
||||
f := str.popStreamFrame(1000)
|
||||
Expect(f).To(BeNil())
|
||||
})
|
||||
|
||||
It("doesn't allow FIN twice", func() {
|
||||
str.Close()
|
||||
f := str.PopStreamFrame(1000)
|
||||
f := str.popStreamFrame(1000)
|
||||
Expect(f).ToNot(BeNil())
|
||||
Expect(f.Data).To(BeEmpty())
|
||||
Expect(f.FinBit).To(BeTrue())
|
||||
Expect(str.PopStreamFrame(1000)).To(BeNil())
|
||||
Expect(str.popStreamFrame(1000)).To(BeNil())
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -331,7 +331,7 @@ var _ = Describe("Send Stream", func() {
|
|||
testErr := errors.New("test")
|
||||
|
||||
It("returns errors when the stream is cancelled", func() {
|
||||
str.CloseForShutdown(testErr)
|
||||
str.closeForShutdown(testErr)
|
||||
n, err := strWithTimeout.Write([]byte("foo"))
|
||||
Expect(n).To(BeZero())
|
||||
Expect(err).To(MatchError(testErr))
|
||||
|
@ -348,15 +348,15 @@ var _ = Describe("Send Stream", func() {
|
|||
Expect(err).To(MatchError(testErr))
|
||||
close(done)
|
||||
}()
|
||||
Eventually(func() *wire.StreamFrame { return str.PopStreamFrame(50) }).ShouldNot(BeNil()) // get a STREAM frame containing some data, but not all
|
||||
str.CloseForShutdown(testErr)
|
||||
Expect(str.PopStreamFrame(1000)).To(BeNil())
|
||||
Eventually(func() *wire.StreamFrame { return str.popStreamFrame(50) }).ShouldNot(BeNil()) // get a STREAM frame containing some data, but not all
|
||||
str.closeForShutdown(testErr)
|
||||
Expect(str.popStreamFrame(1000)).To(BeNil())
|
||||
Eventually(done).Should(BeClosed())
|
||||
})
|
||||
|
||||
It("cancels the context", func() {
|
||||
Expect(str.Context().Done()).ToNot(BeClosed())
|
||||
str.CloseForShutdown(testErr)
|
||||
str.closeForShutdown(testErr)
|
||||
Expect(str.Context().Done()).To(BeClosed())
|
||||
})
|
||||
})
|
||||
|
@ -392,7 +392,7 @@ var _ = Describe("Send Stream", func() {
|
|||
}()
|
||||
var frame *wire.StreamFrame
|
||||
Eventually(func() *wire.StreamFrame {
|
||||
frame = str.PopStreamFrame(50)
|
||||
frame = str.popStreamFrame(50)
|
||||
return frame
|
||||
}).ShouldNot(BeNil())
|
||||
err := str.CancelWrite(1234)
|
||||
|
@ -433,7 +433,7 @@ var _ = Describe("Send Stream", func() {
|
|||
|
||||
Context("receiving STOP_SENDING frames", func() {
|
||||
It("queues a RST_STREAM frames with error code Stopping", func() {
|
||||
str.HandleStopSendingFrame(&wire.StopSendingFrame{
|
||||
str.handleStopSendingFrame(&wire.StopSendingFrame{
|
||||
StreamID: streamID,
|
||||
ErrorCode: 101,
|
||||
})
|
||||
|
@ -457,7 +457,7 @@ var _ = Describe("Send Stream", func() {
|
|||
close(done)
|
||||
}()
|
||||
Consistently(done).ShouldNot(BeClosed())
|
||||
str.HandleStopSendingFrame(&wire.StopSendingFrame{
|
||||
str.handleStopSendingFrame(&wire.StopSendingFrame{
|
||||
StreamID: streamID,
|
||||
ErrorCode: 123,
|
||||
})
|
||||
|
@ -465,7 +465,7 @@ var _ = Describe("Send Stream", func() {
|
|||
})
|
||||
|
||||
It("doesn't allow further calls to Write", func() {
|
||||
str.HandleStopSendingFrame(&wire.StopSendingFrame{
|
||||
str.handleStopSendingFrame(&wire.StopSendingFrame{
|
||||
StreamID: streamID,
|
||||
ErrorCode: 123,
|
||||
})
|
||||
|
@ -480,26 +480,26 @@ var _ = Describe("Send Stream", func() {
|
|||
|
||||
Context("saying if it is finished", func() {
|
||||
It("is finished after it is closed for shutdown", func() {
|
||||
str.CloseForShutdown(errors.New("testErr"))
|
||||
Expect(str.Finished()).To(BeTrue())
|
||||
str.closeForShutdown(errors.New("testErr"))
|
||||
Expect(str.finished()).To(BeTrue())
|
||||
})
|
||||
|
||||
It("is finished after Close()", func() {
|
||||
str.Close()
|
||||
f := str.PopStreamFrame(1000)
|
||||
f := str.popStreamFrame(1000)
|
||||
Expect(f.FinBit).To(BeTrue())
|
||||
Expect(str.Finished()).To(BeTrue())
|
||||
Expect(str.finished()).To(BeTrue())
|
||||
})
|
||||
|
||||
It("is finished after CancelWrite", func() {
|
||||
err := str.CancelWrite(123)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(str.Finished()).To(BeTrue())
|
||||
Expect(str.finished()).To(BeTrue())
|
||||
})
|
||||
|
||||
It("is finished after receiving a STOP_SENDING (and sending a RST_STREAM)", func() {
|
||||
str.HandleStopSendingFrame(&wire.StopSendingFrame{StreamID: streamID})
|
||||
Expect(str.Finished()).To(BeTrue())
|
||||
str.handleStopSendingFrame(&wire.StopSendingFrame{StreamID: streamID})
|
||||
Expect(str.finished()).To(BeTrue())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -176,7 +176,7 @@ func (s *serverTLS) handleInitialImpl(remoteAddr net.Addr, hdr *wire.Header, dat
|
|||
return nil, err
|
||||
}
|
||||
cs := sess.getCryptoStream()
|
||||
cs.SetReadOffset(frame.DataLen())
|
||||
cs.setReadOffset(frame.DataLen())
|
||||
bc.SetStream(cs)
|
||||
return sess, nil
|
||||
}
|
||||
|
|
18
session.go
18
session.go
|
@ -566,7 +566,7 @@ func (s *session) handleStreamFrame(frame *wire.StreamFrame) error {
|
|||
if frame.FinBit {
|
||||
return errors.New("Received STREAM frame with FIN bit for the crypto stream")
|
||||
}
|
||||
return s.cryptoStream.HandleStreamFrame(frame)
|
||||
return s.cryptoStream.handleStreamFrame(frame)
|
||||
}
|
||||
str, err := s.streamsMap.GetOrOpenStream(frame.StreamID)
|
||||
if err != nil {
|
||||
|
@ -577,7 +577,7 @@ func (s *session) handleStreamFrame(frame *wire.StreamFrame) error {
|
|||
// ignore this StreamFrame
|
||||
return nil
|
||||
}
|
||||
return str.HandleStreamFrame(frame)
|
||||
return str.handleStreamFrame(frame)
|
||||
}
|
||||
|
||||
func (s *session) handleMaxDataFrame(frame *wire.MaxDataFrame) {
|
||||
|
@ -586,7 +586,7 @@ func (s *session) handleMaxDataFrame(frame *wire.MaxDataFrame) {
|
|||
|
||||
func (s *session) handleMaxStreamDataFrame(frame *wire.MaxStreamDataFrame) error {
|
||||
if frame.StreamID == s.version.CryptoStreamID() {
|
||||
s.cryptoStream.HandleMaxStreamDataFrame(frame)
|
||||
s.cryptoStream.handleMaxStreamDataFrame(frame)
|
||||
return nil
|
||||
}
|
||||
str, err := s.streamsMap.GetOrOpenStream(frame.StreamID)
|
||||
|
@ -597,7 +597,7 @@ func (s *session) handleMaxStreamDataFrame(frame *wire.MaxStreamDataFrame) error
|
|||
// stream is closed and already garbage collected
|
||||
return nil
|
||||
}
|
||||
str.HandleMaxStreamDataFrame(frame)
|
||||
str.handleMaxStreamDataFrame(frame)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -613,7 +613,7 @@ func (s *session) handleStopSendingFrame(frame *wire.StopSendingFrame) error {
|
|||
// stream is closed and already garbage collected
|
||||
return nil
|
||||
}
|
||||
str.HandleStopSendingFrame(frame)
|
||||
str.handleStopSendingFrame(frame)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -629,7 +629,7 @@ func (s *session) handleRstStreamFrame(frame *wire.RstStreamFrame) error {
|
|||
// stream is closed and already garbage collected
|
||||
return nil
|
||||
}
|
||||
return str.HandleRstStreamFrame(frame)
|
||||
return str.handleRstStreamFrame(frame)
|
||||
}
|
||||
|
||||
func (s *session) handleAckFrame(frame *wire.AckFrame, encLevel protocol.EncryptionLevel) error {
|
||||
|
@ -677,7 +677,7 @@ func (s *session) handleCloseError(closeErr closeError) error {
|
|||
utils.Errorf("Closing session with error: %s", closeErr.err.Error())
|
||||
}
|
||||
|
||||
s.cryptoStream.CloseForShutdown(quicErr)
|
||||
s.cryptoStream.closeForShutdown(quicErr)
|
||||
s.streamsMap.CloseWithError(quicErr)
|
||||
|
||||
if closeErr.err == errCloseSessionForNewVersion || closeErr.err == handshake.ErrCloseSessionForRetry {
|
||||
|
@ -706,7 +706,7 @@ func (s *session) processTransportParameters(params *handshake.TransportParamete
|
|||
s.connFlowController.UpdateSendWindow(params.ConnectionFlowControlWindow)
|
||||
// increase the flow control windows of all streams by sending them a fake MAX_STREAM_DATA frame
|
||||
s.streamsMap.Range(func(str streamI) {
|
||||
str.HandleMaxStreamDataFrame(&wire.MaxStreamDataFrame{
|
||||
str.handleMaxStreamDataFrame(&wire.MaxStreamDataFrame{
|
||||
StreamID: str.StreamID(),
|
||||
ByteOffset: params.StreamFlowControlWindow,
|
||||
})
|
||||
|
@ -950,7 +950,7 @@ func (s *session) tryDecryptingQueuedPackets() {
|
|||
func (s *session) getWindowUpdates() []wire.Frame {
|
||||
var res []wire.Frame
|
||||
s.streamsMap.Range(func(str streamI) {
|
||||
if offset := str.GetWindowUpdate(); offset != 0 {
|
||||
if offset := str.getWindowUpdate(); offset != 0 {
|
||||
res = append(res, &wire.MaxStreamDataFrame{
|
||||
StreamID: str.StreamID(),
|
||||
ByteOffset: offset,
|
||||
|
|
|
@ -193,10 +193,10 @@ var _ = Describe("Session", func() {
|
|||
Context("frame handling", func() {
|
||||
BeforeEach(func() {
|
||||
sess.streamsMap.newStream = func(id protocol.StreamID) streamI {
|
||||
str := mocks.NewMockStreamI(mockCtrl)
|
||||
str := NewMockStreamI(mockCtrl)
|
||||
str.EXPECT().StreamID().Return(id).AnyTimes()
|
||||
if id == 1 {
|
||||
str.EXPECT().Finished().AnyTimes()
|
||||
str.EXPECT().finished().AnyTimes()
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ var _ = Describe("Session", func() {
|
|||
sess.streamsMap.newStream = func(id protocol.StreamID) streamI {
|
||||
str := newStreamLambda(id)
|
||||
if id == 5 {
|
||||
str.(*mocks.MockStreamI).EXPECT().HandleStreamFrame(f)
|
||||
str.(*MockStreamI).EXPECT().handleStreamFrame(f)
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
@ -241,8 +241,8 @@ var _ = Describe("Session", func() {
|
|||
sess.streamsMap.newStream = func(id protocol.StreamID) streamI {
|
||||
str := newStreamLambda(id)
|
||||
if id == 5 {
|
||||
str.(*mocks.MockStreamI).EXPECT().HandleStreamFrame(f1)
|
||||
str.(*mocks.MockStreamI).EXPECT().HandleStreamFrame(f2)
|
||||
str.(*MockStreamI).EXPECT().handleStreamFrame(f1)
|
||||
str.(*MockStreamI).EXPECT().handleStreamFrame(f2)
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
@ -308,7 +308,7 @@ var _ = Describe("Session", func() {
|
|||
}
|
||||
str, err := sess.GetOrOpenStream(5)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
str.(*mocks.MockStreamI).EXPECT().HandleRstStreamFrame(f)
|
||||
str.(*MockStreamI).EXPECT().handleRstStreamFrame(f)
|
||||
err = sess.handleRstStreamFrame(f)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
@ -321,7 +321,7 @@ var _ = Describe("Session", func() {
|
|||
testErr := errors.New("flow control violation")
|
||||
str, err := sess.GetOrOpenStream(5)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
str.(*mocks.MockStreamI).EXPECT().HandleRstStreamFrame(f).Return(testErr)
|
||||
str.(*MockStreamI).EXPECT().handleRstStreamFrame(f).Return(testErr)
|
||||
err = sess.handleRstStreamFrame(f)
|
||||
Expect(err).To(MatchError(testErr))
|
||||
})
|
||||
|
@ -329,7 +329,7 @@ var _ = Describe("Session", func() {
|
|||
It("ignores the error when the stream is not known", func() {
|
||||
str, err := sess.GetOrOpenStream(3)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
str.(*mocks.MockStreamI).EXPECT().Finished().Return(true)
|
||||
str.(*MockStreamI).EXPECT().finished().Return(true)
|
||||
sess.streamsMap.DeleteClosedStreams()
|
||||
str, err = sess.GetOrOpenStream(3)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -377,7 +377,7 @@ var _ = Describe("Session", func() {
|
|||
}
|
||||
str, err := sess.GetOrOpenStream(5)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
str.(*mocks.MockStreamI).EXPECT().HandleMaxStreamDataFrame(f)
|
||||
str.(*MockStreamI).EXPECT().handleMaxStreamDataFrame(f)
|
||||
err = sess.handleMaxStreamDataFrame(f)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
@ -397,7 +397,7 @@ var _ = Describe("Session", func() {
|
|||
sess.streamsMap.newStream = func(id protocol.StreamID) streamI {
|
||||
str := newStreamLambda(id)
|
||||
if id == 5 {
|
||||
str.(*mocks.MockStreamI).EXPECT().HandleMaxStreamDataFrame(f)
|
||||
str.(*MockStreamI).EXPECT().handleMaxStreamDataFrame(f)
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
@ -411,7 +411,7 @@ var _ = Describe("Session", func() {
|
|||
It("ignores MAX_STREAM_DATA frames for a closed stream", func() {
|
||||
str, err := sess.GetOrOpenStream(3)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
str.(*mocks.MockStreamI).EXPECT().Finished().Return(true)
|
||||
str.(*MockStreamI).EXPECT().finished().Return(true)
|
||||
err = sess.streamsMap.DeleteClosedStreams()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
str, err = sess.GetOrOpenStream(3)
|
||||
|
@ -435,7 +435,7 @@ var _ = Describe("Session", func() {
|
|||
sess.streamsMap.newStream = func(id protocol.StreamID) streamI {
|
||||
str := newStreamLambda(id)
|
||||
if id == 5 {
|
||||
str.(*mocks.MockStreamI).EXPECT().HandleStopSendingFrame(f)
|
||||
str.(*MockStreamI).EXPECT().handleStopSendingFrame(f)
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
@ -457,7 +457,7 @@ var _ = Describe("Session", func() {
|
|||
It("ignores STOP_SENDING frames for a closed stream", func() {
|
||||
str, err := sess.GetOrOpenStream(3)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
str.(*mocks.MockStreamI).EXPECT().Finished().Return(true)
|
||||
str.(*MockStreamI).EXPECT().finished().Return(true)
|
||||
err = sess.streamsMap.DeleteClosedStreams()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
str, err = sess.GetOrOpenStream(3)
|
||||
|
@ -502,7 +502,7 @@ var _ = Describe("Session", func() {
|
|||
_, err := sess.GetOrOpenStream(5)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
sess.streamsMap.Range(func(s streamI) {
|
||||
s.(*mocks.MockStreamI).EXPECT().CloseForShutdown(gomock.Any())
|
||||
s.(*MockStreamI).EXPECT().closeForShutdown(gomock.Any())
|
||||
})
|
||||
err = sess.handleFrames([]wire.Frame{&wire.ConnectionCloseFrame{ErrorCode: qerr.ProofInvalid, ReasonPhrase: "foobar"}}, protocol.EncryptionUnspecified)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
@ -1114,7 +1114,7 @@ var _ = Describe("Session", func() {
|
|||
close(done)
|
||||
}()
|
||||
Eventually(sess.sendingScheduled).Should(Receive())
|
||||
s.(*stream).PopStreamFrame(1000) // unblock
|
||||
s.(*stream).popStreamFrame(1000) // unblock
|
||||
})
|
||||
|
||||
It("sets the timer to the ack timer", func() {
|
||||
|
@ -1501,8 +1501,8 @@ var _ = Describe("Session", func() {
|
|||
str, err := sess.GetOrOpenStream(9)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
str.Close()
|
||||
str.(*stream).CloseForShutdown(nil)
|
||||
Expect(str.(*stream).Finished()).To(BeTrue())
|
||||
str.(*stream).closeForShutdown(nil)
|
||||
Expect(str.(*stream).finished()).To(BeTrue())
|
||||
err = sess.streamsMap.DeleteClosedStreams()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(sess.streamsMap.GetOrOpenStream(9)).To(BeNil())
|
||||
|
@ -1537,7 +1537,7 @@ var _ = Describe("Session", func() {
|
|||
s, err := sess.GetOrOpenStream(protocol.StreamID(i*2 + 1))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(s.Close()).To(Succeed())
|
||||
f := s.(*stream).PopStreamFrame(1000) // trigger "sending" of the FIN bit
|
||||
f := s.(*stream).popStreamFrame(1000) // trigger "sending" of the FIN bit
|
||||
Expect(f.FinBit).To(BeTrue())
|
||||
s.(*stream).CloseRemote(0)
|
||||
_, err = s.Read([]byte("a"))
|
||||
|
|
32
stream.go
32
stream.go
|
@ -17,15 +17,15 @@ const (
|
|||
type streamI interface {
|
||||
Stream
|
||||
|
||||
HandleStreamFrame(*wire.StreamFrame) error
|
||||
HandleRstStreamFrame(*wire.RstStreamFrame) error
|
||||
HandleStopSendingFrame(*wire.StopSendingFrame)
|
||||
PopStreamFrame(maxBytes protocol.ByteCount) *wire.StreamFrame
|
||||
Finished() bool
|
||||
CloseForShutdown(error)
|
||||
handleStreamFrame(*wire.StreamFrame) error
|
||||
handleRstStreamFrame(*wire.RstStreamFrame) error
|
||||
handleStopSendingFrame(*wire.StopSendingFrame)
|
||||
popStreamFrame(maxBytes protocol.ByteCount) *wire.StreamFrame
|
||||
finished() bool
|
||||
closeForShutdown(error)
|
||||
// methods needed for flow control
|
||||
GetWindowUpdate() protocol.ByteCount
|
||||
HandleMaxStreamDataFrame(*wire.MaxStreamDataFrame)
|
||||
getWindowUpdate() protocol.ByteCount
|
||||
handleMaxStreamDataFrame(*wire.MaxStreamDataFrame)
|
||||
}
|
||||
|
||||
// A Stream assembles the data from StreamFrames and provides a super-convenient Read-Interface
|
||||
|
@ -96,17 +96,17 @@ func (s *stream) SetDeadline(t time.Time) error {
|
|||
// CloseForShutdown closes a stream abruptly.
|
||||
// It makes Read and Write unblock (and return the error) immediately.
|
||||
// The peer will NOT be informed about this: the stream is closed without sending a FIN or RST.
|
||||
func (s *stream) CloseForShutdown(err error) {
|
||||
s.sendStream.CloseForShutdown(err)
|
||||
s.receiveStream.CloseForShutdown(err)
|
||||
func (s *stream) closeForShutdown(err error) {
|
||||
s.sendStream.closeForShutdown(err)
|
||||
s.receiveStream.closeForShutdown(err)
|
||||
}
|
||||
|
||||
func (s *stream) HandleRstStreamFrame(frame *wire.RstStreamFrame) error {
|
||||
if err := s.receiveStream.HandleRstStreamFrame(frame); err != nil {
|
||||
func (s *stream) handleRstStreamFrame(frame *wire.RstStreamFrame) error {
|
||||
if err := s.receiveStream.handleRstStreamFrame(frame); err != nil {
|
||||
return err
|
||||
}
|
||||
if !s.version.UsesIETFFrameFormat() {
|
||||
s.HandleStopSendingFrame(&wire.StopSendingFrame{
|
||||
s.handleStopSendingFrame(&wire.StopSendingFrame{
|
||||
StreamID: s.StreamID(),
|
||||
ErrorCode: frame.ErrorCode,
|
||||
})
|
||||
|
@ -114,6 +114,6 @@ func (s *stream) HandleRstStreamFrame(frame *wire.RstStreamFrame) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *stream) Finished() bool {
|
||||
return s.sendStream.Finished() && s.receiveStream.Finished()
|
||||
func (s *stream) finished() bool {
|
||||
return s.sendStream.finished() && s.receiveStream.finished()
|
||||
}
|
||||
|
|
|
@ -39,12 +39,12 @@ func (f *streamFramer) HasFramesForRetransmission() bool {
|
|||
}
|
||||
|
||||
func (f *streamFramer) HasCryptoStreamFrame() bool {
|
||||
return f.cryptoStream.HasDataForWriting()
|
||||
return f.cryptoStream.hasDataForWriting()
|
||||
}
|
||||
|
||||
// TODO(lclemente): This is somewhat duplicate with the normal path for generating frames.
|
||||
func (f *streamFramer) PopCryptoStreamFrame(maxLen protocol.ByteCount) *wire.StreamFrame {
|
||||
return f.cryptoStream.PopStreamFrame(maxLen)
|
||||
return f.cryptoStream.popStreamFrame(maxLen)
|
||||
}
|
||||
|
||||
func (f *streamFramer) maybePopFramesForRetransmission(maxTotalLen protocol.ByteCount) (res []*wire.StreamFrame, currentLen protocol.ByteCount) {
|
||||
|
@ -84,7 +84,7 @@ func (f *streamFramer) maybePopNormalFrames(maxTotalLen protocol.ByteCount) (res
|
|||
if maxLen < protocol.MinStreamFrameSize { // don't try to add new STREAM frames, if only little space is left in the packet
|
||||
return false, nil
|
||||
}
|
||||
frame := s.PopStreamFrame(maxLen)
|
||||
frame := s.popStreamFrame(maxLen)
|
||||
if frame == nil {
|
||||
return true, nil
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bytes"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/lucas-clemente/quic-go/internal/mocks"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||
"github.com/lucas-clemente/quic-go/internal/wire"
|
||||
|
@ -22,11 +21,11 @@ var _ = Describe("Stream Framer", func() {
|
|||
retransmittedFrame1, retransmittedFrame2 *wire.StreamFrame
|
||||
framer *streamFramer
|
||||
streamsMap *streamsMap
|
||||
stream1, stream2 *mocks.MockStreamI
|
||||
stream1, stream2 *MockStreamI
|
||||
)
|
||||
|
||||
setNoData := func(str *mocks.MockStreamI) {
|
||||
str.EXPECT().PopStreamFrame(gomock.Any()).AnyTimes()
|
||||
setNoData := func(str *MockStreamI) {
|
||||
str.EXPECT().popStreamFrame(gomock.Any()).AnyTimes()
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
|
@ -39,9 +38,9 @@ var _ = Describe("Stream Framer", func() {
|
|||
Data: []byte{0xDE, 0xCA, 0xFB, 0xAD},
|
||||
}
|
||||
|
||||
stream1 = mocks.NewMockStreamI(mockCtrl)
|
||||
stream1 = NewMockStreamI(mockCtrl)
|
||||
stream1.EXPECT().StreamID().Return(protocol.StreamID(5)).AnyTimes()
|
||||
stream2 = mocks.NewMockStreamI(mockCtrl)
|
||||
stream2 = NewMockStreamI(mockCtrl)
|
||||
stream2.EXPECT().StreamID().Return(protocol.StreamID(6)).AnyTimes()
|
||||
|
||||
streamsMap = newStreamsMap(nil, protocol.PerspectiveServer, versionGQUICFrames)
|
||||
|
@ -114,7 +113,7 @@ var _ = Describe("Stream Framer", func() {
|
|||
Data: []byte("foobar"),
|
||||
Offset: 42,
|
||||
}
|
||||
stream1.EXPECT().PopStreamFrame(gomock.Any()).Return(f)
|
||||
stream1.EXPECT().popStreamFrame(gomock.Any()).Return(f)
|
||||
fs := framer.PopStreamFrames(1000)
|
||||
Expect(fs).To(Equal([]*wire.StreamFrame{f}))
|
||||
})
|
||||
|
@ -122,8 +121,8 @@ var _ = Describe("Stream Framer", func() {
|
|||
It("returns multiple normal frames", func() {
|
||||
f1 := &wire.StreamFrame{Data: []byte("foobar")}
|
||||
f2 := &wire.StreamFrame{Data: []byte("foobaz")}
|
||||
stream1.EXPECT().PopStreamFrame(gomock.Any()).Return(f1)
|
||||
stream2.EXPECT().PopStreamFrame(gomock.Any()).Return(f2)
|
||||
stream1.EXPECT().popStreamFrame(gomock.Any()).Return(f1)
|
||||
stream2.EXPECT().popStreamFrame(gomock.Any()).Return(f2)
|
||||
fs := framer.PopStreamFrames(1000)
|
||||
Expect(fs).To(HaveLen(2))
|
||||
Expect(fs).To(ContainElement(f1))
|
||||
|
@ -133,7 +132,7 @@ var _ = Describe("Stream Framer", func() {
|
|||
It("returns retransmission frames before normal frames", func() {
|
||||
setNoData(stream2)
|
||||
f1 := &wire.StreamFrame{Data: []byte("foobar")}
|
||||
stream1.EXPECT().PopStreamFrame(gomock.Any()).Return(f1)
|
||||
stream1.EXPECT().popStreamFrame(gomock.Any()).Return(f1)
|
||||
framer.AddFrameForRetransmission(retransmittedFrame1)
|
||||
fs := framer.PopStreamFrames(1000)
|
||||
Expect(fs).To(Equal([]*wire.StreamFrame{retransmittedFrame1, f1}))
|
||||
|
@ -147,7 +146,7 @@ var _ = Describe("Stream Framer", func() {
|
|||
})
|
||||
|
||||
It("pops frames that have the minimum size", func() {
|
||||
stream1.EXPECT().PopStreamFrame(protocol.MinStreamFrameSize).Return(&wire.StreamFrame{Data: []byte("foobar")})
|
||||
stream1.EXPECT().popStreamFrame(protocol.MinStreamFrameSize).Return(&wire.StreamFrame{Data: []byte("foobar")})
|
||||
framer.PopStreamFrames(protocol.MinStreamFrameSize)
|
||||
})
|
||||
|
||||
|
@ -157,16 +156,16 @@ var _ = Describe("Stream Framer", func() {
|
|||
})
|
||||
|
||||
It("uses the round-robin scheduling", func() {
|
||||
stream1.EXPECT().PopStreamFrame(gomock.Any()).Return(&wire.StreamFrame{
|
||||
stream1.EXPECT().popStreamFrame(gomock.Any()).Return(&wire.StreamFrame{
|
||||
StreamID: id1,
|
||||
Data: []byte("foobar"),
|
||||
})
|
||||
stream1.EXPECT().PopStreamFrame(gomock.Any()).MaxTimes(1)
|
||||
stream2.EXPECT().PopStreamFrame(gomock.Any()).Return(&wire.StreamFrame{
|
||||
stream1.EXPECT().popStreamFrame(gomock.Any()).MaxTimes(1)
|
||||
stream2.EXPECT().popStreamFrame(gomock.Any()).Return(&wire.StreamFrame{
|
||||
StreamID: id2,
|
||||
Data: []byte("foobaz"),
|
||||
})
|
||||
stream2.EXPECT().PopStreamFrame(gomock.Any()).MaxTimes(1)
|
||||
stream2.EXPECT().popStreamFrame(gomock.Any()).MaxTimes(1)
|
||||
fs := framer.PopStreamFrames(protocol.MinStreamFrameSize)
|
||||
Expect(fs).To(HaveLen(1))
|
||||
// it doesn't matter here if this data is from stream1 or from stream2...
|
||||
|
@ -183,7 +182,7 @@ var _ = Describe("Stream Framer", func() {
|
|||
StreamID: id1,
|
||||
Data: bytes.Repeat([]byte("f"), int(500-protocol.MinStreamFrameSize)),
|
||||
}
|
||||
stream1.EXPECT().PopStreamFrame(protocol.ByteCount(500)).Return(f)
|
||||
stream1.EXPECT().popStreamFrame(protocol.ByteCount(500)).Return(f)
|
||||
setNoData(stream2)
|
||||
fs := framer.PopStreamFrames(500)
|
||||
Expect(fs).To(Equal([]*wire.StreamFrame{f}))
|
||||
|
|
|
@ -91,7 +91,7 @@ var _ = Describe("Stream", func() {
|
|||
close(writeReturned)
|
||||
}()
|
||||
Consistently(writeReturned).ShouldNot(BeClosed())
|
||||
err := str.HandleRstStreamFrame(f)
|
||||
err := str.handleRstStreamFrame(f)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(queuedControlFrames).To(Equal([]wire.Frame{
|
||||
&wire.RstStreamFrame{
|
||||
|
@ -122,7 +122,7 @@ var _ = Describe("Stream", func() {
|
|||
close(writeReturned)
|
||||
}()
|
||||
Consistently(writeReturned).ShouldNot(BeClosed())
|
||||
err := str.HandleRstStreamFrame(f)
|
||||
err := str.handleRstStreamFrame(f)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(queuedControlFrames).To(Equal([]wire.Frame{
|
||||
&wire.RstStreamFrame{
|
||||
|
@ -149,7 +149,7 @@ var _ = Describe("Stream", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
close(writeReturned)
|
||||
}()
|
||||
Eventually(func() *wire.StreamFrame { return str.PopStreamFrame(1000) }).ShouldNot(BeNil())
|
||||
Eventually(func() *wire.StreamFrame { return str.popStreamFrame(1000) }).ShouldNot(BeNil())
|
||||
Eventually(writeReturned).Should(BeClosed())
|
||||
Expect(queuedControlFrames).To(BeEmpty()) // no RST_STREAM frame queued yet
|
||||
err = str.Close()
|
||||
|
@ -187,7 +187,7 @@ var _ = Describe("Stream", func() {
|
|||
It("sets a read deadline, when SetDeadline is called", func() {
|
||||
mockFC.EXPECT().UpdateHighestReceived(protocol.ByteCount(6), false).AnyTimes()
|
||||
f := &wire.StreamFrame{Data: []byte("foobar")}
|
||||
err := str.HandleStreamFrame(f)
|
||||
err := str.handleStreamFrame(f)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
str.SetDeadline(time.Now().Add(-time.Second))
|
||||
b := make([]byte, 6)
|
||||
|
@ -199,24 +199,24 @@ var _ = Describe("Stream", func() {
|
|||
|
||||
Context("saying if it is finished", func() {
|
||||
It("is finished when both the send and the receive side are finished", func() {
|
||||
str.receiveStream.CloseForShutdown(errors.New("shutdown"))
|
||||
Expect(str.receiveStream.Finished()).To(BeTrue())
|
||||
Expect(str.sendStream.Finished()).To(BeFalse())
|
||||
Expect(str.Finished()).To(BeFalse())
|
||||
str.receiveStream.closeForShutdown(errors.New("shutdown"))
|
||||
Expect(str.receiveStream.finished()).To(BeTrue())
|
||||
Expect(str.sendStream.finished()).To(BeFalse())
|
||||
Expect(str.finished()).To(BeFalse())
|
||||
})
|
||||
|
||||
It("is not finished when the receive side is finished", func() {
|
||||
str.sendStream.CloseForShutdown(errors.New("shutdown"))
|
||||
Expect(str.receiveStream.Finished()).To(BeFalse())
|
||||
Expect(str.sendStream.Finished()).To(BeTrue())
|
||||
Expect(str.Finished()).To(BeFalse())
|
||||
str.sendStream.closeForShutdown(errors.New("shutdown"))
|
||||
Expect(str.receiveStream.finished()).To(BeFalse())
|
||||
Expect(str.sendStream.finished()).To(BeTrue())
|
||||
Expect(str.finished()).To(BeFalse())
|
||||
})
|
||||
|
||||
It("is not finished when the send side is finished", func() {
|
||||
str.CloseForShutdown(errors.New("shutdown"))
|
||||
Expect(str.receiveStream.Finished()).To(BeTrue())
|
||||
Expect(str.sendStream.Finished()).To(BeTrue())
|
||||
Expect(str.Finished()).To(BeTrue())
|
||||
str.closeForShutdown(errors.New("shutdown"))
|
||||
Expect(str.receiveStream.finished()).To(BeTrue())
|
||||
Expect(str.sendStream.finished()).To(BeTrue())
|
||||
Expect(str.finished()).To(BeTrue())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -220,7 +220,7 @@ func (m *streamsMap) DeleteClosedStreams() error {
|
|||
if !ok {
|
||||
return errMapAccess
|
||||
}
|
||||
if !str.Finished() {
|
||||
if !str.finished() {
|
||||
continue
|
||||
}
|
||||
numDeletedStreams++
|
||||
|
@ -317,7 +317,7 @@ func (m *streamsMap) CloseWithError(err error) {
|
|||
m.nextStreamOrErrCond.Broadcast()
|
||||
m.openStreamOrErrCond.Broadcast()
|
||||
for _, s := range m.openStreams {
|
||||
m.streams[s].CloseForShutdown(err)
|
||||
m.streams[s].closeForShutdown(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"errors"
|
||||
"sort"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/internal/mocks"
|
||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||
"github.com/lucas-clemente/quic-go/qerr"
|
||||
|
||||
|
@ -20,9 +19,9 @@ var _ = Describe("Streams Map", func() {
|
|||
)
|
||||
|
||||
newStream := func(id protocol.StreamID) streamI {
|
||||
str := mocks.NewMockStreamI(mockCtrl)
|
||||
str := NewMockStreamI(mockCtrl)
|
||||
str.EXPECT().StreamID().Return(id).AnyTimes()
|
||||
c := str.EXPECT().Finished().Return(false).AnyTimes()
|
||||
c := str.EXPECT().finished().Return(false).AnyTimes()
|
||||
finishedStreams[id] = c
|
||||
return str
|
||||
}
|
||||
|
@ -245,7 +244,7 @@ var _ = Describe("Streams Map", func() {
|
|||
testErr := errors.New("test error")
|
||||
openMaxNumStreams()
|
||||
for _, str := range m.streams {
|
||||
str.(*mocks.MockStreamI).EXPECT().CloseForShutdown(testErr)
|
||||
str.(*MockStreamI).EXPECT().closeForShutdown(testErr)
|
||||
}
|
||||
|
||||
done := make(chan struct{})
|
||||
|
@ -551,7 +550,7 @@ var _ = Describe("Streams Map", func() {
|
|||
It("does not delete streams with Close()", func() {
|
||||
str, err := m.GetOrOpenStream(55)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
str.(*mocks.MockStreamI).EXPECT().Close()
|
||||
str.(*MockStreamI).EXPECT().Close()
|
||||
str.Close()
|
||||
err = m.DeleteClosedStreams()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -678,7 +677,7 @@ var _ = Describe("Streams Map", func() {
|
|||
BeforeEach(func() {
|
||||
callbackCalledForStream = callbackCalledForStream[:0]
|
||||
for i := 4; i <= 8; i++ {
|
||||
str := mocks.NewMockStreamI(mockCtrl)
|
||||
str := NewMockStreamI(mockCtrl)
|
||||
str.EXPECT().StreamID().Return(protocol.StreamID(i)).AnyTimes()
|
||||
err := m.putStream(str)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue