diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/IncomingJingleSession.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/IncomingJingleSession.java index b7b15cbaf..6dab8a255 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/IncomingJingleSession.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/IncomingJingleSession.java @@ -64,6 +64,7 @@ import org.jivesoftware.smackx.jingle.media.PayloadType; import org.jivesoftware.smackx.jingle.nat.TransportCandidate; import org.jivesoftware.smackx.jingle.nat.TransportNegotiator; import org.jivesoftware.smackx.jingle.nat.TransportResolver; +import org.jivesoftware.smackx.jingle.nat.JingleTransportManager; import org.jivesoftware.smackx.packet.Jingle; import org.jivesoftware.smackx.packet.JingleContentDescription; import org.jivesoftware.smackx.packet.JingleContentDescription.JinglePayloadType; @@ -96,21 +97,31 @@ public class IncomingJingleSession extends JingleSession { /** * Constructor for a Jingle incoming session * - * @param conn the XMPP connection - * @param responder the responder - * @param resolver The transport resolver + * @param conn the XMPP connection + * @param responder the responder + * @param transportManager The transport manager */ protected IncomingJingleSession(XMPPConnection conn, String responder, - List payloadTypes, TransportResolver resolver) { + List payloadTypes, JingleTransportManager transportManager, String sid) { super(conn, responder, conn.getUser()); + setSid(sid); + // Create the states... accepting = new Accepting(this); pending = new Pending(this); active = new Active(this); + TransportResolver resolver = null; + try { + resolver = transportManager.getResolver(this); + } + catch (XMPPException e) { + e.printStackTrace(); + } + setMediaNeg(new MediaNegotiator(this, payloadTypes)); if (resolver.getType().equals(TransportResolver.Type.rawupd)) { setTransportNeg(new TransportNegotiator.RawUdp(this, resolver)); @@ -126,12 +137,12 @@ public class IncomingJingleSession extends JingleSession { * * @param conn the XMPP connection * @param responder the responder - * @param resolver The transport resolver + * @param transportManager The transport manager * @param jingleMediaManager The Media Manager for this Session */ protected IncomingJingleSession(XMPPConnection conn, String responder, - List payloadTypes, TransportResolver resolver, JingleMediaManager jingleMediaManager) { - this(conn, responder, payloadTypes, resolver); + List payloadTypes, JingleTransportManager transportManager, JingleMediaManager jingleMediaManager, String sid) { + this(conn, responder, payloadTypes, transportManager, sid); this.jingleMediaManager = jingleMediaManager; } diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleManager.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleManager.java index e8d35b65b..ef81bef9a 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleManager.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleManager.java @@ -307,7 +307,7 @@ public class JingleManager implements JingleSessionListener { */ public JingleManager(XMPPConnection connection) { this(connection, new JingleTransportManager() { - protected TransportResolver createResolver() { + protected TransportResolver createResolver(JingleSession session) { return new BasicResolver(); } }); @@ -321,7 +321,7 @@ public class JingleManager implements JingleSessionListener { */ public JingleManager(XMPPConnection connection, final TransportResolver resolver) { this(connection, new JingleTransportManager() { - protected TransportResolver createResolver() { + protected TransportResolver createResolver(JingleSession session) { return resolver; } }); @@ -496,7 +496,7 @@ public class JingleManager implements JingleSessionListener { jingleSession.removeListener(this); jingleSessions.remove(jingleSession); jingleSession.close(); - System.err.println("Declined:"+reason); + System.err.println("Declined:" + reason); } public void sessionRedirected(String redirection, JingleSession jingleSession) { @@ -609,12 +609,10 @@ public class JingleManager implements JingleSessionListener { OutgoingJingleSession session; - TransportResolver resolver = jingleTransportManager.getResolver(); - if (jingleMediaManager != null) - session = new OutgoingJingleSession(connection, responder, payloadTypes, resolver, jingleMediaManager); + session = new OutgoingJingleSession(connection, responder, payloadTypes, jingleTransportManager, jingleMediaManager); else - session = new OutgoingJingleSession(connection, responder, payloadTypes, jingleTransportManager.getResolver()); + session = new OutgoingJingleSession(connection, responder, payloadTypes, jingleTransportManager); triggerSessionCreated(session); @@ -649,14 +647,12 @@ public class JingleManager implements JingleSessionListener { IncomingJingleSession session; - TransportResolver resolver = jingleTransportManager.getResolver(); - if (jingleMediaManager != null) session = new IncomingJingleSession(connection, request - .getFrom(), payloadTypes, resolver, jingleMediaManager); + .getFrom(), payloadTypes, jingleTransportManager, jingleMediaManager, request.getSessionID()); else session = new IncomingJingleSession(connection, request - .getFrom(), payloadTypes, resolver); + .getFrom(), payloadTypes, jingleTransportManager, request.getSessionID()); triggerSessionCreated(session); diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java index f3d9a73e8..4ba0c2361 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java @@ -239,7 +239,7 @@ public abstract class JingleSession extends JingleNegotiator { /** * Generate a unique session ID. */ - protected String generateSessionId() { + protected static String generateSessionId() { return String.valueOf(Math.abs(randomGenerator.nextLong())); } diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/OutgoingJingleSession.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/OutgoingJingleSession.java index 4e36c43b2..db8d4ebf1 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/OutgoingJingleSession.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/OutgoingJingleSession.java @@ -63,6 +63,7 @@ import org.jivesoftware.smackx.jingle.media.PayloadType; import org.jivesoftware.smackx.jingle.nat.TransportCandidate; import org.jivesoftware.smackx.jingle.nat.TransportNegotiator; import org.jivesoftware.smackx.jingle.nat.TransportResolver; +import org.jivesoftware.smackx.jingle.nat.JingleTransportManager; import org.jivesoftware.smackx.packet.Jingle; import org.jivesoftware.smackx.packet.JingleContentDescription; import org.jivesoftware.smackx.packet.JingleContentDescription.JinglePayloadType; @@ -93,13 +94,13 @@ public class OutgoingJingleSession extends JingleSession { /** * Constructor for a Jingle outgoing session. * - * @param conn the XMPP connection - * @param responder the other endpoint - * @param payloadTypes A list of payload types, in order of preference. - * @param resolver The transport resolver. + * @param conn the XMPP connection + * @param responder the other endpoint + * @param payloadTypes A list of payload types, in order of preference. + * @param transportManager The transport manager. */ protected OutgoingJingleSession(XMPPConnection conn, String responder, - List payloadTypes, TransportResolver resolver) { + List payloadTypes, JingleTransportManager transportManager) { super(conn, conn.getUser(), responder); @@ -110,6 +111,14 @@ public class OutgoingJingleSession extends JingleSession { pending = new Pending(this); active = new Active(this); + TransportResolver resolver = null; + try { + resolver = transportManager.getResolver(this); + } + catch (XMPPException e) { + e.printStackTrace(); + } + // Create description and transport negotiatiors... setMediaNeg(new MediaNegotiator(this, payloadTypes)); if (resolver.getType().equals(TransportResolver.Type.rawupd)) { @@ -126,12 +135,12 @@ public class OutgoingJingleSession extends JingleSession { * @param conn the XMPP connection * @param responder the other endpoint * @param payloadTypes A list of payload types, in order of preference. - * @param resolver The transport resolver. + * @param transportManager The transport manager. * @param jingleMediaManager The Media Manager for this Session */ protected OutgoingJingleSession(XMPPConnection conn, String responder, - List payloadTypes, TransportResolver resolver, JingleMediaManager jingleMediaManager) { - this(conn, responder, payloadTypes, resolver); + List payloadTypes, JingleTransportManager transportManager, JingleMediaManager jingleMediaManager) { + this(conn, responder, payloadTypes, transportManager); this.jingleMediaManager = jingleMediaManager; } diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BasicResolver.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BasicResolver.java index 903da8d9e..26db955f3 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BasicResolver.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BasicResolver.java @@ -21,6 +21,7 @@ package org.jivesoftware.smackx.jingle.nat; import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smackx.jingle.JingleSession; import java.net.InetAddress; import java.net.NetworkInterface; @@ -47,7 +48,7 @@ public class BasicResolver extends TransportResolver { * The BasicResolver takes the IP addresses of the interfaces and uses the * first non-loopback, non-linklocal and non-sitelocal address. */ - public synchronized void resolve() throws XMPPException { + public synchronized void resolve(JingleSession session) throws XMPPException { setResolveInit(); diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BasicTransportManager.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BasicTransportManager.java index a88837ff2..35f7a3d9d 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BasicTransportManager.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BasicTransportManager.java @@ -1,5 +1,7 @@ package org.jivesoftware.smackx.jingle.nat; +import org.jivesoftware.smackx.jingle.JingleSession; + /** * $RCSfile$ * $Revision: $ @@ -26,7 +28,7 @@ package org.jivesoftware.smackx.jingle.nat; */ public class BasicTransportManager extends JingleTransportManager{ - protected TransportResolver createResolver() { + protected TransportResolver createResolver(JingleSession session) { return new BasicResolver(); } } diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BridgedResolver.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BridgedResolver.java index 5573d6103..89f1758ed 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BridgedResolver.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BridgedResolver.java @@ -21,6 +21,7 @@ package org.jivesoftware.smackx.jingle.nat; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smackx.jingle.JingleSession; import java.util.Random; @@ -54,7 +55,7 @@ public class BridgedResolver extends TransportResolver{ *
* The BridgedResolver takes the IP addresse and ports of a jmf proxy service. */ - public synchronized void resolve() throws XMPPException { + public synchronized void resolve(JingleSession session) throws XMPPException { setResolveInit(); @@ -67,7 +68,6 @@ public class BridgedResolver extends TransportResolver{ BasicResolver basicResolver = new BasicResolver(); basicResolver.initializeAndWait(); - basicResolver.resolve(); TransportCandidate localCandidate = new TransportCandidate.Fixed( rtpBridge.getIp(), rtpBridge.getPortA()); diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BridgedTransportManager.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BridgedTransportManager.java index 2b68d4243..09ff8aa2d 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BridgedTransportManager.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/BridgedTransportManager.java @@ -43,7 +43,7 @@ public class BridgedTransportManager extends JingleTransportManager implements J } // Return the correspondent resolver - protected TransportResolver createResolver() { + protected TransportResolver createResolver(JingleSession session) { BridgedResolver bridgedResolver = new BridgedResolver(this.xmppConnection); return bridgedResolver; } diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/FixedResolver.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/FixedResolver.java index b97ec7624..b417e72d4 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/FixedResolver.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/FixedResolver.java @@ -20,6 +20,7 @@ package org.jivesoftware.smackx.jingle.nat; import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smackx.jingle.JingleSession; /** * The FixedResolver is a resolver where @@ -53,7 +54,7 @@ public class FixedResolver extends TransportResolver { /** * Resolve the IP address. */ - public synchronized void resolve() throws XMPPException { + public synchronized void resolve(JingleSession session) throws XMPPException { if (!isResolving()) { setResolveInit(); 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 b58a26cbb..08254b584 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICEResolver.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICEResolver.java @@ -25,6 +25,7 @@ import de.javawi.jstun.test.demo.ice.ICENegociator; import de.javawi.jstun.util.UtilityException; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smackx.jingle.JingleSession; import java.net.UnknownHostException; import java.net.SocketException; @@ -76,7 +77,7 @@ public class ICEResolver extends TransportResolver { /** * Resolve the IP and obtain a valid transport method. */ - public synchronized void resolve() throws XMPPException { + public synchronized void resolve(JingleSession session) throws XMPPException { this.setResolveInit(); for (TransportCandidate candidate : this.getCandidatesList()) { @@ -105,7 +106,7 @@ public class ICEResolver extends TransportResolver { transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress()); transportCandidate.setPort(getFreePort()); try { - transportCandidate.addCandidateEcho(); + transportCandidate.addCandidateEcho(session); } catch (SocketException e) { e.printStackTrace(); 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 04cd5d466..b91ec9432 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICETransportManager.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICETransportManager.java @@ -40,9 +40,9 @@ public class ICETransportManager extends JingleTransportManager implements Jingl } } - protected TransportResolver createResolver() { + protected TransportResolver createResolver(JingleSession session) { try { - iceResolver.resolve(); + iceResolver.resolve(session); } catch (XMPPException e) { e.printStackTrace(); diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/JingleTransportManager.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/JingleTransportManager.java index 287c8d9be..386aa3884 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/JingleTransportManager.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/JingleTransportManager.java @@ -20,6 +20,7 @@ package org.jivesoftware.smackx.jingle.nat; import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smackx.jingle.JingleSession; /** * Transport manager for Jingle. @@ -53,8 +54,8 @@ public abstract class JingleTransportManager { * * @return */ - public TransportResolver getResolver() throws XMPPException { - TransportResolver resolver = createResolver(); + public TransportResolver getResolver(JingleSession session) throws XMPPException { + TransportResolver resolver = createResolver(session); if (resolver == null) { resolver = new BasicResolver(); } @@ -68,6 +69,6 @@ public abstract class JingleTransportManager { * * @return */ - protected abstract TransportResolver createResolver(); + protected abstract TransportResolver createResolver(JingleSession session); } diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUNResolver.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUNResolver.java index c07b8403f..261735d6b 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUNResolver.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUNResolver.java @@ -23,6 +23,7 @@ import de.javawi.jstun.test.BindingLifetimeTest; import de.javawi.jstun.test.DiscoveryInfo; import de.javawi.jstun.test.DiscoveryTest; import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smackx.jingle.JingleSession; import org.xmlpull.mxp1.MXParser; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -271,7 +272,7 @@ public class STUNResolver extends TransportResolver { /** * Resolve the IP and obtain a valid transport method. */ - public synchronized void resolve() throws XMPPException { + public synchronized void resolve(JingleSession session) throws XMPPException { setResolveInit(); diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUNTransportManager.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUNTransportManager.java index 8775f1ad7..259b661ce 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUNTransportManager.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUNTransportManager.java @@ -20,6 +20,7 @@ package org.jivesoftware.smackx.jingle.nat; import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smackx.jingle.JingleSession; /** * A Jingle Transport Manager implementation to be used on NAT networks with STUN Service NOT Blocked. @@ -39,9 +40,9 @@ public class STUNTransportManager extends JingleTransportManager { } } - protected TransportResolver createResolver() { + protected TransportResolver createResolver(JingleSession session) { try { - stunResolver.resolve(); + stunResolver.resolve(session); } catch (XMPPException e) { e.printStackTrace(); } diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportCandidate.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportCandidate.java index 6cc6bcc79..520e02671 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportCandidate.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportCandidate.java @@ -53,6 +53,7 @@ package org.jivesoftware.smackx.jingle.nat; import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smackx.jingle.JingleSession; import java.io.IOException; import java.net.*; @@ -60,6 +61,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.Arrays; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; /** * Transport candidate. @@ -97,8 +100,8 @@ public abstract class TransportCandidate { // Listeners for events private final List