Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ntp-client

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ntp-client - npm Package Compare versions

Comparing version 0.5.0 to 0.5.1

24

lib/ntp-client.js
/*
* ntp-client
* https://github.com/moonpyk/node-ntp
* https://github.com/moonpyk/node-ntp-client
*

@@ -16,7 +16,15 @@ * Copyright (c) 2013 Clément Bourgeois

exports.defaultNtpServer = "pool.ntp.org";
/**
* Amount of acceptable time to await for a response from the remote server.
* Configured default to 10 seconds.
*/
exports.ntpReplyTimeout = 10000;
/**
* Fetches the current NTP Time from the given server and port.
* @param {string} server IP/Hostname of the remote NTP Server
* @param {number} port Remote NTP Server port number
* @param {function(Object, Date)} callback
* @param {function(Object, Date)} callback(err, date) Async callback for
* the result date or eventually error.
*/

@@ -33,2 +41,7 @@ exports.getNetworkTime = function (server, port, callback) {

var timeout = setTimeout(function() {
client.close();
callback("Timeout waiting for NTP response.", null);
}, exports.ntpReplyTimeout);
client.send(ntpData, 0, ntpData.length, port, server, function (err) {

@@ -41,5 +54,6 @@ if (err) {

client.on('message', function (msg) {
client.once('message', function (msg) {
clearTimeout(timeout);
client.close();
// Offset to get to the "Transmit Timestamp" field (time at which the reply

@@ -67,3 +81,3 @@ // departed the server for the client, in 64-bit timestamp format."

callback(err, date);
callback(null, date);
});

@@ -70,0 +84,0 @@ });

{
"name": "ntp-client",
"description": "Pure Javascript implementation of the NTP Client Protocol",
"version": "0.5.0",
"version": "0.5.1",
"homepage": "https://github.com/moonpyk/node-ntp-client",

@@ -26,3 +26,3 @@ "author": {

"scripts": {
"test": "grunt nodeunit"
"test": "grunt jshint nodeunit"
},

@@ -29,0 +29,0 @@ "devDependencies": {

@@ -24,3 +24,3 @@ /*

var ntp_client = require('../lib/ntp-client.js');
var ntpClient = require('../lib/ntp-client.js');

@@ -32,6 +32,32 @@ exports.setUp = function (done) {

exports.noop = function (test) {
test.ok(true);
test.done();
exports.validNTPServer = function (test) {
ntpClient.ntpReplyTimeout = 5000; // Reducing timeout to avoid warnings.
ntpClient.getNetworkTime(ntpClient.defaultNtpServer, ntpClient.defaultNtpPort, function (err, date) {
var now = new Date();
console.log();
console.log("System reported : %s", now);
test.ok(err === null);
test.ok(date !== null);
console.log("NTP Reported : %s", date);
// I won't test returned datetime against the system datetime
// this is the whole purpose of NTP : putting clocks in sync.
test.done();
});
};
exports.invalidNTPServer = function (test) {
// I'm pretty sure there is no NTP Server listening at google.com
ntpClient.getNetworkTime("google.com", 123, function (err, date) {
test.ok(err !== null);
test.ok(date === null);
test.equal(err, "Timeout waiting for NTP response.");
test.done();
});
};
}(exports));
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc