made the loopback check more robust

This commit is contained in:
tigerbot 2017-11-01 11:40:56 -06:00
parent 5de8edb33d
commit b4e967f152
2 changed files with 17 additions and 5 deletions

View File

@ -141,8 +141,9 @@ module.exports.create = function (deps, conf) {
// If we are on a public address or all ports we are listening on are forwarded to us then
// we don't need the tunnel and we can set the DNS records for all our domains to our public
// address. Otherwise we need to use the tunnel to accept traffic.
if (!notLooped.length) {
// address. Otherwise we need to use the tunnel to accept traffic. Also since the tunnel will
// only be listening on ports 80 and 443 if those are forwarded to us we don't want the tunnel.
if (!notLooped.length || (loopResult.ports['80'] && loopResult.ports['443'])) {
if (tunnelActive) {
await disconnectTunnels();
}

View File

@ -17,6 +17,9 @@ module.exports.create = function (deps, conf) {
// Note that the error on the body will probably have a message that overwrites the default
throw Object.assign(new Error('error in check IP response'), result.body.error);
}
if (!result.body.address) {
throw new Error("public address resonse doesn't contain address: "+JSON.stringify(result.body));
}
return result.body.address;
}
async function checkPublicAddr(provider) {
@ -33,12 +36,14 @@ module.exports.create = function (deps, conf) {
var reqObj = {
method: 'POST'
, url: deps.OAUTH3.url.normalize(host)+'/api/org.oauth3.tunnel/loopback'
, timeout: 20*1000
, json: {
address: address
, port: port
, token: token
, keyAuthorization: keyAuth
, iat: Date.now()
, timeout: 18*1000
}
};
@ -47,12 +52,18 @@ module.exports.create = function (deps, conf) {
result = await deps.request(reqObj);
} catch (err) {
delete pending[token];
throw err;
if (conf.debug) {
console.log('error making loopback request for port ' + port + ' loopback', err.message);
}
return false;
}
delete pending[token];
if (!result.body) {
throw new Error('No response body in loopback request for port '+port);
if (conf.debug) {
console.log('No response body in loopback request for port '+port);
}
return false;
}
// If the loopback requests don't go to us then there are all kinds of ways it could
// error, but none of them really provide much extra information so we don't do
@ -75,7 +86,7 @@ module.exports.create = function (deps, conf) {
return checkSinglePort(directives.api, address, port);
}));
if (conf.debug) {
if (conf.debug && Object.keys(pending).length) {
console.log('remaining loopback tokens', pending);
}