@celljs/ta-relay 0.0.0-stage → 4.6.0
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/README.md +34 -2
- package/esm/common/index.d.ts +6 -0
- package/esm/common/index.js +7 -0
- package/esm/common/index.js.map +1 -0
- package/esm/common/relay-bytes.d.ts +8 -0
- package/esm/common/relay-bytes.js +40 -0
- package/esm/common/relay-bytes.js.map +1 -0
- package/esm/common/relay-cipher.d.ts +22 -0
- package/esm/common/relay-cipher.js +55 -0
- package/esm/common/relay-cipher.js.map +1 -0
- package/esm/common/relay-pairing.d.ts +18 -0
- package/esm/common/relay-pairing.js +35 -0
- package/esm/common/relay-pairing.js.map +1 -0
- package/esm/common/relay-protocol.d.ts +56 -0
- package/esm/common/relay-protocol.js +29 -0
- package/esm/common/relay-protocol.js.map +1 -0
- package/esm/common/relay-room.d.ts +31 -0
- package/esm/common/relay-room.js +63 -0
- package/esm/common/relay-room.js.map +1 -0
- package/esm/common/relay-socket.d.ts +38 -0
- package/esm/common/relay-socket.js +98 -0
- package/esm/common/relay-socket.js.map +1 -0
- package/esm/node/index.d.ts +4 -0
- package/esm/node/index.js +5 -0
- package/esm/node/index.js.map +1 -0
- package/esm/node/relay-host.d.ts +61 -0
- package/esm/node/relay-host.js +208 -0
- package/esm/node/relay-host.js.map +1 -0
- package/esm/node/relay-server.d.ts +33 -0
- package/esm/node/relay-server.js +127 -0
- package/esm/node/relay-server.js.map +1 -0
- package/esm/node/relay-store.d.ts +35 -0
- package/esm/node/relay-store.js +59 -0
- package/esm/node/relay-store.js.map +1 -0
- package/esm/package.json +3 -0
- package/lib/common/index.d.ts +7 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/common/index.js +23 -0
- package/lib/common/index.js.map +1 -0
- package/lib/common/relay-bytes.d.ts +9 -0
- package/lib/common/relay-bytes.d.ts.map +1 -0
- package/lib/common/relay-bytes.js +43 -0
- package/lib/common/relay-bytes.js.map +1 -0
- package/lib/common/relay-cipher.d.ts +23 -0
- package/lib/common/relay-cipher.d.ts.map +1 -0
- package/lib/common/relay-cipher.js +59 -0
- package/lib/common/relay-cipher.js.map +1 -0
- package/lib/common/relay-cipher.spec.d.ts +2 -0
- package/lib/common/relay-cipher.spec.d.ts.map +1 -0
- package/lib/common/relay-cipher.spec.js +43 -0
- package/lib/common/relay-cipher.spec.js.map +1 -0
- package/lib/common/relay-pairing.d.ts +19 -0
- package/lib/common/relay-pairing.d.ts.map +1 -0
- package/lib/common/relay-pairing.js +38 -0
- package/lib/common/relay-pairing.js.map +1 -0
- package/lib/common/relay-pairing.spec.d.ts +2 -0
- package/lib/common/relay-pairing.spec.d.ts.map +1 -0
- package/lib/common/relay-pairing.spec.js +25 -0
- package/lib/common/relay-pairing.spec.js.map +1 -0
- package/lib/common/relay-protocol.d.ts +57 -0
- package/lib/common/relay-protocol.d.ts.map +1 -0
- package/lib/common/relay-protocol.js +32 -0
- package/lib/common/relay-protocol.js.map +1 -0
- package/lib/common/relay-room.d.ts +32 -0
- package/lib/common/relay-room.d.ts.map +1 -0
- package/lib/common/relay-room.js +67 -0
- package/lib/common/relay-room.js.map +1 -0
- package/lib/common/relay-socket.d.ts +39 -0
- package/lib/common/relay-socket.d.ts.map +1 -0
- package/lib/common/relay-socket.js +102 -0
- package/lib/common/relay-socket.js.map +1 -0
- package/lib/node/index.d.ts +5 -0
- package/lib/node/index.d.ts.map +1 -0
- package/lib/node/index.js +21 -0
- package/lib/node/index.js.map +1 -0
- package/lib/node/relay-host.d.ts +62 -0
- package/lib/node/relay-host.d.ts.map +1 -0
- package/lib/node/relay-host.js +212 -0
- package/lib/node/relay-host.js.map +1 -0
- package/lib/node/relay-server.d.ts +34 -0
- package/lib/node/relay-server.d.ts.map +1 -0
- package/lib/node/relay-server.js +131 -0
- package/lib/node/relay-server.js.map +1 -0
- package/lib/node/relay-store.d.ts +36 -0
- package/lib/node/relay-store.d.ts.map +1 -0
- package/lib/node/relay-store.js +63 -0
- package/lib/node/relay-store.js.map +1 -0
- package/lib/node/relay.spec.d.ts +2 -0
- package/lib/node/relay.spec.d.ts.map +1 -0
- package/lib/node/relay.spec.js +141 -0
- package/lib/node/relay.spec.js.map +1 -0
- package/package.json +58 -4
- package/src/common/index.ts +6 -0
- package/src/common/relay-bytes.ts +37 -0
- package/src/common/relay-cipher.spec.ts +45 -0
- package/src/common/relay-cipher.ts +74 -0
- package/src/common/relay-pairing.spec.ts +26 -0
- package/src/common/relay-pairing.ts +46 -0
- package/src/common/relay-protocol.ts +50 -0
- package/src/common/relay-room.ts +79 -0
- package/src/common/relay-socket.ts +106 -0
- package/src/node/index.ts +4 -0
- package/src/node/relay-host.ts +230 -0
- package/src/node/relay-server.ts +143 -0
- package/src/node/relay-store.ts +84 -0
- package/src/node/relay.spec.ts +151 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { RelayCipher } from '../common/relay-cipher.js';
|
|
2
|
+
import { type RelayHostMessage, type RelayWelcome } from '../common/relay-protocol.js';
|
|
3
|
+
import type { RelayStore } from './relay-store.js';
|
|
4
|
+
export interface RelayHostOptions {
|
|
5
|
+
store: RelayStore;
|
|
6
|
+
/** The WebSocket of this ta serve, with its token: every device gets a connection to it of its own. */
|
|
7
|
+
localUrl: string;
|
|
8
|
+
/** First wait before reconnecting to the relay; it doubles up to 30 seconds. */
|
|
9
|
+
reconnectDelayMs?: number;
|
|
10
|
+
}
|
|
11
|
+
/** A device on a channel: the handshake, then its connection to ta serve. */
|
|
12
|
+
declare class RelayChannel {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
protected readonly host: RelayHost;
|
|
15
|
+
protected readonly options: RelayHostOptions;
|
|
16
|
+
protected cipher?: RelayCipher;
|
|
17
|
+
protected local?: WebSocket;
|
|
18
|
+
protected readonly early: string[];
|
|
19
|
+
protected readonly timer: NodeJS.Timeout;
|
|
20
|
+
constructor(id: string, host: RelayHost, options: RelayHostOptions);
|
|
21
|
+
receive(text: string): Promise<void>;
|
|
22
|
+
/** From the relay: the device is gone. */
|
|
23
|
+
closed(): void;
|
|
24
|
+
protected hello(text: string): Promise<void>;
|
|
25
|
+
protected connectLocal(cipher: RelayCipher): void;
|
|
26
|
+
protected answer(welcome: RelayWelcome): void;
|
|
27
|
+
protected close(): void;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* ta serve at the relay: one WebSocket out to it, over which the paired devices come in, each on a
|
|
31
|
+
* channel of its own. A device that knows its key gets a connection to ta serve; nothing else does, and
|
|
32
|
+
* the relay sees only what the two seal.
|
|
33
|
+
*/
|
|
34
|
+
export declare class RelayHost {
|
|
35
|
+
protected readonly options: RelayHostOptions;
|
|
36
|
+
protected socket?: WebSocket;
|
|
37
|
+
/** Where {@link socket} goes: WebSocket.url is normalised. */
|
|
38
|
+
protected target?: string;
|
|
39
|
+
protected stopped: boolean;
|
|
40
|
+
protected attempts: number;
|
|
41
|
+
protected timer?: ReturnType<typeof setTimeout>;
|
|
42
|
+
protected readonly channels: Map<string, RelayChannel>;
|
|
43
|
+
constructor(options: RelayHostOptions);
|
|
44
|
+
/** Whether the connection to the relay is open. */
|
|
45
|
+
get online(): boolean;
|
|
46
|
+
/** Connects when relay.json has a relay and a device, and keeps connected; checks again on {@link refresh}. */
|
|
47
|
+
start(): void;
|
|
48
|
+
/** relay.json may have changed: connect if it now has devices, or leave if it has none. */
|
|
49
|
+
refresh(): void;
|
|
50
|
+
stop(): void;
|
|
51
|
+
/** @internal */
|
|
52
|
+
send(message: RelayHostMessage): void;
|
|
53
|
+
/** @internal */
|
|
54
|
+
closeChannel(id: string): void;
|
|
55
|
+
protected connect(target: string): void;
|
|
56
|
+
protected receive(text: string): void;
|
|
57
|
+
protected scheduleReconnect(): void;
|
|
58
|
+
protected disconnect(): void;
|
|
59
|
+
protected closeChannels(): void;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { RelayBytes } from '../common/relay-bytes.js';
|
|
2
|
+
import { RelayCipher } from '../common/relay-cipher.js';
|
|
3
|
+
import { RelayPairingUtil } from '../common/relay-pairing.js';
|
|
4
|
+
import { RELAY_HOST_PATH, RELAY_PROOF, RelayCloseCode } from '../common/relay-protocol.js';
|
|
5
|
+
const MAX_RECONNECT_DELAY_MS = 30000;
|
|
6
|
+
const HELLO_TIMEOUT_MS = 10000;
|
|
7
|
+
/** A device on a channel: the handshake, then its connection to ta serve. */
|
|
8
|
+
class RelayChannel {
|
|
9
|
+
constructor(id, host, options) {
|
|
10
|
+
this.id = id;
|
|
11
|
+
this.host = host;
|
|
12
|
+
this.options = options;
|
|
13
|
+
this.early = [];
|
|
14
|
+
this.timer = setTimeout(() => this.close(), HELLO_TIMEOUT_MS);
|
|
15
|
+
}
|
|
16
|
+
async receive(text) {
|
|
17
|
+
var _a;
|
|
18
|
+
if (!this.cipher) {
|
|
19
|
+
await this.hello(text);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
let data;
|
|
23
|
+
try {
|
|
24
|
+
data = await this.cipher.open(text);
|
|
25
|
+
}
|
|
26
|
+
catch (_b) {
|
|
27
|
+
this.close();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (((_a = this.local) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN) {
|
|
31
|
+
this.local.send(data);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
this.early.push(data);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** From the relay: the device is gone. */
|
|
38
|
+
closed() {
|
|
39
|
+
var _a;
|
|
40
|
+
clearTimeout(this.timer);
|
|
41
|
+
(_a = this.local) === null || _a === void 0 ? void 0 : _a.close();
|
|
42
|
+
}
|
|
43
|
+
async hello(text) {
|
|
44
|
+
let hello;
|
|
45
|
+
try {
|
|
46
|
+
hello = JSON.parse(text);
|
|
47
|
+
}
|
|
48
|
+
catch (_a) {
|
|
49
|
+
this.close();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const device = hello.t === 'hello' && hello.v === 1 ? this.options.store.device(hello.device) : undefined;
|
|
53
|
+
if (!device || typeof hello.nonce !== 'string') {
|
|
54
|
+
this.answer({ t: 'refused', reason: 'This device is not paired.' });
|
|
55
|
+
this.close();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
clearTimeout(this.timer);
|
|
59
|
+
const nonce = RelayBytes.random(16);
|
|
60
|
+
const cipher = await RelayCipher.derive(RelayBytes.fromBase64(device.key), RelayBytes.fromBase64(hello.nonce), nonce, 'host');
|
|
61
|
+
this.cipher = cipher;
|
|
62
|
+
this.answer({ t: 'ready', nonce: RelayBytes.toBase64(nonce), proof: await cipher.seal(RELAY_PROOF) });
|
|
63
|
+
this.connectLocal(cipher);
|
|
64
|
+
}
|
|
65
|
+
connectLocal(cipher) {
|
|
66
|
+
const local = new WebSocket(this.options.localUrl);
|
|
67
|
+
this.local = local;
|
|
68
|
+
local.onopen = () => {
|
|
69
|
+
for (const data of this.early.splice(0)) {
|
|
70
|
+
local.send(data);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
local.onmessage = message => {
|
|
74
|
+
cipher.seal(String(message.data)).then(frame => this.host.send({ t: 'data', ch: this.id, d: frame }));
|
|
75
|
+
};
|
|
76
|
+
local.onclose = () => this.close();
|
|
77
|
+
}
|
|
78
|
+
answer(welcome) {
|
|
79
|
+
this.host.send({ t: 'data', ch: this.id, d: JSON.stringify(welcome) });
|
|
80
|
+
}
|
|
81
|
+
close() {
|
|
82
|
+
clearTimeout(this.timer);
|
|
83
|
+
this.host.closeChannel(this.id);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* ta serve at the relay: one WebSocket out to it, over which the paired devices come in, each on a
|
|
88
|
+
* channel of its own. A device that knows its key gets a connection to ta serve; nothing else does, and
|
|
89
|
+
* the relay sees only what the two seal.
|
|
90
|
+
*/
|
|
91
|
+
export class RelayHost {
|
|
92
|
+
constructor(options) {
|
|
93
|
+
this.options = options;
|
|
94
|
+
this.stopped = false;
|
|
95
|
+
this.attempts = 0;
|
|
96
|
+
this.channels = new Map();
|
|
97
|
+
}
|
|
98
|
+
/** Whether the connection to the relay is open. */
|
|
99
|
+
get online() {
|
|
100
|
+
var _a;
|
|
101
|
+
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN;
|
|
102
|
+
}
|
|
103
|
+
/** Connects when relay.json has a relay and a device, and keeps connected; checks again on {@link refresh}. */
|
|
104
|
+
start() {
|
|
105
|
+
this.stopped = false;
|
|
106
|
+
this.refresh();
|
|
107
|
+
}
|
|
108
|
+
/** relay.json may have changed: connect if it now has devices, or leave if it has none. */
|
|
109
|
+
refresh() {
|
|
110
|
+
const { url, host, devices } = this.options.store.read();
|
|
111
|
+
const wanted = !this.stopped && url !== undefined && host !== undefined && devices.length > 0;
|
|
112
|
+
if (!wanted) {
|
|
113
|
+
this.disconnect();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const target = `${RelayPairingUtil.websocketUrl(url, RELAY_HOST_PATH + host.id)}?secret=${encodeURIComponent(host.secret)}`;
|
|
117
|
+
if (this.socket && this.target === target && this.socket.readyState <= WebSocket.OPEN) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
this.disconnect();
|
|
121
|
+
this.connect(target);
|
|
122
|
+
}
|
|
123
|
+
stop() {
|
|
124
|
+
this.stopped = true;
|
|
125
|
+
this.disconnect();
|
|
126
|
+
}
|
|
127
|
+
/** @internal */
|
|
128
|
+
send(message) {
|
|
129
|
+
var _a;
|
|
130
|
+
if (((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN) {
|
|
131
|
+
this.socket.send(JSON.stringify(message));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/** @internal */
|
|
135
|
+
closeChannel(id) {
|
|
136
|
+
const channel = this.channels.get(id);
|
|
137
|
+
if (channel) {
|
|
138
|
+
this.channels.delete(id);
|
|
139
|
+
channel.closed();
|
|
140
|
+
this.send({ t: 'close', ch: id });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
connect(target) {
|
|
144
|
+
const socket = new WebSocket(target);
|
|
145
|
+
this.socket = socket;
|
|
146
|
+
this.target = target;
|
|
147
|
+
socket.onopen = () => {
|
|
148
|
+
this.attempts = 0;
|
|
149
|
+
};
|
|
150
|
+
socket.onmessage = message => this.receive(String(message.data));
|
|
151
|
+
socket.onclose = event => {
|
|
152
|
+
if (this.socket !== socket) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
this.socket = undefined;
|
|
156
|
+
this.closeChannels();
|
|
157
|
+
// Another host has this id: trying again would not change that.
|
|
158
|
+
if (event.code !== RelayCloseCode.REFUSED && event.code !== RelayCloseCode.REPLACED) {
|
|
159
|
+
this.scheduleReconnect();
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
// A failed connection also closes it.
|
|
163
|
+
socket.onerror = () => undefined;
|
|
164
|
+
}
|
|
165
|
+
receive(text) {
|
|
166
|
+
var _a, _b;
|
|
167
|
+
let message;
|
|
168
|
+
try {
|
|
169
|
+
message = JSON.parse(text);
|
|
170
|
+
}
|
|
171
|
+
catch (_c) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (message.t === 'open') {
|
|
175
|
+
this.channels.set(message.ch, new RelayChannel(message.ch, this, this.options));
|
|
176
|
+
}
|
|
177
|
+
else if (message.t === 'data') {
|
|
178
|
+
void ((_a = this.channels.get(message.ch)) === null || _a === void 0 ? void 0 : _a.receive(message.d));
|
|
179
|
+
}
|
|
180
|
+
else if (message.t === 'close') {
|
|
181
|
+
(_b = this.channels.get(message.ch)) === null || _b === void 0 ? void 0 : _b.closed();
|
|
182
|
+
this.channels.delete(message.ch);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
scheduleReconnect() {
|
|
186
|
+
var _a;
|
|
187
|
+
if (this.stopped) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const delay = Math.min(((_a = this.options.reconnectDelayMs) !== null && _a !== void 0 ? _a : 500) * 2 ** this.attempts++, MAX_RECONNECT_DELAY_MS);
|
|
191
|
+
clearTimeout(this.timer);
|
|
192
|
+
this.timer = setTimeout(() => this.refresh(), delay);
|
|
193
|
+
}
|
|
194
|
+
disconnect() {
|
|
195
|
+
clearTimeout(this.timer);
|
|
196
|
+
const socket = this.socket;
|
|
197
|
+
this.socket = undefined;
|
|
198
|
+
this.closeChannels();
|
|
199
|
+
socket === null || socket === void 0 ? void 0 : socket.close();
|
|
200
|
+
}
|
|
201
|
+
closeChannels() {
|
|
202
|
+
for (const channel of this.channels.values()) {
|
|
203
|
+
channel.closed();
|
|
204
|
+
}
|
|
205
|
+
this.channels.clear();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=relay-host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relay-host.js","sourceRoot":"","sources":["../../src/node/relay-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,cAAc,EAA6D,MAAM,0BAA0B,CAAC;AAWnJ,MAAM,sBAAsB,GAAG,KAAK,CAAC;AACrC,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAE/B,6EAA6E;AAC7E,MAAM,YAAY;IAMd,YACa,EAAU,EACA,IAAe,EACf,OAAyB;QAFnC,OAAE,GAAF,EAAE,CAAQ;QACA,SAAI,GAAJ,IAAI,CAAW;QACf,YAAO,GAAP,OAAO,CAAkB;QAN7B,UAAK,GAAa,EAAE,CAAC;QACrB,UAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,CA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C,CAAC;QACzB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QACxB,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,EAAE,CAAC;IACpB,CAAC;IAES,aAAa;QACnB,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;YAC3C,OAAO,CAAC,MAAM,EAAE,CAAC;QACrB,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;CACJ"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type IncomingMessage, type Server } from 'node:http';
|
|
2
|
+
import type { Duplex } from 'node:stream';
|
|
3
|
+
import { WebSocketConnection } from '@celljs/rpc/lib/node/websocket/websocket-connection';
|
|
4
|
+
import { RelayRoom } from '../common/relay-room.js';
|
|
5
|
+
export interface RelayServerOptions {
|
|
6
|
+
host?: string;
|
|
7
|
+
port?: number;
|
|
8
|
+
}
|
|
9
|
+
interface Room {
|
|
10
|
+
secretHash: string;
|
|
11
|
+
host?: WebSocketConnection;
|
|
12
|
+
clients: Map<string, WebSocketConnection>;
|
|
13
|
+
relay: RelayRoom;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* `ta relay`: the relay on a machine of one's own, as the Cloudflare Worker is in the cloud. It forwards,
|
|
17
|
+
* and keeps the hash of each host's secret in memory, for as long as it runs.
|
|
18
|
+
*/
|
|
19
|
+
export declare class RelayServer {
|
|
20
|
+
protected readonly options: RelayServerOptions;
|
|
21
|
+
protected readonly rooms: Map<string, Room>;
|
|
22
|
+
protected server?: Server;
|
|
23
|
+
constructor(options?: RelayServerOptions);
|
|
24
|
+
listen(): Promise<string>;
|
|
25
|
+
close(): Promise<void>;
|
|
26
|
+
protected upgrade(request: IncomingMessage, socket: Duplex, head: Buffer): void;
|
|
27
|
+
/** The first host to come with an id keeps it, for as long as the relay runs. */
|
|
28
|
+
protected openHost(id: string, secret: string, connection: WebSocketConnection): void;
|
|
29
|
+
protected openClient(id: string, connection: WebSocketConnection): void;
|
|
30
|
+
protected createRoom(id: string, secretHash: string): Room;
|
|
31
|
+
protected static same(a: string, b: string): boolean;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { createHash, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { createServer } from 'node:http';
|
|
3
|
+
import { WebSocketConnection } from '@celljs/rpc/lib/node/websocket/websocket-connection';
|
|
4
|
+
import { RELAY_CONNECT_PATH, RELAY_HOST_PATH, RELAY_ID, RELAY_PAIR_PAGE, RELAY_PAIR_PATH, RelayCloseCode } from '../common/relay-protocol.js';
|
|
5
|
+
import { RelayRoom } from '../common/relay-room.js';
|
|
6
|
+
const WEBSOCKET = { maxPayload: 32 * 1024 * 1024, heartbeat: 30000 };
|
|
7
|
+
const peer = (connection) => ({ send: text => connection.send(text), close: (code, reason) => connection.close(code, reason) });
|
|
8
|
+
/**
|
|
9
|
+
* `ta relay`: the relay on a machine of one's own, as the Cloudflare Worker is in the cloud. It forwards,
|
|
10
|
+
* and keeps the hash of each host's secret in memory, for as long as it runs.
|
|
11
|
+
*/
|
|
12
|
+
export class RelayServer {
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
this.options = options;
|
|
15
|
+
this.rooms = new Map();
|
|
16
|
+
}
|
|
17
|
+
listen() {
|
|
18
|
+
const server = createServer((request, response) => {
|
|
19
|
+
var _a;
|
|
20
|
+
const page = ((_a = request.url) !== null && _a !== void 0 ? _a : '/').split(/[?#]/)[0] === RELAY_PAIR_PATH;
|
|
21
|
+
response.writeHead(200, { 'content-type': page ? 'text/html; charset=utf-8' : 'text/plain' });
|
|
22
|
+
response.end(page ? RELAY_PAIR_PAGE : 'Ta relay\n');
|
|
23
|
+
});
|
|
24
|
+
server.on('upgrade', (request, socket, head) => this.upgrade(request, socket, head));
|
|
25
|
+
this.server = server;
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
server.once('error', reject);
|
|
29
|
+
server.listen((_a = this.options.port) !== null && _a !== void 0 ? _a : 0, (_b = this.options.host) !== null && _b !== void 0 ? _b : '127.0.0.1', () => {
|
|
30
|
+
const { address, port } = server.address();
|
|
31
|
+
resolve(`http://${address.includes(':') ? `[${address}]` : address}:${port}`);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
close() {
|
|
36
|
+
var _a;
|
|
37
|
+
for (const room of this.rooms.values()) {
|
|
38
|
+
(_a = room.host) === null || _a === void 0 ? void 0 : _a.close(1001, 'The relay is stopping.');
|
|
39
|
+
for (const client of room.clients.values()) {
|
|
40
|
+
client.close(1001, 'The relay is stopping.');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
this.rooms.clear();
|
|
44
|
+
return new Promise(resolve => (this.server ? this.server.close(() => resolve()) : resolve()));
|
|
45
|
+
}
|
|
46
|
+
upgrade(request, socket, head) {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
const url = new URL((_a = request.url) !== null && _a !== void 0 ? _a : '/', 'http://relay');
|
|
49
|
+
const checked = WebSocketConnection.check(request);
|
|
50
|
+
if ('status' in checked) {
|
|
51
|
+
WebSocketConnection.refuse(socket, checked.status, checked.message);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const [path, id] = url.pathname.startsWith(RELAY_HOST_PATH)
|
|
55
|
+
? [RELAY_HOST_PATH, url.pathname.slice(RELAY_HOST_PATH.length)]
|
|
56
|
+
: [RELAY_CONNECT_PATH, url.pathname.slice(RELAY_CONNECT_PATH.length)];
|
|
57
|
+
if (!url.pathname.startsWith(path) || !RELAY_ID.test(id)) {
|
|
58
|
+
WebSocketConnection.refuse(socket, 404, 'Not found.');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const connection = WebSocketConnection.open(socket, checked.key, head, WEBSOCKET);
|
|
62
|
+
if (path === RELAY_HOST_PATH) {
|
|
63
|
+
this.openHost(id, (_b = url.searchParams.get('secret')) !== null && _b !== void 0 ? _b : '', connection);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
this.openClient(id, connection);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** The first host to come with an id keeps it, for as long as the relay runs. */
|
|
70
|
+
openHost(id, secret, connection) {
|
|
71
|
+
var _a;
|
|
72
|
+
var _b;
|
|
73
|
+
const hash = createHash('sha256').update(secret).digest('base64url');
|
|
74
|
+
const room = (_b = this.rooms.get(id)) !== null && _b !== void 0 ? _b : this.createRoom(id, hash);
|
|
75
|
+
if (secret.length < 32 || !RelayServer.same(room.secretHash, hash)) {
|
|
76
|
+
connection.close(RelayCloseCode.REFUSED, 'Refused.');
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
(_a = room.host) === null || _a === void 0 ? void 0 : _a.close(RelayCloseCode.REPLACED, 'The host connected again.');
|
|
80
|
+
room.host = connection;
|
|
81
|
+
connection.onMessage(text => room.relay.fromHost(text));
|
|
82
|
+
connection.onClose(() => {
|
|
83
|
+
if (room.host === connection) {
|
|
84
|
+
room.host = undefined;
|
|
85
|
+
room.relay.hostClosed();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
openClient(id, connection) {
|
|
90
|
+
const room = this.rooms.get(id);
|
|
91
|
+
const channel = randomBytes(9).toString('base64url');
|
|
92
|
+
room === null || room === void 0 ? void 0 : room.clients.set(channel, connection);
|
|
93
|
+
const refused = room ? room.relay.clientOpened(channel) : RelayCloseCode.HOST_OFFLINE;
|
|
94
|
+
if (!room || refused !== undefined) {
|
|
95
|
+
room === null || room === void 0 ? void 0 : room.clients.delete(channel);
|
|
96
|
+
connection.close(refused !== null && refused !== void 0 ? refused : RelayCloseCode.HOST_OFFLINE, 'The host is not available.');
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
connection.onMessage(text => room.relay.fromClient(channel, text));
|
|
100
|
+
connection.onClose(() => {
|
|
101
|
+
if (room.clients.delete(channel)) {
|
|
102
|
+
room.relay.clientClosed(channel);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
createRoom(id, secretHash) {
|
|
107
|
+
const room = {
|
|
108
|
+
secretHash,
|
|
109
|
+
clients: new Map(),
|
|
110
|
+
relay: new RelayRoom({
|
|
111
|
+
host: () => (room.host ? peer(room.host) : undefined),
|
|
112
|
+
client: channel => {
|
|
113
|
+
const client = room.clients.get(channel);
|
|
114
|
+
return client ? peer(client) : undefined;
|
|
115
|
+
},
|
|
116
|
+
clients: () => [...room.clients.values()].map(peer),
|
|
117
|
+
}),
|
|
118
|
+
};
|
|
119
|
+
this.rooms.set(id, room);
|
|
120
|
+
return room;
|
|
121
|
+
}
|
|
122
|
+
static same(a, b) {
|
|
123
|
+
const [left, right] = [Buffer.from(a), Buffer.from(b)];
|
|
124
|
+
return left.length === right.length && timingSafeEqual(left, right);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=relay-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relay-server.js","sourceRoot":"","sources":["../../src/node/relay-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,YAAY,EAAqC,MAAM,WAAW,CAAC;AAG5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,qDAAqD,CAAC;AAC1F,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,QAAQ,EAAE,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC3I,OAAO,EAAkB,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAOjE,MAAM,SAAS,GAAG,EAAE,U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G,CAAC,OAAO,CAAC,CAAC;oBACzC,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;gBAC7C,CAAC;gBACD,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;aACtD,CAAC;SACL,CAAC;QACF,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IAChB,CAAC;IAES,MAAM,CAAC,IAAI,CAAC,CAAS,EAAE,CAAS;QACtC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACvD,OAAO,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,IAAI,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACxE,CAAC;CACJ"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { RelayPairing } from '../common/relay-pairing.js';
|
|
2
|
+
export interface RelayDevice {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
/** base64url, 32 bytes: what the device and ta serve encrypt with. */
|
|
6
|
+
key: string;
|
|
7
|
+
createdAt: number;
|
|
8
|
+
}
|
|
9
|
+
/** relay.json in the agent directory. Without devices, ta serve does not connect to the relay. */
|
|
10
|
+
export interface RelayConfig {
|
|
11
|
+
/** The relay, without a trailing slash. */
|
|
12
|
+
url?: string;
|
|
13
|
+
/** This ta serve at the relay: the id is public, the secret keeps another host from taking it. */
|
|
14
|
+
host?: {
|
|
15
|
+
id: string;
|
|
16
|
+
secret: string;
|
|
17
|
+
};
|
|
18
|
+
devices: RelayDevice[];
|
|
19
|
+
}
|
|
20
|
+
/** The devices paired with this ta serve. Read again on every use: `ta pair` changes it while ta serve runs. */
|
|
21
|
+
export declare class RelayStore {
|
|
22
|
+
protected readonly agentDir: string;
|
|
23
|
+
static readonly FILE = "relay.json";
|
|
24
|
+
constructor(agentDir: string);
|
|
25
|
+
get file(): string;
|
|
26
|
+
read(): RelayConfig;
|
|
27
|
+
device(deviceId: string): RelayDevice | undefined;
|
|
28
|
+
/** A new device for this relay; another relay than before unpairs the devices of the old one. */
|
|
29
|
+
pair(relay: string, deviceName: string): RelayPairing;
|
|
30
|
+
/** False when there was no such device. */
|
|
31
|
+
remove(deviceId: string): boolean;
|
|
32
|
+
/** What the relay keeps of the host's secret. */
|
|
33
|
+
static secretHash(secret: string): string;
|
|
34
|
+
protected write(config: RelayConfig): void;
|
|
35
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
+
import { chmodSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { hostname } from 'node:os';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
const id = () => randomBytes(16).toString('base64url');
|
|
6
|
+
/** The devices paired with this ta serve. Read again on every use: `ta pair` changes it while ta serve runs. */
|
|
7
|
+
export class RelayStore {
|
|
8
|
+
constructor(agentDir) {
|
|
9
|
+
this.agentDir = agentDir;
|
|
10
|
+
}
|
|
11
|
+
get file() {
|
|
12
|
+
return join(this.agentDir, RelayStore.FILE);
|
|
13
|
+
}
|
|
14
|
+
read() {
|
|
15
|
+
try {
|
|
16
|
+
const config = JSON.parse(readFileSync(this.file, 'utf8'));
|
|
17
|
+
return { url: config.url, host: config.host, devices: Array.isArray(config.devices) ? config.devices : [] };
|
|
18
|
+
}
|
|
19
|
+
catch (_a) {
|
|
20
|
+
return { devices: [] };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
device(deviceId) {
|
|
24
|
+
return this.read().devices.find(device => device.id === deviceId);
|
|
25
|
+
}
|
|
26
|
+
/** A new device for this relay; another relay than before unpairs the devices of the old one. */
|
|
27
|
+
pair(relay, deviceName) {
|
|
28
|
+
const url = relay.replace(/\/+$/, '');
|
|
29
|
+
const before = this.read();
|
|
30
|
+
const config = before.url === url && before.host ? before : { url, host: { id: id(), secret: randomBytes(32).toString('base64url') }, devices: [] };
|
|
31
|
+
const device = { id: id(), name: deviceName, key: randomBytes(32).toString('base64url'), createdAt: Date.now() };
|
|
32
|
+
config.devices.push(device);
|
|
33
|
+
this.write(config);
|
|
34
|
+
return { relay: url, host: config.host.id, device: device.id, key: device.key, name: hostname() };
|
|
35
|
+
}
|
|
36
|
+
/** False when there was no such device. */
|
|
37
|
+
remove(deviceId) {
|
|
38
|
+
const config = this.read();
|
|
39
|
+
const devices = config.devices.filter(device => device.id !== deviceId);
|
|
40
|
+
if (devices.length === config.devices.length) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
this.write({ ...config, devices });
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
/** What the relay keeps of the host's secret. */
|
|
47
|
+
static secretHash(secret) {
|
|
48
|
+
return createHash('sha256').update(secret).digest('base64url');
|
|
49
|
+
}
|
|
50
|
+
write(config) {
|
|
51
|
+
mkdirSync(dirname(this.file), { recursive: true });
|
|
52
|
+
const temporary = `${this.file}.${process.pid}.tmp`;
|
|
53
|
+
writeFileSync(temporary, `${JSON.stringify(config, null, 2)}\n`, { mode: 0o600 });
|
|
54
|
+
chmodSync(temporary, 0o600);
|
|
55
|
+
renameSync(temporary, this.file);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
RelayStore.FILE = 'relay.json';
|
|
59
|
+
//# sourceMappingURL=relay-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relay-store.js","sourceRoot":"","sources":["../../src/node/relay-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACt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CAAC;QACjB,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,iDAAiD;IACjD,MAAM,CAAC,UAAU,CAAC,MAAc;QAC5B,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IACnE,CAAC;IAES,KAAK,CAAC,MAAmB;QAC/B,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACnD,MAAM,SAAS,GAAG,GAAG,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,MAAM,CAAC;QACpD,aAAa,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAClF,SAAS,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAC5B,UAAU,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;CACJ;AAxDmB,eAAI,GAAG,YAAY,CAAC"}
|
package/esm/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./relay-bytes"), exports);
|
|
18
|
+
__exportStar(require("./relay-cipher"), exports);
|
|
19
|
+
__exportStar(require("./relay-pairing"), exports);
|
|
20
|
+
__exportStar(require("./relay-protocol"), exports);
|
|
21
|
+
__exportStar(require("./relay-room"), exports);
|
|
22
|
+
__exportStar(require("./relay-socket"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,iDAA+B;AAC/B,kDAAgC;AAChC,mDAAiC;AACjC,+CAA6B;AAC7B,iDAA+B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Bytes as text and back, in base64url, with what every platform has (no Buffer in a browser). */
|
|
2
|
+
export declare namespace RelayBytes {
|
|
3
|
+
function random(length: number): Uint8Array;
|
|
4
|
+
function toBase64(bytes: Uint8Array): string;
|
|
5
|
+
/** Throws on what is not base64url. */
|
|
6
|
+
function fromBase64(text: string): Uint8Array;
|
|
7
|
+
function concat(...parts: Uint8Array[]): Uint8Array;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=relay-bytes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relay-bytes.d.ts","sourceRoot":"","sources":["../../src/common/relay-bytes.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,yBAAiB,UAAU,CAAC;IACxB,SAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAEjD;IAED,SAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAMlD;IAED,uCAAuC;IACvC,SAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAUnD;IAED,SAAgB,MAAM,CAAC,GAAG,KAAK,EAAE,UAAU,EAAE,GAAG,UAAU,CAQzD;CACJ"}
|