fix Jingle FT candidate selection for equal priority. fixes #3771
This commit is contained in:
parent
c029382410
commit
b78d45c7cc
|
@ -147,7 +147,6 @@ public class JingleCandidate {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.getHost() + ":" + this.getPort() + " (prio="
|
return String.format("%s:%s (priority=%s,ours=%s)", getHost(), getPort(), getPriority(), isOurs());
|
||||||
+ this.getPriority() + ")";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import android.util.Log;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.Collections2;
|
import com.google.common.collect.Collections2;
|
||||||
|
import com.google.common.collect.FluentIterable;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
@ -825,8 +827,9 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
|
||||||
this.sendFallbackToIbb();
|
this.sendFallbackToIbb();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
//TODO at this point we can already close other connections to free some resources
|
||||||
final JingleCandidate candidate = connection.getCandidate();
|
final JingleCandidate candidate = connection.getCandidate();
|
||||||
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": elected candidate " + candidate.getHost() + ":" + candidate.getPort());
|
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": elected candidate " + candidate.toString());
|
||||||
this.mJingleStatus = JINGLE_STATUS_TRANSMITTING;
|
this.mJingleStatus = JINGLE_STATUS_TRANSMITTING;
|
||||||
if (connection.needsActivation()) {
|
if (connection.needsActivation()) {
|
||||||
if (connection.getCandidate().isOurs()) {
|
if (connection.getCandidate().isOurs()) {
|
||||||
|
@ -875,38 +878,23 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
|
||||||
}
|
}
|
||||||
|
|
||||||
private JingleSocks5Transport chooseConnection() {
|
private JingleSocks5Transport chooseConnection() {
|
||||||
JingleSocks5Transport connection = null;
|
final List<JingleSocks5Transport> establishedConnections = FluentIterable.from(connections.entrySet())
|
||||||
for (Entry<String, JingleSocks5Transport> cursor : connections
|
.transform(Entry::getValue)
|
||||||
.entrySet()) {
|
.filter(c -> (c != null && c.isEstablished() && (c.getCandidate().isUsedByCounterpart() || !c.getCandidate().isOurs())))
|
||||||
JingleSocks5Transport currentConnection = cursor.getValue();
|
.toSortedList((a, b) -> {
|
||||||
// Log.d(Config.LOGTAG,"comparing candidate: "+currentConnection.getCandidate().toString());
|
final int compare = Integer.compare(b.getCandidate().getPriority(), a.getCandidate().getPriority());
|
||||||
if (currentConnection.isEstablished()
|
if (compare == 0) {
|
||||||
&& (currentConnection.getCandidate().isUsedByCounterpart() || (!currentConnection
|
|
||||||
.getCandidate().isOurs()))) {
|
|
||||||
// Log.d(Config.LOGTAG,"is usable");
|
|
||||||
if (connection == null) {
|
|
||||||
connection = currentConnection;
|
|
||||||
} else {
|
|
||||||
if (connection.getCandidate().getPriority() < currentConnection
|
|
||||||
.getCandidate().getPriority()) {
|
|
||||||
connection = currentConnection;
|
|
||||||
} else if (connection.getCandidate().getPriority() == currentConnection
|
|
||||||
.getCandidate().getPriority()) {
|
|
||||||
// Log.d(Config.LOGTAG,"found two candidates with same priority");
|
|
||||||
if (isInitiator()) {
|
if (isInitiator()) {
|
||||||
if (currentConnection.getCandidate().isOurs()) {
|
//pick the one we sent a candidate-used for (meaning not ours)
|
||||||
connection = currentConnection;
|
return a.getCandidate().isOurs() ? 1 : -1;
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (!currentConnection.getCandidate().isOurs()) {
|
//pick the one they sent a candidate-used for (meaning ours)
|
||||||
connection = currentConnection;
|
return a.getCandidate().isOurs() ? -1 : 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return compare;
|
||||||
}
|
});
|
||||||
}
|
return Iterables.getFirst(establishedConnections, null);
|
||||||
}
|
|
||||||
return connection;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendSuccess() {
|
private void sendSuccess() {
|
||||||
|
|
Loading…
Reference in New Issue