clarify myDuplex => reader, myDuplex2 => writer
This commit is contained in:
parent
a0ed74b641
commit
a84899f8c5
36
README.md
36
README.md
|
@ -145,7 +145,7 @@ 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 Dup = {
|
var StreamImpl = {
|
||||||
write: function (chunk, encoding, cb) {
|
write: function (chunk, encoding, cb) {
|
||||||
this.__my_socket.write(chunk, encoding);
|
this.__my_socket.write(chunk, encoding);
|
||||||
cb();
|
cb();
|
||||||
|
@ -163,34 +163,36 @@ 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 myDuplex = new (require('stream').Duplex)();
|
// here "reader" means the socket that looks like the connection being accepted
|
||||||
var myDuplex2 = new (require('stream').Duplex)();
|
var reader = new (require('stream').Duplex)();
|
||||||
|
// here "writer" means the remote-looking part of the socket that driving the connection
|
||||||
|
var writer = new (require('stream').Duplex)();
|
||||||
// duplex = { write, push, end, events: [ 'readable', 'data', 'error', 'end' ] };
|
// duplex = { write, push, end, events: [ 'readable', 'data', 'error', 'end' ] };
|
||||||
|
|
||||||
myDuplex2.__my_socket = myDuplex;
|
reader.__my_socket = writer;
|
||||||
myDuplex2._write = Dup.write;
|
reader._write = StreamImpl.write;
|
||||||
myDuplex2._read = Dup.read;
|
reader._read = StreamImpl.read;
|
||||||
|
|
||||||
myDuplex.__my_socket = myDuplex2;
|
writer.__my_socket = reader;
|
||||||
myDuplex._write = Dup.write;
|
writer._write = StreamImpl.write;
|
||||||
myDuplex._read = Dup.read;
|
writer._read = StreamImpl.read;
|
||||||
|
|
||||||
myDuplex.remoteFamily = info.remoteFamily;
|
reader.remoteFamily = info.remoteFamily;
|
||||||
myDuplex.remoteAddress = info.remoteAddress;
|
reader.remoteAddress = info.remoteAddress;
|
||||||
myDuplex.remotePort = info.remotePort;
|
reader.remotePort = info.remotePort;
|
||||||
|
|
||||||
// socket.local{Family,Address,Port}
|
// socket.local{Family,Address,Port}
|
||||||
myDuplex.localFamily = 'IPv4';
|
reader.localFamily = 'IPv4';
|
||||||
myDuplex.localAddress = '127.0.01';
|
reader.localAddress = '127.0.01';
|
||||||
myDuplex.localPort = info.port;
|
reader.localPort = info.port;
|
||||||
|
|
||||||
httpsServer.emit('connection', myDuplex);
|
httpsServer.emit('connection', reader);
|
||||||
|
|
||||||
if (cb) {
|
if (cb) {
|
||||||
process.nextTick(cb);
|
process.nextTick(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
return myDuplex2;
|
return writer;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue