mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 06:09:55 +01:00
The connection recogniser doesn't need to store newly added windows.
This commit is contained in:
@@ -18,7 +18,7 @@ public interface ConnectionRecogniser {
|
|||||||
ConnectionContext acceptConnection(TransportId t, byte[] tag)
|
ConnectionContext acceptConnection(TransportId t, byte[] tag)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
void addSecret(TemporarySecret s) throws DbException;
|
void addSecret(TemporarySecret s);
|
||||||
|
|
||||||
void removeSecret(ContactId c, TransportId t, long period);
|
void removeSecret(ContactId c, TransportId t, long period);
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class ConnectionRecogniserImpl implements ConnectionRecogniser {
|
|||||||
return r.acceptConnection(tag);
|
return r.acceptConnection(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSecret(TemporarySecret s) throws DbException {
|
public void addSecret(TemporarySecret s) {
|
||||||
TransportId t = s.getTransportId();
|
TransportId t = s.getTransportId();
|
||||||
TransportConnectionRecogniser r;
|
TransportConnectionRecogniser r;
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ import net.sf.briar.util.ByteUtils;
|
|||||||
|
|
||||||
import com.google.inject.Inject;
|
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 {
|
class KeyManagerImpl extends TimerTask implements KeyManager, DatabaseListener {
|
||||||
|
|
||||||
private static final int MS_BETWEEN_CHECKS = 60 * 1000;
|
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);
|
Collection<TemporarySecret> dead = assignSecretsToMaps(now, secrets);
|
||||||
// Replace any dead secrets
|
// Replace any dead secrets
|
||||||
Collection<TemporarySecret> created = replaceDeadSecrets(now, dead);
|
Collection<TemporarySecret> created = replaceDeadSecrets(now, dead);
|
||||||
try {
|
if(!created.isEmpty()) {
|
||||||
// Store any secrets that have been created
|
// Store any secrets that have been created
|
||||||
if(!created.isEmpty()) db.addSecrets(created);
|
try {
|
||||||
// Pass the current incoming secrets to the recogniser
|
db.addSecrets(created);
|
||||||
// FIXME: This uses a separate database transaction per secret
|
} catch(DbException e) {
|
||||||
for(TemporarySecret s : incomingOld.values())
|
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
|
||||||
recogniser.addSecret(s);
|
return false;
|
||||||
for(TemporarySecret s : incomingNew.values())
|
}
|
||||||
recogniser.addSecret(s);
|
|
||||||
} 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
|
// Schedule periodic key rotation
|
||||||
timer.scheduleAtFixedRate(this, MS_BETWEEN_CHECKS, MS_BETWEEN_CHECKS);
|
timer.scheduleAtFixedRate(this, MS_BETWEEN_CHECKS, MS_BETWEEN_CHECKS);
|
||||||
running = true;
|
running = true;
|
||||||
@@ -247,15 +248,14 @@ class KeyManagerImpl extends TimerTask implements KeyManager, DatabaseListener {
|
|||||||
// Replace any dead secrets
|
// Replace any dead secrets
|
||||||
Collection<TemporarySecret> created = replaceDeadSecrets(now, dead);
|
Collection<TemporarySecret> created = replaceDeadSecrets(now, dead);
|
||||||
if(!created.isEmpty()) {
|
if(!created.isEmpty()) {
|
||||||
|
// Store any secrets that have been created
|
||||||
try {
|
try {
|
||||||
// Store any secrets that have been created
|
|
||||||
db.addSecrets(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) {
|
} catch(DbException e) {
|
||||||
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
|
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;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized void addSecret(TemporarySecret s) throws DbException {
|
synchronized void addSecret(TemporarySecret s) {
|
||||||
ContactId contactId = s.getContactId();
|
ContactId contactId = s.getContactId();
|
||||||
long period = s.getPeriod();
|
long period = s.getPeriod();
|
||||||
byte[] secret = s.getSecret();
|
byte[] secret = s.getSecret();
|
||||||
@@ -95,9 +95,7 @@ class TransportConnectionRecogniser {
|
|||||||
WindowContext old = tagMap.put(new Bytes(tag), wctx);
|
WindowContext old = tagMap.put(new Bytes(tag), wctx);
|
||||||
assert old == null;
|
assert old == null;
|
||||||
}
|
}
|
||||||
// Store the new connection window in the DB
|
// Create a removal context to remove the window later
|
||||||
db.setConnectionWindow(contactId, transportId, period, centre, bitmap);
|
|
||||||
// Create a removal context to remove the window when the key expires
|
|
||||||
RemovalContext rctx = new RemovalContext(window, secret, alice);
|
RemovalContext rctx = new RemovalContext(window, secret, alice);
|
||||||
removalMap.put(new RemovalKey(contactId, period), rctx);
|
removalMap.put(new RemovalKey(contactId, period), rctx);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user