mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Add method for unpairing to MailboxManager
This commit is contained in:
@@ -2,6 +2,7 @@ package org.briarproject.bramble.api.mailbox;
|
||||
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -41,4 +42,10 @@ public interface MailboxManager {
|
||||
*/
|
||||
boolean checkConnection();
|
||||
|
||||
/**
|
||||
* Unpairs the owner's mailbox and tries to wipe it.
|
||||
* As this makes a network call, it should be run on the {@link IoExecutor}.
|
||||
*/
|
||||
@IoExecutor
|
||||
void unPair() throws DbException;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ public interface MailboxSettingsManager {
|
||||
void setOwnMailboxProperties(Transaction txn, MailboxProperties p)
|
||||
throws DbException;
|
||||
|
||||
void removeOwnMailboxProperties(Transaction txn) throws DbException;
|
||||
|
||||
MailboxStatus getOwnMailboxStatus(Transaction txn) throws DbException;
|
||||
|
||||
void recordSuccessfulConnection(Transaction txn, long now)
|
||||
|
||||
@@ -131,4 +131,18 @@ class MailboxManagerImpl implements MailboxManager {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unPair() throws DbException {
|
||||
MailboxProperties properties = db.transactionWithNullableResult(true,
|
||||
mailboxSettingsManager::getOwnMailboxProperties);
|
||||
try {
|
||||
api.wipeMailbox(properties);
|
||||
} catch (IOException | MailboxApi.ApiException e) {
|
||||
// We wipe on a best-effort basis.
|
||||
// If we can't do it, we still unpair.
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
db.transaction(false,
|
||||
mailboxSettingsManager::removeOwnMailboxProperties);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,17 @@ class MailboxSettingsManagerImpl implements MailboxSettingsManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeOwnMailboxProperties(Transaction txn) throws DbException {
|
||||
Settings s = new Settings();
|
||||
s.put(SETTINGS_KEY_ONION, "");
|
||||
s.put(SETTINGS_KEY_TOKEN, "");
|
||||
settingsManager.mergeSettings(txn, s, SETTINGS_NAMESPACE);
|
||||
for (MailboxHook hook : hooks) {
|
||||
hook.mailboxUnpaired(txn);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MailboxStatus getOwnMailboxStatus(Transaction txn)
|
||||
throws DbException {
|
||||
|
||||
Reference in New Issue
Block a user