Comparing version 1.0.9 to 2.0.0
@@ -1,16 +0,25 @@ | ||
var Sntp = require('../lib'); | ||
'use strict'; | ||
// Load modules | ||
const Sntp = require('../lib'); | ||
// Declare internals | ||
const internals = {}; | ||
// Request offset once | ||
Sntp.offset(function (err, offset) { | ||
Sntp.offset((err, offset1) => { | ||
console.log(offset); // New (served fresh) | ||
console.log(offset1); // New (served fresh) | ||
// Request offset again | ||
Sntp.offset(function (err, offset) { | ||
Sntp.offset((err, offset2) => { | ||
console.log(offset); // Identical (served from cache) | ||
console.log(offset2); // Identical (served from cache) | ||
}); | ||
}); | ||
@@ -1,6 +0,16 @@ | ||
var Sntp = require('../lib'); | ||
'use strict'; | ||
// Load modules | ||
const Sntp = require('../lib'); | ||
// Declare internals | ||
const internals = {}; | ||
// All options are optional | ||
var options = { | ||
const options = { | ||
host: 'nist1-sj.ustiming.org', // Defaults to pool.ntp.org | ||
@@ -14,3 +24,3 @@ port: 123, // Defaults to 123 (NTP) | ||
Sntp.time(options, function (err, time) { | ||
Sntp.time(options, (err, time) => { | ||
@@ -26,2 +36,1 @@ if (err) { | ||
}); | ||
110
lib/index.js
@@ -0,6 +1,8 @@ | ||
'use strict'; | ||
// Load modules | ||
var Dgram = require('dgram'); | ||
var Dns = require('dns'); | ||
var Hoek = require('hoek'); | ||
const Dgram = require('dgram'); | ||
const Dns = require('dns'); | ||
const Hoek = require('hoek'); | ||
@@ -10,3 +12,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -21,3 +23,3 @@ | ||
var settings = Hoek.clone(options); | ||
const settings = Hoek.clone(options); | ||
settings.host = settings.host || 'pool.ntp.org'; | ||
@@ -29,8 +31,8 @@ settings.port = settings.port || 123; | ||
var timeoutId = 0; | ||
var sent = 0; | ||
let timeoutId = 0; | ||
let sent = 0; | ||
// Ensure callback is only called once | ||
var finish = function (err, result) { | ||
const finish = Hoek.once((err, result) => { | ||
@@ -43,25 +45,20 @@ if (timeoutId) { | ||
socket.removeAllListeners(); | ||
socket.once('error', internals.ignore); | ||
socket.once('error', Hoek.ignore); | ||
socket.close(); | ||
return callback(err, result); | ||
}; | ||
}); | ||
finish = Hoek.once(finish); | ||
// Create UDP socket | ||
var socket = Dgram.createSocket('udp4'); | ||
const socket = Dgram.createSocket('udp4'); | ||
socket.once('error', function (err) { | ||
socket.once('error', (err) => finish(err)); | ||
return finish(err); | ||
}); | ||
// Listen to incoming messages | ||
socket.on('message', function (buffer, rinfo) { | ||
socket.on('message', (buffer, rinfo) => { | ||
var received = Date.now(); | ||
const received = Date.now(); | ||
var message = new internals.NtpMessage(buffer); | ||
const message = new internals.NtpMessage(buffer); | ||
if (!message.isValid) { | ||
@@ -86,6 +83,6 @@ return finish(new Error('Invalid server response'), message); | ||
var T1 = message.originateTimestamp; | ||
var T2 = message.receiveTimestamp; | ||
var T3 = message.transmitTimestamp; | ||
var T4 = received; | ||
const T1 = message.originateTimestamp; | ||
const T2 = message.receiveTimestamp; | ||
const T3 = message.transmitTimestamp; | ||
const T4 = received; | ||
@@ -104,3 +101,3 @@ message.d = (T4 - T1) - (T3 - T2); | ||
Dns.reverse(message.referenceId, function (err, domains) { | ||
Dns.reverse(message.referenceId, (err, domains) => { | ||
@@ -118,3 +115,3 @@ if (/* $lab:coverage:off$ */ !err /* $lab:coverage:on$ */) { | ||
if (settings.timeout) { | ||
timeoutId = setTimeout(function () { | ||
timeoutId = setTimeout(() => { | ||
@@ -128,8 +125,8 @@ timeoutId = 0; | ||
var message = new Buffer(48); | ||
for (var i = 0; i < 48; i++) { // Zero message | ||
const message = new Buffer(48); | ||
for (let i = 0; i < 48; i++) { // Zero message | ||
message[i] = 0; | ||
} | ||
message[0] = (0 << 6) + (4 << 3) + (3 << 0) // Set version number to 4 and Mode to 3 (client) | ||
message[0] = (0 << 6) + (4 << 3) + (3 << 0); // Set version number to 4 and Mode to 3 (client) | ||
sent = Date.now(); | ||
@@ -140,3 +137,3 @@ internals.fromMsecs(sent, message, 40); // Set transmit timestamp (returns as originate) | ||
socket.send(message, 0, message.length, settings.port, settings.host, function (err, bytes) { | ||
socket.send(message, 0, message.length, settings.port, settings.host, (err, bytes) => { | ||
@@ -164,3 +161,3 @@ if (err || | ||
var li = (buffer[0] >> 6); | ||
const li = (buffer[0] >> 6); | ||
switch (li) { | ||
@@ -175,3 +172,3 @@ case 0: this.leapIndicator = 'no-warning'; break; | ||
var vn = ((buffer[0] & 0x38) >> 3); | ||
const vn = ((buffer[0] & 0x38) >> 3); | ||
this.version = vn; | ||
@@ -181,3 +178,3 @@ | ||
var mode = (buffer[0] & 0x7); | ||
const mode = (buffer[0] & 0x7); | ||
switch (mode) { | ||
@@ -196,3 +193,3 @@ case 1: this.mode = 'symmetric-active'; break; | ||
var stratum = buffer[1]; | ||
const stratum = buffer[1]; | ||
if (stratum === 0) { | ||
@@ -221,3 +218,3 @@ this.stratum = 'death'; | ||
var rootDelay = 256 * (256 * (256 * buffer[4] + buffer[5]) + buffer[6]) + buffer[7]; | ||
const rootDelay = 256 * (256 * (256 * buffer[4] + buffer[5]) + buffer[6]) + buffer[7]; | ||
this.rootDelay = 1000 * (rootDelay / 0x10000); | ||
@@ -276,10 +273,10 @@ | ||
var seconds = 0; | ||
var fraction = 0; | ||
let seconds = 0; | ||
let fraction = 0; | ||
for (var i = 0; i < 4; ++i) { | ||
for (let i = 0; i < 4; ++i) { | ||
seconds = (seconds * 256) + buffer[offset + i]; | ||
} | ||
for (i = 4; i < 8; ++i) { | ||
for (let i = 4; i < 8; ++i) { | ||
fraction = (fraction * 256) + buffer[offset + i]; | ||
@@ -294,4 +291,4 @@ } | ||
var seconds = Math.floor(ts / 1000) + 2208988800; | ||
var fraction = Math.round((ts % 1000) / 1000 * Math.pow(2, 32)); | ||
const seconds = Math.floor(ts / 1000) + 2208988800; | ||
const fraction = Math.round((ts % 1000) / 1000 * Math.pow(2, 32)); | ||
@@ -327,4 +324,4 @@ buffer[offset + 0] = (seconds & 0xFF000000) >> 24; | ||
var now = Date.now(); | ||
var clockSyncRefresh = options.clockSyncRefresh || 24 * 60 * 60 * 1000; // Daily | ||
const now = Date.now(); | ||
const clockSyncRefresh = options.clockSyncRefresh || 24 * 60 * 60 * 1000; // Daily | ||
@@ -336,11 +333,7 @@ if (internals.last.offset && | ||
process.nextTick(function () { | ||
callback(null, internals.last.offset); | ||
}); | ||
process.nextTick(() => callback(null, internals.last.offset)); | ||
return; | ||
} | ||
exports.time(options, function (err, time) { | ||
exports.time(options, (err, time) => { | ||
@@ -378,15 +371,11 @@ if (err) { | ||
if (internals.now.intervalId) { | ||
process.nextTick(function () { | ||
callback(); | ||
}); | ||
process.nextTick(() => callback()); | ||
return; | ||
} | ||
exports.offset(options, function (err, offset) { | ||
exports.offset(options, (err, offset) => { | ||
internals.now.intervalId = setInterval(function () { | ||
internals.now.intervalId = setInterval(() => { | ||
exports.offset(options, function () { }); | ||
exports.offset(options, () => { }); | ||
}, options.clockSyncRefresh || 24 * 60 * 60 * 1000); // Daily | ||
@@ -418,3 +407,3 @@ | ||
var now = Date.now(); | ||
const now = Date.now(); | ||
if (!exports.isLive() || | ||
@@ -428,6 +417,1 @@ now >= internals.last.expires) { | ||
}; | ||
internals.ignore = function () { | ||
}; |
{ | ||
"name": "sntp", | ||
"description": "SNTP Client", | ||
"version": "1.0.9", | ||
"version": "2.0.0", | ||
"author": "Eran Hammer <eran@hammer.io> (http://hueniverse.com)", | ||
"contributors": [], | ||
"repository": "git://github.com/hueniverse/sntp", | ||
"main": "index", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/hapijs/hapi" | ||
}, | ||
"main": "lib/index.js", | ||
"keywords": [ | ||
@@ -15,19 +17,16 @@ "sntp", | ||
"engines": { | ||
"node": ">=0.8.0" | ||
"node": ">=4.0.0" | ||
}, | ||
"dependencies": { | ||
"hoek": "2.x.x" | ||
"hoek": "3.x.x" | ||
}, | ||
"devDependencies": { | ||
"lab": "4.x.x" | ||
"code": "2.x.x", | ||
"lab": "7.x.x" | ||
}, | ||
"scripts": { | ||
"test": "make test-cov" | ||
"test": "lab -a code -t 100 -L", | ||
"test-cov-html": "lab -a code -r html -o coverage.html" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "BSD", | ||
"url": "http://github.com/hueniverse/sntp/raw/master/LICENSE" | ||
} | ||
] | ||
"license": "BSD-3-Clause" | ||
} |
@@ -0,7 +1,9 @@ | ||
'use strict'; | ||
// Load modules | ||
var Dns = require('dns'); | ||
var Dgram = require('dgram'); | ||
var Lab = require('lab'); | ||
var Sntp = require('../lib'); | ||
const Dgram = require('dgram'); | ||
const Code = require('code'); | ||
const Lab = require('lab'); | ||
const Sntp = require('../lib'); | ||
@@ -11,3 +13,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -17,28 +19,26 @@ | ||
var lab = exports.lab = Lab.script(); | ||
var before = lab.before; | ||
var after = lab.after; | ||
var describe = lab.experiment; | ||
var it = lab.test; | ||
var expect = Lab.expect; | ||
const lab = exports.lab = Lab.script(); | ||
const describe = lab.describe; | ||
const it = lab.it; | ||
const expect = Code.expect; | ||
describe('SNTP', function () { | ||
describe('SNTP', () => { | ||
describe('#time', function () { | ||
describe('time()', () => { | ||
it('returns consistent result over multiple tries', function (done) { | ||
it('returns consistent result over multiple tries', (done) => { | ||
Sntp.time(function (err, time) { | ||
Sntp.time((err, time1) => { | ||
expect(err).to.not.exist; | ||
expect(time).to.exist; | ||
var t1 = time.t; | ||
expect(err).to.not.exist(); | ||
expect(time1).to.exist(); | ||
const t1 = time1.t; | ||
Sntp.time(function (err, time) { | ||
Sntp.time((err, time2) => { | ||
expect(err).to.not.exist; | ||
expect(time).to.exist; | ||
var t2 = time.t; | ||
expect(Math.abs(t1 - t2)).is.below(200); | ||
expect(err).to.not.exist(); | ||
expect(time2).to.exist(); | ||
const t2 = time2.t; | ||
expect(Math.abs(t1 - t2)).to.be.below(200); | ||
done(); | ||
@@ -49,9 +49,9 @@ }); | ||
it('resolves reference IP', function (done) { | ||
it('resolves reference IP', (done) => { | ||
Sntp.time({ host: 'ntp.exnet.com', resolveReference: true }, function (err, time) { | ||
Sntp.time({ host: 'ntp.exnet.com', resolveReference: true }, (err, time) => { | ||
expect(err).to.not.exist; | ||
expect(time).to.exist; | ||
expect(time.referenceHost).to.exist; | ||
expect(err).to.not.exist(); | ||
expect(time).to.exist(); | ||
expect(time.referenceHost).to.exist(); | ||
done(); | ||
@@ -61,8 +61,8 @@ }); | ||
it('times out on no response', function (done) { | ||
it('times out on no response', (done) => { | ||
Sntp.time({ port: 124, timeout: 100 }, function (err, time) { | ||
Sntp.time({ port: 124, timeout: 100 }, (err, time) => { | ||
expect(err).to.exist; | ||
expect(time).to.not.exist; | ||
expect(err).to.exist(); | ||
expect(time).to.not.exist(); | ||
expect(err.message).to.equal('Timeout'); | ||
@@ -73,17 +73,20 @@ done(); | ||
it('errors on error event', { parallel: false }, function (done) { | ||
it('errors on error event', { parallel: false }, (done) => { | ||
var orig = Dgram.createSocket; | ||
const orig = Dgram.createSocket; | ||
Dgram.createSocket = function (type) { | ||
Dgram.createSocket = orig; | ||
var socket = Dgram.createSocket(type); | ||
setImmediate(function () { socket.emit('error', new Error('Fake')) }); | ||
const socket = Dgram.createSocket(type); | ||
setImmediate(() => { | ||
socket.emit('error', new Error('Fake')); | ||
}); | ||
return socket; | ||
}; | ||
Sntp.time(function (err, time) { | ||
Sntp.time((err, time) => { | ||
expect(err).to.exist; | ||
expect(time).to.not.exist; | ||
expect(err).to.exist(); | ||
expect(time).to.not.exist(); | ||
expect(err.message).to.equal('Fake'); | ||
@@ -94,5 +97,5 @@ done(); | ||
it('errors on incorrect sent size', { parallel: false }, function (done) { | ||
it('errors on incorrect sent size', { parallel: false }, (done) => { | ||
var orig = Dgram.Socket.prototype.send; | ||
const orig = Dgram.Socket.prototype.send; | ||
Dgram.Socket.prototype.send = function (buf, offset, length, port, address, callback) { | ||
@@ -104,6 +107,6 @@ | ||
Sntp.time(function (err, time) { | ||
Sntp.time((err, time) => { | ||
expect(err).to.exist; | ||
expect(time).to.not.exist; | ||
expect(err).to.exist(); | ||
expect(time).to.not.exist(); | ||
expect(err.message).to.equal('Could not send entire message'); | ||
@@ -114,8 +117,8 @@ done(); | ||
it('times out on invalid host', function (done) { | ||
it('times out on invalid host', (done) => { | ||
Sntp.time({ host: 'error', timeout: 10000 }, function (err, time) { | ||
Sntp.time({ host: 'error', timeout: 10000 }, (err, time) => { | ||
expect(err).to.exist; | ||
expect(time).to.not.exist; | ||
expect(err).to.exist(); | ||
expect(time).to.not.exist(); | ||
expect(err.message).to.contain('getaddrinfo'); | ||
@@ -126,9 +129,10 @@ done(); | ||
it('fails on bad response buffer size', function (done) { | ||
it('fails on bad response buffer size', (done) => { | ||
var server = Dgram.createSocket('udp4'); | ||
server.on('message', function (message, remote) { | ||
var message = new Buffer(10); | ||
server.send(message, 0, message.length, remote.port, remote.address, function (err, bytes) { | ||
const server = Dgram.createSocket('udp4'); | ||
server.on('message', (message, remote) => { | ||
const msg = new Buffer(10); | ||
server.send(msg, 0, msg.length, remote.port, remote.address, (err, bytes) => { | ||
server.close(); | ||
@@ -140,5 +144,5 @@ }); | ||
Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { | ||
Sntp.time({ host: 'localhost', port: 49123 }, (err, time) => { | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(err.message).to.equal('Invalid server response'); | ||
@@ -149,8 +153,8 @@ done(); | ||
var messup = function (bytes) { | ||
const messup = function (bytes) { | ||
var server = Dgram.createSocket('udp4'); | ||
server.on('message', function (message, remote) { | ||
const server = Dgram.createSocket('udp4'); | ||
server.on('message', (message, remote) => { | ||
var message = new Buffer([ | ||
const msg = new Buffer([ | ||
0x24, 0x01, 0x00, 0xe3, | ||
@@ -170,7 +174,7 @@ 0x00, 0x00, 0x00, 0x00, | ||
for (var i = 0, il = bytes.length; i < il; ++i) { | ||
message[bytes[i][0]] = bytes[i][1]; | ||
for (let i = 0; i < bytes.length; ++i) { | ||
msg[bytes[i][0]] = bytes[i][1]; | ||
} | ||
server.send(message, 0, message.length, remote.port, remote.address, function (err, bytes) { | ||
server.send(msg, 0, msg.length, remote.port, remote.address, (err, bytes2) => { | ||
@@ -184,9 +188,9 @@ server.close(); | ||
it('fails on bad version', function (done) { | ||
it('fails on bad version', (done) => { | ||
messup([[0, (0 << 6) + (3 << 3) + (4 << 0)]]); | ||
Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { | ||
Sntp.time({ host: 'localhost', port: 49123 }, (err, time) => { | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(time.version).to.equal(3); | ||
@@ -198,9 +202,9 @@ expect(err.message).to.equal('Invalid server response'); | ||
it('fails on bad originateTimestamp', function (done) { | ||
it('fails on bad originateTimestamp', (done) => { | ||
messup([[24, 0x83], [25, 0xaa], [26, 0x7e], [27, 0x80], [28, 0], [29, 0], [30, 0], [31, 0]]); | ||
Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { | ||
Sntp.time({ host: 'localhost', port: 49123 }, (err, time) => { | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(err.message).to.equal('Invalid server response'); | ||
@@ -211,9 +215,9 @@ done(); | ||
it('fails on bad receiveTimestamp', function (done) { | ||
it('fails on bad receiveTimestamp', (done) => { | ||
messup([[32, 0x83], [33, 0xaa], [34, 0x7e], [35, 0x80], [36, 0], [37, 0], [38, 0], [39, 0]]); | ||
Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { | ||
Sntp.time({ host: 'localhost', port: 49123 }, (err, time) => { | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(err.message).to.equal('Invalid server response'); | ||
@@ -224,9 +228,9 @@ done(); | ||
it('fails on bad originate timestamp and alarm li', function (done) { | ||
it('fails on bad originate timestamp and alarm li', (done) => { | ||
messup([[0, (3 << 6) + (4 << 3) + (4 << 0)]]); | ||
Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { | ||
Sntp.time({ host: 'localhost', port: 49123 }, (err, time) => { | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(err.message).to.equal('Wrong originate timestamp'); | ||
@@ -238,7 +242,7 @@ expect(time.leapIndicator).to.equal('alarm'); | ||
it('returns time with death stratum and last61 li', function (done) { | ||
it('returns time with death stratum and last61 li', (done) => { | ||
messup([[0, (1 << 6) + (4 << 3) + (4 << 0)], [1, 0]]); | ||
Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { | ||
Sntp.time({ host: 'localhost', port: 49123 }, (err, time) => { | ||
@@ -251,7 +255,7 @@ expect(time.stratum).to.equal('death'); | ||
it('returns time with reserved stratum and last59 li', function (done) { | ||
it('returns time with reserved stratum and last59 li', (done) => { | ||
messup([[0, (2 << 6) + (4 << 3) + (4 << 0)], [1, 0x1f]]); | ||
Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { | ||
Sntp.time({ host: 'localhost', port: 49123 }, (err, time) => { | ||
@@ -264,9 +268,9 @@ expect(time.stratum).to.equal('reserved'); | ||
it('fails on bad mode (symmetric-active)', function (done) { | ||
it('fails on bad mode (symmetric-active)', (done) => { | ||
messup([[0, (0 << 6) + (4 << 3) + (1 << 0)]]); | ||
Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { | ||
Sntp.time({ host: 'localhost', port: 49123 }, (err, time) => { | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(time.mode).to.equal('symmetric-active'); | ||
@@ -277,9 +281,9 @@ done(); | ||
it('fails on bad mode (symmetric-passive)', function (done) { | ||
it('fails on bad mode (symmetric-passive)', (done) => { | ||
messup([[0, (0 << 6) + (4 << 3) + (2 << 0)]]); | ||
Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { | ||
Sntp.time({ host: 'localhost', port: 49123 }, (err, time) => { | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(time.mode).to.equal('symmetric-passive'); | ||
@@ -290,9 +294,9 @@ done(); | ||
it('fails on bad mode (client)', function (done) { | ||
it('fails on bad mode (client)', (done) => { | ||
messup([[0, (0 << 6) + (4 << 3) + (3 << 0)]]); | ||
Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { | ||
Sntp.time({ host: 'localhost', port: 49123 }, (err, time) => { | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(time.mode).to.equal('client'); | ||
@@ -303,9 +307,9 @@ done(); | ||
it('fails on bad mode (broadcast)', function (done) { | ||
it('fails on bad mode (broadcast)', (done) => { | ||
messup([[0, (0 << 6) + (4 << 3) + (5 << 0)]]); | ||
Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { | ||
Sntp.time({ host: 'localhost', port: 49123 }, (err, time) => { | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(time.mode).to.equal('broadcast'); | ||
@@ -316,9 +320,9 @@ done(); | ||
it('fails on bad mode (reserved)', function (done) { | ||
it('fails on bad mode (reserved)', (done) => { | ||
messup([[0, (0 << 6) + (4 << 3) + (6 << 0)]]); | ||
Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { | ||
Sntp.time({ host: 'localhost', port: 49123 }, (err, time) => { | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(time.mode).to.equal('reserved'); | ||
@@ -330,9 +334,9 @@ done(); | ||
describe('#offset', function () { | ||
describe('offset()', () => { | ||
it('gets the current offset', function (done) { | ||
it('gets the current offset', (done) => { | ||
Sntp.offset(function (err, offset) { | ||
Sntp.offset((err, offset) => { | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(offset).to.not.equal(0); | ||
@@ -343,13 +347,13 @@ done(); | ||
it('gets the current offset from cache', function (done) { | ||
it('gets the current offset from cache', (done) => { | ||
Sntp.offset(function (err, offset) { | ||
Sntp.offset((err, offset1) => { | ||
expect(err).to.not.exist; | ||
expect(offset).to.not.equal(0); | ||
var offset1 = offset; | ||
Sntp.offset({}, function (err, offset) { | ||
expect(err).to.not.exist(); | ||
expect(offset1).to.not.equal(0); | ||
expect(err).to.not.exist; | ||
expect(offset).to.equal(offset1); | ||
Sntp.offset({}, (err, offset2) => { | ||
expect(err).to.not.exist(); | ||
expect(offset2).to.equal(offset1); | ||
done(); | ||
@@ -360,13 +364,13 @@ }); | ||
it('gets the new offset on different server', function (done) { | ||
it('gets the new offset on different server', (done) => { | ||
Sntp.offset(function (err, offset) { | ||
Sntp.offset((err, offset1) => { | ||
expect(err).to.not.exist; | ||
expect(offset).to.not.equal(0); | ||
var offset1 = offset; | ||
Sntp.offset({ host: 'nist1-sj.ustiming.org' }, function (err, offset) { | ||
expect(err).to.not.exist(); | ||
expect(offset1).to.not.equal(0); | ||
expect(err).to.not.exist; | ||
expect(offset).to.not.equal(offset1); | ||
Sntp.offset({ host: 'us.pool.ntp.org' }, (err, offset2) => { | ||
expect(err).to.not.exist(); | ||
expect(offset2).to.not.equal(offset1); | ||
done(); | ||
@@ -377,13 +381,13 @@ }); | ||
it('gets the new offset on different server', function (done) { | ||
it('gets the new offset on different server', (done) => { | ||
Sntp.offset(function (err, offset) { | ||
Sntp.offset((err, offset1) => { | ||
expect(err).to.not.exist; | ||
expect(offset).to.not.equal(0); | ||
var offset1 = offset; | ||
Sntp.offset({ port: 123 }, function (err, offset) { | ||
expect(err).to.not.exist(); | ||
expect(offset1).to.not.equal(0); | ||
expect(err).to.not.exist; | ||
expect(offset).to.not.equal(offset1); | ||
Sntp.offset({ port: 123 }, (err, offset2) => { | ||
expect(err).to.not.exist(); | ||
expect(offset2).to.not.equal(offset1); | ||
done(); | ||
@@ -394,7 +398,7 @@ }); | ||
it('fails getting the current offset on invalid server', function (done) { | ||
it('fails getting the current offset on invalid server', (done) => { | ||
Sntp.offset({ host: 'error' }, function (err, offset) { | ||
Sntp.offset({ host: 'error' }, (err, offset) => { | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(offset).to.equal(0); | ||
@@ -406,14 +410,14 @@ done(); | ||
describe('#now', function () { | ||
describe('now()', () => { | ||
it('starts auto-sync, gets now, then stops', function (done) { | ||
it('starts auto-sync, gets now, then stops', (done) => { | ||
Sntp.stop(); | ||
var before = Sntp.now(); | ||
expect(before).to.equal(Date.now()); | ||
const before = Sntp.now(); | ||
expect(before).to.be.about(Date.now(), 5); | ||
Sntp.start(function () { | ||
Sntp.start(() => { | ||
var now = Sntp.now(); | ||
const now = Sntp.now(); | ||
expect(now).to.not.equal(Date.now()); | ||
@@ -426,9 +430,9 @@ Sntp.stop(); | ||
it('starts twice', function (done) { | ||
it('starts twice', (done) => { | ||
Sntp.start(function () { | ||
Sntp.start(() => { | ||
Sntp.start(function () { | ||
Sntp.start(() => { | ||
var now = Sntp.now(); | ||
const now = Sntp.now(); | ||
expect(now).to.not.equal(Date.now()); | ||
@@ -442,16 +446,16 @@ Sntp.stop(); | ||
it('starts auto-sync, gets now, waits, gets again after timeout', function (done) { | ||
it('starts auto-sync, gets now, waits, gets again after timeout', (done) => { | ||
Sntp.stop(); | ||
var before = Sntp.now(); | ||
expect(before).to.equal(Date.now()); | ||
const before = Sntp.now(); | ||
expect(before).to.be.about(Date.now(), 5); | ||
Sntp.start({ clockSyncRefresh: 100 }, function () { | ||
Sntp.start({ clockSyncRefresh: 100 }, () => { | ||
var now = Sntp.now(); | ||
const now = Sntp.now(); | ||
expect(now).to.not.equal(Date.now()); | ||
expect(now).to.equal(Sntp.now()); | ||
expect(now).to.be.about(Sntp.now(), 5); | ||
setTimeout(function () { | ||
setTimeout(() => { | ||
@@ -458,0 +462,0 @@ expect(Sntp.now()).to.not.equal(now); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
0
3
27589
2
9
610
+ Addedhoek@3.0.4(transitive)
- Removedhoek@2.16.3(transitive)
Updatedhoek@3.x.x