From 5067c4a462deabd057006ac3ccd4a18e04bffe64 Mon Sep 17 00:00:00 2001 From: emcho Date: Sat, 8 May 2010 21:36:45 +0000 Subject: [PATCH] Implements client side valid list construction (RFC 5245: Section 7.1.3.2.2) --- src/org/ice4j/ice/Agent.java | 7 +- src/org/ice4j/ice/IceMediaStream.java | 22 ++++++ .../ice/checks/ConnectivityCheckClient.java | 73 +++++++++++++++++-- 3 files changed, 89 insertions(+), 13 deletions(-) diff --git a/src/org/ice4j/ice/Agent.java b/src/org/ice4j/ice/Agent.java index 584e0a0..d8906c2 100644 --- a/src/org/ice4j/ice/Agent.java +++ b/src/org/ice4j/ice/Agent.java @@ -291,12 +291,7 @@ public class Agent synchronized(startLock) { initCheckLists(); - - List streams = getStreams(); - - CheckList list = streams.get(0).getCheckList(); - connCheckClient.startChecks(list); - + connCheckClient.startChecks(); iceStarted = true; } } diff --git a/src/org/ice4j/ice/IceMediaStream.java b/src/org/ice4j/ice/IceMediaStream.java index df667c6..96101ad 100644 --- a/src/org/ice4j/ice/IceMediaStream.java +++ b/src/org/ice4j/ice/IceMediaStream.java @@ -558,4 +558,26 @@ public class IceMediaStream validList.add(pair); } } + + /** + * Returns true if this stream's validList contains a + * pair with the specified foundation and false otherwise. + * + * @param foundation the foundation String we'd like to search our + * validList for. + * + * @return true if this stream's validList contains a + * pair with the specified foundation and false otherwise. + */ + public boolean containsFoundation(String foundation) + { + synchronized(validList) + { + for(CandidatePair pair : validList) + if (pair.getFoundation().equals(foundation)) + return true; + } + + return false; + } } diff --git a/src/org/ice4j/ice/checks/ConnectivityCheckClient.java b/src/org/ice4j/ice/checks/ConnectivityCheckClient.java index b3c1031..8429b90 100644 --- a/src/org/ice4j/ice/checks/ConnectivityCheckClient.java +++ b/src/org/ice4j/ice/checks/ConnectivityCheckClient.java @@ -63,15 +63,29 @@ public class ConnectivityCheckClient } /** - * Starts client connectivity checks using checkList as the - * {@link CheckList} of the first {@link IceMediaStream}. - * - * @param firstCheckList the check list that we should start our checks - * with. + * Starts client connectivity checks for the first {@link IceMediaStream} + * in our parent {@link Agent}. This method should only be called by + * the parent {@link Agent} when connectivity establishment starts for a + * particular check list. */ - public void startChecks(CheckList firstCheckList) + public void startChecks() { - PaceMaker paceMaker = new PaceMaker(this, firstCheckList); + CheckList firstCheckList = parentAgent.getStreams().get(0) + .getCheckList(); + + startChecks(firstCheckList); + } + + /** + * Starts client connectivity checks for the {@link CandidatePair}s in + * checkList + * + * @param checkList the {@link CheckList} to start client side connectivity + * checks for. + */ + private void startChecks(CheckList checkList) + { + PaceMaker paceMaker = new PaceMaker(this, checkList); paceMakers.add(paceMaker); paceMaker.start(); @@ -289,6 +303,51 @@ public class ConnectivityCheckClient validPair.getParentComponent().getParentStream() .addValidPair(validPair); + + //The agent sets the state of the pair that *generated* the check to + //Succeeded. Note that, the pair which *generated* the check may be + //different than the valid pair constructed above + checkedPair.setStateSucceeded(); + + //The agent changes the states for all other Frozen pairs for the + //same media stream and same foundation to Waiting. + IceMediaStream parentStream = checkedPair.getParentComponent() + .getParentStream(); + CheckList parentCheckList = parentStream.getCheckList(); + + for(CandidatePair pair : parentCheckList) + if (pair.getState() == CandidatePairState.FROZEN) + pair.setStateWaiting(); + + // The agent examines the check list for all other streams in turn + // If the check list is active, the agent changes the state of + // all Frozen pairs in that check list whose foundation matches a + // pair in the valid list under consideration to Waiting. + List allOtherStreams = parentAgent.getStreams(); + allOtherStreams.remove(parentStream); + + for (IceMediaStream stream : allOtherStreams) + { + CheckList checkList = stream.getCheckList(); + boolean wasFrozen = checkList.isFrozen(); + + for(CandidatePair pair : checkList) + if (parentStream.containsFoundation(pair.getFoundation())) + pair.setStateWaiting(); + + //if the checklList is still frozen after the above operations, and + //there are no pairs in the check list whose foundation matches a + //pair in the valid list under consideration, the agent groups + //together all of the pairs with the same foundation, and for each + //group, sets the state of the pair with the lowest component ID to + //Waiting. If there is more than one such pair, the one with the + //highest priority is used. + if(!checkList.isFrozen()) + checkList.computeInitialCheckListPairStates(); + + if (wasFrozen) + startChecks(checkList); + } } /**