From 18c14f70d40f066698f93a8bc4b94d1a2e6e47ce Mon Sep 17 00:00:00 2001 From: Thiago Camargo Date: Thu, 1 Mar 2007 21:03:31 +0000 Subject: [PATCH] STUN Failure Ignored in Negotiation git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7339 b35dd754-fafc-0310-a699-88a17e54d16e --- .../smackx/jingle/nat/ICECandidate.java | 30 +++++++------------ .../smackx/jingle/nat/ICEResolver.java | 17 +++++++++-- .../jingle/nat/ICETransportManager.java | 2 +- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICECandidate.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICECandidate.java index e4a1d640e..eb6c25252 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICECandidate.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICECandidate.java @@ -98,8 +98,8 @@ public class ICECandidate extends TransportCandidate implements Comparable { * @param type type as defined in ICE-12 */ public ICECandidate(String ip, int generation, int network, - String password, int port, String username, - int preference, String type) { + String password, int port, String username, + int preference, String type) { super(ip, port, generation); proto = Protocol.UDP; @@ -266,7 +266,7 @@ public class ICECandidate extends TransportCandidate implements Comparable { if (echo != null) { try { InetAddress address = InetAddress.getByName(getIp()); - if (echo.test(address, getPort())) isUsable = true; + if (echo.test(address, getPort(),2000)) isUsable = true; if (isUsable) break; } catch (UnknownHostException e) { @@ -321,16 +321,14 @@ public class ICECandidate extends TransportCandidate implements Comparable { if (other.getChannel() != null) { return false; } - } - else if (!getChannel().equals(other.getChannel())) { + } else if (!getChannel().equals(other.getChannel())) { return false; } if (getId() == null) { if (other.getId() != null) { return false; } - } - else if (!getId().equals(other.getId())) { + } else if (!getId().equals(other.getId())) { return false; } if (getNetwork() != other.getNetwork()) { @@ -340,8 +338,7 @@ public class ICECandidate extends TransportCandidate implements Comparable { if (other.getPassword() != null) { return false; } - } - else if (!getPassword().equals(other.password)) { + } else if (!getPassword().equals(other.password)) { return false; } if (getPreference() != other.getPreference()) { @@ -351,16 +348,14 @@ public class ICECandidate extends TransportCandidate implements Comparable { if (other.getProto() != null) { return false; } - } - else if (!getProto().equals(other.getProto())) { + } else if (!getProto().equals(other.getProto())) { return false; } if (getUsername() == null) { if (other.getUsername() != null) { return false; } - } - else if (!getUsername().equals(other.getUsername())) { + } else if (!getUsername().equals(other.getUsername())) { return false; } return true; @@ -369,11 +364,9 @@ public class ICECandidate extends TransportCandidate implements Comparable { public boolean isNull() { if (super.isNull()) { return true; - } - else if (getProto().isNull()) { + } else if (getProto().isNull()) { return true; - } - else if (getChannel().isNull()) { + } else if (getChannel().isNull()) { return true; } return false; @@ -392,8 +385,7 @@ public class ICECandidate extends TransportCandidate implements Comparable { ICECandidate tc = (ICECandidate) arg; if (getPreference() < tc.getPreference()) { return -1; - } - else if (getPreference() > tc.getPreference()) { + } else if (getPreference() > tc.getPreference()) { return 1; } } diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICEResolver.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICEResolver.java index 6f3bc92b7..b58a26cbb 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICEResolver.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICEResolver.java @@ -124,18 +124,29 @@ public class ICEResolver extends TransportResolver { if (RTPBridge.serviceAvailable(connection)) { try { - String localIp = iceNegociator.getPublicCandidate().getBase().getAddress().getInetAddress().getHostAddress(); + + String localIp; + int network; + + if (iceNegociator.getPublicCandidate() != null) { + localIp = iceNegociator.getPublicCandidate().getBase().getAddress().getInetAddress().getHostAddress(); + network = iceNegociator.getPublicCandidate().getNetwork(); + } + else { + localIp = iceNegociator.getSortedCandidates().get(0).getAddress().getInetAddress().getHostAddress(); + network = iceNegociator.getSortedCandidates().get(0).getNetwork(); + } sid = Math.abs(random.nextLong()); RTPBridge rtpBridge = RTPBridge.getRTPBridge(connection, String.valueOf(sid)); TransportCandidate localCandidate = new ICECandidate( - rtpBridge.getIp(), 1, iceNegociator.getPublicCandidate().getNetwork(), "1", rtpBridge.getPortA(), "1", 0, "relay"); + rtpBridge.getIp(), 1, network, "1", rtpBridge.getPortA(), "1", 0, "relay"); localCandidate.setLocalIp(localIp); TransportCandidate remoteCandidate = new ICECandidate( - rtpBridge.getIp(), 1, iceNegociator.getPublicCandidate().getNetwork(), "1", rtpBridge.getPortB(), "1", 0, "relay"); + rtpBridge.getIp(), 1, network, "1", rtpBridge.getPortB(), "1", 0, "relay"); remoteCandidate.setLocalIp(localIp); localCandidate.setSymmetric(remoteCandidate); diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICETransportManager.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICETransportManager.java index 864883331..04cd5d466 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICETransportManager.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICETransportManager.java @@ -28,7 +28,7 @@ import org.jivesoftware.smackx.jingle.listeners.CreatedJingleSessionListener; */ public class ICETransportManager extends JingleTransportManager implements JingleSessionListener, CreatedJingleSessionListener { - ICEResolver iceResolver = null; + ICEResolver iceResolver = null; public ICETransportManager(XMPPConnection xmppConnection, String server, int port) { iceResolver = new ICEResolver(xmppConnection, server, port);