diff --git a/handlers.js b/handlers.js index efd044b..10c8751 100644 --- a/handlers.js +++ b/handlers.js @@ -2,7 +2,7 @@ var http = require('http'); var tls = require('tls'); -var packerStream = require('tunnel-packer').Stream; +var wrapSocket = require('tunnel-packer').wrapSocket; var redirectHttps = require('redirect-https')(); module.exports.create = function (program) { @@ -57,19 +57,8 @@ module.exports.create = function (program) { // tlsServer.emit('connection', socket); // this didn't work either //console.log('chunkLen', firstChunk.byteLength); - var myDuplex = packerStream.create(socket); - console.log('httpsInvalid servername', servername); - program.tlsInvalidSniServer.emit('connection', myDuplex); - - socket.on('data', function (chunk) { - console.log('[' + Date.now() + '] socket data', chunk.byteLength); - myDuplex.push(chunk); - }); - socket.on('error', function (err) { - console.error('[error] httpsInvalid TODO close'); - console.error(err); - }); + program.tlsInvalidSniServer.emit('connection', wrapSocket(socket)); }; // @@ -97,18 +86,7 @@ module.exports.create = function (program) { // tlsServer.emit('connection', socket); // this didn't work either //console.log('chunkLen', firstChunk.byteLength); - var myDuplex = packerStream.create(socket); - console.log('httpsTunnel (Admin) servername', servername); - program.tlsTunnelServer.emit('connection', myDuplex); - - socket.on('data', function (chunk) { - console.log('[' + Date.now() + '] socket data', chunk.byteLength); - myDuplex.push(chunk); - }); - socket.on('error', function (err) { - console.error('[error] httpsTunnel (Admin) TODO close'); - console.error(err); - }); + program.tlsTunnelServer.emit('connection', wrapSocket(socket)); }; }; diff --git a/package.json b/package.json index 51720cb..77a568e 100644 --- a/package.json +++ b/package.json @@ -51,10 +51,10 @@ "commander": "^2.9.0", "greenlock": "^2.1.12", "jsonwebtoken": "^7.1.9", - "localhost.daplie.me-certificates": "^1.3.0", + "localhost.daplie.me-certificates": "^1.3.3", "redirect-https": "^1.1.0", "sni": "^1.0.0", - "tunnel-packer": "^1.2.0", + "tunnel-packer": "^1.3.0", "ws": "^2.2.3" } } diff --git a/wstunneld.js b/wstunneld.js index ee22a1f..c03eef0 100644 --- a/wstunneld.js +++ b/wstunneld.js @@ -347,6 +347,7 @@ module.exports.create = function (copts) { Object.keys(remotes).forEach(function (jwtoken) { removeToken(jwtoken); }); + ws.terminate(); } ws.on('close', hangup);