mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
ENH: Replaces transport config with namespaced settings
This commit is contained in:
@@ -3,7 +3,7 @@ package org.briarproject.db;
|
||||
import org.briarproject.BriarTestCase;
|
||||
import org.briarproject.TestMessage;
|
||||
import org.briarproject.TestUtils;
|
||||
import org.briarproject.api.TransportConfig;
|
||||
import org.briarproject.api.Settings;
|
||||
import org.briarproject.api.TransportId;
|
||||
import org.briarproject.api.TransportProperties;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
@@ -611,13 +611,13 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
||||
oneOf(database).commitTransaction(txn);
|
||||
oneOf(eventBus).broadcast(with(any(ContactAddedEvent.class)));
|
||||
// Check whether the transport is in the DB (which it's not)
|
||||
exactly(8).of(database).startTransaction();
|
||||
exactly(6).of(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
exactly(2).of(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
exactly(8).of(database).containsTransport(txn, transportId);
|
||||
exactly(6).of(database).containsTransport(txn, transportId);
|
||||
will(returnValue(false));
|
||||
exactly(8).of(database).abortTransaction(txn);
|
||||
exactly(6).of(database).abortTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||
shutdown);
|
||||
@@ -625,13 +625,6 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
||||
db.addLocalAuthor(localAuthor);
|
||||
assertEquals(contactId, db.addContact(author, localAuthorId));
|
||||
|
||||
try {
|
||||
db.getConfig(transportId);
|
||||
fail();
|
||||
} catch (NoSuchTransportException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.getLocalProperties(transportId);
|
||||
fail();
|
||||
@@ -646,13 +639,6 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.mergeConfig(transportId, new TransportConfig());
|
||||
fail();
|
||||
} catch (NoSuchTransportException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.mergeLocalProperties(transportId, new TransportProperties());
|
||||
fail();
|
||||
|
||||
@@ -4,7 +4,6 @@ import org.briarproject.BriarTestCase;
|
||||
import org.briarproject.TestDatabaseConfig;
|
||||
import org.briarproject.TestMessage;
|
||||
import org.briarproject.TestUtils;
|
||||
import org.briarproject.api.TransportConfig;
|
||||
import org.briarproject.api.TransportId;
|
||||
import org.briarproject.api.TransportProperties;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
@@ -21,6 +20,7 @@ import org.briarproject.api.sync.MessageId;
|
||||
import org.briarproject.api.transport.IncomingKeys;
|
||||
import org.briarproject.api.transport.OutgoingKeys;
|
||||
import org.briarproject.api.transport.TransportKeys;
|
||||
import org.briarproject.api.Settings;
|
||||
import org.briarproject.system.SystemClock;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -568,7 +568,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateTransportConfig() throws Exception {
|
||||
public void testUpdateSettings() throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
@@ -576,22 +576,22 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addTransport(txn, transportId, 123);
|
||||
|
||||
// Set the transport config
|
||||
TransportConfig c = new TransportConfig();
|
||||
c.put("foo", "foo");
|
||||
c.put("bar", "bar");
|
||||
db.mergeConfig(txn, transportId, c);
|
||||
assertEquals(c, db.getConfig(txn, transportId));
|
||||
Settings s = new Settings();
|
||||
s.put("foo", "foo");
|
||||
s.put("bar", "bar");
|
||||
db.mergeSettings(txn, s, "test");
|
||||
assertEquals(s, db.getSettings(txn, "test"));
|
||||
|
||||
// Update one of the properties and add another
|
||||
TransportConfig c1 = new TransportConfig();
|
||||
c1.put("bar", "baz");
|
||||
c1.put("bam", "bam");
|
||||
db.mergeConfig(txn, transportId, c1);
|
||||
TransportConfig merged = new TransportConfig();
|
||||
Settings s1 = new Settings();
|
||||
s1.put("bar", "baz");
|
||||
s1.put("bam", "bam");
|
||||
db.mergeSettings(txn, s1, "test");
|
||||
Settings merged = new Settings();
|
||||
merged.put("foo", "foo");
|
||||
merged.put("bar", "baz");
|
||||
merged.put("bam", "bam");
|
||||
assertEquals(merged, db.getConfig(txn, transportId));
|
||||
assertEquals(merged, db.getSettings(txn, "test"));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.briarproject.plugins;
|
||||
|
||||
import org.briarproject.api.TransportConfig;
|
||||
import org.briarproject.api.Settings;
|
||||
import org.briarproject.api.TransportProperties;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.crypto.PseudoRandom;
|
||||
@@ -58,19 +58,19 @@ public abstract class DuplexClientTest extends DuplexTest {
|
||||
|
||||
protected static class ClientCallback implements DuplexPluginCallback {
|
||||
|
||||
private TransportConfig config = null;
|
||||
private Settings settings = null;
|
||||
private TransportProperties local = null;
|
||||
private Map<ContactId, TransportProperties> remote = null;
|
||||
|
||||
public ClientCallback(TransportConfig config, TransportProperties local,
|
||||
public ClientCallback(Settings settings, TransportProperties local,
|
||||
Map<ContactId, TransportProperties> remote) {
|
||||
this.config = config;
|
||||
this.settings = settings;
|
||||
this.local = local;
|
||||
this.remote = remote;
|
||||
}
|
||||
|
||||
public TransportConfig getConfig() {
|
||||
return config;
|
||||
public Settings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
public TransportProperties getLocalProperties() {
|
||||
@@ -81,8 +81,8 @@ public abstract class DuplexClientTest extends DuplexTest {
|
||||
return remote;
|
||||
}
|
||||
|
||||
public void mergeConfig(TransportConfig c) {
|
||||
config = c;
|
||||
public void mergeSettings(Settings s) {
|
||||
settings = s;
|
||||
}
|
||||
|
||||
public void mergeLocalProperties(TransportProperties p) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.briarproject.plugins;
|
||||
|
||||
import org.briarproject.api.TransportConfig;
|
||||
import org.briarproject.api.Settings;
|
||||
import org.briarproject.api.TransportProperties;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
||||
@@ -57,19 +57,19 @@ public abstract class DuplexServerTest extends DuplexTest {
|
||||
|
||||
private final CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
private TransportConfig config;
|
||||
private Settings settings;
|
||||
private TransportProperties local;
|
||||
private Map<ContactId, TransportProperties> remote;
|
||||
|
||||
public ServerCallback(TransportConfig config, TransportProperties local,
|
||||
public ServerCallback(Settings settings, TransportProperties local,
|
||||
Map<ContactId, TransportProperties> remote) {
|
||||
this.config = config;
|
||||
this.settings = settings;
|
||||
this.local = local;
|
||||
this.remote = remote;
|
||||
}
|
||||
|
||||
public TransportConfig getConfig() {
|
||||
return config;
|
||||
public Settings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
public TransportProperties getLocalProperties() {
|
||||
@@ -80,8 +80,8 @@ public abstract class DuplexServerTest extends DuplexTest {
|
||||
return remote;
|
||||
}
|
||||
|
||||
public void mergeConfig(TransportConfig c) {
|
||||
config = c;
|
||||
public void mergeSettings(Settings s) {
|
||||
settings = s;
|
||||
}
|
||||
|
||||
public void mergeLocalProperties(TransportProperties p) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.briarproject.plugins.bluetooth;
|
||||
|
||||
import org.briarproject.api.TransportConfig;
|
||||
import org.briarproject.api.Settings;
|
||||
import org.briarproject.api.TransportProperties;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.plugins.DuplexClientTest;
|
||||
@@ -25,7 +25,7 @@ public class BluetoothClientTest extends DuplexClientTest {
|
||||
Map<ContactId, TransportProperties> remote =
|
||||
Collections.singletonMap(contactId, p);
|
||||
// Create the plugin
|
||||
callback = new ClientCallback(new TransportConfig(),
|
||||
callback = new ClientCallback(new Settings(),
|
||||
new TransportProperties(), remote);
|
||||
plugin = new BluetoothPlugin(executor, new SystemClock(),
|
||||
new SecureRandom(), callback, 0, 0);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.briarproject.plugins.bluetooth;
|
||||
|
||||
import org.briarproject.api.TransportConfig;
|
||||
import org.briarproject.api.Settings;
|
||||
import org.briarproject.api.TransportProperties;
|
||||
import org.briarproject.plugins.DuplexServerTest;
|
||||
import org.briarproject.system.SystemClock;
|
||||
@@ -20,7 +20,7 @@ public class BluetoothServerTest extends DuplexServerTest {
|
||||
TransportProperties local = new TransportProperties();
|
||||
local.put("uuid", BluetoothTest.EMPTY_UUID);
|
||||
// Create the plugin
|
||||
callback = new ServerCallback(new TransportConfig(), local,
|
||||
callback = new ServerCallback(new Settings(), local,
|
||||
Collections.singletonMap(contactId, new TransportProperties()));
|
||||
plugin = new BluetoothPlugin(executor, new SystemClock(),
|
||||
new SecureRandom(), callback, 0, 0);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.briarproject.plugins.tcp;
|
||||
|
||||
import org.briarproject.api.TransportConfig;
|
||||
import org.briarproject.api.Settings;
|
||||
import org.briarproject.api.TransportProperties;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.plugins.DuplexClientTest;
|
||||
@@ -28,7 +28,7 @@ public class LanTcpClientTest extends DuplexClientTest {
|
||||
Map<ContactId, TransportProperties> remote =
|
||||
Collections.singletonMap(contactId, p);
|
||||
// Create the plugin
|
||||
callback = new ClientCallback(new TransportConfig(),
|
||||
callback = new ClientCallback(new Settings(),
|
||||
new TransportProperties(), remote);
|
||||
plugin = new LanTcpPlugin(executor, callback, MAX_LATENCY,
|
||||
MAX_IDLE_TIME, POLLING_INTERVAL);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.briarproject.plugins.tcp;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
import org.briarproject.api.TransportConfig;
|
||||
import org.briarproject.api.Settings;
|
||||
import org.briarproject.api.TransportProperties;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
||||
@@ -176,8 +176,8 @@ public class LanTcpPluginTest extends BriarTestCase {
|
||||
private final CountDownLatch connectionsLatch = new CountDownLatch(1);
|
||||
private final TransportProperties local = new TransportProperties();
|
||||
|
||||
public TransportConfig getConfig() {
|
||||
return new TransportConfig();
|
||||
public Settings getSettings() {
|
||||
return new Settings();
|
||||
}
|
||||
|
||||
public TransportProperties getLocalProperties() {
|
||||
@@ -188,7 +188,7 @@ public class LanTcpPluginTest extends BriarTestCase {
|
||||
return remote;
|
||||
}
|
||||
|
||||
public void mergeConfig(TransportConfig c) {}
|
||||
public void mergeSettings(Settings s) {}
|
||||
|
||||
public void mergeLocalProperties(TransportProperties p) {
|
||||
local.putAll(p);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.briarproject.plugins.tcp;
|
||||
|
||||
import org.briarproject.api.TransportConfig;
|
||||
import org.briarproject.api.Settings;
|
||||
import org.briarproject.api.TransportProperties;
|
||||
import org.briarproject.plugins.DuplexServerTest;
|
||||
|
||||
@@ -18,7 +18,7 @@ public class LanTcpServerTest extends DuplexServerTest {
|
||||
private static final int POLLING_INTERVAL = 60 * 1000;
|
||||
|
||||
private LanTcpServerTest(Executor executor) {
|
||||
callback = new ServerCallback(new TransportConfig(),
|
||||
callback = new ServerCallback(new Settings(),
|
||||
new TransportProperties(),
|
||||
Collections.singletonMap(contactId, new TransportProperties()));
|
||||
plugin = new LanTcpPlugin(executor, callback, MAX_LATENCY,
|
||||
|
||||
Reference in New Issue
Block a user