hsync 0.15.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +31 -1
- package/connection.js +21 -1
- package/lib/socket-listen-handler.js +3 -2
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -12,7 +12,13 @@ program
|
|
|
12
12
|
.addOption(new Option('-p, --port <number>', 'port for local webserver', 3000).env('PORT'))
|
|
13
13
|
.addOption(new Option('-d, --dynamic-host <url>', 'host to get a dynamic connection from').env('HSYNC_DYNAMIC_HOST'))
|
|
14
14
|
.addOption(new Option('-s, --hsync-server <url>', 'hsync-server location ex: wss://sub.mydomain.com').env('HSYNC_SERVER'))
|
|
15
|
-
.addOption(new Option('-hs, --hsync-secret <
|
|
15
|
+
.addOption(new Option('-hs, --hsync-secret <string>', 'password to connect to hsync-server').env('HSYNC_SECRET'))
|
|
16
|
+
.addOption(new Option('-llp, --listener-local-port <number>', 'local port to open for listener').env('HSYNC_LLP'))
|
|
17
|
+
.addOption(new Option('-lth, --listener-target-host <url>', 'target host for listener').env('HSYNC_LTH'))
|
|
18
|
+
.addOption(new Option('-ltp, --listener-target-port <number>', 'target port for listener').env('HSYNC_LTP'))
|
|
19
|
+
.addOption(new Option('-rip, --relay-inbound-port <number>', 'inbound port to open for relay').env('HSYNC_RIP'))
|
|
20
|
+
.addOption(new Option('-rth, --relay-target-host <string>', 'target host for relay').env('HSYNC_RTH'))
|
|
21
|
+
.addOption(new Option('-rtp, --relay-target-port <number>', 'target port for relay').env('HSYNC_RTP'));
|
|
16
22
|
|
|
17
23
|
program.parse();
|
|
18
24
|
|
|
@@ -23,6 +29,30 @@ if(options.port) {
|
|
|
23
29
|
options.port = Number(options.port);
|
|
24
30
|
}
|
|
25
31
|
|
|
32
|
+
if(options.listenerLocalPort) {
|
|
33
|
+
options.listenerLocalPort = options.listenerLocalPort.split(',').map((p) => Number(p));
|
|
34
|
+
}
|
|
35
|
+
if (options.listenerTargetHost) {
|
|
36
|
+
options.listenerTargetHost = options.listenerTargetHost.split(',');
|
|
37
|
+
}
|
|
38
|
+
if (options.listenerTargetPort) {
|
|
39
|
+
options.listenerTargetPort = options.listenerTargetPort.split(',').map((p) => Number(p));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if (options.relayInboundPort) {
|
|
44
|
+
options.relayInboundPort = options.relayInboundPort.split(',').map((p) => Number(p));
|
|
45
|
+
}
|
|
46
|
+
if (options.relayTargetHost) {
|
|
47
|
+
options.relayTargetHost = options.relayTargetHost.split(',');
|
|
48
|
+
}
|
|
49
|
+
if (options.relayTargetPort) {
|
|
50
|
+
options.relayTargetPort = options.relayTargetPort.split(',').map((p) => Number(p));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// console.log('options', options);
|
|
54
|
+
|
|
55
|
+
|
|
26
56
|
let [defaultCon] = config.connections;
|
|
27
57
|
defaultCon = {...defaultCon, ...options};
|
|
28
58
|
|
package/connection.js
CHANGED
|
@@ -34,8 +34,16 @@ async function createHsync(config) {
|
|
|
34
34
|
hsyncBase,
|
|
35
35
|
keepalive,
|
|
36
36
|
dynamicHost,
|
|
37
|
+
listenerLocalPort,
|
|
38
|
+
listenerTargetHost,
|
|
39
|
+
listenerTargetPort,
|
|
40
|
+
relayInboundPort,
|
|
41
|
+
relayTargetHost,
|
|
42
|
+
relayTargetPort,
|
|
37
43
|
} = config;
|
|
38
44
|
|
|
45
|
+
// console.log('config', config);
|
|
46
|
+
|
|
39
47
|
let dynamicTimeout;
|
|
40
48
|
|
|
41
49
|
if (dynamicHost) {
|
|
@@ -197,7 +205,8 @@ async function createHsync(config) {
|
|
|
197
205
|
});
|
|
198
206
|
}
|
|
199
207
|
|
|
200
|
-
function addSocketListener (port, hostName, targetPort, targetHost
|
|
208
|
+
function addSocketListener (port, hostName, targetPort, targetHost) {
|
|
209
|
+
// console.log('addSocketListener', port, hostName, targetPort, targetHost);
|
|
201
210
|
const handler = createSocketListenHandler({port, hostName, targetPort, targetHost, hsyncClient});
|
|
202
211
|
const id = b64id.generateId();
|
|
203
212
|
socketListeners[id] = {handler, info: {port, hostName, targetPort, targetHost}, id};
|
|
@@ -277,6 +286,17 @@ async function createHsync(config) {
|
|
|
277
286
|
hsyncClient.webBase = `${hsyncClient.webUrl}/${hsyncBase}`;
|
|
278
287
|
hsyncClient.port = port;
|
|
279
288
|
|
|
289
|
+
if (listenerLocalPort) {
|
|
290
|
+
listenerLocalPort.forEach((llp, i) => {
|
|
291
|
+
const lth = listenerTargetHost ? listenerTargetHost[i] : null;
|
|
292
|
+
if (lth) {
|
|
293
|
+
const ltp = listenerTargetPort ? listenerTargetPort[i] : llp;
|
|
294
|
+
addSocketListener(llp, myHostName, ltp, lth);
|
|
295
|
+
console.log('relaying local', llp, 'to', lth, ltp);
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
280
300
|
return hsyncClient;
|
|
281
301
|
}
|
|
282
302
|
|
|
@@ -37,9 +37,10 @@ function receiveRelayData(requestInfo, { socketId, data }) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
function createSocketListenHandler({hostName, port, targetPort, targetHost, hsyncClient}) {
|
|
40
|
-
debug('creating handler', hostName, port, targetPort, targetHost);
|
|
40
|
+
debug('creating handler', { hostName, port, targetPort, targetHost });
|
|
41
41
|
|
|
42
|
-
const rpcPeer = getRPCPeer({hostName, hsyncClient});
|
|
42
|
+
// const rpcPeer = getRPCPeer({hostName, hsyncClient});
|
|
43
|
+
const rpcPeer = getRPCPeer({hostName: targetHost, hsyncClient});
|
|
43
44
|
|
|
44
45
|
debug('peer crated');
|
|
45
46
|
|