-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.js
More file actions
65 lines (48 loc) · 1.51 KB
/
Server.js
File metadata and controls
65 lines (48 loc) · 1.51 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import EventEmitter from 'events';
import debug from 'debug';
import Router from './Router';
import ControlServer from './ControlServer';
const log = debug('fwdizer:Server');
export default class Server extends EventEmitter {
constructor({
port = 55365,
tlsConfig
}) {
super();
log(`Constructing - control on ${port}`);
const control = this.control = ControlServer({
port,
tlsConfig
});
control.on('connection', (socket) => {
socket.on('createRouter', ({
externalPort
}, callback) => {
log('Received createRouter request');
const router = new Router({
externalPort,
tlsConfig
});
router.on('ready', () => {
log('Router is ready');
callback({
error: null,
internalPort: router.internalPort
});
router.on('newConnection', () => {
log('Sending request for new tunnel');
socket.emit('requestTunnel', {
externalPort,
internalPort: router.internalPort
});
});
});
});
});
}
selfDestruct() {
log('Self-Destructing');
this.control.close();
this.emit('dead');
}
}