tcp-proxy.js
Advanced tools
Comparing version 1.2.0 to 1.3.0
1.3.0 / 2019-06-14 | ||
================== | ||
**features** | ||
* [[`18148bb`](http://github.com/whxaxes/tcp-proxy.js/commit/18148bb3018e8264ff6cba04f21ebfd164ccdafa)] - feat: format (wanghx <<whx89768@alibaba-inc.com>>) | ||
**others** | ||
* [[`a8bea82`](http://github.com/whxaxes/tcp-proxy.js/commit/a8bea8254113017dd1563b3ca18c88ef8a1436ea)] - Removed context from Through2 done() (Chiru B <<33750251+MeinLieblingsmensch@users.noreply.github.com>>) | ||
* [[`cf74f3f`](http://github.com/whxaxes/tcp-proxy.js/commit/cf74f3f3812de421db97da4622b67e2136abdce5)] - Tests retracted to the original (Chiru B <<33750251+MeinLieblingsmensch@users.noreply.github.com>>) | ||
* [[`49eaac7`](http://github.com/whxaxes/tcp-proxy.js/commit/49eaac7d2d9c6868b1b915abbdd717f398ea06f1)] - Fixed for Tests for linting (Chiru B <<33750251+MeinLieblingsmensch@users.noreply.github.com>>) | ||
* [[`e047288`](http://github.com/whxaxes/tcp-proxy.js/commit/e047288e04343c237d33d0945ce014724e6c4cd2)] - Reflecting new changes of 1.2.5 (Chiru B <<33750251+MeinLieblingsmensch@users.noreply.github.com>>) | ||
* [[`41f0834`](http://github.com/whxaxes/tcp-proxy.js/commit/41f0834e37e9f03ef478ebc230d6e613bebbb4ad)] - Update 1.2.5 (Chiru B <<33750251+MeinLieblingsmensch@users.noreply.github.com>>) | ||
* [[`70ceee4`](http://github.com/whxaxes/tcp-proxy.js/commit/70ceee4c4feedd7d20afae6e227e4742f6148fd2)] - Interceptor alter data changed (Chiru B <<33750251+MeinLieblingsmensch@users.noreply.github.com>>) | ||
* [[`6771481`](http://github.com/whxaxes/tcp-proxy.js/commit/67714817a6e92a10843495bf06f00fdf50882df6)] - Fixed linting (Chiru B <<33750251+MeinLieblingsmensch@users.noreply.github.com>>) | ||
* [[`8b7e9cd`](http://github.com/whxaxes/tcp-proxy.js/commit/8b7e9cdcc8fd9f354f094970f057942ae4e01d3c)] - Testing the tests variables for matches (Chiru B <<33750251+MeinLieblingsmensch@users.noreply.github.com>>) | ||
* [[`6461c66`](http://github.com/whxaxes/tcp-proxy.js/commit/6461c66f8709c9c91d3721be67fd57e82af05173)] - Update README.md (Chiru B <<33750251+MeinLieblingsmensch@users.noreply.github.com>>) | ||
* [[`17b0a6e`](http://github.com/whxaxes/tcp-proxy.js/commit/17b0a6ec49e451d465d69a8aca30551d1a6ce9e1)] - Update README.md (Chiru B <<33750251+MeinLieblingsmensch@users.noreply.github.com>>) | ||
* [[`8dca987`](http://github.com/whxaxes/tcp-proxy.js/commit/8dca987ec3c2f04bce44d019d6c270edbb60ff8b)] - Added connection information (Chiru B <<33750251+MeinLieblingsmensch@users.noreply.github.com>>) | ||
* [[`1a2efa4`](http://github.com/whxaxes/tcp-proxy.js/commit/1a2efa46105cff65ea5d081d6684a9c26f737284)] - Update README.md (Chiru B <<33750251+MeinLieblingsmensch@users.noreply.github.com>>) | ||
* [[`7ca6206`](http://github.com/whxaxes/tcp-proxy.js/commit/7ca6206d6f1f98f085a85a5111993e8564e84b64)] - Updated README to make it more readable. (Chiru B <<33750251+MeinLieblingsmensch@users.noreply.github.com>>) | ||
1.2.0 / 2018-06-05 | ||
@@ -3,0 +24,0 @@ ================== |
27
index.js
@@ -8,5 +8,22 @@ 'use strict'; | ||
function genThrough(interceptor) { | ||
function genThrough(interceptor, connection) { | ||
return through.obj(function(chunk, enc, done) { | ||
const result = interceptor(chunk, enc); | ||
const context = { | ||
client: { | ||
ip: connection.client.address().address, | ||
port: connection.client.address().port, | ||
}, | ||
server: { | ||
ip: connection.server.address().address, | ||
port: connection.server.address().port, | ||
}, | ||
self: { | ||
ip: connection.forwardHost, | ||
port: connection.forwardPort, | ||
}, | ||
size: chunk.length, | ||
}; | ||
const result = interceptor(chunk, enc, context); | ||
const handle = data => { | ||
@@ -71,3 +88,3 @@ if (data && !Buffer.isBuffer(data)) { | ||
if (interceptor.client) { | ||
interceptorClient = genThrough(interceptor.client); | ||
interceptorClient = genThrough(interceptor.client, { client, server, forwardHost, forwardPort }); | ||
_client = _client.pipe(interceptorClient); | ||
@@ -78,3 +95,3 @@ } | ||
if (interceptor.server) { | ||
interceptorServer = genThrough(interceptor.server); | ||
interceptorServer = genThrough(interceptor.server, { client, server, forwardHost, forwardPort }); | ||
_server = _server.pipe(interceptorServer); | ||
@@ -85,3 +102,3 @@ } | ||
_server.pipe(client); | ||
debug(`proxy 127.0.0.1:${proxyPort} connect to ${forwardHost}:${forwardPort}`); | ||
debug(`proxy {$proxyHost}:${proxyPort} connect to ${forwardHost}:${forwardPort}`); | ||
this.emit('connection', _client, _server); | ||
@@ -88,0 +105,0 @@ }); |
{ | ||
"name": "tcp-proxy.js", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "simple tcp proxy", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
# tcp-proxy.js | ||
a simple tcp proxy | ||
A TCP Proxy package for NodeJS | ||
@@ -25,3 +25,3 @@ [![NPM version][npm-image]][npm-url] | ||
create proxy | ||
### Create a new proxy instance | ||
@@ -37,9 +37,21 @@ ```js | ||
end proxy | ||
### Create a new proxy instance for a specific IP/Hostname | ||
This will only listen to connections on the specified IP/Hostname, you can have duplicates of ports this way. | ||
```js | ||
const TCPProxy = require('tcp-proxy.js'); | ||
const proxy = new TCPProxy({ host: 'localhost', port: 9229 }); | ||
proxy.createProxy({ | ||
forwardPort: 9999, | ||
forwardHost: 'localhost', | ||
}); | ||
``` | ||
### End proxy | ||
```js | ||
proxy.end(); | ||
``` | ||
interceptor | ||
### Interceptor | ||
@@ -66,3 +78,3 @@ ```js | ||
async interceptor | ||
### Async Interceptor | ||
@@ -87,4 +99,35 @@ ```js | ||
### Connection Information | ||
#### IP, Port of Client, Server and Self | ||
```js | ||
proxy.createProxy({ | ||
forwardPort: 9999, | ||
interceptor: { | ||
client(result, encoding, connection) { | ||
console.info('Connection from ', connection.client.ip, ':', connection.client.port, 'to', connection.self.ip, ':', connection.self.port, 'from', connection.server.ip, ':', connection.server.port); | ||
return result | ||
} | ||
}, | ||
}); | ||
``` | ||
#### Data size | ||
```js | ||
proxy.createProxy({ | ||
forwardPort: 9999, | ||
interceptor: { | ||
server(result, encoding, connection) { | ||
console.log('Connection Size:' + connection.size); | ||
return result | ||
} | ||
}, | ||
}); | ||
``` | ||
## License | ||
MIT | ||
MIT |
12651
128
130