mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
use a single constructor for SentPacketHandler and ReceivedPacketHandler
This commit is contained in:
parent
e9cdb29ef9
commit
f317a471bb
6 changed files with 45 additions and 10 deletions
22
internal/ackhandler/ackhandler.go
Normal file
22
internal/ackhandler/ackhandler.go
Normal 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)
|
||||
}
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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},
|
||||
|
|
21
session.go
21
session.go
|
@ -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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue