summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2020-07-24 16:30:02 +0200
committercyBerta <cyberta@riseup.net>2020-07-24 16:30:02 +0200
commite986a294ec3e328bd48bb4c423fe835d1aa2dc69 (patch)
treea2c13ab9d29c27da15c191f65b013e8d515a6a88 /app/src/main/java
parent501a451b8b932e1f0e001599dbfe53810cb9ead0 (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/java')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java21
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;
}