Include mailbox server versions in MailboxStatus

so we know if the mailbox is incompatible with Briar
This commit is contained in:
Torsten Grote
2022-05-27 09:45:51 -03:00
parent b161a5e115
commit 0f4aa8027a
4 changed files with 62 additions and 13 deletions

View File

@@ -15,6 +15,12 @@ public interface MailboxConstants {
*/
TransportId ID = new TransportId("org.briarproject.bramble.mailbox");
/**
* The highest major version of the mailbox server
* that this client supports.
*/
int MAILBOX_VERSION_MAJOR = 1;
/**
* The maximum length of a file that can be uploaded to or downloaded from
* a mailbox.

View File

@@ -2,8 +2,11 @@ package org.briarproject.bramble.api.mailbox;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.util.List;
import javax.annotation.concurrent.Immutable;
import static org.briarproject.bramble.api.mailbox.MailboxConstants.MAILBOX_VERSION_MAJOR;
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;
@@ -13,12 +16,15 @@ public class MailboxStatus {
private final long lastAttempt, lastSuccess;
private final int attemptsSinceSuccess;
private final List<MailboxVersion> serverSupports;
public MailboxStatus(long lastAttempt, long lastSuccess,
int attemptsSinceSuccess) {
int attemptsSinceSuccess,
List<MailboxVersion> serverSupports) {
this.lastAttempt = lastAttempt;
this.lastSuccess = lastSuccess;
this.attemptsSinceSuccess = attemptsSinceSuccess;
this.serverSupports = serverSupports;
}
/**
@@ -67,4 +73,16 @@ public class MailboxStatus {
return attemptsSinceSuccess >= PROBLEM_NUM_CONNECTION_FAILURES &&
(now - lastSuccess) >= PROBLEM_MS_SINCE_LAST_SUCCESS;
}
/**
* @return true if the Mailbox is incompatible with this version of Briar,
* so that the mailbox needs to be updated.
*/
public boolean isMailboxIncompatible() {
for (MailboxVersion version : serverSupports) {
if (version.getMajor() <= MAILBOX_VERSION_MAJOR) return false;
}
return true;
}
}