From 62509a4800f50866739b95c4a7f6a8efa64bb574 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 30 Dec 2015 11:48:33 -0500 Subject: [PATCH] minor bugfixes, log enchancements, etc --- bin/holepunch.js | 2 +- lib/loopback-listener.js | 42 ++++++++++++++++++++++++++++++---------- lib/pmp.js | 5 ++++- lib/request.js | 1 - lib/upnp.js | 6 +++--- package.json | 1 + 6 files changed, 41 insertions(+), 16 deletions(-) diff --git a/bin/holepunch.js b/bin/holepunch.js index 76f8a65..756c14b 100755 --- a/bin/holepunch.js +++ b/bin/holepunch.js @@ -40,7 +40,7 @@ cli.main(function(_, options) { } if (options.debug) { - console.log('options'); + console.log('[HP CLI] options'); console.log(options); } diff --git a/lib/loopback-listener.js b/lib/loopback-listener.js index d97a0dc..51adf8d 100644 --- a/lib/loopback-listener.js +++ b/lib/loopback-listener.js @@ -41,18 +41,40 @@ module.exports.create = function (opts) { process.nextTick(function () { results.plainServers.forEach(function (plainServer) { - plainServer.listen( - plainServer.__plainPort.internal || plainServer.__plainPort.port - , plainServer.__plainPort.address || '0.0.0.0' - , onListen - ); + plainServer.on('error', function (err) { + plainServer.error = err; + console.warn("[HP loop] Error with plain HTTP server:"); + console.warn(err.stack); + }); + try { + plainServer.listen( + plainServer.__plainPort.internal || plainServer.__plainPort.port + , plainServer.__plainPort.address || '0.0.0.0' + , onListen + ); + } catch(e) { + plainServer.error = e; + console.warn("[HP loop] Could not create plain HTTP listener:"); + console.warn(e.stack); + } }); results.tlsServers.forEach(function (tlsServer) { - tlsServer.listen( - tlsServer.__tlsPort.internal || tlsServer.__tlsPort.port - , tlsServer.__tlsPort.address || '0.0.0.0' - , onListen - ); + tlsServer.on('error', function (err) { + tlsServer.error = err; + console.warn("[HP loop] Error with HTTPS server:"); + console.warn(err.stack); + }); + try { + tlsServer.listen( + tlsServer.__tlsPort.internal || tlsServer.__tlsPort.port + , tlsServer.__tlsPort.address || '0.0.0.0' + , onListen + ); + } catch(e) { + tlsServer.error = e; + console.warn("[HP loop] Could not create HTTPS listener:"); + console.warn(e.stack); + } }); }); diff --git a/lib/pmp.js b/lib/pmp.js index c6138cf..c4c76d1 100644 --- a/lib/pmp.js +++ b/lib/pmp.js @@ -65,9 +65,12 @@ function pmpForwardHelper(gw, portInfo) { } // explicitly ask for the current external IP address + // TODO why did I use a setTimeout here? event loop / timing bug? setTimeout(function () { client.externalIp(function (err, info) { - if (err) { throw err; } + console.error('[HP] Error: setTimeout client.externalIp:'); + console.error(err.stack); + if (err) { return PromiseA.reject(err); } console.log('Current external IP address: %s', info.ip.join('.')); setPortForward(); }); diff --git a/lib/request.js b/lib/request.js index b07115b..a9cef93 100644 --- a/lib/request.js +++ b/lib/request.js @@ -9,7 +9,6 @@ function requestAsync(opts) { var httpr = (false === opts.secure) ? http : https; console.log('[HP] loopback test opts'); - console.log(typeof opts.port, opts.port); console.log(opts); var req = httpr.request(opts, function (res) { diff --git a/lib/upnp.js b/lib/upnp.js index c97f738..84dfb42 100644 --- a/lib/upnp.js +++ b/lib/upnp.js @@ -88,9 +88,9 @@ function run() { exports.upnpForward(options).then(function () { console.log('done'); }).catch(function (err) { - console.error('ERROR'); - console.error(err); - throw err; + console.error('[HP] Error: upnpForward:'); + console.error(err.stack); + return PromiseA.reject(err); }); } diff --git a/package.json b/package.json index 064018c..9168928 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ }, "dependencies": { "bluebird": "^3.1.1", + "cli": "^0.11.1", "express": "^4.13.3", "holepunch-nat-pmp": "^1.0.0-alpha.1", "holepunch-upnp": "^1.0.0-alpha.1",