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

nat-api

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nat-api - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

.github/dependabot.yml

60

index.js

@@ -38,3 +38,3 @@ const arrayRemove = require('unordered-array-remove')

// Lookup gateway IP
var results = defaultGateway.v4.sync()
const results = defaultGateway.v4.sync()
this._pmpClient = NatPMP.connect(results.gateway)

@@ -61,7 +61,7 @@ } catch (err) {

map (publicPort, privatePort, cbParam) {
var self = this
const self = this
if (self._destroyed) throw new Error('client is destroyed')
// Validate input
var { opts, cb } = self._validateInput(publicPort, privatePort, cbParam)
const { opts, cb } = self._validateInput(publicPort, privatePort, cbParam)

@@ -72,3 +72,3 @@ if (opts.protocol) {

if (err) return cb(err)
var newOpts = Object.assign({}, opts)
const newOpts = Object.assign({}, opts)
self._openPorts.push(newOpts)

@@ -79,3 +79,3 @@ cb()

// UDP & TCP
var newOptsUDP = Object.assign({}, opts)
const newOptsUDP = Object.assign({}, opts)
newOptsUDP.protocol = 'UDP'

@@ -87,3 +87,3 @@ self._map(newOptsUDP, function (err) {

var newOptsTCP = Object.assign({}, opts)
const newOptsTCP = Object.assign({}, opts)
newOptsTCP.protocol = 'TCP'

@@ -110,7 +110,7 @@ self._map(newOptsTCP, function (err) {

unmap (publicPort, privatePort, cbParam) {
var self = this
const self = this
if (self._destroyed) throw new Error('client is destroyed')
// Validate input
var { opts, cb } = self._validateInput(publicPort, privatePort, cbParam)
const { opts, cb } = self._validateInput(publicPort, privatePort, cbParam)

@@ -131,3 +131,3 @@ arrayRemove(self._openPorts, self._openPorts.findIndex(function (o) {

// UDP & TCP
var newOptsUDP = Object.assign({}, opts)
const newOptsUDP = Object.assign({}, opts)
newOptsUDP.protocol = 'UDP'

@@ -137,3 +137,3 @@ self._unmap(newOptsUDP, function (err) {

var newOptsTCP = Object.assign({}, opts)
const newOptsTCP = Object.assign({}, opts)
newOptsTCP.protocol = 'TCP'

@@ -149,3 +149,3 @@ self._unmap(newOptsTCP, function (err) {

destroy (cb) {
var self = this
const self = this
if (self._destroyed) throw new Error('client already destroyed')

@@ -175,4 +175,4 @@

// Unmap all ports
var openPortsCopy = Object.assign([], self._openPorts)
var numPorts = openPortsCopy.length
const openPortsCopy = Object.assign([], self._openPorts)
let numPorts = openPortsCopy.length
if (numPorts === 0) return continueDestroy()

@@ -192,3 +192,3 @@

_validateInput (publicPort, privatePort, cb) {
var opts
let opts
if (typeof publicPort === 'object') {

@@ -235,3 +235,3 @@ // opts

if (err) {
var newErr
let newErr
if (self._pmpClient) newErr = new Error('NAT-PMP and UPnP port mapping failed')

@@ -298,3 +298,3 @@ else newErr = new Error('UPnP port mapping failed')

if (err) {
var newErr
let newErr
if (self._pmpClient) newErr = new Error('NAT-PMP and UPnP port mapping failed')

@@ -326,3 +326,3 @@ else newErr = new Error('UPnP port mapping failed')

_upnpMap (opts, cb) {
var self = this
const self = this
debug('Mapping public port %d to private port %d by %s using UPnP', opts.publicPort, opts.privatePort, opts.protocol)

@@ -343,3 +343,3 @@ self._upnpClient.portMapping({

self._upnpIntervals[opts.publicPort + ':' + opts.privatePort + '-' + opts.protocol] = setInterval(
self._upnpMap.bind(self, opts),
self._upnpMap.bind(self, opts, () => {}),
self._timeout

@@ -356,3 +356,3 @@ )

_pmpMap (opts, cb) {
var self = this
const self = this
debug('Mapping public port %d to private port %d by %s using NAT-PMP', opts.publicPort, opts.privatePort, opts.protocol)

@@ -365,7 +365,7 @@

var timeouted = false
var pmpTimeout = setTimeout(function () {
let timeouted = false
const pmpTimeout = setTimeout(function () {
timeouted = true
self._pmpClient.close()
var err = new Error('timeout')
const err = new Error('timeout')
debug('Error mapping port %d:%d using NAT-PMP:', opts.publicPort, opts.privatePort, err.message)

@@ -394,3 +394,3 @@ cb(err)

self._pmpIntervals[opts.publicPort + ':' + opts.privatePort + '-' + opts.protocol] = setInterval(
self._pmpMap.bind(self, opts),
self._pmpMap.bind(self, opts, () => {}),
self._timeout

@@ -407,3 +407,3 @@ )

_upnpUnmap (opts, cb) {
var self = this
const self = this
debug('Unmapping public port %d to private port %d by %s using UPnP', opts.publicPort, opts.privatePort, opts.protocol)

@@ -422,3 +422,3 @@

// Clear intervals
var key = opts.publicPort + ':' + opts.privatePort + '-' + opts.protocol
const key = opts.publicPort + ':' + opts.privatePort + '-' + opts.protocol
if (self._upnpIntervals[key]) {

@@ -436,3 +436,3 @@ clearInterval(self._upnpIntervals[key])

_pmpUnmap (opts, cb) {
var self = this
const self = this
debug('Unmapping public port %d to private port %d by %s using NAT-PMP', opts.publicPort, opts.privatePort, opts.protocol)

@@ -445,7 +445,7 @@

var timeouted = false
var pmpTimeout = setTimeout(function () {
let timeouted = false
const pmpTimeout = setTimeout(function () {
timeouted = true
self._pmpClient.close()
var err = new Error('timeout')
const err = new Error('timeout')
debug('Error unmapping port %d:%d using NAT-PMP:', opts.publicPort, opts.privatePort, err.message)

@@ -472,3 +472,3 @@ cb(err)

// Clear intervals
var key = opts.publicPort + ':' + opts.privatePort + '-' + opts.protocol
const key = opts.publicPort + ':' + opts.privatePort + '-' + opts.protocol
if (self._pmpIntervals[key]) {

@@ -475,0 +475,0 @@ clearInterval(self._pmpIntervals[key])

@@ -162,4 +162,4 @@ const request = require('request')

Object.keys(data['@']).some(function (key) {
if (!/^xmlns:/.test(key)) return
if (data['@'][key] !== uri) return
if (!/^xmlns:/.test(key)) return false
if (data['@'][key] !== uri) return false

@@ -166,0 +166,0 @@ ns = key.replace(/^xmlns:/, '')

@@ -29,3 +29,3 @@ const async = require('async')

const protocol = options.protocol ? options.protocol.toUpperCase() : 'TCP'
var ttl = 60 * 30
let ttl = 60 * 30

@@ -81,5 +81,5 @@ if (typeof options.ttl === 'number') ttl = options.ttl

var i = 0
var end = false
var results = []
let i = 0
let end = false
let results = []

@@ -110,3 +110,3 @@ async.whilst(function () {

var result = {
const result = {
public: {

@@ -113,0 +113,0 @@ host: (typeof data.NewRemoteHost === 'string') && (data.NewRemoteHost || ''),

{
"version": "0.3.0",
"version": "0.3.1",
"name": "nat-api",

@@ -13,6 +13,6 @@ "description": "Port mapping with UPnP and NAT-PMP",

"dependencies": {
"async": "^3.1.0",
"debug": "^4.1.1",
"default-gateway": "^6.0.0",
"request": "^2.88.0",
"async": "^3.2.0",
"debug": "^4.2.0",
"default-gateway": "^6.0.2",
"request": "^2.88.2",
"unordered-array-remove": "^1.0.2",

@@ -22,3 +22,3 @@ "xml2js": "^0.1.0"

"devDependencies": {
"standard": "^14.3.1"
"standard": "^16.0.0"
},

@@ -25,0 +25,0 @@ "author": {

@@ -71,4 +71,4 @@ # nat-api

autoUpdate: true, // Refresh all the port mapping to keep them from expiring (default: true)
gateway: '192.168.1.1' // Default gateway (default: null)
enablePMP: false // PMP is not enable by default
gateway: '192.168.1.1', // Default gateway (default: null)
enablePMP: false // Enable PMP (default: false)
}

@@ -75,0 +75,0 @@ ```

const NatAPI = require('../')
var client = new NatAPI()
const client = new NatAPI()

@@ -5,0 +5,0 @@ const port = 6690

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