Implements candidate nomination as per sections 7.2.1.5. and 7.2.3.2.4. from RFC 5245
This commit is contained in:
parent
988de3fbff
commit
834b10cc69
@ -12,15 +12,14 @@ import java.math.*;
|
|||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.security.*;
|
import java.security.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.*;
|
|
||||||
|
|
||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
|
import org.ice4j.attribute.*;
|
||||||
import org.ice4j.ice.checks.*;
|
import org.ice4j.ice.checks.*;
|
||||||
import org.ice4j.ice.harvest.*;
|
import org.ice4j.ice.harvest.*;
|
||||||
|
import org.ice4j.message.*;
|
||||||
import org.ice4j.stack.*;
|
import org.ice4j.stack.*;
|
||||||
|
|
||||||
import sun.management.resources.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An <tt>Agent</tt> could be described as the main class (i.e. the chef d'orchestre)
|
* An <tt>Agent</tt> could be described as the main class (i.e. the chef d'orchestre)
|
||||||
* of an ICE implementation.
|
* of an ICE implementation.
|
||||||
@ -33,7 +32,6 @@ import sun.management.resources.*;
|
|||||||
* @author Emil Ivov
|
* @author Emil Ivov
|
||||||
*/
|
*/
|
||||||
public class Agent
|
public class Agent
|
||||||
implements IncomingCheckProcessor
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The default maximum size for check lists.
|
* The default maximum size for check lists.
|
||||||
@ -776,12 +774,14 @@ public class Agent
|
|||||||
* @param priority the priority that the remote party assigned to
|
* @param priority the priority that the remote party assigned to
|
||||||
* @param remoteUFrag the user fragment that we should be using when and if
|
* @param remoteUFrag the user fragment that we should be using when and if
|
||||||
* we decide to send a check to <tt>remoteAddress</tt>.
|
* we decide to send a check to <tt>remoteAddress</tt>.
|
||||||
*
|
* @param useCandidate indicates whether the incoming check {@link Request}
|
||||||
|
* contained the USE-CANDIDATE ICE attribute.
|
||||||
*/
|
*/
|
||||||
public void incomingCheckReceived(TransportAddress remoteAddress,
|
public void incomingCheckReceived(TransportAddress remoteAddress,
|
||||||
TransportAddress localAddress,
|
TransportAddress localAddress,
|
||||||
long priority,
|
long priority,
|
||||||
String remoteUFrag)
|
String remoteUFrag,
|
||||||
|
boolean useCandidate)
|
||||||
{
|
{
|
||||||
LocalCandidate localCandidate = findLocalCandidate(localAddress);
|
LocalCandidate localCandidate = findLocalCandidate(localAddress);
|
||||||
Component parentComponent = localCandidate.getParentComponent();
|
Component parentComponent = localCandidate.getParentComponent();
|
||||||
@ -795,6 +795,9 @@ public class Agent
|
|||||||
CandidatePair triggeredPair
|
CandidatePair triggeredPair
|
||||||
= new CandidatePair(localCandidate, remoteCandidate);
|
= new CandidatePair(localCandidate, remoteCandidate);
|
||||||
|
|
||||||
|
if(useCandidate)
|
||||||
|
triggeredPair.setUseCandidateReceived();
|
||||||
|
|
||||||
synchronized(startLock)
|
synchronized(startLock)
|
||||||
{
|
{
|
||||||
if(isStarted())
|
if(isStarted())
|
||||||
@ -817,40 +820,52 @@ public class Agent
|
|||||||
* there's already a pair with the specified remote and local addresses,
|
* there's already a pair with the specified remote and local addresses,
|
||||||
* puts it in the queue instead.
|
* puts it in the queue instead.
|
||||||
*
|
*
|
||||||
* @param triggeredPair the pair containing the local and remote candidate
|
* @param triggerPair the pair containing the local and remote candidate
|
||||||
* that we'd need to trigger a check for.
|
* that we'd need to trigger a check for.
|
||||||
*/
|
*/
|
||||||
private void triggerCheck(CandidatePair triggeredPair)
|
private void triggerCheck(CandidatePair triggerPair)
|
||||||
{
|
{
|
||||||
//first check whether we already know about the remote address in case
|
//first check whether we already know about the remote address in case
|
||||||
//we've just discovered a peer-reflexive candidate.
|
//we've just discovered a peer-reflexive candidate.
|
||||||
CandidatePair knownPair = this.findCandidatePair(
|
CandidatePair knownPair = this.findCandidatePair(
|
||||||
triggeredPair.getLocalCandidate().getTransportAddress(),
|
triggerPair.getLocalCandidate().getTransportAddress(),
|
||||||
triggeredPair.getRemoteCandidate().getTransportAddress());
|
triggerPair.getRemoteCandidate().getTransportAddress());
|
||||||
|
|
||||||
IceMediaStream parentStream = triggeredPair.getLocalCandidate()
|
IceMediaStream parentStream = triggerPair.getLocalCandidate()
|
||||||
.getParentComponent().getParentStream();
|
.getParentComponent().getParentStream();
|
||||||
|
|
||||||
if (knownPair != null)
|
if (knownPair != null)
|
||||||
{
|
{
|
||||||
triggeredPair = knownPair;
|
//if the incoming request contained a USE-CANDIDATE attribute then
|
||||||
|
//make sure we don't lose this piece of info.
|
||||||
|
if (triggerPair.useCandidateReceived())
|
||||||
|
knownPair.setUseCandidateReceived();
|
||||||
|
|
||||||
|
triggerPair = knownPair;
|
||||||
|
|
||||||
//we already know about the remote address so we only need to
|
//we already know about the remote address so we only need to
|
||||||
//trigger a check for the existing pair
|
//trigger a check for the existing pair
|
||||||
|
|
||||||
/**
|
|
||||||
* RFC 5245: If the state of that pair is Succeeded, nothing
|
|
||||||
* further is done.
|
|
||||||
*/
|
|
||||||
if (knownPair.getState() == CandidatePairState.SUCCEEDED )
|
if (knownPair.getState() == CandidatePairState.SUCCEEDED )
|
||||||
{
|
{
|
||||||
|
//7.2.1.5. Updating the Nominated Flag
|
||||||
|
if (!isControlling() && triggerPair.useCandidateReceived())
|
||||||
|
{
|
||||||
|
//If the state of this pair is Succeeded, it means that a
|
||||||
|
//previous check generated by this pair produced a
|
||||||
|
//successful response. This would have caused the agent to
|
||||||
|
//construct a valid pair when that success response was
|
||||||
|
//received. The agent now sets the nominated flag in the
|
||||||
|
//valid pair to true.
|
||||||
|
if( triggerPair.getState() == CandidatePairState.SUCCEEDED )
|
||||||
|
nominatePair( triggerPair );
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// RFC 5245: If the state of that pair is In-Progress, the agent
|
||||||
* RFC 5245: If the state of that pair is In-Progress, the agent
|
// cancels the in-progress transaction.
|
||||||
* cancels the in-progress transaction.
|
|
||||||
**/
|
|
||||||
if (knownPair.getState() == CandidatePairState.IN_PROGRESS )
|
if (knownPair.getState() == CandidatePairState.IN_PROGRESS )
|
||||||
{
|
{
|
||||||
TransactionID checkTransaction
|
TransactionID checkTransaction
|
||||||
@ -863,23 +878,35 @@ public class Agent
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
//it appears that we've just discovered a peer-reflexive address.
|
//it appears that we've just discovered a peer-reflexive address.
|
||||||
/*
|
// RFC 5245: If the pair is not already on the check list:
|
||||||
* RFC 5245: If the pair is not already on the check list:
|
// The pair is inserted into the check list based on its priority
|
||||||
* The pair is inserted into the check list based on its priority
|
// Its state is set to Waiting [and it] is enqueued into the
|
||||||
* Its state is set to Waiting [and it] is enqueued into the
|
// triggered check queue.
|
||||||
* triggered check queue.
|
//
|
||||||
*/
|
parentStream.addToCheckList(triggerPair);
|
||||||
parentStream.addToCheckList(triggeredPair);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// RFC 5245: The agent MUST create a new connectivity check for that
|
||||||
* RFC 5245: The agent MUST create a new connectivity check for that
|
// pair (representing a new STUN Binding request transaction) by
|
||||||
* pair (representing a new STUN Binding request transaction) by
|
// enqueueing the pair in the triggered check queue. The state of
|
||||||
* enqueueing the pair in the triggered check queue. The state of
|
// the pair is then changed to Waiting.
|
||||||
* the pair is then changed to Waiting.
|
// Emil: This actually applies for all cases.
|
||||||
* Emil: This actually applies for all case.
|
parentStream.getCheckList().scheduleTriggeredCheck(triggerPair);
|
||||||
*/
|
}
|
||||||
parentStream.getCheckList().scheduleTriggeredCheck(triggeredPair);
|
|
||||||
|
/**
|
||||||
|
* Looks for the specified {@link CandidatePair} with in the valid lists
|
||||||
|
* of the media streams and sets its nominated flag to <tt>true</tt>. This
|
||||||
|
* may end ICE processing for this media stream as per Section 8 in RFC
|
||||||
|
* 5245. The method has no effect if <tt>pairToNominate</tt> is not on any
|
||||||
|
* valid list.
|
||||||
|
*
|
||||||
|
* @param pairToNominate the pair that we'd like to nominate in case it's on
|
||||||
|
* a valid list somewhere.
|
||||||
|
*/
|
||||||
|
public void nominatePair(CandidatePair pairToNominate)
|
||||||
|
{
|
||||||
|
//implement todo !!!
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -39,6 +39,12 @@ public class CandidatePair
|
|||||||
*/
|
*/
|
||||||
private long priority;
|
private long priority;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A flag indicating whether we have seen an incoming check request that
|
||||||
|
* contained the USE-CANDIDATE attribute for this pair.
|
||||||
|
*/
|
||||||
|
private boolean useCandidate = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A <tt>Comparator</tt> using the <tt>compareTo</tt> method of the
|
* A <tt>Comparator</tt> using the <tt>compareTo</tt> method of the
|
||||||
* <tt>CandidatePair</tt>.
|
* <tt>CandidatePair</tt>.
|
||||||
@ -476,4 +482,24 @@ public class CandidatePair
|
|||||||
{
|
{
|
||||||
return connCheckTranID;
|
return connCheckTranID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Raises the <tt>useCandidate</tt> flag for this pair.
|
||||||
|
*/
|
||||||
|
public void setUseCandidateReceived()
|
||||||
|
{
|
||||||
|
this.useCandidate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns <tt>true</tt> if someone has previously raised this pair's
|
||||||
|
* <tt>useCandidate</tt> flag and <tt>false</tt> otherwise.
|
||||||
|
*
|
||||||
|
* @return <tt>true</tt> if someone has previously raised this pair's
|
||||||
|
* <tt>useCandidate</tt> flag and <tt>false</tt> otherwise.
|
||||||
|
*/
|
||||||
|
public boolean useCandidateReceived()
|
||||||
|
{
|
||||||
|
return useCandidate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -347,6 +347,23 @@ public class ConnectivityCheckClient
|
|||||||
if (wasFrozen)
|
if (wasFrozen)
|
||||||
startChecks(checkList);
|
startChecks(checkList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//If the agent was a controlling agent, and it had included a USE-
|
||||||
|
//CANDIDATE attribute in the Binding request, the valid pair generated
|
||||||
|
//from that check has its nominated flag set to true.
|
||||||
|
if(parentAgent.isControlling()
|
||||||
|
&& request.contains(Attribute.USE_CANDIDATE))
|
||||||
|
{
|
||||||
|
parentAgent.nominatePair( validPair );
|
||||||
|
}
|
||||||
|
//If the agent is the controlled agent, the response may be the result
|
||||||
|
//of a triggered check that was sent in response to a request that
|
||||||
|
//itself had the USE-CANDIDATE attribute. This case is described in
|
||||||
|
//Section 7.2.1.5, and may now result in setting the nominated flag for
|
||||||
|
//the pair learned from the original request.
|
||||||
|
else if(checkedPair.useCandidateReceived())
|
||||||
|
parentAgent.nominatePair( checkedPair );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -109,11 +109,11 @@ public class ConnectivityCheckServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
long priority = extractPriority(request);
|
long priority = extractPriority(request);
|
||||||
|
boolean useCandidate = request.contains(Attribute.USE_CANDIDATE);
|
||||||
|
|
||||||
//tell our address handler we saw a new remote address;
|
//tell our address handler we saw a new remote address;
|
||||||
addressHandler.incomingCheckReceived(evt.getRemoteAddress(),
|
parentAgent.incomingCheckReceived(evt.getRemoteAddress(),
|
||||||
evt.getLocalAddress(),
|
evt.getLocalAddress(), priority, remoteUfrag, useCandidate);
|
||||||
priority, remoteUfrag);
|
|
||||||
|
|
||||||
Response response = MessageFactory.createBindingResponse(
|
Response response = MessageFactory.createBindingResponse(
|
||||||
request, evt.getRemoteAddress());
|
request, evt.getRemoteAddress());
|
||||||
@ -129,12 +129,6 @@ public class ConnectivityCheckServer
|
|||||||
//then chances are the 500 will fail too.
|
//then chances are the 500 will fail too.
|
||||||
throw new RuntimeException("Failed to send a response", e);
|
throw new RuntimeException("Failed to send a response", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parentAgent.isControlling()
|
|
||||||
&& request.contains(Attribute.USE_CANDIDATE))
|
|
||||||
{
|
|
||||||
/////////////!!!!!!!!!!!!!!! TODO continue here.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
* ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
|
|
||||||
* Maintained by the SIP Communicator community (http://sip-communicator.org).
|
|
||||||
*
|
|
||||||
* Distributable under LGPL license. See terms of license at gnu.org.
|
|
||||||
*/
|
|
||||||
package org.ice4j.ice.checks;
|
|
||||||
|
|
||||||
import org.ice4j.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This interface is used by {@link ConnectivityCheckServer}s to deliver remote
|
|
||||||
* addresses that they see while handling incoming connectivity checks.
|
|
||||||
* Implementations of this interface should determine whether these addresses
|
|
||||||
* were (or will be) advertised by the remote peer and, if not, consider them
|
|
||||||
* as new, peer reflexive candidates.
|
|
||||||
* <p>
|
|
||||||
* This is also the interface that allows us to queue triggered checks.
|
|
||||||
*
|
|
||||||
* @author Emil Ivov
|
|
||||||
*/
|
|
||||||
public interface IncomingCheckProcessor
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Notifies the implementation that the {@link ConnectivityCheckServer} has
|
|
||||||
* just received a message on <tt>localAddress</tt> originating at
|
|
||||||
* <tt>remoteAddress</tt> carrying the specified <tt>priority</tt>. This
|
|
||||||
* will cause us to schedule a triggered check for the corresponding
|
|
||||||
* remote candidate and potentially to the discovery of a PEER-REFLEXIVE
|
|
||||||
* candidate.
|
|
||||||
*
|
|
||||||
* @param remoteAddress the address that we've just seen, and that is
|
|
||||||
* potentially a peer-reflexive address.
|
|
||||||
* @param localAddress the address that we were contacted on.
|
|
||||||
* @param priority the priority that the remote party assigned to
|
|
||||||
* @param remoteUFrag the user fragment that we should be using when and if
|
|
||||||
* we decide to send a check to <tt>remoteAddress</tt>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void incomingCheckReceived(TransportAddress remoteAddress,
|
|
||||||
TransportAddress localAddress,
|
|
||||||
long priority,
|
|
||||||
String remoteUFrag);
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user