mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
Remove transport ID from connection context.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user