...

Source file src/golang.org/x/net/internal/quic/conn_loss.go

Documentation: golang.org/x/net/internal/quic

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build go1.21
     6  
     7  package quic
     8  
     9  import "fmt"
    10  
    11  // handleAckOrLoss deals with the final fate of a packet we sent:
    12  // Either the peer acknowledges it, or we declare it lost.
    13  //
    14  // In order to handle packet loss, we must retain any information sent to the peer
    15  // until the peer has acknowledged it.
    16  //
    17  // When information is acknowledged, we can discard it.
    18  //
    19  // When information is lost, we mark it for retransmission.
    20  // See RFC 9000, Section 13.3 for a complete list of information which is retransmitted on loss.
    21  // https://www.rfc-editor.org/rfc/rfc9000#section-13.3
    22  func (c *Conn) handleAckOrLoss(space numberSpace, sent *sentPacket, fate packetFate) {
    23  	// The list of frames in a sent packet is marshaled into a buffer in the sentPacket
    24  	// by the packetWriter. Unmarshal that buffer here. This code must be kept in sync with
    25  	// packetWriter.append*.
    26  	//
    27  	// A sent packet meets its fate (acked or lost) only once, so it's okay to consume
    28  	// the sentPacket's buffer here.
    29  	for !sent.done() {
    30  		switch f := sent.next(); f {
    31  		default:
    32  			panic(fmt.Sprintf("BUG: unhandled acked/lost frame type %x", f))
    33  		case frameTypeAck:
    34  			// Unlike most information, loss of an ACK frame does not trigger
    35  			// retransmission. ACKs are sent in response to ack-eliciting packets,
    36  			// and always contain the latest information available.
    37  			//
    38  			// Acknowledgement of an ACK frame may allow us to discard information
    39  			// about older packets.
    40  			largest := packetNumber(sent.nextInt())
    41  			if fate == packetAcked {
    42  				c.acks[space].handleAck(largest)
    43  			}
    44  		case frameTypeCrypto:
    45  			start, end := sent.nextRange()
    46  			c.crypto[space].ackOrLoss(start, end, fate)
    47  		case frameTypeMaxData:
    48  			c.ackOrLossMaxData(sent.num, fate)
    49  		case frameTypeResetStream,
    50  			frameTypeStopSending,
    51  			frameTypeMaxStreamData,
    52  			frameTypeStreamDataBlocked:
    53  			id := streamID(sent.nextInt())
    54  			s := c.streamForID(id)
    55  			if s == nil {
    56  				continue
    57  			}
    58  			s.ackOrLoss(sent.num, f, fate)
    59  		case frameTypeStreamBase,
    60  			frameTypeStreamBase | streamFinBit:
    61  			id := streamID(sent.nextInt())
    62  			start, end := sent.nextRange()
    63  			s := c.streamForID(id)
    64  			if s == nil {
    65  				continue
    66  			}
    67  			fin := f&streamFinBit != 0
    68  			s.ackOrLossData(sent.num, start, end, fin, fate)
    69  		case frameTypeMaxStreamsBidi:
    70  			c.streams.remoteLimit[bidiStream].sendMax.ackLatestOrLoss(sent.num, fate)
    71  		case frameTypeMaxStreamsUni:
    72  			c.streams.remoteLimit[uniStream].sendMax.ackLatestOrLoss(sent.num, fate)
    73  		case frameTypeNewConnectionID:
    74  			seq := int64(sent.nextInt())
    75  			c.connIDState.ackOrLossNewConnectionID(sent.num, seq, fate)
    76  		case frameTypeRetireConnectionID:
    77  			seq := int64(sent.nextInt())
    78  			c.connIDState.ackOrLossRetireConnectionID(sent.num, seq, fate)
    79  		case frameTypeHandshakeDone:
    80  			c.handshakeConfirmed.ackOrLoss(sent.num, fate)
    81  		}
    82  	}
    83  }
    84  

View as plain text