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.BytestreamSession;
|
||||
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.hashes.HashManager;
|
||||
import org.jivesoftware.smackx.jingle.AbstractJingleTransportManager;
|
||||
import org.jivesoftware.smackx.jingle.JingleTransportManager;
|
||||
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.provider.JingleContentTransportProvider;
|
||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransport;
|
||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportCandidate;
|
||||
import org.jivesoftware.smackx.jingle_s5b.provider.JingleSocks5BytestreamTransportProvider;
|
||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransport;
|
||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate;
|
||||
import org.jivesoftware.smackx.jingle_s5b.provider.JingleS5BTransportProvider;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
public static JingleSocks5BytestreamTransportManager getInstanceFor(XMPPConnection connection) {
|
||||
JingleSocks5BytestreamTransportManager manager = INSTANCES.get(connection);
|
||||
public static JingleS5BTransportManager getInstanceFor(XMPPConnection connection) {
|
||||
JingleS5BTransportManager manager = INSTANCES.get(connection);
|
||||
if (manager == null) {
|
||||
manager = new JingleSocks5BytestreamTransportManager(connection);
|
||||
manager = new JingleS5BTransportManager(connection);
|
||||
INSTANCES.put(connection, 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 {
|
||||
Socks5BytestreamManager s5m = Socks5BytestreamManager.getBytestreamManager(connection());
|
||||
List<Jid> proxies = s5m.determineProxies();
|
||||
return determineStreamHostInfos(proxies);
|
||||
return determineStreamHostInfo(proxies);
|
||||
}
|
||||
|
||||
public List<Bytestream.StreamHost> getLocalStreamHosts() {
|
||||
|
@ -74,7 +74,7 @@ public final class JingleSocks5BytestreamTransportManager extends AbstractJingle
|
|||
.getLocalStreamHost();
|
||||
}
|
||||
|
||||
public List<Bytestream.StreamHost> determineStreamHostInfos(List<Jid> proxies) {
|
||||
public List<Bytestream.StreamHost> determineStreamHostInfo(List<Jid> proxies) {
|
||||
XMPPConnection connection = connection();
|
||||
List<Bytestream.StreamHost> streamHosts = new ArrayList<>();
|
||||
|
||||
|
@ -102,13 +102,13 @@ public final class JingleSocks5BytestreamTransportManager extends AbstractJingle
|
|||
|
||||
|
||||
@Override
|
||||
protected JingleContentTransportProvider<JingleSocks5BytestreamTransport> createJingleContentTransportProvider() {
|
||||
return new JingleSocks5BytestreamTransportProvider();
|
||||
protected JingleContentTransportProvider<JingleS5BTransport> createJingleContentTransportProvider() {
|
||||
return new JingleS5BTransportProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return JingleSocks5BytestreamTransport.NAMESPACE_V1;
|
||||
return JingleS5BTransport.NAMESPACE_V1;
|
||||
}
|
||||
|
||||
@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 {
|
||||
JingleSocks5BytestreamTransport received = (JingleSocks5BytestreamTransport) received_;
|
||||
public JingleS5BTransport createJingleContentTransport(Jid remote, JingleContentTransport received_) throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
||||
JingleS5BTransport received = (JingleS5BTransport) received_;
|
||||
|
||||
JingleSocks5BytestreamTransport.Builder builder = JingleSocks5BytestreamTransport.getBuilder();
|
||||
JingleS5BTransport.Builder builder = JingleS5BTransport.getBuilder();
|
||||
List<Bytestream.StreamHost> localStreams = getLocalStreamHosts();
|
||||
List<Bytestream.StreamHost> availableStreams = getAvailableStreamHosts();
|
||||
|
||||
for (Bytestream.StreamHost host : localStreams) {
|
||||
JingleSocks5BytestreamTransportCandidate candidate = new JingleSocks5BytestreamTransportCandidate(host, 100);
|
||||
JingleS5BTransportCandidate candidate = new JingleS5BTransportCandidate(host, 100);
|
||||
builder.addTransportCandidate(candidate);
|
||||
}
|
||||
|
||||
for (Bytestream.StreamHost host : availableStreams) {
|
||||
JingleSocks5BytestreamTransportCandidate candidate = new JingleSocks5BytestreamTransportCandidate(host, 0);
|
||||
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());
|
||||
|
||||
String digestString =
|
||||
sid +
|
||||
connection().getUser().asFullJidIfPossible().toString() +
|
||||
remote.asFullJidIfPossible().toString();
|
||||
builder.setDestinationAddress(HashManager.sha_1HexString(digestString));
|
||||
builder.setDestinationAddress(Socks5Utils.createDigest(sid, connection().getUser(), remote));
|
||||
return builder.build();
|
||||
}
|
||||
|
|
@ -29,7 +29,7 @@ import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfo;
|
|||
/**
|
||||
* 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 ATTR_DSTADDR = "dstaddr";
|
||||
public static final String ATTR_MODE = "mode";
|
||||
|
@ -39,7 +39,7 @@ public class JingleSocks5BytestreamTransport extends JingleContentTransport {
|
|||
private final String dstAddr;
|
||||
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);
|
||||
this.streamId = streamId;
|
||||
this.dstAddr = dstAddr;
|
||||
|
@ -96,7 +96,7 @@ public class JingleSocks5BytestreamTransport extends JingleContentTransport {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder addTransportCandidate(JingleSocks5BytestreamTransportCandidate candidate) {
|
||||
public Builder addTransportCandidate(JingleS5BTransportCandidate candidate) {
|
||||
this.candidates.add(candidate);
|
||||
return this;
|
||||
}
|
||||
|
@ -107,24 +107,24 @@ public class JingleSocks5BytestreamTransport extends JingleContentTransport {
|
|||
}
|
||||
|
||||
public Builder setCandidateUsed(String candidateId) {
|
||||
return addTransportInfo(JingleSocks5BytestreamTransportInfo.CandidateUsed(candidateId));
|
||||
return addTransportInfo(JingleS5BTransportInfo.CandidateUsed(candidateId));
|
||||
}
|
||||
|
||||
public Builder setCandidateActivated(String candidateId) {
|
||||
return addTransportInfo(JingleSocks5BytestreamTransportInfo.CandidateActivated(candidateId));
|
||||
return addTransportInfo(JingleS5BTransportInfo.CandidateActivated(candidateId));
|
||||
}
|
||||
|
||||
public Builder setCandidateError() {
|
||||
return addTransportInfo(JingleSocks5BytestreamTransportInfo.CandidateError());
|
||||
return addTransportInfo(JingleS5BTransportInfo.CandidateError());
|
||||
}
|
||||
|
||||
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.");
|
||||
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.
|
||||
*/
|
||||
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_HOST = "host";
|
||||
|
@ -48,7 +48,7 @@ public final class JingleSocks5BytestreamTransportCandidate extends JingleConten
|
|||
private final int priority;
|
||||
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.host = host;
|
||||
this.jid = jid;
|
||||
|
@ -57,7 +57,7 @@ public final class JingleSocks5BytestreamTransportCandidate extends JingleConten
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public JingleSocks5BytestreamTransportCandidate(Bytestream.StreamHost streamHost, int priority) {
|
||||
public JingleS5BTransportCandidate(Bytestream.StreamHost streamHost, int priority) {
|
||||
this.cid = JingleTransportManager.generateRandomId();
|
||||
this.host = streamHost.getAddress();
|
||||
this.jid = streamHost.getJID();
|
||||
|
@ -189,14 +189,14 @@ public final class JingleSocks5BytestreamTransportCandidate extends JingleConten
|
|||
return this;
|
||||
}
|
||||
|
||||
public JingleSocks5BytestreamTransportCandidate build() {
|
||||
public JingleS5BTransportCandidate build() {
|
||||
Objects.requireNonNull(cid);
|
||||
Objects.requireNonNull(host);
|
||||
Objects.requireNonNull(jid);
|
||||
if (priority < 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.
|
||||
*/
|
||||
public abstract class JingleSocks5BytestreamTransportInfo extends JingleContentTransportInfo {
|
||||
public abstract class JingleS5BTransportInfo extends JingleContentTransportInfo {
|
||||
|
||||
private static CandidateError CEI;
|
||||
private static ProxyError PEI;
|
||||
|
@ -49,7 +49,7 @@ public abstract class JingleSocks5BytestreamTransportInfo extends JingleContentT
|
|||
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 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 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";
|
||||
|
||||
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";
|
||||
|
||||
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.udp;
|
||||
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportCandidate.ATTR_CID;
|
||||
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportCandidate.ATTR_HOST;
|
||||
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportCandidate.ATTR_JID;
|
||||
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportCandidate.ATTR_PORT;
|
||||
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportCandidate.ATTR_PRIORITY;
|
||||
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportCandidate.ATTR_TYPE;
|
||||
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate.ATTR_CID;
|
||||
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate.ATTR_HOST;
|
||||
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate.ATTR_JID;
|
||||
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate.ATTR_PORT;
|
||||
import static org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate.ATTR_PRIORITY;
|
||||
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.START_TAG;
|
||||
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
|
||||
import org.jivesoftware.smackx.jingle.provider.JingleContentTransportProvider;
|
||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransport;
|
||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportCandidate;
|
||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportInfo;
|
||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransport;
|
||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate;
|
||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportInfo;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
* Provider for JingleSocks5BytestreamTransport elements.
|
||||
*/
|
||||
public class JingleSocks5BytestreamTransportProvider extends JingleContentTransportProvider<JingleSocks5BytestreamTransport> {
|
||||
public class JingleS5BTransportProvider extends JingleContentTransportProvider<JingleS5BTransport> {
|
||||
|
||||
@Override
|
||||
public JingleSocks5BytestreamTransport parse(XmlPullParser parser, int initialDepth) throws Exception {
|
||||
JingleSocks5BytestreamTransport.Builder builder = JingleSocks5BytestreamTransport.getBuilder();
|
||||
public JingleS5BTransport parse(XmlPullParser parser, int initialDepth) throws Exception {
|
||||
JingleS5BTransport.Builder builder = JingleS5BTransport.getBuilder();
|
||||
|
||||
String streamId = parser.getAttributeValue(null, JingleSocks5BytestreamTransport.ATTR_SID);
|
||||
String streamId = parser.getAttributeValue(null, JingleS5BTransport.ATTR_SID);
|
||||
builder.setStreamId(streamId);
|
||||
|
||||
String dstAddr = parser.getAttributeValue(null, JingleSocks5BytestreamTransport.ATTR_DSTADDR);
|
||||
String dstAddr = parser.getAttributeValue(null, JingleS5BTransport.ATTR_DSTADDR);
|
||||
builder.setDestinationAddress(dstAddr);
|
||||
|
||||
String mode = parser.getAttributeValue(null, JingleSocks5BytestreamTransport.ATTR_MODE);
|
||||
String mode = parser.getAttributeValue(null, JingleS5BTransport.ATTR_MODE);
|
||||
if (mode != null) {
|
||||
builder.setMode(mode.equals(udp.toString()) ? udp : tcp);
|
||||
}
|
||||
|
||||
JingleSocks5BytestreamTransportCandidate.Builder cb;
|
||||
JingleS5BTransportCandidate.Builder cb;
|
||||
while (true) {
|
||||
int tag = parser.nextTag();
|
||||
String name = parser.getName();
|
||||
if (tag == START_TAG) {
|
||||
switch (name) {
|
||||
|
||||
case JingleSocks5BytestreamTransportCandidate.ELEMENT:
|
||||
cb = JingleSocks5BytestreamTransportCandidate.getBuilder();
|
||||
case JingleS5BTransportCandidate.ELEMENT:
|
||||
cb = JingleS5BTransportCandidate.getBuilder();
|
||||
cb.setCandidateId(parser.getAttributeValue(null, ATTR_CID));
|
||||
cb.setHost(parser.getAttributeValue(null, ATTR_HOST));
|
||||
cb.setJid(parser.getAttributeValue(null, ATTR_JID));
|
||||
|
@ -75,29 +75,29 @@ public class JingleSocks5BytestreamTransportProvider extends JingleContentTransp
|
|||
|
||||
String typeString = parser.getAttributeValue(null, ATTR_TYPE);
|
||||
if (typeString != null) {
|
||||
cb.setType(JingleSocks5BytestreamTransportCandidate.Type.fromString(typeString));
|
||||
cb.setType(JingleS5BTransportCandidate.Type.fromString(typeString));
|
||||
}
|
||||
builder.addTransportCandidate(cb.build());
|
||||
break;
|
||||
|
||||
case JingleSocks5BytestreamTransportInfo.CandidateActivated.ELEMENT:
|
||||
builder.addTransportInfo(JingleSocks5BytestreamTransportInfo.CandidateActivated(
|
||||
case JingleS5BTransportInfo.CandidateActivated.ELEMENT:
|
||||
builder.addTransportInfo(JingleS5BTransportInfo.CandidateActivated(
|
||||
parser.getAttributeValue(null,
|
||||
JingleSocks5BytestreamTransportInfo.CandidateActivated.ATTR_CID)));
|
||||
JingleS5BTransportInfo.CandidateActivated.ATTR_CID)));
|
||||
break;
|
||||
|
||||
case JingleSocks5BytestreamTransportInfo.CandidateUsed.ELEMENT:
|
||||
builder.addTransportInfo(JingleSocks5BytestreamTransportInfo.CandidateUsed(
|
||||
case JingleS5BTransportInfo.CandidateUsed.ELEMENT:
|
||||
builder.addTransportInfo(JingleS5BTransportInfo.CandidateUsed(
|
||||
parser.getAttributeValue(null,
|
||||
JingleSocks5BytestreamTransportInfo.CandidateUsed.ATTR_CID)));
|
||||
JingleS5BTransportInfo.CandidateUsed.ATTR_CID)));
|
||||
break;
|
||||
|
||||
case JingleSocks5BytestreamTransportInfo.CandidateError.ELEMENT:
|
||||
builder.addTransportInfo(JingleSocks5BytestreamTransportInfo.CandidateError());
|
||||
case JingleS5BTransportInfo.CandidateError.ELEMENT:
|
||||
builder.addTransportInfo(JingleS5BTransportInfo.CandidateError());
|
||||
break;
|
||||
|
||||
case JingleSocks5BytestreamTransportInfo.ProxyError.ELEMENT:
|
||||
builder.addTransportInfo(JingleSocks5BytestreamTransportInfo.ProxyError());
|
||||
case JingleS5BTransportInfo.ProxyError.ELEMENT:
|
||||
builder.addTransportInfo(JingleS5BTransportInfo.ProxyError());
|
||||
break;
|
||||
}
|
||||
}
|
|
@ -22,17 +22,17 @@ import static org.junit.Assert.assertEquals;
|
|||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smack.test.util.TestUtils;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransport;
|
||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportCandidate;
|
||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransportInfo;
|
||||
import org.jivesoftware.smackx.jingle_s5b.provider.JingleSocks5BytestreamTransportProvider;
|
||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransport;
|
||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate;
|
||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportInfo;
|
||||
import org.jivesoftware.smackx.jingle_s5b.provider.JingleS5BTransportProvider;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
|
||||
/**
|
||||
* Test Provider and serialization.
|
||||
*/
|
||||
public class JingleSocks5BytestreamTransportTest extends SmackTestSuite {
|
||||
public class JingleS5BTransportTest extends SmackTestSuite {
|
||||
|
||||
@Test
|
||||
public void candidatesProviderTest() throws Exception {
|
||||
|
@ -68,38 +68,38 @@ public class JingleSocks5BytestreamTransportTest extends SmackTestSuite {
|
|||
"type='proxy'/>" +
|
||||
|
||||
"</transport>";
|
||||
JingleSocks5BytestreamTransport transport = new JingleSocks5BytestreamTransportProvider().parse(TestUtils.getParser(xml));
|
||||
JingleS5BTransport transport = new JingleS5BTransportProvider().parse(TestUtils.getParser(xml));
|
||||
assertEquals("972b7bf47291ca609517f67f86b5081086052dad", transport.getDestinationAddress());
|
||||
assertEquals("vj3hs98y", transport.getStreamId());
|
||||
assertEquals(Bytestream.Mode.tcp, transport.getMode());
|
||||
assertEquals(3, transport.getCandidates().size());
|
||||
|
||||
JingleSocks5BytestreamTransportCandidate candidate1 =
|
||||
(JingleSocks5BytestreamTransportCandidate) transport.getCandidates().get(0);
|
||||
JingleS5BTransportCandidate candidate1 =
|
||||
(JingleS5BTransportCandidate) transport.getCandidates().get(0);
|
||||
assertEquals("hft54dqy", candidate1.getCandidateId());
|
||||
assertEquals("192.168.4.1", candidate1.getHost());
|
||||
assertEquals(JidCreate.from("romeo@montague.lit/orchard"), candidate1.getJid());
|
||||
assertEquals(5086, candidate1.getPort());
|
||||
assertEquals(8257636, candidate1.getPriority());
|
||||
assertEquals(JingleSocks5BytestreamTransportCandidate.Type.direct, candidate1.getType());
|
||||
assertEquals(JingleS5BTransportCandidate.Type.direct, candidate1.getType());
|
||||
|
||||
JingleSocks5BytestreamTransportCandidate candidate2 =
|
||||
(JingleSocks5BytestreamTransportCandidate) transport.getCandidates().get(1);
|
||||
JingleS5BTransportCandidate candidate2 =
|
||||
(JingleS5BTransportCandidate) transport.getCandidates().get(1);
|
||||
assertEquals("hutr46fe", candidate2.getCandidateId());
|
||||
assertEquals("24.24.24.1", candidate2.getHost());
|
||||
assertEquals(JidCreate.from("romeo@montague.lit/orchard"), candidate2.getJid());
|
||||
assertEquals(5087, candidate2.getPort());
|
||||
assertEquals(8258636, candidate2.getPriority());
|
||||
assertEquals(JingleSocks5BytestreamTransportCandidate.Type.direct, candidate2.getType());
|
||||
assertEquals(JingleS5BTransportCandidate.Type.direct, candidate2.getType());
|
||||
|
||||
JingleSocks5BytestreamTransportCandidate candidate3 =
|
||||
(JingleSocks5BytestreamTransportCandidate) transport.getCandidates().get(2);
|
||||
JingleS5BTransportCandidate candidate3 =
|
||||
(JingleS5BTransportCandidate) transport.getCandidates().get(2);
|
||||
assertEquals("xmdh4b7i", candidate3.getCandidateId());
|
||||
assertEquals("123.456.7.8", candidate3.getHost());
|
||||
assertEquals(JidCreate.domainBareFrom("streamer.shakespeare.lit"), candidate3.getJid());
|
||||
assertEquals(7625, candidate3.getPort());
|
||||
assertEquals(7878787, candidate3.getPriority());
|
||||
assertEquals(JingleSocks5BytestreamTransportCandidate.Type.proxy, candidate3.getType());
|
||||
assertEquals(JingleS5BTransportCandidate.Type.proxy, candidate3.getType());
|
||||
|
||||
assertEquals(xml, transport.toXML().toString());
|
||||
}
|
||||
|
@ -110,12 +110,12 @@ public class JingleSocks5BytestreamTransportTest extends SmackTestSuite {
|
|||
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
|
||||
"<candidate-error/>" +
|
||||
"</transport>";
|
||||
JingleSocks5BytestreamTransport candidateErrorTransport = new JingleSocks5BytestreamTransportProvider()
|
||||
JingleS5BTransport candidateErrorTransport = new JingleS5BTransportProvider()
|
||||
.parse(TestUtils.getParser(candidateError));
|
||||
assertNull(candidateErrorTransport.getDestinationAddress());
|
||||
assertEquals(1, candidateErrorTransport.getInfos().size());
|
||||
assertEquals("vj3hs98y", candidateErrorTransport.getStreamId());
|
||||
assertEquals(JingleSocks5BytestreamTransportInfo.CandidateError(),
|
||||
assertEquals(JingleS5BTransportInfo.CandidateError(),
|
||||
candidateErrorTransport.getInfos().get(0));
|
||||
assertEquals(candidateError, candidateErrorTransport.toXML().toString());
|
||||
|
||||
|
@ -123,12 +123,12 @@ public class JingleSocks5BytestreamTransportTest extends SmackTestSuite {
|
|||
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
|
||||
"<proxy-error/>" +
|
||||
"</transport>";
|
||||
JingleSocks5BytestreamTransport proxyErrorTransport = new JingleSocks5BytestreamTransportProvider()
|
||||
JingleS5BTransport proxyErrorTransport = new JingleS5BTransportProvider()
|
||||
.parse(TestUtils.getParser(proxyError));
|
||||
assertNull(proxyErrorTransport.getDestinationAddress());
|
||||
assertEquals(1, proxyErrorTransport.getInfos().size());
|
||||
assertEquals("vj3hs98y", proxyErrorTransport.getStreamId());
|
||||
assertEquals(JingleSocks5BytestreamTransportInfo.ProxyError(),
|
||||
assertEquals(JingleS5BTransportInfo.ProxyError(),
|
||||
proxyErrorTransport.getInfos().get(0));
|
||||
assertEquals(proxyError, proxyErrorTransport.toXML().toString());
|
||||
|
||||
|
@ -136,13 +136,13 @@ public class JingleSocks5BytestreamTransportTest extends SmackTestSuite {
|
|||
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
|
||||
"<candidate-used cid='hr65dqyd'/>" +
|
||||
"</transport>";
|
||||
JingleSocks5BytestreamTransport candidateUsedTransport = new JingleSocks5BytestreamTransportProvider()
|
||||
JingleS5BTransport candidateUsedTransport = new JingleS5BTransportProvider()
|
||||
.parse(TestUtils.getParser(candidateUsed));
|
||||
assertEquals(1, candidateUsedTransport.getInfos().size());
|
||||
assertEquals(JingleSocks5BytestreamTransportInfo.CandidateUsed("hr65dqyd"),
|
||||
assertEquals(JingleS5BTransportInfo.CandidateUsed("hr65dqyd"),
|
||||
candidateUsedTransport.getInfos().get(0));
|
||||
assertEquals("hr65dqyd",
|
||||
((JingleSocks5BytestreamTransportInfo.CandidateUsed)
|
||||
((JingleS5BTransportInfo.CandidateUsed)
|
||||
candidateUsedTransport.getInfos().get(0)).getCandidateId());
|
||||
assertEquals(candidateUsed, candidateUsedTransport.toXML().toString());
|
||||
|
||||
|
@ -150,13 +150,13 @@ public class JingleSocks5BytestreamTransportTest extends SmackTestSuite {
|
|||
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
|
||||
"<candidate-activated cid='hr65dqyd'/>" +
|
||||
"</transport>";
|
||||
JingleSocks5BytestreamTransport candidateActivatedTransport = new JingleSocks5BytestreamTransportProvider()
|
||||
JingleS5BTransport candidateActivatedTransport = new JingleS5BTransportProvider()
|
||||
.parse(TestUtils.getParser(candidateActivated));
|
||||
assertEquals(1, candidateActivatedTransport.getInfos().size());
|
||||
assertEquals(JingleSocks5BytestreamTransportInfo.CandidateActivated("hr65dqyd"),
|
||||
assertEquals(JingleS5BTransportInfo.CandidateActivated("hr65dqyd"),
|
||||
candidateActivatedTransport.getInfos().get(0));
|
||||
assertEquals("hr65dqyd",
|
||||
((JingleSocks5BytestreamTransportInfo.CandidateActivated)
|
||||
((JingleS5BTransportInfo.CandidateActivated)
|
||||
candidateActivatedTransport.getInfos().get(0)).getCandidateId());
|
||||
assertEquals(candidateActivated, candidateActivatedTransport.toXML().toString());
|
||||
}
|
|
@ -28,7 +28,7 @@ import org.jxmpp.jid.Jid;
|
|||
*
|
||||
* @author Henning Staib
|
||||
*/
|
||||
class Socks5Utils {
|
||||
public class Socks5Utils {
|
||||
|
||||
/**
|
||||
* Returns a SHA-1 digest of the given parameters as specified in <a
|
||||
|
|
Loading…
Reference in a new issue