Implements client side valid list construction (RFC 5245: Section 7.1.3.2.2)
This commit is contained in:
parent
ba1fdf0a9d
commit
7e2b709d28
@ -156,15 +156,66 @@ public class CandidatePair
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the <tt>CandidatePairState</tt> of this pair to
|
||||||
|
* {@link CandidatePairState#FAILED}. This method should only be called by
|
||||||
|
* the ice agent, during the execution of the ICE procedures.
|
||||||
|
*/
|
||||||
|
public void setStateFailed()
|
||||||
|
{
|
||||||
|
setState(CandidatePairState.FAILED, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the <tt>CandidatePairState</tt> of this pair to
|
||||||
|
* {@link CandidatePairState#FROZEN}. This method should only be called by
|
||||||
|
* the ice agent, during the execution of the ICE procedures.
|
||||||
|
*/
|
||||||
|
public void setStateFrozen()
|
||||||
|
{
|
||||||
|
setState(CandidatePairState.FROZEN, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the <tt>CandidatePairState</tt> of this pair to
|
||||||
|
* {@link CandidatePairState#FROZEN}. This method should only be called by
|
||||||
|
* the ice agent, during the execution of the ICE procedures.
|
||||||
|
*
|
||||||
|
* @param tranID the {@link TransactionID} that we are using for the
|
||||||
|
* connectivity check in case we are entering the <tt>In-Progress</tt>
|
||||||
|
* state and <tt>null</tt> otherwise.
|
||||||
|
*/
|
||||||
|
public void setStateInProgress(TransactionID tranID)
|
||||||
|
{
|
||||||
|
setState(CandidatePairState.IN_PROGRESS, tranID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the <tt>CandidatePairState</tt> of this pair to
|
||||||
|
* {@link CandidatePairState#SUCCEEDED}. This method should only be called
|
||||||
|
* by the ice agent, during the execution of the ICE procedures.
|
||||||
|
*/
|
||||||
|
public void setStateSucceeded()
|
||||||
|
{
|
||||||
|
setState(CandidatePairState.SUCCEEDED, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the <tt>CandidatePairState</tt> of this pair to
|
||||||
|
* {@link CandidatePairState#WAITING}. This method should only be called by
|
||||||
|
* the ice agent, during the execution of the ICE procedures.
|
||||||
|
*/
|
||||||
|
public void setStateWaiting()
|
||||||
|
{
|
||||||
|
setState(CandidatePairState.WAITING, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the <tt>CandidatePairState</tt> of this pair to <tt>state</tt>. This
|
* Sets the <tt>CandidatePairState</tt> of this pair to <tt>state</tt>. This
|
||||||
* method should only be called by the ice agent, during the execution of
|
* method should only be called by the ice agent, during the execution of
|
||||||
* the ICE procedures. Note that passing a <tt>null</tt> transaction for the
|
* the ICE procedures. Note that passing a <tt>null</tt> transaction for the
|
||||||
* {@link CandidatePairState#IN_PROGRESS} or a non-<tt>null</tt> for any
|
* {@link CandidatePairState#IN_PROGRESS} or a non-<tt>null</tt> for any
|
||||||
* other state would cause an {@link IllegalArgumentException} to be thrown.
|
* other state would cause an {@link IllegalArgumentException} to be thrown.
|
||||||
* I know this is not the most elegant way to handle it but this method is
|
|
||||||
* supposed to only be used internally and I prefer the exception rather
|
|
||||||
* than implementing one method for every state transition.
|
|
||||||
*
|
*
|
||||||
* @param state the state that this candidate pair is to enter.
|
* @param state the state that this candidate pair is to enter.
|
||||||
* @param tranID the {@link TransactionID} that we are using for the
|
* @param tranID the {@link TransactionID} that we are using for the
|
||||||
@ -174,8 +225,8 @@ public class CandidatePair
|
|||||||
* @throws IllegalArgumentException if state is {@link CandidatePairState
|
* @throws IllegalArgumentException if state is {@link CandidatePairState
|
||||||
* #IN_PROGRESS} and <tt>tranID</tt> is <tt>null</tt>.
|
* #IN_PROGRESS} and <tt>tranID</tt> is <tt>null</tt>.
|
||||||
*/
|
*/
|
||||||
public synchronized void setState(CandidatePairState state,
|
private synchronized void setState(CandidatePairState state,
|
||||||
TransactionID tranID)
|
TransactionID tranID)
|
||||||
throws IllegalArgumentException
|
throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
this.state = state;
|
this.state = state;
|
||||||
@ -325,6 +376,10 @@ public class CandidatePair
|
|||||||
.remoteCandidate))
|
.remoteCandidate))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
//DO NOT change this method to also depend on other pair properties
|
||||||
|
//because the Conn Check Client counts on it only using the candidates
|
||||||
|
//for comparisons.
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -74,7 +74,7 @@ public class CheckList
|
|||||||
if(!triggeredCheckQueue.contains(pair))
|
if(!triggeredCheckQueue.contains(pair))
|
||||||
{
|
{
|
||||||
triggeredCheckQueue.add(pair);
|
triggeredCheckQueue.add(pair);
|
||||||
pair.setState(CandidatePairState.WAITING, null);
|
pair.setStateWaiting();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -257,7 +257,7 @@ public class CheckList
|
|||||||
|
|
||||||
while(pairsIter.hasNext())
|
while(pairsIter.hasNext())
|
||||||
{
|
{
|
||||||
pairsIter.next().setState(CandidatePairState.WAITING, null);
|
pairsIter.next().setStateWaiting();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -50,8 +50,7 @@ public class FoundationsRegistry
|
|||||||
= candidate.getBase().getTransportAddress().getHostAddress();
|
= candidate.getBase().getTransportAddress().getHostAddress();
|
||||||
String server = null;
|
String server = null;
|
||||||
|
|
||||||
if(candidate.getType()
|
if(candidate.getType() == CandidateType.SERVER_REFLEXIVE_CANDIDATE
|
||||||
== CandidateType.SERVER_REFLEXIVE_CANDIDATE
|
|
||||||
|| candidate.getType() == CandidateType.RELAYED_CANDIDATE)
|
|| candidate.getType() == CandidateType.RELAYED_CANDIDATE)
|
||||||
{
|
{
|
||||||
server = candidate.getStunServerAddress().getHostAddress();
|
server = candidate.getStunServerAddress().getHostAddress();
|
||||||
|
|||||||
@ -42,6 +42,15 @@ public class IceMediaStream
|
|||||||
private final LinkedHashMap<Integer, Component> components
|
private final LinkedHashMap<Integer, Component> components
|
||||||
= new LinkedHashMap<Integer, Component>();
|
= new LinkedHashMap<Integer, Component>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An ordered set of candidate pairs for a media stream that have been
|
||||||
|
* validated by a successful STUN transaction. This list is empty at the
|
||||||
|
* start of ICE processing, and fills as checks are performed, resulting in
|
||||||
|
* valid candidate pairs.
|
||||||
|
*/
|
||||||
|
private final TreeSet<CandidatePair> validList
|
||||||
|
= new TreeSet<CandidatePair>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The id that was last assigned to a component. The next id that we give
|
* The id that was last assigned to a component. The next id that we give
|
||||||
* to a component would be lastComponendID + 1;
|
* to a component would be lastComponendID + 1;
|
||||||
@ -535,4 +544,18 @@ public class IceMediaStream
|
|||||||
this.checkList.add(candidatePair);
|
this.checkList.add(candidatePair);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds <tt>pair</tt> to the <tt>valid list</tt> that this stream is
|
||||||
|
* maintaining.
|
||||||
|
*
|
||||||
|
* @param pair the {@link CandidatePair} to add to our valid list.
|
||||||
|
*/
|
||||||
|
public void addValidPair(CandidatePair pair)
|
||||||
|
{
|
||||||
|
synchronized (validList)
|
||||||
|
{
|
||||||
|
validList.add(pair);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -180,7 +180,7 @@ public class ConnectivityCheckClient
|
|||||||
|
|
||||||
logger.fine("Received a non-symmetric response for pair: "+ pair
|
logger.fine("Received a non-symmetric response for pair: "+ pair
|
||||||
+". Failing");
|
+". Failing");
|
||||||
pair.setState(CandidatePairState.FAILED, null);
|
pair.setStateFailed();
|
||||||
}
|
}
|
||||||
//handle error responses.
|
//handle error responses.
|
||||||
else if(evt.getResponse().getMessageType()
|
else if(evt.getResponse().getMessageType()
|
||||||
@ -220,7 +220,7 @@ public class ConnectivityCheckClient
|
|||||||
{
|
{
|
||||||
logger.fine("Received a success response with no "
|
logger.fine("Received a success response with no "
|
||||||
+"XOR_MAPPED_ADDRESS attribute.");
|
+"XOR_MAPPED_ADDRESS attribute.");
|
||||||
checkedPair.setState(CandidatePairState.FAILED, null);
|
checkedPair.setStateFailed();
|
||||||
return; //malformed error response
|
return; //malformed error response
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,20 +270,25 @@ public class ConnectivityCheckClient
|
|||||||
validLocalCandidate = peerReflexiveCandidate;
|
validLocalCandidate = peerReflexiveCandidate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//check if the resulting valid pair was already in our check lists.
|
||||||
|
CandidatePair existingPair = parentAgent.findCandidatePair(
|
||||||
|
validLocalCandidate.getTransportAddress(),
|
||||||
|
validRemoteCandidate.getTransportAddress());
|
||||||
|
|
||||||
// RFC 5245: 7.1.3.2.2. The agent constructs a candidate pair whose
|
// RFC 5245: 7.1.3.2.2. The agent constructs a candidate pair whose
|
||||||
// local candidate equals the mapped address of the response, and whose
|
// local candidate equals the mapped address of the response, and whose
|
||||||
// remote candidate equals the destination address to which the request
|
// remote candidate equals the destination address to which the request
|
||||||
// was sent. This is called a valid pair, since it has been validated
|
// was sent. This is called a valid pair, since it has been validated
|
||||||
// by a STUN connectivity check.
|
// by a STUN connectivity check.
|
||||||
CandidatePair validPair = new CandidatePair(validLocalCandidate,
|
CandidatePair validPair;
|
||||||
|
if(existingPair != null)
|
||||||
|
validPair = existingPair;
|
||||||
|
else
|
||||||
|
validPair = new CandidatePair(validLocalCandidate,
|
||||||
validRemoteCandidate);
|
validRemoteCandidate);
|
||||||
|
|
||||||
//If the pair equals the pair that generated the check or is on a check
|
validPair.getParentComponent().getParentStream()
|
||||||
//list currently, it is also added to the VALID LIST, which is
|
.addValidPair(validPair);
|
||||||
// maintained by the agent for each media stream.
|
|
||||||
|
|
||||||
//if
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -353,7 +358,7 @@ public class ConnectivityCheckClient
|
|||||||
{
|
{
|
||||||
logger.fine("Received an unrecoverable error response for pair "
|
logger.fine("Received an unrecoverable error response for pair "
|
||||||
+ pair + " will mark the pair as FAILED.");
|
+ pair + " will mark the pair as FAILED.");
|
||||||
pair.setState(CandidatePairState.FAILED, null);
|
pair.setStateFailed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,10 +483,9 @@ public class ConnectivityCheckClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(transactionID == null)
|
if(transactionID == null)
|
||||||
pairToCheck.setState(CandidatePairState.FAILED, null);
|
pairToCheck.setStateFailed();
|
||||||
else
|
else
|
||||||
pairToCheck.setState(
|
pairToCheck.setStateInProgress(transactionID);
|
||||||
CandidatePairState.IN_PROGRESS, transactionID);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -133,7 +133,7 @@ public class ConnectivityCheckServer
|
|||||||
if (!parentAgent.isControlling()
|
if (!parentAgent.isControlling()
|
||||||
&& request.contains(Attribute.USE_CANDIDATE))
|
&& request.contains(Attribute.USE_CANDIDATE))
|
||||||
{
|
{
|
||||||
|
/////////////!!!!!!!!!!!!!!! TODO continue here.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user