From 939901a89abb169648423473056260335d3af639 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 6 Apr 2023 01:08:05 +0200 Subject: first pass on obfs4-hop pt integration --- .../blinkt/openvpn/core/connection/Connection.java | 56 ++++++++++++++++++++-- 1 file changed, 52 insertions(+), 4 deletions(-) (limited to 'app/src/main/java/de/blinkt/openvpn/core/connection/Connection.java') diff --git a/app/src/main/java/de/blinkt/openvpn/core/connection/Connection.java b/app/src/main/java/de/blinkt/openvpn/core/connection/Connection.java index 137b3f16..6dc78a30 100644 --- a/app/src/main/java/de/blinkt/openvpn/core/connection/Connection.java +++ b/app/src/main/java/de/blinkt/openvpn/core/connection/Connection.java @@ -5,6 +5,8 @@ package de.blinkt.openvpn.core.connection; +import static de.blinkt.openvpn.core.connection.Connection.TransportType.*; + import android.text.TextUtils; import com.google.gson.annotations.JsonAdapter; @@ -42,7 +44,7 @@ public abstract class Connection implements Serializable, Cloneable { TCP("tcp"), KCP("kcp"); - String protocol; + final String protocol; TransportProtocol(String transportProtocol) { this.protocol = transportProtocol; @@ -55,11 +57,12 @@ public abstract class Connection implements Serializable, Cloneable { } public enum TransportType { OBFS4("obfs4"), + OBFS4_HOP("obfs4Hop"), OPENVPN("openvpn"), PT("metaTransport"); - String transport; + final String transport; TransportType(String transportType) { this.transport = transportType; @@ -70,12 +73,57 @@ public abstract class Connection implements Serializable, Cloneable { return transport; } + public int toInt() { + switch (this) { + case PT: + return 0; + case OPENVPN: + return 1; + case OBFS4: + return 2; + case OBFS4_HOP: + return 3; + default: + return -1; + } + } + + public static TransportType fromString(String value) { + switch (value) { + case "obfs4": + return OBFS4; + case "obfs4-hop": + return OBFS4_HOP; + case "metaTransport": + return PT; + case "openvpn": + return OPENVPN; + default: + throw new IllegalArgumentException(value + " is not a valid value for TransportType."); + } + } + + public static TransportType fromInt(int value) { + switch (value) { + case 0: + return PT; + case 1: + return OPENVPN; + case 2: + return OBFS4; + case 3: + return OBFS4_HOP; + default: + return null; + } + } + public boolean isPluggableTransport() { - return this == OBFS4 || this == PT; + return this == OBFS4 || this == OBFS4_HOP || this == PT; } public TransportType getMetaType() { - if (this == OBFS4 || this == PT) { + if (this == OBFS4 || this == OBFS4_HOP || this == PT) { return PT; } return OPENVPN; -- cgit v1.2.3