Skip to content

Commit

Permalink
Don't start multiple PaceMakers for a single CheckList. (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanLennox authored Oct 5, 2024
1 parent d08e5a5 commit b4c8cd1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/org/ice4j/ice/CheckList.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.beans.*;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* A check list is a list of <tt>CandidatePair</tt>s with a state (i.e. a
Expand Down Expand Up @@ -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 <tt>triggeredCheckQueue</tt> is a FIFO queue containing candidate
* pairs for which checks are to be sent at the next available opportunity.
Expand Down Expand Up @@ -604,4 +610,9 @@ public IceMediaStream getParentStream()
{
return parentStream;
}

public boolean shouldStartPaceMaker()
{
return paceMakerStarted.compareAndSet(false, true);
}
}
14 changes: 14 additions & 0 deletions src/main/java/org/ice4j/ice/ConnectivityCheckClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b4c8cd1

Please sign in to comment.