github.com/TugasAkhir-QUIC/quic-go@v0.0.2-0.20240215011318-d20e25a9054c/closed_conn.go (about) 1 package quic 2 3 import ( 4 "math/bits" 5 "net" 6 7 "github.com/TugasAkhir-QUIC/quic-go/internal/protocol" 8 "github.com/TugasAkhir-QUIC/quic-go/internal/utils" 9 ) 10 11 // A closedLocalConn is a connection that we closed locally. 12 // When receiving packets for such a connection, we need to retransmit the packet containing the CONNECTION_CLOSE frame, 13 // with an exponential backoff. 14 type closedLocalConn struct { 15 counter uint32 16 perspective protocol.Perspective 17 logger utils.Logger 18 19 sendPacket func(net.Addr, packetInfo) 20 } 21 22 var _ packetHandler = &closedLocalConn{} 23 24 // newClosedLocalConn creates a new closedLocalConn and runs it. 25 func newClosedLocalConn(sendPacket func(net.Addr, packetInfo), pers protocol.Perspective, logger utils.Logger) packetHandler { 26 return &closedLocalConn{ 27 sendPacket: sendPacket, 28 perspective: pers, 29 logger: logger, 30 } 31 } 32 33 func (c *closedLocalConn) handlePacket(p receivedPacket) { 34 c.counter++ 35 // exponential backoff 36 // only send a CONNECTION_CLOSE for the 1st, 2nd, 4th, 8th, 16th, ... packet arriving 37 if bits.OnesCount32(c.counter) != 1 { 38 return 39 } 40 c.logger.Debugf("Received %d packets after sending CONNECTION_CLOSE. Retransmitting.", c.counter) 41 c.sendPacket(p.remoteAddr, p.info) 42 } 43 44 func (c *closedLocalConn) destroy(error) {} 45 func (c *closedLocalConn) closeWithTransportError(TransportErrorCode) {} 46 func (c *closedLocalConn) getPerspective() protocol.Perspective { return c.perspective } 47 48 // A closedRemoteConn is a connection that was closed remotely. 49 // For such a connection, we might receive reordered packets that were sent before the CONNECTION_CLOSE. 50 // We can just ignore those packets. 51 type closedRemoteConn struct { 52 perspective protocol.Perspective 53 } 54 55 var _ packetHandler = &closedRemoteConn{} 56 57 func newClosedRemoteConn(pers protocol.Perspective) packetHandler { 58 return &closedRemoteConn{perspective: pers} 59 } 60 61 func (c *closedRemoteConn) handlePacket(receivedPacket) {} 62 func (c *closedRemoteConn) destroy(error) {} 63 func (c *closedRemoteConn) closeWithTransportError(TransportErrorCode) {} 64 func (c *closedRemoteConn) getPerspective() protocol.Perspective { return c.perspective }