mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
New polling logic for Bluetooth. #251
The polling interval increases exponentially each time polling is unsuccessful, up to a maximum of 60 minutes. The interval is reset to 2 minutes whenever a connection is made and whenever Bluetooth is re-enabled.
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package org.briarproject.plugins;
|
||||
|
||||
import org.briarproject.api.plugins.Backoff;
|
||||
import org.briarproject.api.plugins.BackoffFactory;
|
||||
|
||||
class BackoffFactoryImpl implements BackoffFactory {
|
||||
|
||||
@Override
|
||||
public Backoff createBackoff(int minInterval, int maxInterval,
|
||||
double base) {
|
||||
return new BackoffImpl(minInterval, maxInterval, base);
|
||||
}
|
||||
}
|
||||
37
briar-core/src/org/briarproject/plugins/BackoffImpl.java
Normal file
37
briar-core/src/org/briarproject/plugins/BackoffImpl.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package org.briarproject.plugins;
|
||||
|
||||
import org.briarproject.api.plugins.Backoff;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
class BackoffImpl implements Backoff {
|
||||
|
||||
private final int minInterval, maxInterval;
|
||||
private final double base;
|
||||
private final AtomicInteger backoff;
|
||||
|
||||
BackoffImpl(int minInterval, int maxInterval, double base) {
|
||||
this.minInterval = minInterval;
|
||||
this.maxInterval = maxInterval;
|
||||
this.base = base;
|
||||
backoff = new AtomicInteger(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPollingInterval() {
|
||||
double multiplier = Math.pow(base, backoff.get());
|
||||
// Large or infinite values will be rounded to Integer.MAX_VALUE
|
||||
int interval = (int) (minInterval * multiplier);
|
||||
return Math.min(interval, maxInterval);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void increment() {
|
||||
backoff.incrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
backoff.set(0);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,21 @@
|
||||
package org.briarproject.plugins;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.api.plugins.BackoffFactory;
|
||||
import org.briarproject.api.plugins.ConnectionManager;
|
||||
import org.briarproject.api.plugins.ConnectionRegistry;
|
||||
import org.briarproject.api.plugins.PluginManager;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
public class PluginsModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(BackoffFactory.class).to(BackoffFactoryImpl.class);
|
||||
bind(Poller.class).to(PollerImpl.class);
|
||||
bind(ConnectionManager.class).to(ConnectionManagerImpl.class);
|
||||
bind(ConnectionRegistry.class).to(
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package org.briarproject.plugins;
|
||||
|
||||
import static java.util.logging.Level.INFO;
|
||||
import org.briarproject.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.api.plugins.ConnectionRegistry;
|
||||
import org.briarproject.api.plugins.Plugin;
|
||||
import org.briarproject.api.system.Timer;
|
||||
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -8,10 +11,7 @@ import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.briarproject.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.api.plugins.ConnectionRegistry;
|
||||
import org.briarproject.api.plugins.Plugin;
|
||||
import org.briarproject.api.system.Timer;
|
||||
import static java.util.logging.Level.INFO;
|
||||
|
||||
class PollerImpl implements Poller {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user