When receive a STALE-CREDENTIALS error, delay the reemission of the connectivity check for that candidate pair. Fix thread stopping when ICE Agent is free()d otherwise some threads (Stun4J Message Processor, StunKeepAliveThread, ...) stay even after the call is finished.
This commit is contained in:
parent
8b759a4dd0
commit
2591b21992
@ -213,6 +213,11 @@ public class Agent
|
||||
*/
|
||||
private int generation = 0;
|
||||
|
||||
/**
|
||||
* Indicates that ICE will be shutdown.
|
||||
*/
|
||||
private boolean shutdown = false;
|
||||
|
||||
/**
|
||||
* Creates an empty <tt>Agent</tt> with no streams, and no address.
|
||||
*/
|
||||
@ -451,6 +456,7 @@ public class Agent
|
||||
synchronized(startLock)
|
||||
{
|
||||
logger.info("Start ICE connectivity establishment");
|
||||
shutdown = false;
|
||||
pruneNonMatchedStreams();
|
||||
initCheckLists();
|
||||
|
||||
@ -1921,6 +1927,11 @@ public class Agent
|
||||
{
|
||||
logger.info("Free ICE agent");
|
||||
|
||||
shutdown = true;
|
||||
|
||||
if(stunKeepAliveThread != null)
|
||||
stunKeepAliveThread.interrupt();
|
||||
|
||||
/*
|
||||
* Set the IceProcessingState#TERMINATED state on this Agent unless it
|
||||
* is in a termination state already.
|
||||
@ -1945,6 +1956,10 @@ public class Agent
|
||||
}
|
||||
logger.info("remove stream " + stream.getName());
|
||||
}
|
||||
|
||||
getStunStack().shutDown();
|
||||
|
||||
logger.info("ICE agent freed");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2013,6 +2028,9 @@ public class Agent
|
||||
while(state == IceProcessingState.COMPLETED || state ==
|
||||
IceProcessingState.TERMINATED)
|
||||
{
|
||||
if(shutdown)
|
||||
break;
|
||||
|
||||
List<IceMediaStream> streams = getStreams();
|
||||
|
||||
for(IceMediaStream stream : streams)
|
||||
@ -2040,6 +2058,9 @@ public class Agent
|
||||
|
||||
streams = null;
|
||||
|
||||
if(shutdown)
|
||||
break;
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep(3000);
|
||||
|
||||
@ -151,6 +151,31 @@ class ConnectivityCheckClient
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start check for pair after some delay seconds
|
||||
*
|
||||
* @param candidatePair
|
||||
* @param delay delay in millisecond
|
||||
*/
|
||||
private void startDelayedCheckForPair(final CandidatePair candidatePair,
|
||||
final int delay)
|
||||
{
|
||||
new Thread()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(delay);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
}
|
||||
startCheckForPair(candidatePair);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a STUN {@link Request} containing the necessary PRIORITY and
|
||||
* CONTROLLING/CONTROLLED attributes. Also stores a reference to
|
||||
@ -834,12 +859,14 @@ class ConnectivityCheckClient
|
||||
{
|
||||
// it may be an error due to remote peer that does not processed
|
||||
// our candidates IQ and we start connectivity checks too quickly
|
||||
//(that's why we get a STALE CREDENTIALS because remote peer doesn't
|
||||
// know the candidate ufrag). So let's send another check for that
|
||||
// pair
|
||||
// (that's why we get a STALE CREDENTIALS because remote peer does
|
||||
// not know the candidate ufrag). So let's send another check for
|
||||
// that pair
|
||||
logger.info("stale credentials for GTalk check for " +
|
||||
pair.toShortString());
|
||||
startCheckForPair(pair);
|
||||
|
||||
// try again after some delay
|
||||
startDelayedCheckForPair(pair, 50);
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
package org.ice4j.ice;
|
||||
|
||||
import org.ice4j.*;
|
||||
import org.ice4j.ice.harvest.*;
|
||||
import org.ice4j.socket.*;
|
||||
|
||||
/**
|
||||
@ -26,6 +27,10 @@ import org.ice4j.socket.*;
|
||||
public class ServerReflexiveCandidate
|
||||
extends LocalCandidate
|
||||
{
|
||||
/**
|
||||
* The STUN candidate harvest.
|
||||
*/
|
||||
private final StunCandidateHarvest stunHarvest;
|
||||
|
||||
/**
|
||||
* Creates a <tt>ServerReflexiveCandidate</tt> for the specified transport
|
||||
@ -41,6 +46,32 @@ public class ServerReflexiveCandidate
|
||||
public ServerReflexiveCandidate(TransportAddress address,
|
||||
HostCandidate base,
|
||||
TransportAddress stunSrvrAddr)
|
||||
{
|
||||
super(address,
|
||||
base.getParentComponent(),
|
||||
CandidateType.SERVER_REFLEXIVE_CANDIDATE);
|
||||
|
||||
setBase(base);
|
||||
setStunServerAddress(stunSrvrAddr);
|
||||
stunHarvest = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <tt>ServerReflexiveCandidate</tt> for the specified transport
|
||||
* address, and base.
|
||||
*
|
||||
* @param address the {@link TransportAddress} that this <tt>Candidate</tt>
|
||||
* is representing.
|
||||
* @param base the {@link HostCandidate} that this server reflexive
|
||||
* candidate was obtained through.
|
||||
* @param stunSrvrAddr the {@link TransportAddress} of the stun server that
|
||||
* reflected this candidate.
|
||||
* @param stunHarvest the {@link StunCandidateHarvest}
|
||||
*/
|
||||
public ServerReflexiveCandidate(TransportAddress address,
|
||||
HostCandidate base,
|
||||
TransportAddress stunSrvrAddr,
|
||||
StunCandidateHarvest stunHarvest)
|
||||
{
|
||||
super(address,
|
||||
base.getParentComponent(),
|
||||
@ -48,6 +79,7 @@ public class ServerReflexiveCandidate
|
||||
|
||||
setBase(base);
|
||||
setStunServerAddress(stunSrvrAddr);
|
||||
this.stunHarvest = stunHarvest;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,4 +93,20 @@ public class ServerReflexiveCandidate
|
||||
{
|
||||
return getBase().getIceSocketWrapper();
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees resources allocated by this candidate such as its
|
||||
* <tt>DatagramSocket</tt>, for example. The <tt>socket</tt> of this
|
||||
* <tt>LocalCandidate</tt> is closed only if it is not the <tt>socket</tt>
|
||||
* of the <tt>base</tt> of this <tt>LocalCandidate</tt>.
|
||||
*/
|
||||
protected void free()
|
||||
{
|
||||
super.free();
|
||||
|
||||
if(stunHarvest != null)
|
||||
{
|
||||
stunHarvest.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1315,4 +1315,14 @@ public class StunCandidateHarvest
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the harvest.
|
||||
*/
|
||||
public void close()
|
||||
{
|
||||
// stop keep alive thread
|
||||
setSendKeepAliveMessageInterval(
|
||||
SEND_KEEP_ALIVE_MESSAGE_INTERVAL_NOT_SPECIFIED);
|
||||
}
|
||||
}
|
||||
|
||||
@ -247,6 +247,17 @@ class NetAccessManager
|
||||
ap.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops <tt>NetAccessManager</tt> and all of its <tt>MessageProcessor</tt>.
|
||||
*/
|
||||
public void stop()
|
||||
{
|
||||
for(MessageProcessor mp : messageProcessors)
|
||||
{
|
||||
mp.stop();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------thread pool implementation --------------------------------
|
||||
/**
|
||||
* Adjusts the number of concurrently running MessageProcessors.
|
||||
|
||||
@ -792,6 +792,8 @@ public class StunStack
|
||||
if(tran != null)
|
||||
tran.expire();
|
||||
}
|
||||
|
||||
netAccessManager.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user