mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 04:39:54 +01:00
Use numeric IDs rather than names to identify transports.
This commit is contained in:
@@ -73,7 +73,7 @@ public class ProtocolIntegrationTest extends TestCase {
|
||||
private final Message message, message1, message2, message3;
|
||||
private final String authorName = "Alice";
|
||||
private final String messageBody = "Hello world";
|
||||
private final Map<String, Map<String, String>> transports;
|
||||
private final Map<Integer, Map<String, String>> transports;
|
||||
|
||||
public ProtocolIntegrationTest() throws Exception {
|
||||
super();
|
||||
@@ -114,7 +114,7 @@ public class ProtocolIntegrationTest extends TestCase {
|
||||
message3 = messageEncoder.encodeMessage(null, group1,
|
||||
groupKeyPair.getPrivate(), author, authorKeyPair.getPrivate(),
|
||||
messageBody.getBytes("UTF-8"));
|
||||
transports = Collections.singletonMap("foo",
|
||||
transports = Collections.singletonMap(transportId,
|
||||
Collections.singletonMap("bar", "baz"));
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public abstract class DatabaseComponentTest extends TestCase {
|
||||
private final byte[] raw;
|
||||
private final Message message, privateMessage;
|
||||
private final Group group;
|
||||
private final Map<String, Map<String, String>> transports;
|
||||
private final Map<Integer, Map<String, String>> transports;
|
||||
private final byte[] secret;
|
||||
|
||||
public DatabaseComponentTest() {
|
||||
@@ -72,7 +72,7 @@ public abstract class DatabaseComponentTest extends TestCase {
|
||||
privateMessage =
|
||||
new TestMessage(messageId, null, null, null, timestamp, raw);
|
||||
group = new TestGroup(groupId, "The really exciting group", null);
|
||||
transports = Collections.singletonMap("foo",
|
||||
transports = Collections.singletonMap(123,
|
||||
Collections.singletonMap("bar", "baz"));
|
||||
secret = new byte[123];
|
||||
}
|
||||
@@ -1284,15 +1284,15 @@ public abstract class DatabaseComponentTest extends TestCase {
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).getTransports(txn);
|
||||
will(returnValue(Collections.singletonMap("foo", properties)));
|
||||
oneOf(database).setTransportProperties(txn, "foo", properties1);
|
||||
will(returnValue(Collections.singletonMap(123, properties)));
|
||||
oneOf(database).setTransportProperties(txn, 123, properties1);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
oneOf(listener).eventOccurred(Event.TRANSPORTS_UPDATED);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner);
|
||||
|
||||
db.addListener(listener);
|
||||
db.setTransportProperties("foo", properties1);
|
||||
db.setTransportProperties(123, properties1);
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
@@ -1311,13 +1311,13 @@ public abstract class DatabaseComponentTest extends TestCase {
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).getTransports(txn);
|
||||
will(returnValue(Collections.singletonMap("foo", properties)));
|
||||
will(returnValue(Collections.singletonMap(123, properties)));
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner);
|
||||
|
||||
db.addListener(listener);
|
||||
db.setTransportProperties("foo", properties);
|
||||
db.setTransportProperties(123, properties);
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
@@ -1336,16 +1336,16 @@ public abstract class DatabaseComponentTest extends TestCase {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).getTransportConfig(txn, "foo");
|
||||
oneOf(database).getTransportConfig(txn, 123);
|
||||
will(returnValue(config));
|
||||
oneOf(database).setTransportConfig(txn, "foo", config1);
|
||||
oneOf(database).setTransportConfig(txn, 123, config1);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
oneOf(listener).eventOccurred(Event.TRANSPORTS_UPDATED);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner);
|
||||
|
||||
db.addListener(listener);
|
||||
db.setTransportConfig("foo", config1);
|
||||
db.setTransportConfig(123, config1);
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
@@ -1363,14 +1363,14 @@ public abstract class DatabaseComponentTest extends TestCase {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).getTransportConfig(txn, "foo");
|
||||
oneOf(database).getTransportConfig(txn, 123);
|
||||
will(returnValue(config));
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner);
|
||||
|
||||
db.addListener(listener);
|
||||
db.setTransportConfig("foo", config);
|
||||
db.setTransportConfig(123, config);
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
private final byte[] raw;
|
||||
private final Message message, privateMessage;
|
||||
private final Group group;
|
||||
private final Map<String, Map<String, String>> transports;
|
||||
private final Map<Integer, Map<String, String>> transports;
|
||||
private final Map<Group, Long> subscriptions;
|
||||
private final byte[] secret;
|
||||
|
||||
@@ -91,7 +91,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
privateMessage =
|
||||
new TestMessage(privateMessageId, null, null, null, timestamp, raw);
|
||||
group = groupFactory.createGroup(groupId, "Group name", null);
|
||||
transports = Collections.singletonMap("foo",
|
||||
transports = Collections.singletonMap(123,
|
||||
Collections.singletonMap("bar", "baz"));
|
||||
subscriptions = Collections.singletonMap(group, 0L);
|
||||
secret = new byte[123];
|
||||
@@ -991,27 +991,28 @@ public class H2DatabaseTest extends TestCase {
|
||||
assertEquals(transports, db.getTransports(txn, contactId));
|
||||
|
||||
// Replace the transport properties
|
||||
Map<String, Map<String, String>> transports1 =
|
||||
new TreeMap<String, Map<String, String>>();
|
||||
transports1.put("foo", Collections.singletonMap("bar", "baz"));
|
||||
transports1.put("bar", Collections.singletonMap("baz", "quux"));
|
||||
Map<Integer, Map<String, String>> transports1 =
|
||||
new TreeMap<Integer, Map<String, String>>();
|
||||
transports1.put(123, Collections.singletonMap("bar", "baz"));
|
||||
transports1.put(456, Collections.singletonMap("baz", "quux"));
|
||||
db.setTransports(txn, contactId, transports1, 1);
|
||||
assertEquals(transports1, db.getTransports(txn, contactId));
|
||||
|
||||
// Remove the transport properties
|
||||
db.setTransports(txn, contactId,
|
||||
Collections.<String, Map<String, String>>emptyMap(), 2);
|
||||
Collections.<Integer, Map<String, String>>emptyMap(), 2);
|
||||
assertEquals(Collections.emptyMap(), db.getTransports(txn, contactId));
|
||||
|
||||
// Set the local transport properties
|
||||
for(String name : transports.keySet()) {
|
||||
db.setTransportProperties(txn, name, transports.get(name));
|
||||
for(Integer transportId : transports.keySet()) {
|
||||
Map<String, String> properties = transports.get(transportId);
|
||||
db.setTransportProperties(txn, transportId, properties);
|
||||
}
|
||||
assertEquals(transports, db.getTransports(txn));
|
||||
|
||||
// Remove the local transport properties
|
||||
for(String name : transports.keySet()) {
|
||||
db.setTransportProperties(txn, name,
|
||||
for(Integer transportId : transports.keySet()) {
|
||||
db.setTransportProperties(txn, transportId,
|
||||
Collections.<String, String>emptyMap());
|
||||
}
|
||||
assertEquals(Collections.emptyMap(), db.getTransports(txn));
|
||||
@@ -1029,17 +1030,17 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Set the transport config
|
||||
db.setTransportConfig(txn, "foo", config);
|
||||
assertEquals(config, db.getTransportConfig(txn, "foo"));
|
||||
db.setTransportConfig(txn, 123, config);
|
||||
assertEquals(config, db.getTransportConfig(txn, 123));
|
||||
|
||||
// Update the transport config
|
||||
db.setTransportConfig(txn, "foo", config1);
|
||||
assertEquals(config1, db.getTransportConfig(txn, "foo"));
|
||||
db.setTransportConfig(txn, 123, config1);
|
||||
assertEquals(config1, db.getTransportConfig(txn, 123));
|
||||
|
||||
// Remove the transport config
|
||||
db.setTransportConfig(txn, "foo",
|
||||
db.setTransportConfig(txn, 123,
|
||||
Collections.<String, String>emptyMap());
|
||||
assertEquals(Collections.emptyMap(), db.getTransportConfig(txn, "foo"));
|
||||
assertEquals(Collections.emptyMap(), db.getTransportConfig(txn, 123));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
@@ -1055,18 +1056,18 @@ public class H2DatabaseTest extends TestCase {
|
||||
assertEquals(transports, db.getTransports(txn, contactId));
|
||||
|
||||
// Replace the transport properties using a timestamp of 2
|
||||
Map<String, Map<String, String>> transports1 =
|
||||
new TreeMap<String, Map<String, String>>();
|
||||
transports1.put("foo", Collections.singletonMap("bar", "baz"));
|
||||
transports1.put("bar", Collections.singletonMap("baz", "quux"));
|
||||
Map<Integer, Map<String, String>> transports1 =
|
||||
new TreeMap<Integer, Map<String, String>>();
|
||||
transports1.put(123, Collections.singletonMap("bar", "baz"));
|
||||
transports1.put(456, Collections.singletonMap("baz", "quux"));
|
||||
db.setTransports(txn, contactId, transports1, 2);
|
||||
assertEquals(transports1, db.getTransports(txn, contactId));
|
||||
|
||||
// Try to replace the transport properties using a timestamp of 1
|
||||
Map<String, Map<String, String>> transports2 =
|
||||
new TreeMap<String, Map<String, String>>();
|
||||
transports2.put("bar", Collections.singletonMap("baz", "quux"));
|
||||
transports2.put("baz", Collections.singletonMap("quux", "fnord"));
|
||||
Map<Integer, Map<String, String>> transports2 =
|
||||
new TreeMap<Integer, Map<String, String>>();
|
||||
transports2.put(456, Collections.singletonMap("baz", "quux"));
|
||||
transports2.put(789, Collections.singletonMap("quux", "fnord"));
|
||||
db.setTransports(txn, contactId, transports2, 1);
|
||||
|
||||
// The old properties should still be there
|
||||
|
||||
@@ -47,7 +47,7 @@ public class ProtocolReadWriteTest extends TestCase {
|
||||
private final String messageBody = "Hello world";
|
||||
private final BitSet bitSet;
|
||||
private final Map<Group, Long> subscriptions;
|
||||
private final Map<String, Map<String, String>> transports;
|
||||
private final Map<Integer, Map<String, String>> transports;
|
||||
private final long timestamp = System.currentTimeMillis();
|
||||
|
||||
public ProtocolReadWriteTest() throws Exception {
|
||||
@@ -67,7 +67,7 @@ public class ProtocolReadWriteTest extends TestCase {
|
||||
bitSet.set(3);
|
||||
bitSet.set(7);
|
||||
subscriptions = Collections.singletonMap(group, 123L);
|
||||
transports = Collections.singletonMap("foo",
|
||||
transports = Collections.singletonMap(123,
|
||||
Collections.singletonMap("bar", "baz"));
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.security.PrivateKey;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.briar.TestUtils;
|
||||
@@ -189,13 +190,10 @@ public class ConstantsTest extends TestCase {
|
||||
public void testTransportsFitIntoUpdate() throws Exception {
|
||||
// Create the maximum number of plugins, each with the maximum number
|
||||
// of maximum-length properties
|
||||
Map<String, Map<String, String>> transports =
|
||||
new HashMap<String, Map<String, String>>(
|
||||
TransportUpdate.MAX_PLUGINS_PER_UPDATE);
|
||||
Map<Integer, Map<String, String>> transports =
|
||||
new TreeMap<Integer, Map<String, String>>();
|
||||
for(int i = 0; i < TransportUpdate.MAX_PLUGINS_PER_UPDATE; i++) {
|
||||
String name = createRandomString(TransportUpdate.MAX_NAME_LENGTH);
|
||||
Map<String, String> properties = new HashMap<String, String>(
|
||||
TransportUpdate.MAX_PROPERTIES_PER_PLUGIN);
|
||||
Map<String, String> properties = new TreeMap<String, String>();
|
||||
for(int j = 0; j < TransportUpdate.MAX_PROPERTIES_PER_PLUGIN; j++) {
|
||||
String key = createRandomString(
|
||||
TransportUpdate.MAX_KEY_OR_VALUE_LENGTH);
|
||||
@@ -203,7 +201,7 @@ public class ConstantsTest extends TestCase {
|
||||
TransportUpdate.MAX_KEY_OR_VALUE_LENGTH);
|
||||
properties.put(key, value);
|
||||
}
|
||||
transports.put(name, properties);
|
||||
transports.put(i, properties);
|
||||
}
|
||||
// Add the transports to an update
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(
|
||||
@@ -212,8 +210,7 @@ public class ConstantsTest extends TestCase {
|
||||
t.writeTransports(transports, Long.MAX_VALUE);
|
||||
// Check the size of the serialised update
|
||||
assertTrue(out.size() > TransportUpdate.MAX_PLUGINS_PER_UPDATE *
|
||||
(TransportUpdate.MAX_NAME_LENGTH +
|
||||
TransportUpdate.MAX_PROPERTIES_PER_PLUGIN *
|
||||
(4 + TransportUpdate.MAX_PROPERTIES_PER_PLUGIN *
|
||||
TransportUpdate.MAX_KEY_OR_VALUE_LENGTH * 2) + 8);
|
||||
assertTrue(out.size() <= ProtocolConstants.MAX_PACKET_LENGTH);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class BatchConnectionReadWriteTest extends TestCase {
|
||||
private final File testDir = TestUtils.getTestDirectory();
|
||||
private final File aliceDir = new File(testDir, "alice");
|
||||
private final File bobDir = new File(testDir, "bob");
|
||||
private final Map<String, Map<String, String>> transports =
|
||||
private final Map<Integer, Map<String, String>> transports =
|
||||
Collections.emptyMap();
|
||||
private final byte[] aliceSecret, bobSecret;
|
||||
private final int transportId = 123;
|
||||
|
||||
Reference in New Issue
Block a user