mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 14:02:06 +01:00
ECHO Refactoring
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7460 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
41fbc3906a
commit
a078606ab4
21 changed files with 136 additions and 80 deletions
|
@ -64,6 +64,7 @@ import org.jivesoftware.smackx.jingle.media.PayloadType;
|
||||||
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
|
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
|
||||||
import org.jivesoftware.smackx.jingle.nat.TransportNegotiator;
|
import org.jivesoftware.smackx.jingle.nat.TransportNegotiator;
|
||||||
import org.jivesoftware.smackx.jingle.nat.TransportResolver;
|
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.Jingle;
|
||||||
import org.jivesoftware.smackx.packet.JingleContentDescription;
|
import org.jivesoftware.smackx.packet.JingleContentDescription;
|
||||||
import org.jivesoftware.smackx.packet.JingleContentDescription.JinglePayloadType;
|
import org.jivesoftware.smackx.packet.JingleContentDescription.JinglePayloadType;
|
||||||
|
@ -96,21 +97,31 @@ public class IncomingJingleSession extends JingleSession {
|
||||||
/**
|
/**
|
||||||
* Constructor for a Jingle incoming session
|
* Constructor for a Jingle incoming session
|
||||||
*
|
*
|
||||||
* @param conn the XMPP connection
|
* @param conn the XMPP connection
|
||||||
* @param responder the responder
|
* @param responder the responder
|
||||||
* @param resolver The transport resolver
|
* @param transportManager The transport manager
|
||||||
*/
|
*/
|
||||||
protected IncomingJingleSession(XMPPConnection conn, String responder,
|
protected IncomingJingleSession(XMPPConnection conn, String responder,
|
||||||
List payloadTypes, TransportResolver resolver) {
|
List payloadTypes, JingleTransportManager transportManager, String sid) {
|
||||||
|
|
||||||
super(conn, responder, conn.getUser());
|
super(conn, responder, conn.getUser());
|
||||||
|
|
||||||
|
setSid(sid);
|
||||||
|
|
||||||
// Create the states...
|
// Create the states...
|
||||||
|
|
||||||
accepting = new Accepting(this);
|
accepting = new Accepting(this);
|
||||||
pending = new Pending(this);
|
pending = new Pending(this);
|
||||||
active = new Active(this);
|
active = new Active(this);
|
||||||
|
|
||||||
|
TransportResolver resolver = null;
|
||||||
|
try {
|
||||||
|
resolver = transportManager.getResolver(this);
|
||||||
|
}
|
||||||
|
catch (XMPPException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
setMediaNeg(new MediaNegotiator(this, payloadTypes));
|
setMediaNeg(new MediaNegotiator(this, payloadTypes));
|
||||||
if (resolver.getType().equals(TransportResolver.Type.rawupd)) {
|
if (resolver.getType().equals(TransportResolver.Type.rawupd)) {
|
||||||
setTransportNeg(new TransportNegotiator.RawUdp(this, resolver));
|
setTransportNeg(new TransportNegotiator.RawUdp(this, resolver));
|
||||||
|
@ -126,12 +137,12 @@ public class IncomingJingleSession extends JingleSession {
|
||||||
*
|
*
|
||||||
* @param conn the XMPP connection
|
* @param conn the XMPP connection
|
||||||
* @param responder the responder
|
* @param responder the responder
|
||||||
* @param resolver The transport resolver
|
* @param transportManager The transport manager
|
||||||
* @param jingleMediaManager The Media Manager for this Session
|
* @param jingleMediaManager The Media Manager for this Session
|
||||||
*/
|
*/
|
||||||
protected IncomingJingleSession(XMPPConnection conn, String responder,
|
protected IncomingJingleSession(XMPPConnection conn, String responder,
|
||||||
List payloadTypes, TransportResolver resolver, JingleMediaManager jingleMediaManager) {
|
List payloadTypes, JingleTransportManager transportManager, JingleMediaManager jingleMediaManager, String sid) {
|
||||||
this(conn, responder, payloadTypes, resolver);
|
this(conn, responder, payloadTypes, transportManager, sid);
|
||||||
this.jingleMediaManager = jingleMediaManager;
|
this.jingleMediaManager = jingleMediaManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -307,7 +307,7 @@ public class JingleManager implements JingleSessionListener {
|
||||||
*/
|
*/
|
||||||
public JingleManager(XMPPConnection connection) {
|
public JingleManager(XMPPConnection connection) {
|
||||||
this(connection, new JingleTransportManager() {
|
this(connection, new JingleTransportManager() {
|
||||||
protected TransportResolver createResolver() {
|
protected TransportResolver createResolver(JingleSession session) {
|
||||||
return new BasicResolver();
|
return new BasicResolver();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -321,7 +321,7 @@ public class JingleManager implements JingleSessionListener {
|
||||||
*/
|
*/
|
||||||
public JingleManager(XMPPConnection connection, final TransportResolver resolver) {
|
public JingleManager(XMPPConnection connection, final TransportResolver resolver) {
|
||||||
this(connection, new JingleTransportManager() {
|
this(connection, new JingleTransportManager() {
|
||||||
protected TransportResolver createResolver() {
|
protected TransportResolver createResolver(JingleSession session) {
|
||||||
return resolver;
|
return resolver;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -496,7 +496,7 @@ public class JingleManager implements JingleSessionListener {
|
||||||
jingleSession.removeListener(this);
|
jingleSession.removeListener(this);
|
||||||
jingleSessions.remove(jingleSession);
|
jingleSessions.remove(jingleSession);
|
||||||
jingleSession.close();
|
jingleSession.close();
|
||||||
System.err.println("Declined:"+reason);
|
System.err.println("Declined:" + reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sessionRedirected(String redirection, JingleSession jingleSession) {
|
public void sessionRedirected(String redirection, JingleSession jingleSession) {
|
||||||
|
@ -609,12 +609,10 @@ public class JingleManager implements JingleSessionListener {
|
||||||
|
|
||||||
OutgoingJingleSession session;
|
OutgoingJingleSession session;
|
||||||
|
|
||||||
TransportResolver resolver = jingleTransportManager.getResolver();
|
|
||||||
|
|
||||||
if (jingleMediaManager != null)
|
if (jingleMediaManager != null)
|
||||||
session = new OutgoingJingleSession(connection, responder, payloadTypes, resolver, jingleMediaManager);
|
session = new OutgoingJingleSession(connection, responder, payloadTypes, jingleTransportManager, jingleMediaManager);
|
||||||
else
|
else
|
||||||
session = new OutgoingJingleSession(connection, responder, payloadTypes, jingleTransportManager.getResolver());
|
session = new OutgoingJingleSession(connection, responder, payloadTypes, jingleTransportManager);
|
||||||
|
|
||||||
triggerSessionCreated(session);
|
triggerSessionCreated(session);
|
||||||
|
|
||||||
|
@ -649,14 +647,12 @@ public class JingleManager implements JingleSessionListener {
|
||||||
|
|
||||||
IncomingJingleSession session;
|
IncomingJingleSession session;
|
||||||
|
|
||||||
TransportResolver resolver = jingleTransportManager.getResolver();
|
|
||||||
|
|
||||||
if (jingleMediaManager != null)
|
if (jingleMediaManager != null)
|
||||||
session = new IncomingJingleSession(connection, request
|
session = new IncomingJingleSession(connection, request
|
||||||
.getFrom(), payloadTypes, resolver, jingleMediaManager);
|
.getFrom(), payloadTypes, jingleTransportManager, jingleMediaManager, request.getSessionID());
|
||||||
else
|
else
|
||||||
session = new IncomingJingleSession(connection, request
|
session = new IncomingJingleSession(connection, request
|
||||||
.getFrom(), payloadTypes, resolver);
|
.getFrom(), payloadTypes, jingleTransportManager, request.getSessionID());
|
||||||
|
|
||||||
triggerSessionCreated(session);
|
triggerSessionCreated(session);
|
||||||
|
|
||||||
|
|
|
@ -239,7 +239,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
/**
|
/**
|
||||||
* Generate a unique session ID.
|
* Generate a unique session ID.
|
||||||
*/
|
*/
|
||||||
protected String generateSessionId() {
|
protected static String generateSessionId() {
|
||||||
return String.valueOf(Math.abs(randomGenerator.nextLong()));
|
return String.valueOf(Math.abs(randomGenerator.nextLong()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,7 @@ import org.jivesoftware.smackx.jingle.media.PayloadType;
|
||||||
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
|
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
|
||||||
import org.jivesoftware.smackx.jingle.nat.TransportNegotiator;
|
import org.jivesoftware.smackx.jingle.nat.TransportNegotiator;
|
||||||
import org.jivesoftware.smackx.jingle.nat.TransportResolver;
|
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.Jingle;
|
||||||
import org.jivesoftware.smackx.packet.JingleContentDescription;
|
import org.jivesoftware.smackx.packet.JingleContentDescription;
|
||||||
import org.jivesoftware.smackx.packet.JingleContentDescription.JinglePayloadType;
|
import org.jivesoftware.smackx.packet.JingleContentDescription.JinglePayloadType;
|
||||||
|
@ -93,13 +94,13 @@ public class OutgoingJingleSession extends JingleSession {
|
||||||
/**
|
/**
|
||||||
* Constructor for a Jingle outgoing session.
|
* Constructor for a Jingle outgoing session.
|
||||||
*
|
*
|
||||||
* @param conn the XMPP connection
|
* @param conn the XMPP connection
|
||||||
* @param responder the other endpoint
|
* @param responder the other endpoint
|
||||||
* @param payloadTypes A list of payload types, in order of preference.
|
* @param payloadTypes A list of payload types, in order of preference.
|
||||||
* @param resolver The transport resolver.
|
* @param transportManager The transport manager.
|
||||||
*/
|
*/
|
||||||
protected OutgoingJingleSession(XMPPConnection conn, String responder,
|
protected OutgoingJingleSession(XMPPConnection conn, String responder,
|
||||||
List payloadTypes, TransportResolver resolver) {
|
List payloadTypes, JingleTransportManager transportManager) {
|
||||||
|
|
||||||
super(conn, conn.getUser(), responder);
|
super(conn, conn.getUser(), responder);
|
||||||
|
|
||||||
|
@ -110,6 +111,14 @@ public class OutgoingJingleSession extends JingleSession {
|
||||||
pending = new Pending(this);
|
pending = new Pending(this);
|
||||||
active = new Active(this);
|
active = new Active(this);
|
||||||
|
|
||||||
|
TransportResolver resolver = null;
|
||||||
|
try {
|
||||||
|
resolver = transportManager.getResolver(this);
|
||||||
|
}
|
||||||
|
catch (XMPPException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
// Create description and transport negotiatiors...
|
// Create description and transport negotiatiors...
|
||||||
setMediaNeg(new MediaNegotiator(this, payloadTypes));
|
setMediaNeg(new MediaNegotiator(this, payloadTypes));
|
||||||
if (resolver.getType().equals(TransportResolver.Type.rawupd)) {
|
if (resolver.getType().equals(TransportResolver.Type.rawupd)) {
|
||||||
|
@ -126,12 +135,12 @@ public class OutgoingJingleSession extends JingleSession {
|
||||||
* @param conn the XMPP connection
|
* @param conn the XMPP connection
|
||||||
* @param responder the other endpoint
|
* @param responder the other endpoint
|
||||||
* @param payloadTypes A list of payload types, in order of preference.
|
* @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
|
* @param jingleMediaManager The Media Manager for this Session
|
||||||
*/
|
*/
|
||||||
protected OutgoingJingleSession(XMPPConnection conn, String responder,
|
protected OutgoingJingleSession(XMPPConnection conn, String responder,
|
||||||
List payloadTypes, TransportResolver resolver, JingleMediaManager jingleMediaManager) {
|
List payloadTypes, JingleTransportManager transportManager, JingleMediaManager jingleMediaManager) {
|
||||||
this(conn, responder, payloadTypes, resolver);
|
this(conn, responder, payloadTypes, transportManager);
|
||||||
this.jingleMediaManager = jingleMediaManager;
|
this.jingleMediaManager = jingleMediaManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
package org.jivesoftware.smackx.jingle.nat;
|
package org.jivesoftware.smackx.jingle.nat;
|
||||||
|
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.NetworkInterface;
|
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
|
* The BasicResolver takes the IP addresses of the interfaces and uses the
|
||||||
* first non-loopback, non-linklocal and non-sitelocal address.
|
* first non-loopback, non-linklocal and non-sitelocal address.
|
||||||
*/
|
*/
|
||||||
public synchronized void resolve() throws XMPPException {
|
public synchronized void resolve(JingleSession session) throws XMPPException {
|
||||||
|
|
||||||
setResolveInit();
|
setResolveInit();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.jivesoftware.smackx.jingle.nat;
|
package org.jivesoftware.smackx.jingle.nat;
|
||||||
|
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $RCSfile$
|
* $RCSfile$
|
||||||
* $Revision: $
|
* $Revision: $
|
||||||
|
@ -26,7 +28,7 @@ package org.jivesoftware.smackx.jingle.nat;
|
||||||
*/
|
*/
|
||||||
public class BasicTransportManager extends JingleTransportManager{
|
public class BasicTransportManager extends JingleTransportManager{
|
||||||
|
|
||||||
protected TransportResolver createResolver() {
|
protected TransportResolver createResolver(JingleSession session) {
|
||||||
return new BasicResolver();
|
return new BasicResolver();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.jivesoftware.smackx.jingle.nat;
|
||||||
|
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ public class BridgedResolver extends TransportResolver{
|
||||||
* <p/>
|
* <p/>
|
||||||
* The BridgedResolver takes the IP addresse and ports of a jmf proxy service.
|
* 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();
|
setResolveInit();
|
||||||
|
|
||||||
|
@ -67,7 +68,6 @@ public class BridgedResolver extends TransportResolver{
|
||||||
BasicResolver basicResolver = new BasicResolver();
|
BasicResolver basicResolver = new BasicResolver();
|
||||||
|
|
||||||
basicResolver.initializeAndWait();
|
basicResolver.initializeAndWait();
|
||||||
basicResolver.resolve();
|
|
||||||
|
|
||||||
TransportCandidate localCandidate = new TransportCandidate.Fixed(
|
TransportCandidate localCandidate = new TransportCandidate.Fixed(
|
||||||
rtpBridge.getIp(), rtpBridge.getPortA());
|
rtpBridge.getIp(), rtpBridge.getPortA());
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class BridgedTransportManager extends JingleTransportManager implements J
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the correspondent resolver
|
// Return the correspondent resolver
|
||||||
protected TransportResolver createResolver() {
|
protected TransportResolver createResolver(JingleSession session) {
|
||||||
BridgedResolver bridgedResolver = new BridgedResolver(this.xmppConnection);
|
BridgedResolver bridgedResolver = new BridgedResolver(this.xmppConnection);
|
||||||
return bridgedResolver;
|
return bridgedResolver;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.jivesoftware.smackx.jingle.nat;
|
package org.jivesoftware.smackx.jingle.nat;
|
||||||
|
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The FixedResolver is a resolver where
|
* The FixedResolver is a resolver where
|
||||||
|
@ -53,7 +54,7 @@ public class FixedResolver extends TransportResolver {
|
||||||
/**
|
/**
|
||||||
* Resolve the IP address.
|
* Resolve the IP address.
|
||||||
*/
|
*/
|
||||||
public synchronized void resolve() throws XMPPException {
|
public synchronized void resolve(JingleSession session) throws XMPPException {
|
||||||
if (!isResolving()) {
|
if (!isResolving()) {
|
||||||
setResolveInit();
|
setResolveInit();
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import de.javawi.jstun.test.demo.ice.ICENegociator;
|
||||||
import de.javawi.jstun.util.UtilityException;
|
import de.javawi.jstun.util.UtilityException;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
|
@ -76,7 +77,7 @@ public class ICEResolver extends TransportResolver {
|
||||||
/**
|
/**
|
||||||
* Resolve the IP and obtain a valid transport method.
|
* 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();
|
this.setResolveInit();
|
||||||
|
|
||||||
for (TransportCandidate candidate : this.getCandidatesList()) {
|
for (TransportCandidate candidate : this.getCandidatesList()) {
|
||||||
|
@ -105,7 +106,7 @@ public class ICEResolver extends TransportResolver {
|
||||||
transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress());
|
transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress());
|
||||||
transportCandidate.setPort(getFreePort());
|
transportCandidate.setPort(getFreePort());
|
||||||
try {
|
try {
|
||||||
transportCandidate.addCandidateEcho();
|
transportCandidate.addCandidateEcho(session);
|
||||||
}
|
}
|
||||||
catch (SocketException e) {
|
catch (SocketException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -40,9 +40,9 @@ public class ICETransportManager extends JingleTransportManager implements Jingl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TransportResolver createResolver() {
|
protected TransportResolver createResolver(JingleSession session) {
|
||||||
try {
|
try {
|
||||||
iceResolver.resolve();
|
iceResolver.resolve(session);
|
||||||
}
|
}
|
||||||
catch (XMPPException e) {
|
catch (XMPPException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.jivesoftware.smackx.jingle.nat;
|
package org.jivesoftware.smackx.jingle.nat;
|
||||||
|
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transport manager for Jingle.
|
* Transport manager for Jingle.
|
||||||
|
@ -53,8 +54,8 @@ public abstract class JingleTransportManager {
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public TransportResolver getResolver() throws XMPPException {
|
public TransportResolver getResolver(JingleSession session) throws XMPPException {
|
||||||
TransportResolver resolver = createResolver();
|
TransportResolver resolver = createResolver(session);
|
||||||
if (resolver == null) {
|
if (resolver == null) {
|
||||||
resolver = new BasicResolver();
|
resolver = new BasicResolver();
|
||||||
}
|
}
|
||||||
|
@ -68,6 +69,6 @@ public abstract class JingleTransportManager {
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected abstract TransportResolver createResolver();
|
protected abstract TransportResolver createResolver(JingleSession session);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import de.javawi.jstun.test.BindingLifetimeTest;
|
||||||
import de.javawi.jstun.test.DiscoveryInfo;
|
import de.javawi.jstun.test.DiscoveryInfo;
|
||||||
import de.javawi.jstun.test.DiscoveryTest;
|
import de.javawi.jstun.test.DiscoveryTest;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||||
import org.xmlpull.mxp1.MXParser;
|
import org.xmlpull.mxp1.MXParser;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
@ -271,7 +272,7 @@ public class STUNResolver extends TransportResolver {
|
||||||
/**
|
/**
|
||||||
* Resolve the IP and obtain a valid transport method.
|
* Resolve the IP and obtain a valid transport method.
|
||||||
*/
|
*/
|
||||||
public synchronized void resolve() throws XMPPException {
|
public synchronized void resolve(JingleSession session) throws XMPPException {
|
||||||
|
|
||||||
setResolveInit();
|
setResolveInit();
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.jivesoftware.smackx.jingle.nat;
|
package org.jivesoftware.smackx.jingle.nat;
|
||||||
|
|
||||||
import org.jivesoftware.smack.XMPPException;
|
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.
|
* 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 {
|
try {
|
||||||
stunResolver.resolve();
|
stunResolver.resolve(session);
|
||||||
} catch (XMPPException e) {
|
} catch (XMPPException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
package org.jivesoftware.smackx.jingle.nat;
|
package org.jivesoftware.smackx.jingle.nat;
|
||||||
|
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
@ -60,6 +61,8 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.CharBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transport candidate.
|
* Transport candidate.
|
||||||
|
@ -97,8 +100,8 @@ public abstract class TransportCandidate {
|
||||||
// Listeners for events
|
// Listeners for events
|
||||||
private final List<TransportResolverListener.Checker> listeners = new ArrayList();
|
private final List<TransportResolverListener.Checker> listeners = new ArrayList();
|
||||||
|
|
||||||
public void addCandidateEcho() throws SocketException, UnknownHostException {
|
public void addCandidateEcho(JingleSession session) throws SocketException, UnknownHostException {
|
||||||
candidateEcho = new CandidateEcho(this);
|
candidateEcho = new CandidateEcho(this, session);
|
||||||
echoThread = new Thread(candidateEcho);
|
echoThread = new Thread(candidateEcho);
|
||||||
echoThread.start();
|
echoThread.start();
|
||||||
}
|
}
|
||||||
|
@ -647,17 +650,52 @@ public abstract class TransportCandidate {
|
||||||
public class CandidateEcho implements Runnable {
|
public class CandidateEcho implements Runnable {
|
||||||
|
|
||||||
DatagramSocket socket = null;
|
DatagramSocket socket = null;
|
||||||
byte password[] = null;
|
String localUser = null;
|
||||||
|
String remoteUser = null;
|
||||||
|
String id = null;
|
||||||
|
byte send[] = null;
|
||||||
|
byte receive[] = null;
|
||||||
|
DatagramPacket sendPacket = null;
|
||||||
List<DatagramListener> listeners = new ArrayList<DatagramListener>();
|
List<DatagramListener> listeners = new ArrayList<DatagramListener>();
|
||||||
List<ResultListener> resultListeners = new ArrayList<ResultListener>();
|
List<ResultListener> resultListeners = new ArrayList<ResultListener>();
|
||||||
boolean enabled = true;
|
boolean enabled = true;
|
||||||
boolean ended = false;
|
boolean ended = false;
|
||||||
long tries = 10;
|
long tries = 10;
|
||||||
|
|
||||||
public CandidateEcho(TransportCandidate candidate) throws UnknownHostException, SocketException {
|
public CandidateEcho(TransportCandidate candidate, JingleSession session) throws UnknownHostException, SocketException {
|
||||||
this.socket = new DatagramSocket(candidate.getPort(), InetAddress.getByName(candidate.getLocalIp()));
|
this.socket = new DatagramSocket(candidate.getPort(), InetAddress.getByName(candidate.getLocalIp()));
|
||||||
Random r = new Random();
|
this.localUser = session.getInitiator();
|
||||||
password = longToByteArray((Math.abs(r.nextLong())));
|
this.remoteUser = session.getResponder();
|
||||||
|
this.id = session.getSid();
|
||||||
|
|
||||||
|
int keySplitIndex = ((int) Math.ceil(((float) id.length()) / 2));
|
||||||
|
|
||||||
|
|
||||||
|
int size = 4 + localUser.length() * 2 + (id.length() - keySplitIndex) * 2;
|
||||||
|
ByteBuffer bufLocal = ByteBuffer.allocate(size);
|
||||||
|
// Create a character ByteBuffer Wrap
|
||||||
|
CharBuffer cbufLocal = bufLocal.asCharBuffer();
|
||||||
|
cbufLocal.append(id.substring(0, keySplitIndex));
|
||||||
|
cbufLocal.append(';');
|
||||||
|
cbufLocal.append(localUser);
|
||||||
|
|
||||||
|
size = 4 + remoteUser.length() * 2 + keySplitIndex * 2;
|
||||||
|
ByteBuffer bufRemote = ByteBuffer.allocate(size);
|
||||||
|
// Create a character ByteBuffer Wrap
|
||||||
|
CharBuffer cbufRemote = bufRemote.asCharBuffer();
|
||||||
|
cbufRemote.append(id.substring(keySplitIndex));
|
||||||
|
cbufRemote.append(';');
|
||||||
|
cbufRemote.append(remoteUser);
|
||||||
|
|
||||||
|
if (session.getConnection().getUser().equals(session.getInitiator())) {
|
||||||
|
this.send = bufLocal.array();
|
||||||
|
this.receive = bufRemote.array();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.receive = bufLocal.array();
|
||||||
|
this.send = bufRemote.array();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -665,7 +703,7 @@ public abstract class TransportCandidate {
|
||||||
System.out.println("Listening for ECHO: " + socket.getLocalAddress().getHostAddress() + ":" + socket.getLocalPort());
|
System.out.println("Listening for ECHO: " + socket.getLocalAddress().getHostAddress() + ":" + socket.getLocalPort());
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
DatagramPacket packet = new DatagramPacket(new byte[8], 8);
|
DatagramPacket packet = new DatagramPacket(new byte[this.receive.length], this.receive.length);
|
||||||
|
|
||||||
socket.receive(packet);
|
socket.receive(packet);
|
||||||
|
|
||||||
|
@ -681,8 +719,10 @@ public abstract class TransportCandidate {
|
||||||
long delay = 1000 / tries / 2;
|
long delay = 1000 / tries / 2;
|
||||||
|
|
||||||
if (delay < 0) delay = 10;
|
if (delay < 0) delay = 10;
|
||||||
if (!Arrays.equals(packet.getData(), password))
|
if (Arrays.equals(packet.getData(), receive))
|
||||||
for (int i = 0; i < tries; i++) {
|
for (int i = 0; i < tries; i++) {
|
||||||
|
packet.setData(send);
|
||||||
|
packet.setLength(send.length);
|
||||||
socket.send(packet);
|
socket.send(packet);
|
||||||
if (!enabled) break;
|
if (!enabled) break;
|
||||||
try {
|
try {
|
||||||
|
@ -731,7 +771,7 @@ public abstract class TransportCandidate {
|
||||||
DatagramListener listener = new DatagramListener() {
|
DatagramListener listener = new DatagramListener() {
|
||||||
public boolean datagramReceived(DatagramPacket datagramPacket) {
|
public boolean datagramReceived(DatagramPacket datagramPacket) {
|
||||||
if (datagramPacket.getAddress().equals(address) && datagramPacket.getPort() == port) {
|
if (datagramPacket.getAddress().equals(address) && datagramPacket.getPort() == port) {
|
||||||
if (Arrays.equals(datagramPacket.getData(), password)) {
|
if (Arrays.equals(datagramPacket.getData(), receive)) {
|
||||||
testResult.setResult(true);
|
testResult.setResult(true);
|
||||||
ended = true;
|
ended = true;
|
||||||
return true;
|
return true;
|
||||||
|
@ -743,7 +783,7 @@ public abstract class TransportCandidate {
|
||||||
|
|
||||||
this.addListener(listener);
|
this.addListener(listener);
|
||||||
|
|
||||||
DatagramPacket packet = new DatagramPacket(password, password.length);
|
DatagramPacket packet = new DatagramPacket(send, send.length);
|
||||||
|
|
||||||
packet.setAddress(address);
|
packet.setAddress(address);
|
||||||
packet.setPort(port);
|
packet.setPort(port);
|
||||||
|
@ -781,7 +821,7 @@ public abstract class TransportCandidate {
|
||||||
DatagramListener listener = new DatagramListener() {
|
DatagramListener listener = new DatagramListener() {
|
||||||
public boolean datagramReceived(DatagramPacket datagramPacket) {
|
public boolean datagramReceived(DatagramPacket datagramPacket) {
|
||||||
if (datagramPacket.getAddress().equals(address) && datagramPacket.getPort() == port) {
|
if (datagramPacket.getAddress().equals(address) && datagramPacket.getPort() == port) {
|
||||||
if (Arrays.equals(datagramPacket.getData(), password)) {
|
if (Arrays.equals(datagramPacket.getData(), receive)) {
|
||||||
TestResult testResult = new TestResult();
|
TestResult testResult = new TestResult();
|
||||||
testResult.setResult(true);
|
testResult.setResult(true);
|
||||||
fireTestResult(testResult);
|
fireTestResult(testResult);
|
||||||
|
@ -795,7 +835,7 @@ public abstract class TransportCandidate {
|
||||||
|
|
||||||
addListener(listener);
|
addListener(listener);
|
||||||
|
|
||||||
DatagramPacket packet = new DatagramPacket(password, password.length);
|
DatagramPacket packet = new DatagramPacket(send, send.length);
|
||||||
|
|
||||||
packet.setAddress(address);
|
packet.setAddress(address);
|
||||||
packet.setPort(port);
|
packet.setPort(port);
|
||||||
|
@ -842,13 +882,4 @@ public abstract class TransportCandidate {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] longToByteArray(long valor) {
|
|
||||||
byte[] result = new byte[8];
|
|
||||||
for (int i = 0; i < result.length; i++) {
|
|
||||||
result[7 - i] = (byte) (valor & 0xFF);
|
|
||||||
valor = valor >> 8;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -507,7 +507,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
||||||
if (!(resolver.isResolving() || resolver.isResolved())) {
|
if (!(resolver.isResolving() || resolver.isResolved())) {
|
||||||
// Resolve our IP and port
|
// Resolve our IP and port
|
||||||
System.out.println("RESOLVER CALLED");
|
System.out.println("RESOLVER CALLED");
|
||||||
resolver.resolve();
|
resolver.resolve(session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
package org.jivesoftware.smackx.jingle.nat;
|
package org.jivesoftware.smackx.jingle.nat;
|
||||||
|
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
|
@ -89,7 +90,7 @@ public abstract class TransportResolver {
|
||||||
public Type type = Type.rawupd;
|
public Type type = Type.rawupd;
|
||||||
|
|
||||||
// the time, in milliseconds, before a check aborts
|
// the time, in milliseconds, before a check aborts
|
||||||
public static final int CHECK_TIMEOUT = 5000;
|
public static final int CHECK_TIMEOUT = 3000;
|
||||||
|
|
||||||
// Listeners for events
|
// Listeners for events
|
||||||
private final ArrayList<TransportResolverListener> listeners = new ArrayList<TransportResolverListener>();
|
private final ArrayList<TransportResolverListener> listeners = new ArrayList<TransportResolverListener>();
|
||||||
|
@ -126,7 +127,7 @@ public abstract class TransportResolver {
|
||||||
/**
|
/**
|
||||||
* Start a the resolution.
|
* Start a the resolution.
|
||||||
*/
|
*/
|
||||||
public abstract void resolve() throws XMPPException;
|
public abstract void resolve(JingleSession session) throws XMPPException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear the list of candidates and start a new resolution process.
|
* Clear the list of candidates and start a new resolution process.
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.jivesoftware.smackx.jingle;
|
||||||
|
|
||||||
import org.jivesoftware.smack.test.SmackTestCase;
|
import org.jivesoftware.smack.test.SmackTestCase;
|
||||||
import org.jivesoftware.smackx.jingle.nat.BasicResolver;
|
import org.jivesoftware.smackx.jingle.nat.BasicResolver;
|
||||||
|
import org.jivesoftware.smackx.jingle.nat.BasicTransportManager;
|
||||||
|
|
||||||
public class JingleSessionTest extends SmackTestCase {
|
public class JingleSessionTest extends SmackTestCase {
|
||||||
|
|
||||||
|
@ -10,9 +11,9 @@ public class JingleSessionTest extends SmackTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEqualsObject() {
|
public void testEqualsObject() {
|
||||||
JingleSession js1 = new OutgoingJingleSession(getConnection(0), "res1", null, new BasicResolver());
|
JingleSession js1 = new OutgoingJingleSession(getConnection(0), "res1", null, new BasicTransportManager());
|
||||||
JingleSession js2 = new OutgoingJingleSession(getConnection(1), "res1", null, new BasicResolver());
|
JingleSession js2 = new OutgoingJingleSession(getConnection(1), "res1", null, new BasicTransportManager());
|
||||||
JingleSession js3 = new OutgoingJingleSession(getConnection(2), "res2", null, new BasicResolver());
|
JingleSession js3 = new OutgoingJingleSession(getConnection(2), "res2", null, new BasicTransportManager());
|
||||||
|
|
||||||
System.out.println(js1.getSid());
|
System.out.println(js1.getSid());
|
||||||
System.out.println(js2.getSid());
|
System.out.println(js2.getSid());
|
||||||
|
@ -34,8 +35,8 @@ public class JingleSessionTest extends SmackTestCase {
|
||||||
String ini2 = "initiator2";
|
String ini2 = "initiator2";
|
||||||
String sid2 = "sid2";
|
String sid2 = "sid2";
|
||||||
|
|
||||||
JingleSession js1 = new OutgoingJingleSession(getConnection(0), sid1, null, new BasicResolver());
|
JingleSession js1 = new OutgoingJingleSession(getConnection(0), sid1, null, new BasicTransportManager());
|
||||||
JingleSession js2 = new OutgoingJingleSession(getConnection(1), sid2, null, new BasicResolver());
|
JingleSession js2 = new OutgoingJingleSession(getConnection(1), sid2, null, new BasicTransportManager());
|
||||||
|
|
||||||
// For a packet, we should be able to get a session that handles that...
|
// For a packet, we should be able to get a session that handles that...
|
||||||
assertNotNull(JingleSession.getInstanceFor(getConnection(0)));
|
assertNotNull(JingleSession.getInstanceFor(getConnection(0)));
|
||||||
|
|
|
@ -205,10 +205,9 @@ public class STUNResolverTest extends SmackTestCase {
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
stunResolver.initialize();
|
stunResolver.initializeAndWait();
|
||||||
Thread.sleep(55000);
|
Thread.sleep(55000);
|
||||||
assertTrue(valCounter() > 0);
|
assertTrue(valCounter() > 0);
|
||||||
stunResolver.resolve();
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -257,8 +256,8 @@ public class STUNResolverTest extends SmackTestCase {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Explicit resolution
|
// Explicit resolution
|
||||||
tr1.resolve();
|
tr1.resolve(null);
|
||||||
tr2.resolve();
|
tr2.resolve(null);
|
||||||
|
|
||||||
final JingleManager man0 = new JingleManager(getConnection(0), tr1);
|
final JingleManager man0 = new JingleManager(getConnection(0), tr1);
|
||||||
final JingleManager man1 = new JingleManager(getConnection(1), tr2);
|
final JingleManager man1 = new JingleManager(getConnection(1), tr2);
|
||||||
|
@ -356,8 +355,8 @@ public class STUNResolverTest extends SmackTestCase {
|
||||||
TransportCandidate.Fixed c2 = new TransportCandidate.Fixed("localhost", 22444);
|
TransportCandidate.Fixed c2 = new TransportCandidate.Fixed("localhost", 22444);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
c1.addCandidateEcho();
|
c1.addCandidateEcho(null);
|
||||||
c2.addCandidateEcho();
|
c2.addCandidateEcho(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class TransportCandidateTest extends SmackTestCase {
|
||||||
|
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
tc.addCandidateEcho();
|
tc.addCandidateEcho(null);
|
||||||
assertTrue(tc.getCandidateEcho().test(InetAddress.getByName("localhost"),10020));
|
assertTrue(tc.getCandidateEcho().test(InetAddress.getByName("localhost"),10020));
|
||||||
}
|
}
|
||||||
catch (SocketException e) {
|
catch (SocketException e) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class TransportResolverTest extends SmackTestCase {
|
||||||
assertFalse(tr.isResolved());
|
assertFalse(tr.isResolved());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
tr.resolve();
|
tr.resolve(null);
|
||||||
} catch (XMPPException e) {
|
} catch (XMPPException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
fail("Error resolving");
|
fail("Error resolving");
|
||||||
|
|
Loading…
Reference in a new issue