From 4f12286b558b90141e0ee0310f049b57430c93ea Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 30 Dec 2015 08:46:22 +0000 Subject: [PATCH] pass nat-pmp --- bin/holepunch.js | 3 ++- lib/index.js | 9 ++++++++- lib/loopback-listener.js | 2 ++ lib/middleware.js | 12 ++++++++---- lib/pmp.js | 2 +- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/bin/holepunch.js b/bin/holepunch.js index bf8d1de..76f8a65 100755 --- a/bin/holepunch.js +++ b/bin/holepunch.js @@ -71,6 +71,7 @@ cli.main(function(_, options) { } return hp.create(args).then(function () { - process.exit(0); + console.log('wishing wanting waiting'); + //process.exit(0); }); }); diff --git a/lib/index.js b/lib/index.js index cbcd439..e333485 100644 --- a/lib/index.js +++ b/lib/index.js @@ -28,6 +28,10 @@ module.exports.create = function (args) { function testOpenPort(ip, portInfo) { var requestAsync = require('./request'); + if (args.debug) { + console.log('[HP] hostname', args.loopbackHostname); + } + return requestAsync({ secure: portInfo.secure , rejectUnauthorized: false @@ -92,7 +96,10 @@ module.exports.create = function (args) { return getExternalIps().then(function (ips) { var pretest = (-1 !== args.protocols.indexOf('none')); - var portInfos = args.plainPorts.concat(args.tlsPorts.map(function (info) { + var portInfos = args.plainPorts.map(function (info) { + info.secure = false; + return info; + }).concat(args.tlsPorts.map(function (info) { info.secure = true; return info; })); diff --git a/lib/loopback-listener.js b/lib/loopback-listener.js index f5f5bf8..d97a0dc 100644 --- a/lib/loopback-listener.js +++ b/lib/loopback-listener.js @@ -58,6 +58,8 @@ module.exports.create = function (opts) { results.key = opts.key; results.value = opts.value; + results.loopbackHostname = opts.loopbackHostname; + results.loopbackPrefix = opts.loopbackPrefix; return results; }; diff --git a/lib/middleware.js b/lib/middleware.js index f56dcb3..bc9dcd0 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -43,16 +43,20 @@ function middleware(opts) { if (0 !== urlpath.indexOf(pathnamePrefix)) { if (opts.debug) { console.log("[HP] Pathname '" + urlpath + "'" - + " failed to match '" + pathnamePrefix + "'"); + + " failed to match prefix '" + pathnamePrefix + ": " + + urlpath.indexOf(pathnamePrefix) + ); } next(); return; } - if (scmp(key, urlpath.substr(pathnamePrefix.length, key.length))) { + if (!scmp(key, urlpath.substr(pathnamePrefix.length))) { if (opts.debug) { - console.log("[HP] Pathname '" + urlpath + "'" - + " failed to match '" + pathnamePrefix + key + "'"); + console.log("[HP] key '" + urlpath.substr(pathnamePrefix.length) + "'" + + " failed to match '" + key + "': " + + scmp(key, urlpath.substr(pathnamePrefix.length)) + ); } next(); return; diff --git a/lib/pmp.js b/lib/pmp.js index f86635e..c6138cf 100644 --- a/lib/pmp.js +++ b/lib/pmp.js @@ -45,7 +45,7 @@ function pmpForwardHelper(gw, portInfo) { || portInfo.external || portInfo.public , public: portInfo.external || portInfo.public || portInfo.internal || portInfo.private - , ttl: portInfo.ttl || 0 // 600 + , ttl: portInfo.ttl || 7200 // 0 // 600 }, function (err, info) { if (err) { reject(err);