timedata: refactor time.add().
This commit is contained in:
parent
7ef658049c
commit
beacd48462
@ -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-2015, Fedor Indutny (MIT License)
|
||||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||||
* https://github.com/bcoin-org/bcoin
|
* https://github.com/bcoin-org/bcoin
|
||||||
@ -64,12 +64,9 @@ TimeData.prototype.add = function add(id, time) {
|
|||||||
this.emit('sample', sample, this.samples.length);
|
this.emit('sample', sample, this.samples.length);
|
||||||
|
|
||||||
if (this.samples.length >= 5 && this.samples.length % 2 === 1) {
|
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) {
|
if (Math.abs(median) >= 70 * 60) {
|
||||||
this.offset = median;
|
|
||||||
} else {
|
|
||||||
this.offset = 0;
|
|
||||||
if (!this.checked) {
|
if (!this.checked) {
|
||||||
let match = false;
|
let match = false;
|
||||||
for (let offset of this.samples) {
|
for (let offset of this.samples) {
|
||||||
@ -83,8 +80,10 @@ TimeData.prototype.add = function add(id, time) {
|
|||||||
this.emit('mismatch');
|
this.emit('mismatch');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
median = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.offset = median;
|
||||||
this.emit('offset', this.offset);
|
this.emit('offset', this.offset);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user