mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 04:39:54 +01:00
Separated contact transports from secrets and cleaned up some tests.
This commit is contained in:
@@ -1,23 +1,33 @@
|
|||||||
package net.sf.briar.api;
|
package net.sf.briar.api.db;
|
||||||
|
|
||||||
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.protocol.TransportId;
|
import net.sf.briar.api.protocol.TransportId;
|
||||||
|
|
||||||
public class ContactTransport extends TemporarySecret {
|
public class ContactTransport {
|
||||||
|
|
||||||
|
private final ContactId contactId;
|
||||||
|
private final TransportId transportId;
|
||||||
private final long epoch, clockDiff, latency;
|
private final long epoch, clockDiff, latency;
|
||||||
private final boolean alice;
|
private final boolean alice;
|
||||||
|
|
||||||
public ContactTransport(ContactId contactId, TransportId transportId,
|
public ContactTransport(ContactId contactId, TransportId transportId,
|
||||||
long epoch, long clockDiff, long latency, boolean alice,
|
long epoch, long clockDiff, long latency, boolean alice) {
|
||||||
long period, byte[] secret, long outgoing, long centre,
|
this.contactId = contactId;
|
||||||
byte[] bitmap) {
|
this.transportId = transportId;
|
||||||
super(contactId, transportId, period, secret, outgoing, centre, bitmap);
|
|
||||||
this.epoch = epoch;
|
this.epoch = epoch;
|
||||||
this.clockDiff = clockDiff;
|
this.clockDiff = clockDiff;
|
||||||
this.latency = latency;
|
this.latency = latency;
|
||||||
this.alice = alice;
|
this.alice = alice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ContactId getContactId() {
|
||||||
|
return contactId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TransportId getTransportId() {
|
||||||
|
return transportId;
|
||||||
|
}
|
||||||
|
|
||||||
public long getEpoch() {
|
public long getEpoch() {
|
||||||
return epoch;
|
return epoch;
|
||||||
}
|
}
|
||||||
@@ -5,9 +5,7 @@ import java.util.Collection;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.ContactTransport;
|
|
||||||
import net.sf.briar.api.Rating;
|
import net.sf.briar.api.Rating;
|
||||||
import net.sf.briar.api.TemporarySecret;
|
|
||||||
import net.sf.briar.api.TransportConfig;
|
import net.sf.briar.api.TransportConfig;
|
||||||
import net.sf.briar.api.TransportProperties;
|
import net.sf.briar.api.TransportProperties;
|
||||||
import net.sf.briar.api.db.event.DatabaseListener;
|
import net.sf.briar.api.db.event.DatabaseListener;
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
package net.sf.briar.api;
|
package net.sf.briar.api.db;
|
||||||
|
|
||||||
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.protocol.TransportId;
|
import net.sf.briar.api.protocol.TransportId;
|
||||||
|
|
||||||
public class TemporarySecret {
|
public class TemporarySecret {
|
||||||
|
|
||||||
protected final ContactId contactId;
|
private final ContactId contactId;
|
||||||
protected final TransportId transportId;
|
private final TransportId transportId;
|
||||||
protected final long period, outgoing, centre;
|
private final long period, outgoing, centre;
|
||||||
protected final byte[] secret, bitmap;
|
private final byte[] secret, bitmap;
|
||||||
|
|
||||||
public TemporarySecret(ContactId contactId, TransportId transportId,
|
public TemporarySecret(ContactId contactId, TransportId transportId,
|
||||||
long period, byte[] secret, long outgoing, long centre,
|
long period, byte[] secret, long outgoing, long centre,
|
||||||
@@ -5,14 +5,14 @@ import java.util.Collection;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.ContactTransport;
|
|
||||||
import net.sf.briar.api.Rating;
|
import net.sf.briar.api.Rating;
|
||||||
import net.sf.briar.api.TemporarySecret;
|
|
||||||
import net.sf.briar.api.TransportConfig;
|
import net.sf.briar.api.TransportConfig;
|
||||||
import net.sf.briar.api.TransportProperties;
|
import net.sf.briar.api.TransportProperties;
|
||||||
|
import net.sf.briar.api.db.ContactTransport;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
import net.sf.briar.api.db.MessageHeader;
|
import net.sf.briar.api.db.MessageHeader;
|
||||||
import net.sf.briar.api.db.Status;
|
import net.sf.briar.api.db.Status;
|
||||||
|
import net.sf.briar.api.db.TemporarySecret;
|
||||||
import net.sf.briar.api.protocol.AuthorId;
|
import net.sf.briar.api.protocol.AuthorId;
|
||||||
import net.sf.briar.api.protocol.BatchId;
|
import net.sf.briar.api.protocol.BatchId;
|
||||||
import net.sf.briar.api.protocol.Group;
|
import net.sf.briar.api.protocol.Group;
|
||||||
@@ -91,8 +91,7 @@ interface Database<T> {
|
|||||||
* <p>
|
* <p>
|
||||||
* Locking: contact read, window write.
|
* Locking: contact read, window write.
|
||||||
*/
|
*/
|
||||||
void addContactTransport(T txn, ContactTransport ct)
|
void addContactTransport(T txn, ContactTransport ct) throws DbException;
|
||||||
throws DbException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns false if the given message is already in the database. Otherwise
|
* Returns false if the given message is already in the database. Otherwise
|
||||||
@@ -366,6 +365,13 @@ interface Database<T> {
|
|||||||
Map<ContactId, TransportProperties> getRemoteProperties(T txn,
|
Map<ContactId, TransportProperties> getRemoteProperties(T txn,
|
||||||
TransportId t) throws DbException;
|
TransportId t) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all temporary secrets.
|
||||||
|
* <p>
|
||||||
|
* Locking: contact read, window read.
|
||||||
|
*/
|
||||||
|
Collection<TemporarySecret> getSecrets(T txn) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the sendability score of the given group message.
|
* Returns the sendability score of the given group message.
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -22,18 +22,18 @@ import java.util.logging.Level;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.ContactTransport;
|
|
||||||
import net.sf.briar.api.Rating;
|
import net.sf.briar.api.Rating;
|
||||||
import net.sf.briar.api.TemporarySecret;
|
|
||||||
import net.sf.briar.api.TransportConfig;
|
import net.sf.briar.api.TransportConfig;
|
||||||
import net.sf.briar.api.TransportProperties;
|
import net.sf.briar.api.TransportProperties;
|
||||||
import net.sf.briar.api.clock.Clock;
|
import net.sf.briar.api.clock.Clock;
|
||||||
|
import net.sf.briar.api.db.ContactTransport;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
import net.sf.briar.api.db.MessageHeader;
|
import net.sf.briar.api.db.MessageHeader;
|
||||||
import net.sf.briar.api.db.NoSuchContactException;
|
import net.sf.briar.api.db.NoSuchContactException;
|
||||||
import net.sf.briar.api.db.NoSuchContactTransportException;
|
import net.sf.briar.api.db.NoSuchContactTransportException;
|
||||||
import net.sf.briar.api.db.Status;
|
import net.sf.briar.api.db.Status;
|
||||||
|
import net.sf.briar.api.db.TemporarySecret;
|
||||||
import net.sf.briar.api.db.event.BatchReceivedEvent;
|
import net.sf.briar.api.db.event.BatchReceivedEvent;
|
||||||
import net.sf.briar.api.db.event.ContactAddedEvent;
|
import net.sf.briar.api.db.event.ContactAddedEvent;
|
||||||
import net.sf.briar.api.db.event.ContactRemovedEvent;
|
import net.sf.briar.api.db.event.ContactRemovedEvent;
|
||||||
|
|||||||
@@ -24,15 +24,15 @@ import java.util.logging.Level;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.ContactTransport;
|
|
||||||
import net.sf.briar.api.Rating;
|
import net.sf.briar.api.Rating;
|
||||||
import net.sf.briar.api.TemporarySecret;
|
|
||||||
import net.sf.briar.api.TransportConfig;
|
import net.sf.briar.api.TransportConfig;
|
||||||
import net.sf.briar.api.TransportProperties;
|
import net.sf.briar.api.TransportProperties;
|
||||||
import net.sf.briar.api.clock.Clock;
|
import net.sf.briar.api.clock.Clock;
|
||||||
|
import net.sf.briar.api.db.ContactTransport;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
import net.sf.briar.api.db.MessageHeader;
|
import net.sf.briar.api.db.MessageHeader;
|
||||||
import net.sf.briar.api.db.Status;
|
import net.sf.briar.api.db.Status;
|
||||||
|
import net.sf.briar.api.db.TemporarySecret;
|
||||||
import net.sf.briar.api.protocol.AuthorId;
|
import net.sf.briar.api.protocol.AuthorId;
|
||||||
import net.sf.briar.api.protocol.BatchId;
|
import net.sf.briar.api.protocol.BatchId;
|
||||||
import net.sf.briar.api.protocol.Group;
|
import net.sf.briar.api.protocol.Group;
|
||||||
@@ -559,21 +559,6 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
int affected = ps.executeUpdate();
|
int affected = ps.executeUpdate();
|
||||||
if(affected != 1) throw new DbStateException();
|
if(affected != 1) throw new DbStateException();
|
||||||
ps.close();
|
ps.close();
|
||||||
sql = "INSERT INTO secrets"
|
|
||||||
+ " (contactId, transportId, period, secret, outgoing,"
|
|
||||||
+ " centre, bitmap)"
|
|
||||||
+ " VALUES (?, ?, ?, ?, ?, ?, ?)";
|
|
||||||
ps = txn.prepareStatement(sql);
|
|
||||||
ps.setInt(1, ct.getContactId().getInt());
|
|
||||||
ps.setBytes(2, ct.getTransportId().getBytes());
|
|
||||||
ps.setLong(3, ct.getPeriod());
|
|
||||||
ps.setBytes(4, ct.getSecret());
|
|
||||||
ps.setLong(5, ct.getOutgoingConnectionCounter());
|
|
||||||
ps.setLong(6, ct.getWindowCentre());
|
|
||||||
ps.setBytes(7, ct.getWindowBitmap());
|
|
||||||
affected = ps.executeUpdate();
|
|
||||||
if(affected != 1) throw new DbStateException();
|
|
||||||
ps.close();
|
|
||||||
} catch(SQLException e) {
|
} catch(SQLException e) {
|
||||||
tryToClose(ps);
|
tryToClose(ps);
|
||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
@@ -1094,32 +1079,21 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
String sql = "SELECT c.contactId, c.transportId, epoch,"
|
String sql = "SELECT contactId, transportId, epoch, clockDiff,"
|
||||||
+ " clockDiff, latency, alice, period, secret,"
|
+ " latency, alice"
|
||||||
+ " outgoing, centre, bitmap"
|
+ " FROM contactTransports";
|
||||||
+ " FROM contactTransports AS c"
|
|
||||||
+ " JOIN secrets AS s"
|
|
||||||
+ " ON c.contactId = s.contactId"
|
|
||||||
+ " AND c.transportId = s.transportId";
|
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
List<ContactTransport> cts = new ArrayList<ContactTransport>();
|
List<ContactTransport> cts = new ArrayList<ContactTransport>();
|
||||||
while(rs.next()) {
|
while(rs.next()) {
|
||||||
ContactId contactId = new ContactId(rs.getInt(1));
|
ContactId c = new ContactId(rs.getInt(1));
|
||||||
TransportId transportId = new TransportId(rs.getBytes(2));
|
TransportId t = new TransportId(rs.getBytes(2));
|
||||||
long epoch = rs.getLong(3);
|
long epoch = rs.getLong(3);
|
||||||
long clockDiff = rs.getLong(4);
|
long clockDiff = rs.getLong(4);
|
||||||
long latency = rs.getLong(5);
|
long latency = rs.getLong(5);
|
||||||
boolean alice = rs.getBoolean(6);
|
boolean alice = rs.getBoolean(6);
|
||||||
long period = rs.getLong(7);
|
cts.add(new ContactTransport(c, t, epoch, clockDiff, latency,
|
||||||
byte[] secret = rs.getBytes(8);
|
alice));
|
||||||
long outgoing = rs.getLong(9);
|
|
||||||
long centre = rs.getLong(10);
|
|
||||||
byte[] bitmap = rs.getBytes(11);
|
|
||||||
ContactTransport ct = new ContactTransport(contactId,
|
|
||||||
transportId, epoch, clockDiff, latency, alice, period,
|
|
||||||
secret, outgoing, centre, bitmap);
|
|
||||||
cts.add(ct);
|
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableList(cts);
|
return Collections.unmodifiableList(cts);
|
||||||
} catch(SQLException e) {
|
} catch(SQLException e) {
|
||||||
@@ -1577,6 +1551,38 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<TemporarySecret> getSecrets(Connection txn)
|
||||||
|
throws DbException {
|
||||||
|
PreparedStatement ps = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
String sql = "SELECT contactId, transportId, period, secret,"
|
||||||
|
+ " outgoing, centre, bitmap"
|
||||||
|
+ " FROM secrets";
|
||||||
|
ps = txn.prepareStatement(sql);
|
||||||
|
rs = ps.executeQuery();
|
||||||
|
List<TemporarySecret> secrets = new ArrayList<TemporarySecret>();
|
||||||
|
while(rs.next()) {
|
||||||
|
ContactId c = new ContactId(rs.getInt(1));
|
||||||
|
TransportId t = new TransportId(rs.getBytes(2));
|
||||||
|
long period = rs.getLong(3);
|
||||||
|
byte[] secret = rs.getBytes(4);
|
||||||
|
long outgoing = rs.getLong(5);
|
||||||
|
long centre = rs.getLong(6);
|
||||||
|
byte[] bitmap = rs.getBytes(7);
|
||||||
|
secrets.add(new TemporarySecret(c, t, period, secret, outgoing,
|
||||||
|
centre, bitmap));
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
return Collections.unmodifiableList(secrets);
|
||||||
|
} catch(SQLException e) {
|
||||||
|
tryToClose(rs);
|
||||||
|
tryToClose(ps);
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int getSendability(Connection txn, MessageId m) throws DbException {
|
public int getSendability(Connection txn, MessageId m) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
|
|||||||
@@ -153,21 +153,14 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
|||||||
Ack a = packetFactory.createAck(Collections.singletonList(ack));
|
Ack a = packetFactory.createAck(Collections.singletonList(ack));
|
||||||
writer.writeAck(a);
|
writer.writeAck(a);
|
||||||
|
|
||||||
Collection<byte[]> batch = Arrays.asList(new byte[][] {
|
Collection<byte[]> batch = Arrays.asList(message.getSerialised(),
|
||||||
message.getSerialised(),
|
message1.getSerialised(), message2.getSerialised(),
|
||||||
message1.getSerialised(),
|
message3.getSerialised());
|
||||||
message2.getSerialised(),
|
|
||||||
message3.getSerialised()
|
|
||||||
});
|
|
||||||
RawBatch b = packetFactory.createBatch(batch);
|
RawBatch b = packetFactory.createBatch(batch);
|
||||||
writer.writeBatch(b);
|
writer.writeBatch(b);
|
||||||
|
|
||||||
Collection<MessageId> offer = Arrays.asList(new MessageId[] {
|
Collection<MessageId> offer = Arrays.asList(message.getId(),
|
||||||
message.getId(),
|
message1.getId(), message2.getId(), message3.getId());
|
||||||
message1.getId(),
|
|
||||||
message2.getId(),
|
|
||||||
message3.getId()
|
|
||||||
});
|
|
||||||
Offer o = packetFactory.createOffer(offer);
|
Offer o = packetFactory.createOffer(offer);
|
||||||
writer.writeOffer(o);
|
writer.writeOffer(o);
|
||||||
|
|
||||||
|
|||||||
@@ -639,10 +639,9 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
public void testGenerateBatch() throws Exception {
|
public void testGenerateBatch() throws Exception {
|
||||||
final MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
final MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||||
final byte[] raw1 = new byte[size];
|
final byte[] raw1 = new byte[size];
|
||||||
final Collection<MessageId> sendable =
|
final Collection<MessageId> sendable = Arrays.asList(messageId,
|
||||||
Arrays.asList(new MessageId[] {messageId, messageId1});
|
messageId1);
|
||||||
final Collection<byte[]> messages =
|
final Collection<byte[]> messages = Arrays.asList(raw, raw1);
|
||||||
Arrays.asList(new byte[][] {raw, raw1});
|
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final Database<Object> database = context.mock(Database.class);
|
final Database<Object> database = context.mock(Database.class);
|
||||||
@@ -689,7 +688,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
requested.add(messageId);
|
requested.add(messageId);
|
||||||
requested.add(messageId1);
|
requested.add(messageId1);
|
||||||
requested.add(messageId2);
|
requested.add(messageId2);
|
||||||
final Collection<byte[]> msgs = Arrays.asList(new byte[][] {raw1});
|
final Collection<byte[]> msgs = Arrays.asList(raw1);
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final Database<Object> database = context.mock(Database.class);
|
final Database<Object> database = context.mock(Database.class);
|
||||||
@@ -1477,8 +1476,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testVisibilityChangedCallsListeners() throws Exception {
|
public void testVisibilityChangedCallsListeners() throws Exception {
|
||||||
final ContactId contactId1 = new ContactId(123);
|
final ContactId contactId1 = new ContactId(123);
|
||||||
final Collection<ContactId> both =
|
final Collection<ContactId> both = Arrays.asList(contactId, contactId1);
|
||||||
Arrays.asList(new ContactId[] {contactId, contactId1});
|
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final Database<Object> database = context.mock(Database.class);
|
final Database<Object> database = context.mock(Database.class);
|
||||||
@@ -1510,8 +1508,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testVisibilityUnchangedDoesNotCallListeners() throws Exception {
|
public void testVisibilityUnchangedDoesNotCallListeners() throws Exception {
|
||||||
final ContactId contactId1 = new ContactId(234);
|
final ContactId contactId1 = new ContactId(234);
|
||||||
final Collection<ContactId> both =
|
final Collection<ContactId> both = Arrays.asList(contactId, contactId1);
|
||||||
Arrays.asList(new ContactId[] {contactId, contactId1});
|
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final Database<Object> database = context.mock(Database.class);
|
final Database<Object> database = context.mock(Database.class);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import net.sf.briar.api.TransportConfig;
|
|||||||
import net.sf.briar.api.TransportProperties;
|
import net.sf.briar.api.TransportProperties;
|
||||||
import net.sf.briar.api.clock.SystemClock;
|
import net.sf.briar.api.clock.SystemClock;
|
||||||
import net.sf.briar.api.crypto.Password;
|
import net.sf.briar.api.crypto.Password;
|
||||||
|
import net.sf.briar.api.db.ContactTransport;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
import net.sf.briar.api.db.MessageHeader;
|
import net.sf.briar.api.db.MessageHeader;
|
||||||
import net.sf.briar.api.db.Status;
|
import net.sf.briar.api.db.Status;
|
||||||
@@ -1720,6 +1721,59 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
|
|
||||||
// FIXME: Test new methods
|
// FIXME: Test new methods
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testContactTransports() throws Exception {
|
||||||
|
// Create some contact transports
|
||||||
|
TransportId transportId1 = new TransportId(TestUtils.getRandomId());
|
||||||
|
ContactTransport ct1 = new ContactTransport(contactId, transportId,
|
||||||
|
123L, 2345L, 34567L, true);
|
||||||
|
ContactTransport ct2 = new ContactTransport(contactId, transportId1,
|
||||||
|
12345L, 2345L, 345L, false);
|
||||||
|
|
||||||
|
Database<Connection> db = open(false);
|
||||||
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
|
// Initially there should be no contact transports in the database
|
||||||
|
assertEquals(Collections.emptyList(), db.getContactTransports(txn));
|
||||||
|
|
||||||
|
// Add a contact and the contact transports
|
||||||
|
assertEquals(contactId, db.addContact(txn));
|
||||||
|
db.addContactTransport(txn, ct1);
|
||||||
|
db.addContactTransport(txn, ct2);
|
||||||
|
|
||||||
|
// Retrieve the contact transports
|
||||||
|
Collection<ContactTransport> cts = db.getContactTransports(txn);
|
||||||
|
assertEquals(2, cts.size());
|
||||||
|
boolean foundFirst = false, foundSecond = false;
|
||||||
|
for(ContactTransport ct : cts) {
|
||||||
|
assertEquals(contactId, ct.getContactId());
|
||||||
|
if(ct.getTransportId().equals(transportId)) {
|
||||||
|
assertEquals(123L, ct.getEpoch());
|
||||||
|
assertEquals(2345L, ct.getClockDifference());
|
||||||
|
assertEquals(34567L, ct.getLatency());
|
||||||
|
assertTrue(ct.getAlice());
|
||||||
|
foundFirst = true;
|
||||||
|
} else if(ct.getTransportId().equals(transportId1)) {
|
||||||
|
assertEquals(12345L, ct.getEpoch());
|
||||||
|
assertEquals(2345L, ct.getClockDifference());
|
||||||
|
assertEquals(345L, ct.getLatency());
|
||||||
|
assertFalse(ct.getAlice());
|
||||||
|
foundSecond = true;
|
||||||
|
} else {
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue(foundFirst);
|
||||||
|
assertTrue(foundSecond);
|
||||||
|
|
||||||
|
// Removing the contact should remove the contact transports
|
||||||
|
db.removeContact(txn, contactId);
|
||||||
|
assertEquals(Collections.emptyList(), db.getContactTransports(txn));
|
||||||
|
|
||||||
|
db.commitTransaction(txn);
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExceptionHandling() throws Exception {
|
public void testExceptionHandling() throws Exception {
|
||||||
Database<Connection> db = open(false);
|
Database<Connection> db = open(false);
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class PollingRemovableDriveMonitorTest extends BriarTestCase {
|
|||||||
|
|
||||||
public Collection<File> findRemovableDrives() throws IOException {
|
public Collection<File> findRemovableDrives() throws IOException {
|
||||||
if(firstCall.getAndSet(false)) return Collections.emptyList();
|
if(firstCall.getAndSet(false)) return Collections.emptyList();
|
||||||
else return Arrays.asList(new File[] {file1, file2});
|
else return Arrays.asList(file1, file2);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Create a callback that waits for two files
|
// Create a callback that waits for two files
|
||||||
|
|||||||
@@ -66,9 +66,9 @@ public class UnverifiedBatchImplTest extends BriarTestCase {
|
|||||||
// Verify the batch
|
// Verify the batch
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final UnverifiedMessage message =
|
final UnverifiedMessage message =
|
||||||
context.mock(UnverifiedMessage.class, "message");
|
context.mock(UnverifiedMessage.class, "message");
|
||||||
final UnverifiedMessage message1 =
|
final UnverifiedMessage message1 =
|
||||||
context.mock(UnverifiedMessage.class, "message1");
|
context.mock(UnverifiedMessage.class, "message1");
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
// First message
|
// First message
|
||||||
oneOf(message).getRaw();
|
oneOf(message).getRaw();
|
||||||
@@ -105,8 +105,8 @@ public class UnverifiedBatchImplTest extends BriarTestCase {
|
|||||||
oneOf(message1).getBodyLength();
|
oneOf(message1).getBodyLength();
|
||||||
will(returnValue(1000));
|
will(returnValue(1000));
|
||||||
}});
|
}});
|
||||||
Collection<UnverifiedMessage> messages =
|
Collection<UnverifiedMessage> messages = Arrays.asList(message,
|
||||||
Arrays.asList(new UnverifiedMessage[] {message, message1});
|
message1);
|
||||||
UnverifiedBatch batch = new UnverifiedBatchImpl(crypto, messages);
|
UnverifiedBatch batch = new UnverifiedBatchImpl(crypto, messages);
|
||||||
Batch verifiedBatch = batch.verify();
|
Batch verifiedBatch = batch.verify();
|
||||||
// Check that the batch and message IDs match
|
// Check that the batch and message IDs match
|
||||||
@@ -137,11 +137,11 @@ public class UnverifiedBatchImplTest extends BriarTestCase {
|
|||||||
// Verify the batch
|
// Verify the batch
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final UnverifiedMessage message =
|
final UnverifiedMessage message =
|
||||||
context.mock(UnverifiedMessage.class, "message");
|
context.mock(UnverifiedMessage.class, "message");
|
||||||
final Author author = context.mock(Author.class);
|
final Author author = context.mock(Author.class);
|
||||||
final Group group = context.mock(Group.class);
|
final Group group = context.mock(Group.class);
|
||||||
final UnverifiedMessage message1 =
|
final UnverifiedMessage message1 =
|
||||||
context.mock(UnverifiedMessage.class, "message1");
|
context.mock(UnverifiedMessage.class, "message1");
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
// First message
|
// First message
|
||||||
oneOf(message).getRaw();
|
oneOf(message).getRaw();
|
||||||
@@ -194,8 +194,8 @@ public class UnverifiedBatchImplTest extends BriarTestCase {
|
|||||||
oneOf(message1).getBodyLength();
|
oneOf(message1).getBodyLength();
|
||||||
will(returnValue(1000));
|
will(returnValue(1000));
|
||||||
}});
|
}});
|
||||||
Collection<UnverifiedMessage> messages =
|
Collection<UnverifiedMessage> messages = Arrays.asList(message,
|
||||||
Arrays.asList(new UnverifiedMessage[] {message, message1});
|
message1);
|
||||||
UnverifiedBatch batch = new UnverifiedBatchImpl(crypto, messages);
|
UnverifiedBatch batch = new UnverifiedBatchImpl(crypto, messages);
|
||||||
batch.verify();
|
batch.verify();
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
@@ -215,10 +215,10 @@ public class UnverifiedBatchImplTest extends BriarTestCase {
|
|||||||
// Verify the batch
|
// Verify the batch
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final UnverifiedMessage message =
|
final UnverifiedMessage message =
|
||||||
context.mock(UnverifiedMessage.class, "message");
|
context.mock(UnverifiedMessage.class, "message");
|
||||||
final Author author = context.mock(Author.class);
|
final Author author = context.mock(Author.class);
|
||||||
final UnverifiedMessage message1 =
|
final UnverifiedMessage message1 =
|
||||||
context.mock(UnverifiedMessage.class, "message1");
|
context.mock(UnverifiedMessage.class, "message1");
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
// First message - verification will fail at the author's signature
|
// First message - verification will fail at the author's signature
|
||||||
oneOf(message).getRaw();
|
oneOf(message).getRaw();
|
||||||
@@ -232,8 +232,8 @@ public class UnverifiedBatchImplTest extends BriarTestCase {
|
|||||||
oneOf(message).getAuthorSignature();
|
oneOf(message).getAuthorSignature();
|
||||||
will(returnValue(authorSignature));
|
will(returnValue(authorSignature));
|
||||||
}});
|
}});
|
||||||
Collection<UnverifiedMessage> messages =
|
Collection<UnverifiedMessage> messages = Arrays.asList(message,
|
||||||
Arrays.asList(new UnverifiedMessage[] {message, message1});
|
message1);
|
||||||
UnverifiedBatch batch = new UnverifiedBatchImpl(crypto, messages);
|
UnverifiedBatch batch = new UnverifiedBatchImpl(crypto, messages);
|
||||||
try {
|
try {
|
||||||
batch.verify();
|
batch.verify();
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public class ConnectionRegistryImplTest extends BriarTestCase {
|
|||||||
c.registerConnection(contactId, transportId);
|
c.registerConnection(contactId, transportId);
|
||||||
c.registerConnection(contactId1, transportId);
|
c.registerConnection(contactId1, transportId);
|
||||||
c.registerConnection(contactId1, transportId1);
|
c.registerConnection(contactId1, transportId1);
|
||||||
assertEquals(Arrays.asList(new ContactId[] {contactId, contactId1}),
|
assertEquals(Arrays.asList(contactId, contactId1),
|
||||||
c.getConnectedContacts(transportId));
|
c.getConnectedContacts(transportId));
|
||||||
assertEquals(Collections.singletonList(contactId1),
|
assertEquals(Collections.singletonList(contactId1),
|
||||||
c.getConnectedContacts(transportId1));
|
c.getConnectedContacts(transportId1));
|
||||||
|
|||||||
Reference in New Issue
Block a user