summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2019-12-13 15:58:58 +0100
committercyBerta <cyberta@riseup.net>2019-12-13 16:00:03 +0100
commit2267c1d82c5c0ccd3d1cd2fe9e723709c993643c (patch)
treede4b0a6d58d74205c578d90efbced5624d1f22b9 /app/src/main
parent0977dcb66048d3039d6ff84b8d484ec90cf1c38e (diff)
improve better server balancing: update eip-service.json every 3 days after a successful connection in order to recognize newly added gateways (#8974)
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java8
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Provider.java19
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java1
3 files changed, 23 insertions, 5 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java b/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java
index 1a0214dd..eceba0db 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java
@@ -141,6 +141,7 @@ class EipSetupObserver extends BroadcastReceiver implements VpnStatus.StateListe
Provider provider;
switch (resultCode) {
case CORRECTLY_DOWNLOADED_EIP_SERVICE:
+ Log.d(TAG, "correctly updated service json");
provider = resultData.getParcelable(PROVIDER_KEY);
ProviderObservable.getInstance().updateProvider(provider);
PreferenceHelper.storeProviderInPreferences(preferences, provider);
@@ -269,10 +270,9 @@ class EipSetupObserver extends BroadcastReceiver implements VpnStatus.StateListe
//??
} else if ("CONNECTED".equals(state)) {
//saveLastProfile(context.getApplicationContext(), setupVpnProfile.getUUIDString());
- if (setupNClosestGateway.get() > 0) {
- //at least one failed gateway -> did the provider change it's gateways?
- SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
- Provider provider = getSavedProviderFromSharedPreferences(preferences);
+ Provider provider = ProviderObservable.getInstance().getCurrentProvider();
+ if (setupNClosestGateway.get() > 0 || provider.shouldUpdateEipServiceJson()) {
+ //setupNClostestGateway > 0: at least one failed gateway -> did the provider change it's gateways?
ProviderAPICommand.execute(context, ProviderAPI.DOWNLOAD_SERVICE_JSON, provider);
}
finishGatewaySetup(false);
diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java
index 067f9b2e..507a11bf 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Provider.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java
@@ -44,6 +44,7 @@ import static se.leap.bitmaskclient.ProviderAPI.ERRORS;
*/
public final class Provider implements Parcelable {
+ private static long EIP_SERVICE_TIMEOUT = 1000 * 60 * 60 * 24 * 3;
private JSONObject definition = new JSONObject(); // Represents our Provider's provider.json
private JSONObject eipServiceJson = new JSONObject();
private DefaultedURL mainUrl = new DefaultedURL();
@@ -54,6 +55,7 @@ public final class Provider implements Parcelable {
private String apiVersion = "";
private String privateKey = "";
private String vpnCertificate = "";
+ private long lastEipServiceUpdate = 0L;
private boolean allowAnonymous;
private boolean allowRegistered;
@@ -268,6 +270,7 @@ public final class Provider implements Parcelable {
parcel.writeString(getEipServiceJsonString());
parcel.writeString(getPrivateKey());
parcel.writeString(getVpnCertificate());
+ parcel.writeLong(lastEipServiceUpdate);
}
@Override
@@ -286,7 +289,8 @@ public final class Provider implements Parcelable {
privateKey.equals(p.getPrivateKey()) &&
vpnCertificate.equals(p.getVpnCertificate()) &&
allowAnonymous == p.allowsAnonymous() &&
- allowRegistered == p.allowsRegistered();
+ allowRegistered == p.allowsRegistered() &&
+ lastEipServiceUpdate == p.getLastEipServiceUpdate();
} else return false;
}
@@ -336,6 +340,7 @@ public final class Provider implements Parcelable {
if (!tmpString.isEmpty()) {
this.setVpnCertificate(tmpString);
}
+ this.lastEipServiceUpdate = in.readLong();
} catch (MalformedURLException | JSONException e) {
e.printStackTrace();
}
@@ -368,6 +373,18 @@ public final class Provider implements Parcelable {
return allowRegistered;
}
+ public void setLastEipServiceUpdate(long timestamp) {
+ lastEipServiceUpdate = timestamp;
+ }
+
+ public long getLastEipServiceUpdate() {
+ return lastEipServiceUpdate;
+ }
+
+ public boolean shouldUpdateEipServiceJson() {
+ return System.currentTimeMillis() - lastEipServiceUpdate >= EIP_SERVICE_TIMEOUT;
+ }
+
public boolean setEipServiceJson(JSONObject eipServiceJson) {
if (eipServiceJson.has(ERRORS)) {
return false;
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java b/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java
index 46782802..0baa4e0d 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java
@@ -216,6 +216,7 @@ public abstract class ProviderApiManagerBase {
}
break;
case DOWNLOAD_SERVICE_JSON:
+ Log.d(TAG, "update eip service json");
result = getAndSetEipServiceJson(provider);
if (result.getBoolean(BROADCAST_RESULT_KEY)) {
sendToReceiverOrBroadcast(receiver, CORRECTLY_DOWNLOADED_EIP_SERVICE, result, provider);