From 8c1c8d800697c193ca7a4abf53c436b39d793660 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 31 May 2018 14:48:12 -0600 Subject: [PATCH] cleanup --- lib/sorting-hat.js | 87 +++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/lib/sorting-hat.js b/lib/sorting-hat.js index a105864..7eb971a 100644 --- a/lib/sorting-hat.js +++ b/lib/sorting-hat.js @@ -55,17 +55,6 @@ module.exports.print = function (config) { module.exports.assign = function (state, tun, cb) { var net = state.net || require('net'); - if (!tun.name && !tun.serviceport) { - console.log('tun:\n',tun); - //console.warn(tun.data.toString()); - cb(new Error("No routing information for ':tun_id'. Missing both 'name' and 'serviceport'.")); - return; - } - - if (!state.config.servernames) { - state.config.servernames = {}; - } - var handlers = {}; handlers.http = function (socket) { if (!state.greenlock) { @@ -109,13 +98,6 @@ module.exports.assign = function (state, tun, cb) { return conn; } - if ('http' === tun.service || 'https' === tun.service) { - if (!tun.name) { - cb(new Error("No routing information for ':tun_id'. Service '" + tun.service + "' is missing 'name'.")); - return; - } - } - function redirectHttp(cb) { var socketPair = require('socket-pair'); var conn = socketPair.create(function (err, other) { @@ -127,31 +109,6 @@ module.exports.assign = function (state, tun, cb) { return conn; } - var handled; - - if ('http' === tun.service) { - // TODO match *.example.com - handled = Object.keys(state.config.servernames).some(function (sn) { - if (sn !== tun.name) { return; } - - console.log('Found config match for PLAIN', tun.name); - if (!state.config.servernames[sn]) { return; } - - if (false === state.config.servernames[sn].terminate) { - cb(new Error("insecure http not supported yet")); - return true; - } - - console.log('Redirecting HTPTP for', tun.name); - redirectHttp(cb); - return true; - }); - if (!handled) { - redirectHttp(cb); - } - return; - } - function defineProps(other, tun) { Object.defineProperty(other, 'remoteFamily', { enumerable: false, @@ -233,6 +190,50 @@ module.exports.assign = function (state, tun, cb) { return conn; } + var handled; + + if (!tun.name && !tun.serviceport) { + console.log('tun:\n',tun); + //console.warn(tun.data.toString()); + cb(new Error("No routing information for ':tun_id'. Missing both 'name' and 'serviceport'.")); + return; + } + + if (!state.config.servernames) { + state.config.servernames = {}; + } + + + if ('http' === tun.service || 'https' === tun.service) { + if (!tun.name) { + cb(new Error("No routing information for ':tun_id'. Service '" + tun.service + "' is missing 'name'.")); + return; + } + } + + if ('http' === tun.service) { + // TODO match *.example.com + handled = Object.keys(state.config.servernames).some(function (sn) { + if (sn !== tun.name) { return; } + + console.log('Found config match for PLAIN', tun.name); + if (!state.config.servernames[sn]) { return; } + + if (false === state.config.servernames[sn].terminate) { + cb(new Error("insecure http not supported yet")); + return true; + } + + console.log('Redirecting HTPTP for', tun.name); + redirectHttp(cb); + return true; + }); + if (!handled) { + redirectHttp(cb); + } + return; + } + if ('https' === tun.service) { // TODO match *.example.com handled = Object.keys(state.config.servernames).some(function (sn) {