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:
parent
289651c38c
commit
8b759a4dd0
@ -1307,9 +1307,11 @@ public class Agent
|
|||||||
{
|
{
|
||||||
//we are started, which means we have the remote candidates
|
//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.
|
//so it's now safe to go and see whether this is a new PR cand.
|
||||||
logger.fine("Receive check from " +
|
if(triggeredPair.getParentComponent().getSelectedPair() == null)
|
||||||
triggeredPair.toShortString() +
|
{
|
||||||
"triggered a check");
|
logger.info("Receive check from " +
|
||||||
|
triggeredPair.toShortString() + "triggered a check");
|
||||||
|
}
|
||||||
triggerCheck(triggeredPair);
|
triggerCheck(triggeredPair);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1364,10 +1366,24 @@ public class Agent
|
|||||||
{
|
{
|
||||||
logger.fine("set useCandidateReceived for " +
|
logger.fine("set useCandidateReceived for " +
|
||||||
triggerPair.toShortString());
|
triggerPair.toShortString());
|
||||||
|
|
||||||
|
// 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
|
//next time we will see a request it will be considered as
|
||||||
// having USE-CANDIDATE
|
//having USE-CANDIDATE
|
||||||
triggerPair.setUseCandidateReceived();
|
triggerPair.setUseCandidateReceived();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (knownPair.getState() == CandidatePairState.SUCCEEDED )
|
if (knownPair.getState() == CandidatePairState.SUCCEEDED )
|
||||||
{
|
{
|
||||||
|
|||||||
@ -622,12 +622,24 @@ class ConnectivityCheckClient
|
|||||||
validRemoteCandidate);
|
validRemoteCandidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
//The agent sets the state of the pair that *generated* the check to
|
||||||
//Succeeded. Note that, the pair which *generated* the check may be
|
//Succeeded. Note that, the pair which *generated* the check may be
|
||||||
//different than the valid pair constructed above
|
//different than the valid pair constructed above
|
||||||
if(checkedPair.getParentComponent().getSelectedPair() == null)
|
if(checkedPair.getParentComponent().getSelectedPair() == null)
|
||||||
logger.info("Pair succeeded: " + checkedPair.toShortString());
|
logger.info("Pair succeeded: " + checkedPair.toShortString());
|
||||||
checkedPair.setStateSucceeded();
|
checkedPair.setStateSucceeded();
|
||||||
|
}
|
||||||
|
|
||||||
if(! validPair.isValid())
|
if(! validPair.isValid())
|
||||||
{
|
{
|
||||||
|
|||||||
@ -147,10 +147,33 @@ class ConnectivityCheckServer
|
|||||||
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");
|
||||||
|
|
||||||
// no candidate pair for the moment so do not send response
|
// no candidate pair for the moment so do not send response
|
||||||
// XXX maybe sent an error
|
// 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;
|
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;
|
//tell our address handler we saw a new remote address;
|
||||||
parentAgent.incomingCheckReceived(evt.getRemoteAddress(),
|
parentAgent.incomingCheckReceived(evt.getRemoteAddress(),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user