mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Don't reschedule the same TimerTask. #254
This commit is contained in:
@@ -27,7 +27,7 @@ import static org.briarproject.api.transport.TransportConstants.MAX_CLOCK_DIFFER
|
||||
import static org.briarproject.api.transport.TransportConstants.TAG_LENGTH;
|
||||
import static org.briarproject.util.ByteUtils.MAX_32_BIT_UNSIGNED;
|
||||
|
||||
class TransportKeyManager extends TimerTask {
|
||||
class TransportKeyManager {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(TransportKeyManager.class.getName());
|
||||
@@ -110,8 +110,7 @@ class TransportKeyManager extends TimerTask {
|
||||
lock.unlock();
|
||||
}
|
||||
// Schedule the next key rotation
|
||||
long delay = rotationPeriodLength - now % rotationPeriodLength;
|
||||
timer.schedule(this, delay);
|
||||
scheduleKeyRotation(now);
|
||||
}
|
||||
|
||||
// Locking: lock
|
||||
@@ -133,6 +132,16 @@ class TransportKeyManager extends TimerTask {
|
||||
}
|
||||
}
|
||||
|
||||
private void scheduleKeyRotation(long now) {
|
||||
TimerTask task = new TimerTask() {
|
||||
public void run() {
|
||||
rotateKeys();
|
||||
}
|
||||
};
|
||||
long delay = rotationPeriodLength - now % rotationPeriodLength;
|
||||
timer.schedule(task, delay);
|
||||
}
|
||||
|
||||
void addContact(ContactId c, SecretKey master, long timestamp,
|
||||
boolean alice) {
|
||||
lock.lock();
|
||||
@@ -253,8 +262,7 @@ class TransportKeyManager extends TimerTask {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
private void rotateKeys() {
|
||||
long now = clock.currentTimeMillis();
|
||||
lock.lock();
|
||||
try {
|
||||
@@ -293,8 +301,7 @@ class TransportKeyManager extends TimerTask {
|
||||
lock.unlock();
|
||||
}
|
||||
// Schedule the next key rotation
|
||||
long delay = rotationPeriodLength - now % rotationPeriodLength;
|
||||
timer.schedule(this, delay);
|
||||
scheduleKeyRotation(now);
|
||||
}
|
||||
|
||||
private static class TagContext {
|
||||
|
||||
Reference in New Issue
Block a user