1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-23 20:42:06 +01:00

Towards S5B!

This commit is contained in:
vanitasvitae 2017-06-10 18:27:41 +02:00
parent e5edb4cd04
commit a4454aa8b5
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
4 changed files with 86 additions and 11 deletions

View file

@ -56,7 +56,7 @@ import org.jivesoftware.smackx.jingle_filetransfer.handler.InitiatorOutgoingFile
import org.jivesoftware.smackx.jingle_filetransfer.handler.ResponderIncomingFileTransferAccepted; import org.jivesoftware.smackx.jingle_filetransfer.handler.ResponderIncomingFileTransferAccepted;
import org.jivesoftware.smackx.jingle_filetransfer.listener.IncomingJingleFileTransferListener; import org.jivesoftware.smackx.jingle_filetransfer.listener.IncomingJingleFileTransferListener;
import org.jivesoftware.smackx.jingle_filetransfer.provider.JingleFileTransferContentDescriptionProvider; import org.jivesoftware.smackx.jingle_filetransfer.provider.JingleFileTransferContentDescriptionProvider;
import org.jivesoftware.smackx.jingle_ibb.JingleIBBTransportManager; import org.jivesoftware.smackx.jingle_s5b.JingleS5BTransportManager;
import org.jxmpp.jid.FullJid; import org.jxmpp.jid.FullJid;
/** /**
@ -88,8 +88,8 @@ public final class JingleFileTransferManager extends Manager implements JingleHa
NAMESPACE_V5, this); NAMESPACE_V5, this);
JingleContentProviderManager.addJingleContentDescriptionProvider( JingleContentProviderManager.addJingleContentDescriptionProvider(
NAMESPACE_V5, new JingleFileTransferContentDescriptionProvider()); NAMESPACE_V5, new JingleFileTransferContentDescriptionProvider());
JingleIBBTransportManager.getInstanceFor(connection); //JingleIBBTransportManager.getInstanceFor(connection);
//JingleS5BTransportManager.getInstanceFor(connection); JingleS5BTransportManager.getInstanceFor(connection);
} }
/** /**

View file

@ -1,19 +1,32 @@
package org.jivesoftware.smackx.jingle_s5b; package org.jivesoftware.smackx.jingle_s5b;
import java.io.IOException;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.net.Socket;
import java.util.ArrayList;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Client;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
import org.jivesoftware.smackx.jingle.JingleManager; import org.jivesoftware.smackx.jingle.JingleManager;
import org.jivesoftware.smackx.jingle.JingleSessionHandler; import org.jivesoftware.smackx.jingle.JingleSessionHandler;
import org.jivesoftware.smackx.jingle.JingleTransportEstablishedCallback; import org.jivesoftware.smackx.jingle.JingleTransportEstablishedCallback;
import org.jivesoftware.smackx.jingle.JingleTransportHandler; import org.jivesoftware.smackx.jingle.JingleTransportHandler;
import org.jivesoftware.smackx.jingle.element.JingleContentTransport; import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
import org.jivesoftware.smackx.jingle.element.JingleContentTransportCandidate;
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransport; import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransport;
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate;
/** /**
* JingleTransportHandler for Socks5Bytestreams. * JingleTransportHandler for Socks5Bytestreams.
*/ */
public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS5BTransport> { public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS5BTransport> {
private static final Logger LOGGER = Logger.getLogger(JingleS5BTransportHandler.class.getName());
private final WeakReference<JingleSessionHandler> sessionHandler; private final WeakReference<JingleSessionHandler> sessionHandler;
@ -27,11 +40,78 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
throw new IllegalArgumentException("Transport must be a JingleS5BTransport."); throw new IllegalArgumentException("Transport must be a JingleS5BTransport.");
} }
JingleS5BTransport transport = (JingleS5BTransport) hopefullyS5BTransport; JingleS5BTransport transport = (JingleS5BTransport) hopefullyS5BTransport;
ArrayList<Bytestream.StreamHost> streamHosts = new ArrayList<>();
for (JingleContentTransportCandidate c : transport.getCandidates()) {
streamHosts.add(((JingleS5BTransportCandidate) c).getStreamHost());
}
for (Bytestream.StreamHost streamHost : streamHosts) {
String address = streamHost.getAddress() + ":" + streamHost.getPort();
LOGGER.log(Level.INFO, "Connect outwards to " + address);
// establish socket
try {
// build SOCKS5 client
final Socks5Client socks5Client = new Socks5Client(streamHost, transport.getDestinationAddress());
// connect to SOCKS5 proxy with a timeout
Socket socket = socks5Client.getSocket(10 * 1000);
// set selected host
break;
}
catch (TimeoutException | IOException | SmackException | XMPPException e) {
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} }
@Override @Override
public void establishIncomingSession(JingleManager.FullJidAndSessionId target, JingleContentTransport transport, JingleTransportEstablishedCallback callback) { public void establishIncomingSession(JingleManager.FullJidAndSessionId target, JingleContentTransport hopefullyS5BTransport, JingleTransportEstablishedCallback callback) {
if (!hopefullyS5BTransport.getNamespace().equals(JingleS5BTransport.NAMESPACE_V1)) {
throw new IllegalArgumentException("Transport must be a JingleS5BTransport.");
}
JingleS5BTransport transport = (JingleS5BTransport) hopefullyS5BTransport;
ArrayList<Bytestream.StreamHost> streamHosts = new ArrayList<>();
for (JingleContentTransportCandidate c : transport.getCandidates()) { //TODO Sort
streamHosts.add(((JingleS5BTransportCandidate) c).getStreamHost());
}
for (Bytestream.StreamHost streamHost : streamHosts) {
String address = streamHost.getAddress() + ":" + streamHost.getPort();
LOGGER.log(Level.INFO, "Connect inwards to " + address);
// establish socket
try {
// build SOCKS5 client
final Socks5Client socks5Client = new Socks5Client(streamHost, transport.getDestinationAddress());
// connect to SOCKS5 proxy with a timeout
Socket socket = socks5Client.getSocket(10 * 1000);
// set selected host
break;
}
catch (TimeoutException | IOException | SmackException | XMPPException e) {
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} }
@Override @Override

View file

@ -66,7 +66,7 @@ public final class JingleS5BTransportManager extends AbstractJingleTransportMana
@Override @Override
public JingleS5BTransportHandler createJingleTransportHandler(JingleSessionHandler sessionHandler) { public JingleS5BTransportHandler createJingleTransportHandler(JingleSessionHandler sessionHandler) {
return null; return new JingleS5BTransportHandler(sessionHandler);
} }
@Override @Override
@ -140,9 +140,4 @@ public final class JingleS5BTransportManager extends AbstractJingleTransportMana
return streamHosts; return streamHosts;
} }
public void connectToStreamHost() {
}
} }

View file

@ -45,7 +45,7 @@ import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost;
* *
* @author Henning Staib * @author Henning Staib
*/ */
class Socks5Client { public class Socks5Client {
private static final Logger LOGGER = Logger.getLogger(Socks5Client.class.getName()); private static final Logger LOGGER = Logger.getLogger(Socks5Client.class.getName());