From af2aa865329dc0ea8ba24e0ee7af71daf6e8dea2 Mon Sep 17 00:00:00 2001 From: emcho Date: Sat, 6 Mar 2010 16:05:26 +0000 Subject: [PATCH] Adds CheckList initialization --- src/org/ice4j/ice/Agent.java | 14 +++++- src/org/ice4j/ice/Candidate.java | 31 +++++++++++++ src/org/ice4j/ice/CandidatePair.java | 6 +-- src/org/ice4j/ice/Component.java | 6 +-- src/org/ice4j/ice/IceMediaStream.java | 62 ++++++++++++++++++++++++++ src/org/ice4j/ice/LocalCandidate.java | 19 ++++++++ src/org/ice4j/ice/RemoteCandidate.java | 19 ++++++++ test/test/Ice.java | 8 +++- 8 files changed, 157 insertions(+), 8 deletions(-) diff --git a/src/org/ice4j/ice/Agent.java b/src/org/ice4j/ice/Agent.java index f5935ab..014bba8 100644 --- a/src/org/ice4j/ice/Agent.java +++ b/src/org/ice4j/ice/Agent.java @@ -215,6 +215,18 @@ public class Agent component.selectDefaultCandidate(); } + /** + * Initializes all stream check lists and begins the checks. + */ + public void startChecks() + { + List streams = getStreams(); + + for(IceMediaStream stream : streams) + { + stream.initCheckList(); + } + } /** * Computes and sets the foundations foundation for all Candidates * currently found in component. @@ -224,7 +236,7 @@ public class Agent */ private void computeFoundations(Component component) { - List candidates = component.getLocalCandidates(); + List candidates = component.getLocalCandidates(); for (Candidate cand : candidates) { diff --git a/src/org/ice4j/ice/Candidate.java b/src/org/ice4j/ice/Candidate.java index b4bc425..55594a2 100644 --- a/src/org/ice4j/ice/Candidate.java +++ b/src/org/ice4j/ice/Candidate.java @@ -645,4 +645,35 @@ public abstract class Candidate //WTF? return 5; } + + /** + * Determines whether this Candidate'sTransportAddress is + * theoretically usable for communication with that of dst. Same + * as calling: + *

+ * getTransportAddress().canReach(dst.getTransportAddress()) + *

+ * + * @param dst the Candidate that we'd like to check for + * reachability from this one. + * + * @return true if this {@link Candidate} shares the same + * Transport and family as dst or false + * otherwise. + * + */ + public boolean canReach(Candidate dst) + { + return getTransportAddress().canReach(dst.getTransportAddress()); + } + + /** + * Determines whether this Candidate is the default one for its + * parent component. + * + * @return true if this Candidate is the default for its + * parent component and false if it isn't or if it has no parent + * Component yet. + */ + public abstract boolean isDefault(); } diff --git a/src/org/ice4j/ice/CandidatePair.java b/src/org/ice4j/ice/CandidatePair.java index 150a2f6..5a2773b 100644 --- a/src/org/ice4j/ice/CandidatePair.java +++ b/src/org/ice4j/ice/CandidatePair.java @@ -37,7 +37,7 @@ public class CandidatePair /** * The remote candidate of this pair. */ - private final RemoteCandidate remoteCandidate; + private final Candidate remoteCandidate; /** * Priority of the candidate-pair @@ -60,7 +60,7 @@ public class CandidatePair * @param remoteCandidate the remote candidate of the pair. */ public CandidatePair(LocalCandidate localCandidate, - RemoteCandidate remoteCandidate) + Candidate remoteCandidate) { this.localCandidate = localCandidate; @@ -103,7 +103,7 @@ public class CandidatePair * * @return the remote Candidate of this CandidatePair. */ - public RemoteCandidate getRemoteCandidate() + public Candidate getRemoteCandidate() { return remoteCandidate; } diff --git a/src/org/ice4j/ice/Component.java b/src/org/ice4j/ice/Component.java index 98f0cd1..9265491 100644 --- a/src/org/ice4j/ice/Component.java +++ b/src/org/ice4j/ice/Component.java @@ -137,11 +137,11 @@ public class Component * @return Returns a copy of the list containing all local candidates * currently registered in this Component. */ - public List getLocalCandidates() + public List getLocalCandidates() { synchronized(localCandidates) { - return new ArrayList(localCandidates); + return new ArrayList(localCandidates); } } @@ -447,7 +447,7 @@ public class Component */ protected void eliminateRedundantCandidates() { - List candidatesCopy = getLocalCandidates(); + List candidatesCopy = getLocalCandidates(); for (Candidate cand : candidatesCopy) { diff --git a/src/org/ice4j/ice/IceMediaStream.java b/src/org/ice4j/ice/IceMediaStream.java index 2e78470..7463fe1 100644 --- a/src/org/ice4j/ice/IceMediaStream.java +++ b/src/org/ice4j/ice/IceMediaStream.java @@ -48,6 +48,12 @@ public class IceMediaStream */ private int lastComponentID = 0; + /** + * The CHECK-LIST for this stream as described in the ICE specification. + */ + private final List checkList + = new LinkedList(); + /** * The agent that this media stream belongs to. */ @@ -243,4 +249,60 @@ public class IceMediaStream component.free(); } } + + /** + * Creates, initializes and orders the list of candidate pairs that would + * be used for the connectivity checks for all components in this stream. + */ + protected void initCheckList() + { + synchronized(checkList) + { + checkList.clear(); + List componentsList = getComponents(); + + for(Component cmp : componentsList) + { + createCheckList(cmp, checkList); + } + } + } + + /** + * Creates and adds to checkList all the CandidatePairs + * in component. + * + * @param component the Component whose candidates we need to + * pair and extract. + * @param checkList the list that we need to update with the new pairs. + */ + private void createCheckList(Component component, + List checkList) + { + List localCnds = component.getLocalCandidates(); + List remoteCnds = component.getRemoteCandidates(); + + for(LocalCandidate localCnd : localCnds) + { + for(Candidate remoteCnd : remoteCnds) + { + if(!localCnd.canReach(remoteCnd)) + continue; + + CandidatePair pair = new CandidatePair(localCnd, remoteCnd); + + checkList.add(pair); + } + } + } + + /** + * Returns the list of CandidatePairs for this stream. + * + * @return the list of CandidatePairs for this stream. + */ + public List getCheckList() + { + return checkList; + } } diff --git a/src/org/ice4j/ice/LocalCandidate.java b/src/org/ice4j/ice/LocalCandidate.java index 9158794..2655688 100644 --- a/src/org/ice4j/ice/LocalCandidate.java +++ b/src/org/ice4j/ice/LocalCandidate.java @@ -54,4 +54,23 @@ public abstract class LocalCandidate { getSocket().close(); } + + /** + * Determines whether this Candidate is the default one for its + * parent component. + * + * @return true if this Candidate is the default for its + * parent component and false if it isn't or if it has no parent + * Component yet. + */ + @Override + public boolean isDefault() + { + Component parentCmp = getParentComponent(); + + if (parentCmp == null) + return false; + + return equals(parentCmp.getDefaultCandidate()); + } } diff --git a/src/org/ice4j/ice/RemoteCandidate.java b/src/org/ice4j/ice/RemoteCandidate.java index 33a1ea0..a907541 100644 --- a/src/org/ice4j/ice/RemoteCandidate.java +++ b/src/org/ice4j/ice/RemoteCandidate.java @@ -59,4 +59,23 @@ public class RemoteCandidate { super.priority = priority; } + + /** + * Determines whether this Candidate is the default one for its + * parent component. + * + * @return true if this Candidate is the default for its + * parent component and false if it isn't or if it has no parent + * Component yet. + */ + @Override + public boolean isDefault() + { + Component parentCmp = getParentComponent(); + + if (parentCmp == null) + return false; + + return equals(parentCmp.getDefaultRemoteCandidate()); + } } diff --git a/test/test/Ice.java b/test/test/Ice.java index 219af0a..6895866 100644 --- a/test/test/Ice.java +++ b/test/test/Ice.java @@ -41,6 +41,11 @@ public class Ice System.out.println("LocalAgent:\n" + localAgent); + localAgent.startChecks(); + + System.out.println("Local audio clist:\n" + + localAgent.getStream("audio").getCheckList()); + System.out.println("Total execution time: " + (endTime - startTime) + "ms"); } @@ -112,7 +117,8 @@ public class Ice private static void transferRemoteCandidates(Component localComponent, Component remoteComponent) { - List remoteCandidates = remoteComponent.getLocalCandidates(); + List remoteCandidates + = remoteComponent.getLocalCandidates(); localComponent.setDefaultRemoteCandidate( remoteComponent.getDefaultCandidate());