made the loopback check more robust
This commit is contained in:
parent
5de8edb33d
commit
b4e967f152
|
@ -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
|
// 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
|
// 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.
|
// address. Otherwise we need to use the tunnel to accept traffic. Also since the tunnel will
|
||||||
if (!notLooped.length) {
|
// 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) {
|
if (tunnelActive) {
|
||||||
await disconnectTunnels();
|
await disconnectTunnels();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
// 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);
|
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;
|
return result.body.address;
|
||||||
}
|
}
|
||||||
async function checkPublicAddr(provider) {
|
async function checkPublicAddr(provider) {
|
||||||
|
@ -33,12 +36,14 @@ module.exports.create = function (deps, conf) {
|
||||||
var reqObj = {
|
var reqObj = {
|
||||||
method: 'POST'
|
method: 'POST'
|
||||||
, url: deps.OAUTH3.url.normalize(host)+'/api/org.oauth3.tunnel/loopback'
|
, url: deps.OAUTH3.url.normalize(host)+'/api/org.oauth3.tunnel/loopback'
|
||||||
|
, timeout: 20*1000
|
||||||
, json: {
|
, json: {
|
||||||
address: address
|
address: address
|
||||||
, port: port
|
, port: port
|
||||||
, token: token
|
, token: token
|
||||||
, keyAuthorization: keyAuth
|
, keyAuthorization: keyAuth
|
||||||
, iat: Date.now()
|
, iat: Date.now()
|
||||||
|
, timeout: 18*1000
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,12 +52,18 @@ module.exports.create = function (deps, conf) {
|
||||||
result = await deps.request(reqObj);
|
result = await deps.request(reqObj);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
delete pending[token];
|
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];
|
delete pending[token];
|
||||||
if (!result.body) {
|
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
|
// 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
|
// 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);
|
return checkSinglePort(directives.api, address, port);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (conf.debug) {
|
if (conf.debug && Object.keys(pending).length) {
|
||||||
console.log('remaining loopback tokens', pending);
|
console.log('remaining loopback tokens', pending);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue