Starts work on supporting triggered checks and peer-reflexive candidate discovery
This commit is contained in:
parent
9d07b54f05
commit
a3bd377fe7
@ -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<RemoteCandidate> preDiscoveredRemoteCandidatesQueue
|
||||
= new Vector<RemoteCandidate>();
|
||||
private final List<CandidatePair> preDiscoveredPairsQueue
|
||||
= 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.
|
||||
@ -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<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)
|
||||
return cnd;
|
||||
@ -692,29 +693,50 @@ public class Agent
|
||||
* we decide to send a check to <tt>remoteAddress</tt>.
|
||||
*
|
||||
*/
|
||||
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 <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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,6 +22,12 @@ public class FoundationsRegistry
|
||||
*/
|
||||
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
|
||||
* <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
|
||||
* 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 <tt>Candidate</tt> 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 <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
|
||||
* tracked by the registry.
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user