mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Pass mailbox properties to hook when pairing.
This commit is contained in:
@@ -49,10 +49,8 @@ public interface MailboxSettingsManager {
|
|||||||
* Called when Briar is paired with a mailbox
|
* Called when Briar is paired with a mailbox
|
||||||
*
|
*
|
||||||
* @param txn A read-write transaction
|
* @param txn A read-write transaction
|
||||||
* @param ownOnion Our new mailbox's onion (56 base32 chars)
|
|
||||||
*/
|
*/
|
||||||
void mailboxPaired(Transaction txn, String ownOnion,
|
void mailboxPaired(Transaction txn, MailboxProperties p)
|
||||||
List<MailboxVersion> serverSupports)
|
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ class MailboxSettingsManagerImpl implements MailboxSettingsManager {
|
|||||||
encodeServerSupports(serverSupports, s);
|
encodeServerSupports(serverSupports, s);
|
||||||
settingsManager.mergeSettings(txn, s, SETTINGS_NAMESPACE);
|
settingsManager.mergeSettings(txn, s, SETTINGS_NAMESPACE);
|
||||||
for (MailboxHook hook : hooks) {
|
for (MailboxHook hook : hooks) {
|
||||||
hook.mailboxPaired(txn, p.getOnion(), p.getServerSupports());
|
hook.mailboxPaired(txn, p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,6 +89,10 @@ class MailboxSettingsManagerImpl implements MailboxSettingsManager {
|
|||||||
Settings s = new Settings();
|
Settings s = new Settings();
|
||||||
s.put(SETTINGS_KEY_ONION, "");
|
s.put(SETTINGS_KEY_ONION, "");
|
||||||
s.put(SETTINGS_KEY_TOKEN, "");
|
s.put(SETTINGS_KEY_TOKEN, "");
|
||||||
|
s.put(SETTINGS_KEY_ATTEMPTS, "");
|
||||||
|
s.put(SETTINGS_KEY_LAST_ATTEMPT, "");
|
||||||
|
s.put(SETTINGS_KEY_LAST_SUCCESS, "");
|
||||||
|
s.put(SETTINGS_KEY_SERVER_SUPPORTS, "");
|
||||||
settingsManager.mergeSettings(txn, s, SETTINGS_NAMESPACE);
|
settingsManager.mergeSettings(txn, s, SETTINGS_NAMESPACE);
|
||||||
for (MailboxHook hook : hooks) {
|
for (MailboxHook hook : hooks) {
|
||||||
hook.mailboxUnpaired(txn);
|
hook.mailboxUnpaired(txn);
|
||||||
|
|||||||
@@ -159,10 +159,11 @@ class MailboxUpdateManagerImpl implements MailboxUpdateManager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mailboxPaired(Transaction txn, String ownOnion,
|
public void mailboxPaired(Transaction txn, MailboxProperties p)
|
||||||
List<MailboxVersion> serverSupports) throws DbException {
|
throws DbException {
|
||||||
for (Contact c : db.getContacts(txn)) {
|
for (Contact c : db.getContacts(txn)) {
|
||||||
createAndSendUpdateWithMailbox(txn, c, serverSupports, ownOnion);
|
createAndSendUpdateWithMailbox(txn, c, p.getServerSupports(),
|
||||||
|
p.getOnion());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.briarproject.bramble.api.db.Transaction;
|
|||||||
import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
|
import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxProperties;
|
import org.briarproject.bramble.api.mailbox.MailboxProperties;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxSettingsManager;
|
import org.briarproject.bramble.api.mailbox.MailboxSettingsManager;
|
||||||
|
import org.briarproject.bramble.api.mailbox.MailboxSettingsManager.MailboxHook;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxStatus;
|
import org.briarproject.bramble.api.mailbox.MailboxStatus;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxVersion;
|
import org.briarproject.bramble.api.mailbox.MailboxVersion;
|
||||||
import org.briarproject.bramble.api.mailbox.event.OwnMailboxConnectionStatusEvent;
|
import org.briarproject.bramble.api.mailbox.event.OwnMailboxConnectionStatusEvent;
|
||||||
@@ -39,6 +40,7 @@ public class MailboxSettingsManagerImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
private final SettingsManager settingsManager =
|
private final SettingsManager settingsManager =
|
||||||
context.mock(SettingsManager.class);
|
context.mock(SettingsManager.class);
|
||||||
|
private final MailboxHook hook = context.mock(MailboxHook.class);
|
||||||
|
|
||||||
private final MailboxSettingsManager manager =
|
private final MailboxSettingsManager manager =
|
||||||
new MailboxSettingsManagerImpl(settingsManager);
|
new MailboxSettingsManagerImpl(settingsManager);
|
||||||
@@ -47,6 +49,8 @@ public class MailboxSettingsManagerImplTest extends BrambleMockTestCase {
|
|||||||
private final MailboxAuthToken token = new MailboxAuthToken(getRandomId());
|
private final MailboxAuthToken token = new MailboxAuthToken(getRandomId());
|
||||||
private final List<MailboxVersion> serverSupports =
|
private final List<MailboxVersion> serverSupports =
|
||||||
asList(new MailboxVersion(1, 0), new MailboxVersion(1, 1));
|
asList(new MailboxVersion(1, 0), new MailboxVersion(1, 1));
|
||||||
|
private final MailboxProperties properties = new MailboxProperties(onion,
|
||||||
|
token, serverSupports);
|
||||||
private final int[] serverSupportsInts = {1, 0, 1, 1};
|
private final int[] serverSupportsInts = {1, 0, 1, 1};
|
||||||
private final ContactId contactId1 = new ContactId(random.nextInt());
|
private final ContactId contactId1 = new ContactId(random.nextInt());
|
||||||
private final ContactId contactId2 = new ContactId(random.nextInt());
|
private final ContactId contactId2 = new ContactId(random.nextInt());
|
||||||
@@ -98,17 +102,40 @@ public class MailboxSettingsManagerImplTest extends BrambleMockTestCase {
|
|||||||
expectedSettings.put(SETTINGS_KEY_TOKEN, token.toString());
|
expectedSettings.put(SETTINGS_KEY_TOKEN, token.toString());
|
||||||
expectedSettings.putIntArray(SETTINGS_KEY_SERVER_SUPPORTS,
|
expectedSettings.putIntArray(SETTINGS_KEY_SERVER_SUPPORTS,
|
||||||
serverSupportsInts);
|
serverSupportsInts);
|
||||||
MailboxProperties properties = new MailboxProperties(onion, token,
|
|
||||||
serverSupports);
|
manager.registerMailboxHook(hook);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(settingsManager).mergeSettings(txn, expectedSettings,
|
oneOf(settingsManager).mergeSettings(txn, expectedSettings,
|
||||||
SETTINGS_NAMESPACE);
|
SETTINGS_NAMESPACE);
|
||||||
|
oneOf(hook).mailboxPaired(txn, properties);
|
||||||
}});
|
}});
|
||||||
|
|
||||||
manager.setOwnMailboxProperties(txn, properties);
|
manager.setOwnMailboxProperties(txn, properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemovesProperties() throws Exception {
|
||||||
|
Transaction txn = new Transaction(null, false);
|
||||||
|
Settings expectedSettings = new Settings();
|
||||||
|
expectedSettings.put(SETTINGS_KEY_ONION, "");
|
||||||
|
expectedSettings.put(SETTINGS_KEY_TOKEN, "");
|
||||||
|
expectedSettings.put(SETTINGS_KEY_ATTEMPTS, "");
|
||||||
|
expectedSettings.put(SETTINGS_KEY_LAST_ATTEMPT, "");
|
||||||
|
expectedSettings.put(SETTINGS_KEY_LAST_SUCCESS, "");
|
||||||
|
expectedSettings.put(SETTINGS_KEY_SERVER_SUPPORTS, "");
|
||||||
|
|
||||||
|
manager.registerMailboxHook(hook);
|
||||||
|
|
||||||
|
context.checking(new Expectations() {{
|
||||||
|
oneOf(settingsManager).mergeSettings(txn, expectedSettings,
|
||||||
|
SETTINGS_NAMESPACE);
|
||||||
|
oneOf(hook).mailboxUnpaired(txn);
|
||||||
|
}});
|
||||||
|
|
||||||
|
manager.removeOwnMailboxProperties(txn);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReturnsDefaultStatusIfSettingsAreEmpty() throws Exception {
|
public void testReturnsDefaultStatusIfSettingsAreEmpty() throws Exception {
|
||||||
Transaction txn = new Transaction(null, true);
|
Transaction txn = new Transaction(null, true);
|
||||||
@@ -182,7 +209,7 @@ public class MailboxSettingsManagerImplTest extends BrambleMockTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
manager.recordSuccessfulConnection(txn, now, versions);
|
manager.recordSuccessfulConnection(txn, now, versions);
|
||||||
hasEvent(txn, OwnMailboxConnectionStatusEvent.class);
|
assertTrue(hasEvent(txn, OwnMailboxConnectionStatusEvent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -78,7 +78,6 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
|
|||||||
private final BdfList someClientSupports;
|
private final BdfList someClientSupports;
|
||||||
private final List<MailboxVersion> newerClientSupportsList;
|
private final List<MailboxVersion> newerClientSupportsList;
|
||||||
private final BdfList newerClientSupports;
|
private final BdfList newerClientSupports;
|
||||||
private final List<MailboxVersion> someServerSupportsList;
|
|
||||||
private final BdfList someServerSupports;
|
private final BdfList someServerSupports;
|
||||||
private final BdfList emptyServerSupports = new BdfList();
|
private final BdfList emptyServerSupports = new BdfList();
|
||||||
private final MailboxProperties updateProps;
|
private final MailboxProperties updateProps;
|
||||||
@@ -100,8 +99,8 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
|
|||||||
newerClientSupportsList.get(0).getMajor(),
|
newerClientSupportsList.get(0).getMajor(),
|
||||||
newerClientSupportsList.get(0).getMinor()));
|
newerClientSupportsList.get(0).getMinor()));
|
||||||
|
|
||||||
someServerSupportsList = singletonList(new MailboxVersion(
|
List<MailboxVersion> someServerSupportsList =
|
||||||
rnd.nextInt(), rnd.nextInt()));
|
singletonList(new MailboxVersion(rnd.nextInt(), rnd.nextInt()));
|
||||||
someServerSupports = BdfList.of(BdfList.of(
|
someServerSupports = BdfList.of(BdfList.of(
|
||||||
someServerSupportsList.get(0).getMajor(),
|
someServerSupportsList.get(0).getMajor(),
|
||||||
someServerSupportsList.get(0).getMinor()));
|
someServerSupportsList.get(0).getMinor()));
|
||||||
@@ -679,7 +678,7 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
MailboxUpdateManagerImpl t = createInstance(someClientSupportsList);
|
MailboxUpdateManagerImpl t = createInstance(someClientSupportsList);
|
||||||
t.mailboxPaired(txn, ownProps.getOnion(), someServerSupportsList);
|
t.mailboxPaired(txn, ownProps);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user