Skip to content
Snippets Groups Projects
Unverified Commit 8d034960 authored by akwizgran's avatar akwizgran
Browse files

Don't reschedule the same TimerTask. #254

parent a774b341
No related branches found
No related tags found
No related merge requests found
......@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment