From 03a1a116449f119fc158ba3c65cb3587f76f30cb Mon Sep 17 00:00:00 2001 From: seb Date: Thu, 8 Sep 2011 11:15:03 +0000 Subject: [PATCH] Supports for XOR-PEER-ADDRESS attribute for GTalk compatibility mode (as Empathy/libnice uses this attribute instead of MAPPED-ATTRIBUTE). --- src/org/ice4j/ice/Candidate.java | 6 +++++ src/org/ice4j/ice/Component.java | 14 ++++++++++ .../ice4j/ice/ConnectivityCheckClient.java | 27 +++++++++++++------ src/org/ice4j/ice/DefaultNominator.java | 6 +++-- src/org/ice4j/ice/IceMediaStream.java | 14 ++++++++++ 5 files changed, 57 insertions(+), 10 deletions(-) diff --git a/src/org/ice4j/ice/Candidate.java b/src/org/ice4j/ice/Candidate.java index aae9c4a..18c3962 100644 --- a/src/org/ice4j/ice/Candidate.java +++ b/src/org/ice4j/ice/Candidate.java @@ -400,6 +400,12 @@ public abstract class Candidate priority -= getParentComponent().getComponentID() - 1; + InetAddress addr = getTransportAddress().getAddress(); + + // IPv6 has better priority than IPv4 + if(addr instanceof Inet6Address) + priority += 10; + return priority; } diff --git a/src/org/ice4j/ice/Component.java b/src/org/ice4j/ice/Component.java index 6311913..16b2a8f 100644 --- a/src/org/ice4j/ice/Component.java +++ b/src/org/ice4j/ice/Component.java @@ -310,6 +310,20 @@ public class Component return; List localCnds = getLocalCandidates(); + + // remove UPnP base from local candidate + LocalCandidate upnpBase = null; + for(LocalCandidate lc : localCnds) + { + if(lc instanceof UPNPCandidate) + { + upnpBase = lc.getBase(); + } + } + if(upnpBase != null) + { + localCnds.remove(upnpBase); + } checkList = new Vector(); for(LocalCandidate localCnd : localCnds) diff --git a/src/org/ice4j/ice/ConnectivityCheckClient.java b/src/org/ice4j/ice/ConnectivityCheckClient.java index 3ec3635..a028ed6 100644 --- a/src/org/ice4j/ice/ConnectivityCheckClient.java +++ b/src/org/ice4j/ice/ConnectivityCheckClient.java @@ -394,7 +394,24 @@ class ConnectivityCheckClient TransportAddress mappedAddress = null; if(this.parentAgent.getCompatibilityMode() == CompatibilityMode.GTALK) { - if(!response.containsAttribute(Attribute.MAPPED_ADDRESS)) + if(response.containsAttribute(Attribute.XOR_MAPPED_ADDRESS)) + { + XorMappedAddressAttribute mappedAddressAttr + = (XorMappedAddressAttribute)response + .getAttribute(Attribute.XOR_MAPPED_ADDRESS); + mappedAddress = mappedAddressAttr.getAddress( + response.getTransactionID()); + } + else if(response.containsAttribute(Attribute.MAPPED_ADDRESS)) + { + + MappedAddressAttribute mappedAddressAttr + = (MappedAddressAttribute)response + .getAttribute(Attribute.MAPPED_ADDRESS); + + mappedAddress = mappedAddressAttr.getAddress(); + } + else { logger.fine("Received a success response with no " + "MAPPED_ADDRESS attribute."); @@ -403,12 +420,6 @@ class ConnectivityCheckClient checkedPair.setStateFailed(); return; //malformed error response } - - MappedAddressAttribute mappedAddressAttr - = (MappedAddressAttribute)response - .getAttribute(Attribute.MAPPED_ADDRESS); - - mappedAddress = mappedAddressAttr.getAddress(); } else { @@ -586,7 +597,7 @@ class ConnectivityCheckClient if((parentAgent.isControlling() && (request.containsAttribute(Attribute.USE_CANDIDATE)) || parentAgent.getCompatibilityMode() == - CompatibilityMode.GTALK)) + CompatibilityMode.GTALK) && validPair.isNominated()) { logger.info("Nomination confirmed for pair: " + validPair.toShortString()); diff --git a/src/org/ice4j/ice/DefaultNominator.java b/src/org/ice4j/ice/DefaultNominator.java index 974fb40..9aca5d8 100644 --- a/src/org/ice4j/ice/DefaultNominator.java +++ b/src/org/ice4j/ice/DefaultNominator.java @@ -174,7 +174,7 @@ public class DefaultNominator * @param evt the {@link PropertyChangeEvent} containing the pair which * has been validated. */ - private void strategyNominateFirstHostOrReflexiveValid( + private synchronized void strategyNominateFirstHostOrReflexiveValid( PropertyChangeEvent evt) { if(IceMediaStream.PROPERTY_PAIR_VALIDATED.equals(evt.getPropertyName())) @@ -184,7 +184,9 @@ public class DefaultNominator TimerTask task = validatedCandidates.get( validPair.getParentComponent().toShortString()); boolean isRelayed = - validPair.getLocalCandidate() instanceof RelayedCandidate; + validPair.getLocalCandidate() instanceof RelayedCandidate || + validPair.getRemoteCandidate().getType().equals( + CandidateType.RELAYED_CANDIDATE); if(isRelayed && task == null) { diff --git a/src/org/ice4j/ice/IceMediaStream.java b/src/org/ice4j/ice/IceMediaStream.java index 131009f..0533826 100644 --- a/src/org/ice4j/ice/IceMediaStream.java +++ b/src/org/ice4j/ice/IceMediaStream.java @@ -353,6 +353,20 @@ public class IceMediaStream List localCnds = component.getLocalCandidates(); List remoteCnds = component.getRemoteCandidates(); + // remove UPnP base from local candidate + LocalCandidate upnpBase = null; + for(LocalCandidate lc : localCnds) + { + if(lc instanceof UPNPCandidate) + { + upnpBase = lc.getBase(); + } + } + if(upnpBase != null) + { + localCnds.remove(upnpBase); + } + for(LocalCandidate localCnd : localCnds) { for(Candidate remoteCnd : remoteCnds)