mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 20:42:06 +01:00
Rename classes and reuse Socks5Utils class
This commit is contained in:
parent
327e63f52d
commit
a8f172c66b
7 changed files with 96 additions and 101 deletions
|
@ -29,35 +29,35 @@ import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smackx.bytestreams.BytestreamListener;
|
import org.jivesoftware.smackx.bytestreams.BytestreamListener;
|
||||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
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.packet.Bytestream;
|
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||||
import org.jivesoftware.smackx.hashes.HashManager;
|
|
||||||
import org.jivesoftware.smackx.jingle.AbstractJingleTransportManager;
|
import org.jivesoftware.smackx.jingle.AbstractJingleTransportManager;
|
||||||
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.JingleContentDescription;
|
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.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransport;
|
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransport;
|
||||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportCandidate;
|
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate;
|
||||||
import org.jivesoftware.smackx.jingle_s5b.provider.JingleSocks5BytestreamTransportProvider;
|
import org.jivesoftware.smackx.jingle_s5b.provider.JingleS5BTransportProvider;
|
||||||
import org.jxmpp.jid.FullJid;
|
import org.jxmpp.jid.FullJid;
|
||||||
import org.jxmpp.jid.Jid;
|
import org.jxmpp.jid.Jid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manager for JingleSocks5BytestreamTransports.
|
* Manager for JingleSocks5BytestreamTransports.
|
||||||
*/
|
*/
|
||||||
public final class JingleSocks5BytestreamTransportManager extends AbstractJingleTransportManager<JingleSocks5BytestreamTransport> {
|
public final class JingleS5BTransportManager extends AbstractJingleTransportManager<JingleS5BTransport> {
|
||||||
|
|
||||||
private static final WeakHashMap<XMPPConnection, JingleSocks5BytestreamTransportManager> INSTANCES = new WeakHashMap<>();
|
private static final WeakHashMap<XMPPConnection, JingleS5BTransportManager> INSTANCES = new WeakHashMap<>();
|
||||||
|
|
||||||
private JingleSocks5BytestreamTransportManager(XMPPConnection connection) {
|
private JingleS5BTransportManager(XMPPConnection connection) {
|
||||||
super(connection);
|
super(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JingleSocks5BytestreamTransportManager getInstanceFor(XMPPConnection connection) {
|
public static JingleS5BTransportManager getInstanceFor(XMPPConnection connection) {
|
||||||
JingleSocks5BytestreamTransportManager manager = INSTANCES.get(connection);
|
JingleS5BTransportManager manager = INSTANCES.get(connection);
|
||||||
if (manager == null) {
|
if (manager == null) {
|
||||||
manager = new JingleSocks5BytestreamTransportManager(connection);
|
manager = new JingleS5BTransportManager(connection);
|
||||||
INSTANCES.put(connection, manager);
|
INSTANCES.put(connection, manager);
|
||||||
}
|
}
|
||||||
return manager;
|
return manager;
|
||||||
|
@ -66,7 +66,7 @@ public final class JingleSocks5BytestreamTransportManager extends AbstractJingle
|
||||||
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();
|
||||||
return determineStreamHostInfos(proxies);
|
return determineStreamHostInfo(proxies);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Bytestream.StreamHost> getLocalStreamHosts() {
|
public List<Bytestream.StreamHost> getLocalStreamHosts() {
|
||||||
|
@ -74,7 +74,7 @@ public final class JingleSocks5BytestreamTransportManager extends AbstractJingle
|
||||||
.getLocalStreamHost();
|
.getLocalStreamHost();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Bytestream.StreamHost> determineStreamHostInfos(List<Jid> proxies) {
|
public List<Bytestream.StreamHost> determineStreamHostInfo(List<Jid> proxies) {
|
||||||
XMPPConnection connection = connection();
|
XMPPConnection connection = connection();
|
||||||
List<Bytestream.StreamHost> streamHosts = new ArrayList<>();
|
List<Bytestream.StreamHost> streamHosts = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -102,13 +102,13 @@ public final class JingleSocks5BytestreamTransportManager extends AbstractJingle
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JingleContentTransportProvider<JingleSocks5BytestreamTransport> createJingleContentTransportProvider() {
|
protected JingleContentTransportProvider<JingleS5BTransport> createJingleContentTransportProvider() {
|
||||||
return new JingleSocks5BytestreamTransportProvider();
|
return new JingleS5BTransportProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNamespace() {
|
public String getNamespace() {
|
||||||
return JingleSocks5BytestreamTransport.NAMESPACE_V1;
|
return JingleS5BTransport.NAMESPACE_V1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -131,32 +131,27 @@ public final class JingleSocks5BytestreamTransportManager extends AbstractJingle
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public JingleSocks5BytestreamTransport createJingleContentTransport(Jid remote, JingleContentTransport received_) throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
public JingleS5BTransport createJingleContentTransport(Jid remote, JingleContentTransport received_) throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
||||||
JingleSocks5BytestreamTransport received = (JingleSocks5BytestreamTransport) received_;
|
JingleS5BTransport received = (JingleS5BTransport) received_;
|
||||||
|
|
||||||
JingleSocks5BytestreamTransport.Builder builder = JingleSocks5BytestreamTransport.getBuilder();
|
JingleS5BTransport.Builder builder = JingleS5BTransport.getBuilder();
|
||||||
List<Bytestream.StreamHost> localStreams = getLocalStreamHosts();
|
List<Bytestream.StreamHost> localStreams = getLocalStreamHosts();
|
||||||
List<Bytestream.StreamHost> availableStreams = getAvailableStreamHosts();
|
List<Bytestream.StreamHost> availableStreams = getAvailableStreamHosts();
|
||||||
|
|
||||||
for (Bytestream.StreamHost host : localStreams) {
|
for (Bytestream.StreamHost host : localStreams) {
|
||||||
JingleSocks5BytestreamTransportCandidate candidate = new JingleSocks5BytestreamTransportCandidate(host, 100);
|
JingleS5BTransportCandidate candidate = new JingleS5BTransportCandidate(host, 100);
|
||||||
builder.addTransportCandidate(candidate);
|
builder.addTransportCandidate(candidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Bytestream.StreamHost host : availableStreams) {
|
for (Bytestream.StreamHost host : availableStreams) {
|
||||||
JingleSocks5BytestreamTransportCandidate candidate = new JingleSocks5BytestreamTransportCandidate(host, 0);
|
JingleS5BTransportCandidate candidate = new JingleS5BTransportCandidate(host, 0);
|
||||||
builder.addTransportCandidate(candidate);
|
builder.addTransportCandidate(candidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
String sid = (received == null ? JingleTransportManager.generateRandomId() : received.getStreamId());
|
String sid = (received == null ? JingleTransportManager.generateRandomId() : received.getStreamId());
|
||||||
builder.setStreamId(sid);
|
builder.setStreamId(sid);
|
||||||
builder.setMode(received == null ? Bytestream.Mode.tcp : received.getMode());
|
builder.setMode(received == null ? Bytestream.Mode.tcp : received.getMode());
|
||||||
|
builder.setDestinationAddress(Socks5Utils.createDigest(sid, connection().getUser(), remote));
|
||||||
String digestString =
|
|
||||||
sid +
|
|
||||||
connection().getUser().asFullJidIfPossible().toString() +
|
|
||||||
remote.asFullJidIfPossible().toString();
|
|
||||||
builder.setDestinationAddress(HashManager.sha_1HexString(digestString));
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfo;
|
||||||
/**
|
/**
|
||||||
* Socks5Bytestream transport element.
|
* Socks5Bytestream transport element.
|
||||||
*/
|
*/
|
||||||
public class JingleSocks5BytestreamTransport extends JingleContentTransport {
|
public class JingleS5BTransport extends JingleContentTransport {
|
||||||
public static final String NAMESPACE_V1 = "urn:xmpp:jingle:transports:s5b:1";
|
public static final String NAMESPACE_V1 = "urn:xmpp:jingle:transports:s5b:1";
|
||||||
public static final String ATTR_DSTADDR = "dstaddr";
|
public static final String ATTR_DSTADDR = "dstaddr";
|
||||||
public static final String ATTR_MODE = "mode";
|
public static final String ATTR_MODE = "mode";
|
||||||
|
@ -39,7 +39,7 @@ public class JingleSocks5BytestreamTransport extends JingleContentTransport {
|
||||||
private final String dstAddr;
|
private final String dstAddr;
|
||||||
private final Bytestream.Mode mode;
|
private final Bytestream.Mode mode;
|
||||||
|
|
||||||
protected JingleSocks5BytestreamTransport(List<JingleContentTransportCandidate> candidates, List<JingleContentTransportInfo> infos, String streamId, String dstAddr, Bytestream.Mode mode) {
|
protected JingleS5BTransport(List<JingleContentTransportCandidate> candidates, List<JingleContentTransportInfo> infos, String streamId, String dstAddr, Bytestream.Mode mode) {
|
||||||
super(candidates, infos);
|
super(candidates, infos);
|
||||||
this.streamId = streamId;
|
this.streamId = streamId;
|
||||||
this.dstAddr = dstAddr;
|
this.dstAddr = dstAddr;
|
||||||
|
@ -96,7 +96,7 @@ public class JingleSocks5BytestreamTransport extends JingleContentTransport {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder addTransportCandidate(JingleSocks5BytestreamTransportCandidate candidate) {
|
public Builder addTransportCandidate(JingleS5BTransportCandidate candidate) {
|
||||||
this.candidates.add(candidate);
|
this.candidates.add(candidate);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -107,24 +107,24 @@ public class JingleSocks5BytestreamTransport extends JingleContentTransport {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setCandidateUsed(String candidateId) {
|
public Builder setCandidateUsed(String candidateId) {
|
||||||
return addTransportInfo(JingleSocks5BytestreamTransportInfo.CandidateUsed(candidateId));
|
return addTransportInfo(JingleS5BTransportInfo.CandidateUsed(candidateId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setCandidateActivated(String candidateId) {
|
public Builder setCandidateActivated(String candidateId) {
|
||||||
return addTransportInfo(JingleSocks5BytestreamTransportInfo.CandidateActivated(candidateId));
|
return addTransportInfo(JingleS5BTransportInfo.CandidateActivated(candidateId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setCandidateError() {
|
public Builder setCandidateError() {
|
||||||
return addTransportInfo(JingleSocks5BytestreamTransportInfo.CandidateError());
|
return addTransportInfo(JingleS5BTransportInfo.CandidateError());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setProxyError() {
|
public Builder setProxyError() {
|
||||||
return addTransportInfo(JingleSocks5BytestreamTransportInfo.ProxyError());
|
return addTransportInfo(JingleS5BTransportInfo.ProxyError());
|
||||||
}
|
}
|
||||||
|
|
||||||
public JingleSocks5BytestreamTransport build() {
|
public JingleS5BTransport build() {
|
||||||
StringUtils.requireNotNullOrEmpty(streamId, "sid MUST be neither null, nor empty.");
|
StringUtils.requireNotNullOrEmpty(streamId, "sid MUST be neither null, nor empty.");
|
||||||
return new JingleSocks5BytestreamTransport(candidates, infos, streamId, dstAddr, mode);
|
return new JingleS5BTransport(candidates, infos, streamId, dstAddr, mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -30,9 +30,9 @@ import org.jxmpp.stringprep.XmppStringprepException;
|
||||||
/**
|
/**
|
||||||
* TransportCandidate for Jingle Socks5Bytestream transports.
|
* TransportCandidate for Jingle Socks5Bytestream transports.
|
||||||
*/
|
*/
|
||||||
public final class JingleSocks5BytestreamTransportCandidate extends JingleContentTransportCandidate {
|
public final class JingleS5BTransportCandidate extends JingleContentTransportCandidate {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(JingleSocks5BytestreamTransportCandidate.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(JingleS5BTransportCandidate.class.getName());
|
||||||
|
|
||||||
public static final String ATTR_CID = "cid";
|
public static final String ATTR_CID = "cid";
|
||||||
public static final String ATTR_HOST = "host";
|
public static final String ATTR_HOST = "host";
|
||||||
|
@ -48,7 +48,7 @@ public final class JingleSocks5BytestreamTransportCandidate extends JingleConten
|
||||||
private final int priority;
|
private final int priority;
|
||||||
private final Type type;
|
private final Type type;
|
||||||
|
|
||||||
public JingleSocks5BytestreamTransportCandidate(String candidateId, String host, Jid jid, int port, int priority, Type type) {
|
public JingleS5BTransportCandidate(String candidateId, String host, Jid jid, int port, int priority, Type type) {
|
||||||
this.cid = candidateId;
|
this.cid = candidateId;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.jid = jid;
|
this.jid = jid;
|
||||||
|
@ -57,7 +57,7 @@ public final class JingleSocks5BytestreamTransportCandidate extends JingleConten
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JingleSocks5BytestreamTransportCandidate(Bytestream.StreamHost streamHost, int priority) {
|
public JingleS5BTransportCandidate(Bytestream.StreamHost streamHost, int priority) {
|
||||||
this.cid = JingleTransportManager.generateRandomId();
|
this.cid = JingleTransportManager.generateRandomId();
|
||||||
this.host = streamHost.getAddress();
|
this.host = streamHost.getAddress();
|
||||||
this.jid = streamHost.getJID();
|
this.jid = streamHost.getJID();
|
||||||
|
@ -189,14 +189,14 @@ public final class JingleSocks5BytestreamTransportCandidate extends JingleConten
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JingleSocks5BytestreamTransportCandidate build() {
|
public JingleS5BTransportCandidate build() {
|
||||||
Objects.requireNonNull(cid);
|
Objects.requireNonNull(cid);
|
||||||
Objects.requireNonNull(host);
|
Objects.requireNonNull(host);
|
||||||
Objects.requireNonNull(jid);
|
Objects.requireNonNull(jid);
|
||||||
if (priority < 0) {
|
if (priority < 0) {
|
||||||
throw new IllegalArgumentException("Priority MUST be present and NOT less than 0.");
|
throw new IllegalArgumentException("Priority MUST be present and NOT less than 0.");
|
||||||
}
|
}
|
||||||
return new JingleSocks5BytestreamTransportCandidate(cid, host, jid, port, priority, type);
|
return new JingleS5BTransportCandidate(cid, host, jid, port, priority, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -22,7 +22,7 @@ import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfo;
|
||||||
/**
|
/**
|
||||||
* Class representing possible SOCKS5 TransportInfo elements.
|
* Class representing possible SOCKS5 TransportInfo elements.
|
||||||
*/
|
*/
|
||||||
public abstract class JingleSocks5BytestreamTransportInfo extends JingleContentTransportInfo {
|
public abstract class JingleS5BTransportInfo extends JingleContentTransportInfo {
|
||||||
|
|
||||||
private static CandidateError CEI;
|
private static CandidateError CEI;
|
||||||
private static ProxyError PEI;
|
private static ProxyError PEI;
|
||||||
|
@ -49,7 +49,7 @@ public abstract class JingleSocks5BytestreamTransportInfo extends JingleContentT
|
||||||
return PEI;
|
return PEI;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class CandidateActivated extends JingleSocks5BytestreamTransportInfo {
|
public static final class CandidateActivated extends JingleS5BTransportInfo {
|
||||||
public static final String ELEMENT = "candidate-activated";
|
public static final String ELEMENT = "candidate-activated";
|
||||||
public static final String ATTR_CID = "cid";
|
public static final String ATTR_CID = "cid";
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ public abstract class JingleSocks5BytestreamTransportInfo extends JingleContentT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class CandidateUsed extends JingleSocks5BytestreamTransportInfo {
|
public static final class CandidateUsed extends JingleS5BTransportInfo {
|
||||||
public static final String ELEMENT = "candidate-used";
|
public static final String ELEMENT = "candidate-used";
|
||||||
public static final String ATTR_CID = "cid";
|
public static final String ATTR_CID = "cid";
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ public abstract class JingleSocks5BytestreamTransportInfo extends JingleContentT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class CandidateError extends JingleSocks5BytestreamTransportInfo {
|
public static final class CandidateError extends JingleS5BTransportInfo {
|
||||||
public static final String ELEMENT = "candidate-error";
|
public static final String ELEMENT = "candidate-error";
|
||||||
|
|
||||||
private CandidateError() {
|
private CandidateError() {
|
||||||
|
@ -160,7 +160,7 @@ public abstract class JingleSocks5BytestreamTransportInfo extends JingleContentT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class ProxyError extends JingleSocks5BytestreamTransportInfo {
|
public static final class ProxyError extends JingleS5BTransportInfo {
|
||||||
public static final String ELEMENT = "proxy-error";
|
public static final String ELEMENT = "proxy-error";
|
||||||
|
|
||||||
private ProxyError() {
|
private ProxyError() {
|
|
@ -18,51 +18,51 @@ package org.jivesoftware.smackx.jingle_s5b.provider;
|
||||||
|
|
||||||
import static org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.Mode.tcp;
|
import static org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.Mode.tcp;
|
||||||
import static org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.Mode.udp;
|
import static org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.Mode.udp;
|
||||||
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportCandidate.ATTR_CID;
|
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate.ATTR_CID;
|
||||||
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportCandidate.ATTR_HOST;
|
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate.ATTR_HOST;
|
||||||
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportCandidate.ATTR_JID;
|
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate.ATTR_JID;
|
||||||
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportCandidate.ATTR_PORT;
|
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate.ATTR_PORT;
|
||||||
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportCandidate.ATTR_PRIORITY;
|
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate.ATTR_PRIORITY;
|
||||||
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportCandidate.ATTR_TYPE;
|
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate.ATTR_TYPE;
|
||||||
import static org.xmlpull.v1.XmlPullParser.END_TAG;
|
import static org.xmlpull.v1.XmlPullParser.END_TAG;
|
||||||
import static org.xmlpull.v1.XmlPullParser.START_TAG;
|
import static org.xmlpull.v1.XmlPullParser.START_TAG;
|
||||||
|
|
||||||
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.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransport;
|
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransport;
|
||||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportCandidate;
|
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate;
|
||||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportInfo;
|
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportInfo;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provider for JingleSocks5BytestreamTransport elements.
|
* Provider for JingleSocks5BytestreamTransport elements.
|
||||||
*/
|
*/
|
||||||
public class JingleSocks5BytestreamTransportProvider extends JingleContentTransportProvider<JingleSocks5BytestreamTransport> {
|
public class JingleS5BTransportProvider extends JingleContentTransportProvider<JingleS5BTransport> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JingleSocks5BytestreamTransport parse(XmlPullParser parser, int initialDepth) throws Exception {
|
public JingleS5BTransport parse(XmlPullParser parser, int initialDepth) throws Exception {
|
||||||
JingleSocks5BytestreamTransport.Builder builder = JingleSocks5BytestreamTransport.getBuilder();
|
JingleS5BTransport.Builder builder = JingleS5BTransport.getBuilder();
|
||||||
|
|
||||||
String streamId = parser.getAttributeValue(null, JingleSocks5BytestreamTransport.ATTR_SID);
|
String streamId = parser.getAttributeValue(null, JingleS5BTransport.ATTR_SID);
|
||||||
builder.setStreamId(streamId);
|
builder.setStreamId(streamId);
|
||||||
|
|
||||||
String dstAddr = parser.getAttributeValue(null, JingleSocks5BytestreamTransport.ATTR_DSTADDR);
|
String dstAddr = parser.getAttributeValue(null, JingleS5BTransport.ATTR_DSTADDR);
|
||||||
builder.setDestinationAddress(dstAddr);
|
builder.setDestinationAddress(dstAddr);
|
||||||
|
|
||||||
String mode = parser.getAttributeValue(null, JingleSocks5BytestreamTransport.ATTR_MODE);
|
String mode = parser.getAttributeValue(null, JingleS5BTransport.ATTR_MODE);
|
||||||
if (mode != null) {
|
if (mode != null) {
|
||||||
builder.setMode(mode.equals(udp.toString()) ? udp : tcp);
|
builder.setMode(mode.equals(udp.toString()) ? udp : tcp);
|
||||||
}
|
}
|
||||||
|
|
||||||
JingleSocks5BytestreamTransportCandidate.Builder cb;
|
JingleS5BTransportCandidate.Builder cb;
|
||||||
while (true) {
|
while (true) {
|
||||||
int tag = parser.nextTag();
|
int tag = parser.nextTag();
|
||||||
String name = parser.getName();
|
String name = parser.getName();
|
||||||
if (tag == START_TAG) {
|
if (tag == START_TAG) {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
|
|
||||||
case JingleSocks5BytestreamTransportCandidate.ELEMENT:
|
case JingleS5BTransportCandidate.ELEMENT:
|
||||||
cb = JingleSocks5BytestreamTransportCandidate.getBuilder();
|
cb = JingleS5BTransportCandidate.getBuilder();
|
||||||
cb.setCandidateId(parser.getAttributeValue(null, ATTR_CID));
|
cb.setCandidateId(parser.getAttributeValue(null, ATTR_CID));
|
||||||
cb.setHost(parser.getAttributeValue(null, ATTR_HOST));
|
cb.setHost(parser.getAttributeValue(null, ATTR_HOST));
|
||||||
cb.setJid(parser.getAttributeValue(null, ATTR_JID));
|
cb.setJid(parser.getAttributeValue(null, ATTR_JID));
|
||||||
|
@ -75,29 +75,29 @@ public class JingleSocks5BytestreamTransportProvider extends JingleContentTransp
|
||||||
|
|
||||||
String typeString = parser.getAttributeValue(null, ATTR_TYPE);
|
String typeString = parser.getAttributeValue(null, ATTR_TYPE);
|
||||||
if (typeString != null) {
|
if (typeString != null) {
|
||||||
cb.setType(JingleSocks5BytestreamTransportCandidate.Type.fromString(typeString));
|
cb.setType(JingleS5BTransportCandidate.Type.fromString(typeString));
|
||||||
}
|
}
|
||||||
builder.addTransportCandidate(cb.build());
|
builder.addTransportCandidate(cb.build());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JingleSocks5BytestreamTransportInfo.CandidateActivated.ELEMENT:
|
case JingleS5BTransportInfo.CandidateActivated.ELEMENT:
|
||||||
builder.addTransportInfo(JingleSocks5BytestreamTransportInfo.CandidateActivated(
|
builder.addTransportInfo(JingleS5BTransportInfo.CandidateActivated(
|
||||||
parser.getAttributeValue(null,
|
parser.getAttributeValue(null,
|
||||||
JingleSocks5BytestreamTransportInfo.CandidateActivated.ATTR_CID)));
|
JingleS5BTransportInfo.CandidateActivated.ATTR_CID)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JingleSocks5BytestreamTransportInfo.CandidateUsed.ELEMENT:
|
case JingleS5BTransportInfo.CandidateUsed.ELEMENT:
|
||||||
builder.addTransportInfo(JingleSocks5BytestreamTransportInfo.CandidateUsed(
|
builder.addTransportInfo(JingleS5BTransportInfo.CandidateUsed(
|
||||||
parser.getAttributeValue(null,
|
parser.getAttributeValue(null,
|
||||||
JingleSocks5BytestreamTransportInfo.CandidateUsed.ATTR_CID)));
|
JingleS5BTransportInfo.CandidateUsed.ATTR_CID)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JingleSocks5BytestreamTransportInfo.CandidateError.ELEMENT:
|
case JingleS5BTransportInfo.CandidateError.ELEMENT:
|
||||||
builder.addTransportInfo(JingleSocks5BytestreamTransportInfo.CandidateError());
|
builder.addTransportInfo(JingleS5BTransportInfo.CandidateError());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JingleSocks5BytestreamTransportInfo.ProxyError.ELEMENT:
|
case JingleS5BTransportInfo.ProxyError.ELEMENT:
|
||||||
builder.addTransportInfo(JingleSocks5BytestreamTransportInfo.ProxyError());
|
builder.addTransportInfo(JingleS5BTransportInfo.ProxyError());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -22,17 +22,17 @@ import static org.junit.Assert.assertEquals;
|
||||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||||
import org.jivesoftware.smack.test.util.TestUtils;
|
import org.jivesoftware.smack.test.util.TestUtils;
|
||||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransport;
|
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransport;
|
||||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportCandidate;
|
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate;
|
||||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportInfo;
|
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportInfo;
|
||||||
import org.jivesoftware.smackx.jingle_s5b.provider.JingleSocks5BytestreamTransportProvider;
|
import org.jivesoftware.smackx.jingle_s5b.provider.JingleS5BTransportProvider;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.jxmpp.jid.impl.JidCreate;
|
import org.jxmpp.jid.impl.JidCreate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test Provider and serialization.
|
* Test Provider and serialization.
|
||||||
*/
|
*/
|
||||||
public class JingleSocks5BytestreamTransportTest extends SmackTestSuite {
|
public class JingleS5BTransportTest extends SmackTestSuite {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void candidatesProviderTest() throws Exception {
|
public void candidatesProviderTest() throws Exception {
|
||||||
|
@ -68,38 +68,38 @@ public class JingleSocks5BytestreamTransportTest extends SmackTestSuite {
|
||||||
"type='proxy'/>" +
|
"type='proxy'/>" +
|
||||||
|
|
||||||
"</transport>";
|
"</transport>";
|
||||||
JingleSocks5BytestreamTransport transport = new JingleSocks5BytestreamTransportProvider().parse(TestUtils.getParser(xml));
|
JingleS5BTransport transport = new JingleS5BTransportProvider().parse(TestUtils.getParser(xml));
|
||||||
assertEquals("972b7bf47291ca609517f67f86b5081086052dad", transport.getDestinationAddress());
|
assertEquals("972b7bf47291ca609517f67f86b5081086052dad", transport.getDestinationAddress());
|
||||||
assertEquals("vj3hs98y", transport.getStreamId());
|
assertEquals("vj3hs98y", transport.getStreamId());
|
||||||
assertEquals(Bytestream.Mode.tcp, transport.getMode());
|
assertEquals(Bytestream.Mode.tcp, transport.getMode());
|
||||||
assertEquals(3, transport.getCandidates().size());
|
assertEquals(3, transport.getCandidates().size());
|
||||||
|
|
||||||
JingleSocks5BytestreamTransportCandidate candidate1 =
|
JingleS5BTransportCandidate candidate1 =
|
||||||
(JingleSocks5BytestreamTransportCandidate) transport.getCandidates().get(0);
|
(JingleS5BTransportCandidate) transport.getCandidates().get(0);
|
||||||
assertEquals("hft54dqy", candidate1.getCandidateId());
|
assertEquals("hft54dqy", candidate1.getCandidateId());
|
||||||
assertEquals("192.168.4.1", candidate1.getHost());
|
assertEquals("192.168.4.1", candidate1.getHost());
|
||||||
assertEquals(JidCreate.from("romeo@montague.lit/orchard"), candidate1.getJid());
|
assertEquals(JidCreate.from("romeo@montague.lit/orchard"), candidate1.getJid());
|
||||||
assertEquals(5086, candidate1.getPort());
|
assertEquals(5086, candidate1.getPort());
|
||||||
assertEquals(8257636, candidate1.getPriority());
|
assertEquals(8257636, candidate1.getPriority());
|
||||||
assertEquals(JingleSocks5BytestreamTransportCandidate.Type.direct, candidate1.getType());
|
assertEquals(JingleS5BTransportCandidate.Type.direct, candidate1.getType());
|
||||||
|
|
||||||
JingleSocks5BytestreamTransportCandidate candidate2 =
|
JingleS5BTransportCandidate candidate2 =
|
||||||
(JingleSocks5BytestreamTransportCandidate) transport.getCandidates().get(1);
|
(JingleS5BTransportCandidate) transport.getCandidates().get(1);
|
||||||
assertEquals("hutr46fe", candidate2.getCandidateId());
|
assertEquals("hutr46fe", candidate2.getCandidateId());
|
||||||
assertEquals("24.24.24.1", candidate2.getHost());
|
assertEquals("24.24.24.1", candidate2.getHost());
|
||||||
assertEquals(JidCreate.from("romeo@montague.lit/orchard"), candidate2.getJid());
|
assertEquals(JidCreate.from("romeo@montague.lit/orchard"), candidate2.getJid());
|
||||||
assertEquals(5087, candidate2.getPort());
|
assertEquals(5087, candidate2.getPort());
|
||||||
assertEquals(8258636, candidate2.getPriority());
|
assertEquals(8258636, candidate2.getPriority());
|
||||||
assertEquals(JingleSocks5BytestreamTransportCandidate.Type.direct, candidate2.getType());
|
assertEquals(JingleS5BTransportCandidate.Type.direct, candidate2.getType());
|
||||||
|
|
||||||
JingleSocks5BytestreamTransportCandidate candidate3 =
|
JingleS5BTransportCandidate candidate3 =
|
||||||
(JingleSocks5BytestreamTransportCandidate) transport.getCandidates().get(2);
|
(JingleS5BTransportCandidate) transport.getCandidates().get(2);
|
||||||
assertEquals("xmdh4b7i", candidate3.getCandidateId());
|
assertEquals("xmdh4b7i", candidate3.getCandidateId());
|
||||||
assertEquals("123.456.7.8", candidate3.getHost());
|
assertEquals("123.456.7.8", candidate3.getHost());
|
||||||
assertEquals(JidCreate.domainBareFrom("streamer.shakespeare.lit"), candidate3.getJid());
|
assertEquals(JidCreate.domainBareFrom("streamer.shakespeare.lit"), candidate3.getJid());
|
||||||
assertEquals(7625, candidate3.getPort());
|
assertEquals(7625, candidate3.getPort());
|
||||||
assertEquals(7878787, candidate3.getPriority());
|
assertEquals(7878787, candidate3.getPriority());
|
||||||
assertEquals(JingleSocks5BytestreamTransportCandidate.Type.proxy, candidate3.getType());
|
assertEquals(JingleS5BTransportCandidate.Type.proxy, candidate3.getType());
|
||||||
|
|
||||||
assertEquals(xml, transport.toXML().toString());
|
assertEquals(xml, transport.toXML().toString());
|
||||||
}
|
}
|
||||||
|
@ -110,12 +110,12 @@ public class JingleSocks5BytestreamTransportTest extends SmackTestSuite {
|
||||||
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
|
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
|
||||||
"<candidate-error/>" +
|
"<candidate-error/>" +
|
||||||
"</transport>";
|
"</transport>";
|
||||||
JingleSocks5BytestreamTransport candidateErrorTransport = new JingleSocks5BytestreamTransportProvider()
|
JingleS5BTransport candidateErrorTransport = new JingleS5BTransportProvider()
|
||||||
.parse(TestUtils.getParser(candidateError));
|
.parse(TestUtils.getParser(candidateError));
|
||||||
assertNull(candidateErrorTransport.getDestinationAddress());
|
assertNull(candidateErrorTransport.getDestinationAddress());
|
||||||
assertEquals(1, candidateErrorTransport.getInfos().size());
|
assertEquals(1, candidateErrorTransport.getInfos().size());
|
||||||
assertEquals("vj3hs98y", candidateErrorTransport.getStreamId());
|
assertEquals("vj3hs98y", candidateErrorTransport.getStreamId());
|
||||||
assertEquals(JingleSocks5BytestreamTransportInfo.CandidateError(),
|
assertEquals(JingleS5BTransportInfo.CandidateError(),
|
||||||
candidateErrorTransport.getInfos().get(0));
|
candidateErrorTransport.getInfos().get(0));
|
||||||
assertEquals(candidateError, candidateErrorTransport.toXML().toString());
|
assertEquals(candidateError, candidateErrorTransport.toXML().toString());
|
||||||
|
|
||||||
|
@ -123,12 +123,12 @@ public class JingleSocks5BytestreamTransportTest extends SmackTestSuite {
|
||||||
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
|
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
|
||||||
"<proxy-error/>" +
|
"<proxy-error/>" +
|
||||||
"</transport>";
|
"</transport>";
|
||||||
JingleSocks5BytestreamTransport proxyErrorTransport = new JingleSocks5BytestreamTransportProvider()
|
JingleS5BTransport proxyErrorTransport = new JingleS5BTransportProvider()
|
||||||
.parse(TestUtils.getParser(proxyError));
|
.parse(TestUtils.getParser(proxyError));
|
||||||
assertNull(proxyErrorTransport.getDestinationAddress());
|
assertNull(proxyErrorTransport.getDestinationAddress());
|
||||||
assertEquals(1, proxyErrorTransport.getInfos().size());
|
assertEquals(1, proxyErrorTransport.getInfos().size());
|
||||||
assertEquals("vj3hs98y", proxyErrorTransport.getStreamId());
|
assertEquals("vj3hs98y", proxyErrorTransport.getStreamId());
|
||||||
assertEquals(JingleSocks5BytestreamTransportInfo.ProxyError(),
|
assertEquals(JingleS5BTransportInfo.ProxyError(),
|
||||||
proxyErrorTransport.getInfos().get(0));
|
proxyErrorTransport.getInfos().get(0));
|
||||||
assertEquals(proxyError, proxyErrorTransport.toXML().toString());
|
assertEquals(proxyError, proxyErrorTransport.toXML().toString());
|
||||||
|
|
||||||
|
@ -136,13 +136,13 @@ public class JingleSocks5BytestreamTransportTest extends SmackTestSuite {
|
||||||
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
|
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
|
||||||
"<candidate-used cid='hr65dqyd'/>" +
|
"<candidate-used cid='hr65dqyd'/>" +
|
||||||
"</transport>";
|
"</transport>";
|
||||||
JingleSocks5BytestreamTransport candidateUsedTransport = new JingleSocks5BytestreamTransportProvider()
|
JingleS5BTransport candidateUsedTransport = new JingleS5BTransportProvider()
|
||||||
.parse(TestUtils.getParser(candidateUsed));
|
.parse(TestUtils.getParser(candidateUsed));
|
||||||
assertEquals(1, candidateUsedTransport.getInfos().size());
|
assertEquals(1, candidateUsedTransport.getInfos().size());
|
||||||
assertEquals(JingleSocks5BytestreamTransportInfo.CandidateUsed("hr65dqyd"),
|
assertEquals(JingleS5BTransportInfo.CandidateUsed("hr65dqyd"),
|
||||||
candidateUsedTransport.getInfos().get(0));
|
candidateUsedTransport.getInfos().get(0));
|
||||||
assertEquals("hr65dqyd",
|
assertEquals("hr65dqyd",
|
||||||
((JingleSocks5BytestreamTransportInfo.CandidateUsed)
|
((JingleS5BTransportInfo.CandidateUsed)
|
||||||
candidateUsedTransport.getInfos().get(0)).getCandidateId());
|
candidateUsedTransport.getInfos().get(0)).getCandidateId());
|
||||||
assertEquals(candidateUsed, candidateUsedTransport.toXML().toString());
|
assertEquals(candidateUsed, candidateUsedTransport.toXML().toString());
|
||||||
|
|
||||||
|
@ -150,13 +150,13 @@ public class JingleSocks5BytestreamTransportTest extends SmackTestSuite {
|
||||||
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
|
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
|
||||||
"<candidate-activated cid='hr65dqyd'/>" +
|
"<candidate-activated cid='hr65dqyd'/>" +
|
||||||
"</transport>";
|
"</transport>";
|
||||||
JingleSocks5BytestreamTransport candidateActivatedTransport = new JingleSocks5BytestreamTransportProvider()
|
JingleS5BTransport candidateActivatedTransport = new JingleS5BTransportProvider()
|
||||||
.parse(TestUtils.getParser(candidateActivated));
|
.parse(TestUtils.getParser(candidateActivated));
|
||||||
assertEquals(1, candidateActivatedTransport.getInfos().size());
|
assertEquals(1, candidateActivatedTransport.getInfos().size());
|
||||||
assertEquals(JingleSocks5BytestreamTransportInfo.CandidateActivated("hr65dqyd"),
|
assertEquals(JingleS5BTransportInfo.CandidateActivated("hr65dqyd"),
|
||||||
candidateActivatedTransport.getInfos().get(0));
|
candidateActivatedTransport.getInfos().get(0));
|
||||||
assertEquals("hr65dqyd",
|
assertEquals("hr65dqyd",
|
||||||
((JingleSocks5BytestreamTransportInfo.CandidateActivated)
|
((JingleS5BTransportInfo.CandidateActivated)
|
||||||
candidateActivatedTransport.getInfos().get(0)).getCandidateId());
|
candidateActivatedTransport.getInfos().get(0)).getCandidateId());
|
||||||
assertEquals(candidateActivated, candidateActivatedTransport.toXML().toString());
|
assertEquals(candidateActivated, candidateActivatedTransport.toXML().toString());
|
||||||
}
|
}
|
|
@ -28,7 +28,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
|
||||||
|
|
Loading…
Reference in a new issue