Starts work on supporting triggered checks and peer-reflexive candidate discovery

This commit is contained in:
emcho 2010-04-28 22:31:18 +00:00
parent 9d07b54f05
commit a3bd377fe7
4 changed files with 75 additions and 35 deletions

View File

@ -30,7 +30,7 @@ import org.ice4j.ice.harvest.*;
* @author Emil Ivov * @author Emil Ivov
*/ */
public class Agent public class Agent
implements RemoteAddressHandler implements IncomingCheckProcessor
{ {
/** /**
* Our class logger. * Our class logger.
@ -90,8 +90,13 @@ public class Agent
* addresses in here are actually peer-reflexive or not, and schedule * addresses in here are actually peer-reflexive or not, and schedule
* the necessary triggered checks. * the necessary triggered checks.
*/ */
private final List<RemoteCandidate> preDiscoveredRemoteCandidatesQueue private final List<CandidatePair> preDiscoveredPairsQueue
= new Vector<RemoteCandidate>(); = new Vector<CandidatePair>();
/**
* 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. * The user fragment that we should use for the ice-ufrag attribute.
@ -289,7 +294,7 @@ public class Agent
*/ */
public void startConnectivityEstablishment() public void startConnectivityEstablishment()
{ {
synchronized(this) synchronized(startLock)
{ {
initCheckLists(); initCheckLists();
@ -326,14 +331,10 @@ public class Agent
* state) and <tt>false</tt> otherwise. * state) and <tt>false</tt> otherwise.
*/ */
public boolean isStarted() public boolean isStarted()
{
synchronized(this)
{ {
return iceStarted; return iceStarted;
} }
}
/** /**
* Creates, initializes and orders the list of candidate pairs that would * Creates, initializes and orders the list of candidate pairs that would
* be used for the connectivity checks for all components in this stream. * be used for the connectivity checks for all components in this stream.
@ -665,9 +666,9 @@ public class Agent
{ {
Collection<IceMediaStream> streamsCollection = mediaStreams.values(); Collection<IceMediaStream> streamsCollection = mediaStreams.values();
for( IceMediaStream cmp : streamsCollection) for( IceMediaStream stream : streamsCollection)
{ {
LocalCandidate cnd = cmp.findLocalCandidate(localAddress); LocalCandidate cnd = stream.findLocalCandidate(localAddress);
if(cnd != null) if(cnd != null)
return cnd; return cnd;
@ -692,29 +693,50 @@ public class Agent
* we decide to send a check to <tt>remoteAddress</tt>. * we decide to send a check to <tt>remoteAddress</tt>.
* *
*/ */
public void handleRemoteAddress(TransportAddress remoteAddress, public void incomingCheckReceived(TransportAddress remoteAddress,
TransportAddress localAddress, TransportAddress localAddress,
long priority, long priority,
String remoteUFrag) 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,
if remoteAddress is not known foundationsRegistry.obtainFoundationForPeerReflexiveCandidate(),
{ priority);
create peer reflexive candidate
}
schedule triggered check CandidatePair triggeredPair
*/ = new CandidatePair(localCandidate, remoteCandidate);
synchronized(startLock)
{
if(isStarted())
{
//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 else
{ {
RemoteCandidate remoteCand = new RemoteCandidate( //we are not started yet so we'd better wait until we get the
remoteAddres, ); //remote candidates incase we are holding to a new PR one.
this.preDiscoveredPairsQueue.add(triggeredPair);
} }
}
}
/**
* Either queues a triggered check for <tt>triggeredPair</tt> 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)
{
} }
} }

View File

@ -22,6 +22,12 @@ public class FoundationsRegistry
*/ */
private int lastAssignedFoundation = 0; private int lastAssignedFoundation = 0;
/**
* The foundation number that was last assigned to a PEER-REFLEXIVE
* <tt>RemoteCandidate</tt>
*/
private int lastAssignedRemoteFoundation = 10000;
/** /**
* Contains mappings between a type+baseIP+server+transport * Contains mappings between a type+baseIP+server+transport
* <tt>String</tt>s and the foundation that has been assigned to them. * <tt>String</tt>s and the foundation that has been assigned to them.
@ -30,8 +36,8 @@ public class FoundationsRegistry
/** /**
* Assigns to <tt>candidate</tt> the foundation that corresponds to its * Assigns to <tt>candidate</tt> the foundation that corresponds to its
* bas type and transport properties or a new one if no foundation has been * base, type and transport properties or a new one if no foundation has
* generated yet for the specific combination. * been generated yet for the specific combination.
* *
* @param candidate the <tt>Candidate</tt> that we'd like to assign a * @param candidate the <tt>Candidate</tt> that we'd like to assign a
* foundation to. * foundation to.
@ -79,6 +85,18 @@ public class FoundationsRegistry
candidate.setFoundation(foundationValue); 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 <tt>String</tt> that could be assigned to a
* learned PEER-REFLEXIVE candidate.
*/
public String obtainFoundationForPeerReflexiveCandidate()
{
return Integer.toString(lastAssignedRemoteFoundation++);
}
/** /**
* Returns the number of foundation <tt>String</tt>s that are currently * Returns the number of foundation <tt>String</tt>s that are currently
* tracked by the registry. * tracked by the registry.

View File

@ -34,10 +34,10 @@ public class ConnectivityCheckServer
private final Agent parentAgent; 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. * new remote transport addresses.
*/ */
private final RemoteAddressHandler addressHandler; private final IncomingCheckProcessor addressHandler;
/** /**
* The stun stack that we will use for connectivity checks. * The stun stack that we will use for connectivity checks.
@ -53,7 +53,7 @@ public class ConnectivityCheckServer
* @param addressHandler the handler that * @param addressHandler the handler that
*/ */
public ConnectivityCheckServer(Agent parentAgent, public ConnectivityCheckServer(Agent parentAgent,
RemoteAddressHandler addressHandler) IncomingCheckProcessor addressHandler)
{ {
this.parentAgent = parentAgent; this.parentAgent = parentAgent;
this.addressHandler = addressHandler; this.addressHandler = addressHandler;
@ -102,7 +102,7 @@ public class ConnectivityCheckServer
long priority = priorityAttr.getPriority(); long priority = priorityAttr.getPriority();
//tell our address handler we saw a new remote address; //tell our address handler we saw a new remote address;
addressHandler.handleRemoteAddress(evt.getRemoteAddress(), addressHandler.incomingCheckReceived(evt.getRemoteAddress(),
evt.getLocalAddress(), evt.getLocalAddress(),
priority, remoteUfrag); priority, remoteUfrag);

View File

@ -51,7 +51,7 @@ public class Ice
+ (endTime - startTime) + "ms"); + (endTime - startTime) + "ms");
System.out.println("LocalAgent:\n" + localAgent); System.out.println("LocalAgent:\n" + localAgent);
localAgent.startChecks(); localAgent.startConnectivityEstablishment();
System.out.println("Local audio clist:\n" System.out.println("Local audio clist:\n"
+ localAgent.getStream("audio").getCheckList()); + localAgent.getStream("audio").getCheckList());