use stream-pair, which actually does what we want
This commit is contained in:
parent
a84899f8c5
commit
1242e65e9c
25
README.md
25
README.md
|
@ -145,17 +145,6 @@ local handler and the tunnel handler.
|
||||||
You could do a little magic like this:
|
You could do a little magic like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var StreamImpl = {
|
|
||||||
write: function (chunk, encoding, cb) {
|
|
||||||
this.__my_socket.write(chunk, encoding);
|
|
||||||
cb();
|
|
||||||
}
|
|
||||||
, read: function (size) {
|
|
||||||
var x = this.__my_socket.read(size);
|
|
||||||
if (x) { this.push(x); }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
stunnel.connect({
|
stunnel.connect({
|
||||||
// ...
|
// ...
|
||||||
, net: {
|
, net: {
|
||||||
|
@ -163,20 +152,14 @@ stunnel.connect({
|
||||||
// data is the hello packet / first chunk
|
// data is the hello packet / first chunk
|
||||||
// info = { data, servername, port, host, remoteAddress: { family, address, port } }
|
// info = { data, servername, port, host, remoteAddress: { family, address, port } }
|
||||||
|
|
||||||
|
var streamPair = require('stream-pair');
|
||||||
|
|
||||||
// here "reader" means the socket that looks like the connection being accepted
|
// here "reader" means the socket that looks like the connection being accepted
|
||||||
var reader = new (require('stream').Duplex)();
|
var writer = streamPair.create();
|
||||||
// here "writer" means the remote-looking part of the socket that driving the connection
|
// here "writer" means the remote-looking part of the socket that driving the connection
|
||||||
var writer = new (require('stream').Duplex)();
|
var reader = writer.other;
|
||||||
// duplex = { write, push, end, events: [ 'readable', 'data', 'error', 'end' ] };
|
// duplex = { write, push, end, events: [ 'readable', 'data', 'error', 'end' ] };
|
||||||
|
|
||||||
reader.__my_socket = writer;
|
|
||||||
reader._write = StreamImpl.write;
|
|
||||||
reader._read = StreamImpl.read;
|
|
||||||
|
|
||||||
writer.__my_socket = reader;
|
|
||||||
writer._write = StreamImpl.write;
|
|
||||||
writer._read = StreamImpl.read;
|
|
||||||
|
|
||||||
reader.remoteFamily = info.remoteFamily;
|
reader.remoteFamily = info.remoteFamily;
|
||||||
reader.remoteAddress = info.remoteAddress;
|
reader.remoteAddress = info.remoteAddress;
|
||||||
reader.remotePort = info.remotePort;
|
reader.remotePort = info.remotePort;
|
||||||
|
|
Loading…
Reference in New Issue