timedata: refactor time.add().

This commit is contained in:
Christopher Jeffrey 2017-07-20 13:13:47 -07:00
parent 7ef658049c
commit beacd48462
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -1,5 +1,5 @@
/*!
* time.js - time management for bcoin
* timedata.js - time management for bcoin
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
* https://github.com/bcoin-org/bcoin
@ -64,12 +64,9 @@ TimeData.prototype.add = function add(id, time) {
this.emit('sample', sample, this.samples.length);
if (this.samples.length >= 5 && this.samples.length % 2 === 1) {
let median = this.samples[this.samples / 2 | 0];
let median = this.samples[this.samples.length >>> 1];
if (Math.abs(median) < 70 * 60) {
this.offset = median;
} else {
this.offset = 0;
if (Math.abs(median) >= 70 * 60) {
if (!this.checked) {
let match = false;
for (let offset of this.samples) {
@ -83,8 +80,10 @@ TimeData.prototype.add = function add(id, time) {
this.emit('mismatch');
}
}
median = 0;
}
this.offset = median;
this.emit('offset', this.offset);
}
};