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{}
// NewReceivedPacketHandler creates a new receivedPacketHandler
func NewReceivedPacketHandler(
func newReceivedPacketHandler(
rttStats *congestion.RTTStats,
logger utils.Logger,
version protocol.VersionNumber,

View file

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

View file

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

View file

@ -27,7 +27,7 @@ var _ = Describe("SentPacketHandler", func() {
JustBeforeEach(func() {
lostPackets = nil
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{
StreamID: 5,
Data: []byte{0x13, 0x37},

View file

@ -249,7 +249,15 @@ var newSession = func(
s.queueControlFrame,
)
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()
handshakeStream := newCryptoStream()
params := &handshake.TransportParameters{
@ -354,7 +362,15 @@ var newClientSession = func(
s.queueControlFrame,
)
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()
handshakeStream := newCryptoStream()
params := &handshake.TransportParameters{
@ -424,7 +440,6 @@ func (s *session) preSetup() {
s.retransmissionQueue = newRetransmissionQueue(s.version)
s.frameParser = wire.NewFrameParser(s.version)
s.rttStats = &congestion.RTTStats{}
s.receivedPacketHandler = ackhandler.NewReceivedPacketHandler(s.rttStats, s.logger, s.version)
s.connFlowController = flowcontrol.NewConnectionFlowController(
protocol.InitialMaxData,
protocol.ByteCount(s.config.MaxReceiveConnectionFlowControlWindow),