minor bugfixes, log enchancements, etc

This commit is contained in:
AJ ONeal 2015-12-30 11:48:33 -05:00
parent e8e23388d0
commit 62509a4800
6 changed files with 41 additions and 16 deletions

View File

@ -40,7 +40,7 @@ cli.main(function(_, options) {
}
if (options.debug) {
console.log('options');
console.log('[HP CLI] options');
console.log(options);
}

View File

@ -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);
}
});
});

View File

@ -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();
});

View File

@ -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) {

View File

@ -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);
});
}

View File

@ -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",