From 2ad5090e232218a91908d198b9db9740aa9ab35d Mon Sep 17 00:00:00 2001 From: emcho Date: Sat, 8 May 2010 21:37:24 +0000 Subject: [PATCH] Implements support for Check List and Timer State Updates (RFC 5245 7.1.3.3.) --- src/org/ice4j/ice/Agent.java | 2 +- src/org/ice4j/ice/IceMediaStream.java | 49 ++++++++++++++++++- .../ice/checks/ConnectivityCheckClient.java | 47 +++++++++++++++++- .../ice/checks/ConnectivityCheckServer.java | 11 +---- 4 files changed, 96 insertions(+), 13 deletions(-) diff --git a/src/org/ice4j/ice/Agent.java b/src/org/ice4j/ice/Agent.java index 661dcc6..475eeb1 100644 --- a/src/org/ice4j/ice/Agent.java +++ b/src/org/ice4j/ice/Agent.java @@ -132,7 +132,7 @@ public class Agent * The entity that will be taking care of incoming connectivity checks. */ private final ConnectivityCheckServer connCheckServer - = new ConnectivityCheckServer(this, this); + = new ConnectivityCheckServer(this); /** * Indicates whether this agent has both sent and received candidate lists diff --git a/src/org/ice4j/ice/IceMediaStream.java b/src/org/ice4j/ice/IceMediaStream.java index 96101ad..8cff4a9 100644 --- a/src/org/ice4j/ice/IceMediaStream.java +++ b/src/org/ice4j/ice/IceMediaStream.java @@ -569,7 +569,7 @@ public class IceMediaStream * @return true if this stream's validList contains a * pair with the specified foundation and false otherwise. */ - public boolean containsFoundation(String foundation) + public boolean validListContainsFoundation(String foundation) { synchronized(validList) { @@ -580,4 +580,51 @@ public class IceMediaStream return false; } + + /** + * Returns true if this stream's valid list contains at least + * one {@link CandidatePair} for each {@link Component} of the stream and + * false otherwise. + * + * @return true if this stream's valid list contains at least + * one {@link CandidatePair} for each {@link Component} of the stream and + * false otherwise. + */ + public boolean validListContainsAllComponents() + { + List cmpList = getComponents(); + for(Component cmp : cmpList) + { + if (getValidPair(cmp) != null) + continue; + + //it looks like there's at least one component we don't have a + //valid candidate for. + return false; + } + + return true; + } + + /** + * Returns the first {@link CandidatePair} stored in this stream's valid + * list, that belongs to the specified component. + * + * @param component the {@link Component} we'd like to obtain a valid + * pair for. + * + * @return a valid {@link CandidatePair} for the specified + * component if at least one exists, and null otherwise. + */ + public CandidatePair getValidPair(Component component) + { + synchronized(validList) + { + for(CandidatePair pair : validList) + if(pair.getParentComponent() == component) + return pair; + } + + return null; + } } diff --git a/src/org/ice4j/ice/checks/ConnectivityCheckClient.java b/src/org/ice4j/ice/checks/ConnectivityCheckClient.java index 7ae4358..65f536a 100644 --- a/src/org/ice4j/ice/checks/ConnectivityCheckClient.java +++ b/src/org/ice4j/ice/checks/ConnectivityCheckClient.java @@ -214,6 +214,51 @@ public class ConnectivityCheckClient { processSuccessResponse(evt); } + + //7.1.3.3. Check List and Timer State Updates + //Regardless of whether the check was successful or failed, the + //completion of the transaction may require updating of check list and + //timer states. + CandidatePair checkedPair = ((CandidatePair)evt.getTransactionID() + .getApplicationData()); + IceMediaStream stream = checkedPair.getParentComponent() + .getParentStream(); + CheckList checkList = stream.getCheckList(); + + //If all of the pairs in the check list are now either in the Failed or + //Succeeded state: + boolean allPairsDone = true; + for(CandidatePair pair : checkList) + if(pair.getState() != CandidatePairState.FAILED + && pair.getState() != CandidatePairState.SUCCEEDED) + allPairsDone = false; + + if (allPairsDone) + { + //If there is not a pair in the valid list for each component of the + //media stream, the state of the check list is set to Failed. + if ( !stream.validListContainsAllComponents()) + { + checkList.setState(CheckListState.FAILED); + } + + //For each frozen check list, 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. + List allOtherStreams = parentAgent.getStreams(); + allOtherStreams.remove(checkList); + for (IceMediaStream anotherStream : allOtherStreams) + { + CheckList anotherCheckList = anotherStream.getCheckList(); + if(anotherCheckList.isFrozen()) + { + anotherCheckList.computeInitialCheckListPairStates(); + startChecks(anotherCheckList); + } + } + } } /** @@ -332,7 +377,7 @@ public class ConnectivityCheckClient boolean wasFrozen = checkList.isFrozen(); for(CandidatePair pair : checkList) - if (parentStream.containsFoundation(pair.getFoundation()) + if (parentStream.validListContainsFoundation(pair.getFoundation()) && pair.getState() == CandidatePairState.FROZEN) pair.setStateWaiting(); diff --git a/src/org/ice4j/ice/checks/ConnectivityCheckServer.java b/src/org/ice4j/ice/checks/ConnectivityCheckServer.java index 3921473..5ae69e5 100644 --- a/src/org/ice4j/ice/checks/ConnectivityCheckServer.java +++ b/src/org/ice4j/ice/checks/ConnectivityCheckServer.java @@ -35,12 +35,6 @@ public class ConnectivityCheckServer */ private final Agent parentAgent; - /** - * The {@link IncomingCheckProcessor} that we should notify when we notice - * new remote transport addresses. - */ - private final IncomingCheckProcessor addressHandler; - /** * The stun stack that we will use for connectivity checks. */ @@ -52,13 +46,10 @@ public class ConnectivityCheckServer * information such as user fragments for example. * * @param parentAgent the Agent that is creating this instance. - * @param addressHandler the handler that */ - public ConnectivityCheckServer(Agent parentAgent, - IncomingCheckProcessor addressHandler) + public ConnectivityCheckServer(Agent parentAgent) { this.parentAgent = parentAgent; - this.addressHandler = addressHandler; stunStack.addRequestListener(this); stunStack.getCredentialsManager().registerAuthority(this); }