diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-09-03 19:43:29 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-09-03 19:43:29 +0200 |
commit | edcfdb974dc544c0e79e457f50c12e5942619251 (patch) | |
tree | 4d420b79aa16b7d448384a5890f649341a3b9924 /src/main/java/de/pixart/messenger/xmpp | |
parent | ae2a4ed49533715a77cdf85e9dcbefbb61e40cf1 (diff) |
order canditates by priority before attempting to connect
Diffstat (limited to 'src/main/java/de/pixart/messenger/xmpp')
-rw-r--r-- | src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java | 3 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/xmpp/jingle/JingleSocks5Transport.java | 49 |
2 files changed, 27 insertions, 25 deletions
diff --git a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java index 30ca27391..7050874fb 100644 --- a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java @@ -309,7 +309,7 @@ public class JingleConnection implements Transferable { if (this.initialTransport == Transport.IBB) { this.sendInitRequest(); } else if (this.candidates.size() > 0) { - this.sendInitRequest(); + this.sendInitRequest(); //TODO we will never get here? Can probably be removed } else { this.mJingleConnectionManager.getPrimaryCandidate(account, (success, candidate) -> { if (success) { @@ -1097,6 +1097,7 @@ public class JingleConnection implements Transferable { } private void mergeCandidates(List<JingleCandidate> candidates) { + Collections.sort(candidates, (a, b) -> Integer.compare(b.getPriority(), a.getPriority())); for (JingleCandidate c : candidates) { mergeCandidate(c); } diff --git a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleSocks5Transport.java b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleSocks5Transport.java index 15b811bf7..7538ad980 100644 --- a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleSocks5Transport.java +++ b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleSocks5Transport.java @@ -22,9 +22,10 @@ import de.pixart.messenger.utils.WakeLockHelper; import de.pixart.messenger.xmpp.jingle.stanzas.Content; public class JingleSocks5Transport extends JingleTransport { - private JingleCandidate candidate; - private JingleConnection connection; - private String destination; + + private final JingleCandidate candidate; + private final JingleConnection connection; + private final String destination; private OutputStream outputStream; private InputStream inputStream; private boolean isEstablished = false; @@ -32,30 +33,30 @@ public class JingleSocks5Transport extends JingleTransport { private Socket socket; JingleSocks5Transport(JingleConnection jingleConnection, JingleCandidate candidate) { - this.candidate = candidate; - this.connection = jingleConnection; + final MessageDigest messageDigest; try { - MessageDigest mDigest = MessageDigest.getInstance("SHA-1"); - StringBuilder destBuilder = new StringBuilder(); - if (jingleConnection.getFtVersion() == Content.Version.FT_3) { - Log.d(Config.LOGTAG, this.connection.getAccount().getJid().asBareJid() + ": using session Id instead of transport Id for proxy destination"); - destBuilder.append(jingleConnection.getSessionId()); - } else { - destBuilder.append(jingleConnection.getTransportId()); - } - if (candidate.isOurs()) { - destBuilder.append(jingleConnection.getAccount().getJid()); - destBuilder.append(jingleConnection.getCounterPart()); - } else { - destBuilder.append(jingleConnection.getCounterPart()); - destBuilder.append(jingleConnection.getAccount().getJid()); - } - mDigest.reset(); - this.destination = CryptoHelper.bytesToHex(mDigest - .digest(destBuilder.toString().getBytes())); + messageDigest = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException e) { - + throw new AssertionError(e); + } + this.candidate = candidate; + this.connection = jingleConnection; + final StringBuilder destBuilder = new StringBuilder(); + if (jingleConnection.getFtVersion() == Content.Version.FT_3) { + Log.d(Config.LOGTAG, this.connection.getAccount().getJid().asBareJid() + ": using session Id instead of transport Id for proxy destination"); + destBuilder.append(jingleConnection.getSessionId()); + } else { + destBuilder.append(jingleConnection.getTransportId()); + } + if (candidate.isOurs()) { + destBuilder.append(jingleConnection.getAccount().getJid()); + destBuilder.append(jingleConnection.getCounterPart()); + } else { + destBuilder.append(jingleConnection.getCounterPart()); + destBuilder.append(jingleConnection.getAccount().getJid()); } + messageDigest.reset(); + this.destination = CryptoHelper.bytesToHex(messageDigest.digest(destBuilder.toString().getBytes())); } public void connect(final OnTransportConnected callback) { |