mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-24 04:52:05 +01:00
s5b createTransport
This commit is contained in:
parent
4c1ee37ea7
commit
ecd29a1ea8
6 changed files with 48 additions and 9 deletions
|
@ -87,7 +87,7 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
|
||||||
return jutil.createAck(initiate);
|
return jutil.createAck(initiate);
|
||||||
}
|
}
|
||||||
|
|
||||||
transport = transportManager.createTransport();
|
transport = transportManager.createTransport(getInitiator());
|
||||||
jutil.sendTransportReplace(initiate.getFrom().asFullJidOrThrow(), initiate.getInitiator(),
|
jutil.sendTransportReplace(initiate.getFrom().asFullJidOrThrow(), initiate.getInitiator(),
|
||||||
initiate.getSid(), creator, name, transport);
|
initiate.getSid(), creator, name, transport);
|
||||||
state = State.sent_transport_replace;
|
state = State.sent_transport_replace;
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
|
||||||
throw new IllegalStateException("There must be at least one workable transport method.");
|
throw new IllegalStateException("There must be at least one workable transport method.");
|
||||||
}
|
}
|
||||||
|
|
||||||
transport = transportManager.createTransport();
|
transport = transportManager.createTransport(getResponder());
|
||||||
|
|
||||||
jutil.sendSessionInitiateFileOffer(getResponder(), getSessionId(), creator, name, file, transport);
|
jutil.sendSessionInitiateFileOffer(getResponder(), getSessionId(), creator, name, file, transport);
|
||||||
state = State.pending;
|
state = State.pending;
|
||||||
|
@ -130,7 +130,7 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
|
||||||
if (replacementManager != null) {
|
if (replacementManager != null) {
|
||||||
jutil.sendTransportAccept(transportReplace.getFrom().asFullJidOrThrow(),
|
jutil.sendTransportAccept(transportReplace.getFrom().asFullJidOrThrow(),
|
||||||
transportReplace.getInitiator(), transportReplace.getSid(), creator, name,
|
transportReplace.getInitiator(), transportReplace.getSid(), creator, name,
|
||||||
replacementManager.createTransport());
|
replacementManager.createTransport(getResponder()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return jutil.createAck(transportReplace);
|
return jutil.createAck(transportReplace);
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.jxmpp.jid.Jid;
|
||||||
*
|
*
|
||||||
* @author Henning Staib
|
* @author Henning Staib
|
||||||
*/
|
*/
|
||||||
class Socks5Utils {
|
public class Socks5Utils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a SHA-1 digest of the given parameters as specified in <a
|
* Returns a SHA-1 digest of the given parameters as specified in <a
|
||||||
|
|
|
@ -40,7 +40,7 @@ public abstract class JingleTransportManager<D extends JingleContentTransport> {
|
||||||
|
|
||||||
public abstract String getNamespace();
|
public abstract String getNamespace();
|
||||||
|
|
||||||
public abstract D createTransport();
|
public abstract D createTransport(FullJid recipient);
|
||||||
|
|
||||||
public abstract D createTransport(Jingle request);
|
public abstract D createTransport(Jingle request);
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ public final class JingleIBBTransportManager extends JingleTransportManager<Jing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JingleIBBTransport createTransport() {
|
public JingleIBBTransport createTransport(FullJid recipient) {
|
||||||
return new JingleIBBTransport();
|
return new JingleIBBTransport();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,21 +17,27 @@
|
||||||
package org.jivesoftware.smackx.jingle.transports.jingle_s5b;
|
package org.jivesoftware.smackx.jingle.transports.jingle_s5b;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
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.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
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.packet.Bytestream;
|
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
|
import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
|
||||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportInitiationCallback;
|
import org.jivesoftware.smackx.jingle.transports.JingleTransportInitiationCallback;
|
||||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
||||||
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransport;
|
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransport;
|
||||||
|
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransportCandidate;
|
||||||
|
|
||||||
import org.jxmpp.jid.FullJid;
|
import org.jxmpp.jid.FullJid;
|
||||||
import org.jxmpp.jid.Jid;
|
import org.jxmpp.jid.Jid;
|
||||||
|
@ -41,6 +47,8 @@ import org.jxmpp.jid.Jid;
|
||||||
*/
|
*/
|
||||||
public final class JingleS5BTransportManager extends JingleTransportManager<JingleS5BTransport> {
|
public final class JingleS5BTransportManager extends JingleTransportManager<JingleS5BTransport> {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = Logger.getLogger(JingleS5BTransportManager.class.getName());
|
||||||
|
|
||||||
private static final WeakHashMap<XMPPConnection, JingleS5BTransportManager> INSTANCES = new WeakHashMap<>();
|
private static final WeakHashMap<XMPPConnection, JingleS5BTransportManager> INSTANCES = new WeakHashMap<>();
|
||||||
|
|
||||||
private JingleS5BTransportManager(XMPPConnection connection) {
|
private JingleS5BTransportManager(XMPPConnection connection) {
|
||||||
|
@ -62,15 +70,46 @@ public final class JingleS5BTransportManager extends JingleTransportManager<Jing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JingleS5BTransport createTransport() {
|
public JingleS5BTransport createTransport(FullJid recipient) {
|
||||||
return null;
|
return createTransport(recipient, JingleManager.randomSid(), Bytestream.Mode.tcp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JingleS5BTransport createTransport(Jingle request) {
|
public JingleS5BTransport createTransport(Jingle request) {
|
||||||
return null;
|
FullJid remote = request.getFrom().asFullJidIfPossible();
|
||||||
|
JingleS5BTransport received = (JingleS5BTransport) request.getContents().get(0).getJingleTransport();
|
||||||
|
|
||||||
|
return createTransport(remote, received.getStreamId(), received.getMode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JingleS5BTransport createTransport(FullJid remote, String sid, Bytestream.Mode mode) {
|
||||||
|
JingleS5BTransport.Builder builder = JingleS5BTransport.getBuilder();
|
||||||
|
List<Bytestream.StreamHost> localStreams = getLocalStreamHosts();
|
||||||
|
List<Bytestream.StreamHost> availableStreams;
|
||||||
|
try {
|
||||||
|
availableStreams = getAvailableStreamHosts();
|
||||||
|
} catch (XMPPException.XMPPErrorException | SmackException.NoResponseException | InterruptedException | SmackException.NotConnectedException e) {
|
||||||
|
LOGGER.log(Level.WARNING, "Could not determine available StreamHosts: ", e);
|
||||||
|
availableStreams = Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
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, getConnection().getUser().asFullJidOrThrow(), remote));
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initiateOutgoingSession(FullJid remote, JingleContentTransport transport, JingleTransportInitiationCallback callback) {
|
public void initiateOutgoingSession(FullJid remote, JingleContentTransport transport, JingleTransportInitiationCallback callback) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue