diff options
author | cyBerta <cyberta@riseup.net> | 2020-07-24 16:30:02 +0200 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2020-07-24 16:30:02 +0200 |
commit | e986a294ec3e328bd48bb4c423fe835d1aa2dc69 (patch) | |
tree | a2c13ab9d29c27da15c191f65b013e8d515a6a88 /app/src/main | |
parent | 501a451b8b932e1f0e001599dbfe53810cb9ead0 (diff) |
fix bug in gateway selection - always iterate through all gateways and count those supporting the requested transport in order to get the nClosest gateway; adding more tests
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java index aa10ffae..f3773758 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java @@ -81,22 +81,29 @@ public class GatewaysManager { List<Gateway> list = new ArrayList<>(gateways.values()); GatewaySelector gatewaySelector = new GatewaySelector(list); Gateway gateway; - while ((gateway = gatewaySelector.select(nClosest)) != null) { + int found = 0; + int i = 0; + while ((gateway = gatewaySelector.select(i)) != null) { if (gateway.getProfile(transportType) != null) { - return gateway; + if (found == nClosest) { + return gateway; + } + found++; } - nClosest++; + i++; } return null; } private Gateway getGatewayFromPresortedList(int nClosest, Connection.TransportType transportType) { - while (nClosest < presortedList.size()) { - Gateway gateway = presortedList.get(nClosest); + int found = 0; + for (Gateway gateway : presortedList) { if (gateway.getProfile(transportType) != null) { - return gateway; + if (found == nClosest) { + return gateway; + } + found++; } - nClosest++; } return null; } |