Keeps the Conn Check Server going until we free the agent at the end of a call, so that we can answer STUN binding requests (that Chrome's WebRTC impl seems to be using to determine if we're still there
This commit is contained in:
parent
4cc6d4ab72
commit
a9d4dc4406
@ -565,8 +565,23 @@ public class Agent
|
|||||||
*/
|
*/
|
||||||
public boolean isStarted()
|
public boolean isStarted()
|
||||||
{
|
{
|
||||||
return state != IceProcessingState.WAITING &&
|
return state != IceProcessingState.WAITING
|
||||||
state != IceProcessingState.TERMINATED;
|
&& state != IceProcessingState.COMPLETED
|
||||||
|
&& state != IceProcessingState.TERMINATED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether this {@link Agent} has finished ICE processing.
|
||||||
|
*
|
||||||
|
* @return <tt>true</tt> if ICE processing is in the {@link
|
||||||
|
* IceProcessingState#FAILED}, {@link IceProcessingState#COMPLETED} or
|
||||||
|
* {@link IceProcessingState#TERMINATED} and <tt>false</tt> otherwise.
|
||||||
|
*/
|
||||||
|
public boolean isOver()
|
||||||
|
{
|
||||||
|
return state == IceProcessingState.COMPLETED
|
||||||
|
|| state != IceProcessingState.TERMINATED
|
||||||
|
|| state != IceProcessingState.FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1273,6 +1288,15 @@ public class Agent
|
|||||||
String localUFrag,
|
String localUFrag,
|
||||||
boolean useCandidate)
|
boolean useCandidate)
|
||||||
{
|
{
|
||||||
|
if (isOver())
|
||||||
|
{
|
||||||
|
//means we already completed ICE and are happily running media
|
||||||
|
//the only reason we are called is most probably because the remote
|
||||||
|
//party is still sending Binding Requests our way and making sure we
|
||||||
|
//are still alive.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String ufrag = null;
|
String ufrag = null;
|
||||||
LocalCandidate localCandidate = null;
|
LocalCandidate localCandidate = null;
|
||||||
|
|
||||||
@ -1604,7 +1628,7 @@ public class Agent
|
|||||||
boolean allListsEnded = true;
|
boolean allListsEnded = true;
|
||||||
boolean atLeastOneListSucceeded = false;
|
boolean atLeastOneListSucceeded = false;
|
||||||
|
|
||||||
if(state == IceProcessingState.COMPLETED)
|
if(getState() == IceProcessingState.COMPLETED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
List<IceMediaStream> streams = getStreams();
|
List<IceMediaStream> streams = getStreams();
|
||||||
@ -1626,14 +1650,26 @@ public class Agent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(!allListsEnded)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!atLeastOneListSucceeded)
|
||||||
|
{
|
||||||
|
//all lists ended but none succeeded. No love today ;(
|
||||||
|
logger.info("ICE state is FAILED");
|
||||||
|
terminate(IceProcessingState.FAILED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//Once the state of each check list is Completed:
|
//Once the state of each check list is Completed:
|
||||||
//The agent sets the state of ICE processing overall to Completed.
|
//The agent sets the state of ICE processing overall to Completed.
|
||||||
if(allListsEnded)
|
if(getState() != IceProcessingState.RUNNING)
|
||||||
{
|
|
||||||
if(atLeastOneListSucceeded)
|
|
||||||
{
|
|
||||||
if(getState() == IceProcessingState.RUNNING)
|
|
||||||
{
|
{
|
||||||
|
//Oh, seems like we already did this.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
logger.info("ICE state is COMPLETED");
|
logger.info("ICE state is COMPLETED");
|
||||||
|
|
||||||
setState(IceProcessingState.COMPLETED);
|
setState(IceProcessingState.COMPLETED);
|
||||||
@ -1650,63 +1686,60 @@ public class Agent
|
|||||||
scheduleTermination();
|
scheduleTermination();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//print logs for the types of addresses we chose.
|
||||||
|
logCandTypes();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Goes through all streams and components and prints into the logs the type
|
||||||
|
* of local candidates that were selected as well as the server that
|
||||||
|
* were used (if any) to obtain them.
|
||||||
|
*/
|
||||||
|
private void logCandTypes()
|
||||||
|
{
|
||||||
List<IceMediaStream> strms = getStreams();
|
List<IceMediaStream> strms = getStreams();
|
||||||
|
|
||||||
// logs the harvester type and server used for each of
|
|
||||||
// of the components
|
|
||||||
for(IceMediaStream stream : strms)
|
for(IceMediaStream stream : strms)
|
||||||
{
|
{
|
||||||
for(Component c : stream.getComponents())
|
for(Component component : stream.getComponents())
|
||||||
{
|
{
|
||||||
StringBuffer buf = new StringBuffer(
|
CandidatePair selectedPair = component.getSelectedPair();
|
||||||
"Harvester selected for ");
|
|
||||||
buf.append(c.toShortString());
|
StringBuffer buf = new StringBuffer( "Harvester selected for ");
|
||||||
|
buf.append(component.toShortString());
|
||||||
buf.append(" ");
|
buf.append(" ");
|
||||||
if(c.getSelectedPair() == null)
|
|
||||||
|
if(selectedPair == null)
|
||||||
{
|
{
|
||||||
buf.append("none ");
|
buf.append("none (conn checks failed)");
|
||||||
buf.append("(it means that conncheck failed)");
|
|
||||||
logger.info(buf.toString());
|
logger.info(buf.toString());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
TransportAddress serverAddr = c.getSelectedPair().
|
Candidate localCnd = selectedPair.getLocalCandidate();
|
||||||
getLocalCandidate().getStunServerAddress();
|
|
||||||
TransportAddress relayAddr =
|
|
||||||
c.getSelectedPair().getLocalCandidate().
|
|
||||||
getRelayServerAddress();
|
|
||||||
|
|
||||||
buf.append(c.getSelectedPair().getLocalCandidate().
|
TransportAddress serverAddr = localCnd.getStunServerAddress();
|
||||||
getType());
|
TransportAddress relayAddr = localCnd.getRelayServerAddress();
|
||||||
|
|
||||||
|
buf.append(localCnd.getType());
|
||||||
|
|
||||||
if(serverAddr != null)
|
if(serverAddr != null)
|
||||||
{
|
{
|
||||||
buf.append(" (server = ");
|
buf.append(" (STUN server = ");
|
||||||
buf.append(c.getSelectedPair().
|
buf.append(localCnd.getStunServerAddress());
|
||||||
getLocalCandidate().
|
|
||||||
getStunServerAddress());
|
|
||||||
buf.append(")");
|
buf.append(")");
|
||||||
}
|
}
|
||||||
else if(relayAddr != null)
|
else if(relayAddr != null)
|
||||||
{
|
{
|
||||||
buf.append(" (relay = ");
|
buf.append(" (relay = ");
|
||||||
buf.append(c.getSelectedPair().
|
buf.append(localCnd.getRelayServerAddress());
|
||||||
getLocalCandidate().
|
|
||||||
getRelayServerAddress());
|
|
||||||
buf.append(")");
|
buf.append(")");
|
||||||
}
|
}
|
||||||
logger.info(buf.toString());
|
logger.info(buf.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.info("ICE state is FAILED");
|
|
||||||
terminate(IceProcessingState.FAILED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of host {@link Candidate}s in this {@link Agent}.
|
* Returns the number of host {@link Candidate}s in this {@link Agent}.
|
||||||
@ -1855,7 +1888,7 @@ public class Agent
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes and starts the {@link STUNKeepAliveThread}
|
* Initializes and starts the {@link StunKeepAliveThread}
|
||||||
*/
|
*/
|
||||||
private void scheduleSTUNKeepAlive()
|
private void scheduleSTUNKeepAlive()
|
||||||
{
|
{
|
||||||
@ -1937,9 +1970,13 @@ public class Agent
|
|||||||
&& !IceProcessingState.TERMINATED.equals(terminationState))
|
&& !IceProcessingState.TERMINATED.equals(terminationState))
|
||||||
throw new IllegalArgumentException("terminationState");
|
throw new IllegalArgumentException("terminationState");
|
||||||
|
|
||||||
// stop listening for checks
|
// stop making any checks.
|
||||||
connCheckClient.stop();
|
connCheckClient.stop();
|
||||||
connCheckServer.stop();
|
|
||||||
|
//do not stop the conn check server here because it may still need to
|
||||||
|
//process STUN Binding Requests that remote agents may send our way.
|
||||||
|
//we'll do this in "free()" instead.
|
||||||
|
//connCheckServer.stop();
|
||||||
|
|
||||||
setState(terminationState);
|
setState(terminationState);
|
||||||
}
|
}
|
||||||
@ -1963,10 +2000,10 @@ public class Agent
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares this <tt>Agent</tt> for garbage collection by setting the
|
* Prepares this <tt>Agent</tt> for garbage collection by ending all related
|
||||||
* {@link IceProcessingState#TERMINATED} state on it unless this
|
* processes and freeing its <tt>IceMediaStream</tt>s, <tt>Component</tt>s
|
||||||
* <tt>Agent</tt> is in termination state already and freeing its
|
* and <tt>Candidate</tt>s. This method will also place the agent in the
|
||||||
* <tt>IceMediaStream</tt>s, <tt>Component</tt>s and <tt>Candidate</tt>s.
|
* terminated state in case it wasn't already there.
|
||||||
*/
|
*/
|
||||||
public void free()
|
public void free()
|
||||||
{
|
{
|
||||||
@ -1974,18 +2011,24 @@ public class Agent
|
|||||||
|
|
||||||
shutdown = true;
|
shutdown = true;
|
||||||
|
|
||||||
|
//stop sending keep alives (STUN Binding Indications).
|
||||||
if(stunKeepAliveThread != null)
|
if(stunKeepAliveThread != null)
|
||||||
stunKeepAliveThread.interrupt();
|
stunKeepAliveThread.interrupt();
|
||||||
|
|
||||||
|
//stop responding to STUN Binding Requests.
|
||||||
|
connCheckServer.stop();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set the IceProcessingState#TERMINATED state on this Agent unless it
|
* Set the IceProcessingState#TERMINATED state on this Agent unless it
|
||||||
* is in a termination state already.
|
* is in a termination state already.
|
||||||
*/
|
*/
|
||||||
IceProcessingState state = getState();
|
IceProcessingState state = getState();
|
||||||
|
|
||||||
if (!IceProcessingState.FAILED.equals(state)
|
if ( !IceProcessingState.FAILED.equals(state)
|
||||||
&& !IceProcessingState.TERMINATED.equals(state))
|
&& !IceProcessingState.TERMINATED.equals(state))
|
||||||
|
{
|
||||||
terminate(IceProcessingState.TERMINATED);
|
terminate(IceProcessingState.TERMINATED);
|
||||||
|
}
|
||||||
|
|
||||||
logger.info("remove streams");
|
logger.info("remove streams");
|
||||||
// Free its IceMediaStreams, Components and Candidates.
|
// Free its IceMediaStreams, Components and Candidates.
|
||||||
@ -2090,20 +2133,23 @@ public class Agent
|
|||||||
{
|
{
|
||||||
if(compatibilityMode == CompatibilityMode.GTALK)
|
if(compatibilityMode == CompatibilityMode.GTALK)
|
||||||
{
|
{
|
||||||
|
//apparently GTalk insists on seeing binding
|
||||||
|
//requests or else it believes we are dead
|
||||||
|
//Emil: I am not sure this is true. I think it would
|
||||||
|
//be enough for us to respond to their binding
|
||||||
|
//requests. At least that's how it seems to work for
|
||||||
|
//Chrome and WebRTC.
|
||||||
|
//TODO: check and maybe remove
|
||||||
connCheckClient.startCheckForPair(pair);
|
connCheckClient.startCheckForPair(pair);
|
||||||
}
|
}
|
||||||
else if(compatibilityMode == CompatibilityMode.RFC5245)
|
else if(compatibilityMode == CompatibilityMode.RFC5245)
|
||||||
{
|
{
|
||||||
connCheckClient.sendBindingIndicationForPair(pair);
|
connCheckClient.sendBindingIndicationForPair(pair);
|
||||||
}
|
}
|
||||||
pair = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stream = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
streams = null;
|
|
||||||
|
|
||||||
if(shutdown)
|
if(shutdown)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@ -91,8 +91,8 @@ class ConnectivityCheckServer
|
|||||||
UsernameAttribute uname = (UsernameAttribute)request
|
UsernameAttribute uname = (UsernameAttribute)request
|
||||||
.getAttribute(Attribute.USERNAME);
|
.getAttribute(Attribute.USERNAME);
|
||||||
|
|
||||||
if(uname == null ||
|
if( uname == null
|
||||||
(parentAgent.getCompatibilityMode() == CompatibilityMode.RFC5245
|
|| ( parentAgent.getCompatibilityMode() == CompatibilityMode.RFC5245
|
||||||
&& !checkLocalUserName(new String(uname.getUsername()))))
|
&& !checkLocalUserName(new String(uname.getUsername()))))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -143,8 +143,8 @@ class ConnectivityCheckServer
|
|||||||
remoteUfrag = username.substring(0, colon);
|
remoteUfrag = username.substring(0, colon);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(parentAgent.getCompatibilityMode() == CompatibilityMode.GTALK &&
|
if( parentAgent.getCompatibilityMode() == CompatibilityMode.GTALK
|
||||||
parentAgent.findCandidatePair(localUFrag, remoteUfrag) == null)
|
&& parentAgent.findCandidatePair(localUFrag, remoteUfrag) == null)
|
||||||
{
|
{
|
||||||
logger.info("No candidate pair that match local and remote ufrag");
|
logger.info("No candidate pair that match local and remote ufrag");
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user