Renamed ContactTransport -> Endpoint, added more database exceptions.

This commit is contained in:
akwizgran
2013-01-29 15:24:34 +00:00
parent 54067763a6
commit 61a6931643
15 changed files with 199 additions and 161 deletions

View File

@@ -13,7 +13,7 @@ import net.sf.briar.api.Rating;
import net.sf.briar.api.TransportProperties;
import net.sf.briar.api.db.DatabaseComponent;
import net.sf.briar.api.db.NoSuchContactException;
import net.sf.briar.api.db.NoSuchContactTransportException;
import net.sf.briar.api.db.NoSuchTransportException;
import net.sf.briar.api.db.event.ContactAddedEvent;
import net.sf.briar.api.db.event.ContactRemovedEvent;
import net.sf.briar.api.db.event.DatabaseListener;
@@ -33,7 +33,7 @@ import net.sf.briar.api.protocol.SubscriptionUpdate;
import net.sf.briar.api.protocol.Transport;
import net.sf.briar.api.protocol.TransportId;
import net.sf.briar.api.protocol.TransportUpdate;
import net.sf.briar.api.transport.ContactTransport;
import net.sf.briar.api.transport.Endpoint;
import net.sf.briar.api.transport.TemporarySecret;
import org.jmock.Expectations;
@@ -55,7 +55,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
private final Group group;
private final TransportId transportId;
private final Collection<Transport> transports;
private final ContactTransport contactTransport;
private final Endpoint contactTransport;
private final TemporarySecret temporarySecret;
public DatabaseComponentTest() {
@@ -79,7 +79,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
Collections.singletonMap("foo", "bar"));
Transport transport = new Transport(transportId, properties);
transports = Collections.singletonList(transport);
contactTransport = new ContactTransport(contactId, transportId, 123L,
contactTransport = new Endpoint(contactId, transportId, 123L,
234L, 345L, true);
temporarySecret = new TemporarySecret(contactId, transportId, 1L, 2L,
3L, false, 4L, new byte[32], 5L, 6L, new byte[4]);
@@ -494,7 +494,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
shutdown);
try {
db.addContactTransport(contactTransport);
db.addEndpoint(contactTransport);
fail();
} catch(NoSuchContactException expected) {}
@@ -589,7 +589,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
// Check whether the contact transport is in the DB (which it's not)
exactly(2).of(database).startTransaction();
will(returnValue(txn));
exactly(2).of(database).containsContactTransport(txn, contactId,
exactly(2).of(database).containsEndpoint(txn, contactId,
transportId);
will(returnValue(false));
exactly(2).of(database).abortTransaction(txn);
@@ -600,12 +600,12 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
try {
db.incrementConnectionCounter(contactId, transportId, 0L);
fail();
} catch(NoSuchContactTransportException expected) {}
} catch(NoSuchTransportException expected) {}
try {
db.setConnectionWindow(contactId, transportId, 0L, 0L, new byte[4]);
fail();
} catch(NoSuchContactTransportException expected) {}
} catch(NoSuchTransportException expected) {}
context.assertIsSatisfied();
}
@@ -1427,7 +1427,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
// addSecrets()
oneOf(database).startTransaction();
will(returnValue(txn));
oneOf(database).containsContactTransport(txn, contactId,
oneOf(database).containsEndpoint(txn, contactId,
transportId);
will(returnValue(true));
oneOf(database).addSecrets(txn,

View File

@@ -35,7 +35,7 @@ import net.sf.briar.api.protocol.Message;
import net.sf.briar.api.protocol.MessageId;
import net.sf.briar.api.protocol.Transport;
import net.sf.briar.api.protocol.TransportId;
import net.sf.briar.api.transport.ContactTransport;
import net.sf.briar.api.transport.Endpoint;
import net.sf.briar.api.transport.TemporarySecret;
import org.apache.commons.io.FileSystemUtils;
@@ -1562,7 +1562,7 @@ public class H2DatabaseTest extends BriarTestCase {
long outgoing1 = 456L, centre1 = 567L;
long outgoing2 = 678L, centre2 = 789L;
long outgoing3 = 890L, centre3 = 901L;
ContactTransport ct = new ContactTransport(contactId, transportId,
Endpoint ct = new Endpoint(contactId, transportId,
epoch, clockDiff, latency, alice);
Random random = new Random();
byte[] secret1 = new byte[32], bitmap1 = new byte[4];
@@ -1592,7 +1592,7 @@ public class H2DatabaseTest extends BriarTestCase {
// Add the contact transport and the first two secrets
assertEquals(contactId, db.addContact(txn));
db.addContactTransport(txn, ct);
db.addEndpoint(txn, ct);
db.addSecrets(txn, Arrays.asList(s1, s2));
// Retrieve the first two secrets
@@ -1671,7 +1671,7 @@ public class H2DatabaseTest extends BriarTestCase {
long epoch = 123L, clockDiff = 234L, latency = 345L;
boolean alice = false;
long period = 456L, outgoing = 567L, centre = 678L;
ContactTransport ct = new ContactTransport(contactId, transportId,
Endpoint ct = new Endpoint(contactId, transportId,
epoch, clockDiff, latency, alice);
Random random = new Random();
byte[] secret = new byte[32], bitmap = new byte[4];
@@ -1685,7 +1685,7 @@ public class H2DatabaseTest extends BriarTestCase {
// Add the contact transport and the temporary secret
assertEquals(contactId, db.addContact(txn));
db.addContactTransport(txn, ct);
db.addEndpoint(txn, ct);
db.addSecrets(txn, Arrays.asList(s));
// Retrieve the secret
@@ -1726,7 +1726,7 @@ public class H2DatabaseTest extends BriarTestCase {
long epoch = 123L, clockDiff = 234L, latency = 345L;
boolean alice = false;
long period = 456L, outgoing = 567L, centre = 678L;
ContactTransport ct = new ContactTransport(contactId, transportId,
Endpoint ct = new Endpoint(contactId, transportId,
epoch, clockDiff, latency, alice);
Random random = new Random();
byte[] secret = new byte[32], bitmap = new byte[4];
@@ -1740,7 +1740,7 @@ public class H2DatabaseTest extends BriarTestCase {
// Add the contact transport and the temporary secret
assertEquals(contactId, db.addContact(txn));
db.addContactTransport(txn, ct);
db.addEndpoint(txn, ct);
db.addSecrets(txn, Arrays.asList(s));
// Retrieve the secret
@@ -1797,27 +1797,27 @@ public class H2DatabaseTest extends BriarTestCase {
boolean alice1 = true, alice2 = false;
TransportId transportId1 = new TransportId(TestUtils.getRandomId());
TransportId transportId2 = new TransportId(TestUtils.getRandomId());
ContactTransport ct1 = new ContactTransport(contactId, transportId1,
Endpoint ct1 = new Endpoint(contactId, transportId1,
epoch1, clockDiff1, latency1, alice1);
ContactTransport ct2 = new ContactTransport(contactId, transportId2,
Endpoint ct2 = new Endpoint(contactId, transportId2,
epoch2, clockDiff2, latency2, alice2);
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));
assertEquals(Collections.emptyList(), db.getEndpoints(txn));
// Add a contact and the contact transports
assertEquals(contactId, db.addContact(txn));
db.addContactTransport(txn, ct1);
db.addContactTransport(txn, ct2);
db.addEndpoint(txn, ct1);
db.addEndpoint(txn, ct2);
// Retrieve the contact transports
Collection<ContactTransport> cts = db.getContactTransports(txn);
Collection<Endpoint> cts = db.getEndpoints(txn);
assertEquals(2, cts.size());
boolean foundFirst = false, foundSecond = false;
for(ContactTransport ct : cts) {
for(Endpoint ct : cts) {
assertEquals(contactId, ct.getContactId());
if(ct.getTransportId().equals(transportId1)) {
assertEquals(epoch1, ct.getEpoch());
@@ -1840,7 +1840,7 @@ public class H2DatabaseTest extends BriarTestCase {
// Removing the contact should remove the contact transports
db.removeContact(txn, contactId);
assertEquals(Collections.emptyList(), db.getContactTransports(txn));
assertEquals(Collections.emptyList(), db.getEndpoints(txn));
db.commitTransaction(txn);
db.close();

View File

@@ -29,7 +29,7 @@ import net.sf.briar.api.transport.ConnectionReaderFactory;
import net.sf.briar.api.transport.ConnectionRecogniser;
import net.sf.briar.api.transport.ConnectionRegistry;
import net.sf.briar.api.transport.ConnectionWriterFactory;
import net.sf.briar.api.transport.ContactTransport;
import net.sf.briar.api.transport.Endpoint;
import net.sf.briar.clock.ClockModule;
import net.sf.briar.crypto.CryptoModule;
import net.sf.briar.db.DatabaseModule;
@@ -107,10 +107,10 @@ public class SimplexProtocolIntegrationTest extends BriarTestCase {
km.start();
// Add Bob as a contact
ContactId contactId = db.addContact();
ContactTransport ct = new ContactTransport(contactId, transportId,
Endpoint ct = new Endpoint(contactId, transportId,
epoch, CLOCK_DIFFERENCE, LATENCY, true);
db.addContactTransport(ct);
km.contactTransportAdded(ct, initialSecret.clone());
db.addEndpoint(ct);
km.endpointAdded(ct, initialSecret.clone());
// Send Bob a message
String subject = "Hello";
byte[] body = "Hi Bob!".getBytes("UTF-8");
@@ -151,10 +151,10 @@ public class SimplexProtocolIntegrationTest extends BriarTestCase {
km.start();
// Add Alice as a contact
ContactId contactId = db.addContact();
ContactTransport ct = new ContactTransport(contactId, transportId,
Endpoint ct = new Endpoint(contactId, transportId,
epoch, CLOCK_DIFFERENCE, LATENCY, false);
db.addContactTransport(ct);
km.contactTransportAdded(ct, initialSecret.clone());
db.addEndpoint(ct);
km.endpointAdded(ct, initialSecret.clone());
// Set up a database listener
MessageListener listener = new MessageListener();
db.addListener(listener);