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