use a single constructor for SentPacketHandler and ReceivedPacketHandler

This commit is contained in:
Marten Seemann 2020-02-20 18:19:52 +07:00
parent e9cdb29ef9
commit f317a471bb
6 changed files with 45 additions and 10 deletions

View file

@ -0,0 +1,22 @@
package ackhandler
import (
"github.com/lucas-clemente/quic-go/internal/congestion"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/utils"
"github.com/lucas-clemente/quic-go/qlog"
"github.com/lucas-clemente/quic-go/quictrace"
)
func NewAckHandler(
initialPacketNumber protocol.PacketNumber,
rttStats *congestion.RTTStats,
pers protocol.Perspective,
traceCallback func(quictrace.Event),
qlogger qlog.Tracer,
logger utils.Logger,
version protocol.VersionNumber,
) (SentPacketHandler, ReceivedPacketHandler) {
return newSentPacketHandler(initialPacketNumber, rttStats, pers, traceCallback, qlogger, logger),
newReceivedPacketHandler(rttStats, logger, version)
}

View file

@ -41,8 +41,7 @@ type receivedPacketHandler struct {
var _ ReceivedPacketHandler = &receivedPacketHandler{} var _ ReceivedPacketHandler = &receivedPacketHandler{}
// NewReceivedPacketHandler creates a new receivedPacketHandler func newReceivedPacketHandler(
func NewReceivedPacketHandler(
rttStats *congestion.RTTStats, rttStats *congestion.RTTStats,
logger utils.Logger, logger utils.Logger,
version protocol.VersionNumber, version protocol.VersionNumber,

View file

@ -16,7 +16,7 @@ var _ = Describe("Received Packet Handler", func() {
var handler ReceivedPacketHandler var handler ReceivedPacketHandler
BeforeEach(func() { BeforeEach(func() {
handler = NewReceivedPacketHandler( handler = newReceivedPacketHandler(
&congestion.RTTStats{}, &congestion.RTTStats{},
utils.DefaultLogger, utils.DefaultLogger,
protocol.VersionWhatever, protocol.VersionWhatever,

View file

@ -80,15 +80,14 @@ type sentPacketHandler struct {
logger utils.Logger logger utils.Logger
} }
// NewSentPacketHandler creates a new sentPacketHandler func newSentPacketHandler(
func NewSentPacketHandler(
initialPacketNumber protocol.PacketNumber, initialPacketNumber protocol.PacketNumber,
rttStats *congestion.RTTStats, rttStats *congestion.RTTStats,
pers protocol.Perspective, pers protocol.Perspective,
traceCallback func(quictrace.Event), traceCallback func(quictrace.Event),
qlogger qlog.Tracer, qlogger qlog.Tracer,
logger utils.Logger, logger utils.Logger,
) SentPacketHandler { ) *sentPacketHandler {
congestion := congestion.NewCubicSender( congestion := congestion.NewCubicSender(
congestion.DefaultClock{}, congestion.DefaultClock{},
rttStats, rttStats,

View file

@ -27,7 +27,7 @@ var _ = Describe("SentPacketHandler", func() {
JustBeforeEach(func() { JustBeforeEach(func() {
lostPackets = nil lostPackets = nil
rttStats := &congestion.RTTStats{} rttStats := &congestion.RTTStats{}
handler = NewSentPacketHandler(42, rttStats, perspective, nil, nil, utils.DefaultLogger).(*sentPacketHandler) handler = newSentPacketHandler(42, rttStats, perspective, nil, nil, utils.DefaultLogger)
streamFrame = wire.StreamFrame{ streamFrame = wire.StreamFrame{
StreamID: 5, StreamID: 5,
Data: []byte{0x13, 0x37}, Data: []byte{0x13, 0x37},

View file

@ -249,7 +249,15 @@ var newSession = func(
s.queueControlFrame, s.queueControlFrame,
) )
s.preSetup() s.preSetup()
s.sentPacketHandler = ackhandler.NewSentPacketHandler(0, s.rttStats, protocol.PerspectiveServer, s.traceCallback, s.qlogger, s.logger) s.sentPacketHandler, s.receivedPacketHandler = ackhandler.NewAckHandler(
0,
s.rttStats,
s.perspective,
s.traceCallback,
s.qlogger,
s.logger,
s.version,
)
initialStream := newCryptoStream() initialStream := newCryptoStream()
handshakeStream := newCryptoStream() handshakeStream := newCryptoStream()
params := &handshake.TransportParameters{ params := &handshake.TransportParameters{
@ -354,7 +362,15 @@ var newClientSession = func(
s.queueControlFrame, s.queueControlFrame,
) )
s.preSetup() s.preSetup()
s.sentPacketHandler = ackhandler.NewSentPacketHandler(initialPacketNumber, s.rttStats, protocol.PerspectiveClient, s.traceCallback, s.qlogger, s.logger) s.sentPacketHandler, s.receivedPacketHandler = ackhandler.NewAckHandler(
initialPacketNumber,
s.rttStats,
s.perspective,
s.traceCallback,
s.qlogger,
s.logger,
s.version,
)
initialStream := newCryptoStream() initialStream := newCryptoStream()
handshakeStream := newCryptoStream() handshakeStream := newCryptoStream()
params := &handshake.TransportParameters{ params := &handshake.TransportParameters{
@ -424,7 +440,6 @@ func (s *session) preSetup() {
s.retransmissionQueue = newRetransmissionQueue(s.version) s.retransmissionQueue = newRetransmissionQueue(s.version)
s.frameParser = wire.NewFrameParser(s.version) s.frameParser = wire.NewFrameParser(s.version)
s.rttStats = &congestion.RTTStats{} s.rttStats = &congestion.RTTStats{}
s.receivedPacketHandler = ackhandler.NewReceivedPacketHandler(s.rttStats, s.logger, s.version)
s.connFlowController = flowcontrol.NewConnectionFlowController( s.connFlowController = flowcontrol.NewConnectionFlowController(
protocol.InitialMaxData, protocol.InitialMaxData,
protocol.ByteCount(s.config.MaxReceiveConnectionFlowControlWindow), protocol.ByteCount(s.config.MaxReceiveConnectionFlowControlWindow),