chimney (log cleanup)

This commit is contained in:
AJ ONeal 2018-09-13 23:42:04 -06:00
parent 5d099b36a8
commit a714d7a7c5
3 changed files with 32 additions and 31 deletions

View File

@ -71,7 +71,7 @@ var tokenpath = path.join(path.dirname(state._confpath), 'access_token.txt');
var token; var token;
try { try {
token = fs.readFileSync(tokenpath, 'ascii').trim(); token = fs.readFileSync(tokenpath, 'ascii').trim();
console.log('[DEBUG] access_token', typeof token, token); //console.log('[DEBUG] access_token', typeof token, token);
} catch(e) { } catch(e) {
// ignore // ignore
} }
@ -458,7 +458,7 @@ function serveControlsHelper() {
} }
if (!state.config.relay || !state.config.email || !state.config.agreeTos) { if (!state.config.relay || !state.config.email || !state.config.agreeTos) {
console.log('aborting for some reason'); console.warn('missing config');
res.statusCode = 400; res.statusCode = 400;
res.setHeader('Content-Type', 'application/json'); res.setHeader('Content-Type', 'application/json');
@ -806,18 +806,18 @@ function safeStartTelebitRemote(forceOn) {
// this won't restart either // this won't restart either
trPromise = rawStartTelebitRemote(state.keepAlive); trPromise = rawStartTelebitRemote(state.keepAlive);
trPromise.then(function () { trPromise.then(function () {
console.log("I'm RIGHT HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); //console.log("I'm RIGHT HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
state.keepAlive.state = true; state.keepAlive.state = true;
trPromise = null; trPromise = null;
}).catch(function () { }).catch(function () {
console.log("I FAILED US ALL!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); //console.log("I FAILED US ALL!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
// this will restart // this will restart
state.keepAlive = { state: true }; state.keepAlive = { state: true };
trPromise = rawStartTelebitRemote(state.keepAlive); trPromise = rawStartTelebitRemote(state.keepAlive);
trPromise.then(function () { trPromise.then(function () {
trPromise = null; trPromise = null;
}).catch(function () { }).catch(function () {
console.log('DEBUG state.keepAlive turned off and remote quit'); //console.log('DEBUG state.keepAlive turned off and remote quit');
trPromise = null; trPromise = null;
}); });
}); });
@ -829,7 +829,7 @@ function rawStartTelebitRemote(keepAlive) {
var exiting = false; var exiting = false;
var localRemote = myRemote; var localRemote = myRemote;
myRemote = null; myRemote = null;
if (localRemote) { console.log('DEBUG destroy() existing'); localRemote.destroy(); } if (localRemote) { /*console.log('DEBUG destroy() existing');*/ localRemote.destroy(); }
function safeReload(delay) { function safeReload(delay) {
if (exiting) { if (exiting) {
@ -846,14 +846,14 @@ function rawStartTelebitRemote(keepAlive) {
} }
if (state.config.disable) { if (state.config.disable) {
console.log('DEBUG disabled or incapable'); //console.log('DEBUG disabled or incapable');
err = new Error("connecting is disabled"); err = new Error("connecting is disabled");
err.code = 'EDISABLED'; err.code = 'EDISABLED';
return PromiseA.reject(err); return PromiseA.reject(err);
} }
if (!(state.config.token || state.config.agreeTos)) { if (!(state.config.token || state.config.agreeTos)) {
console.log('DEBUG Must agreeTos to generate preauth'); //console.log('DEBUG Must agreeTos to generate preauth');
err = new Error("Must either supply token (for auth) or agreeTos (for preauth)"); err = new Error("Must either supply token (for auth) or agreeTos (for preauth)");
err.code = 'ENOAGREE'; err.code = 'ENOAGREE';
return PromiseA.reject(err); return PromiseA.reject(err);
@ -861,7 +861,7 @@ function rawStartTelebitRemote(keepAlive) {
state.relay = state.config.relay; state.relay = state.config.relay;
if (!state.relay) { if (!state.relay) {
console.log('DEBUG no relay'); //console.log('DEBUG no relay');
err = new Error("'" + state._confpath + "' is missing 'relay'"); err = new Error("'" + state._confpath + "' is missing 'relay'");
err.code = 'ENORELAY'; err.code = 'ENORELAY';
return PromiseA.reject(err); return PromiseA.reject(err);
@ -870,24 +870,24 @@ function rawStartTelebitRemote(keepAlive) {
// TODO: we need some form of pre-authorization before connecting, // TODO: we need some form of pre-authorization before connecting,
// otherwise we'll get disconnected pretty quickly // otherwise we'll get disconnected pretty quickly
if (!(state.token || state.pretoken)) { if (!(state.token || state.pretoken)) {
console.log('DEBUG no token'); //console.log('DEBUG no token');
err = new Error("no jwt token or preauthorization"); err = new Error("no jwt token or preauthorization");
err.code = 'ENOAUTH'; err.code = 'ENOAUTH';
return PromiseA.reject(err); return PromiseA.reject(err);
} }
return PromiseA.resolve().then(function () { return PromiseA.resolve().then(function () {
console.log('DEBUG rawStartTelebitRemote'); //console.log('DEBUG rawStartTelebitRemote');
function startHelper() { function startHelper() {
console.log('DEBUG startHelper'); //console.log('DEBUG startHelper');
greenlockHelper(state); greenlockHelper(state);
// Saves the token // Saves the token
// state.handlers.access_token({ jwt: token }); // state.handlers.access_token({ jwt: token });
// Adds the token to the connection // Adds the token to the connection
// tun.append(token); // tun.append(token);
console.log("[DEBUG] token", typeof token, token); //console.log("[DEBUG] token", typeof token, token);
//state.sortingHat = state.config.sortingHat; //state.sortingHat = state.config.sortingHat;
// { relay, config, servernames, ports, sortingHat, net, insecure, token, handlers, greenlockConfig } // { relay, config, servernames, ports, sortingHat, net, insecure, token, handlers, greenlockConfig }
@ -898,22 +898,22 @@ function rawStartTelebitRemote(keepAlive) {
myResolve = null; myResolve = null;
myReject = null; myReject = null;
} else { } else {
console.log('DEBUG double rejection'); //console.log('DEBUG double rejection');
} }
} }
function resolve(val) { function resolve(val) {
console.log('[DEBUG] pre-resolve'); //console.log('[DEBUG] pre-resolve');
if (myResolve) { if (myResolve) {
myResolve(val); myResolve(val);
myResolve = null; myResolve = null;
myReject = null; myReject = null;
} else { } else {
console.log('DEBUG double resolution'); //console.log('DEBUG double resolution');
} }
} }
function onConnect() { function onConnect() {
console.log('DEBUG [connect]'); console.info('[connect] relay established');
myRemote.removeListener('error', onConnectError); myRemote.removeListener('error', onConnectError);
myRemote.once('error', function () { myRemote.once('error', function () {
if (!keepAlive.state) { if (!keepAlive.state) {
@ -928,7 +928,6 @@ function rawStartTelebitRemote(keepAlive) {
function onConnectError(err) { function onConnectError(err) {
myRemote = null; myRemote = null;
console.log('DEBUG onConnectError (will safeReload)', err);
// Likely causes: // Likely causes:
// * DNS lookup failed (no Internet) // * DNS lookup failed (no Internet)
// * Rejected (bad authn) // * Rejected (bad authn)
@ -938,15 +937,17 @@ function rawStartTelebitRemote(keepAlive) {
reject(err); reject(err);
return; return;
} }
console.warn('[Warn] onConnectError: network error, will retry', err);
safeReload(10 * 1000).then(resolve).catch(reject); safeReload(10 * 1000).then(resolve).catch(reject);
return; return;
} }
console.error('[Error] onConnectError: no retry (possibly bad auth)', err);
reject(err); reject(err);
return; return;
} }
function retryLoop() { function retryLoop() {
console.log('DEBUG [retryLoop] keepAlive.state', keepAlive.state); console.warn('[Warn] disconnected. Will retry?', keepAlive.state);
if (keepAlive.state) { if (keepAlive.state) {
safeReload(10 * 1000).then(resolve).catch(reject); safeReload(10 * 1000).then(resolve).catch(reject);
} }

View File

@ -58,7 +58,7 @@ function TelebitRemote(state) {
var clientHandlers = { var clientHandlers = {
add: function (conn, cid, tun) { add: function (conn, cid, tun) {
priv.localclients[cid] = conn; priv.localclients[cid] = conn;
console.info("[connect] new client '" + cid + "' for '" + tun.name + ":" + tun.serviceport + "' " console.info("[connect] new client '" + tun.name + ":" + tun.serviceport + "' for '" + cid + "'"
+ "(" + clientHandlers.count() + " clients)"); + "(" + clientHandlers.count() + " clients)");
conn.tunnelCid = cid; conn.tunnelCid = cid;
@ -94,7 +94,7 @@ function TelebitRemote(state) {
var sentEnd = false; var sentEnd = false;
conn.on('end', function onLocalEnd() { conn.on('end', function onLocalEnd() {
console.info("[onLocalEnd] connection '" + cid + "' ended, will probably close soon"); //console.info("[onLocalEnd] connection '" + cid + "' ended, will probably close soon");
conn.tunnelClosing = true; conn.tunnelClosing = true;
if (!sentEnd) { if (!sentEnd) {
sendMessage(Packer.packHeader(tun, null, 'end')); sendMessage(Packer.packHeader(tun, null, 'end'));
@ -155,7 +155,7 @@ function TelebitRemote(state) {
return; return;
} }
console.log('[closeSingle]', cid); //console.log('[closeSingle]', cid);
PromiseA.resolve().then(function () { PromiseA.resolve().then(function () {
var conn = priv.localclients[cid]; var conn = priv.localclients[cid];
conn.tunnelClosing = true; conn.tunnelClosing = true;
@ -439,7 +439,7 @@ function TelebitRemote(state) {
// Otherwise we check to see if the pong has also timed out, and if not we send a ping // Otherwise we check to see if the pong has also timed out, and if not we send a ping
// and call this function again when the pong will have timed out. // and call this function again when the pong will have timed out.
else if (silent < activityTimeout + pongTimeout) { else if (silent < activityTimeout + pongTimeout) {
console.log('pinging tunnel server'); //console.log('DEBUG: pinging tunnel server');
try { try {
wstunneler.ping(); wstunneler.ping();
} catch (err) { } catch (err) {
@ -524,7 +524,7 @@ function TelebitRemote(state) {
// Our library will automatically handle sending the pong respose to ping requests. // Our library will automatically handle sending the pong respose to ping requests.
wstunneler.on('ping', priv.refreshTimeout); wstunneler.on('ping', priv.refreshTimeout);
wstunneler.on('pong', function () { wstunneler.on('pong', function () {
console.log('DEBUG got pong'); //console.log('DEBUG received pong');
priv.refreshTimeout(); priv.refreshTimeout();
}); });
wstunneler.on('message', function (data, flags) { wstunneler.on('message', function (data, flags) {

View File

@ -59,7 +59,7 @@ module.exports.print = function (config) {
}; };
module.exports.assign = function (state, tun, cb) { module.exports.assign = function (state, tun, cb) {
console.log('first message from', tun); //console.log('first message from', tun);
var net = state.net || require('net'); var net = state.net || require('net');
function trySsh(tun, cb) { function trySsh(tun, cb) {
@ -328,15 +328,15 @@ module.exports.assign = function (state, tun, cb) {
try { try {
handler = require(handlerpath); handler = require(handlerpath);
console.info("Handling '" + handle + ":" + id + "' with '" + handlerpath + "'"); console.info("Trying to handle '" + handle + ":" + id + "' with '" + handlerpath + "'");
} catch(e1) { } catch(e1) {
try { try {
handler = require(path.join(localshare, handlerpath)); handler = require(path.join(localshare, handlerpath));
console.info("Handling '" + handle + ":" + id + "' with '" + handlerpath + "'"); console.info("Skip. (couldn't require('" + handlerpath + "'):", e1.message + ")");
console.info("Trying to handle '" + handle + ":" + id + "' with '" + handlerpath + "'");
} catch(e2) { } catch(e2) {
console.error("Failed to require('" + handlerpath + "'):", e1.message); console.info("Skip. (couldn't require('" + path.join(localshare, handlerpath) + "'):", e2.message + ")");
console.error("Failed to require('" + path.join(localshare, handlerpath) + "'):", e2.message); console.info("Last chance! (using static and index handlers for '" + handle + ":" + id + "')");
console.warn("Trying static and index handlers for '" + handle + ":" + id + "'");
handler = null; handler = null;
// fallthru // fallthru
} }
@ -452,7 +452,7 @@ module.exports.assign = function (state, tun, cb) {
return; return;
} }
console.log('https invokeHandler'); //console.log('https invokeHandler');
invokeHandler(conf, tlsSocket, tun, id); invokeHandler(conf, tlsSocket, tun, id);
}); });
}); });