1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-23 20:42:06 +01:00
This commit is contained in:
vanitasvitae 2017-06-12 14:44:00 +02:00
parent d4deaa2517
commit 4feda2ffa9
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
9 changed files with 188 additions and 68 deletions

View file

@ -16,9 +16,12 @@
*/ */
package org.jivesoftware.smackx.jingle_filetransfer; package org.jivesoftware.smackx.jingle_filetransfer;
import java.util.ArrayList;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.jingle.JingleSessionHandler; import org.jivesoftware.smackx.jingle.JingleSessionHandler;
import org.jivesoftware.smackx.jingle.JingleTransportInfoListener;
import org.jivesoftware.smackx.jingle.element.Jingle; import org.jivesoftware.smackx.jingle.element.Jingle;
/** /**
@ -28,6 +31,7 @@ public abstract class AbstractJingleSession implements JingleSessionHandler {
protected final XMPPConnection connection; protected final XMPPConnection connection;
protected AbstractJingleSession state; protected AbstractJingleSession state;
protected final ArrayList<JingleTransportInfoListener> transportInfoListeners = new ArrayList<>();
public AbstractJingleSession(XMPPConnection connection) { public AbstractJingleSession(XMPPConnection connection) {
this.connection = connection; this.connection = connection;
@ -120,6 +124,9 @@ public abstract class AbstractJingleSession implements JingleSessionHandler {
} }
protected IQ handleTransportInfo(Jingle transportInfo) { protected IQ handleTransportInfo(Jingle transportInfo) {
for (JingleTransportInfoListener l : transportInfoListeners) {
l.onTransportInfoReceived(transportInfo);
}
return IQ.createResultIQ(transportInfo); return IQ.createResultIQ(transportInfo);
} }
@ -131,6 +138,16 @@ public abstract class AbstractJingleSession implements JingleSessionHandler {
return IQ.createResultIQ(transportReject); return IQ.createResultIQ(transportReject);
} }
@Override
public void addTransportInfoListener(JingleTransportInfoListener listener) {
transportInfoListeners.add(listener);
}
@Override
public void removeTransportInfoListener(JingleTransportInfoListener listener) {
transportInfoListeners.remove(listener);
}
@Override @Override
public XMPPConnection getConnection() { public XMPPConnection getConnection() {
return connection; return connection;

View file

@ -31,7 +31,7 @@ import org.jivesoftware.smackx.jingle_filetransfer.callback.JingleFileTransferCa
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild; import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
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;
/** /**
@ -48,8 +48,8 @@ public final class JingleFileTransferManager extends Manager implements JingleHa
super(connection); super(connection);
JingleContentProviderManager.addJingleContentDescriptionProvider(NAMESPACE_V5, new JingleFileTransferContentDescriptionProvider()); JingleContentProviderManager.addJingleContentDescriptionProvider(NAMESPACE_V5, new JingleFileTransferContentDescriptionProvider());
JingleManager.getInstanceFor(connection).registerDescriptionHandler(NAMESPACE_V5, this); JingleManager.getInstanceFor(connection).registerDescriptionHandler(NAMESPACE_V5, this);
JingleIBBTransportManager.getInstanceFor(connection); //JingleIBBTransportManager.getInstanceFor(connection);
//JingleS5BTransportManager.getInstanceFor(connection); JingleS5BTransportManager.getInstanceFor(connection);
} }
public static JingleFileTransferManager getInstanceFor(XMPPConnection connection) { public static JingleFileTransferManager getInstanceFor(XMPPConnection connection) {

View file

@ -59,7 +59,8 @@ public class JingleFileTransferSession extends AbstractJingleSession {
private final File source; private final File source;
private File target; private File target;
private final JingleContent proposedContent; private JingleContent proposedContent;
private JingleContent receivedContent;
private final FullJid remote; private final FullJid remote;
private final String sessionId; private final String sessionId;
@ -109,7 +110,7 @@ public class JingleFileTransferSession extends AbstractJingleSession {
this.sessionId = initiate.getSessionId(); this.sessionId = initiate.getSessionId();
this.remote = initiate.getInitiator(); this.remote = initiate.getInitiator();
this.source = null; this.source = null;
this.proposedContent = initiate.getContents().get(0); this.receivedContent = initiate.getContents().get(0);
this.state = new IncomingFresh(connection, this); this.state = new IncomingFresh(connection, this);
} }
@ -117,7 +118,7 @@ public class JingleFileTransferSession extends AbstractJingleSession {
/** /**
* session-initiate has been sent. * session-initiate has been sent.
*/ */
public static class OutgoingInitiated extends AbstractJingleSession { private static class OutgoingInitiated extends AbstractJingleSession {
private final JingleFileTransferSession parent; private final JingleFileTransferSession parent;
@ -128,6 +129,7 @@ public class JingleFileTransferSession extends AbstractJingleSession {
@Override @Override
protected IQ handleSessionAccept(Jingle jingle) { protected IQ handleSessionAccept(Jingle jingle) {
parent.receivedContent = jingle.getContents().get(0);
parent.state = new OutgoingAccepted(connection, parent); parent.state = new OutgoingAccepted(connection, parent);
//TODO: Notify parent //TODO: Notify parent
return IQ.createResultIQ(jingle); return IQ.createResultIQ(jingle);
@ -142,7 +144,7 @@ public class JingleFileTransferSession extends AbstractJingleSession {
} }
public static class OutgoingAccepted extends AbstractJingleSession { private static class OutgoingAccepted extends AbstractJingleSession {
private final JingleFileTransferSession parent; private final JingleFileTransferSession parent;
public OutgoingAccepted(XMPPConnection connection, final JingleFileTransferSession parent) { public OutgoingAccepted(XMPPConnection connection, final JingleFileTransferSession parent) {
@ -158,12 +160,14 @@ public class JingleFileTransferSession extends AbstractJingleSession {
} }
JingleTransportHandler<?> transportHandler = tm.createJingleTransportHandler(this); JingleTransportHandler<?> transportHandler = tm.createJingleTransportHandler(this);
transportHandler.establishOutgoingSession(parent.getFullJidAndSessionId(), transportHandler.prepareOutgoingSession(parent.getFullJidAndSessionId(), parent.proposedContent);
parent.addTransportInfoListener(transportHandler);
transportHandler.establishOutgoingSession(parent.getFullJidAndSessionId(), parent.receivedContent,
parent.proposedContent, parent.outgoingFileTransferSessionEstablishedCallback); parent.proposedContent, parent.outgoingFileTransferSessionEstablishedCallback);
} }
} }
public static class IncomingFresh extends AbstractJingleSession { private static class IncomingFresh extends AbstractJingleSession {
private final JingleFileTransferSession parent; private final JingleFileTransferSession parent;
public IncomingFresh(XMPPConnection connection, JingleFileTransferSession parent) { public IncomingFresh(XMPPConnection connection, JingleFileTransferSession parent) {
@ -177,8 +181,10 @@ public class JingleFileTransferSession extends AbstractJingleSession {
throw new IllegalArgumentException("Jingle action MUST be session-initiate!"); throw new IllegalArgumentException("Jingle action MUST be session-initiate!");
} }
parent.receivedContent = initiate.getContents().get(0);
//Get <file/> //Get <file/>
JingleFileTransferChild file = (JingleFileTransferChild) initiate.getContents().get(0) JingleFileTransferChild file = (JingleFileTransferChild) parent.receivedContent
.getDescription().getJingleContentDescriptionChildren().get(0); .getDescription().getJingleContentDescriptionChildren().get(0);
final JingleFileTransferCallback callback = new JingleFileTransferCallback() { final JingleFileTransferCallback callback = new JingleFileTransferCallback() {
@ -186,12 +192,13 @@ public class JingleFileTransferSession extends AbstractJingleSession {
public void acceptFileTransfer(File target) throws SmackException.NotConnectedException, InterruptedException { public void acceptFileTransfer(File target) throws SmackException.NotConnectedException, InterruptedException {
Jingle response = null; Jingle response = null;
try { try {
response = parent.createSessionAccept(initiate); response = parent.createSessionAccept();
} catch (Exception e) { } catch (Exception e) {
LOGGER.log(Level.WARNING, "Could not create accept-session stanza: " + e, e); LOGGER.log(Level.WARNING, "Could not create accept-session stanza: " + e, e);
} }
connection.sendStanza(response); connection.sendStanza(response);
parent.proposedContent = response.getContents().get(0);
parent.target = target; parent.target = target;
parent.state = new IncomingAccepted(connection, parent); parent.state = new IncomingAccepted(connection, parent);
} }
@ -210,7 +217,7 @@ public class JingleFileTransferSession extends AbstractJingleSession {
} }
} }
public static class IncomingAccepted extends AbstractJingleSession { private static class IncomingAccepted extends AbstractJingleSession {
public IncomingAccepted(XMPPConnection connection, JingleFileTransferSession parent) { public IncomingAccepted(XMPPConnection connection, JingleFileTransferSession parent) {
super(connection); super(connection);
@ -223,7 +230,8 @@ public class JingleFileTransferSession extends AbstractJingleSession {
} }
JingleTransportHandler<?> transportHandler = tm.createJingleTransportHandler(this); JingleTransportHandler<?> transportHandler = tm.createJingleTransportHandler(this);
transportHandler.establishIncomingSession(parent.getFullJidAndSessionId(), parent.addTransportInfoListener(transportHandler);
transportHandler.establishIncomingSession(parent.getFullJidAndSessionId(), parent.receivedContent,
parent.proposedContent, parent.incomingFileTransferSessionEstablishedCallback); parent.proposedContent, parent.incomingFileTransferSessionEstablishedCallback);
} }
} }
@ -252,8 +260,7 @@ public class JingleFileTransferSession extends AbstractJingleSession {
return jingle; return jingle;
} }
protected Jingle createSessionAccept(Jingle jingle) throws Exception { protected Jingle createSessionAccept() throws Exception {
JingleContent content = jingle.getContents().get(0);
Jingle.Builder jb = Jingle.getBuilder(); Jingle.Builder jb = Jingle.getBuilder();
jb.setAction(JingleAction.session_accept) jb.setAction(JingleAction.session_accept)
@ -265,16 +272,16 @@ public class JingleFileTransferSession extends AbstractJingleSession {
AbstractJingleTransportManager<?> tm; AbstractJingleTransportManager<?> tm;
try { try {
tm = JingleTransportManager.getJingleContentTransportManager( tm = JingleTransportManager.getJingleContentTransportManager(
connection, jingle); connection, receivedContent.getJingleTransports().get(0));
} catch (UnsupportedJingleTransportException e) { } catch (UnsupportedJingleTransportException e) {
throw new AssertionError("Should never happen."); //TODO: Make sure. throw new AssertionError("Should never happen."); //TODO: Make sure.
} }
cb.addTransport(tm.createJingleContentTransport(jingle)) cb.addTransport(tm.createJingleContentTransport(remote))
.setDescription(content.getDescription()) .setDescription(receivedContent.getDescription())
.setName(content.getName()) .setName(receivedContent.getName())
.setCreator(content.getCreator()) .setCreator(receivedContent.getCreator())
.setSenders(content.getSenders()); .setSenders(receivedContent.getSenders());
jb.addJingleContent(cb.build()); jb.addJingleContent(cb.build());
Jingle accept = jb.build(); Jingle accept = jb.build();

View file

@ -30,6 +30,7 @@ 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.Jingle;
import org.jivesoftware.smackx.jingle.element.JingleContent; import org.jivesoftware.smackx.jingle.element.JingleContent;
import org.jivesoftware.smackx.jingle.exception.JingleTransportFailureException; import org.jivesoftware.smackx.jingle.exception.JingleTransportFailureException;
import org.jivesoftware.smackx.jingle_ibb.element.JingleIBBTransport; import org.jivesoftware.smackx.jingle_ibb.element.JingleIBBTransport;
@ -45,9 +46,15 @@ public class JingleIBBTransportHandler implements JingleTransportHandler<JingleI
this.jingleSessionHandler = new WeakReference<>(sessionHandler); this.jingleSessionHandler = new WeakReference<>(sessionHandler);
} }
@Override
public void prepareOutgoingSession(JingleManager.FullJidAndSessionId fullJidAndSessionId, JingleContent content) {
// Nothing to do
}
@Override @Override
public void establishOutgoingSession(JingleManager.FullJidAndSessionId fullJidAndSessionId, public void establishOutgoingSession(JingleManager.FullJidAndSessionId fullJidAndSessionId,
JingleContent content, JingleContent receivedContent,
JingleContent proposedContent,
JingleTransportEstablishedCallback callback) { JingleTransportEstablishedCallback callback) {
InBandBytestreamSession session; InBandBytestreamSession session;
@ -64,7 +71,8 @@ public class JingleIBBTransportHandler implements JingleTransportHandler<JingleI
@Override @Override
public void establishIncomingSession(final JingleManager.FullJidAndSessionId fullJidAndSessionId, public void establishIncomingSession(final JingleManager.FullJidAndSessionId fullJidAndSessionId,
JingleContent content, JingleContent receivedContent,
JingleContent proposedContent,
final JingleTransportEstablishedCallback callback) { final JingleTransportEstablishedCallback callback) {
InBandBytestreamManager.getByteStreamManager(getConnection()).addIncomingBytestreamListener(new BytestreamListener() { InBandBytestreamManager.getByteStreamManager(getConnection()).addIncomingBytestreamListener(new BytestreamListener() {
@Override @Override
@ -91,4 +99,9 @@ public class JingleIBBTransportHandler implements JingleTransportHandler<JingleI
JingleSessionHandler sessionHandler = jingleSessionHandler.get(); JingleSessionHandler sessionHandler = jingleSessionHandler.get();
return sessionHandler != null ? sessionHandler.getConnection() : null; return sessionHandler != null ? sessionHandler.getConnection() : null;
} }
@Override
public void onTransportInfoReceived(Jingle transportInfo) {
}
} }

View file

@ -19,7 +19,6 @@ package org.jivesoftware.smackx.jingle_s5b;
import java.io.IOException; import java.io.IOException;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.net.Socket; import java.net.Socket;
import java.util.ArrayList;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -27,6 +26,7 @@ import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamSession;
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Client; import org.jivesoftware.smackx.bytestreams.socks5.Socks5Client;
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Proxy; import org.jivesoftware.smackx.bytestreams.socks5.Socks5Proxy;
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Utils; import org.jivesoftware.smackx.bytestreams.socks5.Socks5Utils;
@ -52,6 +52,8 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
private final WeakReference<JingleSessionHandler> sessionHandler; private final WeakReference<JingleSessionHandler> sessionHandler;
private JingleS5BTransport myTransport;
private JingleS5BTransportCandidate receivedCandidateUsed = null; private JingleS5BTransportCandidate receivedCandidateUsed = null;
private Socket connectedSocket = null; private Socket connectedSocket = null;
@ -60,11 +62,34 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
this.sessionHandler = new WeakReference<>(sessionHandler); this.sessionHandler = new WeakReference<>(sessionHandler);
} }
@Override
public void prepareOutgoingSession(JingleManager.FullJidAndSessionId fullJidAndSessionId, JingleContent content) {
myTransport = (JingleS5BTransport) content.getJingleTransports().get(0);
Socks5Proxy.getSocks5Proxy().addLocalAddress(myTransport.getDestinationAddress());
}
@Override @Override
public void establishOutgoingSession(JingleManager.FullJidAndSessionId fullJidAndSessionId, public void establishOutgoingSession(JingleManager.FullJidAndSessionId fullJidAndSessionId,
JingleContent content, JingleContent receivedContent,
JingleContent proposedContent,
JingleTransportEstablishedCallback callback) { JingleTransportEstablishedCallback callback) {
JingleContentTransport hopefullyS5BTransport = content.getJingleTransports().get(0); establishSession(fullJidAndSessionId, receivedContent, proposedContent, callback);
}
@Override
public void establishIncomingSession(JingleManager.FullJidAndSessionId fullJidAndSessionId,
JingleContent receivedContent,
JingleContent proposedContent,
JingleTransportEstablishedCallback callback) {
establishSession(fullJidAndSessionId, receivedContent, proposedContent, callback);
}
void establishSession(JingleManager.FullJidAndSessionId fullJidAndSessionId,
JingleContent receivedContent,
JingleContent proposedContent,
JingleTransportEstablishedCallback callback) {
JingleContentTransport hopefullyS5BTransport = receivedContent.getJingleTransports().get(0);
if (!hopefullyS5BTransport.getNamespace().equals(JingleS5BTransport.NAMESPACE_V1)) { if (!hopefullyS5BTransport.getNamespace().equals(JingleS5BTransport.NAMESPACE_V1)) {
throw new IllegalArgumentException("Transport must be a JingleS5BTransport."); throw new IllegalArgumentException("Transport must be a JingleS5BTransport.");
} }
@ -82,7 +107,7 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
Bytestream.StreamHost streamHost = usedCandidate.getStreamHost(); Bytestream.StreamHost streamHost = usedCandidate.getStreamHost();
String address = streamHost.getAddress() + ":" + streamHost.getPort(); String address = streamHost.getAddress() + ":" + streamHost.getPort();
LOGGER.log(Level.INFO, "Connect outwards to " + address); LOGGER.log(Level.INFO, "Connect to " + address);
// establish socket // establish socket
try { try {
@ -98,7 +123,7 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
} }
catch (TimeoutException | IOException | SmackException | XMPPException | InterruptedException e) { catch (TimeoutException | IOException | SmackException | XMPPException | InterruptedException e) {
LOGGER.log(Level.WARNING, "Could not connect outwards to " + address + ": " + e, e); LOGGER.log(Level.WARNING, "Could not connect to " + address + ": " + e, e);
} }
} }
@ -109,12 +134,13 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
.setInitiator(getConnection().getUser()); .setInitiator(getConnection().getUser());
JingleContent.Builder cb = JingleContent.getBuilder(); JingleContent.Builder cb = JingleContent.getBuilder();
cb.setName(content.getName()) cb.setName(receivedContent.getName())
.setCreator(content.getCreator()) .setCreator(receivedContent.getCreator())
.setSenders(content.getSenders()); .setSenders(receivedContent.getSenders());
JingleS5BTransport.Builder tb = JingleS5BTransport.getBuilder(); JingleS5BTransport.Builder tb = JingleS5BTransport.getBuilder();
tb.addTransportInfo(JingleS5BTransportInfo.CandidateUsed(usedCandidate.getCandidateId())); tb.setStreamId(((JingleS5BTransport) receivedContent.getJingleTransports().get(0)).getStreamId());
tb.setCandidateUsed(usedCandidate.getCandidateId());
cb.addTransport(tb.build()); cb.addTransport(tb.build());
jb.addJingleContent(cb.build()); jb.addJingleContent(cb.build());
@ -127,47 +153,48 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
} catch (SmackException.NotConnectedException | InterruptedException e) { } catch (SmackException.NotConnectedException | InterruptedException e) {
LOGGER.log(Level.WARNING, "Could not send candidate-used stanza: " + e, e); LOGGER.log(Level.WARNING, "Could not send candidate-used stanza: " + e, e);
} }
}
}
@Override //Activate proxy
public void establishIncomingSession(JingleManager.FullJidAndSessionId fullJidAndSessionId, if (usedCandidate.getType() == JingleS5BTransportCandidate.Type.proxy) {
JingleContent content, Bytestream bytestream = new Bytestream(fullJidAndSessionId.getSessionId());
JingleTransportEstablishedCallback callback) { bytestream.setToActivate(fullJidAndSessionId.getFullJid());
JingleContentTransport hopefullyS5BTransport = content.getJingleTransports().get(0); bytestream.setTo(usedCandidate.getJid());
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 { try {
getConnection().sendStanza(bytestream);
// build SOCKS5 client } catch (SmackException.NotConnectedException | InterruptedException e) {
final Socks5Client socks5Client = new Socks5Client(streamHost, transport.getDestinationAddress()); LOGGER.log(Level.WARNING, "Could not activate proxy: " + e, e);
// connect to SOCKS5 proxy with a timeout
Socket socket = socks5Client.getSocket(10 * 1000);
// set selected host
break;
} }
catch (TimeoutException | IOException | SmackException | XMPPException | InterruptedException e) {
LOGGER.log(Level.WARNING, "Could not connect inwards to " + address + ": " + e, e);
} }
jb = Jingle.getBuilder();
jb.setAction(JingleAction.transport_info)
.setSessionId(fullJidAndSessionId.getSessionId());
//TODO: setInitiator
cb = JingleContent.getBuilder();
cb.setCreator(JingleContent.Creator.initiator)
.setName(receivedContent.getName());
tb = JingleS5BTransport.getBuilder();
tb.setStreamId(((JingleS5BTransport) receivedContent.getJingleTransports().get(0)).getStreamId());
tb.setCandidateActivated(usedCandidate.getCandidateId());
cb.addTransport(tb.build());
jb.addJingleContent(cb.build());
Jingle activate = jb.build();
activate.setTo(fullJidAndSessionId.getFullJid());
activate.setFrom(getConnection().getUser());
try {
getConnection().sendStanza(activate);
} catch (SmackException.NotConnectedException | InterruptedException e) {
LOGGER.log(Level.SEVERE, "Could not send transport-activated: " + e, e);
}
callback.onSessionEstablished(new Socks5BytestreamSession(connectedSocket, false));
} else {
} }
} }
@ -180,4 +207,24 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
public void setReceivedCandidateUsed(JingleS5BTransportCandidate used) { public void setReceivedCandidateUsed(JingleS5BTransportCandidate used) {
this.receivedCandidateUsed = used; this.receivedCandidateUsed = used;
} }
@Override
public void onTransportInfoReceived(Jingle jingle) {
if (jingle.getAction() != JingleAction.transport_info) {
throw new IllegalArgumentException("Jingle Action must be transport-info.");
}
JingleContentTransport jingleTransport = jingle.getContents().get(0).getJingleTransports().get(0);
if (jingleTransport == null || !jingleTransport.getNamespace().equals(JingleS5BTransport.NAMESPACE_V1)) {
throw new IllegalArgumentException("Jingle must contain transport of type S5B.");
}
JingleS5BTransport transport = (JingleS5BTransport) jingleTransport;
JingleS5BTransportInfo info = (JingleS5BTransportInfo) transport.getInfos().get(0);
if (info == null) {
throw new IllegalArgumentException("Jingle must contain at least one JingleS5BTransportInfo.");
}
if (info.getElementName().equals(JingleS5BTransportInfo.CandidateUsed.ELEMENT)) {
String candidateUsedId = ((JingleS5BTransportInfo.CandidateUsed) info).getCandidateId();
}
}
} }

View file

@ -37,7 +37,7 @@ public class Socks5BytestreamSession implements BytestreamSession {
/* flag to indicate if this session is a direct or mediated connection */ /* flag to indicate if this session is a direct or mediated connection */
private final boolean isDirect; private final boolean isDirect;
protected Socks5BytestreamSession(Socket socket, boolean isDirect) { public Socks5BytestreamSession(Socket socket, boolean isDirect) {
this.socket = socket; this.socket = socket;
this.isDirect = isDirect; this.isDirect = isDirect;
} }

View file

@ -26,4 +26,8 @@ public interface JingleSessionHandler {
XMPPConnection getConnection(); XMPPConnection getConnection();
void addTransportInfoListener(JingleTransportInfoListener listener);
void removeTransportInfoListener(JingleTransportInfoListener listener);
} }

View file

@ -23,14 +23,19 @@ import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
/** /**
* Handler for JingleTransports. * Handler for JingleTransports.
*/ */
public interface JingleTransportHandler<D extends JingleContentTransport> { public interface JingleTransportHandler<D extends JingleContentTransport> extends JingleTransportInfoListener {
void prepareOutgoingSession(JingleManager.FullJidAndSessionId fullJidAndSessionId,
JingleContent content);
void establishOutgoingSession(JingleManager.FullJidAndSessionId fullJidAndSessionId, void establishOutgoingSession(JingleManager.FullJidAndSessionId fullJidAndSessionId,
JingleContent content, JingleContent receivedContent,
JingleContent proposedContent,
JingleTransportEstablishedCallback callback); JingleTransportEstablishedCallback callback);
void establishIncomingSession(JingleManager.FullJidAndSessionId fullJidAndSessionId, void establishIncomingSession(JingleManager.FullJidAndSessionId fullJidAndSessionId,
JingleContent content, JingleContent receivedContent,
JingleContent proposedContent,
JingleTransportEstablishedCallback callback); JingleTransportEstablishedCallback callback);
XMPPConnection getConnection(); XMPPConnection getConnection();

View file

@ -0,0 +1,27 @@
/**
*
* Copyright © 2017 Paul Schaub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle;
import org.jivesoftware.smackx.jingle.element.Jingle;
/**
* Listener for transport-info Jingle stanzas.
*/
public interface JingleTransportInfoListener {
void onTransportInfoReceived(Jingle transportInfo);
}