Commit aef83df5 authored by akwizgran's avatar akwizgran

The connection recogniser doesn't need to store newly added windows.

parent 9b00a6f0
......@@ -18,7 +18,7 @@ public interface ConnectionRecogniser {
ConnectionContext acceptConnection(TransportId t, byte[] tag)
throws DbException;
void addSecret(TemporarySecret s) throws DbException;
void addSecret(TemporarySecret s);
void removeSecret(ContactId c, TransportId t, long period);
......
......@@ -38,7 +38,7 @@ class ConnectionRecogniserImpl implements ConnectionRecogniser {
return r.acceptConnection(tag);
}
public void addSecret(TemporarySecret s) throws DbException {
public void addSecret(TemporarySecret s) {
TransportId t = s.getTransportId();
TransportConnectionRecogniser r;
synchronized(this) {
......
......@@ -26,6 +26,8 @@ import net.sf.briar.util.ByteUtils;
import com.google.inject.Inject;
// FIXME: When a contact transport is added we need to load its secrets
class KeyManagerImpl extends TimerTask implements KeyManager, DatabaseListener {
private static final int MS_BETWEEN_CHECKS = 60 * 1000;
......@@ -73,19 +75,18 @@ class KeyManagerImpl extends TimerTask implements KeyManager, DatabaseListener {
Collection<TemporarySecret> dead = assignSecretsToMaps(now, secrets);
// Replace any dead secrets
Collection<TemporarySecret> created = replaceDeadSecrets(now, dead);
try {
if(!created.isEmpty()) {
// Store any secrets that have been created
if(!created.isEmpty()) db.addSecrets(created);
// Pass the current incoming secrets to the recogniser
// FIXME: This uses a separate database transaction per secret
for(TemporarySecret s : incomingOld.values())
recogniser.addSecret(s);
for(TemporarySecret s : incomingNew.values())
recogniser.addSecret(s);
} catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
return false;
try {
db.addSecrets(created);
} catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
return false;
}
}
// Pass the current incoming secrets to the recogniser
for(TemporarySecret s : incomingOld.values()) recogniser.addSecret(s);
for(TemporarySecret s : incomingNew.values()) recogniser.addSecret(s);
// Schedule periodic key rotation
timer.scheduleAtFixedRate(this, MS_BETWEEN_CHECKS, MS_BETWEEN_CHECKS);
running = true;
......@@ -247,15 +248,14 @@ class KeyManagerImpl extends TimerTask implements KeyManager, DatabaseListener {
// Replace any dead secrets
Collection<TemporarySecret> created = replaceDeadSecrets(now, dead);
if(!created.isEmpty()) {
// Store any secrets that have been created
try {
// Store any secrets that have been created
db.addSecrets(created);
// Pass any secrets that have been created to the recogniser
// FIXME: This uses a separate database transaction per secret
for(TemporarySecret s : created) recogniser.addSecret(s);
} catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
}
// Pass any secrets that have been created to the recogniser
for(TemporarySecret s : created) recogniser.addSecret(s);
}
}
......
......@@ -75,7 +75,7 @@ class TransportConnectionRecogniser {
return ctx;
}
synchronized void addSecret(TemporarySecret s) throws DbException {
synchronized void addSecret(TemporarySecret s) {
ContactId contactId = s.getContactId();
long period = s.getPeriod();
byte[] secret = s.getSecret();
......@@ -95,9 +95,7 @@ class TransportConnectionRecogniser {
WindowContext old = tagMap.put(new Bytes(tag), wctx);
assert old == null;
}
// Store the new connection window in the DB
db.setConnectionWindow(contactId, transportId, period, centre, bitmap);
// Create a removal context to remove the window when the key expires
// Create a removal context to remove the window later
RemovalContext rctx = new RemovalContext(window, secret, alice);
removalMap.put(new RemovalKey(contactId, period), rctx);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment