Calm time travel checks, don't continually reschedule key rotation

FREEBIE
This commit is contained in:
Scott Nonnenberg 2017-07-28 11:11:26 -07:00
parent f37af04818
commit bc437095f6
No known key found for this signature in database
GPG key ID: A4931C09644C654B
2 changed files with 16 additions and 10 deletions

View file

@ -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,15 +36,21 @@
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;
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);
}
}
Whisper.RotateSignedPreKeyListener = {
init: function(events) {

View file

@ -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);
}
};
}());