mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
Factor out mailbox constants into a MailboxConfig
so that we can change them for integration tests via the new ModularMailboxModule that now also includes the UrlProvider
This commit is contained in:
@@ -20,12 +20,15 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
class MailboxApiCallerImpl implements MailboxApiCaller {
|
||||
|
||||
private final TaskScheduler taskScheduler;
|
||||
private final MailboxConfig mailboxConfig;
|
||||
private final Executor ioExecutor;
|
||||
|
||||
@Inject
|
||||
MailboxApiCallerImpl(TaskScheduler taskScheduler,
|
||||
MailboxConfig mailboxConfig,
|
||||
@IoExecutor Executor ioExecutor) {
|
||||
this.taskScheduler = taskScheduler;
|
||||
this.mailboxConfig = mailboxConfig;
|
||||
this.ioExecutor = ioExecutor;
|
||||
}
|
||||
|
||||
@@ -49,7 +52,8 @@ class MailboxApiCallerImpl implements MailboxApiCaller {
|
||||
private boolean cancelled = false;
|
||||
|
||||
@GuardedBy("lock")
|
||||
private long retryIntervalMs = MIN_RETRY_INTERVAL_MS;
|
||||
private long retryIntervalMs =
|
||||
mailboxConfig.getApiCallerMinRetryInterval();
|
||||
|
||||
private Task(ApiCall apiCall) {
|
||||
this.apiCall = apiCall;
|
||||
@@ -74,8 +78,9 @@ class MailboxApiCallerImpl implements MailboxApiCaller {
|
||||
scheduledTask = taskScheduler.schedule(this::callApi,
|
||||
ioExecutor, retryIntervalMs, MILLISECONDS);
|
||||
// Increase the retry interval each time we retry
|
||||
retryIntervalMs =
|
||||
min(MAX_RETRY_INTERVAL_MS, retryIntervalMs * 2);
|
||||
retryIntervalMs = min(
|
||||
mailboxConfig.getApiCallerMaxRetryInterval(),
|
||||
retryIntervalMs * 2);
|
||||
}
|
||||
} else {
|
||||
synchronized (lock) {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.briarproject.bramble.mailbox;
|
||||
|
||||
import org.briarproject.bramble.api.plugin.Plugin;
|
||||
|
||||
interface MailboxConfig {
|
||||
|
||||
/**
|
||||
* The minimum interval between API call retries in milliseconds.
|
||||
*/
|
||||
long getApiCallerMinRetryInterval();
|
||||
|
||||
/**
|
||||
* The maximum interval between API call retries in milliseconds.
|
||||
*/
|
||||
long getApiCallerMaxRetryInterval();
|
||||
|
||||
/**
|
||||
* How long (in milliseconds) the Tor plugin needs to be continuously
|
||||
* {@link Plugin.State#ACTIVE active} before we assume our contacts can
|
||||
* reach our hidden service.
|
||||
*/
|
||||
long getTorReachabilityPeriod();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.briarproject.bramble.mailbox;
|
||||
|
||||
import org.briarproject.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
class MailboxConfigImpl implements MailboxConfig {
|
||||
|
||||
@Inject
|
||||
MailboxConfigImpl() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getApiCallerMinRetryInterval() {
|
||||
return MailboxApiCaller.MIN_RETRY_INTERVAL_MS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getApiCallerMaxRetryInterval() {
|
||||
return MailboxApiCaller.MAX_RETRY_INTERVAL_MS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTorReachabilityPeriod() {
|
||||
return TorReachabilityMonitor.REACHABILITY_PERIOD_MS;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,11 @@ import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
@Module
|
||||
public class UrlConverterModule {
|
||||
public class ModularMailboxModule {
|
||||
@Provides
|
||||
MailboxConfig provideMailboxConfig(MailboxConfigImpl mailboxConfig) {
|
||||
return mailboxConfig;
|
||||
}
|
||||
|
||||
@Provides
|
||||
UrlConverter provideUrlConverter(UrlConverterImpl urlConverter) {
|
||||
@@ -32,6 +32,7 @@ class TorReachabilityMonitorImpl
|
||||
|
||||
private final Executor ioExecutor;
|
||||
private final TaskScheduler taskScheduler;
|
||||
private final MailboxConfig mailboxConfig;
|
||||
private final PluginManager pluginManager;
|
||||
private final EventBus eventBus;
|
||||
private final Object lock = new Object();
|
||||
@@ -50,10 +51,12 @@ class TorReachabilityMonitorImpl
|
||||
TorReachabilityMonitorImpl(
|
||||
@IoExecutor Executor ioExecutor,
|
||||
TaskScheduler taskScheduler,
|
||||
MailboxConfig mailboxConfig,
|
||||
PluginManager pluginManager,
|
||||
EventBus eventBus) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.taskScheduler = taskScheduler;
|
||||
this.mailboxConfig = mailboxConfig;
|
||||
this.pluginManager = pluginManager;
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
@@ -110,7 +113,7 @@ class TorReachabilityMonitorImpl
|
||||
synchronized (lock) {
|
||||
if (destroyed || task != null) return;
|
||||
task = taskScheduler.schedule(this::onTorReachable, ioExecutor,
|
||||
REACHABILITY_PERIOD_MS, MILLISECONDS);
|
||||
mailboxConfig.getTorReachabilityPeriod(), MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user