Remove transport ID from connection context.

This commit is contained in:
akwizgran
2011-11-15 17:32:31 +00:00
parent 9220bb3426
commit fabdaf5957
6 changed files with 8 additions and 32 deletions

View File

@@ -1,15 +1,12 @@
package net.sf.briar.api.transport;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.protocol.TransportId;
import net.sf.briar.api.protocol.TransportIndex;
public interface ConnectionContext {
ContactId getContactId();
TransportId getTransportId();
TransportIndex getTransportIndex();
long getConnectionNumber();

View File

@@ -1,21 +1,18 @@
package net.sf.briar.transport;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.protocol.TransportId;
import net.sf.briar.api.protocol.TransportIndex;
import net.sf.briar.api.transport.ConnectionContext;
class ConnectionContextImpl implements ConnectionContext {
private final ContactId contactId;
private final TransportId transportId;
private final TransportIndex transportIndex;
private final long connectionNumber;
ConnectionContextImpl(ContactId contactId, TransportId transportId,
TransportIndex transportIndex, long connectionNumber) {
ConnectionContextImpl(ContactId contactId, TransportIndex transportIndex,
long connectionNumber) {
this.contactId = contactId;
this.transportId = transportId;
this.transportIndex = transportIndex;
this.connectionNumber = connectionNumber;
}
@@ -24,10 +21,6 @@ class ConnectionContextImpl implements ConnectionContext {
return contactId;
}
public TransportId getTransportId() {
return transportId;
}
public TransportIndex getTransportIndex() {
return transportIndex;
}

View File

@@ -62,12 +62,6 @@ public class ConnectionDispatcherImpl implements ConnectionDispatcher {
r.dispose(false);
return;
}
if(!t.equals(ctx.getTransportId())) {
if(LOG.isLoggable(Level.WARNING))
LOG.warning("Connection has unexpected transport ID");
r.dispose(false);
return;
}
batchConnFactory.createIncomingConnection(ctx.getTransportIndex(),
ctx.getContactId(), r, encryptedIv);
}
@@ -112,12 +106,6 @@ public class ConnectionDispatcherImpl implements ConnectionDispatcher {
s.dispose(false);
return;
}
if(!t.equals(ctx.getTransportId())) {
if(LOG.isLoggable(Level.WARNING))
LOG.warning("Connection has unexpected transport ID");
s.dispose(false);
return;
}
streamConnFactory.createIncomingConnection(ctx.getTransportIndex(),
ctx.getContactId(), s, encryptedIv);
}

View File

@@ -82,17 +82,17 @@ DatabaseListener {
TransportIndex i = db.getRemoteIndex(c, t);
if(i != null) {
ConnectionWindow w = db.getConnectionWindow(c, i);
calculateIvs(c, t, i, ivKey, w);
calculateIvs(c, i, ivKey, w);
}
}
}
private synchronized void calculateIvs(ContactId c, TransportId t,
TransportIndex i, ErasableKey ivKey, ConnectionWindow w)
private synchronized void calculateIvs(ContactId c, TransportIndex i,
ErasableKey ivKey, ConnectionWindow w)
throws DbException {
for(Long unseen : w.getUnseen()) {
Bytes iv = new Bytes(encryptIv(i, unseen, ivKey));
expected.put(iv, new ConnectionContextImpl(c, t, i, unseen));
expected.put(iv, new ConnectionContextImpl(c, i, unseen));
}
}
@@ -136,7 +136,7 @@ DatabaseListener {
byte[] secret = db.getSharedSecret(c, true);
ErasableKey ivKey = crypto.deriveIvKey(secret, true);
for(int j = 0; j < secret.length; j++) secret[j] = 0;
calculateIvs(c, ctx.getTransportId(), i, ivKey, w);
calculateIvs(c, i, ivKey, w);
} catch(NoSuchContactException e) {
// The contact was removed - clean up when we get the event
}
@@ -191,7 +191,7 @@ DatabaseListener {
TransportIndex i = db.getRemoteIndex(c, t);
if(i != null) {
ConnectionWindow w = db.getConnectionWindow(c, i);
calculateIvs(c, t, i, ivKey, w);
calculateIvs(c, i, ivKey, w);
}
} catch(NoSuchContactException e) {
// The contact was removed - clean up when we get the event

View File

@@ -116,7 +116,6 @@ public class ConnectionRecogniserImplTest extends TestCase {
ConnectionContext ctx = c.acceptConnection(encryptedIv);
assertNotNull(ctx);
assertEquals(contactId, ctx.getContactId());
assertEquals(transportId, ctx.getTransportId());
assertEquals(remoteIndex, ctx.getTransportIndex());
assertEquals(3L, ctx.getConnectionNumber());
// Second time - the IV should no longer be expected

View File

@@ -162,7 +162,6 @@ public class BatchConnectionReadWriteTest extends TestCase {
ConnectionContext ctx = rec.acceptConnection(encryptedIv);
assertNotNull(ctx);
assertEquals(contactId, ctx.getContactId());
assertEquals(transportId, ctx.getTransportId());
assertEquals(transportIndex, ctx.getTransportIndex());
// Create an incoming batch connection
ConnectionReaderFactory connFactory =