From 611a5706f9c2fa844e40801ca8a257536f2a21e7 Mon Sep 17 00:00:00 2001 From: Jonathan Lennox Date: Fri, 4 Oct 2024 17:24:14 -0400 Subject: [PATCH] Don't start multiple PaceMakers for a single CheckList. --- src/main/java/org/ice4j/ice/CheckList.java | 11 +++++++++++ .../org/ice4j/ice/ConnectivityCheckClient.java | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/main/java/org/ice4j/ice/CheckList.java b/src/main/java/org/ice4j/ice/CheckList.java index 26071bf2..0993344f 100644 --- a/src/main/java/org/ice4j/ice/CheckList.java +++ b/src/main/java/org/ice4j/ice/CheckList.java @@ -21,6 +21,7 @@ import java.beans.*; import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; /** * A check list is a list of CandidatePairs with a state (i.e. a @@ -57,6 +58,11 @@ public class CheckList */ private CheckListState state = CheckListState.RUNNING; + /** + * Whether a PaceMaker has been started for this check list. + */ + private AtomicBoolean paceMakerStarted = new AtomicBoolean(false); + /** * The triggeredCheckQueue is a FIFO queue containing candidate * pairs for which checks are to be sent at the next available opportunity. @@ -604,4 +610,9 @@ public IceMediaStream getParentStream() { return parentStream; } + + public boolean shouldStartPaceMaker() + { + return paceMakerStarted.compareAndSet(false, true); + } } diff --git a/src/main/java/org/ice4j/ice/ConnectivityCheckClient.java b/src/main/java/org/ice4j/ice/ConnectivityCheckClient.java index dbeb4600..fa40a046 100644 --- a/src/main/java/org/ice4j/ice/ConnectivityCheckClient.java +++ b/src/main/java/org/ice4j/ice/ConnectivityCheckClient.java @@ -165,6 +165,12 @@ public void startChecks() */ public void startChecks(CheckList checkList) { + if (!checkList.shouldStartPaceMaker()) + { + logger.debug("Checks for " + checkList.getName() + " already started"); + return; + } + logger.debug("Start connectivity checks for " + checkList.getName()); synchronized (paceMakers) { if (stopped) @@ -925,10 +931,18 @@ protected void run() { CandidatePair pairToCheck = checkList.popTriggeredCheck(); + if (pairToCheck != null) + { + logger.trace("Starting triggered check " + pairToCheck.toRedactedString()); + } //if there are no triggered checks, go for an ordinary one. if (pairToCheck == null) { pairToCheck = checkList.getNextOrdinaryPairToCheck(); + if (pairToCheck != null) + { + logger.trace("Starting ordinary check " + pairToCheck.toRedactedString()); + } } if (pairToCheck != null)