Skip to content

Commit 2ac2dca

Browse files
authored
Ping remote candidate for sped when pair is selected (#3)
* Ping remote caniddate for sped when pair is selected Ping to send piggyback dtls packet immediately after candidate pair is nominated to send pending packets * fix test
1 parent eeaf8b0 commit 2ac2dca

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎agent.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,18 @@ func (a *Agent) setSelectedPair(pair *CandidatePair) {
816816

817817
// Notify when the selected candidate pair changes
818818
a.selectedCandidatePairNotifier.EnqueueSelectedCandidatePair(pair)
819+
820+
// If a SPED (DTLS-in-STUN) handshake is still in flight when the pair is
821+
// nominated, drive a piggybacked ping on the freshly-selected pair *now*
822+
// rather than waiting for the next scheduled connectivity check. A local
823+
// DTLS flight (e.g. the DTLS-client Finished on the publisher / ice-lite
824+
// answerer path) that became ready just before nomination would otherwise
825+
// sit un-carried until the next check tick and miss the DTLS retransmit
826+
// window (~1 RTT / ~100-140ms stall). Sending it on the nominated pair
827+
// immediately gets it acked within ~1 RTT. Runs on the agent task loop.
828+
if a.piggybackActive() {
829+
a.pingSelectedPairForPiggyback()
830+
}
819831
}
820832

821833
func (a *Agent) pingAllCandidates() {

‎selection_test.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func newPingNoIOCand() *pingNoIOCand {
262262
func (d *pingNoIOCand) writeTo(b []byte, _ Candidate) (int, error) { return len(b), nil }
263263

264264
func bareAgentForPing() *Agent {
265-
return &Agent{
265+
a := &Agent{
266266
hostAcceptanceMinWait: time.Hour,
267267
srflxAcceptanceMinWait: time.Hour,
268268
prflxAcceptanceMinWait: time.Hour,
@@ -288,6 +288,8 @@ func bareAgentForPing() *Agent {
288288
candidatePairFunc: func(*CandidatePair) {},
289289
}, //nolint formatting
290290
}
291+
a.piggyback.init()
292+
return a
291293
}
292294

293295
func bigStr() string { return strings.Repeat("x", 40000) }

0 commit comments

Comments
 (0)