mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-21 15:19:53 +01:00
Discover contacts' BT addresses from incoming connections.
This commit is contained in:
@@ -10,6 +10,8 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.api.plugin.BluetoothConstants.PROP_ADDRESS;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class AndroidBluetoothTransportConnection
|
class AndroidBluetoothTransportConnection
|
||||||
extends AbstractDuplexTransportConnection {
|
extends AbstractDuplexTransportConnection {
|
||||||
@@ -23,6 +25,7 @@ class AndroidBluetoothTransportConnection
|
|||||||
super(plugin);
|
super(plugin);
|
||||||
this.connectionManager = connectionManager;
|
this.connectionManager = connectionManager;
|
||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
|
remote.put(PROP_ADDRESS, socket.getRemoteDevice().getAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|||||||
import org.briarproject.bramble.api.plugin.Plugin;
|
import org.briarproject.bramble.api.plugin.Plugin;
|
||||||
import org.briarproject.bramble.api.plugin.TransportConnectionReader;
|
import org.briarproject.bramble.api.plugin.TransportConnectionReader;
|
||||||
import org.briarproject.bramble.api.plugin.TransportConnectionWriter;
|
import org.briarproject.bramble.api.plugin.TransportConnectionWriter;
|
||||||
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -14,6 +15,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
public abstract class AbstractDuplexTransportConnection
|
public abstract class AbstractDuplexTransportConnection
|
||||||
implements DuplexTransportConnection {
|
implements DuplexTransportConnection {
|
||||||
|
|
||||||
|
protected final TransportProperties remote = new TransportProperties();
|
||||||
|
|
||||||
private final Plugin plugin;
|
private final Plugin plugin;
|
||||||
private final Reader reader;
|
private final Reader reader;
|
||||||
private final Writer writer;
|
private final Writer writer;
|
||||||
@@ -44,6 +47,11 @@ public abstract class AbstractDuplexTransportConnection
|
|||||||
return writer;
|
return writer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProperties getRemoteProperties() {
|
||||||
|
return remote;
|
||||||
|
}
|
||||||
|
|
||||||
private class Reader implements TransportConnectionReader {
|
private class Reader implements TransportConnectionReader {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.briarproject.bramble.api.plugin.duplex;
|
|||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.plugin.TransportConnectionReader;
|
import org.briarproject.bramble.api.plugin.TransportConnectionReader;
|
||||||
import org.briarproject.bramble.api.plugin.TransportConnectionWriter;
|
import org.briarproject.bramble.api.plugin.TransportConnectionWriter;
|
||||||
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface for reading and writing data over a duplex transport. The
|
* An interface for reading and writing data over a duplex transport. The
|
||||||
@@ -23,4 +24,10 @@ public interface DuplexTransportConnection {
|
|||||||
* for writing to the connection.
|
* for writing to the connection.
|
||||||
*/
|
*/
|
||||||
TransportConnectionWriter getWriter();
|
TransportConnectionWriter getWriter();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a possibly empty set of {@link TransportProperties} describing
|
||||||
|
* the remote peer.
|
||||||
|
*/
|
||||||
|
TransportProperties getRemoteProperties();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,14 @@ public interface TransportPropertyManager {
|
|||||||
void addRemoteProperties(Transaction txn, ContactId c,
|
void addRemoteProperties(Transaction txn, ContactId c,
|
||||||
Map<TransportId, TransportProperties> props) throws DbException;
|
Map<TransportId, TransportProperties> props) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the given properties discovered from an incoming transport
|
||||||
|
* connection. They will be overridden by any properties received while
|
||||||
|
* adding the contact or synced from the contact.
|
||||||
|
*/
|
||||||
|
void addRemotePropertiesFromConnection(ContactId c, TransportId t,
|
||||||
|
TransportProperties props) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the local transport properties for all transports.
|
* Returns the local transport properties for all transports.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import org.briarproject.bramble.api.plugin.TransportConnectionReader;
|
|||||||
import org.briarproject.bramble.api.plugin.TransportConnectionWriter;
|
import org.briarproject.bramble.api.plugin.TransportConnectionWriter;
|
||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||||
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
|
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
||||||
import org.briarproject.bramble.api.sync.SyncSession;
|
import org.briarproject.bramble.api.sync.SyncSession;
|
||||||
import org.briarproject.bramble.api.sync.SyncSessionFactory;
|
import org.briarproject.bramble.api.sync.SyncSessionFactory;
|
||||||
import org.briarproject.bramble.api.transport.KeyManager;
|
import org.briarproject.bramble.api.transport.KeyManager;
|
||||||
@@ -52,6 +54,7 @@ class ConnectionManagerImpl implements ConnectionManager {
|
|||||||
private final HandshakeManager handshakeManager;
|
private final HandshakeManager handshakeManager;
|
||||||
private final ContactExchangeManager contactExchangeManager;
|
private final ContactExchangeManager contactExchangeManager;
|
||||||
private final ConnectionRegistry connectionRegistry;
|
private final ConnectionRegistry connectionRegistry;
|
||||||
|
private final TransportPropertyManager transportPropertyManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ConnectionManagerImpl(@IoExecutor Executor ioExecutor,
|
ConnectionManagerImpl(@IoExecutor Executor ioExecutor,
|
||||||
@@ -60,7 +63,8 @@ class ConnectionManagerImpl implements ConnectionManager {
|
|||||||
SyncSessionFactory syncSessionFactory,
|
SyncSessionFactory syncSessionFactory,
|
||||||
HandshakeManager handshakeManager,
|
HandshakeManager handshakeManager,
|
||||||
ContactExchangeManager contactExchangeManager,
|
ContactExchangeManager contactExchangeManager,
|
||||||
ConnectionRegistry connectionRegistry) {
|
ConnectionRegistry connectionRegistry,
|
||||||
|
TransportPropertyManager transportPropertyManager) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
this.keyManager = keyManager;
|
this.keyManager = keyManager;
|
||||||
this.streamReaderFactory = streamReaderFactory;
|
this.streamReaderFactory = streamReaderFactory;
|
||||||
@@ -69,6 +73,7 @@ class ConnectionManagerImpl implements ConnectionManager {
|
|||||||
this.handshakeManager = handshakeManager;
|
this.handshakeManager = handshakeManager;
|
||||||
this.contactExchangeManager = contactExchangeManager;
|
this.contactExchangeManager = contactExchangeManager;
|
||||||
this.connectionRegistry = connectionRegistry;
|
this.connectionRegistry = connectionRegistry;
|
||||||
|
this.transportPropertyManager = transportPropertyManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -269,6 +274,7 @@ class ConnectionManagerImpl implements ConnectionManager {
|
|||||||
private final TransportId transportId;
|
private final TransportId transportId;
|
||||||
private final TransportConnectionReader reader;
|
private final TransportConnectionReader reader;
|
||||||
private final TransportConnectionWriter writer;
|
private final TransportConnectionWriter writer;
|
||||||
|
private final TransportProperties remote;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private volatile SyncSession outgoingSession = null;
|
private volatile SyncSession outgoingSession = null;
|
||||||
@@ -278,6 +284,7 @@ class ConnectionManagerImpl implements ConnectionManager {
|
|||||||
this.transportId = transportId;
|
this.transportId = transportId;
|
||||||
reader = connection.getReader();
|
reader = connection.getReader();
|
||||||
writer = connection.getWriter();
|
writer = connection.getWriter();
|
||||||
|
remote = connection.getRemoteProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -313,13 +320,16 @@ class ConnectionManagerImpl implements ConnectionManager {
|
|||||||
// Start the outgoing session on another thread
|
// Start the outgoing session on another thread
|
||||||
ioExecutor.execute(() -> runOutgoingSession(contactId));
|
ioExecutor.execute(() -> runOutgoingSession(contactId));
|
||||||
try {
|
try {
|
||||||
|
// Store any transport properties discovered from the connection
|
||||||
|
transportPropertyManager.addRemotePropertiesFromConnection(
|
||||||
|
contactId, transportId, remote);
|
||||||
// Create and run the incoming session
|
// Create and run the incoming session
|
||||||
createIncomingSession(ctx, reader).run();
|
createIncomingSession(ctx, reader).run();
|
||||||
reader.dispose(false, true);
|
reader.dispose(false, true);
|
||||||
// Interrupt the outgoing session so it finishes cleanly
|
// Interrupt the outgoing session so it finishes cleanly
|
||||||
SyncSession out = outgoingSession;
|
SyncSession out = outgoingSession;
|
||||||
if (out != null) out.interrupt();
|
if (out != null) out.interrupt();
|
||||||
} catch (IOException e) {
|
} catch (DbException | IOException e) {
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
onReadError(true);
|
onReadError(true);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -140,6 +140,27 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addRemotePropertiesFromConnection(ContactId c, TransportId t,
|
||||||
|
TransportProperties props) throws DbException {
|
||||||
|
if (props.isEmpty()) return;
|
||||||
|
try {
|
||||||
|
db.transaction(false, txn -> {
|
||||||
|
Group g = getContactGroup(db.getContact(txn, c));
|
||||||
|
BdfDictionary meta = clientHelper.getGroupMetadataAsDictionary(
|
||||||
|
txn, g.getId());
|
||||||
|
BdfDictionary discovered =
|
||||||
|
meta.getOptionalDictionary("discovered");
|
||||||
|
if (discovered == null) discovered = new BdfDictionary();
|
||||||
|
discovered.putAll(props);
|
||||||
|
meta.put("discovered", discovered);
|
||||||
|
clientHelper.mergeGroupMetadata(txn, g.getId(), meta);
|
||||||
|
});
|
||||||
|
} catch (FormatException e) {
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<TransportId, TransportProperties> getLocalProperties()
|
public Map<TransportId, TransportProperties> getLocalProperties()
|
||||||
throws DbException {
|
throws DbException {
|
||||||
@@ -203,12 +224,26 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
|||||||
Group g = getContactGroup(c);
|
Group g = getContactGroup(c);
|
||||||
try {
|
try {
|
||||||
// Find the latest remote update
|
// Find the latest remote update
|
||||||
|
TransportProperties remote;
|
||||||
LatestUpdate latest = findLatest(txn, g.getId(), t, false);
|
LatestUpdate latest = findLatest(txn, g.getId(), t, false);
|
||||||
if (latest == null) return new TransportProperties();
|
if (latest == null) {
|
||||||
// Retrieve and parse the latest remote properties
|
remote = new TransportProperties();
|
||||||
BdfList message =
|
} else {
|
||||||
clientHelper.getMessageAsList(txn, latest.messageId);
|
// Retrieve and parse the latest remote properties
|
||||||
return parseProperties(message);
|
BdfList message =
|
||||||
|
clientHelper.getMessageAsList(txn, latest.messageId);
|
||||||
|
remote = parseProperties(message);
|
||||||
|
}
|
||||||
|
// Merge in any discovered properties
|
||||||
|
BdfDictionary meta =
|
||||||
|
clientHelper.getGroupMetadataAsDictionary(txn, g.getId());
|
||||||
|
BdfDictionary d = meta.getOptionalDictionary("discovered");
|
||||||
|
if (d == null) return remote;
|
||||||
|
TransportProperties merged =
|
||||||
|
clientHelper.parseAndValidateTransportProperties(d);
|
||||||
|
// Received properties override discovered properties
|
||||||
|
merged.putAll(remote);
|
||||||
|
return merged;
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,12 +24,12 @@ import org.briarproject.bramble.test.DbExpectations;
|
|||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
|
import static java.util.Collections.emptyMap;
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
import static java.util.Collections.singletonMap;
|
import static java.util.Collections.singletonMap;
|
||||||
import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_ID;
|
import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_ID;
|
||||||
@@ -405,25 +405,25 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
|||||||
List<Contact> contacts = asList(contact1, contact2);
|
List<Contact> contacts = asList(contact1, contact2);
|
||||||
Group contactGroup1 = getGroup(CLIENT_ID, MAJOR_VERSION);
|
Group contactGroup1 = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||||
Group contactGroup2 = getGroup(CLIENT_ID, MAJOR_VERSION);
|
Group contactGroup2 = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||||
Map<MessageId, BdfDictionary> messageMetadata2 =
|
Map<MessageId, BdfDictionary> messageMetadata =
|
||||||
new LinkedHashMap<>();
|
new LinkedHashMap<>();
|
||||||
// A remote update for another transport should be ignored
|
// A remote update for another transport should be ignored
|
||||||
MessageId barUpdateId = new MessageId(getRandomId());
|
MessageId barUpdateId = new MessageId(getRandomId());
|
||||||
messageMetadata2.put(barUpdateId, BdfDictionary.of(
|
messageMetadata.put(barUpdateId, BdfDictionary.of(
|
||||||
new BdfEntry("transportId", "bar"),
|
new BdfEntry("transportId", "bar"),
|
||||||
new BdfEntry("version", 1),
|
new BdfEntry("version", 1),
|
||||||
new BdfEntry("local", false)
|
new BdfEntry("local", false)
|
||||||
));
|
));
|
||||||
// A local update for the right transport should be ignored
|
// A local update for the right transport should be ignored
|
||||||
MessageId localUpdateId = new MessageId(getRandomId());
|
MessageId localUpdateId = new MessageId(getRandomId());
|
||||||
messageMetadata2.put(localUpdateId, BdfDictionary.of(
|
messageMetadata.put(localUpdateId, BdfDictionary.of(
|
||||||
new BdfEntry("transportId", "foo"),
|
new BdfEntry("transportId", "foo"),
|
||||||
new BdfEntry("version", 1),
|
new BdfEntry("version", 1),
|
||||||
new BdfEntry("local", true)
|
new BdfEntry("local", true)
|
||||||
));
|
));
|
||||||
// A remote update for the right transport should be returned
|
// A remote update for the right transport should be returned
|
||||||
MessageId fooUpdateId = new MessageId(getRandomId());
|
MessageId fooUpdateId = new MessageId(getRandomId());
|
||||||
messageMetadata2.put(fooUpdateId, BdfDictionary.of(
|
messageMetadata.put(fooUpdateId, BdfDictionary.of(
|
||||||
new BdfEntry("transportId", "foo"),
|
new BdfEntry("transportId", "foo"),
|
||||||
new BdfEntry("version", 1),
|
new BdfEntry("version", 1),
|
||||||
new BdfEntry("local", false)
|
new BdfEntry("local", false)
|
||||||
@@ -440,19 +440,25 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(contactGroup1));
|
will(returnValue(contactGroup1));
|
||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||||
contactGroup1.getId());
|
contactGroup1.getId());
|
||||||
will(returnValue(Collections.emptyMap()));
|
will(returnValue(emptyMap()));
|
||||||
|
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||||
|
contactGroup1.getId());
|
||||||
|
will(returnValue(new BdfDictionary()));
|
||||||
// Second contact: returns an update
|
// Second contact: returns an update
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
MAJOR_VERSION, contact2);
|
MAJOR_VERSION, contact2);
|
||||||
will(returnValue(contactGroup2));
|
will(returnValue(contactGroup2));
|
||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||||
contactGroup2.getId());
|
contactGroup2.getId());
|
||||||
will(returnValue(messageMetadata2));
|
will(returnValue(messageMetadata));
|
||||||
oneOf(clientHelper).getMessageAsList(txn, fooUpdateId);
|
oneOf(clientHelper).getMessageAsList(txn, fooUpdateId);
|
||||||
will(returnValue(fooUpdate));
|
will(returnValue(fooUpdate));
|
||||||
oneOf(clientHelper).parseAndValidateTransportProperties(
|
oneOf(clientHelper).parseAndValidateTransportProperties(
|
||||||
fooPropertiesDict);
|
fooPropertiesDict);
|
||||||
will(returnValue(fooProperties));
|
will(returnValue(fooProperties));
|
||||||
|
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||||
|
contactGroup2.getId());
|
||||||
|
will(returnValue(new BdfDictionary()));
|
||||||
}});
|
}});
|
||||||
|
|
||||||
TransportPropertyManagerImpl t = createInstance();
|
TransportPropertyManagerImpl t = createInstance();
|
||||||
@@ -463,6 +469,61 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
|||||||
assertEquals(fooProperties, properties.get(contact2.getId()));
|
assertEquals(fooProperties, properties.get(contact2.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReceivePropertiesOverrideDiscoveredProperties()
|
||||||
|
throws Exception {
|
||||||
|
Transaction txn = new Transaction(null, true);
|
||||||
|
Contact contact = getContact();
|
||||||
|
List<Contact> contacts = singletonList(contact);
|
||||||
|
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||||
|
MessageId updateId = new MessageId(getRandomId());
|
||||||
|
Map<MessageId, BdfDictionary> messageMetadata = singletonMap(updateId,
|
||||||
|
BdfDictionary.of(
|
||||||
|
new BdfEntry("transportId", "foo"),
|
||||||
|
new BdfEntry("version", 1),
|
||||||
|
new BdfEntry("local", false)
|
||||||
|
));
|
||||||
|
BdfList update = BdfList.of("foo", 1, fooPropertiesDict);
|
||||||
|
TransportProperties discovered = new TransportProperties();
|
||||||
|
discovered.put("fooKey1", "overridden");
|
||||||
|
discovered.put("fooKey3", "fooValue3");
|
||||||
|
BdfDictionary discoveredDict = new BdfDictionary(discovered);
|
||||||
|
BdfDictionary groupMeta =
|
||||||
|
BdfDictionary.of(new BdfEntry("discovered", discoveredDict));
|
||||||
|
TransportProperties merged = new TransportProperties();
|
||||||
|
merged.putAll(fooProperties);
|
||||||
|
merged.put("fooKey3", "fooValue3");
|
||||||
|
|
||||||
|
context.checking(new DbExpectations() {{
|
||||||
|
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
||||||
|
oneOf(db).getContacts(txn);
|
||||||
|
will(returnValue(contacts));
|
||||||
|
// One update
|
||||||
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
MAJOR_VERSION, contact);
|
||||||
|
will(returnValue(contactGroup));
|
||||||
|
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||||
|
contactGroup.getId());
|
||||||
|
will(returnValue(messageMetadata));
|
||||||
|
oneOf(clientHelper).getMessageAsList(txn, updateId);
|
||||||
|
will(returnValue(update));
|
||||||
|
oneOf(clientHelper).parseAndValidateTransportProperties(
|
||||||
|
fooPropertiesDict);
|
||||||
|
will(returnValue(fooProperties));
|
||||||
|
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||||
|
contactGroup.getId());
|
||||||
|
will(returnValue(groupMeta));
|
||||||
|
oneOf(clientHelper).parseAndValidateTransportProperties(
|
||||||
|
discoveredDict);
|
||||||
|
will(returnValue(discovered));
|
||||||
|
}});
|
||||||
|
|
||||||
|
TransportPropertyManagerImpl t = createInstance();
|
||||||
|
Map<ContactId, TransportProperties> properties =
|
||||||
|
t.getRemoteProperties(new TransportId("foo"));
|
||||||
|
assertEquals(merged, properties.get(contact.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMergingUnchangedPropertiesDoesNotCreateUpdate()
|
public void testMergingUnchangedPropertiesDoesNotCreateUpdate()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
@@ -505,7 +566,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
|||||||
// There are no existing properties to merge with
|
// There are no existing properties to merge with
|
||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||||
localGroup.getId());
|
localGroup.getId());
|
||||||
will(returnValue(Collections.emptyMap()));
|
will(returnValue(emptyMap()));
|
||||||
// Store the new properties in the local group, version 1
|
// Store the new properties in the local group, version 1
|
||||||
expectStoreMessage(txn, localGroup.getId(), "foo",
|
expectStoreMessage(txn, localGroup.getId(), "foo",
|
||||||
fooPropertiesDict, 1, true, false);
|
fooPropertiesDict, 1, true, false);
|
||||||
@@ -517,7 +578,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||||
contactGroup.getId());
|
contactGroup.getId());
|
||||||
will(returnValue(Collections.emptyMap()));
|
will(returnValue(emptyMap()));
|
||||||
expectStoreMessage(txn, contactGroup.getId(), "foo",
|
expectStoreMessage(txn, contactGroup.getId(), "foo",
|
||||||
fooPropertiesDict, 1, true, true);
|
fooPropertiesDict, 1, true, true);
|
||||||
}});
|
}});
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|||||||
import org.briarproject.bramble.api.plugin.TransportConnectionReader;
|
import org.briarproject.bramble.api.plugin.TransportConnectionReader;
|
||||||
import org.briarproject.bramble.api.plugin.TransportConnectionWriter;
|
import org.briarproject.bramble.api.plugin.TransportConnectionWriter;
|
||||||
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||||
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -37,6 +38,11 @@ public class TestDuplexTransportConnection
|
|||||||
return writer;
|
return writer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProperties getRemoteProperties() {
|
||||||
|
return new TransportProperties();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and returns a pair of TestDuplexTransportConnections that are
|
* Creates and returns a pair of TestDuplexTransportConnections that are
|
||||||
* connected to each other.
|
* connected to each other.
|
||||||
|
|||||||
Reference in New Issue
Block a user