Moves the check lists back to the stream ... sigh ... i am currently quite annoyed with jr.
This commit is contained in:
parent
ce7ec76677
commit
9727d3dc9e
@ -37,6 +37,18 @@ public class Agent
|
|||||||
private static final Logger logger
|
private static final Logger logger
|
||||||
= Logger.getLogger(Agent.class.getName());
|
= Logger.getLogger(Agent.class.getName());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the System property that allows us to set a custom maximum
|
||||||
|
* for check list sizes.
|
||||||
|
*/
|
||||||
|
public static final String PNAME_MAX_CHECK_LIST_SIZE
|
||||||
|
= "org.ice4j.MAX_CHECK_LIST_SIZE";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default maximum size for check lists.
|
||||||
|
*/
|
||||||
|
public static final int DEFAULT_MAX_CHECK_LIST_SIZE = 100;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The LinkedHashMap used to store the media streams
|
* The LinkedHashMap used to store the media streams
|
||||||
* This map preserves the insertion order of the media streams.
|
* This map preserves the insertion order of the media streams.
|
||||||
@ -58,18 +70,6 @@ public class Agent
|
|||||||
private final List<CandidateHarvester> harvesters
|
private final List<CandidateHarvester> harvesters
|
||||||
= new ArrayList<CandidateHarvester>();
|
= new ArrayList<CandidateHarvester>();
|
||||||
|
|
||||||
/**
|
|
||||||
* The name of the System property that allows us to set a custom maximum
|
|
||||||
* for check list sizes.
|
|
||||||
*/
|
|
||||||
public static final String PNAME_MAX_CHECK_LIST_SIZE
|
|
||||||
= "org.ice4j.MAX_CHECK_LIST_SIZE";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default maximum size for check lists.
|
|
||||||
*/
|
|
||||||
public static final int DEFAULT_MAX_CHECK_LIST_SIZE = 100;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We use the <tt>FoundationsRegistry</tt> to keep track of the foundations
|
* We use the <tt>FoundationsRegistry</tt> to keep track of the foundations
|
||||||
* we assign within a session (i.e. the entire life time of an
|
* we assign within a session (i.e. the entire life time of an
|
||||||
@ -77,17 +77,6 @@ public class Agent
|
|||||||
*/
|
*/
|
||||||
private FoundationsRegistry foundationsRegistry = new FoundationsRegistry();
|
private FoundationsRegistry foundationsRegistry = new FoundationsRegistry();
|
||||||
|
|
||||||
/**
|
|
||||||
* The CHECK-LIST for this agent described in the ICE specification. Note
|
|
||||||
* that even though this may sound a bit unclear in the spec,
|
|
||||||
* <tt>checkList</tt>s are supposed to be created on a per-agent basis so
|
|
||||||
* that we could, for example, freeze candidates with common foundations
|
|
||||||
* across streams and not only across components, and so that we could
|
|
||||||
* limit the total number of candidate pairs for all streams.
|
|
||||||
*/
|
|
||||||
private final List<CandidatePair> checkList
|
|
||||||
= new LinkedList<CandidatePair>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user fragment that we should use for the ice-ufrag attribute.
|
* The user fragment that we should use for the ice-ufrag attribute.
|
||||||
*/
|
*/
|
||||||
@ -238,112 +227,33 @@ public class Agent
|
|||||||
component.selectDefaultCandidate();
|
component.selectDefaultCandidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the list of <tt>CandidatePair</tt>s to be used in checks for
|
|
||||||
* this agent.
|
|
||||||
*
|
|
||||||
* @return the list of <tt>CandidatePair</tt>s to be used in checks for
|
|
||||||
* this agent.
|
|
||||||
*/
|
|
||||||
public List<CandidatePair> getCheckList()
|
|
||||||
{
|
|
||||||
return checkList;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes all stream check lists and begins the checks.
|
* Initializes all stream check lists and begins the checks.
|
||||||
*/
|
*/
|
||||||
public void startChecks()
|
public void startChecks()
|
||||||
{
|
{
|
||||||
initCheckList();
|
initCheckLists();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
protected void initCheckList()
|
protected void initCheckLists()
|
||||||
{
|
{
|
||||||
//first init the check list.
|
//first init the check list.
|
||||||
synchronized(checkList)
|
List<IceMediaStream> streams = getStreams();
|
||||||
{
|
|
||||||
checkList.clear();
|
|
||||||
List<IceMediaStream> streams = getStreams();
|
|
||||||
|
|
||||||
for(IceMediaStream stream : streams)
|
|
||||||
{
|
|
||||||
stream.createCheckList(checkList);
|
|
||||||
}
|
|
||||||
|
|
||||||
orderCheckList();
|
|
||||||
pruneCheckList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Orders this stream's pair check list in decreasing order of pair
|
|
||||||
* priority. If two pairs have identical priority, the ordering amongst
|
|
||||||
* them is arbitrary.
|
|
||||||
*/
|
|
||||||
private void orderCheckList()
|
|
||||||
{
|
|
||||||
Collections.sort(checkList, CandidatePair.comparator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes or, as per the ICE spec, "prunes" pairs that we don't need to
|
|
||||||
* run checks for. For example, since we cannot send requests directly
|
|
||||||
* from a reflexive candidate, but only from its base, we go through the
|
|
||||||
* sorted list of candidate pairs and in every pair where the local
|
|
||||||
* candidate is server reflexive, we replace the local server reflexive
|
|
||||||
* candidate with its base. Once this has been done, we remove each pair
|
|
||||||
* where the local and remote candidates are identical to the local and
|
|
||||||
* remote candidates of a pair higher up on the priority list.
|
|
||||||
* <p/>
|
|
||||||
* In addition, in order to limit the attacks described in Section 18.5.2
|
|
||||||
* of the ICE spec, we limit the total number of pairs and hence
|
|
||||||
* (connectivity checks) to a specific value, (100 by default).
|
|
||||||
*/
|
|
||||||
private void pruneCheckList()
|
|
||||||
{
|
|
||||||
//a list that we only use for storing pairs that we've already gone
|
|
||||||
//through. The list is destroyed at the end of this method.
|
|
||||||
List<CandidatePair> tmpCheckList
|
|
||||||
= new ArrayList<CandidatePair>(checkList.size());
|
|
||||||
|
|
||||||
Iterator<CandidatePair> ckListIter = checkList.iterator();
|
|
||||||
|
|
||||||
|
//init the maximum number of check list entries per stream.
|
||||||
int maxCheckListSize = Integer.getInteger(
|
int maxCheckListSize = Integer.getInteger(
|
||||||
PNAME_MAX_CHECK_LIST_SIZE, DEFAULT_MAX_CHECK_LIST_SIZE);
|
PNAME_MAX_CHECK_LIST_SIZE, DEFAULT_MAX_CHECK_LIST_SIZE);
|
||||||
|
|
||||||
while(ckListIter.hasNext())
|
int maxPerStreamSize = maxCheckListSize / streams.size();
|
||||||
|
|
||||||
|
for(IceMediaStream stream : streams)
|
||||||
{
|
{
|
||||||
CandidatePair pair = ckListIter.next();
|
stream.setMaxCheckListSize(maxPerStreamSize);
|
||||||
|
stream.initCheckList();
|
||||||
//drop all pairs above MAX_CHECK_LIST_SIZE.
|
|
||||||
if(tmpCheckList.size() > maxCheckListSize)
|
|
||||||
{
|
|
||||||
ckListIter.remove();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//replace local server reflexive candidates with their base.
|
|
||||||
LocalCandidate localCnd = pair.getLocalCandidate();
|
|
||||||
if( localCnd.getType()
|
|
||||||
== CandidateType.SERVER_REFLEXIVE_CANDIDATE)
|
|
||||||
{
|
|
||||||
pair.setLocalCandidate(localCnd.getBase());
|
|
||||||
|
|
||||||
//if the new pair corresponds to another one with a higher
|
|
||||||
//priority, then remove it.
|
|
||||||
if(tmpCheckList.contains(pair))
|
|
||||||
{
|
|
||||||
ckListIter.remove();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpCheckList.add(pair);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -48,11 +48,30 @@ public class IceMediaStream
|
|||||||
*/
|
*/
|
||||||
private int lastComponentID = 0;
|
private int lastComponentID = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The CHECK-LIST for this agent described in the ICE specification: There
|
||||||
|
* is one check list per in-use media stream resulting from the offer/answer
|
||||||
|
* exchange.
|
||||||
|
*/
|
||||||
|
private final List<CandidatePair> checkList
|
||||||
|
= new LinkedList<CandidatePair>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The agent that this media stream belongs to.
|
* The agent that this media stream belongs to.
|
||||||
*/
|
*/
|
||||||
private final Agent parentAgent;
|
private final Agent parentAgent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum number of candidate pairs that we should have in our check
|
||||||
|
* list. This value depends on the total number of media streams which is
|
||||||
|
* why it should be set by the agent:
|
||||||
|
* In addition, in order to limit the attacks described in Section 18.5.2,
|
||||||
|
* an agent MUST limit the total number of connectivity checks they perform
|
||||||
|
* across all check lists to a specific value, adn this value MUST be
|
||||||
|
* configurable. A default of 100 is RECOMMENDED.
|
||||||
|
*/
|
||||||
|
private int maxCheckListSize = Agent.DEFAULT_MAX_CHECK_LIST_SIZE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a new <tt>IceMediaStream</tt> object.
|
* Initializes a new <tt>IceMediaStream</tt> object.
|
||||||
*
|
*
|
||||||
@ -244,6 +263,87 @@ public class IceMediaStream
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates, initializes and orders the list of candidate pairs that would
|
||||||
|
* be used for the connectivity checks for all components in this stream.
|
||||||
|
*/
|
||||||
|
protected void initCheckList()
|
||||||
|
{
|
||||||
|
//first init the check list.
|
||||||
|
synchronized(checkList)
|
||||||
|
{
|
||||||
|
checkList.clear();
|
||||||
|
createCheckList(checkList);
|
||||||
|
|
||||||
|
orderCheckList();
|
||||||
|
pruneCheckList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Orders this stream's pair check list in decreasing order of pair
|
||||||
|
* priority. If two pairs have identical priority, the ordering amongst
|
||||||
|
* them is arbitrary.
|
||||||
|
*/
|
||||||
|
private void orderCheckList()
|
||||||
|
{
|
||||||
|
Collections.sort(checkList, CandidatePair.comparator);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes or, as per the ICE spec, "prunes" pairs that we don't need to
|
||||||
|
* run checks for. For example, since we cannot send requests directly
|
||||||
|
* from a reflexive candidate, but only from its base, we go through the
|
||||||
|
* sorted list of candidate pairs and in every pair where the local
|
||||||
|
* candidate is server reflexive, we replace the local server reflexive
|
||||||
|
* candidate with its base. Once this has been done, we remove each pair
|
||||||
|
* where the local and remote candidates are identical to the local and
|
||||||
|
* remote candidates of a pair higher up on the priority list.
|
||||||
|
* <p/>
|
||||||
|
* In addition, in order to limit the attacks described in Section 18.5.2
|
||||||
|
* of the ICE spec, we limit the total number of pairs and hence
|
||||||
|
* (connectivity checks) to a specific value, (a total of 100 by default).
|
||||||
|
*/
|
||||||
|
private void pruneCheckList()
|
||||||
|
{
|
||||||
|
//a list that we only use for storing pairs that we've already gone
|
||||||
|
//through. The list is destroyed at the end of this method.
|
||||||
|
List<CandidatePair> tmpCheckList
|
||||||
|
= new ArrayList<CandidatePair>(checkList.size());
|
||||||
|
|
||||||
|
Iterator<CandidatePair> ckListIter = checkList.iterator();
|
||||||
|
|
||||||
|
while(ckListIter.hasNext())
|
||||||
|
{
|
||||||
|
CandidatePair pair = ckListIter.next();
|
||||||
|
|
||||||
|
//drop all pairs above MAX_CHECK_LIST_SIZE.
|
||||||
|
if(tmpCheckList.size() > maxCheckListSize)
|
||||||
|
{
|
||||||
|
ckListIter.remove();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//replace local server reflexive candidates with their base.
|
||||||
|
LocalCandidate localCnd = pair.getLocalCandidate();
|
||||||
|
if( localCnd.getType()
|
||||||
|
== CandidateType.SERVER_REFLEXIVE_CANDIDATE)
|
||||||
|
{
|
||||||
|
pair.setLocalCandidate(localCnd.getBase());
|
||||||
|
|
||||||
|
//if the new pair corresponds to another one with a higher
|
||||||
|
//priority, then remove it.
|
||||||
|
if(tmpCheckList.contains(pair))
|
||||||
|
{
|
||||||
|
ckListIter.remove();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpCheckList.add(pair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
@ -287,4 +387,26 @@ public class IceMediaStream
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the list of <tt>CandidatePair</tt>s to be used in checks for
|
||||||
|
* this stream.
|
||||||
|
*
|
||||||
|
* @return the list of <tt>CandidatePair</tt>s to be used in checks for
|
||||||
|
* this stream.
|
||||||
|
*/
|
||||||
|
public List<CandidatePair> getCheckList()
|
||||||
|
{
|
||||||
|
return checkList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the maximum number of pairs that we should have in our check list.
|
||||||
|
*
|
||||||
|
* @param nSize the size of our check list.
|
||||||
|
*/
|
||||||
|
protected void setMaxCheckListSize(int nSize)
|
||||||
|
{
|
||||||
|
this.maxCheckListSize = nSize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,7 +48,10 @@ public class Ice
|
|||||||
|
|
||||||
localAgent.startChecks();
|
localAgent.startChecks();
|
||||||
|
|
||||||
System.out.println("Local audio clist:\n" + localAgent.getCheckList());
|
System.out.println("Local audio clist:\n"
|
||||||
|
+ localAgent.getStream("audio").getCheckList());
|
||||||
|
System.out.println("Local audio clist:\n"
|
||||||
|
+ localAgent.getStream("video").getCheckList());
|
||||||
|
|
||||||
System.out.println("Total execution time: "
|
System.out.println("Total execution time: "
|
||||||
+ (endTime - startTime) + "ms");
|
+ (endTime - startTime) + "ms");
|
||||||
@ -196,7 +199,7 @@ public class Ice
|
|||||||
//simultaneously with the others.
|
//simultaneously with the others.
|
||||||
|
|
||||||
//rtp
|
//rtp
|
||||||
Component rtpComp = agent.createComponent(
|
agent.createComponent(
|
||||||
stream, Transport.UDP, rtpPort, rtpPort, rtpPort + 100);
|
stream, Transport.UDP, rtpPort, rtpPort, rtpPort + 100);
|
||||||
|
|
||||||
long endTime = System.currentTimeMillis();
|
long endTime = System.currentTimeMillis();
|
||||||
@ -204,7 +207,7 @@ public class Ice
|
|||||||
+ (endTime - startTime) +" ms");
|
+ (endTime - startTime) +" ms");
|
||||||
startTime = endTime;
|
startTime = endTime;
|
||||||
//rtcpComp
|
//rtcpComp
|
||||||
Component rtcpComp = agent.createComponent(
|
agent.createComponent(
|
||||||
stream, Transport.UDP, rtpPort + 1, rtpPort + 1, rtpPort + 101);
|
stream, Transport.UDP, rtpPort + 1, rtpPort + 1, rtpPort + 101);
|
||||||
|
|
||||||
endTime = System.currentTimeMillis();
|
endTime = System.currentTimeMillis();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user