Calm time travel checks, don't continually reschedule key rotation
FREEBIE
This commit is contained in:
parent
f37af04818
commit
bc437095f6
2 changed files with 16 additions and 10 deletions
|
@ -7,6 +7,7 @@
|
|||
window.Whisper = window.Whisper || {};
|
||||
var ROTATION_INTERVAL = 48 * 60 * 60 * 1000;
|
||||
var timeout;
|
||||
var scheduledTime;
|
||||
|
||||
function scheduleNextRotation() {
|
||||
var now = Date.now();
|
||||
|
@ -35,14 +36,20 @@
|
|||
|
||||
function setTimeoutForNextRun() {
|
||||
var now = Date.now();
|
||||
var scheduledTime = storage.get('nextSignedKeyRotationTime', now);
|
||||
console.log('Next signed key rotation scheduled for', new Date(scheduledTime));
|
||||
var waitTime = scheduledTime - now;
|
||||
if (waitTime < 0) {
|
||||
waitTime = 0;
|
||||
var time = storage.get('nextSignedKeyRotationTime', now);
|
||||
|
||||
if (scheduledTime !== time || !timeout) {
|
||||
scheduledTime = time;
|
||||
|
||||
console.log('Next signed key rotation scheduled for', new Date(time));
|
||||
var waitTime = time - now;
|
||||
if (waitTime < 0) {
|
||||
waitTime = 0;
|
||||
}
|
||||
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(runWhenOnline, waitTime);
|
||||
}
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(runWhenOnline, waitTime);
|
||||
}
|
||||
|
||||
Whisper.RotateSignedPreKeyListener = {
|
||||
|
|
|
@ -7,12 +7,11 @@
|
|||
window.Whisper = window.Whisper || {};
|
||||
|
||||
var lastTime;
|
||||
var interval = 1000;
|
||||
var interval = 5000;
|
||||
var events;
|
||||
function checkTime() {
|
||||
var currentTime = Date.now();
|
||||
if (currentTime > (lastTime + interval * 2)) {
|
||||
console.log('time travel detected!');
|
||||
events.trigger('timetravel');
|
||||
}
|
||||
lastTime = currentTime;
|
||||
|
@ -22,7 +21,7 @@
|
|||
init: function(_events) {
|
||||
events = _events;
|
||||
lastTime = Date.now();
|
||||
setInterval(checkTime, 1000);
|
||||
setInterval(checkTime, interval);
|
||||
}
|
||||
};
|
||||
}());
|
||||
|
|
Loading…
Reference in a new issue