Fixes race condition when receiving a binding response from a peer and a binding request (for the same candidate pair). Also sends an 'stale credentials' error when receiving a check where username does not match any local ufrag/rfrag (typically it can happen when peer does not have finish processing transport-info/candidates IQ when STUN binding requests from other peer come.

This commit is contained in:
seb 2011-11-17 13:46:39 +00:00
parent 289651c38c
commit 8b759a4dd0
3 changed files with 65 additions and 14 deletions

View File

@ -1307,9 +1307,11 @@ public class Agent
{
//we are started, which means we have the remote candidates
//so it's now safe to go and see whether this is a new PR cand.
logger.fine("Receive check from " +
triggeredPair.toShortString() +
"triggered a check");
if(triggeredPair.getParentComponent().getSelectedPair() == null)
{
logger.info("Receive check from " +
triggeredPair.toShortString() + "triggered a check");
}
triggerCheck(triggeredPair);
}
else
@ -1364,9 +1366,23 @@ public class Agent
{
logger.fine("set useCandidateReceived for " +
triggerPair.toShortString());
//next time we will see a request it will be considered as
// having USE-CANDIDATE
triggerPair.setUseCandidateReceived();
// we synchronize here because the same pair object can be
// processed (in another thread) in ConnectivityCheckClient's
// processSuccessResponse. A controlled agent select its
// pair here if the pair state is succeeded (set in
// processSuccessResponse) or in processSuccessResponse if
// the pair has useCandidateReceived as true (set here). So be
// sure that if a binding response and a binding request (for
// the same check) from other peer come at the very same time,
// that we will trigger the nominationConfirmed (that will
// pass the pair as selected if it is the first time).
synchronized(triggerPair)
{
//next time we will see a request it will be considered as
//having USE-CANDIDATE
triggerPair.setUseCandidateReceived();
}
}
if (knownPair.getState() == CandidatePairState.SUCCEEDED )

View File

@ -622,12 +622,24 @@ class ConnectivityCheckClient
validRemoteCandidate);
}
//The agent sets the state of the pair that *generated* the check to
//Succeeded. Note that, the pair which *generated* the check may be
//different than the valid pair constructed above
if(checkedPair.getParentComponent().getSelectedPair() == null)
logger.info("Pair succeeded: " + checkedPair.toShortString());
checkedPair.setStateSucceeded();
// we synchronize here because the same pair object can be
// processed (in another thread) in Agent's triggerCheck.
// A controlled agent select its pair here if the pair has
// useCandidateReceived as true (set in triggerCheck) or in t
// triggerCheck if the pair state is succeeded (set here). So be
// sure that if a binding response and a binding request (for
// the same check) from other peer come at the very same time,
// that we will trigger the nominationConfirmed (that will
// pass the pair as selected if it is the first time).
synchronized(checkedPair)
{
//The agent sets the state of the pair that *generated* the check to
//Succeeded. Note that, the pair which *generated* the check may be
//different than the valid pair constructed above
if(checkedPair.getParentComponent().getSelectedPair() == null)
logger.info("Pair succeeded: " + checkedPair.toShortString());
checkedPair.setStateSucceeded();
}
if(! validPair.isValid())
{

View File

@ -147,9 +147,32 @@ class ConnectivityCheckServer
parentAgent.findCandidatePair(localUFrag, remoteUfrag) == null)
{
logger.info("No candidate pair that match local and remote ufrag");
// no candidate pair for the moment so do not send response
// XXX maybe sent an error
return;
// trigger an error so that other peer try again after some time
Response response = MessageFactory.createBindingErrorResponse(
ErrorCodeAttribute.STALE_CREDENTIALS);
ErrorCodeAttribute err = (ErrorCodeAttribute)response.getAttribute(
Attribute.ERROR_CODE);
// Gtalk error code is not RFC5389 compliant
err.setErrorClass((byte)0x01);
err.setErrorNumber((byte)0xae);
try
{
stunStack.sendResponse(
evt.getTransactionID().getBytes(),
response,
evt.getLocalAddress(),
evt.getRemoteAddress());
return;
}
catch(Exception exc)
{
//rethrow so that we would send a 500 response instead.
throw new RuntimeException("Failed to send a 430", exc);
}
}
//tell our address handler we saw a new remote address;