mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-27 14:32:06 +01:00
Towards S5B!
This commit is contained in:
parent
e5edb4cd04
commit
a4454aa8b5
4 changed files with 86 additions and 11 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue