diff --git a/src/org/ice4j/ice/Agent.java b/src/org/ice4j/ice/Agent.java index f8cd69d..a1a5499 100644 --- a/src/org/ice4j/ice/Agent.java +++ b/src/org/ice4j/ice/Agent.java @@ -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 ) diff --git a/src/org/ice4j/ice/ConnectivityCheckClient.java b/src/org/ice4j/ice/ConnectivityCheckClient.java index e8d5d93..9aed93d 100644 --- a/src/org/ice4j/ice/ConnectivityCheckClient.java +++ b/src/org/ice4j/ice/ConnectivityCheckClient.java @@ -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()) { diff --git a/src/org/ice4j/ice/ConnectivityCheckServer.java b/src/org/ice4j/ice/ConnectivityCheckServer.java index d17da2a..1e9dd4e 100644 --- a/src/org/ice4j/ice/ConnectivityCheckServer.java +++ b/src/org/ice4j/ice/ConnectivityCheckServer.java @@ -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;