wip minor refactoring

This commit is contained in:
AJ ONeal 2018-09-25 01:14:54 -06:00
parent 3e0c977511
commit 82f5545d72
5 changed files with 12 additions and 9 deletions

View File

@ -401,6 +401,7 @@ function parseConfig(err, text) {
//console.log("no questioning:");
parseCli(state);
}
function parseCli(/*state*/) {
var special = [
'false', 'none', 'off', 'disable'
@ -472,7 +473,7 @@ function parseConfig(err, text) {
}
state._clientConfig = camelCopy(state._clientConfig || {}) || {};
RC = require('../lib/remote-control-client.js').create(state);
RC = require('../lib/rc/index.js').create(state);
if (!Object.keys(state._clientConfig).length) {
console.info('(' + state._ipc.comment + ": " + state._ipc.path + ')');

View File

@ -24,7 +24,7 @@ var camelCopy = recase.camelCopy.bind(recase);
var snakeCopy = recase.snakeCopy.bind(recase);
var TPLS = TOML.parse(fs.readFileSync(path.join(__dirname, "../lib/en-us.toml"), 'utf8'));
var TelebitRemote = require('../').TelebitRemote;
var TelebitRemote = require('../lib/daemon/index.js').TelebitRemote;
var state = { homedir: os.homedir(), servernames: {}, ports: {}, keepAlive: { state: false } };

View File

@ -28,6 +28,7 @@ function TelebitRemote(state) {
EventEmitter.call(this);
var me = this;
var priv = {};
var path = require('path');
//var defaultHttpTimeout = (2 * 60);
//var activityTimeout = state.activityTimeout || (defaultHttpTimeout - 5) * 1000;
@ -39,8 +40,9 @@ function TelebitRemote(state) {
priv.tokens = [];
var auth;
if(!state.sortingHat) {
state.sortingHat = "./sorting-hat.js";
state.sortingHat = path.join(__dirname, '../sorting-hat.js');
}
state._connectionHandler = require(state.sortingHat);
if (state.token) {
if ('undefined' === state.token) {
throw new Error("passed string 'undefined' as token");
@ -349,7 +351,7 @@ function TelebitRemote(state) {
// TODO use readable streams instead
wstunneler._socket.pause();
require(state.sortingHat).assign(state, tun, function (err, conn) {
state._connectionHandler.assign(state, tun, function (err, conn) {
if (err) {
err.message = err.message.replace(/:tun_id/, tun._id);
packerHandlers._onConnectError(cid, tun, err);
@ -472,12 +474,12 @@ function TelebitRemote(state) {
priv.timeoutId = null;
var machine = Packer.create(packerHandlers);
console.info("[telebit:lib/remote.js] [connect] '" + (state.wss || state.relay) + "'");
console.info("[telebit:lib/daemon.js] [connect] '" + (state.wss || state.relay) + "'");
var tunnelUrl = (state.wss || state.relay).replace(/\/$/, '') + '/'; // + auth;
wstunneler = new WebSocket(tunnelUrl, { rejectUnauthorized: !state.insecure });
// XXXXXX
wstunneler.on('open', function () {
console.info("[telebit:lib/remote.js] [open] connected to '" + (state.wss || state.relay) + "'");
console.info("[telebit:lib/daemon.js] [open] connected to '" + (state.wss || state.relay) + "'");
me.emit('connect');
priv.refreshTimeout();
priv.timeoutId = setTimeout(priv.checkTimeout, activityTimeout);

View File

@ -4,7 +4,7 @@ var os = require('os');
var path = require('path');
var http = require('http');
var common = require('./cli-common.js');
var common = require('../cli-common.js');
function packConfig(config) {
return Object.keys(config).map(function (key) {

View File

@ -1,8 +1,8 @@
{
"name": "telebit",
"version": "0.20.4",
"version": "0.20.5-wip",
"description": "Break out of localhost. Connect to any device from anywhere over any tcp port or securely in a browser. A secure tunnel. A poor man's reverse VPN.",
"main": "lib/remote.js",
"main": "lib/daemon/index.js",
"files": [
"bin",
"lib",