summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2020-07-24 17:40:15 +0200
committercyBerta <cyberta@riseup.net>2020-07-24 17:40:15 +0200
commitd1ddaa7b10fde24b0b5f07369d1a22c221b81287 (patch)
tree2128ffb7fe977e56664623308bda358d100c87e1 /app/src/main
parente986a294ec3e328bd48bb4c423fe835d1aa2dc69 (diff)
fix bug in vpn profile based gateway order detection, write additional tests for it
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java4
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java28
2 files changed, 20 insertions, 12 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java
index 589fa751..f3eea415 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java
@@ -157,6 +157,10 @@ public class Gateway {
return vpnProfiles.get(transportType);
}
+ public boolean suppoortsTransport(Connection.TransportType transportType) {
+ return vpnProfiles.get(transportType) != null;
+ }
+
public int getTimezone() {
return timezone;
}
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 f3773758..0515a35e 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java
@@ -84,7 +84,7 @@ public class GatewaysManager {
int found = 0;
int i = 0;
while ((gateway = gatewaySelector.select(i)) != null) {
- if (gateway.getProfile(transportType) != null) {
+ if (gateway.suppoortsTransport(transportType)) {
if (found == nClosest) {
return gateway;
}
@@ -98,7 +98,7 @@ public class GatewaysManager {
private Gateway getGatewayFromPresortedList(int nClosest, Connection.TransportType transportType) {
int found = 0;
for (Gateway gateway : presortedList) {
- if (gateway.getProfile(transportType) != null) {
+ if (gateway.suppoortsTransport(transportType)) {
if (found == nClosest) {
return gateway;
}
@@ -123,14 +123,14 @@ public class GatewaysManager {
private int getPositionFromPresortedList(VpnProfile profile) {
Connection.TransportType transportType = profile.mUsePluggableTransports ? OBFS4 : OPENVPN;
- Gateway gateway;
int nClosest = 0;
- while ((nClosest < presortedList.size())) {
- gateway = presortedList.get(nClosest);
- if (profile.equals(gateway.getProfile(transportType))) {
- return nClosest;
+ for (Gateway gateway : presortedList) {
+ if (gateway.suppoortsTransport(transportType)) {
+ if (profile.equals(gateway.getProfile(transportType))) {
+ return nClosest;
+ }
+ nClosest++;
}
- nClosest++;
}
return -1;
}
@@ -140,11 +140,15 @@ public class GatewaysManager {
GatewaySelector gatewaySelector = new GatewaySelector(new ArrayList<>(gateways.values()));
Gateway gateway;
int nClosest = 0;
- while ((gateway = gatewaySelector.select(nClosest)) != null) {
- if (profile.equals(gateway.getProfile(transportType))) {
- return nClosest;
+ int i = 0;
+ while ((gateway = gatewaySelector.select(i)) != null) {
+ if (gateway.suppoortsTransport(transportType)) {
+ if (profile.equals(gateway.getProfile(transportType))) {
+ return nClosest;
+ }
+ nClosest++;
}
- nClosest++;
+ i++;
}
return -1;
}