mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-12-11 23:51:09 +01:00
Significant improvement to Jingle logging messages, and a new SmackLogger that allows for use of java.commons.logging. Improvements to Jingle processing to keep up with recent changes in the XEPs as we approach approval of the standard. (There will be more changes as the standard changes.) Fixes to the way STUN gets used, and a new JSTUN library (including performance and reliability changes we added to it).
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@10852 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
995f319f1e
commit
84fcf53512
40 changed files with 755 additions and 337 deletions
|
|
@ -52,28 +52,36 @@
|
|||
|
||||
package org.jivesoftware.smackx.jingle.nat;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.jivesoftware.smackx.jingle.SmackLogger;
|
||||
|
||||
/**
|
||||
* A very Simple HTTP Server
|
||||
*/
|
||||
public class HttpServer {
|
||||
|
||||
public HttpServer(int port) {
|
||||
private static final SmackLogger LOGGER = SmackLogger.getLogger(HttpServer.class);
|
||||
|
||||
public HttpServer(int port) {
|
||||
ServerSocket server_socket;
|
||||
|
||||
try {
|
||||
|
||||
server_socket = new ServerSocket(port);
|
||||
System.out.println("httpServer running on port " +
|
||||
LOGGER.debug("httpServer running on port " +
|
||||
server_socket.getLocalPort());
|
||||
|
||||
while (true) {
|
||||
Socket socket = server_socket.accept();
|
||||
System.out.println("New connection accepted " +
|
||||
LOGGER.debug("New connection accepted " +
|
||||
socket.getInetAddress() +
|
||||
":" + socket.getPort());
|
||||
|
||||
|
|
@ -86,13 +94,13 @@ public class HttpServer {
|
|||
thread.start();
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println(e);
|
||||
LOGGER.debug("", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch (IOException e) {
|
||||
System.out.println(e);
|
||||
LOGGER.debug("", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -129,7 +137,7 @@ public class HttpServer {
|
|||
while (true) {
|
||||
|
||||
String headerLine = br.readLine();
|
||||
System.out.println(headerLine);
|
||||
LOGGER.debug(headerLine);
|
||||
if (headerLine.equals(CRLF) || headerLine.equals("")) break;
|
||||
|
||||
StringTokenizer s = new StringTokenizer(headerLine);
|
||||
|
|
|
|||
|
|
@ -55,6 +55,8 @@ import java.net.InetAddress;
|
|||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smackx.jingle.SmackLogger;
|
||||
|
||||
/**
|
||||
* ICE Transport candidate.
|
||||
* <p/>
|
||||
|
|
@ -65,7 +67,9 @@ import java.util.List;
|
|||
*/
|
||||
public class ICECandidate extends TransportCandidate implements Comparable {
|
||||
|
||||
private String id; // An identification
|
||||
private static final SmackLogger LOGGER = SmackLogger.getLogger(ICECandidate.class);
|
||||
|
||||
private String id; // An identification
|
||||
|
||||
private String username;
|
||||
|
||||
|
|
@ -273,7 +277,7 @@ public class ICECandidate extends TransportCandidate implements Comparable {
|
|||
public void testFinished(TestResult testResult, TransportCandidate candidate) {
|
||||
if (testResult.isReachable() && checkingCandidate.equals(candidate)) {
|
||||
result.setResult(true);
|
||||
System.out.println("RESULT>>>OK:" + candidate.getIp() + ":" + candidate.getPort());
|
||||
LOGGER.debug("Candidate reachable: " + candidate.getIp() + ":" + candidate.getPort() + " from " + getIp() +":" + getPort());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -299,7 +303,7 @@ public class ICECandidate extends TransportCandidate implements Comparable {
|
|||
|
||||
for (int i = 0; i < 10 && !result.isReachable(); i++)
|
||||
try {
|
||||
System.err.println("ICE Candidate retry #" + i);
|
||||
LOGGER.error("ICE Candidate retry #" + i);
|
||||
Thread.sleep(400);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
|
|
|
|||
|
|
@ -20,20 +20,24 @@
|
|||
|
||||
package org.jivesoftware.smackx.jingle.nat;
|
||||
|
||||
import de.javawi.jstun.test.demo.ice.Candidate;
|
||||
import de.javawi.jstun.test.demo.ice.ICENegociator;
|
||||
import de.javawi.jstun.util.UtilityException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||
import org.jivesoftware.smackx.jingle.SmackLogger;
|
||||
|
||||
import de.javawi.jstun.test.demo.ice.Candidate;
|
||||
import de.javawi.jstun.test.demo.ice.ICENegociator;
|
||||
import de.javawi.jstun.util.UtilityException;
|
||||
|
||||
/**
|
||||
* ICE Resolver for Jingle transport method that results in sending data between two entities using the Interactive Connectivity Establishment (ICE) methodology. (XEP-0176)
|
||||
* The goal of this resolver is to make possible to establish and manage out-of-band connections between two XMPP entities, even if they are behind Network Address Translators (NATs) or firewalls.
|
||||
|
|
@ -43,12 +47,15 @@ import java.util.Random;
|
|||
*/
|
||||
public class ICEResolver extends TransportResolver {
|
||||
|
||||
XMPPConnection connection;
|
||||
private static final SmackLogger LOGGER = SmackLogger.getLogger(ICEResolver.class);
|
||||
|
||||
XMPPConnection connection;
|
||||
Random random = new Random();
|
||||
long sid;
|
||||
String server = "stun.xten.net";
|
||||
int port = 3478;
|
||||
ICENegociator iceNegociator = null;
|
||||
String server;
|
||||
int port;
|
||||
static Map<String, ICENegociator> negociatorsMap = new HashMap<String, ICENegociator>();
|
||||
//ICENegociator iceNegociator = null;
|
||||
|
||||
public ICEResolver(XMPPConnection connection, String server, int port) {
|
||||
super();
|
||||
|
|
@ -60,13 +67,21 @@ public class ICEResolver extends TransportResolver {
|
|||
|
||||
public void initialize() throws XMPPException {
|
||||
if (!isResolving() && !isResolved()) {
|
||||
System.out.println("Initialized");
|
||||
LOGGER.debug("Initialized");
|
||||
|
||||
iceNegociator = new ICENegociator((short) 1, server, port);
|
||||
// gather candidates
|
||||
iceNegociator.gatherCandidateAddresses();
|
||||
// priorize candidates
|
||||
iceNegociator.prioritizeCandidates();
|
||||
// Negotiation with a STUN server for a set of interfaces is quite slow, but the results
|
||||
// never change over then instance of a JVM. To increase connection performance considerably
|
||||
// we now cache established/initialized negotiators for each STUN server, so that subsequent uses
|
||||
// of the STUN server are much, much faster.
|
||||
if (negociatorsMap.get(server) == null) {
|
||||
ICENegociator iceNegociator = new ICENegociator(server, port, (short) 1);
|
||||
negociatorsMap.put(server, iceNegociator);
|
||||
|
||||
// gather candidates
|
||||
iceNegociator.gatherCandidateAddresses();
|
||||
// priorize candidates
|
||||
iceNegociator.prioritizeCandidates();
|
||||
}
|
||||
|
||||
}
|
||||
this.setInitialized();
|
||||
|
|
@ -91,6 +106,8 @@ public class ICEResolver extends TransportResolver {
|
|||
|
||||
this.clear();
|
||||
|
||||
// Create a transport candidate for each ICE negotiator candidate we have.
|
||||
ICENegociator iceNegociator = negociatorsMap.get(server);
|
||||
for (Candidate candidate : iceNegociator.getSortedCandidates())
|
||||
try {
|
||||
Candidate.CandidateType type = candidate.getCandidateType();
|
||||
|
|
@ -104,7 +121,26 @@ public class ICEResolver extends TransportResolver {
|
|||
else
|
||||
iceType = ICECandidate.Type.host;
|
||||
|
||||
TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress().getHostAddress(), 1, candidate.getNetwork(), String.valueOf(Math.abs(random.nextLong())), candidate.getPort(), "1", candidate.getPriority(), iceType);
|
||||
// JBW/GW - 17JUL08: Figure out the zero-based NIC number for this candidate.
|
||||
short nicNum = 0;
|
||||
try {
|
||||
Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();
|
||||
short i = 0;
|
||||
NetworkInterface nic = NetworkInterface.getByInetAddress(candidate.getAddress().getInetAddress());
|
||||
while(nics.hasMoreElements()) {
|
||||
NetworkInterface checkNIC = nics.nextElement();
|
||||
if (checkNIC.equals(nic)) {
|
||||
nicNum = i;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
} catch (SocketException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress().getHostAddress(), 1, nicNum, String.valueOf(Math.abs(random.nextLong())), candidate.getPort(), "1", candidate.getPriority(), iceType);
|
||||
transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress());
|
||||
transportCandidate.setPort(getFreePort());
|
||||
try {
|
||||
|
|
@ -115,7 +151,7 @@ public class ICEResolver extends TransportResolver {
|
|||
}
|
||||
this.addCandidate(transportCandidate);
|
||||
|
||||
System.out.println("C: " + candidate.getAddress().getInetAddress() + "|" + candidate.getBase().getAddress().getInetAddress() + " p:" + candidate.getPriority());
|
||||
LOGGER.debug("Candidate addr: " + candidate.getAddress().getInetAddress() + "|" + candidate.getBase().getAddress().getInetAddress() + " Priority:" + candidate.getPriority());
|
||||
|
||||
}
|
||||
catch (UtilityException e) {
|
||||
|
|
@ -128,16 +164,19 @@ public class ICEResolver extends TransportResolver {
|
|||
// Get a Relay Candidate from XMPP Server
|
||||
|
||||
if (RTPBridge.serviceAvailable(connection)) {
|
||||
try {
|
||||
// try {
|
||||
|
||||
String localIp;
|
||||
int network;
|
||||
|
||||
if (iceNegociator.getPublicCandidate() != null) {
|
||||
localIp = iceNegociator.getPublicCandidate().getBase().getAddress().getInetAddress().getHostAddress();
|
||||
network = iceNegociator.getPublicCandidate().getNetwork();
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
// JBW/GW - 17JUL08: ICENegotiator.getPublicCandidate() always returned null in JSTUN 1.7.0, and now the API doesn't exist in JSTUN 1.7.1
|
||||
// if (iceNegociator.getPublicCandidate() != null) {
|
||||
// localIp = iceNegociator.getPublicCandidate().getBase().getAddress().getInetAddress().getHostAddress();
|
||||
// network = iceNegociator.getPublicCandidate().getNetwork();
|
||||
// }
|
||||
// else {
|
||||
{
|
||||
localIp = BridgedResolver.getLocalHost();
|
||||
network = 0;
|
||||
}
|
||||
|
|
@ -168,17 +207,19 @@ public class ICEResolver extends TransportResolver {
|
|||
|
||||
addCandidate(localCandidate);
|
||||
|
||||
}
|
||||
catch (UtilityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// }
|
||||
// catch (UtilityException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// catch (UnknownHostException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
// Get Public Candidate From XMPP Server
|
||||
|
||||
if (iceNegociator.getPublicCandidate() == null) {
|
||||
// JBW/GW - 17JUL08 - ICENegotiator.getPublicCandidate() always returned null in JSTUN 1.7.0, and now it doesn't exist in JSTUN 1.7.1
|
||||
// if (iceNegociator.getPublicCandidate() == null) {
|
||||
if (true) {
|
||||
|
||||
String publicIp = RTPBridge.getPublicIP(connection);
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,12 @@
|
|||
|
||||
package org.jivesoftware.smackx.jingle.nat;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.jivesoftware.smack.PacketCollector;
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
|
|
@ -29,15 +35,10 @@ import org.jivesoftware.smack.packet.IQ;
|
|||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.provider.ProviderManager;
|
||||
import org.jivesoftware.smackx.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.packet.DiscoverItems;
|
||||
import org.jivesoftware.smackx.jingle.SmackLogger;
|
||||
import org.jivesoftware.smackx.packet.DiscoverInfo;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* RTPBridge IQ Packet used to request and retrieve a RTPBridge Candidates that can be used for a Jingle Media Transmission between two parties that are behind NAT.
|
||||
* This Jingle Bridge has all the needed information to establish a full UDP Channel (Send and Receive) between two parties.
|
||||
|
|
@ -51,7 +52,9 @@ import java.util.Iterator;
|
|||
*/
|
||||
public class RTPBridge extends IQ {
|
||||
|
||||
private String sid;
|
||||
private static final SmackLogger LOGGER = SmackLogger.getLogger(RTPBridge.class);
|
||||
|
||||
private String sid;
|
||||
private String pass;
|
||||
private String ip;
|
||||
private String name;
|
||||
|
|
@ -424,20 +427,29 @@ public class RTPBridge extends IQ {
|
|||
return false;
|
||||
}
|
||||
|
||||
System.out.println("Service listing");
|
||||
LOGGER.debug("Service listing");
|
||||
|
||||
ServiceDiscoveryManager disco = ServiceDiscoveryManager
|
||||
.getInstanceFor(xmppConnection);
|
||||
try {
|
||||
DiscoverItems items = disco.discoverItems(xmppConnection.getServiceName());
|
||||
Iterator iter = items.getItems();
|
||||
// DiscoverItems items = disco.discoverItems(xmppConnection.getServiceName());
|
||||
// Iterator iter = items.getItems();
|
||||
// while (iter.hasNext()) {
|
||||
// DiscoverItems.Item item = (DiscoverItems.Item) iter.next();
|
||||
// if (item.getEntityID().startsWith("rtpbridge.")) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
DiscoverInfo discoInfo = disco.discoverInfo(xmppConnection.getServiceName());
|
||||
Iterator iter = discoInfo.getIdentities();
|
||||
while (iter.hasNext()) {
|
||||
DiscoverItems.Item item = (DiscoverItems.Item) iter.next();
|
||||
if (item.getEntityID().startsWith("rtpbridge.")) {
|
||||
return true;
|
||||
}
|
||||
DiscoverInfo.Identity identity = (DiscoverInfo.Identity) iter.next();
|
||||
if ((identity.getName() != null) && (identity.getName().startsWith("rtpbridge"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -467,7 +479,7 @@ public class RTPBridge extends IQ {
|
|||
rtpPacket.setHostA(localCandidate.getIp());
|
||||
rtpPacket.setHostB(proxyCandidate.getIp());
|
||||
|
||||
// System.out.println("Relayed to: " + candidate.getIp() + ":" + candidate.getPort());
|
||||
// LOGGER.debug("Relayed to: " + candidate.getIp() + ":" + candidate.getPort());
|
||||
|
||||
PacketCollector collector = xmppConnection
|
||||
.createPacketCollector(new PacketIDFilter(rtpPacket.getPacketID()));
|
||||
|
|
@ -499,7 +511,7 @@ public class RTPBridge extends IQ {
|
|||
rtpPacket.setTo(RTPBridge.NAME + "." + xmppConnection.getServiceName());
|
||||
rtpPacket.setType(Type.SET);
|
||||
|
||||
// System.out.println("Relayed to: " + candidate.getIp() + ":" + candidate.getPort());
|
||||
// LOGGER.debug("Relayed to: " + candidate.getIp() + ":" + candidate.getPort());
|
||||
|
||||
PacketCollector collector = xmppConnection
|
||||
.createPacketCollector(new PacketIDFilter(rtpPacket.getPacketID()));
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jingle.nat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.PacketCollector;
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
|
|
@ -28,14 +32,11 @@ import org.jivesoftware.smack.packet.IQ;
|
|||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.provider.ProviderManager;
|
||||
import org.jivesoftware.smackx.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.jingle.SmackLogger;
|
||||
import org.jivesoftware.smackx.packet.DiscoverInfo;
|
||||
import org.jivesoftware.smackx.packet.DiscoverItems;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* STUN IQ Packet used to request and retrieve a STUN server and port to make p2p connections easier. STUN is usually used by Jingle Media Transmission between two parties that are behind NAT.
|
||||
* <p/>
|
||||
|
|
@ -47,7 +48,9 @@ import java.util.List;
|
|||
*/
|
||||
public class STUN extends IQ {
|
||||
|
||||
private List<StunServerAddress> servers = new ArrayList<StunServerAddress>();
|
||||
private static final SmackLogger LOGGER = SmackLogger.getLogger(STUN.class);
|
||||
|
||||
private List<StunServerAddress> servers = new ArrayList<StunServerAddress>();
|
||||
|
||||
private String publicIp = null;
|
||||
|
||||
|
|
@ -220,7 +223,7 @@ public class STUN extends IQ {
|
|||
return false;
|
||||
}
|
||||
|
||||
System.out.println("Service listing");
|
||||
LOGGER.debug("Service listing");
|
||||
|
||||
ServiceDiscoveryManager disco = ServiceDiscoveryManager
|
||||
.getInstanceFor(xmppConnection);
|
||||
|
|
@ -240,7 +243,7 @@ public class STUN extends IQ {
|
|||
return true;
|
||||
}
|
||||
|
||||
System.out.println(item.getName()+"-"+info.getType());
|
||||
LOGGER.debug(item.getName()+"-"+info.getType());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,15 +19,6 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jingle.nat;
|
||||
|
||||
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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
|
|
@ -36,6 +27,17 @@ import java.net.URL;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||
import org.jivesoftware.smackx.jingle.SmackLogger;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import de.javawi.jstun.test.BindingLifetimeTest;
|
||||
import de.javawi.jstun.test.DiscoveryInfo;
|
||||
import de.javawi.jstun.test.DiscoveryTest;
|
||||
|
||||
/**
|
||||
* Transport resolver using the JSTUN library, to discover public IP and use it as a candidate.
|
||||
*
|
||||
|
|
@ -45,7 +47,9 @@ import java.util.Enumeration;
|
|||
*/
|
||||
public class STUNResolver extends TransportResolver {
|
||||
|
||||
// The filename where the STUN servers are stored.
|
||||
private static final SmackLogger LOGGER = SmackLogger.getLogger(STUNResolver.class);
|
||||
|
||||
// The filename where the STUN servers are stored.
|
||||
public final static String STUNSERVERS_FILENAME = "META-INF/stun-config.xml";
|
||||
|
||||
// Fallback values when we don't have any STUN server to use...
|
||||
|
|
@ -282,7 +286,7 @@ public class STUNResolver extends TransportResolver {
|
|||
resolvedPublicIP, getFreePort());
|
||||
candidate.setLocalIp(resolvedLocalIP);
|
||||
|
||||
System.out.println("RESOLVING : " + resolvedPublicIP + ":" + candidate.getPort());
|
||||
LOGGER.debug("RESOLVING : " + resolvedPublicIP + ":" + candidate.getPort());
|
||||
|
||||
addCandidate(candidate);
|
||||
|
||||
|
|
@ -296,7 +300,7 @@ public class STUNResolver extends TransportResolver {
|
|||
* @throws XMPPException
|
||||
*/
|
||||
public void initialize() throws XMPPException {
|
||||
System.out.println("Initialized");
|
||||
LOGGER.debug("Initialized");
|
||||
if (!isResolving()&&!isResolved()) {
|
||||
// Get the best STUN server available
|
||||
if (currentServer.isNull()) {
|
||||
|
|
|
|||
|
|
@ -59,6 +59,8 @@ import java.net.DatagramSocket;
|
|||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
|
||||
import org.jivesoftware.smackx.jingle.SmackLogger;
|
||||
|
||||
/**
|
||||
* A Simple and Experimental Bridge.
|
||||
* It Creates a TCP Socket That Connects to another TCP Socket Listener and forwards every packets received to an UDP Listener.
|
||||
|
|
@ -66,7 +68,9 @@ import java.net.Socket;
|
|||
*/
|
||||
public class TcpUdpBridgeClient {
|
||||
|
||||
private String remoteTcpHost = null;
|
||||
private static final SmackLogger LOGGER = SmackLogger.getLogger(TcpUdpBridgeClient.class);
|
||||
|
||||
private String remoteTcpHost = null;
|
||||
private String remoteUdpHost = null;
|
||||
private int remoteTcpPort = -1;
|
||||
private int remoteUdpPort = -1;
|
||||
|
|
@ -85,7 +89,7 @@ public class TcpUdpBridgeClient {
|
|||
localTcpSocket = new Socket(remoteTcpHost, remoteTcpPort);
|
||||
localUdpSocket = new DatagramSocket(0);
|
||||
localUdpPort = localUdpSocket.getLocalPort();
|
||||
System.out.println("UDP: " + localUdpSocket.getLocalPort());
|
||||
LOGGER.debug("UDP: " + localUdpSocket.getLocalPort());
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -110,11 +114,11 @@ public class TcpUdpBridgeClient {
|
|||
localUdpSocket.receive(p);
|
||||
if (p.getLength() == 0) continue;
|
||||
|
||||
System.out.println("UDP Client Received and Sending to TCP Server:"+new String(p.getData(),0,p.getLength(),"UTF-8"));
|
||||
LOGGER.debug("UDP Client Received and Sending to TCP Server:"+new String(p.getData(),0,p.getLength(),"UTF-8"));
|
||||
|
||||
out.write(p.getData(), 0, p.getLength());
|
||||
out.flush();
|
||||
System.out.println("Client Flush");
|
||||
LOGGER.debug("Client Flush");
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -141,7 +145,7 @@ public class TcpUdpBridgeClient {
|
|||
int s = in.read(b);
|
||||
//if (s == -1) continue;
|
||||
|
||||
System.out.println("TCP Client:" +new String(b,0,s,"UTF-8"));
|
||||
LOGGER.debug("TCP Client:" +new String(b,0,s,"UTF-8"));
|
||||
|
||||
DatagramPacket udpPacket = new DatagramPacket(b, s);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,15 @@
|
|||
package org.jivesoftware.smackx.jingle.nat;
|
||||
|
||||
import java.net.*;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
|
||||
import org.jivesoftware.smackx.jingle.SmackLogger;
|
||||
|
||||
/**
|
||||
* A Simple and Experimental Bridge.
|
||||
|
|
@ -12,7 +18,9 @@ import java.io.OutputStream;
|
|||
*/
|
||||
public class TcpUdpBridgeServer {
|
||||
|
||||
private String remoteTcpHost = null;
|
||||
private static final SmackLogger LOGGER = SmackLogger.getLogger(TcpUdpBridgeServer.class);
|
||||
|
||||
private String remoteTcpHost = null;
|
||||
private String remoteUdpHost = null;
|
||||
private int remoteTcpPort = -1;
|
||||
private int remoteUdpPort = -1;
|
||||
|
|
@ -32,7 +40,7 @@ public class TcpUdpBridgeServer {
|
|||
serverTcpSocket = new ServerSocket(remoteTcpPort);
|
||||
localUdpSocket = new DatagramSocket(0);
|
||||
localUdpPort = localUdpSocket.getLocalPort();
|
||||
System.out.println("UDP: " + localUdpSocket.getLocalPort());
|
||||
LOGGER.debug("UDP: " + localUdpSocket.getLocalPort());
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -56,11 +64,11 @@ public class TcpUdpBridgeServer {
|
|||
localUdpSocket.receive(p);
|
||||
if (p.getLength() == 0) continue;
|
||||
|
||||
System.out.println("UDP Server Received and Sending to TCP Client:" + new String(p.getData(), 0, p.getLength(), "UTF-8"));
|
||||
LOGGER.debug("UDP Server Received and Sending to TCP Client:" + new String(p.getData(), 0, p.getLength(), "UTF-8"));
|
||||
|
||||
out.write(p.getData(), 0, p.getLength());
|
||||
out.flush();
|
||||
System.out.println("Server Flush");
|
||||
LOGGER.debug("Server Flush");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -87,7 +95,7 @@ public class TcpUdpBridgeServer {
|
|||
int s = in.read(b);
|
||||
//if (s == -1) continue;
|
||||
|
||||
System.out.println("TCP Server:" + new String(b, 0, s, "UTF-8"));
|
||||
LOGGER.debug("TCP Server:" + new String(b, 0, s, "UTF-8"));
|
||||
|
||||
DatagramPacket udpPacket = new DatagramPacket(b, s);
|
||||
|
||||
|
|
|
|||
|
|
@ -52,16 +52,21 @@
|
|||
|
||||
package org.jivesoftware.smackx.jingle.nat;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.*;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||
import org.jivesoftware.smackx.jingle.SmackLogger;
|
||||
|
||||
/**
|
||||
* Transport candidate.
|
||||
* <p/>
|
||||
|
|
@ -73,7 +78,9 @@ import java.util.List;
|
|||
*/
|
||||
public abstract class TransportCandidate {
|
||||
|
||||
private String name;
|
||||
private static final SmackLogger LOGGER = SmackLogger.getLogger(TransportCandidate.class);
|
||||
|
||||
private String name;
|
||||
|
||||
private String ip; // IP address
|
||||
|
||||
|
|
@ -680,14 +687,14 @@ public abstract class TransportCandidate {
|
|||
|
||||
public void run() {
|
||||
try {
|
||||
System.out.println("Listening for ECHO: " + socket.getLocalAddress().getHostAddress() + ":" + socket.getLocalPort());
|
||||
LOGGER.debug("Listening for ECHO: " + socket.getLocalAddress().getHostAddress() + ":" + socket.getLocalPort());
|
||||
while (true) {
|
||||
|
||||
DatagramPacket packet = new DatagramPacket(new byte[150], 150);
|
||||
|
||||
socket.receive(packet);
|
||||
|
||||
//System.out.println("ECHO Packet Received in: " + socket.getLocalAddress().getHostAddress() + ":" + socket.getLocalPort() + " From: " + packet.getAddress().getHostAddress() + ":" + packet.getPort());
|
||||
//LOGGER.debug("ECHO Packet Received in: " + socket.getLocalAddress().getHostAddress() + ":" + socket.getLocalPort() + " From: " + packet.getAddress().getHostAddress() + ":" + packet.getPort());
|
||||
|
||||
boolean accept = false;
|
||||
|
||||
|
|
@ -766,7 +773,7 @@ public abstract class TransportCandidate {
|
|||
resultListener.testFinished(testResult, candidate);
|
||||
}
|
||||
|
||||
public void testASync(final TransportCandidate candidate, final String password) {
|
||||
public void testASync(final TransportCandidate transportCandidate, final String password) {
|
||||
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
|
||||
|
|
@ -776,19 +783,21 @@ public abstract class TransportCandidate {
|
|||
public boolean datagramReceived(DatagramPacket datagramPacket) {
|
||||
|
||||
try {
|
||||
System.out.println("Content Received: " + new String(datagramPacket.getData(), "UTF-8"));
|
||||
LOGGER.debug("ECHO Received to: " + candidate.getIp() + ":" + candidate.getPort() + " data: " + new String(datagramPacket.getData(), "UTF-8"));
|
||||
String str[] = new String(datagramPacket.getData(), "UTF-8").split(";");
|
||||
String pass = str[0];
|
||||
String addr[] = str[1].split(":");
|
||||
String ip = addr[0];
|
||||
String pt = addr[1];
|
||||
|
||||
if (pass.equals(password) && candidate.getIp().indexOf(ip) != -1 && candidate.getPort() == Integer.parseInt(pt)) {
|
||||
System.out.println("Result OK:" + candidate.getIp() + ":" + candidate.getPort());
|
||||
if (pass.equals(password)
|
||||
&& transportCandidate.getIp().indexOf(ip) != -1
|
||||
&& transportCandidate.getPort() == Integer.parseInt(pt)) {
|
||||
LOGGER.debug("ECHO OK: " + candidate.getIp() + ":" + candidate.getPort() + " <-> " + transportCandidate.getIp() + ":" + transportCandidate.getPort());
|
||||
TestResult testResult = new TestResult();
|
||||
testResult.setResult(true);
|
||||
ended = true;
|
||||
fireTestResult(testResult, candidate);
|
||||
fireTestResult(testResult, transportCandidate);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -797,7 +806,7 @@ public abstract class TransportCandidate {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("Result Wrong Data:" + datagramPacket.getAddress().getHostAddress() + ":" + datagramPacket.getPort());
|
||||
LOGGER.debug("ECHO Wrong Data: " + datagramPacket.getAddress().getHostAddress() + ":" + datagramPacket.getPort());
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
|
@ -815,12 +824,12 @@ public abstract class TransportCandidate {
|
|||
DatagramPacket packet = new DatagramPacket(content, content.length);
|
||||
|
||||
try {
|
||||
packet.setAddress(InetAddress.getByName(candidate.getIp()));
|
||||
packet.setAddress(InetAddress.getByName(transportCandidate.getIp()));
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
packet.setPort(candidate.getPort());
|
||||
packet.setPort(transportCandidate.getPort());
|
||||
|
||||
long delay = 200;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,9 +20,20 @@
|
|||
|
||||
package org.jivesoftware.smackx.jingle.nat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smackx.jingle.*;
|
||||
import org.jivesoftware.smackx.jingle.ContentNegotiator;
|
||||
import org.jivesoftware.smackx.jingle.JingleActionEnum;
|
||||
import org.jivesoftware.smackx.jingle.JingleException;
|
||||
import org.jivesoftware.smackx.jingle.JingleNegotiator;
|
||||
import org.jivesoftware.smackx.jingle.JingleNegotiatorState;
|
||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||
import org.jivesoftware.smackx.jingle.SmackLogger;
|
||||
import org.jivesoftware.smackx.jingle.listeners.JingleListener;
|
||||
import org.jivesoftware.smackx.jingle.listeners.JingleTransportListener;
|
||||
import org.jivesoftware.smackx.packet.Jingle;
|
||||
|
|
@ -30,11 +41,6 @@ import org.jivesoftware.smackx.packet.JingleContent;
|
|||
import org.jivesoftware.smackx.packet.JingleTransport;
|
||||
import org.jivesoftware.smackx.packet.JingleTransport.JingleTransportCandidate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Transport negotiator.
|
||||
* <p/>
|
||||
|
|
@ -46,7 +52,9 @@ import java.util.List;
|
|||
*/
|
||||
public abstract class TransportNegotiator extends JingleNegotiator {
|
||||
|
||||
// The time we give to the candidates check before we accept or decline the
|
||||
private static final SmackLogger LOGGER = SmackLogger.getLogger(TransportNegotiator.class);
|
||||
|
||||
// The time we give to the candidates check before we accept or decline the
|
||||
// transport (in milliseconds)
|
||||
public final static int CANDIDATES_ACCEPT_PERIOD = 4000;
|
||||
|
||||
|
|
@ -134,7 +142,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
return;
|
||||
}
|
||||
}
|
||||
//System.out.println("BEST: " + bestLocalCandidate.getIp());
|
||||
//LOGGER.debug("BEST: " + bestLocalCandidate.getIp());
|
||||
throw new XMPPException("Local transport candidate has not be offered.");
|
||||
}
|
||||
|
||||
|
|
@ -434,7 +442,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
// Add the candidate to the list
|
||||
if (remoteCandidate != null) {
|
||||
synchronized (validRemoteCandidates) {
|
||||
System.out.println("ADDED Valid Cand: " + remoteCandidate.getIp() + ":" + remoteCandidate.getPort());
|
||||
LOGGER.debug("Added valid candidate: " + remoteCandidate.getIp() + ":" + remoteCandidate.getPort());
|
||||
validRemoteCandidates.add(remoteCandidate);
|
||||
}
|
||||
}
|
||||
|
|
@ -562,7 +570,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
|
||||
if (!(resolver.isResolving() || resolver.isResolved())) {
|
||||
// Resolve our IP and port
|
||||
System.out.println("RESOLVER CALLED");
|
||||
LOGGER.debug("RESOLVER CALLED");
|
||||
resolver.resolve(session);
|
||||
}
|
||||
}
|
||||
|
|
@ -727,14 +735,14 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
if (!accepted.isEmpty()) {
|
||||
|
||||
for (TransportCandidate cand : accepted) {
|
||||
System.out.println("Cand: " + cand.getIp());
|
||||
LOGGER.debug("Remote acccepted candidate addr: " + cand.getIp());
|
||||
}
|
||||
|
||||
TransportCandidate cand = (TransportCandidate) accepted.get(0);
|
||||
setAcceptedLocalCandidate(cand);
|
||||
|
||||
if (isEstablished()) {
|
||||
System.out.println("SET ACTIVE");
|
||||
LOGGER.debug(cand.getIp() + " is set active");
|
||||
//setNegotiatorState(JingleNegotiatorState.SUCCEEDED);
|
||||
}
|
||||
}
|
||||
|
|
@ -748,7 +756,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
private IQ receiveSessionAcceptAction(Jingle jingle) {
|
||||
IQ response = null;
|
||||
|
||||
System.out.println("Transport stabilished");
|
||||
LOGGER.debug("Transport stabilished");
|
||||
//triggerTransportEstablished(getAcceptedLocalCandidate(), getBestRemoteCandidate());
|
||||
|
||||
//setNegotiatorState(JingleNegotiatorState.SUCCEEDED);
|
||||
|
|
@ -767,7 +775,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
for (JingleListener li : listeners) {
|
||||
if (li instanceof JingleTransportListener) {
|
||||
JingleTransportListener mli = (JingleTransportListener) li;
|
||||
System.out.println("triggerTransportEstablished " + local.getLocalIp() + ":" + local.getPort() + "|"
|
||||
LOGGER.debug("triggerTransportEstablished " + local.getLocalIp() + ":" + local.getPort() + " <-> "
|
||||
+ remote.getIp() + ":" + remote.getPort());
|
||||
mli.transportEstablished(local, remote);
|
||||
}
|
||||
|
|
@ -827,10 +835,10 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
// Hopefully, we only have one validRemoteCandidate
|
||||
ArrayList cands = getValidRemoteCandidatesList();
|
||||
if (!cands.isEmpty()) {
|
||||
System.out.println("RAW CAND");
|
||||
LOGGER.debug("RAW CAND");
|
||||
return (TransportCandidate) cands.get(0);
|
||||
} else {
|
||||
System.out.println("No Remote Candidate");
|
||||
LOGGER.debug("No Remote Candidate");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -893,7 +901,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
}
|
||||
|
||||
if (result != null && result.getType().equals("relay"))
|
||||
System.out.println("Relay Type");
|
||||
LOGGER.debug("Relay Type");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,9 +52,6 @@
|
|||
|
||||
package org.jivesoftware.smackx.jingle.nat;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -62,6 +59,10 @@ import java.util.Collections;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||
import org.jivesoftware.smackx.jingle.SmackLogger;
|
||||
|
||||
/**
|
||||
* A TransportResolver is used for obtaining a list of valid transport
|
||||
* candidates. A transport candidate is composed by an IP address and a port number.
|
||||
|
|
@ -72,7 +73,9 @@ import java.util.List;
|
|||
*/
|
||||
public abstract class TransportResolver {
|
||||
|
||||
public enum Type {
|
||||
private static final SmackLogger LOGGER = SmackLogger.getLogger(TransportResolver.class);
|
||||
|
||||
public enum Type {
|
||||
|
||||
rawupd, ice
|
||||
}
|
||||
|
|
@ -247,7 +250,7 @@ public abstract class TransportResolver {
|
|||
TransportResolverListener trl = (TransportResolverListener) iter.next();
|
||||
if (trl instanceof TransportResolverListener.Resolver) {
|
||||
TransportResolverListener.Resolver li = (TransportResolverListener.Resolver) trl;
|
||||
System.out.println("triggerCandidateAdded : " + cand.getLocalIp());
|
||||
LOGGER.debug("triggerCandidateAdded : " + cand.getLocalIp());
|
||||
li.candidateAdded(cand);
|
||||
}
|
||||
}
|
||||
|
|
@ -331,7 +334,7 @@ public abstract class TransportResolver {
|
|||
Collections.sort(cands);
|
||||
// Return the last candidate
|
||||
result = (TransportCandidate) cands.get(cands.size() - 1);
|
||||
System.out.println("Result: " + result.getIp());
|
||||
LOGGER.debug("Result: " + result.getIp());
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
@ -383,12 +386,12 @@ public abstract class TransportResolver {
|
|||
public void initializeAndWait() throws XMPPException {
|
||||
this.initialize();
|
||||
try {
|
||||
System.out.print("Initializing...");
|
||||
LOGGER.debug("Initializing transport resolver...");
|
||||
while (!this.isInitialized()) {
|
||||
System.out.print(".");
|
||||
LOGGER.debug("Resolver init still pending");
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
System.out.print("Resolved\n");
|
||||
LOGGER.debug("Transport resolved\n");
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue