From 09548855dd5c25782473beb5154a4c793841a3da Mon Sep 17 00:00:00 2001 From: vanitasvitae Date: Sun, 25 Jun 2017 14:25:17 +0200 Subject: [PATCH] Progess --- .../socks5/Socks5BytestreamSession.java | 2 +- .../socks5/Socks5ClientForInitiator.java | 2 +- .../JingleTransportInitiationException.java | 17 ++ .../transports/JingleTransportManager.java | 1 - .../jingle_s5b/JingleS5BTransportManager.java | 6 + .../jingle_s5b/JingleS5BTransportSession.java | 148 ++++++++++++++++-- 6 files changed, 164 insertions(+), 12 deletions(-) create mode 100644 smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/JingleTransportInitiationException.java diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamSession.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamSession.java index 06cf408ad..c44b85f2a 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamSession.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamSession.java @@ -37,7 +37,7 @@ public class Socks5BytestreamSession implements BytestreamSession { /* flag to indicate if this session is a direct or mediated connection */ private final boolean isDirect; - protected Socks5BytestreamSession(Socket socket, boolean isDirect) { + public Socks5BytestreamSession(Socket socket, boolean isDirect) { this.socket = socket; this.isDirect = isDirect; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java index 53d744776..993aaa829 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java @@ -42,7 +42,7 @@ import org.jxmpp.jid.Jid; * * @author Henning Staib */ -class Socks5ClientForInitiator extends Socks5Client { +public class Socks5ClientForInitiator extends Socks5Client { /* the XMPP connection used to communicate with the SOCKS5 proxy */ private WeakReference connection; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/JingleTransportInitiationException.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/JingleTransportInitiationException.java new file mode 100644 index 000000000..e3ef36bcb --- /dev/null +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/JingleTransportInitiationException.java @@ -0,0 +1,17 @@ +package org.jivesoftware.smackx.jingle.transports; + +/** + * Created by vanitas on 25.06.17. + */ +public abstract class JingleTransportInitiationException extends Exception { + private static final long serialVersionUID = 1L; + + + public static class ProxyError extends JingleTransportInitiationException { + + } + + public static class CandidateError extends JingleTransportInitiationException { + + } +} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/JingleTransportManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/JingleTransportManager.java index 091fbeae6..75d8797b0 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/JingleTransportManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/JingleTransportManager.java @@ -45,7 +45,6 @@ public abstract class JingleTransportManager i @Override public void connected(XMPPConnection connection) { - } @Override diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/JingleS5BTransportManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/JingleS5BTransportManager.java index 591350488..ed7e2a0f2 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/JingleS5BTransportManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/JingleS5BTransportManager.java @@ -28,6 +28,7 @@ import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager; +import org.jivesoftware.smackx.bytestreams.socks5.Socks5Proxy; import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream; import org.jivesoftware.smackx.jingle.JingleSession; import org.jivesoftware.smackx.jingle.element.Jingle; @@ -129,6 +130,10 @@ public final class JingleS5BTransportManager extends JingleTransportManager remoteUsedCandidate.getPriority()) { + return localUsedCandidate; + } + + if (localUsedCandidate.getPriority() < remoteUsedCandidate.getPriority()) { + return remoteUsedCandidate; + } + + return jingleSession.get().isInitiator() ? localUsedCandidate : remoteUsedCandidate; + } + + public IQ handleCandidateUsed(Jingle candidateUsed) { + JingleS5BTransportInfo info = (JingleS5BTransportInfo) candidateUsed.getContents().get(0) + .getJingleTransport().getInfos().get(0); + + String candidateId = ((JingleS5BTransportInfo.CandidateUsed) info).getCandidateId(); + + for (JingleContentTransportCandidate c : localTransport.getCandidates()) { + JingleS5BTransportCandidate candidate = (JingleS5BTransportCandidate) c; + if (candidate.getCandidateId().equals(candidateId)) { + remoteUsedCandidate = candidate; + break; + } + } + + if (remoteUsedCandidate == null) { + callback.onException(new Exception("Unknown candidate")); + return IQ.createResultIQ(candidateUsed); + } + + if (localUsedCandidate != null) { + JingleS5BTransportCandidate used = determineUsedCandidate(); + + // Our candidate is nominated. + if (used == remoteUsedCandidate) { + + if (used.getType() == JingleS5BTransportCandidate.Type.proxy) { + + } + + + + callback.onSessionInitiated(); + } + // Remotes candidate is nominated. + else { + if (connectedSocket != null) { + callback.onSessionInitiated(new Socks5BytestreamSession(connectedSocket, + used.getJid().asBareJid().equals(jingleSession.get().getRemote().asBareJid()))); + } else { + throw new AssertionError("Connected socket is null."); + } + } + } + + return IQ.createResultIQ(candidateUsed); } @Override @@ -160,7 +264,33 @@ public class JingleS5BTransportSession extends JingleTransportSession