-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
40 lines (31 loc) · 1.02 KB
/
server.js
File metadata and controls
40 lines (31 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';
const net = require('net');
const layer4 = require('./src/layer4');
// const layer7 = require('.src/layer7');
const PORT = process.env.PORT || 8000;
const server = net.createServer((clientSocket) => {
clientSocket.setTimeout(30000);
clientSocket.on('timeout', function() {
console.error('client socket timeout, ending connection.');
clientSocket.end();
});
clientSocket.once('data', function(data) {
const reqStr = data.toString();
const isConnect = reqStr.indexOf('CONNECT') === 0;
if (isConnect) {
layer4.handleTunnel(clientSocket, reqStr);
} else {
// layer7.handleHttp(clientSocket, data);
// for now, just ignore non transport layer traffic
}
});
clientSocket.on('error', function(err) {
console.error('Connection dropped from host, err=', (err && err.message));
});
});
server.on('error', function(err) {
console.error('Proxy server error:', err.message);
});
server.listen(PORT, '0.0.0.0', function() {
console.log('Proxy live on ' + PORT);
});