Adds a separate class for check lists so that we could set their state. Implements check/pair state initialization
This commit is contained in:
parent
9727d3dc9e
commit
85415978b0
@ -365,4 +365,14 @@ public class CandidatePair
|
|||||||
return obj instanceof PairComparator;
|
return obj instanceof PairComparator;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the <tt>Component</tt> that this pair belongs to.
|
||||||
|
*
|
||||||
|
* @return the <tt>Component</tt> that this pair belongs to.
|
||||||
|
*/
|
||||||
|
public Component getParentComponent()
|
||||||
|
{
|
||||||
|
return getLocalCandidate().getParentComponent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
23
src/org/ice4j/ice/CheckList.java
Normal file
23
src/org/ice4j/ice/CheckList.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A check list is a list of <tt>CandidatePair</tt>s with a state (i.e. a
|
||||||
|
* <tt>CheckListState</tt>). The pairs in a check list are those that an ICE
|
||||||
|
* agent will run STUN connectivity checks for. There is one check list per
|
||||||
|
* in-use media stream resulting from the offer/answer exchange.
|
||||||
|
*
|
||||||
|
* @author Emil Ivov
|
||||||
|
*/
|
||||||
|
public class CheckList
|
||||||
|
extends LinkedList<CandidatePair>
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
76
src/org/ice4j/ice/CheckListState.java
Normal file
76
src/org/ice4j/ice/CheckListState.java
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Everty <tt>CheckList</tt> is associated with a state, which captures the
|
||||||
|
* state of ICE checks for that media stream. There are three states:
|
||||||
|
* <p/>
|
||||||
|
* Running: In this state, ICE checks are still in progress for this
|
||||||
|
* media stream.
|
||||||
|
* <p/>
|
||||||
|
* Completed: In this state, ICE checks have produced nominated pairs
|
||||||
|
* for each component of the media stream. Consequently, ICE has succeeded and
|
||||||
|
* media can be sent.
|
||||||
|
* <p/>
|
||||||
|
* Failed: In this state, the ICE checks have not completed successfully for
|
||||||
|
* this media stream.
|
||||||
|
* <p/>
|
||||||
|
* When a check list is first constructed as the consequence of an offer/answer
|
||||||
|
* exchange, it is placed in the Running state.
|
||||||
|
*
|
||||||
|
* @author Emil Ivov
|
||||||
|
*/
|
||||||
|
public enum CheckListState
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* In this state, ICE checks are still in progress for this media stream.
|
||||||
|
*/
|
||||||
|
RUNNING("Running"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In this state, ICE checks have produced nominated pairs for each
|
||||||
|
* component of the media stream. Consequently, ICE has succeeded and
|
||||||
|
* media can be sent.
|
||||||
|
*/
|
||||||
|
COMPLETED("Completed"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In this state, the ICE checks have not completed successfully for this
|
||||||
|
* media stream.
|
||||||
|
*/
|
||||||
|
FAILED("Failed");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of this <tt>CheckListState</tt> instance.
|
||||||
|
*/
|
||||||
|
private final String stateName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a <tt>CheckListState</tt> instance with the specified name.
|
||||||
|
*
|
||||||
|
* @param stateName the name of the <tt>CheckListState</tt> instance
|
||||||
|
* we'd like to create.
|
||||||
|
*/
|
||||||
|
private CheckListState(String stateName)
|
||||||
|
{
|
||||||
|
this.stateName = stateName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of this <tt>CheckListStae</tt> (i.e.. "Running",
|
||||||
|
* "Completed", or "Failed").
|
||||||
|
*
|
||||||
|
* @return the name of this <tt>CheckListStae</tt> (i.e.. "Running",
|
||||||
|
* "Completed", or "Failed").
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return stateName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -53,8 +53,7 @@ public class IceMediaStream
|
|||||||
* is one check list per in-use media stream resulting from the offer/answer
|
* is one check list per in-use media stream resulting from the offer/answer
|
||||||
* exchange.
|
* exchange.
|
||||||
*/
|
*/
|
||||||
private final List<CandidatePair> checkList
|
private final CheckList checkList = new CheckList();
|
||||||
= new LinkedList<CandidatePair>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The agent that this media stream belongs to.
|
* The agent that this media stream belongs to.
|
||||||
@ -277,6 +276,51 @@ public class IceMediaStream
|
|||||||
|
|
||||||
orderCheckList();
|
orderCheckList();
|
||||||
pruneCheckList();
|
pruneCheckList();
|
||||||
|
computeInitialCheckListPairStates();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates, initializes and orders the list of candidate pairs that would
|
||||||
|
* be used for the connectivity checks for all components in this stream.
|
||||||
|
*
|
||||||
|
* @param checkList the list that we need to update with the new pairs.
|
||||||
|
*/
|
||||||
|
protected void createCheckList(List<CandidatePair> checkList)
|
||||||
|
{
|
||||||
|
List<Component> componentsList = getComponents();
|
||||||
|
|
||||||
|
for(Component cmp : componentsList)
|
||||||
|
{
|
||||||
|
createCheckList(cmp, checkList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and adds to <tt>checkList</tt> all the <tt>CandidatePair</tt>s
|
||||||
|
* in <tt>component</tt>.
|
||||||
|
*
|
||||||
|
* @param component the <tt>Component</tt> whose candidates we need to
|
||||||
|
* pair and extract.
|
||||||
|
* @param checkList the list that we need to update with the new pairs.
|
||||||
|
*/
|
||||||
|
private void createCheckList(Component component,
|
||||||
|
List<CandidatePair> checkList)
|
||||||
|
{
|
||||||
|
List<LocalCandidate> localCnds = component.getLocalCandidates();
|
||||||
|
List<Candidate> remoteCnds = component.getRemoteCandidates();
|
||||||
|
|
||||||
|
for(LocalCandidate localCnd : localCnds)
|
||||||
|
{
|
||||||
|
for(Candidate remoteCnd : remoteCnds)
|
||||||
|
{
|
||||||
|
if(!localCnd.canReach(remoteCnd))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
CandidatePair pair = new CandidatePair(localCnd, remoteCnd);
|
||||||
|
|
||||||
|
checkList.add(pair);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,46 +389,59 @@ public class IceMediaStream
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates, initializes and orders the list of candidate pairs that would
|
* Computes and resets states of all pairs in this check list. For all pairs
|
||||||
* be used for the connectivity checks for all components in this stream.
|
* with the same foundation, we set the state of the pair with the lowest
|
||||||
*
|
* component ID to Waiting. If there is more than one such pair, the one
|
||||||
* @param checkList the list that we need to update with the new pairs.
|
* with the highest priority is used.
|
||||||
*/
|
*/
|
||||||
protected void createCheckList(List<CandidatePair> checkList)
|
protected void computeInitialCheckListPairStates()
|
||||||
{
|
{
|
||||||
List<Component> componentsList = getComponents();
|
Map<String, CandidatePair> pairsToWait
|
||||||
|
= new Hashtable<String, CandidatePair>();
|
||||||
|
|
||||||
for(Component cmp : componentsList)
|
//first, determine the pairs that we'd need to put in the waiting state.
|
||||||
|
for(CandidatePair pair : checkList)
|
||||||
{
|
{
|
||||||
createCheckList(cmp, checkList);
|
//we need to check whether the pair is already in the wait list. if
|
||||||
}
|
//so we'll compare it with this one and determine which of the two
|
||||||
}
|
//needs to stay.
|
||||||
|
CandidatePair prevPair = pairsToWait.get(pair.getFoundation());
|
||||||
|
|
||||||
/**
|
if(prevPair == null)
|
||||||
* Creates and adds to <tt>checkList</tt> all the <tt>CandidatePair</tt>s
|
|
||||||
* in <tt>component</tt>.
|
|
||||||
*
|
|
||||||
* @param component the <tt>Component</tt> whose candidates we need to
|
|
||||||
* pair and extract.
|
|
||||||
* @param checkList the list that we need to update with the new pairs.
|
|
||||||
*/
|
|
||||||
private void createCheckList(Component component,
|
|
||||||
List<CandidatePair> checkList)
|
|
||||||
{
|
{
|
||||||
List<LocalCandidate> localCnds = component.getLocalCandidates();
|
//first pair with this foundation.
|
||||||
List<Candidate> remoteCnds = component.getRemoteCandidates();
|
pairsToWait.put(pair.getFoundation(), pair);
|
||||||
|
|
||||||
for(LocalCandidate localCnd : localCnds)
|
|
||||||
{
|
|
||||||
for(Candidate remoteCnd : remoteCnds)
|
|
||||||
{
|
|
||||||
if(!localCnd.canReach(remoteCnd))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
CandidatePair pair = new CandidatePair(localCnd, remoteCnd);
|
|
||||||
|
|
||||||
checkList.add(pair);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//we already have a pair with the same foundation. determine which
|
||||||
|
//of the two has the lower component id and higher priority and
|
||||||
|
//keep that one in the list.
|
||||||
|
if( prevPair.getParentComponent() == pair.getParentComponent())
|
||||||
|
{
|
||||||
|
if(pair.getPriority() > prevPair.getPriority())
|
||||||
|
{
|
||||||
|
//need to replace the pair in the list.
|
||||||
|
pairsToWait.put(pair.getFoundation(), pair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(pair.getParentComponent().getComponentID()
|
||||||
|
< prevPair.getParentComponent().getComponentID())
|
||||||
|
{
|
||||||
|
//need to replace the pair in the list.
|
||||||
|
pairsToWait.put(pair.getFoundation(), pair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//now put the pairs we've selected in the Waiting state.
|
||||||
|
Iterator<CandidatePair> pairsIter = pairsToWait.values().iterator();
|
||||||
|
|
||||||
|
while(pairsIter.hasNext())
|
||||||
|
{
|
||||||
|
pairsIter.next().setState(CandidatePairState.WAITING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user