mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 13:49:53 +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.api.transport.TransportConstants.TAG_LENGTH;
|
||||||
import static org.briarproject.util.ByteUtils.MAX_32_BIT_UNSIGNED;
|
import static org.briarproject.util.ByteUtils.MAX_32_BIT_UNSIGNED;
|
||||||
|
|
||||||
class TransportKeyManager extends TimerTask {
|
class TransportKeyManager {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(TransportKeyManager.class.getName());
|
Logger.getLogger(TransportKeyManager.class.getName());
|
||||||
@@ -110,8 +110,7 @@ class TransportKeyManager extends TimerTask {
|
|||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
// Schedule the next key rotation
|
// Schedule the next key rotation
|
||||||
long delay = rotationPeriodLength - now % rotationPeriodLength;
|
scheduleKeyRotation(now);
|
||||||
timer.schedule(this, delay);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Locking: lock
|
// 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,
|
void addContact(ContactId c, SecretKey master, long timestamp,
|
||||||
boolean alice) {
|
boolean alice) {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
@@ -253,8 +262,7 @@ class TransportKeyManager extends TimerTask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void rotateKeys() {
|
||||||
public void run() {
|
|
||||||
long now = clock.currentTimeMillis();
|
long now = clock.currentTimeMillis();
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
@@ -293,8 +301,7 @@ class TransportKeyManager extends TimerTask {
|
|||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
// Schedule the next key rotation
|
// Schedule the next key rotation
|
||||||
long delay = rotationPeriodLength - now % rotationPeriodLength;
|
scheduleKeyRotation(now);
|
||||||
timer.schedule(this, delay);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TagContext {
|
private static class TagContext {
|
||||||
|
|||||||
Reference in New Issue
Block a user