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

ntp-time

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ntp-time - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

2

package.json
{
"name": "ntp-time",
"version": "2.0.1",
"version": "2.0.2",
"description": "A ntp library for nodejs",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -5,9 +5,21 @@ const udp = require('dgram');

function defaultOnInvalidPacket(message, error) {
console.error('[node-ntp-sync] Invalid packet received', message, error.message)
}
class Server extends EventEmitter {
constructor() {
constructor(options) {
super();
options = options || {}
this.socket = udp.createSocket('udp4');
this.socket.on('message', this.parse.bind(this));
if (options.onInvalidPacket && typeof options.onInvalidPacket == 'function') {
this._onInvalidPacket = options.onInvalidPacket
} else {
this._onInvalidPacket = defaultOnInvalidPacket
}
return this;

@@ -24,3 +36,3 @@ }

this.socket.send(sendPackage, rinfo.port, rinfo.server, callback);
this.socket.send(sendPackage, rinfo.port, rinfo.address, callback);

@@ -44,10 +56,14 @@ return this;

parse(message, rinfo) {
const packet = NTPPacket.parse(message);
const rxTimestamp = Math.floor(Date.now() / 1000);
try {
const packet = NTPPacket.parse(message);
const rxTimestamp = Math.floor(Date.now() / 1000);
packet.originateTimestamp = Math.floor(packet.txTimestamp);
packet.referenceTimestamp = rxTimestamp - 5;
packet.rxTimestamp = rxTimestamp;
packet.originateTimestamp = Math.floor(packet.txTimestamp);
packet.referenceTimestamp = rxTimestamp - 5;
packet.rxTimestamp = rxTimestamp;
this.emit('request', packet, this.send.bind(this, rinfo));
this.emit('request', packet, this.send.bind(this, rinfo));
} catch (error) {
this._onInvalidPacket(message, error)
}

@@ -54,0 +70,0 @@ return;

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