Skip to content
Snippets Groups Projects
Commit bce7d19e authored by akwizgran's avatar akwizgran
Browse files

Add method for checking whether bridges should be used.

parent 2e43dfcd
No related branches found
No related tags found
1 merge request!17Update bridges, refactor bridge configuration
Pipeline #16208 canceled
...@@ -50,6 +50,11 @@ public interface CircumventionProvider { ...@@ -50,6 +50,11 @@ public interface CircumventionProvider {
*/ */
String[] COUNTRIES_SNOWFLAKE = {"BY", "CN", "EG", "HK", "IR", "RU", "TM"}; String[] COUNTRIES_SNOWFLAKE = {"BY", "CN", "EG", "HK", "IR", "RU", "TM"};
/**
* Returns true if bridges should be used by default in the given country.
*/
boolean shouldUseBridges(String countryCode);
/** /**
* Returns the types of bridge connection that are suitable for the given country, or * Returns the types of bridge connection that are suitable for the given country, or
* {@link BridgeType#DEFAULT_OBFS4} and {@link BridgeType#VANILLA} if we don't have any * {@link BridgeType#DEFAULT_OBFS4} and {@link BridgeType#VANILLA} if we don't have any
...@@ -57,17 +62,6 @@ public interface CircumventionProvider { ...@@ -57,17 +62,6 @@ public interface CircumventionProvider {
*/ */
List<BridgeType> getSuitableBridgeTypes(String countryCode); List<BridgeType> getSuitableBridgeTypes(String countryCode);
/**
* Returns bridges of the given type that are usable in the given country.
*
* @param letsEncrypt Specifies whether the client is able to verify Let's Encrypt TLS
* certificates signed with the IdentTrust DST Root X3 certificate. Versions of Android
* older than 7.1 consider the certificate to have expired at the end of September 2021.
* This parameter is currently ignored, as no domain-fronted bridges use Let's Encrypt
* certificates.
*/
List<String> getBridges(BridgeType type, String countryCode, boolean letsEncrypt);
/** /**
* Returns bridges of the given type that are usable in the given country. * Returns bridges of the given type that are usable in the given country.
*/ */
......
...@@ -39,6 +39,15 @@ class CircumventionProviderImpl implements CircumventionProvider { ...@@ -39,6 +39,15 @@ class CircumventionProviderImpl implements CircumventionProvider {
CircumventionProviderImpl() { CircumventionProviderImpl() {
} }
@Override
public boolean shouldUseBridges(String countryCode) {
return USE_DEFAULT_OBFS4.contains(countryCode) ||
USE_NON_DEFAULT_OBFS4.contains(countryCode) ||
USE_VANILLA.contains(countryCode) ||
USE_MEEK.contains(countryCode) ||
USE_SNOWFLAKE.contains(countryCode);
}
@Override @Override
public List<BridgeType> getSuitableBridgeTypes(String countryCode) { public List<BridgeType> getSuitableBridgeTypes(String countryCode) {
List<BridgeType> types = new ArrayList<>(); List<BridgeType> types = new ArrayList<>();
...@@ -55,12 +64,6 @@ class CircumventionProviderImpl implements CircumventionProvider { ...@@ -55,12 +64,6 @@ class CircumventionProviderImpl implements CircumventionProvider {
return types; return types;
} }
@Override
public List<String> getBridges(BridgeType type, String countryCode, boolean letsEncrypt) {
// The `letsEncrypt` parameter is ignored, as no domain-fronted bridges use Let's Encrypt
return getBridges(type, countryCode);
}
@Override @Override
public List<String> getBridges(BridgeType type, String countryCode) { public List<String> getBridges(BridgeType type, String countryCode) {
ClassLoader cl = getClass().getClassLoader(); ClassLoader cl = getClass().getClassLoader();
......
...@@ -21,6 +21,27 @@ public class CircumventionProviderImplTest extends BaseTest { ...@@ -21,6 +21,27 @@ public class CircumventionProviderImplTest extends BaseTest {
private final CircumventionProviderImpl provider = private final CircumventionProviderImpl provider =
new CircumventionProviderImpl(); new CircumventionProviderImpl();
@Test
public void testShouldUseBridges() {
for (String countryCode : COUNTRIES_DEFAULT_OBFS4) {
assertTrue(provider.shouldUseBridges(countryCode));
}
for (String countryCode : COUNTRIES_NON_DEFAULT_OBFS4) {
assertTrue(provider.shouldUseBridges(countryCode));
}
for (String countryCode : COUNTRIES_VANILLA) {
assertTrue(provider.shouldUseBridges(countryCode));
}
for (String countryCode : COUNTRIES_MEEK) {
assertTrue(provider.shouldUseBridges(countryCode));
}
for (String countryCode : COUNTRIES_SNOWFLAKE) {
assertTrue(provider.shouldUseBridges(countryCode));
}
assertFalse(provider.shouldUseBridges("US"));
assertFalse(provider.shouldUseBridges("ZZ"));
}
@Test @Test
public void testGetSuitableBridgeTypes() { public void testGetSuitableBridgeTypes() {
for (String countryCode : COUNTRIES_DEFAULT_OBFS4) { for (String countryCode : COUNTRIES_DEFAULT_OBFS4) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment