changed method for wrapping socket pre-TLS

This commit is contained in:
tigerbot 2017-05-26 19:18:53 -06:00
parent 509f2f4f4f
commit e259c4d0ce
2 changed files with 7 additions and 29 deletions

View File

@ -36,40 +36,17 @@ module.exports.create = function (deps, config, netHandler) {
, 'localPort' , 'localPort'
]; ];
function wrapSocket(socket, opts) { function wrapSocket(socket, opts) {
var reader = require('socket-pair').create(function (err, writer) { if (!opts.hyperPeek) {
if (err) {
reader.emit('error', err);
return;
}
process.nextTick(function () { process.nextTick(function () {
socket.unshift(opts.firstChunk); socket.unshift(opts.firstChunk);
}); });
}
socket.pipe(writer); var wrapped = require('tunnel-packer').wrapSocket(socket);
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};
addressNames.forEach(function (name) { addressNames.forEach(function (name) {
descriptor.value = opts[name] || extractSocketProp(socket, name); wrapped[name] = opts[name] || wrapped[name];
Object.defineProperty(reader, name, descriptor);
}); });
return wrapped;
return reader;
} }
var le = greenlock.create({ var le = greenlock.create({

View File

@ -64,6 +64,7 @@
"sni": "^1.0.0", "sni": "^1.0.0",
"socket-pair": "^1.0.0", "socket-pair": "^1.0.0",
"stream-pair": "^1.0.3", "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"
} }
} }