mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 20:42:06 +01:00
Temp
This commit is contained in:
parent
38f54b140c
commit
4728aa4452
13 changed files with 300 additions and 173 deletions
|
@ -28,15 +28,18 @@ 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.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
|
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
import org.jivesoftware.smackx.jingle.AbstractJingleTransportManager;
|
import org.jivesoftware.smackx.jingle.AbstractJingleTransportManager;
|
||||||
import org.jivesoftware.smackx.jingle.JingleContentProviderManager;
|
import org.jivesoftware.smackx.jingle.JingleContentProviderManager;
|
||||||
import org.jivesoftware.smackx.jingle.JingleHandler;
|
import org.jivesoftware.smackx.jingle.JingleHandler;
|
||||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleTransportEstablishedCallback;
|
||||||
import org.jivesoftware.smackx.jingle.JingleTransportManager;
|
import org.jivesoftware.smackx.jingle.JingleTransportManager;
|
||||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
|
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
|
||||||
|
import org.jivesoftware.smackx.jingle.exception.JingleTransportFailureException;
|
||||||
import org.jivesoftware.smackx.jingle.exception.UnsupportedJingleTransportException;
|
import org.jivesoftware.smackx.jingle.exception.UnsupportedJingleTransportException;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.callback.JingleFileTransferCallback;
|
import org.jivesoftware.smackx.jingle_filetransfer.callback.JingleFileTransferCallback;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
|
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
|
||||||
|
@ -172,10 +175,31 @@ public final class JingleFileTransferManager extends Manager implements JingleHa
|
||||||
@Override
|
@Override
|
||||||
public void accept(File target) throws SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException, UnsupportedJingleTransportException, SmackException.NoResponseException {
|
public void accept(File target) throws SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException, UnsupportedJingleTransportException, SmackException.NoResponseException {
|
||||||
connection().sendStanza(finalTransportManager.createSessionAccept(jingle));
|
connection().sendStanza(finalTransportManager.createSessionAccept(jingle));
|
||||||
ResponderIncomingFileTransferAccepted responded = new ResponderIncomingFileTransferAccepted(JingleFileTransferManager.this, jingle, target);
|
|
||||||
|
JingleManager.FullJidAndSessionId fullJidAndSessionId =
|
||||||
|
new JingleManager.FullJidAndSessionId(
|
||||||
|
jingle.getFrom().asFullJidIfPossible(), jingle.getSid());
|
||||||
|
|
||||||
|
|
||||||
|
ResponderIncomingFileTransferAccepted responded = new ResponderIncomingFileTransferAccepted(
|
||||||
|
JingleFileTransferManager.this, jingle, target);
|
||||||
|
|
||||||
jingleManager.registerJingleSessionHandler(jingle.getFrom().asFullJidIfPossible(), jingle.getSid(),
|
jingleManager.registerJingleSessionHandler(jingle.getFrom().asFullJidIfPossible(), jingle.getSid(),
|
||||||
responded);
|
responded);
|
||||||
finalTransportManager.setIncomingRespondedSessionListener(jingle, responded);
|
|
||||||
|
finalTransportManager.createJingleTransportHandler(responded).establishIncomingSession(fullJidAndSessionId,
|
||||||
|
jingle.getContents().get(0).getJingleTransports().get(0),
|
||||||
|
new JingleTransportEstablishedCallback() {
|
||||||
|
@Override
|
||||||
|
public void onSessionEstablished(BytestreamSession bytestreamSession) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSessionFailure(JingleTransportFailureException reason) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -20,6 +20,7 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||||
import org.jivesoftware.smackx.hashes.HashManager;
|
import org.jivesoftware.smackx.hashes.HashManager;
|
||||||
|
@ -49,10 +50,10 @@ public class InitiatorOutgoingFileTransferInitiated implements JingleSessionHand
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IQ handleJingleSessionRequest(Jingle jingle, String sessionId) {
|
public IQ handleJingleSessionRequest(final Jingle jingle, String sessionId) {
|
||||||
AbstractJingleTransportManager<?> bm;
|
final AbstractJingleTransportManager<?> bm;
|
||||||
try {
|
try {
|
||||||
bm = JingleTransportManager.getInstanceFor(manager.get().getConnection())
|
bm = JingleTransportManager.getInstanceFor(getConnection())
|
||||||
.getJingleContentTransportManager(jingle);
|
.getJingleContentTransportManager(jingle);
|
||||||
} catch (UnsupportedJingleTransportException e) {
|
} catch (UnsupportedJingleTransportException e) {
|
||||||
// TODO
|
// TODO
|
||||||
|
@ -61,7 +62,15 @@ public class InitiatorOutgoingFileTransferInitiated implements JingleSessionHand
|
||||||
|
|
||||||
switch (jingle.getAction()) {
|
switch (jingle.getAction()) {
|
||||||
case session_accept:
|
case session_accept:
|
||||||
startTransfer(bm, jingle);
|
|
||||||
|
Runnable transfer = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
startTransfer(bm, jingle);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
transfer.run();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case session_terminate:
|
case session_terminate:
|
||||||
break;
|
break;
|
||||||
|
@ -72,6 +81,12 @@ public class InitiatorOutgoingFileTransferInitiated implements JingleSessionHand
|
||||||
return IQ.createResultIQ(jingle);
|
return IQ.createResultIQ(jingle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public XMPPConnection getConnection() {
|
||||||
|
JingleFileTransferManager m = manager.get();
|
||||||
|
return m != null ? m.getConnection() : null;
|
||||||
|
}
|
||||||
|
|
||||||
public void startTransfer(AbstractJingleTransportManager<?> transportManager, Jingle jingle) {
|
public void startTransfer(AbstractJingleTransportManager<?> transportManager, Jingle jingle) {
|
||||||
BytestreamSession session;
|
BytestreamSession session;
|
||||||
|
|
||||||
|
|
|
@ -30,9 +30,11 @@ import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smackx.bytestreams.BytestreamListener;
|
import org.jivesoftware.smackx.bytestreams.BytestreamListener;
|
||||||
import org.jivesoftware.smackx.bytestreams.BytestreamRequest;
|
import org.jivesoftware.smackx.bytestreams.BytestreamRequest;
|
||||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||||
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager;
|
import org.jivesoftware.smackx.jingle.AbstractJingleTransportManager;
|
||||||
import org.jivesoftware.smackx.jingle.JingleSessionHandler;
|
import org.jivesoftware.smackx.jingle.JingleSessionHandler;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleTransportManager;
|
||||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||||
|
import org.jivesoftware.smackx.jingle.exception.UnsupportedJingleTransportException;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.JingleFileTransferManager;
|
import org.jivesoftware.smackx.jingle_filetransfer.JingleFileTransferManager;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
|
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
|
||||||
import org.jxmpp.jid.FullJid;
|
import org.jxmpp.jid.FullJid;
|
||||||
|
@ -45,6 +47,7 @@ public class ResponderIncomingFileTransferAccepted implements JingleSessionHandl
|
||||||
private static final Logger LOGGER = Logger.getLogger(ResponderIncomingFileTransferAccepted.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(ResponderIncomingFileTransferAccepted.class.getName());
|
||||||
|
|
||||||
private final WeakReference<JingleFileTransferManager> manager;
|
private final WeakReference<JingleFileTransferManager> manager;
|
||||||
|
private AbstractJingleTransportManager<?> transportManager;
|
||||||
private final File target;
|
private final File target;
|
||||||
private final int size;
|
private final int size;
|
||||||
private final FullJid initiator;
|
private final FullJid initiator;
|
||||||
|
@ -55,6 +58,11 @@ public class ResponderIncomingFileTransferAccepted implements JingleSessionHandl
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.size = ((JingleFileTransferChild) initiate.getContents().get(0).getDescription()
|
this.size = ((JingleFileTransferChild) initiate.getContents().get(0).getDescription()
|
||||||
.getJingleContentDescriptionChildren().get(0)).getSize();
|
.getJingleContentDescriptionChildren().get(0)).getSize();
|
||||||
|
try {
|
||||||
|
this.transportManager = JingleTransportManager.getInstanceFor(manager.getConnection()).getJingleContentTransportManager(initiate);
|
||||||
|
} catch (UnsupportedJingleTransportException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
this.initiator = initiate.getInitiator();
|
this.initiator = initiate.getInitiator();
|
||||||
this.sessionId = initiate.getSid();
|
this.sessionId = initiate.getSid();
|
||||||
}
|
}
|
||||||
|
@ -110,7 +118,7 @@ public class ResponderIncomingFileTransferAccepted implements JingleSessionHandl
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.log(Level.SEVERE, "Caught Exception while closing streams: " + e, e);
|
LOGGER.log(Level.SEVERE, "Caught Exception while closing streams: " + e, e);
|
||||||
}
|
}
|
||||||
InBandBytestreamManager.getByteStreamManager(manager.get().getConnection()).removeIncomingBytestreamListener(this);
|
transportManager.removeIncomingRespondedSessionListener(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
package org.jivesoftware.smackx.jingle_ibb;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.SmackException;
|
||||||
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
|
import org.jivesoftware.smack.XMPPException;
|
||||||
|
import org.jivesoftware.smackx.bytestreams.BytestreamListener;
|
||||||
|
import org.jivesoftware.smackx.bytestreams.BytestreamRequest;
|
||||||
|
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||||
|
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager;
|
||||||
|
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamSession;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleSessionHandler;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleTransportEstablishedCallback;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleTransportHandler;
|
||||||
|
import org.jivesoftware.smackx.jingle.exception.JingleTransportFailureException;
|
||||||
|
import org.jivesoftware.smackx.jingle_ibb.element.JingleIBBTransport;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JingleTransportHandler for InBandBytestreams.
|
||||||
|
*/
|
||||||
|
public class JingleIBBTransportHandler implements JingleTransportHandler<JingleIBBTransport> {
|
||||||
|
|
||||||
|
private final WeakReference<JingleSessionHandler> jingleSessionHandler;
|
||||||
|
|
||||||
|
public JingleIBBTransportHandler(JingleSessionHandler sessionHandler) {
|
||||||
|
this.jingleSessionHandler = new WeakReference<>(sessionHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void establishOutgoingSession(JingleManager.FullJidAndSessionId target, JingleIBBTransport transport, JingleTransportEstablishedCallback callback) {
|
||||||
|
InBandBytestreamSession session;
|
||||||
|
|
||||||
|
try {
|
||||||
|
session = InBandBytestreamManager.getByteStreamManager(getConnection())
|
||||||
|
.establishSession(target.getFullJid(), target.getSessionId());
|
||||||
|
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException e) {
|
||||||
|
callback.onSessionFailure(new JingleTransportFailureException(e));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
callback.onSessionEstablished(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void establishIncomingSession(final JingleManager.FullJidAndSessionId target, JingleIBBTransport transport, final JingleTransportEstablishedCallback callback) {
|
||||||
|
InBandBytestreamManager.getByteStreamManager(getConnection()).addIncomingBytestreamListener(new BytestreamListener() {
|
||||||
|
@Override
|
||||||
|
public void incomingBytestreamRequest(BytestreamRequest request) {
|
||||||
|
if (request.getFrom().asFullJidIfPossible().equals(target.getFullJid())
|
||||||
|
&& request.getSessionID().equals(target.getSessionId())) {
|
||||||
|
BytestreamSession session;
|
||||||
|
|
||||||
|
try {
|
||||||
|
session = request.accept();
|
||||||
|
} catch (InterruptedException | SmackException | XMPPException.XMPPErrorException e) {
|
||||||
|
callback.onSessionFailure(new JingleTransportFailureException(e));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback.onSessionEstablished(session);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public XMPPConnection getConnection() {
|
||||||
|
JingleSessionHandler sessionHandler = jingleSessionHandler.get();
|
||||||
|
return sessionHandler != null ? sessionHandler.getConnection() : null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,26 +16,17 @@
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.jingle_ibb;
|
package org.jivesoftware.smackx.jingle_ibb;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
import org.jivesoftware.smack.SmackException;
|
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
|
||||||
import org.jivesoftware.smackx.bytestreams.BytestreamListener;
|
|
||||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
|
||||||
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager;
|
|
||||||
import org.jivesoftware.smackx.jingle.AbstractJingleTransportManager;
|
import org.jivesoftware.smackx.jingle.AbstractJingleTransportManager;
|
||||||
import org.jivesoftware.smackx.jingle.JingleTransportManager;
|
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleSessionHandler;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleTransportHandler;
|
||||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescription;
|
|
||||||
import org.jivesoftware.smackx.jingle.provider.JingleContentTransportProvider;
|
import org.jivesoftware.smackx.jingle.provider.JingleContentTransportProvider;
|
||||||
import org.jivesoftware.smackx.jingle_ibb.element.JingleIBBTransport;
|
import org.jivesoftware.smackx.jingle_ibb.element.JingleIBBTransport;
|
||||||
import org.jivesoftware.smackx.jingle_ibb.provider.JingleIBBTransportProvider;
|
import org.jivesoftware.smackx.jingle_ibb.provider.JingleIBBTransportProvider;
|
||||||
import org.jxmpp.jid.FullJid;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BytestreamManager for Jingle InBandBytestream Transports.
|
* BytestreamManager for Jingle InBandBytestream Transports.
|
||||||
|
@ -58,10 +49,34 @@ public final class JingleIBBTransportManager extends AbstractJingleTransportMana
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Jingle createSessionInitiate(FullJid targetJID, JingleContentDescription application) throws XMPPException, IOException, InterruptedException, SmackException {
|
public JingleTransportHandler<JingleIBBTransport> createJingleTransportHandler(JingleSessionHandler sessionHandler) {
|
||||||
return createSessionInitiate(targetJID, application, JingleTransportManager.generateRandomId());
|
return new JingleIBBTransportHandler(sessionHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JingleIBBTransport createJingleContentTransport(JingleManager.FullJidAndSessionId target) {
|
||||||
|
return new JingleIBBTransport(target.getSessionId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JingleIBBTransport createJingleContentTransport(Jingle remotesRequest) throws Exception {
|
||||||
|
JingleIBBTransport remotesTransport = (JingleIBBTransport) remotesRequest.getContents().get(0)
|
||||||
|
.getJingleTransports().get(0);
|
||||||
|
return new JingleIBBTransport(remotesTransport.getBlockSize(), remotesTransport.getSessionId());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JingleContentTransportProvider<JingleIBBTransport> createJingleContentTransportProvider() {
|
||||||
|
return new JingleIBBTransportProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNamespace() {
|
||||||
|
return JingleIBBTransport.NAMESPACE_V1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
@Override
|
@Override
|
||||||
public Jingle createSessionInitiate(FullJid targetJID, JingleContentDescription application, String sessionID) throws XMPPException, IOException, InterruptedException, SmackException {
|
public Jingle createSessionInitiate(FullJid targetJID, JingleContentDescription application, String sessionID) throws XMPPException, IOException, InterruptedException, SmackException {
|
||||||
Jingle.Builder jb = Jingle.getBuilder();
|
Jingle.Builder jb = Jingle.getBuilder();
|
||||||
|
@ -105,28 +120,6 @@ public final class JingleIBBTransportManager extends AbstractJingleTransportMana
|
||||||
jingle.setFrom(connection().getUser());
|
jingle.setFrom(connection().getUser());
|
||||||
return jingle;
|
return jingle;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
@Override
|
|
||||||
public BytestreamSession outgoingInitiatedSession(Jingle jingle) throws Exception {
|
|
||||||
InBandBytestreamManager ibb = InBandBytestreamManager.getByteStreamManager(connection());
|
|
||||||
return ibb.establishSession(jingle.getResponder(), jingle.getSid());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setIncomingRespondedSessionListener(Jingle jingle, BytestreamListener listener) {
|
|
||||||
InBandBytestreamManager.getByteStreamManager(connection()).addIncomingBytestreamListener(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
//###############################################
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected JingleContentTransportProvider<JingleIBBTransport> createJingleContentTransportProvider() {
|
|
||||||
return new JingleIBBTransportProvider();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getNamespace() {
|
|
||||||
return JingleIBBTransport.NAMESPACE_V1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,10 @@ public class JingleIBBTransport extends JingleContentTransport {
|
||||||
this(DEFAULT_BLOCK_SIZE);
|
this(DEFAULT_BLOCK_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JingleIBBTransport(String sid) {
|
||||||
|
this(DEFAULT_BLOCK_SIZE, sid);
|
||||||
|
}
|
||||||
|
|
||||||
public JingleIBBTransport(short blockSize) {
|
public JingleIBBTransport(short blockSize) {
|
||||||
this(blockSize, JingleTransportManager.generateRandomId());
|
this(blockSize, JingleTransportManager.generateRandomId());
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package org.jivesoftware.smackx.jingle_s5b;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleSessionHandler;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleTransportEstablishedCallback;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleTransportHandler;
|
||||||
|
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransport;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JingleTransportHandler for Socks5Bytestreams.
|
||||||
|
*/
|
||||||
|
public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS5BTransport> {
|
||||||
|
|
||||||
|
private final WeakReference<JingleSessionHandler> sessionHandler;
|
||||||
|
|
||||||
|
public JingleS5BTransportHandler(JingleSessionHandler sessionHandler) {
|
||||||
|
this.sessionHandler = new WeakReference<>(sessionHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void establishOutgoingSession(JingleManager.FullJidAndSessionId target, JingleS5BTransport transport, JingleTransportEstablishedCallback callback) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void establishIncomingSession(JingleManager.FullJidAndSessionId target, JingleS5BTransport transport, JingleTransportEstablishedCallback callback) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public XMPPConnection getConnection() {
|
||||||
|
JingleSessionHandler handler = sessionHandler.get();
|
||||||
|
return handler != null ? handler.getConnection() : null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,7 +16,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.jingle_s5b;
|
package org.jivesoftware.smackx.jingle_s5b;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -26,18 +25,14 @@ 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.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smackx.bytestreams.BytestreamListener;
|
|
||||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
|
||||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager;
|
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager;
|
||||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Utils;
|
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Utils;
|
||||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||||
import org.jivesoftware.smackx.jingle.AbstractJingleTransportManager;
|
import org.jivesoftware.smackx.jingle.AbstractJingleTransportManager;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleSessionHandler;
|
||||||
import org.jivesoftware.smackx.jingle.JingleTransportManager;
|
import org.jivesoftware.smackx.jingle.JingleTransportManager;
|
||||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescription;
|
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
|
|
||||||
import org.jivesoftware.smackx.jingle.provider.JingleContentTransportProvider;
|
import org.jivesoftware.smackx.jingle.provider.JingleContentTransportProvider;
|
||||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransport;
|
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransport;
|
||||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate;
|
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate;
|
||||||
|
@ -65,6 +60,55 @@ public final class JingleS5BTransportManager extends AbstractJingleTransportMana
|
||||||
return manager;
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JingleContentTransportProvider<JingleS5BTransport> createJingleContentTransportProvider() {
|
||||||
|
return new JingleS5BTransportProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JingleS5BTransportHandler createJingleTransportHandler(JingleSessionHandler sessionHandler) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JingleS5BTransport createJingleContentTransport(JingleManager.FullJidAndSessionId target) throws Exception {
|
||||||
|
return createJingleContentTransport(target.getFullJid(), JingleTransportManager.generateRandomId(), Bytestream.Mode.tcp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JingleS5BTransport createJingleContentTransport(Jingle jingle) throws Exception {
|
||||||
|
FullJid remote = jingle.getFrom().asFullJidIfPossible();
|
||||||
|
JingleS5BTransport received = (JingleS5BTransport) jingle.getContents().get(0).getJingleTransports().get(0);
|
||||||
|
|
||||||
|
return createJingleContentTransport(remote, received.getStreamId(), received.getMode());
|
||||||
|
}
|
||||||
|
|
||||||
|
private JingleS5BTransport createJingleContentTransport(FullJid remote, String sid, Bytestream.Mode mode) throws Exception {
|
||||||
|
JingleS5BTransport.Builder builder = JingleS5BTransport.getBuilder();
|
||||||
|
List<Bytestream.StreamHost> localStreams = getLocalStreamHosts();
|
||||||
|
List<Bytestream.StreamHost> availableStreams = getAvailableStreamHosts();
|
||||||
|
|
||||||
|
for (Bytestream.StreamHost host : localStreams) {
|
||||||
|
JingleS5BTransportCandidate candidate = new JingleS5BTransportCandidate(host, 100);
|
||||||
|
builder.addTransportCandidate(candidate);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Bytestream.StreamHost host : availableStreams) {
|
||||||
|
JingleS5BTransportCandidate candidate = new JingleS5BTransportCandidate(host, 0);
|
||||||
|
builder.addTransportCandidate(candidate);
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.setStreamId(sid);
|
||||||
|
builder.setMode(mode);
|
||||||
|
builder.setDestinationAddress(Socks5Utils.createDigest(sid, connection().getUser(), remote));
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNamespace() {
|
||||||
|
return JingleS5BTransport.NAMESPACE_V1;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Bytestream.StreamHost> getAvailableStreamHosts() throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
public List<Bytestream.StreamHost> getAvailableStreamHosts() throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
||||||
Socks5BytestreamManager s5m = Socks5BytestreamManager.getBytestreamManager(connection());
|
Socks5BytestreamManager s5m = Socks5BytestreamManager.getBytestreamManager(connection());
|
||||||
List<Jid> proxies = s5m.determineProxies();
|
List<Jid> proxies = s5m.determineProxies();
|
||||||
|
@ -102,104 +146,4 @@ public final class JingleS5BTransportManager extends AbstractJingleTransportMana
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected JingleContentTransportProvider<JingleS5BTransport> createJingleContentTransportProvider() {
|
|
||||||
return new JingleS5BTransportProvider();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getNamespace() {
|
|
||||||
return JingleS5BTransport.NAMESPACE_V1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Jingle createSessionInitiate(FullJid targetJID, JingleContentDescription application, String sessionId)
|
|
||||||
throws XMPPException, IOException, InterruptedException, SmackException {
|
|
||||||
Jingle.Builder jb = Jingle.getBuilder();
|
|
||||||
jb.setAction(JingleAction.session_initiate)
|
|
||||||
.setInitiator(connection().getUser())
|
|
||||||
.setSessionId(sessionId);
|
|
||||||
|
|
||||||
JingleContent.Builder cb = JingleContent.getBuilder();
|
|
||||||
cb.addTransport(createJingleContentTransport(targetJID, null))
|
|
||||||
.setSenders(JingleContent.Senders.initiator)
|
|
||||||
.setName(JingleTransportManager.generateRandomId())
|
|
||||||
.setCreator(JingleContent.Creator.initiator)
|
|
||||||
.setDescription(application);
|
|
||||||
jb.addJingleContent(cb.build());
|
|
||||||
|
|
||||||
Jingle jingle = jb.build();
|
|
||||||
jingle.setTo(targetJID);
|
|
||||||
jingle.setFrom(connection().getUser());
|
|
||||||
jingle.setType(IQ.Type.set);
|
|
||||||
return jingle;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Jingle createSessionAccept(Jingle request)
|
|
||||||
throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
|
||||||
JingleContent receivedContent = request.getContents().get(0);
|
|
||||||
JingleS5BTransport receivedTransport = (JingleS5BTransport) receivedContent.getJingleTransports().get(0);
|
|
||||||
Jingle.Builder jb = Jingle.getBuilder();
|
|
||||||
jb.setResponder(connection().getUser())
|
|
||||||
.setAction(JingleAction.session_accept)
|
|
||||||
.setSessionId(request.getSid());
|
|
||||||
|
|
||||||
JingleContent.Builder cb = JingleContent.getBuilder();
|
|
||||||
cb.setSenders(receivedContent.getSenders())
|
|
||||||
.setCreator(receivedContent.getCreator())
|
|
||||||
.setName(receivedContent.getName())
|
|
||||||
.setDescription(receivedContent.getDescription())
|
|
||||||
.addTransport(createJingleContentTransport(request.getInitiator(), receivedTransport));
|
|
||||||
jb.addJingleContent(cb.build());
|
|
||||||
|
|
||||||
Jingle jingle = jb.build();
|
|
||||||
jingle.setTo(request.getFrom());
|
|
||||||
jingle.setFrom(connection().getUser());
|
|
||||||
jingle.setType(IQ.Type.set);
|
|
||||||
return jingle;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BytestreamSession outgoingInitiatedSession(Jingle jingle) throws Exception {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setIncomingRespondedSessionListener(Jingle jingle, BytestreamListener listener) {
|
|
||||||
Socks5BytestreamManager.getBytestreamManager(connection()).addIncomingBytestreamListener(listener, jingle.getInitiator());
|
|
||||||
}
|
|
||||||
|
|
||||||
public JingleS5BTransport createJingleContentTransport(Jid remote, JingleContentTransport received_) throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
|
||||||
JingleS5BTransport received = (JingleS5BTransport) received_;
|
|
||||||
|
|
||||||
JingleS5BTransport.Builder builder = JingleS5BTransport.getBuilder();
|
|
||||||
List<Bytestream.StreamHost> localStreams = getLocalStreamHosts();
|
|
||||||
List<Bytestream.StreamHost> availableStreams = getAvailableStreamHosts();
|
|
||||||
|
|
||||||
for (Bytestream.StreamHost host : localStreams) {
|
|
||||||
JingleS5BTransportCandidate candidate = new JingleS5BTransportCandidate(host, 100);
|
|
||||||
builder.addTransportCandidate(candidate);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Bytestream.StreamHost host : availableStreams) {
|
|
||||||
JingleS5BTransportCandidate candidate = new JingleS5BTransportCandidate(host, 0);
|
|
||||||
builder.addTransportCandidate(candidate);
|
|
||||||
}
|
|
||||||
|
|
||||||
String sid = (received == null ? JingleTransportManager.generateRandomId() : received.getStreamId());
|
|
||||||
builder.setStreamId(sid);
|
|
||||||
builder.setMode(received == null ? Bytestream.Mode.tcp : received.getMode());
|
|
||||||
builder.setDestinationAddress(Socks5Utils.createDigest(sid, connection().getUser(), remote));
|
|
||||||
return builder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Session {
|
|
||||||
private ArrayList<Bytestream.StreamHost> ourStreamHosts;
|
|
||||||
private ArrayList<Bytestream.StreamHost> theirStreamHosts;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,20 +16,12 @@
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.jingle;
|
package org.jivesoftware.smackx.jingle;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.jivesoftware.smack.Manager;
|
import org.jivesoftware.smack.Manager;
|
||||||
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.BytestreamListener;
|
|
||||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
|
||||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescription;
|
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
|
import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
|
||||||
import org.jivesoftware.smackx.jingle.provider.JingleContentTransportProvider;
|
import org.jivesoftware.smackx.jingle.provider.JingleContentTransportProvider;
|
||||||
import org.jxmpp.jid.FullJid;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class defines the shape that JingleTransportManager must be of.
|
* This class defines the shape that JingleTransportManager must be of.
|
||||||
|
@ -46,18 +38,11 @@ public abstract class AbstractJingleTransportManager<D extends JingleContentTran
|
||||||
|
|
||||||
protected abstract JingleContentTransportProvider<D> createJingleContentTransportProvider();
|
protected abstract JingleContentTransportProvider<D> createJingleContentTransportProvider();
|
||||||
|
|
||||||
|
public abstract JingleTransportHandler<D> createJingleTransportHandler(JingleSessionHandler sessionHandler);
|
||||||
|
|
||||||
|
public abstract D createJingleContentTransport(JingleManager.FullJidAndSessionId target) throws Exception;
|
||||||
|
|
||||||
|
public abstract D createJingleContentTransport(Jingle remotesRequest) throws Exception;
|
||||||
|
|
||||||
public abstract String getNamespace();
|
public abstract String getNamespace();
|
||||||
|
|
||||||
public Jingle createSessionInitiate(FullJid targetJID, JingleContentDescription application) throws XMPPException, IOException, InterruptedException, SmackException {
|
|
||||||
return createSessionInitiate(targetJID, application, JingleTransportManager.generateRandomId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract Jingle createSessionInitiate(FullJid targetJID, JingleContentDescription application, String sessionId) throws XMPPException, IOException, InterruptedException, SmackException;
|
|
||||||
|
|
||||||
public abstract Jingle createSessionAccept(Jingle request) throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException;
|
|
||||||
|
|
||||||
public abstract BytestreamSession outgoingInitiatedSession(Jingle jingle) throws Exception;
|
|
||||||
|
|
||||||
public abstract void setIncomingRespondedSessionListener(Jingle jingle, BytestreamListener listener);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.jingle;
|
package org.jivesoftware.smackx.jingle;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||||
|
|
||||||
|
@ -23,4 +24,6 @@ public interface JingleSessionHandler {
|
||||||
|
|
||||||
IQ handleJingleSessionRequest(Jingle jingle, String sessionId);
|
IQ handleJingleSessionRequest(Jingle jingle, String sessionId);
|
||||||
|
|
||||||
|
XMPPConnection getConnection();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package org.jivesoftware.smackx.jingle;
|
||||||
|
|
||||||
|
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||||
|
import org.jivesoftware.smackx.jingle.exception.JingleTransportFailureException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by vanitas on 10.06.17.
|
||||||
|
*/
|
||||||
|
public interface JingleTransportEstablishedCallback {
|
||||||
|
void onSessionEstablished(BytestreamSession bytestreamSession);
|
||||||
|
|
||||||
|
void onSessionFailure(JingleTransportFailureException reason);
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package org.jivesoftware.smackx.jingle;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
|
import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for JingleTransports
|
||||||
|
*/
|
||||||
|
public interface JingleTransportHandler<D extends JingleContentTransport> {
|
||||||
|
|
||||||
|
void establishOutgoingSession(JingleManager.FullJidAndSessionId target, JingleContentTransport transport, JingleTransportEstablishedCallback callback);
|
||||||
|
|
||||||
|
void establishIncomingSession(JingleManager.FullJidAndSessionId target, JingleContentTransport transport, JingleTransportEstablishedCallback callback);
|
||||||
|
|
||||||
|
XMPPConnection getConnection();
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package org.jivesoftware.smackx.jingle.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by vanitas on 10.06.17.
|
||||||
|
*/
|
||||||
|
public class JingleTransportFailureException extends Exception {
|
||||||
|
|
||||||
|
public JingleTransportFailureException(Throwable wrapped) {
|
||||||
|
super(wrapped);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue