Makes it possible to complete connectivity establishment, create new streams, components and candidates and start a new connectivity establishment for them only.

This commit is contained in:
lubomir.marinov 2010-10-21 19:18:34 +00:00
parent 1d3ce5ee57
commit 7de929986c
4 changed files with 97 additions and 22 deletions

View File

@ -237,11 +237,11 @@ public class Agent
} }
/** /**
* Creates a new media stream and stores it * Creates a new media stream and stores it.
* *
* @param mediaStreamName the name of the media stream * @param mediaStreamName the name of the media stream
* *
* @return a reference to the newly created <tt>IceMediaStream</tt>. * @return the newly created and stored <tt>IceMediaStream</tt>
*/ */
public IceMediaStream createMediaStream(String mediaStreamName) public IceMediaStream createMediaStream(String mediaStreamName)
{ {
@ -297,6 +297,19 @@ public class Agent
Component component = stream.createComponent(transport); Component component = stream.createComponent(transport);
gatherCandidates(component, preferredPort, minPort, maxPort); gatherCandidates(component, preferredPort, minPort, maxPort);
/*
* Lyubomir: After we've gathered the LocalCandidate for a Component and
* before we've make them available to the caller, we have to make sure
* that the ConnectivityCheckServer is started. If there's been a
* previous connectivity establishment which has completed, it has
* stopped the ConnectivityCheckServer. If the ConnectivtyCheckServer is
* not started after we've made the gathered LocalCandidates available
* to the caller, the caller may send them and a connectivity check may
* arrive from the remote Agent.
*/
connCheckServer.start();
return component; return component;
} }
@ -501,7 +514,8 @@ public class Agent
protected void initCheckLists() protected void initCheckLists()
{ {
//first init the check list. //first init the check list.
List<IceMediaStream> streams = getStreams(); List<IceMediaStream> streams
= getStreamsWithPendingConnectivityEstablishment();
//init the maximum number of check list entries per stream. //init the maximum number of check list entries per stream.
int maxCheckListSize = Integer.getInteger( int maxCheckListSize = Integer.getInteger(
@ -731,6 +745,44 @@ public class Agent
} }
} }
/**
* Gets the <tt>IceMediaStream</tt>s registered with this <tt>Agent</tt> for
* which connectivity establishment is pending. For example, after a set of
* <tt>IceMediaStream</tt>s is registered with this <tt>Agent</tt>,
* connectivity establishment completes for them and then a new set of
* <tt>IceMediaStream</tt>s is registered with this <tt>Agent</tt>, the
* <tt>IceMediaStream</tt>s with pending connectivity establishment are
* those from the second set.
*
* @return a <tt>List</tt> of the <tt>IceMediaStream</tt>s registered with
* this <tt>Agent</tt> for which connectivity is pending.
*/
List<IceMediaStream> getStreamsWithPendingConnectivityEstablishment()
{
/*
* Lyubomir: We want to support establishing connectivity for streams
* which have been created after connectivity has been established for
* previously created streams. That is why we will remove the streams
* which have their connectivity checks completed or failed i.e. these
* streams have been handled by a previous connectivity establishment.
*/
List<IceMediaStream> streams = getStreams();
Iterator<IceMediaStream> streamIter = streams.iterator();
while (streamIter.hasNext())
{
IceMediaStream stream = streamIter.next();
CheckList checkList = stream.getCheckList();
CheckListState checkListState = checkList.getState();
if (CheckListState.COMPLETED.equals(checkListState)
|| CheckListState.FAILED.equals(checkListState))
streamIter.remove();
}
return streams;
}
/** /**
* Gets the <tt>StunStack</tt> used by this <tt>Agent</tt>. * Gets the <tt>StunStack</tt> used by this <tt>Agent</tt>.
* *

View File

@ -70,7 +70,10 @@ class ConnectivityCheckClient
public void startChecks() public void startChecks()
{ {
CheckList firstCheckList CheckList firstCheckList
= parentAgent.getStreams().get(0).getCheckList(); = parentAgent
.getStreamsWithPendingConnectivityEstablishment()
.get(0)
.getCheckList();
startChecks(firstCheckList); startChecks(firstCheckList);
} }

View File

@ -19,6 +19,7 @@ import org.ice4j.stack.*;
* checks. * checks.
* *
* @author Emil Ivov * @author Emil Ivov
* @author Lyubomir Marinov
*/ */
class ConnectivityCheckServer class ConnectivityCheckServer
implements RequestListener, implements RequestListener,
@ -28,14 +29,20 @@ class ConnectivityCheckServer
* The <tt>Logger</tt> used by the <tt>ConnectivityCheckServer</tt> * The <tt>Logger</tt> used by the <tt>ConnectivityCheckServer</tt>
* class and its instances for logging output. * class and its instances for logging output.
*/ */
private static final Logger logger = Logger private static final Logger logger
.getLogger(ConnectivityCheckServer.class.getName()); = Logger.getLogger(ConnectivityCheckServer.class.getName());
/** /**
* The agent that created us. * The agent that created us.
*/ */
private final Agent parentAgent; private final Agent parentAgent;
/**
* The indicator which determines whether this
* <tt>ConnectivityCheckServer</tt> is currently started.
*/
private boolean started = false;
/** /**
* The <tt>StunStack </tt> that we will use for connectivity checks. * The <tt>StunStack </tt> that we will use for connectivity checks.
*/ */
@ -53,8 +60,9 @@ class ConnectivityCheckServer
this.parentAgent = parentAgent; this.parentAgent = parentAgent;
stunStack = this.parentAgent.getStunStack(); stunStack = this.parentAgent.getStunStack();
stunStack.addRequestListener(this);
stunStack.getCredentialsManager().registerAuthority(this); stunStack.getCredentialsManager().registerAuthority(this);
start();
} }
/** /**
@ -366,10 +374,26 @@ class ConnectivityCheckServer
} }
/** /**
* Stops this server. * Starts this <tt>ConnectivityCheckServer</tt>. If it is not currently
* running, does nothing.
*/
public void start()
{
if (!started)
{
stunStack.addRequestListener(this);
started = true;
}
}
/**
* Stops this <tt>ConnectivityCheckServer</tt>. A stopped
* <tt>ConnectivityCheckServer</tt> can be restarted by calling
* {@link #start()} on it.
*/ */
public void stop() public void stop()
{ {
stunStack.removeRequestListener(this); stunStack.removeRequestListener(this);
started = false;
} }
} }

View File

@ -322,13 +322,9 @@ public class IceMediaStream
*/ */
protected void createCheckList(List<CandidatePair> checkList) protected void createCheckList(List<CandidatePair> checkList)
{ {
List<Component> componentsList = getComponents(); for(Component cmp : getComponents())
for(Component cmp : componentsList)
{
createCheckList(cmp, checkList); createCheckList(cmp, checkList);
} }
}
/** /**
* Creates and adds to <tt>checkList</tt> all the <tt>CandidatePair</tt>s * Creates and adds to <tt>checkList</tt> all the <tt>CandidatePair</tt>s
@ -348,15 +344,15 @@ public class IceMediaStream
{ {
for(Candidate remoteCnd : remoteCnds) for(Candidate remoteCnd : remoteCnds)
{ {
if(!localCnd.canReach(remoteCnd)) if(localCnd.canReach(remoteCnd))
continue; {
CandidatePair pair = new CandidatePair(localCnd, remoteCnd); CandidatePair pair = new CandidatePair(localCnd, remoteCnd);
checkList.add(pair); checkList.add(pair);
} }
} }
} }
}
/** /**
* Orders this stream's pair check list in decreasing order of pair * Orders this stream's pair check list in decreasing order of pair
@ -632,9 +628,9 @@ public class IceMediaStream
} }
/** /**
* Returns <tt>false</tt> if there is at least one nominated {@link * Returns <tt>true</tt> if there is at least one nominated {@link
* CandidatePair} in the valid list for every {@link Component} of this * CandidatePair} in the valid list for every {@link Component} of this
* stream and <tt>true</tt> otherwise. * stream and <tt>false</tt> otherwise.
* *
* @return <tt>true</tt> if there is at least one nominated {@link * @return <tt>true</tt> if there is at least one nominated {@link
* CandidatePair} in the valid list for every {@link Component} of this * CandidatePair} in the valid list for every {@link Component} of this