mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 20:42:06 +01:00
SOCKS5 works (no external proxy)
This commit is contained in:
parent
ff2f66fa67
commit
23eb34932f
9 changed files with 166 additions and 89 deletions
|
@ -161,13 +161,18 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
|
||||||
|
|
||||||
public IQ handleSessionAccept(JingleElement request, XMPPConnection connection) {
|
public IQ handleSessionAccept(JingleElement request, XMPPConnection connection) {
|
||||||
LOGGER.log(Level.INFO, "RECEIVED SESSION ACCEPT!");
|
LOGGER.log(Level.INFO, "RECEIVED SESSION ACCEPT!");
|
||||||
for (JingleContentElement contentElement : request.getContents()) {
|
JingleContentElement contentElement = null;
|
||||||
if (contentElement.getName().equals(getName())) {
|
for (JingleContentElement c : request.getContents()) {
|
||||||
JingleContent content = fromElement(contentElement);
|
if (c.getName().equals(getName())) {
|
||||||
getTransport().setPeersProposal(content.getTransport());
|
contentElement = c;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (contentElement == null) {
|
||||||
|
throw new AssertionError("Session Accept did not contain this content.");
|
||||||
|
}
|
||||||
|
|
||||||
|
getTransport().handleSessionAccept(contentElement.getTransport(), connection);
|
||||||
onAccept(connection);
|
onAccept(connection);
|
||||||
return IQ.createResultIQ(request);
|
return IQ.createResultIQ(request);
|
||||||
}
|
}
|
||||||
|
@ -313,9 +318,12 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onAccept(final XMPPConnection connection) {
|
public void onAccept(final XMPPConnection connection) {
|
||||||
|
transport.prepare(connection);
|
||||||
|
|
||||||
if (security != null) {
|
if (security != null) {
|
||||||
security.prepare(connection, getParent().getPeer());
|
security.prepare(connection, getParent().getPeer());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Establish transport
|
//Establish transport
|
||||||
Async.go(new Runnable() {
|
Async.go(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,10 +17,8 @@
|
||||||
package org.jivesoftware.smackx.jingle.components;
|
package org.jivesoftware.smackx.jingle.components;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
@ -66,9 +64,6 @@ public class JingleSession {
|
||||||
|
|
||||||
private SessionState sessionState;
|
private SessionState sessionState;
|
||||||
|
|
||||||
private final Map<JingleContent, PendingJingleAction> pendingJingleActions =
|
|
||||||
Collections.synchronizedMap(new HashMap<JingleContent, PendingJingleAction>());
|
|
||||||
|
|
||||||
public JingleSession(JingleManager manager, FullJid initiator, FullJid responder, Role role, String sessionId) {
|
public JingleSession(JingleManager manager, FullJid initiator, FullJid responder, Role role, String sessionId) {
|
||||||
this.jingleManager = manager;
|
this.jingleManager = manager;
|
||||||
this.initiator = initiator;
|
this.initiator = initiator;
|
||||||
|
@ -88,7 +83,7 @@ public class JingleSession {
|
||||||
List<JingleContentElement> initiateContents = initiate.getContents();
|
List<JingleContentElement> initiateContents = initiate.getContents();
|
||||||
|
|
||||||
for (JingleContentElement content : initiateContents) {
|
for (JingleContentElement content : initiateContents) {
|
||||||
session.addContent(content);
|
session.addContent(content, manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
session.sessionState = SessionState.pending;
|
session.sessionState = SessionState.pending;
|
||||||
|
@ -481,7 +476,7 @@ public class JingleSession {
|
||||||
content.setParent(this);
|
content.setParent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addContent(JingleContentElement content)
|
public void addContent(JingleContentElement content, JingleManager manager)
|
||||||
throws UnsupportedSecurityException, UnsupportedTransportException, UnsupportedDescriptionException {
|
throws UnsupportedSecurityException, UnsupportedTransportException, UnsupportedDescriptionException {
|
||||||
addContent(JingleContent.fromElement(content));
|
addContent(JingleContent.fromElement(content));
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,8 @@ public abstract class JingleTransport<D extends JingleContentTransportElement> e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract void prepare(XMPPConnection connection);
|
||||||
|
|
||||||
public List<JingleTransportCandidate<?>> getOurCandidates() {
|
public List<JingleTransportCandidate<?>> getOurCandidates() {
|
||||||
return ourCandidates;
|
return ourCandidates;
|
||||||
}
|
}
|
||||||
|
@ -116,8 +118,6 @@ public abstract class JingleTransport<D extends JingleContentTransportElement> e
|
||||||
public abstract void establishOutgoingBytestreamSession(XMPPConnection connection, JingleTransportCallback callback, JingleSession session)
|
public abstract void establishOutgoingBytestreamSession(XMPPConnection connection, JingleTransportCallback callback, JingleSession session)
|
||||||
throws SmackException.NotConnectedException, InterruptedException;
|
throws SmackException.NotConnectedException, InterruptedException;
|
||||||
|
|
||||||
public abstract void setPeersProposal(JingleTransport<?> peersProposal);
|
|
||||||
|
|
||||||
public abstract IQ handleTransportInfo(JingleContentTransportInfoElement info, JingleElement wrapping);
|
public abstract IQ handleTransportInfo(JingleContentTransportInfoElement info, JingleElement wrapping);
|
||||||
|
|
||||||
public void setParent(JingleContent parent) {
|
public void setParent(JingleContent parent) {
|
||||||
|
@ -133,4 +133,6 @@ public abstract class JingleTransport<D extends JingleContentTransportElement> e
|
||||||
public BytestreamSession getBytestreamSession() {
|
public BytestreamSession getBytestreamSession() {
|
||||||
return bytestreamSession;
|
return bytestreamSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract void handleSessionAccept(JingleContentTransportElement transportElement, XMPPConnection connection);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.jivesoftware.smackx.jingle.callbacks.JingleTransportCallback;
|
||||||
import org.jivesoftware.smackx.jingle.components.JingleSession;
|
import org.jivesoftware.smackx.jingle.components.JingleSession;
|
||||||
import org.jivesoftware.smackx.jingle.components.JingleTransport;
|
import org.jivesoftware.smackx.jingle.components.JingleTransport;
|
||||||
import org.jivesoftware.smackx.jingle.components.JingleTransportCandidate;
|
import org.jivesoftware.smackx.jingle.components.JingleTransportCandidate;
|
||||||
|
import org.jivesoftware.smackx.jingle.element.JingleContentTransportElement;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfoElement;
|
import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfoElement;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||||
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.element.JingleIBBTransportElement;
|
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.element.JingleIBBTransportElement;
|
||||||
|
@ -76,6 +77,12 @@ public class JingleIBBTransport extends JingleTransport<JingleIBBTransportElemen
|
||||||
return NAMESPACE;
|
return NAMESPACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleSessionAccept(JingleContentTransportElement transportElement, XMPPConnection connection) {
|
||||||
|
JingleIBBTransportElement element = (JingleIBBTransportElement) transportElement;
|
||||||
|
blockSize = (blockSize < element.getBlockSize() ? blockSize : element.getBlockSize());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void establishIncomingBytestreamSession(final XMPPConnection connection, final JingleTransportCallback callback, final JingleSession session) {
|
public void establishIncomingBytestreamSession(final XMPPConnection connection, final JingleTransportCallback callback, final JingleSession session) {
|
||||||
final InBandBytestreamManager inBandBytestreamManager = InBandBytestreamManager.getByteStreamManager(connection);
|
final InBandBytestreamManager inBandBytestreamManager = InBandBytestreamManager.getByteStreamManager(connection);
|
||||||
|
@ -120,15 +127,13 @@ public class JingleIBBTransport extends JingleTransport<JingleIBBTransportElemen
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPeersProposal(JingleTransport<?> peersProposal) {
|
public void addOurCandidate(JingleTransportCandidate<?> candidate) {
|
||||||
JingleIBBTransport transport = (JingleIBBTransport) peersProposal;
|
// Sorry, we don't want any candidates.
|
||||||
//Respect peers wish for smaller block size.
|
|
||||||
blockSize = (blockSize < transport.blockSize ? blockSize : transport.blockSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addOurCandidate(JingleTransportCandidate<?> candidate) {
|
public void prepare(XMPPConnection connection) {
|
||||||
// Sorry, we don't want any candidates.
|
// Nuffin taddooh.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -35,10 +35,11 @@ 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.JingleManager;
|
||||||
import org.jivesoftware.smackx.jingle.callbacks.JingleTransportCallback;
|
import org.jivesoftware.smackx.jingle.callbacks.JingleTransportCallback;
|
||||||
import org.jivesoftware.smackx.jingle.components.JingleContent;
|
|
||||||
import org.jivesoftware.smackx.jingle.components.JingleSession;
|
import org.jivesoftware.smackx.jingle.components.JingleSession;
|
||||||
import org.jivesoftware.smackx.jingle.components.JingleTransport;
|
import org.jivesoftware.smackx.jingle.components.JingleTransport;
|
||||||
import org.jivesoftware.smackx.jingle.components.JingleTransportCandidate;
|
import org.jivesoftware.smackx.jingle.components.JingleTransportCandidate;
|
||||||
|
import org.jivesoftware.smackx.jingle.element.JingleContentTransportCandidateElement;
|
||||||
|
import org.jivesoftware.smackx.jingle.element.JingleContentTransportElement;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfoElement;
|
import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfoElement;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||||
import org.jivesoftware.smackx.jingle.exception.FailedTransportException;
|
import org.jivesoftware.smackx.jingle.exception.FailedTransportException;
|
||||||
|
@ -62,8 +63,11 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
||||||
|
|
||||||
private final String sid;
|
private final String sid;
|
||||||
|
|
||||||
private String dstAddr;
|
private String ourDstAddr;
|
||||||
private Bytestream.Mode mode;
|
private String theirDstAddr;
|
||||||
|
|
||||||
|
private Bytestream.Mode ourMode;
|
||||||
|
private Bytestream.Mode theirMode;
|
||||||
|
|
||||||
// PEERS candidate of OUR choice.
|
// PEERS candidate of OUR choice.
|
||||||
private JingleS5BTransportCandidate ourSelectedCandidate;
|
private JingleS5BTransportCandidate ourSelectedCandidate;
|
||||||
|
@ -71,59 +75,106 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
||||||
|
|
||||||
private JingleTransportCallback callback;
|
private JingleTransportCallback callback;
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Create fresh JingleS5BTransport.
|
public void handleSessionAccept(JingleContentTransportElement transportElement, XMPPConnection connection) {
|
||||||
* @param initiator initiator.
|
JingleS5BTransportElement transport = (JingleS5BTransportElement) transportElement;
|
||||||
* @param responder responder.
|
theirDstAddr = transport.getDestinationAddress();
|
||||||
*/
|
theirMode = transport.getMode();
|
||||||
public JingleS5BTransport(FullJid initiator, FullJid responder, String sid, List<JingleTransportCandidate<?>> ourCandidates, List<JingleTransportCandidate<?>> theirCandidates) {
|
for (JingleContentTransportCandidateElement c : transport.getCandidates()) {
|
||||||
this(sid, Socks5Utils.createDigest(sid, initiator, responder), Bytestream.Mode.tcp, ourCandidates, theirCandidates);
|
JingleS5BTransportCandidateElement candidate = (JingleS5BTransportCandidateElement) c;
|
||||||
|
addTheirCandidate(new JingleS5BTransportCandidate(candidate));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a JingleS5BTransport as response to another JingleS5BTransport proposal.
|
* Create transport as initiator.
|
||||||
* @param content content which this transport will be child of.
|
* @param initiator
|
||||||
* @param other other JingleS5BTransport proposal.
|
* @param responder
|
||||||
* @param candidates list of available JingleS5BTransportCandidates.
|
|
||||||
*/
|
|
||||||
public JingleS5BTransport(JingleContent content, JingleS5BTransport other, List<JingleTransportCandidate<?>> candidates) {
|
|
||||||
this(other.getSid(),
|
|
||||||
Socks5Utils.createDigest(other.getSid(), content.getParent().getInitiator(), content.getParent().getResponder()),
|
|
||||||
other.mode, candidates, other.getOurCandidates());
|
|
||||||
setPeersProposal(other);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new JingleS5BTransport.
|
|
||||||
* @param sid
|
* @param sid
|
||||||
* @param dstAddr
|
|
||||||
* @param mode
|
* @param mode
|
||||||
* @param candidates
|
* @param ourCandidates
|
||||||
*/
|
*/
|
||||||
public JingleS5BTransport(String sid, String dstAddr, Bytestream.Mode mode, List<JingleTransportCandidate<?>> candidates, List<JingleTransportCandidate<?>> theirCandidates) {
|
public JingleS5BTransport(FullJid initiator, FullJid responder, String sid, Bytestream.Mode mode, List<JingleTransportCandidate<?>> ourCandidates) {
|
||||||
this.sid = sid;
|
this.sid = sid;
|
||||||
this.dstAddr = dstAddr;
|
this.ourMode = mode;
|
||||||
this.mode = mode;
|
this.ourDstAddr = Socks5Utils.createDigest(sid, initiator, responder);
|
||||||
|
Socks5Proxy.getSocks5Proxy().addTransfer(ourDstAddr);
|
||||||
|
|
||||||
for (JingleTransportCandidate<?> c : (candidates != null ?
|
for (JingleTransportCandidate<?> c : ourCandidates) {
|
||||||
candidates : Collections.<JingleS5BTransportCandidate>emptySet())) {
|
addOurCandidate(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create simple transport as responder.
|
||||||
|
* @param initiator
|
||||||
|
* @param responder
|
||||||
|
* @param ourCandidates
|
||||||
|
* @param other
|
||||||
|
*/
|
||||||
|
public JingleS5BTransport(FullJid initiator, FullJid responder, List<JingleTransportCandidate<?>> ourCandidates, JingleS5BTransport other) {
|
||||||
|
this.sid = other.sid;
|
||||||
|
this.ourMode = other.theirMode;
|
||||||
|
this.ourDstAddr = Socks5Utils.createDigest(other.sid, initiator, responder);
|
||||||
|
Socks5Proxy.getSocks5Proxy().addTransfer(ourDstAddr);
|
||||||
|
this.theirMode = other.theirMode;
|
||||||
|
this.theirDstAddr = other.theirDstAddr;
|
||||||
|
|
||||||
|
for (JingleTransportCandidate<?> c : ourCandidates) {
|
||||||
addOurCandidate(c);
|
addOurCandidate(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (JingleTransportCandidate<?> c : (theirCandidates != null ?
|
for (JingleTransportCandidate<?> c : other.getTheirCandidates()) {
|
||||||
theirCandidates : Collections.<JingleS5BTransportCandidate>emptySet())) {
|
addTheirCandidate(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create custom transport as responder.
|
||||||
|
* @param sid
|
||||||
|
* @param ourMode
|
||||||
|
* @param theirMode
|
||||||
|
* @param ourDstAddr
|
||||||
|
* @param theirDstAddr
|
||||||
|
* @param ourCandidates
|
||||||
|
* @param theirCandidates
|
||||||
|
*/
|
||||||
|
public JingleS5BTransport(String sid, Bytestream.Mode ourMode, Bytestream.Mode theirMode, String ourDstAddr, String theirDstAddr, List<JingleTransportCandidate<?>> ourCandidates, List<JingleTransportCandidate<?>> theirCandidates) {
|
||||||
|
this.sid = sid;
|
||||||
|
this.ourMode = ourMode;
|
||||||
|
this.theirMode = theirMode;
|
||||||
|
this.ourDstAddr = ourDstAddr;
|
||||||
|
Socks5Proxy.getSocks5Proxy().addTransfer(ourDstAddr);
|
||||||
|
this.theirDstAddr = theirDstAddr;
|
||||||
|
|
||||||
|
for (JingleTransportCandidate<?> c : (ourCandidates != null ? ourCandidates :
|
||||||
|
Collections.<JingleS5BTransportCandidate>emptySet())) {
|
||||||
|
addOurCandidate(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (JingleTransportCandidate<?> c : (theirCandidates != null ? theirCandidates :
|
||||||
|
Collections.<JingleS5BTransportCandidate>emptySet())) {
|
||||||
addTheirCandidate(c);
|
addTheirCandidate(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy constructor.
|
* Copy constructor.
|
||||||
* @param transport which will be copied.
|
* @param original
|
||||||
*/
|
*/
|
||||||
public JingleS5BTransport(JingleS5BTransport transport) {
|
public JingleS5BTransport(JingleS5BTransport original) {
|
||||||
this(transport.sid, transport.dstAddr, transport.mode, null, null);
|
this.sid = original.sid;
|
||||||
for (JingleTransportCandidate<?> c : transport.getOurCandidates()) {
|
this.ourDstAddr = original.ourDstAddr;
|
||||||
this.addOurCandidate(new JingleS5BTransportCandidate((JingleS5BTransportCandidate) c));
|
this.theirDstAddr = original.theirDstAddr;
|
||||||
|
this.ourMode = original.ourMode;
|
||||||
|
this.theirMode = original.theirMode;
|
||||||
|
|
||||||
|
for (JingleTransportCandidate<?> c : original.getOurCandidates()) {
|
||||||
|
addOurCandidate(new JingleS5BTransportCandidate((JingleS5BTransportCandidate) c));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (JingleTransportCandidate<?> c : original.getTheirCandidates()) {
|
||||||
|
addTheirCandidate(new JingleS5BTransportCandidate((JingleS5BTransportCandidate) c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,8 +182,8 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
||||||
public JingleS5BTransportElement getElement() {
|
public JingleS5BTransportElement getElement() {
|
||||||
JingleS5BTransportElement.Builder builder = JingleS5BTransportElement.getBuilder()
|
JingleS5BTransportElement.Builder builder = JingleS5BTransportElement.getBuilder()
|
||||||
.setStreamId(sid)
|
.setStreamId(sid)
|
||||||
.setDestinationAddress(dstAddr)
|
.setDestinationAddress(ourDstAddr)
|
||||||
.setMode(mode);
|
.setMode(ourMode);
|
||||||
|
|
||||||
for (JingleTransportCandidate<?> candidate : getOurCandidates()) {
|
for (JingleTransportCandidate<?> candidate : getOurCandidates()) {
|
||||||
builder.addTransportCandidate((JingleS5BTransportCandidateElement) candidate.getElement());
|
builder.addTransportCandidate((JingleS5BTransportCandidateElement) candidate.getElement());
|
||||||
|
@ -145,12 +196,16 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
||||||
return sid;
|
return sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDstAddr() {
|
public String getOurDstAddr() {
|
||||||
return dstAddr;
|
return ourDstAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bytestream.Mode getMode() {
|
public String getTheirDstAddr() {
|
||||||
return mode;
|
return theirDstAddr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bytestream.Mode getOurMode() {
|
||||||
|
return ourMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -165,6 +220,26 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
||||||
establishBytestreamSession(connection);
|
establishBytestreamSession(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepare(XMPPConnection connection) {
|
||||||
|
JingleSession session = getParent().getParent();
|
||||||
|
if (getOurDstAddr() == null) {
|
||||||
|
ourDstAddr = Socks5Utils.createDigest(session.getSessionId(), session.getInitiator(), session.getResponder());
|
||||||
|
Socks5Proxy.getSocks5Proxy().addTransfer(ourDstAddr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ourMode == null) {
|
||||||
|
ourMode = Bytestream.Mode.tcp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getOurCandidates().size() == 0) {
|
||||||
|
List<JingleTransportCandidate<?>> candidates = JingleS5BTransportManager.getInstanceFor(connection).collectCandidates();
|
||||||
|
for (JingleTransportCandidate<?> c : candidates) {
|
||||||
|
addOurCandidate(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void establishOutgoingBytestreamSession(XMPPConnection connection, JingleTransportCallback callback, JingleSession session)
|
public void establishOutgoingBytestreamSession(XMPPConnection connection, JingleTransportCallback callback, JingleSession session)
|
||||||
throws SmackException.NotConnectedException, InterruptedException {
|
throws SmackException.NotConnectedException, InterruptedException {
|
||||||
|
@ -172,18 +247,9 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
||||||
establishBytestreamSession(connection);
|
establishBytestreamSession(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPeersProposal(JingleTransport<?> peersProposal) {
|
|
||||||
JingleS5BTransport transport = (JingleS5BTransport) peersProposal;
|
|
||||||
getTheirCandidates().clear();
|
|
||||||
for (JingleTransportCandidate<?> c : transport.getOurCandidates()) {
|
|
||||||
addTheirCandidate(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void establishBytestreamSession(XMPPConnection connection)
|
void establishBytestreamSession(XMPPConnection connection)
|
||||||
throws SmackException.NotConnectedException, InterruptedException {
|
throws SmackException.NotConnectedException, InterruptedException {
|
||||||
Socks5Proxy.getSocks5Proxy().addTransfer(dstAddr);
|
Socks5Proxy.getSocks5Proxy().addTransfer(ourDstAddr);
|
||||||
JingleS5BTransportManager transportManager = JingleS5BTransportManager.getInstanceFor(connection);
|
JingleS5BTransportManager transportManager = JingleS5BTransportManager.getInstanceFor(connection);
|
||||||
this.ourSelectedCandidate = connectToCandidates(MAX_TIMEOUT);
|
this.ourSelectedCandidate = connectToCandidates(MAX_TIMEOUT);
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class JingleS5BTransportAdapter implements JingleTransportAdapter<JingleS
|
||||||
candidates.add(JingleS5BTransportCandidate.fromElement((JingleS5BTransportCandidateElement) e));
|
candidates.add(JingleS5BTransportCandidate.fromElement((JingleS5BTransportCandidateElement) e));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new JingleS5BTransport(s5b.getSid(), s5b.getDestinationAddress(), s5b.getMode(), null, candidates);
|
return new JingleS5BTransport(s5b.getSid(), null, s5b.getMode(), null, s5b.getDestinationAddress(), null, candidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -44,6 +44,10 @@ public class JingleS5BTransportCandidate extends JingleTransportCandidate<Jingle
|
||||||
|
|
||||||
private Socket socket;
|
private Socket socket;
|
||||||
|
|
||||||
|
public JingleS5BTransportCandidate(JingleS5BTransportCandidateElement element) {
|
||||||
|
this(element.getCandidateId(), new Bytestream.StreamHost(element.getJid(), element.getHost(), element.getPort()), element.getPriority(), element.getType());
|
||||||
|
}
|
||||||
|
|
||||||
public JingleS5BTransportCandidate(String candidateId,
|
public JingleS5BTransportCandidate(String candidateId,
|
||||||
Bytestream.StreamHost streamHost,
|
Bytestream.StreamHost streamHost,
|
||||||
int priority,
|
int priority,
|
||||||
|
@ -91,14 +95,14 @@ public class JingleS5BTransportCandidate extends JingleTransportCandidate<Jingle
|
||||||
|
|
||||||
Socks5Client client;
|
Socks5Client client;
|
||||||
if (peersProposal) {
|
if (peersProposal) {
|
||||||
LOGGER.log(Level.INFO, "Connect to foreign candidate " + getCandidateId() + " using " + transport.getDstAddr());
|
LOGGER.log(Level.INFO, "Connect to foreign candidate " + getCandidateId() + " using " + transport.getTheirDstAddr());
|
||||||
client = new Socks5Client(getStreamHost(), transport.getDstAddr());
|
client = new Socks5Client(getStreamHost(), transport.getTheirDstAddr());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOGGER.log(Level.INFO, "Connect to our candidate " + getCandidateId() + " using " + ((JingleS5BTransport) getParent()).getDstAddr());
|
LOGGER.log(Level.INFO, "Connect to our candidate " + getCandidateId() + " using " + transport.getOurDstAddr());
|
||||||
JingleContent content = transport.getParent();
|
JingleContent content = transport.getParent();
|
||||||
JingleSession session = content.getParent();
|
JingleSession session = content.getParent();
|
||||||
client = new Socks5ClientForInitiator(getStreamHost(), transport.getDstAddr(), session.getJingleManager().getConnection(), transport.getSid(), session.getPeer());
|
client = new Socks5ClientForInitiator(getStreamHost(), transport.getOurDstAddr(), session.getJingleManager().getConnection(), transport.getSid(), session.getPeer());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.socket = client.getSocket(timeout);
|
this.socket = client.getSocket(timeout);
|
||||||
|
|
|
@ -64,7 +64,7 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
|
||||||
private List<Bytestream.StreamHost> localStreamHosts = null;
|
private List<Bytestream.StreamHost> localStreamHosts = null;
|
||||||
private List<Bytestream.StreamHost> availableStreamHosts = null;
|
private List<Bytestream.StreamHost> availableStreamHosts = null;
|
||||||
|
|
||||||
private static boolean useLocalCandidates = true;
|
private static boolean useLocalCandidates = false;
|
||||||
private static boolean useExternalCandidates = true;
|
private static boolean useExternalCandidates = true;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
@ -99,16 +99,13 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
|
||||||
public JingleTransport<?> createTransport(JingleContent content) {
|
public JingleTransport<?> createTransport(JingleContent content) {
|
||||||
JingleSession session = content.getParent();
|
JingleSession session = content.getParent();
|
||||||
List<JingleTransportCandidate<?>> candidates = collectCandidates();
|
List<JingleTransportCandidate<?>> candidates = collectCandidates();
|
||||||
return new JingleS5BTransport(session.getInitiator(), session.getResponder(), StringUtils.randomString(24), candidates, null);
|
return new JingleS5BTransport(session.getInitiator(), session.getResponder(), StringUtils.randomString(24), Bytestream.Mode.tcp, candidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JingleTransport<?> createTransport(JingleContent content, JingleTransport<?> peersTransport) {
|
public JingleTransport<?> createTransport(JingleContent content, JingleTransport<?> peersTransport) {
|
||||||
JingleS5BTransport transport = (JingleS5BTransport) peersTransport;
|
JingleSession session = content.getParent();
|
||||||
List<JingleTransportCandidate<?>> candidates = collectCandidates();
|
return new JingleS5BTransport(session.getInitiator(), session.getResponder(), collectCandidates(), (JingleS5BTransport) peersTransport);
|
||||||
JingleS5BTransport mTransport = new JingleS5BTransport(content, transport, candidates);
|
|
||||||
mTransport.setPeersProposal(transport);
|
|
||||||
return mTransport;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -116,7 +113,7 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
|
||||||
return 10000;
|
return 10000;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<JingleTransportCandidate<?>> collectCandidates() {
|
public List<JingleTransportCandidate<?>> collectCandidates() {
|
||||||
List<JingleTransportCandidate<?>> candidates = new ArrayList<>();
|
List<JingleTransportCandidate<?>> candidates = new ArrayList<>();
|
||||||
|
|
||||||
//Local host
|
//Local host
|
||||||
|
|
|
@ -93,8 +93,8 @@ public class JingleTransportTest extends AbstractSmackIntegrationTest {
|
||||||
JingleS5BTransport rTransport = (JingleS5BTransport) JingleS5BTransportManager.getInstanceFor(receiver).createTransport(rContent, sTransport);
|
JingleS5BTransport rTransport = (JingleS5BTransport) JingleS5BTransportManager.getInstanceFor(receiver).createTransport(rContent, sTransport);
|
||||||
sContent.setTransport(sTransport);
|
sContent.setTransport(sTransport);
|
||||||
rContent.setTransport(rTransport);
|
rContent.setTransport(rTransport);
|
||||||
sTransport.setPeersProposal(new JingleS5BTransport(rTransport));
|
sTransport.handleSessionAccept(rTransport.getElement(), sender);
|
||||||
rTransport.setPeersProposal(new JingleS5BTransport(sTransport));
|
rTransport.handleSessionAccept(sTransport.getElement(), receiver);
|
||||||
|
|
||||||
basicTransportTest(sSession, rSession, sTransport, rTransport);
|
basicTransportTest(sSession, rSession, sTransport, rTransport);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue