From e259c4d0ceb730ae387d6c18618af6b93ddef3ba Mon Sep 17 00:00:00 2001 From: tigerbot Date: Fri, 26 May 2017 19:18:53 -0600 Subject: [PATCH] changed method for wrapping socket pre-TLS --- lib/modules/tls.js | 33 +++++---------------------------- package.json | 3 ++- 2 files changed, 7 insertions(+), 29 deletions(-) diff --git a/lib/modules/tls.js b/lib/modules/tls.js index a18ab2d..95d9e37 100644 --- a/lib/modules/tls.js +++ b/lib/modules/tls.js @@ -36,40 +36,17 @@ module.exports.create = function (deps, config, netHandler) { , 'localPort' ]; function wrapSocket(socket, opts) { - var reader = require('socket-pair').create(function (err, writer) { - if (err) { - reader.emit('error', err); - return; - } - + if (!opts.hyperPeek) { process.nextTick(function () { socket.unshift(opts.firstChunk); }); + } - socket.pipe(writer); - writer.pipe(socket); - - socket.on('error', function (err) { - console.log('wrapped TLS socket error', err); - reader.emit('error', err); - }); - writer.on('error', function (err) { - console.error('socket-pair writer error', err); - // If the writer had an error the reader probably did too, and I don't think we'll - // get much out of emitting this on the original socket, so logging is enough. - }); - }); - - // We can't set these properties the normal way because there is a getter without a setter, - // but we can use defineProperty. We reuse the descriptor even though we will be manipulating - // it because we will only ever set the value and we set it every time. - var descriptor = {enumerable: true, configurable: true, writable: true}; + var wrapped = require('tunnel-packer').wrapSocket(socket); addressNames.forEach(function (name) { - descriptor.value = opts[name] || extractSocketProp(socket, name); - Object.defineProperty(reader, name, descriptor); + wrapped[name] = opts[name] || wrapped[name]; }); - - return reader; + return wrapped; } var le = greenlock.create({ diff --git a/package.json b/package.json index 0f2629a..4a232f5 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "sni": "^1.0.0", "socket-pair": "^1.0.0", "stream-pair": "^1.0.3", - "stunnel": "git+https://git.daplie.com/Daplie/node-tunnel-client.git#v1" + "stunnel": "git+https://git.daplie.com/Daplie/node-tunnel-client.git#v1", + "tunnel-packer": "^1.3.0" } }