Merge branch '252-lan-polling' into 'master'

New polling logic for LAN. #252

Same approach as !104. Modified the poller to cancel any scheduled poll when pollNow() is called and randomise the next polling interval so plugins that call pollNow() at the same time don't end up polling in sync.

Depends on !104. Fixes #252.

See merge request !105
This commit is contained in:
akwizgran
2016-02-24 20:11:54 +00:00
13 changed files with 139 additions and 146 deletions

View File

@@ -46,7 +46,7 @@ public class AndroidPluginsModule extends PluginsModule {
DuplexPluginFactory tor = new TorPluginFactory(ioExecutor, appContext,
locationUtils, eventBus);
DuplexPluginFactory lan = new AndroidLanTcpPluginFactory(ioExecutor,
appContext);
backoffFactory, appContext);
final Collection<DuplexPluginFactory> factories =
Arrays.asList(bluetooth, tor, lan);
return new DuplexPluginConfig() {

View File

@@ -1,14 +1,5 @@
package org.briarproject.plugins.tcp;
import static android.content.Context.CONNECTIVITY_SERVICE;
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
import static android.net.ConnectivityManager.TYPE_WIFI;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -16,6 +7,16 @@ import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import org.briarproject.api.plugins.Backoff;
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
import static android.content.Context.CONNECTIVITY_SERVICE;
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
import static android.net.ConnectivityManager.TYPE_WIFI;
class AndroidLanTcpPlugin extends LanTcpPlugin {
private static final Logger LOG =
@@ -25,10 +26,10 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
private volatile BroadcastReceiver networkStateReceiver = null;
AndroidLanTcpPlugin(Executor ioExecutor, Context appContext,
DuplexPluginCallback callback, int maxLatency,
int maxIdleTime, int pollingInterval) {
super(ioExecutor, callback, maxLatency, maxIdleTime, pollingInterval);
AndroidLanTcpPlugin(Executor ioExecutor, Backoff backoff,
Context appContext, DuplexPluginCallback callback, int maxLatency,
int maxIdleTime) {
super(ioExecutor, backoff, callback, maxLatency, maxIdleTime);
this.appContext = appContext;
}

View File

@@ -1,25 +1,32 @@
package org.briarproject.plugins.tcp;
import java.util.concurrent.Executor;
import android.content.Context;
import org.briarproject.api.TransportId;
import org.briarproject.api.plugins.Backoff;
import org.briarproject.api.plugins.BackoffFactory;
import org.briarproject.api.plugins.duplex.DuplexPlugin;
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
import android.content.Context;
import java.util.concurrent.Executor;
public class AndroidLanTcpPluginFactory implements DuplexPluginFactory {
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
private static final int MAX_IDLE_TIME = 30 * 1000; // 30 seconds
private static final int POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes
private static final int MIN_POLLING_INTERVAL = 2 * 60 * 1000; // 2 minutes
private static final int MAX_POLLING_INTERVAL = 60 * 60 * 1000; // 1 hour
private static final double BACKOFF_BASE = 1.2;
private final Executor ioExecutor;
private final BackoffFactory backoffFactory;
private final Context appContext;
public AndroidLanTcpPluginFactory(Executor ioExecutor, Context appContext) {
public AndroidLanTcpPluginFactory(Executor ioExecutor,
BackoffFactory backoffFactory, Context appContext) {
this.ioExecutor = ioExecutor;
this.backoffFactory = backoffFactory;
this.appContext = appContext;
}
@@ -28,7 +35,9 @@ public class AndroidLanTcpPluginFactory implements DuplexPluginFactory {
}
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
return new AndroidLanTcpPlugin(ioExecutor, appContext, callback,
MAX_LATENCY, MAX_IDLE_TIME, POLLING_INTERVAL);
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
MAX_POLLING_INTERVAL, BACKOFF_BASE);
return new AndroidLanTcpPlugin(ioExecutor, backoff, appContext,
callback, MAX_LATENCY, MAX_IDLE_TIME);
}
}