summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient/base/models
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2022-07-15 16:31:48 +0200
committercyBerta <cyberta@riseup.net>2022-07-19 00:06:12 +0200
commit95c923f2850ac409e8413cc4902c69848c64d7c8 (patch)
tree8c5bb3cdfde0719449e3f9ea3293bda3d975d99e /app/src/main/java/se/leap/bitmaskclient/base/models
parent1f12d1b99a88bf62f29798a30135473299978234 (diff)
Parse different obfs4 flavors from eip-service.json. In the gateway load / gateway selection UI all pluggable transports flavors will be summed up and handled the same way. A gateway can support both obfs4 and the kcp flavor.
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/base/models')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java1
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/models/Location.java19
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/models/Pair.java57
3 files changed, 66 insertions, 11 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java b/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java
index d7a54fcc..b34a31eb 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java
@@ -44,6 +44,7 @@ public interface Constants {
String USE_SNOWFLAKE = "use_snowflake";
String PREFER_UDP = "prefer_UDP";
String GATEWAY_PINNING = "gateway_pinning";
+ String ALLOW_EXPERIMENTAL_TRANSPORTS = "allow_experimental_transports";
//////////////////////////////////////////////
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/models/Location.java b/app/src/main/java/se/leap/bitmaskclient/base/models/Location.java
index 064f25c0..26f6b14a 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/models/Location.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/models/Location.java
@@ -21,10 +21,7 @@ import androidx.annotation.NonNull;
import java.util.Comparator;
import java.util.HashMap;
-import java.util.HashSet;
-import java.util.function.ToDoubleFunction;
-import de.blinkt.openvpn.core.connection.Connection;
import de.blinkt.openvpn.core.connection.Connection.TransportType;
public class Location implements Cloneable {
@@ -50,27 +47,27 @@ public class Location implements Cloneable {
}
public boolean supportsTransport(TransportType transportType) {
- return numberOfGateways.containsKey(transportType);
+ return numberOfGateways.containsKey(transportType.getMetaType());
}
public void setAverageLoad(TransportType transportType, double load) {
- averageLoad.put(transportType, load);
+ averageLoad.put(transportType.getMetaType(), load);
}
public double getAverageLoad(TransportType transportType) {
- if (averageLoad.containsKey(transportType)) {
- return averageLoad.get(transportType);
+ if (averageLoad.containsKey(transportType.getMetaType())) {
+ return averageLoad.get(transportType.getMetaType());
}
return 0;
}
public void setNumberOfGateways(TransportType transportType, int numbers) {
- numberOfGateways.put(transportType, numbers);
+ numberOfGateways.put(transportType.getMetaType(), numbers);
}
public int getNumberOfGateways(TransportType transportType) {
- if (numberOfGateways.containsKey(transportType)) {
- return numberOfGateways.get(transportType);
+ if (numberOfGateways.containsKey(transportType.getMetaType())) {
+ return numberOfGateways.get(transportType.getMetaType());
}
return 0;
}
@@ -112,7 +109,7 @@ public class Location implements Cloneable {
public static class SortByAverageLoad implements Comparator<Location> {
TransportType transportType;
public SortByAverageLoad(TransportType transportType) {
- this.transportType = transportType;
+ this.transportType = transportType.getMetaType();
}
@Override
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/models/Pair.java b/app/src/main/java/se/leap/bitmaskclient/base/models/Pair.java
new file mode 100644
index 00000000..e2ef4622
--- /dev/null
+++ b/app/src/main/java/se/leap/bitmaskclient/base/models/Pair.java
@@ -0,0 +1,57 @@
+package se.leap.bitmaskclient.base.models;
+
+import java.util.Objects;
+
+/**
+ * Container to ease passing around a tuple of two objects. This object provides a sensible
+ * implementation of equals(), returning true if equals() is true on each of the contained
+ * objects.
+ */
+public class Pair<F, S> {
+ public final F first;
+ public final S second;
+
+ /**
+ * Constructor for a Pair.
+ *
+ * @param first the first object in the Pair
+ * @param second the second object in the pair
+ */
+ public Pair(F first, S second) {
+ this.first = first;
+ this.second = second;
+ }
+
+ /**
+ * Checks the two objects for equality by delegating to their respective
+ * {@link Object#equals(Object)} methods.
+ *
+ * @param o the {@link Pair} to which this one is to be checked for equality
+ * @return true if the underlying objects of the Pair are both considered
+ * equal
+ */
+ @Override
+ public boolean equals(Object o) {
+ if (!(o instanceof Pair)) {
+ return false;
+ }
+ Pair<?, ?> p = (Pair<?, ?>) o;
+ return Objects.equals(p.first, first) && Objects.equals(p.second, second);
+ }
+
+ /**
+ * Compute a hash code using the hash codes of the underlying objects
+ *
+ * @return a hashcode of the Pair
+ */
+ @Override
+ public int hashCode() {
+ return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());
+ }
+
+ @Override
+ public String toString() {
+ return "Pair{" + String.valueOf(first) + " " + String.valueOf(second) + "}";
+ }
+
+}