forked from quic-go/quic-go
remove unneeded cryptoStream interface (#4617)
This commit is contained in:
@@ -152,9 +152,9 @@ type connection struct {
|
||||
|
||||
maxPayloadSizeEstimate atomic.Uint32
|
||||
|
||||
initialStream cryptoStream
|
||||
handshakeStream cryptoStream
|
||||
oneRTTStream cryptoStream // only set for the server
|
||||
initialStream *cryptoStream
|
||||
handshakeStream *cryptoStream
|
||||
oneRTTStream *cryptoStream // only set for the server
|
||||
cryptoStreamHandler cryptoStreamHandler
|
||||
|
||||
receivedPackets chan receivedPacket
|
||||
|
||||
@@ -2,25 +2,13 @@ package quic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/quic-go/quic-go/internal/protocol"
|
||||
"github.com/quic-go/quic-go/internal/qerr"
|
||||
"github.com/quic-go/quic-go/internal/wire"
|
||||
)
|
||||
|
||||
type cryptoStream interface {
|
||||
// for receiving data
|
||||
HandleCryptoFrame(*wire.CryptoFrame) error
|
||||
GetCryptoData() []byte
|
||||
Finish() error
|
||||
// for sending data
|
||||
io.Writer
|
||||
HasData() bool
|
||||
PopCryptoFrame(protocol.ByteCount) *wire.CryptoFrame
|
||||
}
|
||||
|
||||
type cryptoStreamImpl struct {
|
||||
type cryptoStream struct {
|
||||
queue frameSorter
|
||||
|
||||
highestOffset protocol.ByteCount
|
||||
@@ -30,11 +18,11 @@ type cryptoStreamImpl struct {
|
||||
writeBuf []byte
|
||||
}
|
||||
|
||||
func newCryptoStream() cryptoStream {
|
||||
return &cryptoStreamImpl{queue: *newFrameSorter()}
|
||||
func newCryptoStream() *cryptoStream {
|
||||
return &cryptoStream{queue: *newFrameSorter()}
|
||||
}
|
||||
|
||||
func (s *cryptoStreamImpl) HandleCryptoFrame(f *wire.CryptoFrame) error {
|
||||
func (s *cryptoStream) HandleCryptoFrame(f *wire.CryptoFrame) error {
|
||||
highestOffset := f.Offset + protocol.ByteCount(len(f.Data))
|
||||
if maxOffset := highestOffset; maxOffset > protocol.MaxCryptoStreamOffset {
|
||||
return &qerr.TransportError{
|
||||
@@ -59,12 +47,12 @@ func (s *cryptoStreamImpl) HandleCryptoFrame(f *wire.CryptoFrame) error {
|
||||
}
|
||||
|
||||
// GetCryptoData retrieves data that was received in CRYPTO frames
|
||||
func (s *cryptoStreamImpl) GetCryptoData() []byte {
|
||||
func (s *cryptoStream) GetCryptoData() []byte {
|
||||
_, data, _ := s.queue.Pop()
|
||||
return data
|
||||
}
|
||||
|
||||
func (s *cryptoStreamImpl) Finish() error {
|
||||
func (s *cryptoStream) Finish() error {
|
||||
if s.queue.HasMoreData() {
|
||||
return &qerr.TransportError{
|
||||
ErrorCode: qerr.ProtocolViolation,
|
||||
@@ -76,16 +64,16 @@ func (s *cryptoStreamImpl) Finish() error {
|
||||
}
|
||||
|
||||
// Writes writes data that should be sent out in CRYPTO frames
|
||||
func (s *cryptoStreamImpl) Write(p []byte) (int, error) {
|
||||
func (s *cryptoStream) Write(p []byte) (int, error) {
|
||||
s.writeBuf = append(s.writeBuf, p...)
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
func (s *cryptoStreamImpl) HasData() bool {
|
||||
func (s *cryptoStream) HasData() bool {
|
||||
return len(s.writeBuf) > 0
|
||||
}
|
||||
|
||||
func (s *cryptoStreamImpl) PopCryptoFrame(maxLen protocol.ByteCount) *wire.CryptoFrame {
|
||||
func (s *cryptoStream) PopCryptoFrame(maxLen protocol.ByteCount) *wire.CryptoFrame {
|
||||
f := &wire.CryptoFrame{Offset: s.writeOffset}
|
||||
n := min(f.MaxDataLen(maxLen), protocol.ByteCount(len(s.writeBuf)))
|
||||
f.Data = s.writeBuf[:n]
|
||||
|
||||
@@ -8,15 +8,15 @@ import (
|
||||
)
|
||||
|
||||
type cryptoStreamManager struct {
|
||||
initialStream cryptoStream
|
||||
handshakeStream cryptoStream
|
||||
oneRTTStream cryptoStream
|
||||
initialStream *cryptoStream
|
||||
handshakeStream *cryptoStream
|
||||
oneRTTStream *cryptoStream
|
||||
}
|
||||
|
||||
func newCryptoStreamManager(
|
||||
initialStream cryptoStream,
|
||||
handshakeStream cryptoStream,
|
||||
oneRTTStream cryptoStream,
|
||||
initialStream *cryptoStream,
|
||||
handshakeStream *cryptoStream,
|
||||
oneRTTStream *cryptoStream,
|
||||
) *cryptoStreamManager {
|
||||
return &cryptoStreamManager{
|
||||
initialStream: initialStream,
|
||||
@@ -26,7 +26,7 @@ func newCryptoStreamManager(
|
||||
}
|
||||
|
||||
func (m *cryptoStreamManager) HandleCryptoFrame(frame *wire.CryptoFrame, encLevel protocol.EncryptionLevel) error {
|
||||
var str cryptoStream
|
||||
var str *cryptoStream
|
||||
//nolint:exhaustive // CRYPTO frames cannot be sent in 0-RTT packets.
|
||||
switch encLevel {
|
||||
case protocol.EncryptionInitial:
|
||||
@@ -42,7 +42,7 @@ func (m *cryptoStreamManager) HandleCryptoFrame(frame *wire.CryptoFrame, encLeve
|
||||
}
|
||||
|
||||
func (m *cryptoStreamManager) GetCryptoData(encLevel protocol.EncryptionLevel) []byte {
|
||||
var str cryptoStream
|
||||
var str *cryptoStream
|
||||
//nolint:exhaustive // CRYPTO frames cannot be sent in 0-RTT packets.
|
||||
switch encLevel {
|
||||
case protocol.EncryptionInitial:
|
||||
|
||||
@@ -12,9 +12,9 @@ var _ = Describe("Crypto Stream Manager", func() {
|
||||
var (
|
||||
csm *cryptoStreamManager
|
||||
|
||||
initialStream cryptoStream
|
||||
handshakeStream cryptoStream
|
||||
oneRTTStream cryptoStream
|
||||
initialStream *cryptoStream
|
||||
handshakeStream *cryptoStream
|
||||
oneRTTStream *cryptoStream
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
|
||||
@@ -12,11 +12,9 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("Crypto Stream", func() {
|
||||
var str cryptoStream
|
||||
var str *cryptoStream
|
||||
|
||||
BeforeEach(func() {
|
||||
str = newCryptoStream()
|
||||
})
|
||||
BeforeEach(func() { str = newCryptoStream() })
|
||||
|
||||
Context("handling incoming data", func() {
|
||||
It("handles in-order CRYPTO frames", func() {
|
||||
|
||||
@@ -121,8 +121,8 @@ type packetPacker struct {
|
||||
perspective protocol.Perspective
|
||||
cryptoSetup sealingManager
|
||||
|
||||
initialStream cryptoStream
|
||||
handshakeStream cryptoStream
|
||||
initialStream *cryptoStream
|
||||
handshakeStream *cryptoStream
|
||||
|
||||
token []byte
|
||||
|
||||
@@ -141,7 +141,7 @@ var _ packer = &packetPacker{}
|
||||
func newPacketPacker(
|
||||
srcConnID protocol.ConnectionID,
|
||||
getDestConnID func() protocol.ConnectionID,
|
||||
initialStream, handshakeStream cryptoStream,
|
||||
initialStream, handshakeStream *cryptoStream,
|
||||
packetNumberManager packetNumberManager,
|
||||
retransmissionQueue *retransmissionQueue,
|
||||
cryptoSetup sealingManager,
|
||||
@@ -482,7 +482,7 @@ func (p *packetPacker) maybeGetCryptoPacket(maxPacketSize protocol.ByteCount, en
|
||||
return nil, payload{}
|
||||
}
|
||||
|
||||
var s cryptoStream
|
||||
var s *cryptoStream
|
||||
var handler ackhandler.FrameHandler
|
||||
var hasRetransmission bool
|
||||
//nolint:exhaustive // Initial and Handshake are the only two encryption levels here.
|
||||
|
||||
@@ -31,8 +31,8 @@ var _ = Describe("Packet packer", func() {
|
||||
datagramQueue *datagramQueue
|
||||
framer *MockFrameSource
|
||||
ackFramer *MockAckFrameSource
|
||||
initialStream cryptoStream
|
||||
handshakeStream cryptoStream
|
||||
initialStream *cryptoStream
|
||||
handshakeStream *cryptoStream
|
||||
sealingManager *MockSealingManager
|
||||
pnManager *mockackhandler.MockSentPacketHandler
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user