From 1859426ec3ea49b96c5c93d6e43956f60b1b292f Mon Sep 17 00:00:00 2001 From: cnderrauber Date: Thu, 5 Nov 2026 12:29:45 +0800 Subject: [PATCH] Enable PingCandidate for ice-lite when sped is enabled Emit a binding request to carry DTLS flight/ack when sped is on. Otherwise, it will wait for client's next ping to send the dtls packet in a response, which increase the connection time. --- agent.go | 9 +++++++++ selection.go | 13 ++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/agent.go b/agent.go index 018cbd62..fc13ec39 100644 --- a/agent.go +++ b/agent.go @@ -2122,6 +2122,15 @@ func (a *Agent) pingSelectedPairForPiggyback() { if pair == nil { pair = a.getBestValidCandidatePair() } + // During a SPED handshake the pair may not be in the valid list yet: a lite + // controlled agent only validates a pair on nomination, so before that + // getBestValidCandidatePair returns nil and a server-role flight (e.g. the + // ServerHello) would otherwise sit un-carried until the peer's DTLS + // retransmit (~1 RTT). We already learned the remote from its piggybacked + // ClientHello, so fall back to the best available pair to carry the flight now. + if pair == nil && a.piggybackActive() { + pair = a.getBestAvailableCandidatePair() + } if pair == nil { return } diff --git a/selection.go b/selection.go index 31f6b4a7..03594af5 100644 --- a/selection.go +++ b/selection.go @@ -558,6 +558,17 @@ func (s *liteSelector) ContactCandidates() { s.agent.setSelectedPair(pair) } -func (s *liteSelector) PingCandidate(_, _ Candidate) {} +func (s *liteSelector) PingCandidate(local, remote Candidate) { + // Lite agents normally generate no connectivity checks (RFC 8445 ยง7), so this + // is a no-op. The one exception is while a DTLS-in-STUN (SPED) handshake is in + // flight: the agent must emit a binding request to carry its queued DTLS + // flight/ack to the peer. Without it a server-role flight (e.g. the + // ServerHello) sits un-carried until the peer's DTLS retransmit (~1 RTT), + // losing the SPED speedup. Bounded to the handshake window, so it does not + // reintroduce general lite connectivity checks. + if s.agent.piggybackActive() { + s.pairCandidateSelector.PingCandidate(local, remote) + } +} func (s *liteSelector) HandleSuccessResponse(*stun.Message, Candidate, Candidate, netip.AddrPort) {}