diff --git a/lib/protocol/timedata.js b/lib/protocol/timedata.js index 5d27b22e..f0939620 100644 --- a/lib/protocol/timedata.js +++ b/lib/protocol/timedata.js @@ -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); } };