mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-22 07:39:53 +01:00
Factor mailbox problem detection into MailboxStatus and constants
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package org.briarproject.bramble.api.mailbox;
|
package org.briarproject.bramble.api.mailbox;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.HOURS;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.MAX_FRAME_LENGTH;
|
import static org.briarproject.bramble.api.transport.TransportConstants.MAX_FRAME_LENGTH;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.MAX_PAYLOAD_LENGTH;
|
import static org.briarproject.bramble.api.transport.TransportConstants.MAX_PAYLOAD_LENGTH;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.STREAM_HEADER_LENGTH;
|
import static org.briarproject.bramble.api.transport.TransportConstants.STREAM_HEADER_LENGTH;
|
||||||
@@ -20,4 +21,17 @@ public interface MailboxConstants {
|
|||||||
int MAX_FILE_PAYLOAD_BYTES =
|
int MAX_FILE_PAYLOAD_BYTES =
|
||||||
(MAX_FILE_BYTES - TAG_LENGTH - STREAM_HEADER_LENGTH)
|
(MAX_FILE_BYTES - TAG_LENGTH - STREAM_HEADER_LENGTH)
|
||||||
/ MAX_FRAME_LENGTH * MAX_PAYLOAD_LENGTH;
|
/ MAX_FRAME_LENGTH * MAX_PAYLOAD_LENGTH;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of connection failures
|
||||||
|
* that indicate a problem with the mailbox.
|
||||||
|
*/
|
||||||
|
int PROBLEM_NUM_CONNECTION_FAILURES = 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The time in milliseconds since the last connection success
|
||||||
|
* that need to pass to indicates a problem with the mailbox.
|
||||||
|
*/
|
||||||
|
long PROBLEM_MS_SINCE_LAST_SUCCESS = HOURS.toMillis(1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|||||||
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.api.mailbox.MailboxConstants.PROBLEM_MS_SINCE_LAST_SUCCESS;
|
||||||
|
import static org.briarproject.bramble.api.mailbox.MailboxConstants.PROBLEM_NUM_CONNECTION_FAILURES;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class MailboxStatus {
|
public class MailboxStatus {
|
||||||
@@ -56,4 +59,12 @@ public class MailboxStatus {
|
|||||||
public int getAttemptsSinceSuccess() {
|
public int getAttemptsSinceSuccess() {
|
||||||
return attemptsSinceSuccess;
|
return attemptsSinceSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if this status indicates a problem with the mailbox.
|
||||||
|
*/
|
||||||
|
public boolean hasProblem(long now) {
|
||||||
|
return attemptsSinceSuccess >= PROBLEM_NUM_CONNECTION_FAILURES &&
|
||||||
|
(now - lastSuccess) >= PROBLEM_MS_SINCE_LAST_SUCCESS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import javax.annotation.Nullable;
|
|||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static java.util.concurrent.TimeUnit.DAYS;
|
|
||||||
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -143,9 +142,7 @@ class MailboxSettingsManagerImpl implements MailboxSettingsManager {
|
|||||||
settingsManager.mergeSettings(txn, newSettings, SETTINGS_NAMESPACE);
|
settingsManager.mergeSettings(txn, newSettings, SETTINGS_NAMESPACE);
|
||||||
MailboxStatus status = new MailboxStatus(now, lastSuccess, newAttempts);
|
MailboxStatus status = new MailboxStatus(now, lastSuccess, newAttempts);
|
||||||
txn.attach(new OwnMailboxConnectionStatusEvent(status));
|
txn.attach(new OwnMailboxConnectionStatusEvent(status));
|
||||||
if (now - lastSuccess > DAYS.toMillis(3) && newAttempts > 10) {
|
if (status.hasProblem(now)) txn.attach(new MailboxProblemEvent());
|
||||||
txn.attach(new MailboxProblemEvent());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ public class MailboxStatusFragment extends Fragment {
|
|||||||
tintRes = R.color.briar_brand_green;
|
tintRes = R.color.briar_brand_green;
|
||||||
showUnlinkWarning = true;
|
showUnlinkWarning = true;
|
||||||
wizardButton.setVisibility(GONE);
|
wizardButton.setVisibility(GONE);
|
||||||
} else if (status.getAttemptsSinceSuccess() < NUM_FAILURES) {
|
} else if (!status.hasProblem(System.currentTimeMillis())) {
|
||||||
iconRes = R.drawable.ic_help_outline_white;
|
iconRes = R.drawable.ic_help_outline_white;
|
||||||
title = getString(R.string.mailbox_status_problem_title);
|
title = getString(R.string.mailbox_status_problem_title);
|
||||||
tintRes = R.color.briar_orange_500;
|
tintRes = R.color.briar_orange_500;
|
||||||
|
|||||||
Reference in New Issue
Block a user