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; package net.sf.briar.api.transport;
import net.sf.briar.api.ContactId; 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.protocol.TransportIndex;
public interface ConnectionContext { public interface ConnectionContext {
ContactId getContactId(); ContactId getContactId();
TransportId getTransportId();
TransportIndex getTransportIndex(); TransportIndex getTransportIndex();
long getConnectionNumber(); long getConnectionNumber();

View File

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

View File

@@ -62,12 +62,6 @@ public class ConnectionDispatcherImpl implements ConnectionDispatcher {
r.dispose(false); r.dispose(false);
return; 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(), batchConnFactory.createIncomingConnection(ctx.getTransportIndex(),
ctx.getContactId(), r, encryptedIv); ctx.getContactId(), r, encryptedIv);
} }
@@ -112,12 +106,6 @@ public class ConnectionDispatcherImpl implements ConnectionDispatcher {
s.dispose(false); s.dispose(false);
return; 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(), streamConnFactory.createIncomingConnection(ctx.getTransportIndex(),
ctx.getContactId(), s, encryptedIv); ctx.getContactId(), s, encryptedIv);
} }

View File

@@ -82,17 +82,17 @@ DatabaseListener {
TransportIndex i = db.getRemoteIndex(c, t); TransportIndex i = db.getRemoteIndex(c, t);
if(i != null) { if(i != null) {
ConnectionWindow w = db.getConnectionWindow(c, i); 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, private synchronized void calculateIvs(ContactId c, TransportIndex i,
TransportIndex i, ErasableKey ivKey, ConnectionWindow w) ErasableKey ivKey, ConnectionWindow w)
throws DbException { throws DbException {
for(Long unseen : w.getUnseen()) { for(Long unseen : w.getUnseen()) {
Bytes iv = new Bytes(encryptIv(i, unseen, ivKey)); 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); byte[] secret = db.getSharedSecret(c, true);
ErasableKey ivKey = crypto.deriveIvKey(secret, true); ErasableKey ivKey = crypto.deriveIvKey(secret, true);
for(int j = 0; j < secret.length; j++) secret[j] = 0; 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) { } catch(NoSuchContactException e) {
// The contact was removed - clean up when we get the event // The contact was removed - clean up when we get the event
} }
@@ -191,7 +191,7 @@ DatabaseListener {
TransportIndex i = db.getRemoteIndex(c, t); TransportIndex i = db.getRemoteIndex(c, t);
if(i != null) { if(i != null) {
ConnectionWindow w = db.getConnectionWindow(c, i); ConnectionWindow w = db.getConnectionWindow(c, i);
calculateIvs(c, t, i, ivKey, w); calculateIvs(c, i, ivKey, w);
} }
} catch(NoSuchContactException e) { } catch(NoSuchContactException e) {
// The contact was removed - clean up when we get the event // 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); ConnectionContext ctx = c.acceptConnection(encryptedIv);
assertNotNull(ctx); assertNotNull(ctx);
assertEquals(contactId, ctx.getContactId()); assertEquals(contactId, ctx.getContactId());
assertEquals(transportId, ctx.getTransportId());
assertEquals(remoteIndex, ctx.getTransportIndex()); assertEquals(remoteIndex, ctx.getTransportIndex());
assertEquals(3L, ctx.getConnectionNumber()); assertEquals(3L, ctx.getConnectionNumber());
// Second time - the IV should no longer be expected // 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); ConnectionContext ctx = rec.acceptConnection(encryptedIv);
assertNotNull(ctx); assertNotNull(ctx);
assertEquals(contactId, ctx.getContactId()); assertEquals(contactId, ctx.getContactId());
assertEquals(transportId, ctx.getTransportId());
assertEquals(transportIndex, ctx.getTransportIndex()); assertEquals(transportIndex, ctx.getTransportIndex());
// Create an incoming batch connection // Create an incoming batch connection
ConnectionReaderFactory connFactory = ConnectionReaderFactory connFactory =