order canditates by priority before attempting to connect
This commit is contained in:
parent
7d6bd540d9
commit
783ed53d3a
|
@ -11,6 +11,7 @@ import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
@ -303,7 +304,7 @@ public class JingleConnection implements Transferable {
|
||||||
if (this.initialTransport == Transport.IBB) {
|
if (this.initialTransport == Transport.IBB) {
|
||||||
this.sendInitRequest();
|
this.sendInitRequest();
|
||||||
} else if (this.candidates.size() > 0) {
|
} else if (this.candidates.size() > 0) {
|
||||||
this.sendInitRequest();
|
this.sendInitRequest(); //TODO we will never get here? Can probably be removed
|
||||||
} else {
|
} else {
|
||||||
this.mJingleConnectionManager.getPrimaryCandidate(account, (success, candidate) -> {
|
this.mJingleConnectionManager.getPrimaryCandidate(account, (success, candidate) -> {
|
||||||
if (success) {
|
if (success) {
|
||||||
|
@ -1087,6 +1088,7 @@ public class JingleConnection implements Transferable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mergeCandidates(List<JingleCandidate> candidates) {
|
private void mergeCandidates(List<JingleCandidate> candidates) {
|
||||||
|
Collections.sort(candidates, (a, b) -> Integer.compare(b.getPriority(), a.getPriority()));
|
||||||
for (JingleCandidate c : candidates) {
|
for (JingleCandidate c : candidates) {
|
||||||
mergeCandidate(c);
|
mergeCandidate(c);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,9 @@ import eu.siacs.conversations.utils.WakeLockHelper;
|
||||||
import eu.siacs.conversations.xmpp.jingle.stanzas.Content;
|
import eu.siacs.conversations.xmpp.jingle.stanzas.Content;
|
||||||
|
|
||||||
public class JingleSocks5Transport extends JingleTransport {
|
public class JingleSocks5Transport extends JingleTransport {
|
||||||
private JingleCandidate candidate;
|
private final JingleCandidate candidate;
|
||||||
private JingleConnection connection;
|
private final JingleConnection connection;
|
||||||
private String destination;
|
private final String destination;
|
||||||
private OutputStream outputStream;
|
private OutputStream outputStream;
|
||||||
private InputStream inputStream;
|
private InputStream inputStream;
|
||||||
private boolean isEstablished = false;
|
private boolean isEstablished = false;
|
||||||
|
@ -32,11 +32,15 @@ public class JingleSocks5Transport extends JingleTransport {
|
||||||
private Socket socket;
|
private Socket socket;
|
||||||
|
|
||||||
JingleSocks5Transport(JingleConnection jingleConnection, JingleCandidate candidate) {
|
JingleSocks5Transport(JingleConnection jingleConnection, JingleCandidate candidate) {
|
||||||
|
final MessageDigest messageDigest;
|
||||||
|
try {
|
||||||
|
messageDigest = MessageDigest.getInstance("SHA-1");
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new AssertionError(e);
|
||||||
|
}
|
||||||
this.candidate = candidate;
|
this.candidate = candidate;
|
||||||
this.connection = jingleConnection;
|
this.connection = jingleConnection;
|
||||||
try {
|
final StringBuilder destBuilder = new StringBuilder();
|
||||||
MessageDigest mDigest = MessageDigest.getInstance("SHA-1");
|
|
||||||
StringBuilder destBuilder = new StringBuilder();
|
|
||||||
if (jingleConnection.getFtVersion() == Content.Version.FT_3) {
|
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");
|
Log.d(Config.LOGTAG, this.connection.getAccount().getJid().asBareJid() + ": using session Id instead of transport Id for proxy destination");
|
||||||
destBuilder.append(jingleConnection.getSessionId());
|
destBuilder.append(jingleConnection.getSessionId());
|
||||||
|
@ -50,12 +54,8 @@ public class JingleSocks5Transport extends JingleTransport {
|
||||||
destBuilder.append(jingleConnection.getCounterPart());
|
destBuilder.append(jingleConnection.getCounterPart());
|
||||||
destBuilder.append(jingleConnection.getAccount().getJid());
|
destBuilder.append(jingleConnection.getAccount().getJid());
|
||||||
}
|
}
|
||||||
mDigest.reset();
|
messageDigest.reset();
|
||||||
this.destination = CryptoHelper.bytesToHex(mDigest
|
this.destination = CryptoHelper.bytesToHex(messageDigest.digest(destBuilder.toString().getBytes()));
|
||||||
.digest(destBuilder.toString().getBytes()));
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connect(final OnTransportConnected callback) {
|
public void connect(final OnTransportConnected callback) {
|
||||||
|
|
Loading…
Reference in New Issue