Skip to content

Commit

Permalink
quic: add packetFate enum
Browse files Browse the repository at this point in the history
Packets sent by an endpoint are ultimately acknowledged by the peer
or declared lost. When a packet is acked or lost, we will look
through the data it contained and either mark it as received
by the peer or resend it.

Add an enum for the fate of a sent packet: acked or lost.

Update the sentVal ackOrLoss function to take a packetFate
rather than a bool.

For golang/go#58547

Change-Id: I2e526308db2c03b9c44b59ede1ce84684392c576
Reviewed-on: https://go-review.googlesource.com/c/net/+/504615
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
  • Loading branch information
neild committed Jun 21, 2023
1 parent ee81e8c commit 5d50b40
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
9 changes: 9 additions & 0 deletions internal/quic/quic.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,12 @@ func (s streamID) streamType() streamType {
}
return bidiStream
}

// packetFate is the fate of a sent packet: Either acknowledged by the peer,
// or declared lost.
type packetFate byte

const (
packetLost = packetFate(iota)
packetAcked
)
12 changes: 6 additions & 6 deletions internal/quic/sent_val.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,25 @@ func (s *sentVal) setSent(pnum packetNumber) {
func (s *sentVal) setReceived() { *s = sentValReceived }

// ackOrLoss reports that an acknowledgement has been received for the value,
// or (if acked is false) that the packet carrying the value has been lost.
func (s *sentVal) ackOrLoss(pnum packetNumber, acked bool) {
if acked {
// or that the packet carrying the value has been lost.
func (s *sentVal) ackOrLoss(pnum packetNumber, fate packetFate) {
if fate == packetAcked {
*s = sentValReceived
} else if *s == sentVal(pnum)|sentValSent {
*s = sentValUnsent
}
}

// ackLatestOrLoss reports that an acknowledgement has been received for the value,
// or (if acked is false) that the packet carrying the value has been lost.
// or that the packet carrying the value has been lost.
// The value is set to the acked state only if pnum is the latest packet containing it.
//
// We use this to handle acks for data that varies every time it is sent.
// For example, if we send a MAX_DATA frame followed by an updated MAX_DATA value in a
// second packet, we consider the data sent only upon receiving an ack for the most
// recent value.
func (s *sentVal) ackLatestOrLoss(pnum packetNumber, acked bool) {
if acked {
func (s *sentVal) ackLatestOrLoss(pnum packetNumber, fate packetFate) {
if fate == packetAcked {
if *s == sentVal(pnum)|sentValSent {
*s = sentValReceived
}
Expand Down
26 changes: 13 additions & 13 deletions internal/quic/sent_val_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,67 +80,67 @@ func TestSentVal(t *testing.T) {
name: "v.ackOrLoss(!pnum, true)",
f: func(v *sentVal) {
v.setSent(1)
v.ackOrLoss(0, true) // ack different packet containing the val
v.ackOrLoss(0, packetAcked) // ack different packet containing the val
},
wantIsSet: true,
wantShouldSend: false,
wantShouldSendPTO: false,
wantIsReceived: true,
}, {
name: "v.ackOrLoss(!pnum, false)",
name: "v.ackOrLoss(!pnum, packetLost)",
f: func(v *sentVal) {
v.setSent(1)
v.ackOrLoss(0, false) // lose different packet containing the val
v.ackOrLoss(0, packetLost) // lose different packet containing the val
},
wantIsSet: true,
wantShouldSend: false,
wantShouldSendPTO: true,
wantIsReceived: false,
}, {
name: "v.ackOrLoss(pnum, false)",
name: "v.ackOrLoss(pnum, packetLost)",
f: func(v *sentVal) {
v.setSent(1)
v.ackOrLoss(1, false) // lose same packet containing the val
v.ackOrLoss(1, packetLost) // lose same packet containing the val
},
wantIsSet: true,
wantShouldSend: true,
wantShouldSendPTO: true,
wantIsReceived: false,
}, {
name: "v.ackLatestOrLoss(!pnum, true)",
name: "v.ackLatestOrLoss(!pnum, packetAcked)",
f: func(v *sentVal) {
v.setSent(1)
v.ackLatestOrLoss(0, true) // ack different packet containing the val
v.ackLatestOrLoss(0, packetAcked) // ack different packet containing the val
},
wantIsSet: true,
wantShouldSend: false,
wantShouldSendPTO: true,
wantIsReceived: false,
}, {
name: "v.ackLatestOrLoss(pnum, true)",
name: "v.ackLatestOrLoss(pnum, packetAcked)",
f: func(v *sentVal) {
v.setSent(1)
v.ackLatestOrLoss(1, true) // ack same packet containing the val
v.ackLatestOrLoss(1, packetAcked) // ack same packet containing the val
},
wantIsSet: true,
wantShouldSend: false,
wantShouldSendPTO: false,
wantIsReceived: true,
}, {
name: "v.ackLatestOrLoss(!pnum, false)",
name: "v.ackLatestOrLoss(!pnum, packetLost)",
f: func(v *sentVal) {
v.setSent(1)
v.ackLatestOrLoss(0, false) // lose different packet containing the val
v.ackLatestOrLoss(0, packetLost) // lose different packet containing the val
},
wantIsSet: true,
wantShouldSend: false,
wantShouldSendPTO: true,
wantIsReceived: false,
}, {
name: "v.ackLatestOrLoss(pnum, false)",
name: "v.ackLatestOrLoss(pnum, packetLost)",
f: func(v *sentVal) {
v.setSent(1)
v.ackLatestOrLoss(1, false) // lose same packet containing the val
v.ackLatestOrLoss(1, packetLost) // lose same packet containing the val
},
wantIsSet: true,
wantShouldSend: true,
Expand Down

0 comments on commit 5d50b40

Please sign in to comment.