remove unneeded cryptoStream interface (#4617)

This commit is contained in:
Marten Seemann
2024-08-03 17:16:02 -07:00
committed by GitHub
parent f5ceb73171
commit 931166bb8e
7 changed files with 31 additions and 45 deletions

View File

@@ -152,9 +152,9 @@ type connection struct {
maxPayloadSizeEstimate atomic.Uint32 maxPayloadSizeEstimate atomic.Uint32
initialStream cryptoStream initialStream *cryptoStream
handshakeStream cryptoStream handshakeStream *cryptoStream
oneRTTStream cryptoStream // only set for the server oneRTTStream *cryptoStream // only set for the server
cryptoStreamHandler cryptoStreamHandler cryptoStreamHandler cryptoStreamHandler
receivedPackets chan receivedPacket receivedPackets chan receivedPacket

View File

@@ -2,25 +2,13 @@ package quic
import ( import (
"fmt" "fmt"
"io"
"github.com/quic-go/quic-go/internal/protocol" "github.com/quic-go/quic-go/internal/protocol"
"github.com/quic-go/quic-go/internal/qerr" "github.com/quic-go/quic-go/internal/qerr"
"github.com/quic-go/quic-go/internal/wire" "github.com/quic-go/quic-go/internal/wire"
) )
type cryptoStream interface { type cryptoStream struct {
// 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 {
queue frameSorter queue frameSorter
highestOffset protocol.ByteCount highestOffset protocol.ByteCount
@@ -30,11 +18,11 @@ type cryptoStreamImpl struct {
writeBuf []byte writeBuf []byte
} }
func newCryptoStream() cryptoStream { func newCryptoStream() *cryptoStream {
return &cryptoStreamImpl{queue: *newFrameSorter()} 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)) highestOffset := f.Offset + protocol.ByteCount(len(f.Data))
if maxOffset := highestOffset; maxOffset > protocol.MaxCryptoStreamOffset { if maxOffset := highestOffset; maxOffset > protocol.MaxCryptoStreamOffset {
return &qerr.TransportError{ return &qerr.TransportError{
@@ -59,12 +47,12 @@ func (s *cryptoStreamImpl) HandleCryptoFrame(f *wire.CryptoFrame) error {
} }
// GetCryptoData retrieves data that was received in CRYPTO frames // GetCryptoData retrieves data that was received in CRYPTO frames
func (s *cryptoStreamImpl) GetCryptoData() []byte { func (s *cryptoStream) GetCryptoData() []byte {
_, data, _ := s.queue.Pop() _, data, _ := s.queue.Pop()
return data return data
} }
func (s *cryptoStreamImpl) Finish() error { func (s *cryptoStream) Finish() error {
if s.queue.HasMoreData() { if s.queue.HasMoreData() {
return &qerr.TransportError{ return &qerr.TransportError{
ErrorCode: qerr.ProtocolViolation, ErrorCode: qerr.ProtocolViolation,
@@ -76,16 +64,16 @@ func (s *cryptoStreamImpl) Finish() error {
} }
// Writes writes data that should be sent out in CRYPTO frames // 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...) s.writeBuf = append(s.writeBuf, p...)
return len(p), nil return len(p), nil
} }
func (s *cryptoStreamImpl) HasData() bool { func (s *cryptoStream) HasData() bool {
return len(s.writeBuf) > 0 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} f := &wire.CryptoFrame{Offset: s.writeOffset}
n := min(f.MaxDataLen(maxLen), protocol.ByteCount(len(s.writeBuf))) n := min(f.MaxDataLen(maxLen), protocol.ByteCount(len(s.writeBuf)))
f.Data = s.writeBuf[:n] f.Data = s.writeBuf[:n]

View File

@@ -8,15 +8,15 @@ import (
) )
type cryptoStreamManager struct { type cryptoStreamManager struct {
initialStream cryptoStream initialStream *cryptoStream
handshakeStream cryptoStream handshakeStream *cryptoStream
oneRTTStream cryptoStream oneRTTStream *cryptoStream
} }
func newCryptoStreamManager( func newCryptoStreamManager(
initialStream cryptoStream, initialStream *cryptoStream,
handshakeStream cryptoStream, handshakeStream *cryptoStream,
oneRTTStream cryptoStream, oneRTTStream *cryptoStream,
) *cryptoStreamManager { ) *cryptoStreamManager {
return &cryptoStreamManager{ return &cryptoStreamManager{
initialStream: initialStream, initialStream: initialStream,
@@ -26,7 +26,7 @@ func newCryptoStreamManager(
} }
func (m *cryptoStreamManager) HandleCryptoFrame(frame *wire.CryptoFrame, encLevel protocol.EncryptionLevel) error { 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. //nolint:exhaustive // CRYPTO frames cannot be sent in 0-RTT packets.
switch encLevel { switch encLevel {
case protocol.EncryptionInitial: case protocol.EncryptionInitial:
@@ -42,7 +42,7 @@ func (m *cryptoStreamManager) HandleCryptoFrame(frame *wire.CryptoFrame, encLeve
} }
func (m *cryptoStreamManager) GetCryptoData(encLevel protocol.EncryptionLevel) []byte { 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. //nolint:exhaustive // CRYPTO frames cannot be sent in 0-RTT packets.
switch encLevel { switch encLevel {
case protocol.EncryptionInitial: case protocol.EncryptionInitial:

View File

@@ -12,9 +12,9 @@ var _ = Describe("Crypto Stream Manager", func() {
var ( var (
csm *cryptoStreamManager csm *cryptoStreamManager
initialStream cryptoStream initialStream *cryptoStream
handshakeStream cryptoStream handshakeStream *cryptoStream
oneRTTStream cryptoStream oneRTTStream *cryptoStream
) )
BeforeEach(func() { BeforeEach(func() {

View File

@@ -12,11 +12,9 @@ import (
) )
var _ = Describe("Crypto Stream", func() { var _ = Describe("Crypto Stream", func() {
var str cryptoStream var str *cryptoStream
BeforeEach(func() { BeforeEach(func() { str = newCryptoStream() })
str = newCryptoStream()
})
Context("handling incoming data", func() { Context("handling incoming data", func() {
It("handles in-order CRYPTO frames", func() { It("handles in-order CRYPTO frames", func() {

View File

@@ -121,8 +121,8 @@ type packetPacker struct {
perspective protocol.Perspective perspective protocol.Perspective
cryptoSetup sealingManager cryptoSetup sealingManager
initialStream cryptoStream initialStream *cryptoStream
handshakeStream cryptoStream handshakeStream *cryptoStream
token []byte token []byte
@@ -141,7 +141,7 @@ var _ packer = &packetPacker{}
func newPacketPacker( func newPacketPacker(
srcConnID protocol.ConnectionID, srcConnID protocol.ConnectionID,
getDestConnID func() protocol.ConnectionID, getDestConnID func() protocol.ConnectionID,
initialStream, handshakeStream cryptoStream, initialStream, handshakeStream *cryptoStream,
packetNumberManager packetNumberManager, packetNumberManager packetNumberManager,
retransmissionQueue *retransmissionQueue, retransmissionQueue *retransmissionQueue,
cryptoSetup sealingManager, cryptoSetup sealingManager,
@@ -482,7 +482,7 @@ func (p *packetPacker) maybeGetCryptoPacket(maxPacketSize protocol.ByteCount, en
return nil, payload{} return nil, payload{}
} }
var s cryptoStream var s *cryptoStream
var handler ackhandler.FrameHandler var handler ackhandler.FrameHandler
var hasRetransmission bool var hasRetransmission bool
//nolint:exhaustive // Initial and Handshake are the only two encryption levels here. //nolint:exhaustive // Initial and Handshake are the only two encryption levels here.

View File

@@ -31,8 +31,8 @@ var _ = Describe("Packet packer", func() {
datagramQueue *datagramQueue datagramQueue *datagramQueue
framer *MockFrameSource framer *MockFrameSource
ackFramer *MockAckFrameSource ackFramer *MockAckFrameSource
initialStream cryptoStream initialStream *cryptoStream
handshakeStream cryptoStream handshakeStream *cryptoStream
sealingManager *MockSealingManager sealingManager *MockSealingManager
pnManager *mockackhandler.MockSentPacketHandler pnManager *mockackhandler.MockSentPacketHandler
) )