From a714d7a7c5a5c487d6083166aa5f47da0d5bef4b Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 13 Sep 2018 23:42:04 -0600 Subject: [PATCH] chimney (log cleanup) --- bin/telebitd.js | 39 ++++++++++++++++++++------------------- lib/remote.js | 10 +++++----- lib/sorting-hat.js | 14 +++++++------- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/bin/telebitd.js b/bin/telebitd.js index 3811169..e3f0484 100755 --- a/bin/telebitd.js +++ b/bin/telebitd.js @@ -71,7 +71,7 @@ var tokenpath = path.join(path.dirname(state._confpath), 'access_token.txt'); var token; try { token = fs.readFileSync(tokenpath, 'ascii').trim(); - console.log('[DEBUG] access_token', typeof token, token); + //console.log('[DEBUG] access_token', typeof token, token); } catch(e) { // ignore } @@ -458,7 +458,7 @@ function serveControlsHelper() { } if (!state.config.relay || !state.config.email || !state.config.agreeTos) { - console.log('aborting for some reason'); + console.warn('missing config'); res.statusCode = 400; res.setHeader('Content-Type', 'application/json'); @@ -806,18 +806,18 @@ function safeStartTelebitRemote(forceOn) { // this won't restart either trPromise = rawStartTelebitRemote(state.keepAlive); trPromise.then(function () { - console.log("I'm RIGHT HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + //console.log("I'm RIGHT HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); state.keepAlive.state = true; trPromise = null; }).catch(function () { - console.log("I FAILED US ALL!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + //console.log("I FAILED US ALL!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); // this will restart state.keepAlive = { state: true }; trPromise = rawStartTelebitRemote(state.keepAlive); trPromise.then(function () { trPromise = null; }).catch(function () { - console.log('DEBUG state.keepAlive turned off and remote quit'); + //console.log('DEBUG state.keepAlive turned off and remote quit'); trPromise = null; }); }); @@ -829,7 +829,7 @@ function rawStartTelebitRemote(keepAlive) { var exiting = false; var localRemote = myRemote; myRemote = null; - if (localRemote) { console.log('DEBUG destroy() existing'); localRemote.destroy(); } + if (localRemote) { /*console.log('DEBUG destroy() existing');*/ localRemote.destroy(); } function safeReload(delay) { if (exiting) { @@ -846,14 +846,14 @@ function rawStartTelebitRemote(keepAlive) { } if (state.config.disable) { - console.log('DEBUG disabled or incapable'); + //console.log('DEBUG disabled or incapable'); err = new Error("connecting is disabled"); err.code = 'EDISABLED'; return PromiseA.reject(err); } 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.code = 'ENOAGREE'; return PromiseA.reject(err); @@ -861,7 +861,7 @@ function rawStartTelebitRemote(keepAlive) { state.relay = state.config.relay; if (!state.relay) { - console.log('DEBUG no relay'); + //console.log('DEBUG no relay'); err = new Error("'" + state._confpath + "' is missing 'relay'"); err.code = 'ENORELAY'; return PromiseA.reject(err); @@ -870,24 +870,24 @@ function rawStartTelebitRemote(keepAlive) { // TODO: we need some form of pre-authorization before connecting, // otherwise we'll get disconnected pretty quickly if (!(state.token || state.pretoken)) { - console.log('DEBUG no token'); + //console.log('DEBUG no token'); err = new Error("no jwt token or preauthorization"); err.code = 'ENOAUTH'; return PromiseA.reject(err); } return PromiseA.resolve().then(function () { - console.log('DEBUG rawStartTelebitRemote'); + //console.log('DEBUG rawStartTelebitRemote'); function startHelper() { - console.log('DEBUG startHelper'); + //console.log('DEBUG startHelper'); greenlockHelper(state); // Saves the token // state.handlers.access_token({ jwt: token }); // Adds the token to the connection // tun.append(token); - console.log("[DEBUG] token", typeof token, token); + //console.log("[DEBUG] token", typeof token, token); //state.sortingHat = state.config.sortingHat; // { relay, config, servernames, ports, sortingHat, net, insecure, token, handlers, greenlockConfig } @@ -898,22 +898,22 @@ function rawStartTelebitRemote(keepAlive) { myResolve = null; myReject = null; } else { - console.log('DEBUG double rejection'); + //console.log('DEBUG double rejection'); } } function resolve(val) { - console.log('[DEBUG] pre-resolve'); + //console.log('[DEBUG] pre-resolve'); if (myResolve) { myResolve(val); myResolve = null; myReject = null; } else { - console.log('DEBUG double resolution'); + //console.log('DEBUG double resolution'); } } function onConnect() { - console.log('DEBUG [connect]'); + console.info('[connect] relay established'); myRemote.removeListener('error', onConnectError); myRemote.once('error', function () { if (!keepAlive.state) { @@ -928,7 +928,6 @@ function rawStartTelebitRemote(keepAlive) { function onConnectError(err) { myRemote = null; - console.log('DEBUG onConnectError (will safeReload)', err); // Likely causes: // * DNS lookup failed (no Internet) // * Rejected (bad authn) @@ -938,15 +937,17 @@ function rawStartTelebitRemote(keepAlive) { reject(err); return; } + console.warn('[Warn] onConnectError: network error, will retry', err); safeReload(10 * 1000).then(resolve).catch(reject); return; } + console.error('[Error] onConnectError: no retry (possibly bad auth)', err); reject(err); return; } function retryLoop() { - console.log('DEBUG [retryLoop] keepAlive.state', keepAlive.state); + console.warn('[Warn] disconnected. Will retry?', keepAlive.state); if (keepAlive.state) { safeReload(10 * 1000).then(resolve).catch(reject); } diff --git a/lib/remote.js b/lib/remote.js index 80f0818..989a6e8 100644 --- a/lib/remote.js +++ b/lib/remote.js @@ -58,7 +58,7 @@ function TelebitRemote(state) { var clientHandlers = { add: function (conn, cid, tun) { 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)"); conn.tunnelCid = cid; @@ -94,7 +94,7 @@ function TelebitRemote(state) { var sentEnd = false; 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; if (!sentEnd) { sendMessage(Packer.packHeader(tun, null, 'end')); @@ -155,7 +155,7 @@ function TelebitRemote(state) { return; } - console.log('[closeSingle]', cid); + //console.log('[closeSingle]', cid); PromiseA.resolve().then(function () { var conn = priv.localclients[cid]; 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 // and call this function again when the pong will have timed out. else if (silent < activityTimeout + pongTimeout) { - console.log('pinging tunnel server'); + //console.log('DEBUG: pinging tunnel server'); try { wstunneler.ping(); } catch (err) { @@ -524,7 +524,7 @@ function TelebitRemote(state) { // Our library will automatically handle sending the pong respose to ping requests. wstunneler.on('ping', priv.refreshTimeout); wstunneler.on('pong', function () { - console.log('DEBUG got pong'); + //console.log('DEBUG received pong'); priv.refreshTimeout(); }); wstunneler.on('message', function (data, flags) { diff --git a/lib/sorting-hat.js b/lib/sorting-hat.js index b7719f0..f0e0f4e 100644 --- a/lib/sorting-hat.js +++ b/lib/sorting-hat.js @@ -59,7 +59,7 @@ module.exports.print = function (config) { }; 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'); function trySsh(tun, cb) { @@ -328,15 +328,15 @@ module.exports.assign = function (state, tun, cb) { try { handler = require(handlerpath); - console.info("Handling '" + handle + ":" + id + "' with '" + handlerpath + "'"); + console.info("Trying to handle '" + handle + ":" + id + "' with '" + handlerpath + "'"); } catch(e1) { try { 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) { - console.error("Failed to require('" + handlerpath + "'):", e1.message); - console.error("Failed to require('" + path.join(localshare, handlerpath) + "'):", e2.message); - console.warn("Trying static and index handlers for '" + handle + ":" + id + "'"); + console.info("Skip. (couldn't require('" + path.join(localshare, handlerpath) + "'):", e2.message + ")"); + console.info("Last chance! (using static and index handlers for '" + handle + ":" + id + "')"); handler = null; // fallthru } @@ -452,7 +452,7 @@ module.exports.assign = function (state, tun, cb) { return; } - console.log('https invokeHandler'); + //console.log('https invokeHandler'); invokeHandler(conf, tlsSocket, tun, id); }); });