summaryrefslogtreecommitdiff
path: root/app/src/main/java/se
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2019-10-19 01:53:03 +0200
committercyBerta <cyberta@riseup.net>2019-10-19 01:53:03 +0200
commit2e51f351bd9581adfb0e0d6da2bc4255cc139ad2 (patch)
treec8c39ec94b1e9572be378d8bd576b16d906d1bba /app/src/main/java/se
parent6053926be4aab408547ec77d6208cf4e2448eb51 (diff)
fix gateway selection wrt. supported transport
Diffstat (limited to 'app/src/main/java/se')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java32
1 files changed, 31 insertions, 1 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 17a15c95..fbe1861a 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java
@@ -31,6 +31,7 @@ import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.LinkedHashMap;
+import de.blinkt.openvpn.VpnProfile;
import de.blinkt.openvpn.core.ConfigParser;
import de.blinkt.openvpn.core.VpnStatus;
import de.blinkt.openvpn.core.connection.Connection;
@@ -38,6 +39,8 @@ import se.leap.bitmaskclient.Provider;
import se.leap.bitmaskclient.ProviderObservable;
import se.leap.bitmaskclient.utils.PreferenceHelper;
+import static de.blinkt.openvpn.core.connection.Connection.TransportType.OBFS4;
+import static de.blinkt.openvpn.core.connection.Connection.TransportType.OPENVPN;
import static se.leap.bitmaskclient.Constants.GATEWAYS;
import static se.leap.bitmaskclient.Constants.PROVIDER_PRIVATE_KEY;
import static se.leap.bitmaskclient.Constants.PROVIDER_VPN_CERTIFICATE;
@@ -71,8 +74,35 @@ public class GatewaysManager {
* @return the n closest Gateway
*/
public Gateway select(int nClosest) {
+ Connection.TransportType transportType = getUsePluggableTransports(context) ? OBFS4 : OPENVPN;
GatewaySelector gatewaySelector = new GatewaySelector(new ArrayList<>(gateways.values()));
- return gatewaySelector.select(nClosest);
+ Gateway gateway;
+ while ((gateway = gatewaySelector.select(nClosest)) != null) {
+ if (gateway.getProfile(transportType) != null) {
+ return gateway;
+ }
+ nClosest++;
+ }
+ return null;
+ }
+
+ /**
+ * Get position of the gateway from a sorted set (along the distance of the gw to your time zone)
+ * @param profile profile belonging to a gateway
+ * @return position of the gateway owning to the profile
+ */
+ public int getPosition(VpnProfile profile) {
+ Connection.TransportType transportType = getUsePluggableTransports(context) ? OBFS4 : OPENVPN;
+ 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;
+ }
+ nClosest++;
+ }
+ return -1;
}
/**