From a3bd377fe77dc780534774b6cae3495a5d0b286b Mon Sep 17 00:00:00 2001 From: emcho Date: Wed, 28 Apr 2010 22:31:18 +0000 Subject: [PATCH] Starts work on supporting triggered checks and peer-reflexive candidate discovery --- src/org/ice4j/ice/Agent.java | 78 ++++++++++++------- src/org/ice4j/ice/FoundationsRegistry.java | 22 +++++- .../ice/checks/ConnectivityCheckServer.java | 8 +- test/test/Ice.java | 2 +- 4 files changed, 75 insertions(+), 35 deletions(-) diff --git a/src/org/ice4j/ice/Agent.java b/src/org/ice4j/ice/Agent.java index 3304831..8a4add8 100644 --- a/src/org/ice4j/ice/Agent.java +++ b/src/org/ice4j/ice/Agent.java @@ -30,7 +30,7 @@ import org.ice4j.ice.harvest.*; * @author Emil Ivov */ public class Agent - implements RemoteAddressHandler + implements IncomingCheckProcessor { /** * Our class logger. @@ -90,8 +90,13 @@ public class Agent * addresses in here are actually peer-reflexive or not, and schedule * the necessary triggered checks. */ - private final List preDiscoveredRemoteCandidatesQueue - = new Vector(); + private final List preDiscoveredPairsQueue + = new Vector(); + + /** + * The lock that we use while starting connectivity establishment. + */ + private final Object startLock = new Object(); /** * The user fragment that we should use for the ice-ufrag attribute. @@ -289,7 +294,7 @@ public class Agent */ public void startConnectivityEstablishment() { - synchronized(this) + synchronized(startLock) { initCheckLists(); @@ -327,11 +332,7 @@ public class Agent */ public boolean isStarted() { - synchronized(this) - { - return iceStarted; - } - + return iceStarted; } /** @@ -665,9 +666,9 @@ public class Agent { Collection streamsCollection = mediaStreams.values(); - for( IceMediaStream cmp : streamsCollection) + for( IceMediaStream stream : streamsCollection) { - LocalCandidate cnd = cmp.findLocalCandidate(localAddress); + LocalCandidate cnd = stream.findLocalCandidate(localAddress); if(cnd != null) return cnd; @@ -692,29 +693,50 @@ public class Agent * we decide to send a check to remoteAddress. * */ - public void handleRemoteAddress(TransportAddress remoteAddress, - TransportAddress localAddress, - long priority, - String remoteUFrag) + public void incomingCheckReceived(TransportAddress remoteAddress, + TransportAddress localAddress, + long priority, + String remoteUFrag) { - this.createMediaStream(null).createComponent(null). + LocalCandidate localCandidate = findLocalCandidate(localAddress); + Component parentComponent = localCandidate.getParentComponent(); - if(iceStarted) + RemoteCandidate remoteCandidate = new RemoteCandidate( + remoteAddress, parentComponent, + CandidateType.PEER_REFLEXIVE_CANDIDATE, + foundationsRegistry.obtainFoundationForPeerReflexiveCandidate(), + priority); + + CandidatePair triggeredPair + = new CandidatePair(localCandidate, remoteCandidate); + + synchronized(startLock) { - /* - if remoteAddress is not known + if(isStarted()) { - create peer reflexive candidate + //we are started, which means we have the remote candidates + //so it's now safe to go and see whether this is a new PR cand. + triggerCheck(triggeredPair); } + else + { + //we are not started yet so we'd better wait until we get the + //remote candidates incase we are holding to a new PR one. + this.preDiscoveredPairsQueue.add(triggeredPair); + } + } + } - schedule triggered check - */ - } - else - { - RemoteCandidate remoteCand = new RemoteCandidate( - remoteAddres, ); - } + /** + * Either queues a triggered check for triggeredPair or, in case + * there's already a pair with the specified remote and local addresses, + * puts it in the queue instead. + * + * @param triggeredPair the pair containing the local and remote candidate + * that we'd need to trigger a check for. + */ + private void triggerCheck(CandidatePair triggeredPair) + { } } diff --git a/src/org/ice4j/ice/FoundationsRegistry.java b/src/org/ice4j/ice/FoundationsRegistry.java index 760b8f0..670dd47 100644 --- a/src/org/ice4j/ice/FoundationsRegistry.java +++ b/src/org/ice4j/ice/FoundationsRegistry.java @@ -22,6 +22,12 @@ public class FoundationsRegistry */ private int lastAssignedFoundation = 0; + /** + * The foundation number that was last assigned to a PEER-REFLEXIVE + * RemoteCandidate + */ + private int lastAssignedRemoteFoundation = 10000; + /** * Contains mappings between a type+baseIP+server+transport * Strings and the foundation that has been assigned to them. @@ -30,8 +36,8 @@ public class FoundationsRegistry /** * Assigns to candidate the foundation that corresponds to its - * bas type and transport properties or a new one if no foundation has been - * generated yet for the specific combination. + * base, type and transport properties or a new one if no foundation has + * been generated yet for the specific combination. * * @param candidate the Candidate that we'd like to assign a * foundation to. @@ -79,6 +85,18 @@ public class FoundationsRegistry candidate.setFoundation(foundationValue); } + /** + * Returns an (as far as you care) random foundation that could be assigned + * to a learned PEER-REFLEXIVE candidate. + * + * @return a foundation String that could be assigned to a + * learned PEER-REFLEXIVE candidate. + */ + public String obtainFoundationForPeerReflexiveCandidate() + { + return Integer.toString(lastAssignedRemoteFoundation++); + } + /** * Returns the number of foundation Strings that are currently * tracked by the registry. diff --git a/src/org/ice4j/ice/checks/ConnectivityCheckServer.java b/src/org/ice4j/ice/checks/ConnectivityCheckServer.java index 41c9c77..9c2c493 100644 --- a/src/org/ice4j/ice/checks/ConnectivityCheckServer.java +++ b/src/org/ice4j/ice/checks/ConnectivityCheckServer.java @@ -34,10 +34,10 @@ public class ConnectivityCheckServer private final Agent parentAgent; /** - * The {@link RemoteAddressHandler} that we should notify when we notice + * The {@link IncomingCheckProcessor} that we should notify when we notice * new remote transport addresses. */ - private final RemoteAddressHandler addressHandler; + private final IncomingCheckProcessor addressHandler; /** * The stun stack that we will use for connectivity checks. @@ -53,7 +53,7 @@ public class ConnectivityCheckServer * @param addressHandler the handler that */ public ConnectivityCheckServer(Agent parentAgent, - RemoteAddressHandler addressHandler) + IncomingCheckProcessor addressHandler) { this.parentAgent = parentAgent; this.addressHandler = addressHandler; @@ -102,7 +102,7 @@ public class ConnectivityCheckServer long priority = priorityAttr.getPriority(); //tell our address handler we saw a new remote address; - addressHandler.handleRemoteAddress(evt.getRemoteAddress(), + addressHandler.incomingCheckReceived(evt.getRemoteAddress(), evt.getLocalAddress(), priority, remoteUfrag); diff --git a/test/test/Ice.java b/test/test/Ice.java index 09393d1..a6b7caf 100644 --- a/test/test/Ice.java +++ b/test/test/Ice.java @@ -51,7 +51,7 @@ public class Ice + (endTime - startTime) + "ms"); System.out.println("LocalAgent:\n" + localAgent); - localAgent.startChecks(); + localAgent.startConnectivityEstablishment(); System.out.println("Local audio clist:\n" + localAgent.getStream("audio").getCheckList());