From 4658fa88c6729b6ae5cda65a2461414437b7f9df Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 1 Jun 2018 03:50:27 -0600 Subject: [PATCH] echo tcp --- lib/sorting-hat.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/sorting-hat.js b/lib/sorting-hat.js index b7fd3ff..c6a6d75 100644 --- a/lib/sorting-hat.js +++ b/lib/sorting-hat.js @@ -120,6 +120,27 @@ module.exports.assign = function (state, tun, cb) { return conn; } + function echoTcp(cb) { + var socketPair = require('socket-pair'); + var conn = socketPair.create(function (err, other) { + if (err) { cb(err); return; } + + other.on('data', function (chunk) { + other.write(chunk); + }); + + other.on('end', function () { + other.end(); + }); + + cb(null, conn); + + other.write("[Telebit Echo Server] v1.0\nPlease edit your config file to port forward somewhere more useful.\n\n"); + }); + //if (tun.data) { conn.write(tun.data); } + return conn; + } + function defineProps(other, tun) { Object.defineProperty(other, 'remoteFamily', { enumerable: false, @@ -316,8 +337,11 @@ module.exports.assign = function (state, tun, cb) { if ('tcp' === tun.service) { trySsh(tun, function (err, conn) { if (conn) { cb(null, conn); return; } - cb(new Error("No TCP handler")); + // TODO add TCP handlers + console.log('Using echo server for tcp'); + echoTcp(cb); }); + return; } console.warn("Unknown service '" + tun.service + "'");