1package ackhandler
2
3import (
4	"time"
5
6	"github.com/lucas-clemente/quic-go/internal/protocol"
7	"github.com/lucas-clemente/quic-go/internal/wire"
8	"github.com/lucas-clemente/quic-go/quictrace"
9)
10
11// A Packet is a packet
12type Packet struct {
13	PacketNumber    protocol.PacketNumber
14	Frames          []Frame
15	LargestAcked    protocol.PacketNumber // InvalidPacketNumber if the packet doesn't contain an ACK
16	Length          protocol.ByteCount
17	EncryptionLevel protocol.EncryptionLevel
18	SendTime        time.Time
19
20	includedInBytesInFlight bool
21	declaredLost            bool
22	skippedPacket           bool
23}
24
25// SentPacketHandler handles ACKs received for outgoing packets
26type SentPacketHandler interface {
27	// SentPacket may modify the packet
28	SentPacket(packet *Packet)
29	ReceivedAck(ackFrame *wire.AckFrame, encLevel protocol.EncryptionLevel, recvTime time.Time) error
30	ReceivedBytes(protocol.ByteCount)
31	DropPackets(protocol.EncryptionLevel)
32	ResetForRetry() error
33	SetHandshakeConfirmed()
34
35	// The SendMode determines if and what kind of packets can be sent.
36	SendMode() SendMode
37	// TimeUntilSend is the time when the next packet should be sent.
38	// It is used for pacing packets.
39	TimeUntilSend() time.Time
40	// HasPacingBudget says if the pacer allows sending of a (full size) packet at this moment.
41	HasPacingBudget() bool
42
43	// only to be called once the handshake is complete
44	QueueProbePacket(protocol.EncryptionLevel) bool /* was a packet queued */
45
46	PeekPacketNumber(protocol.EncryptionLevel) (protocol.PacketNumber, protocol.PacketNumberLen)
47	PopPacketNumber(protocol.EncryptionLevel) protocol.PacketNumber
48
49	GetLossDetectionTimeout() time.Time
50	OnLossDetectionTimeout() error
51
52	// report some congestion statistics. For tracing only.
53	GetStats() *quictrace.TransportState
54}
55
56type sentPacketTracker interface {
57	GetLowestPacketNotConfirmedAcked() protocol.PacketNumber
58	ReceivedPacket(protocol.EncryptionLevel)
59}
60
61// ReceivedPacketHandler handles ACKs needed to send for incoming packets
62type ReceivedPacketHandler interface {
63	IsPotentiallyDuplicate(protocol.PacketNumber, protocol.EncryptionLevel) bool
64	ReceivedPacket(pn protocol.PacketNumber, ecn protocol.ECN, encLevel protocol.EncryptionLevel, rcvTime time.Time, shouldInstigateAck bool) error
65	DropPackets(protocol.EncryptionLevel)
66
67	GetAlarmTimeout() time.Time
68	GetAckFrame(encLevel protocol.EncryptionLevel, onlyIfQueued bool) *wire.AckFrame
69}
70