diff options
Diffstat (limited to 'deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp')
11 files changed, 72 insertions, 601 deletions
diff --git a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/.npmignore b/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/.npmignore index 77ba16cb05..adac8ad9c6 100644..100755 --- a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/.npmignore +++ b/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/.npmignore @@ -1,18 +1,3 @@ -.idea -*.iml -npm-debug.log -dump.rdb -node_modules -results.tap -results.xml -npm-shrinkwrap.json -config.json -.DS_Store -*/.DS_Store -*/*/.DS_Store -._* -*/._* -*/*/._* -coverage.* -lib-cov - +* +!lib/** +!.npmignore diff --git a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/.travis.yml b/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/.travis.yml deleted file mode 100755 index 047f7e3d5e..0000000000 --- a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/.travis.yml +++ /dev/null @@ -1,5 +0,0 @@ -language: node_js - -node_js: - - 0.10 - diff --git a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/LICENSE b/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/LICENSE index b0d877439e..6dc3e82d3c 100755 --- a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/LICENSE +++ b/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2012-2014, Eran Hammer and other contributors. +Copyright (c) 2012-2016, Eran Hammer and Project contributors All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/Makefile b/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/Makefile deleted file mode 100755 index 417fd93708..0000000000 --- a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -test: - @node node_modules/lab/bin/lab -test-cov: - @node node_modules/lab/bin/lab -t 100 -m 3000 -test-cov-html: - @node node_modules/lab/bin/lab -r html -o coverage.html - -.PHONY: test test-cov test-cov-html - diff --git a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/README.md b/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/README.md index 98a6e025db..98a6e025db 100644..100755 --- a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/README.md +++ b/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/README.md diff --git a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/examples/offset.js b/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/examples/offset.js deleted file mode 100755 index 0303f6dcfa..0000000000 --- a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/examples/offset.js +++ /dev/null @@ -1,16 +0,0 @@ -var Sntp = require('../lib'); - -// Request offset once - -Sntp.offset(function (err, offset) { - - console.log(offset); // New (served fresh) - - // Request offset again - - Sntp.offset(function (err, offset) { - - console.log(offset); // Identical (served from cache) - }); -}); - diff --git a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/examples/time.js b/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/examples/time.js deleted file mode 100755 index bd70d0e6a5..0000000000 --- a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/examples/time.js +++ /dev/null @@ -1,25 +0,0 @@ -var Sntp = require('../lib'); - -// All options are optional - -var options = { - host: 'nist1-sj.ustiming.org', // Defaults to pool.ntp.org - port: 123, // Defaults to 123 (NTP) - resolveReference: true, // Default to false (not resolving) - timeout: 1000 // Defaults to zero (no timeout) -}; - -// Request server time - -Sntp.time(options, function (err, time) { - - if (err) { - console.log('Failed: ' + err.message); - process.exit(1); - } - - console.log(time); - console.log('Local clock is off by: ' + time.t + ' milliseconds'); - process.exit(0); -}); - diff --git a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/index.js b/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/index.js deleted file mode 100755 index 4cc88b3587..0000000000 --- a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./lib');
\ No newline at end of file diff --git a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/lib/index.js b/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/lib/index.js index e91718b4ff..da79cd7c54 100755 --- a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/lib/index.js +++ b/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/lib/index.js @@ -1,13 +1,15 @@ +'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'); // Declare internals -var internals = {}; +const internals = {}; exports.time = function (options, callback) { @@ -17,19 +19,19 @@ exports.time = function (options, callback) { options = {}; } - var settings = Hoek.clone(options); + const settings = Hoek.clone(options); settings.host = settings.host || 'pool.ntp.org'; settings.port = settings.port || 123; settings.resolveReference = settings.resolveReference || false; // Declare variables used by callback - 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) => { if (timeoutId) { clearTimeout(timeoutId); @@ -37,29 +39,24 @@ exports.time = function (options, callback) { } 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'); - - socket.once('error', function (err) { + const socket = Dgram.createSocket('udp4'); - return finish(err); - }); + socket.once('error', (err) => 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) { return finish(new Error('Invalid server response'), message); } @@ -79,10 +76,10 @@ exports.time = function (options, callback) { // // d = (T4 - T1) - (T3 - T2) t = ((T2 - T1) + (T3 - T4)) / 2 - 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; message.d = (T4 - T1) - (T3 - T2); message.t = ((T2 - T1) + (T3 - T4)) / 2; @@ -96,7 +93,7 @@ exports.time = function (options, callback) { // Resolve reference IP address - Dns.reverse(message.referenceId, function (err, domains) { + Dns.reverse(message.referenceId, (err, domains) => { if (/* $lab:coverage:off$ */ !err /* $lab:coverage:on$ */) { message.referenceHost = domains[0]; @@ -109,7 +106,7 @@ exports.time = function (options, callback) { // Set timeout if (settings.timeout) { - timeoutId = setTimeout(function () { + timeoutId = setTimeout(() => { timeoutId = 0; return finish(new Error('Timeout')); @@ -118,18 +115,18 @@ exports.time = function (options, callback) { // Construct NTP message - 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(); - internals.fromMsecs(sent, message, 40); // Set transmit timestamp (returns as originate) + internals.fromMsecs(sent, message, 40); // Set transmit timestamp (returns as originate) // Send NTP request - 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) => { if (err || bytes !== 48) { @@ -152,7 +149,7 @@ internals.NtpMessage = function (buffer) { // Leap indicator - var li = (buffer[0] >> 6); + const li = (buffer[0] >> 6); switch (li) { case 0: this.leapIndicator = 'no-warning'; break; case 1: this.leapIndicator = 'last-minute-61'; break; @@ -162,12 +159,12 @@ internals.NtpMessage = function (buffer) { // Version - var vn = ((buffer[0] & 0x38) >> 3); + const vn = ((buffer[0] & 0x38) >> 3); this.version = vn; // Mode - var mode = (buffer[0] & 0x7); + const mode = (buffer[0] & 0x7); switch (mode) { case 1: this.mode = 'symmetric-active'; break; case 2: this.mode = 'symmetric-passive'; break; @@ -181,7 +178,7 @@ internals.NtpMessage = function (buffer) { // Stratum - var stratum = buffer[1]; + const stratum = buffer[1]; if (stratum === 0) { this.stratum = 'death'; } @@ -205,7 +202,7 @@ internals.NtpMessage = function (buffer) { // Root delay (msecs) - 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); // Root dispersion (msecs) @@ -259,14 +256,14 @@ internals.NtpMessage = function (buffer) { internals.toMsecs = function (buffer, offset) { - 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]; } @@ -276,8 +273,8 @@ internals.toMsecs = function (buffer, offset) { internals.fromMsecs = function (ts, buffer, offset) { - 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)); buffer[offset + 0] = (seconds & 0xFF000000) >> 24; buffer[offset + 1] = (seconds & 0x00FF0000) >> 16; @@ -308,23 +305,19 @@ exports.offset = function (options, callback) { options = {}; } - 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 if (internals.last.offset && internals.last.host === options.host && internals.last.port === options.port && now < internals.last.expires) { - 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) => { if (err) { return callback(err, 0); @@ -357,19 +350,15 @@ exports.start = function (options, callback) { } if (internals.now.intervalId) { - process.nextTick(function () { - - callback(); - }); - + process.nextTick(() => callback()); return; } - exports.offset(options, function (err, offset) { + exports.offset(options, (ignoreErr, offset) => { - internals.now.intervalId = setInterval(function () { + internals.now.intervalId = setInterval(() => { - exports.offset(options, function () { }); + exports.offset(options, Hoek.ignore); }, options.clockSyncRefresh || 24 * 60 * 60 * 1000); // Daily return callback(); @@ -396,7 +385,7 @@ exports.isLive = function () { exports.now = function () { - var now = Date.now(); + const now = Date.now(); if (!exports.isLive() || now >= internals.last.expires) { @@ -405,8 +394,3 @@ exports.now = function () { return now + internals.last.offset; }; - - -internals.ignore = function () { - -}; diff --git a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/package.json b/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/package.json index 9c9c4ca503..cef2194349 100755 --- a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/package.json +++ b/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/package.json @@ -1,48 +1,47 @@ { - "_from": "sntp@1.x.x", - "_id": "sntp@1.0.9", - "_integrity": "sha1-ZUEYTMkK7qbG57NeJlkIJEPGYZg=", + "_from": "sntp@2.x.x", + "_id": "sntp@2.0.2", + "_inBundle": false, + "_integrity": "sha1-UGQRDwr4X3z9t9a2ekACjOUrSys=", "_location": "/request/hawk/sntp", "_phantomChildren": {}, "_requested": { "type": "range", "registry": true, - "raw": "sntp@1.x.x", + "raw": "sntp@2.x.x", "name": "sntp", "escapedName": "sntp", - "rawSpec": "1.x.x", + "rawSpec": "2.x.x", "saveSpec": null, - "fetchSpec": "1.x.x" + "fetchSpec": "2.x.x" }, "_requiredBy": [ "/request/hawk" ], - "_resolved": "https://registry.npmjs.org/sntp/-/sntp-1.0.9.tgz", - "_shasum": "6541184cc90aeea6c6e7b35e2659082443c66198", - "_shrinkwrap": null, - "_spec": "sntp@1.x.x", - "_where": "/Users/zkat/Documents/code/npm/node_modules/request/node_modules/hawk", + "_resolved": "https://registry.npmjs.org/sntp/-/sntp-2.0.2.tgz", + "_shasum": "5064110f0af85f7cfdb7d6b67a40028ce52b4b2b", + "_spec": "sntp@2.x.x", + "_where": "/Users/rebecca/code/npm/node_modules/request/node_modules/hawk", "author": { "name": "Eran Hammer", "email": "eran@hammer.io", "url": "http://hueniverse.com" }, - "bin": null, "bugs": { "url": "https://github.com/hueniverse/sntp/issues" }, "bundleDependencies": false, - "contributors": [], "dependencies": { - "hoek": "2.x.x" + "hoek": "4.x.x" }, "deprecated": false, "description": "SNTP Client", "devDependencies": { - "lab": "4.x.x" + "code": "4.x.x", + "lab": "10.x.x" }, "engines": { - "node": ">=0.8.0" + "node": ">=4.0.0" }, "homepage": "https://github.com/hueniverse/sntp#readme", "keywords": [ @@ -50,22 +49,16 @@ "ntp", "time" ], - "licenses": [ - { - "type": "BSD", - "url": "http://github.com/hueniverse/sntp/raw/master/LICENSE" - } - ], - "main": "index", + "license": "BSD-3-Clause", + "main": "lib/index.js", "name": "sntp", - "optionalDependencies": {}, - "peerDependencies": {}, "repository": { "type": "git", "url": "git://github.com/hueniverse/sntp.git" }, "scripts": { - "test": "make test-cov" + "test": "lab -a code -t 100 -L -m 20000", + "test-cov-html": "lab -a code -r html -o coverage.html -m 20000" }, - "version": "1.0.9" + "version": "2.0.2" } diff --git a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/test/index.js b/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/test/index.js deleted file mode 100755 index f1d1cdabf5..0000000000 --- a/deps/npm/node_modules/request/node_modules/hawk/node_modules/sntp/test/index.js +++ /dev/null @@ -1,435 +0,0 @@ -// Load modules - -var Dns = require('dns'); -var Dgram = require('dgram'); -var Lab = require('lab'); -var Sntp = require('../lib'); - - -// Declare internals - -var internals = {}; - - -// Test shortcuts - -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; - - -describe('SNTP', function () { - - describe('#time', function () { - - it('returns consistent result over multiple tries', function (done) { - - Sntp.time(function (err, time) { - - expect(err).to.not.exist; - expect(time).to.exist; - var t1 = time.t; - - Sntp.time(function (err, time) { - - expect(err).to.not.exist; - expect(time).to.exist; - var t2 = time.t; - expect(Math.abs(t1 - t2)).is.below(200); - done(); - }); - }); - }); - - it('resolves reference IP', function (done) { - - Sntp.time({ host: 'ntp.exnet.com', resolveReference: true }, function (err, time) { - - expect(err).to.not.exist; - expect(time).to.exist; - expect(time.referenceHost).to.exist; - done(); - }); - }); - - it('times out on no response', function (done) { - - Sntp.time({ port: 124, timeout: 100 }, function (err, time) { - - expect(err).to.exist; - expect(time).to.not.exist; - expect(err.message).to.equal('Timeout'); - done(); - }); - }); - - it('errors on error event', { parallel: false }, function (done) { - - var orig = Dgram.createSocket; - Dgram.createSocket = function (type) { - - Dgram.createSocket = orig; - var socket = Dgram.createSocket(type); - setImmediate(function () { socket.emit('error', new Error('Fake')) }); - return socket; - }; - - Sntp.time(function (err, time) { - - expect(err).to.exist; - expect(time).to.not.exist; - expect(err.message).to.equal('Fake'); - done(); - }); - }); - - it('errors on incorrect sent size', { parallel: false }, function (done) { - - var orig = Dgram.Socket.prototype.send; - Dgram.Socket.prototype.send = function (buf, offset, length, port, address, callback) { - - Dgram.Socket.prototype.send = orig; - return callback(null, 40); - }; - - Sntp.time(function (err, time) { - - expect(err).to.exist; - expect(time).to.not.exist; - expect(err.message).to.equal('Could not send entire message'); - done(); - }); - }); - - it('times out on invalid host', function (done) { - - Sntp.time({ host: 'error', timeout: 10000 }, function (err, time) { - - expect(err).to.exist; - expect(time).to.not.exist; - expect(err.message).to.contain('getaddrinfo'); - done(); - }); - }); - - it('fails on bad response buffer size', function (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) { - - server.close(); - }); - }); - - server.bind(49123); - - Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { - - expect(err).to.exist; - expect(err.message).to.equal('Invalid server response'); - done(); - }); - }); - - var messup = function (bytes) { - - var server = Dgram.createSocket('udp4'); - server.on('message', function (message, remote) { - - var message = new Buffer([ - 0x24, 0x01, 0x00, 0xe3, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x41, 0x43, 0x54, 0x53, - 0xd4, 0xa8, 0x2d, 0xc7, - 0x1c, 0x5d, 0x49, 0x1b, - 0xd4, 0xa8, 0x2d, 0xe6, - 0x67, 0xef, 0x9d, 0xb2, - 0xd4, 0xa8, 0x2d, 0xe6, - 0x71, 0xed, 0xb5, 0xfb, - 0xd4, 0xa8, 0x2d, 0xe6, - 0x71, 0xee, 0x6c, 0xc5 - ]); - - for (var i = 0, il = bytes.length; i < il; ++i) { - message[bytes[i][0]] = bytes[i][1]; - } - - server.send(message, 0, message.length, remote.port, remote.address, function (err, bytes) { - - server.close(); - }); - }); - - server.bind(49123); - }; - - it('fails on bad version', function (done) { - - messup([[0, (0 << 6) + (3 << 3) + (4 << 0)]]); - - Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { - - expect(err).to.exist; - expect(time.version).to.equal(3); - expect(err.message).to.equal('Invalid server response'); - done(); - }); - }); - - it('fails on bad originateTimestamp', function (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) { - - expect(err).to.exist; - expect(err.message).to.equal('Invalid server response'); - done(); - }); - }); - - it('fails on bad receiveTimestamp', function (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) { - - expect(err).to.exist; - expect(err.message).to.equal('Invalid server response'); - done(); - }); - }); - - it('fails on bad originate timestamp and alarm li', function (done) { - - messup([[0, (3 << 6) + (4 << 3) + (4 << 0)]]); - - Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { - - expect(err).to.exist; - expect(err.message).to.equal('Wrong originate timestamp'); - expect(time.leapIndicator).to.equal('alarm'); - done(); - }); - }); - - it('returns time with death stratum and last61 li', function (done) { - - messup([[0, (1 << 6) + (4 << 3) + (4 << 0)], [1, 0]]); - - Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { - - expect(time.stratum).to.equal('death'); - expect(time.leapIndicator).to.equal('last-minute-61'); - done(); - }); - }); - - it('returns time with reserved stratum and last59 li', function (done) { - - messup([[0, (2 << 6) + (4 << 3) + (4 << 0)], [1, 0x1f]]); - - Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { - - expect(time.stratum).to.equal('reserved'); - expect(time.leapIndicator).to.equal('last-minute-59'); - done(); - }); - }); - - it('fails on bad mode (symmetric-active)', function (done) { - - messup([[0, (0 << 6) + (4 << 3) + (1 << 0)]]); - - Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { - - expect(err).to.exist; - expect(time.mode).to.equal('symmetric-active'); - done(); - }); - }); - - it('fails on bad mode (symmetric-passive)', function (done) { - - messup([[0, (0 << 6) + (4 << 3) + (2 << 0)]]); - - Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { - - expect(err).to.exist; - expect(time.mode).to.equal('symmetric-passive'); - done(); - }); - }); - - it('fails on bad mode (client)', function (done) { - - messup([[0, (0 << 6) + (4 << 3) + (3 << 0)]]); - - Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { - - expect(err).to.exist; - expect(time.mode).to.equal('client'); - done(); - }); - }); - - it('fails on bad mode (broadcast)', function (done) { - - messup([[0, (0 << 6) + (4 << 3) + (5 << 0)]]); - - Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { - - expect(err).to.exist; - expect(time.mode).to.equal('broadcast'); - done(); - }); - }); - - it('fails on bad mode (reserved)', function (done) { - - messup([[0, (0 << 6) + (4 << 3) + (6 << 0)]]); - - Sntp.time({ host: 'localhost', port: 49123 }, function (err, time) { - - expect(err).to.exist; - expect(time.mode).to.equal('reserved'); - done(); - }); - }); - }); - - describe('#offset', function () { - - it('gets the current offset', function (done) { - - Sntp.offset(function (err, offset) { - - expect(err).to.not.exist; - expect(offset).to.not.equal(0); - done(); - }); - }); - - it('gets the current offset from cache', function (done) { - - Sntp.offset(function (err, offset) { - - 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(offset).to.equal(offset1); - done(); - }); - }); - }); - - it('gets the new offset on different server', function (done) { - - Sntp.offset(function (err, offset) { - - 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(offset).to.not.equal(offset1); - done(); - }); - }); - }); - - it('gets the new offset on different server', function (done) { - - Sntp.offset(function (err, offset) { - - 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(offset).to.not.equal(offset1); - done(); - }); - }); - }); - - it('fails getting the current offset on invalid server', function (done) { - - Sntp.offset({ host: 'error' }, function (err, offset) { - - expect(err).to.exist; - expect(offset).to.equal(0); - done(); - }); - }); - }); - - describe('#now', function () { - - it('starts auto-sync, gets now, then stops', function (done) { - - Sntp.stop(); - - var before = Sntp.now(); - expect(before).to.equal(Date.now()); - - Sntp.start(function () { - - var now = Sntp.now(); - expect(now).to.not.equal(Date.now()); - Sntp.stop(); - - done(); - }); - }); - - it('starts twice', function (done) { - - Sntp.start(function () { - - Sntp.start(function () { - - var now = Sntp.now(); - expect(now).to.not.equal(Date.now()); - Sntp.stop(); - - done(); - }); - }); - }); - - it('starts auto-sync, gets now, waits, gets again after timeout', function (done) { - - Sntp.stop(); - - var before = Sntp.now(); - expect(before).to.equal(Date.now()); - - Sntp.start({ clockSyncRefresh: 100 }, function () { - - var now = Sntp.now(); - expect(now).to.not.equal(Date.now()); - expect(now).to.equal(Sntp.now()); - - setTimeout(function () { - - expect(Sntp.now()).to.not.equal(now); - Sntp.stop(); - done(); - }, 110); - }); - }); - }); -}); - |