From c91bfae9b0393d00baf79ecf19029332a0c54430 Mon Sep 17 00:00:00 2001 From: seb Date: Fri, 10 Jun 2011 14:06:05 +0000 Subject: [PATCH] Fixes problems with server reflexives address checks (as all local candidates has their own ufrag we will not remove server reflexive candidates when pruning checklists. Handles STALE_CREDENTIALS error due to checks being sent too quickly to a remote peer that does not process candidates IQ yet. --- .../ice4j/attribute/ErrorCodeAttribute.java | 5 ++-- src/org/ice4j/ice/Agent.java | 3 ++- .../ice4j/ice/ConnectivityCheckClient.java | 24 +++++++++++++++--- src/org/ice4j/ice/IceMediaStream.java | 25 +++++++++++-------- 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/org/ice4j/attribute/ErrorCodeAttribute.java b/src/org/ice4j/attribute/ErrorCodeAttribute.java index f32b148..1283a43 100644 --- a/src/org/ice4j/attribute/ErrorCodeAttribute.java +++ b/src/org/ice4j/attribute/ErrorCodeAttribute.java @@ -210,14 +210,15 @@ public class ErrorCodeAttribute extends Attribute /** * Sets this error's error class. * @param errorClass this error's error class. - * @throws IllegalArgumentException if errorClass is not a valid error class. + * @throws IllegalArgumentException if errorClass is not a valid error + * class. */ public void setErrorClass(byte errorClass) throws IllegalArgumentException { if(errorClass < 0 || errorClass > 99) throw new IllegalArgumentException( - errorClass + " is not a valid error number!"); + errorClass + " is not a valid error number!"); this.errorClass = errorClass; } diff --git a/src/org/ice4j/ice/Agent.java b/src/org/ice4j/ice/Agent.java index 8a89e3d..13ecddf 100644 --- a/src/org/ice4j/ice/Agent.java +++ b/src/org/ice4j/ice/Agent.java @@ -1193,7 +1193,8 @@ public class Agent CandidatePair pair = findCandidatePair(localUFrag, remoteUFrag); if(pair == null) { - logger.info("No GTalk CandidatePair that match Lufrag/Rufrag"); + logger.info("No GTalk CandidatePair that match Lufrag/Rufrag" + + " " + localUFrag + " " + remoteUFrag); return; } diff --git a/src/org/ice4j/ice/ConnectivityCheckClient.java b/src/org/ice4j/ice/ConnectivityCheckClient.java index 2652ddb..e2b8089 100644 --- a/src/org/ice4j/ice/ConnectivityCheckClient.java +++ b/src/org/ice4j/ice/ConnectivityCheckClient.java @@ -603,9 +603,14 @@ class ConnectivityCheckClient Response response = evt.getResponse(); Request originalRequest = evt.getRequest(); - char errorCode - = ((ErrorCodeAttribute) response.getAttribute(Attribute.ERROR_CODE)) - .getErrorCode(); + ErrorCodeAttribute errorAttr = (ErrorCodeAttribute)response. + getAttribute(Attribute.ERROR_CODE); + // GTalk error code is not RFC3489/RFC5389 compliant + // example: 400 becomes 0x01 0x90 with GTalk + // RFC3489/RFC5389 gives 0x04 0x00 + int cl = errorAttr.getErrorClass(); + int co = errorAttr.getErrorNumber() & 0xff; + char errorCode = errorAttr.getErrorCode(); CandidatePair pair = ((CandidatePair)evt.getTransactionID() .getApplicationData()); @@ -624,6 +629,19 @@ class ConnectivityCheckClient pair.getParentComponent().getParentStream().getCheckList() .scheduleTriggeredCheck(pair); } + else if(parentAgent.getCompatibilityMode() == CompatibilityMode.GTALK && + cl == 1 && co == 0xae) // STALE_CREDENTIALS (430) + { + // 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 + logger.info("stale credentials for GTalk check for " + + pair.toShortString()); + startCheckForPair(pair); + return; + } else { logger.fine("Received an unrecoverable error response for pair " diff --git a/src/org/ice4j/ice/IceMediaStream.java b/src/org/ice4j/ice/IceMediaStream.java index 98b2953..8a37360 100644 --- a/src/org/ice4j/ice/IceMediaStream.java +++ b/src/org/ice4j/ice/IceMediaStream.java @@ -410,19 +410,22 @@ public class IceMediaStream continue; } - //replace local server reflexive candidates with their base. - LocalCandidate localCnd = pair.getLocalCandidate(); - if( localCnd.getType() - == CandidateType.SERVER_REFLEXIVE_CANDIDATE) + if(parentAgent.getCompatibilityMode() == CompatibilityMode.RFC5245) { - pair.setLocalCandidate(localCnd.getBase()); - - //if the new pair corresponds to another one with a higher - //priority, then remove it. - if(tmpCheckList.contains(pair)) + //replace local server reflexive candidates with their base. + LocalCandidate localCnd = pair.getLocalCandidate(); + if( localCnd.getType() + == CandidateType.SERVER_REFLEXIVE_CANDIDATE) { - ckListIter.remove(); - continue; + pair.setLocalCandidate(localCnd.getBase()); + + //if the new pair corresponds to another one with a higher + //priority, then remove it. + if(tmpCheckList.contains(pair)) + { + ckListIter.remove(); + continue; + } } }