@nervur.org/installer-node 0.0.0-stage → 0.37.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/LICENSE +105 -0
- package/README.md +158 -2
- package/SECURITY.md +8 -0
- package/bin/nervur.js +5 -0
- package/cargo/emscripten-module.wasm +0 -0
- package/cargo/manifest.json +1 -0
- package/cargo/sqlite3.wasm +0 -0
- package/cargo/table-i-i.wasm +0 -0
- package/cargo/table-i-ii.wasm +0 -0
- package/cargo/table-i-iii.wasm +0 -0
- package/cargo/table-i-iiii.wasm +0 -0
- package/cargo/table-i-iiiii.wasm +0 -0
- package/cargo/table-i-iiij.wasm +0 -0
- package/cargo/table-i-ij.wasm +0 -0
- package/cargo/table-v-ii.wasm +0 -0
- package/cargo/table-v-iii.wasm +0 -0
- package/cargo/worker.js +30756 -0
- package/organs/console/node/guard.d.ts +10 -0
- package/organs/console/node/guard.js +52 -0
- package/organs/console/node/index.d.ts +4 -0
- package/organs/console/node/index.js +5 -0
- package/organs/console/node/line.d.ts +16 -0
- package/organs/console/node/line.js +150 -0
- package/organs/console/node/main.js +51 -0
- package/organs/console/node/program.d.ts +1 -0
- package/organs/console/node/program.js +5 -0
- package/organs/console/node/proof.d.ts +15 -0
- package/organs/console/node/proof.js +84 -0
- package/organs/console/node/socket.d.ts +15 -0
- package/organs/console/node/socket.js +99 -0
- package/organs/disk/index.d.ts +1 -0
- package/organs/disk/index.js +2 -0
- package/organs/disk/node/files.js +162 -0
- package/organs/disk/node/main.js +20 -0
- package/organs/disk/node/program.d.ts +1 -0
- package/organs/disk/node/program.js +5 -0
- package/organs/disk/organ.d.ts +5 -0
- package/organs/disk/organ.js +69 -0
- package/organs/network/node/fill.d.ts +21 -0
- package/organs/network/node/fill.js +195 -0
- package/organs/network/node/flows.js +66 -0
- package/organs/network/node/half.js +260 -0
- package/organs/network/node/lines.d.ts +29 -0
- package/organs/network/node/lines.js +236 -0
- package/organs/network/node/link.d.ts +24 -0
- package/organs/network/node/link.js +215 -0
- package/organs/network/node/main.js +41 -0
- package/organs/network/node/moved.d.ts +2 -0
- package/organs/network/node/moved.js +20 -0
- package/organs/network/node/near.d.ts +63 -0
- package/organs/network/node/near.js +263 -0
- package/organs/network/node/program.d.ts +1 -0
- package/organs/network/node/program.js +5 -0
- package/organs/network/node/schemes.d.ts +1 -0
- package/organs/network/node/schemes.js +2 -0
- package/organs/network/node/sent.d.ts +13 -0
- package/organs/network/node/sent.js +101 -0
- package/organs/network/node/served.d.ts +19 -0
- package/organs/network/node/served.js +237 -0
- package/organs/screen/node/client.js +3 -0
- package/organs/screen/node/follow.js +266 -0
- package/organs/screen/node/frames.js +26 -0
- package/organs/screen/node/held.js +27 -0
- package/organs/screen/node/http.js +179 -0
- package/organs/screen/node/lay.js +116 -0
- package/organs/screen/node/leave.js +27 -0
- package/organs/screen/node/linked.js +69 -0
- package/organs/screen/node/listen.js +61 -0
- package/organs/screen/node/look.js +121 -0
- package/organs/screen/node/loop.js +154 -0
- package/organs/screen/node/main.js +74 -0
- package/organs/screen/node/mirror.js +112 -0
- package/organs/screen/node/notice.js +44 -0
- package/organs/screen/node/presser.js +11 -0
- package/organs/screen/node/presses.js +108 -0
- package/organs/screen/node/program.d.ts +1 -0
- package/organs/screen/node/program.js +5 -0
- package/organs/screen/node/shown.js +205 -0
- package/organs/screen/node/standing.js +29 -0
- package/organs/screen/node/state.js +80 -0
- package/organs/screen/node/tell.js +47 -0
- package/organs/screen/node/uid.js +65 -0
- package/organs/screen/node/worn.js +23 -0
- package/organs/shell/index.d.ts +1 -0
- package/organs/shell/index.js +2 -0
- package/organs/shell/node/main.js +26 -0
- package/organs/shell/node/output.js +70 -0
- package/organs/shell/node/pressure.js +14 -0
- package/organs/shell/node/program.d.ts +1 -0
- package/organs/shell/node/program.js +5 -0
- package/organs/shell/node/runs.js +220 -0
- package/organs/shell/node/told.js +70 -0
- package/organs/shell/organ.d.ts +5 -0
- package/organs/shell/organ.js +59 -0
- package/package.json +43 -4
- package/src/command/act.d.ts +31 -0
- package/src/command/act.js +256 -0
- package/src/command/answers.d.ts +3 -0
- package/src/command/answers.js +232 -0
- package/src/command/args.d.ts +14 -0
- package/src/command/args.js +220 -0
- package/src/command/arrive.d.ts +2 -0
- package/src/command/arrive.js +21 -0
- package/src/command/asked.d.ts +18 -0
- package/src/command/asked.js +49 -0
- package/src/command/backup.d.ts +18 -0
- package/src/command/backup.js +261 -0
- package/src/command/before.d.ts +41 -0
- package/src/command/before.js +237 -0
- package/src/command/born.d.ts +27 -0
- package/src/command/born.js +103 -0
- package/src/command/bridge.d.ts +19 -0
- package/src/command/bridge.js +152 -0
- package/src/command/chain.d.ts +9 -0
- package/src/command/chain.js +48 -0
- package/src/command/channel.d.ts +29 -0
- package/src/command/channel.js +263 -0
- package/src/command/choices.d.ts +35 -0
- package/src/command/choices.js +173 -0
- package/src/command/claim.d.ts +12 -0
- package/src/command/claim.js +46 -0
- package/src/command/commands.d.ts +16 -0
- package/src/command/commands.js +257 -0
- package/src/command/ends.d.ts +16 -0
- package/src/command/ends.js +78 -0
- package/src/command/follow.d.ts +12 -0
- package/src/command/follow.js +66 -0
- package/src/command/given.d.ts +39 -0
- package/src/command/given.js +53 -0
- package/src/command/held.d.ts +15 -0
- package/src/command/held.js +56 -0
- package/src/command/index.d.ts +1 -0
- package/src/command/index.js +203 -0
- package/src/command/jailer.d.ts +28 -0
- package/src/command/jailer.js +135 -0
- package/src/command/laid.d.ts +6 -0
- package/src/command/laid.js +31 -0
- package/src/command/left.d.ts +9 -0
- package/src/command/left.js +34 -0
- package/src/command/line.d.ts +7 -0
- package/src/command/line.js +39 -0
- package/src/command/link.d.ts +30 -0
- package/src/command/link.js +123 -0
- package/src/command/lobes.d.ts +1 -0
- package/src/command/lobes.js +10 -0
- package/src/command/locks.d.ts +17 -0
- package/src/command/locks.js +76 -0
- package/src/command/mcp/calls.d.ts +27 -0
- package/src/command/mcp/calls.js +155 -0
- package/src/command/mcp/notices.d.ts +22 -0
- package/src/command/mcp/notices.js +203 -0
- package/src/command/mcp/resources.d.ts +31 -0
- package/src/command/mcp/resources.js +108 -0
- package/src/command/mcp/server.d.ts +19 -0
- package/src/command/mcp/server.js +149 -0
- package/src/command/mcp/tools.d.ts +39 -0
- package/src/command/mcp/tools.js +131 -0
- package/src/command/mcp.d.ts +8 -0
- package/src/command/mcp.js +39 -0
- package/src/command/noticed.d.ts +11 -0
- package/src/command/noticed.js +55 -0
- package/src/command/older.d.ts +11 -0
- package/src/command/older.js +45 -0
- package/src/command/open.d.ts +24 -0
- package/src/command/open.js +107 -0
- package/src/command/passphrase.d.ts +6 -0
- package/src/command/passphrase.js +82 -0
- package/src/command/reclaim.d.ts +7 -0
- package/src/command/reclaim.js +47 -0
- package/src/command/refused.d.ts +4 -0
- package/src/command/refused.js +27 -0
- package/src/command/release.d.ts +27 -0
- package/src/command/release.js +153 -0
- package/src/command/repo.d.ts +31 -0
- package/src/command/repo.js +133 -0
- package/src/command/rewrap.d.ts +16 -0
- package/src/command/rewrap.js +175 -0
- package/src/command/runtime.d.ts +25 -0
- package/src/command/runtime.js +175 -0
- package/src/command/salvage.d.ts +4 -0
- package/src/command/salvage.js +42 -0
- package/src/command/screen.d.ts +14 -0
- package/src/command/screen.js +62 -0
- package/src/command/spawn.d.ts +23 -0
- package/src/command/spawn.js +213 -0
- package/src/command/start.d.ts +34 -0
- package/src/command/start.js +246 -0
- package/src/command/state.d.ts +5 -0
- package/src/command/state.js +39 -0
- package/src/command/token.d.ts +1 -0
- package/src/command/token.js +9 -0
- package/src/command/trial.d.ts +17 -0
- package/src/command/trial.js +92 -0
- package/src/command/vouch.d.ts +1 -0
- package/src/command/vouch.js +15 -0
- package/src/command/windows-processes.d.ts +2 -0
- package/src/command/windows-processes.js +22 -0
- package/src/command/wipe.d.ts +9 -0
- package/src/command/wipe.js +105 -0
- package/src/command/words.d.ts +5 -0
- package/src/command/words.js +53 -0
- package/src/door/claim.d.ts +5 -0
- package/src/door/claim.js +21 -0
- package/src/door/claimed.d.ts +7 -0
- package/src/door/claimed.js +110 -0
- package/src/door/configuration.d.ts +40 -0
- package/src/door/configuration.js +206 -0
- package/src/door/design.d.ts +13 -0
- package/src/door/design.js +71 -0
- package/src/door/digests.d.ts +7 -0
- package/src/door/digests.js +36 -0
- package/src/door/distribution.d.ts +25 -0
- package/src/door/distribution.js +88 -0
- package/src/door/door.d.ts +41 -0
- package/src/door/door.js +219 -0
- package/src/door/dressed.d.ts +34 -0
- package/src/door/dressed.js +182 -0
- package/src/door/faculties.d.ts +29 -0
- package/src/door/faculties.js +88 -0
- package/src/door/longest.d.ts +6 -0
- package/src/door/longest.js +25 -0
- package/src/fills/account-only.d.ts +3 -0
- package/src/fills/account-only.js +24 -0
- package/src/fills/boot-key.d.ts +21 -0
- package/src/fills/boot-key.js +70 -0
- package/src/fills/boot-move.d.ts +25 -0
- package/src/fills/boot-move.js +86 -0
- package/src/fills/bridge.d.ts +13 -0
- package/src/fills/bridge.js +86 -0
- package/src/fills/chance.d.ts +2 -0
- package/src/fills/chance.js +7 -0
- package/src/fills/crypto.d.ts +2 -0
- package/src/fills/crypto.js +94 -0
- package/src/fills/flushed.d.ts +9 -0
- package/src/fills/flushed.js +80 -0
- package/src/fills/hardware.d.ts +18 -0
- package/src/fills/hardware.js +70 -0
- package/src/fills/held.d.ts +31 -0
- package/src/fills/held.js +171 -0
- package/src/fills/keepers.d.ts +23 -0
- package/src/fills/keepers.js +151 -0
- package/src/fills/keyring.d.ts +19 -0
- package/src/fills/keyring.js +131 -0
- package/src/fills/pages.d.ts +3 -0
- package/src/fills/pages.js +260 -0
- package/src/fills/reserve.d.ts +11 -0
- package/src/fills/reserve.js +72 -0
- package/src/fills/time.d.ts +2 -0
- package/src/fills/time.js +29 -0
- package/src/fills/unlocker.d.ts +6 -0
- package/src/fills/unlocker.js +26 -0
- package/src/fills/vitals.d.ts +8 -0
- package/src/fills/vitals.js +100 -0
- package/src/fills/windows-start.d.ts +2 -0
- package/src/fills/windows-start.js +21 -0
- package/src/halves/build.d.ts +10 -0
- package/src/halves/build.js +219 -0
- package/src/halves/end.d.ts +17 -0
- package/src/halves/end.js +157 -0
- package/src/halves/genome.d.ts +3 -0
- package/src/halves/genome.js +21 -0
- package/src/halves/handler.d.ts +8 -0
- package/src/halves/handler.js +40 -0
- package/src/halves/index.d.ts +5 -0
- package/src/halves/index.js +6 -0
- package/src/halves/laid.d.ts +12 -0
- package/src/halves/laid.js +103 -0
- package/src/halves/lent.d.ts +6 -0
- package/src/halves/lent.js +147 -0
- package/src/halves/native.d.ts +12 -0
- package/src/halves/native.js +53 -0
- package/src/halves/statements.d.ts +23 -0
- package/src/halves/statements.js +165 -0
- package/src/halves/tokens.d.ts +22 -0
- package/src/halves/tokens.js +135 -0
- package/src/link/link.d.ts +4 -0
- package/src/link/link.js +4 -0
- package/src/link/placeholder.d.ts +1 -0
- package/src/link/placeholder.js +21 -0
- package/src/link/steps.d.ts +52 -0
- package/src/link/steps.js +118 -0
- package/src/lobes/calls.d.ts +76 -0
- package/src/lobes/calls.js +61 -0
- package/src/lobes/channel.d.ts +76 -0
- package/src/lobes/channel.js +202 -0
- package/src/lobes/index.d.ts +1 -0
- package/src/lobes/index.js +2 -0
- package/src/lobes/lobes.d.ts +15 -0
- package/src/lobes/lobes.js +244 -0
- package/src/lobes/main.js +107 -0
- package/src/lobes/thread.d.ts +22 -0
- package/src/lobes/thread.js +270 -0
- package/src/organism/act.d.ts +8 -0
- package/src/organism/act.js +63 -0
- package/src/organism/beat.d.ts +5 -0
- package/src/organism/beat.js +45 -0
- package/src/organism/compiled.d.ts +2 -0
- package/src/organism/compiled.js +24 -0
- package/src/organism/folder.d.ts +88 -0
- package/src/organism/folder.js +259 -0
- package/src/organism/main.d.ts +1 -0
- package/src/organism/main.js +11 -0
- package/src/organism/organism.d.ts +1 -0
- package/src/organism/organism.js +219 -0
- package/src/organism/said.d.ts +12 -0
- package/src/organism/said.js +30 -0
- package/src/organism/told.d.ts +5 -0
- package/src/organism/told.js +110 -0
- package/src/organism/unlock.d.ts +8 -0
- package/src/organism/unlock.js +95 -0
- package/src/organism/upgrade.d.ts +24 -0
- package/src/organism/upgrade.js +145 -0
- package/src/organism/via.d.ts +7 -0
- package/src/organism/via.js +20 -0
- package/src/service/body.d.ts +8 -0
- package/src/service/body.js +34 -0
- package/src/service/handler.d.ts +20 -0
- package/src/service/handler.js +128 -0
- package/src/service/index.d.ts +4 -0
- package/src/service/index.js +16 -0
- package/src/service/manager.d.ts +18 -0
- package/src/service/manager.js +185 -0
- package/src/service/service.d.ts +24 -0
- package/src/service/service.js +200 -0
- package/src/service/swap.d.ts +12 -0
- package/src/service/swap.js +74 -0
- package/src/service/watchdog.d.ts +6 -0
- package/src/service/watchdog.js +31 -0
- package/src/tcp/crowd.d.ts +18 -0
- package/src/tcp/crowd.js +85 -0
- package/src/tcp/dial.d.ts +23 -0
- package/src/tcp/dial.js +102 -0
- package/src/tcp/frame.d.ts +23 -0
- package/src/tcp/frame.js +159 -0
- package/src/tcp/listen.d.ts +50 -0
- package/src/tcp/listen.js +207 -0
- package/src/tcp/source.d.ts +2 -0
- package/src/tcp/source.js +26 -0
- package/src/version/index.d.ts +1 -0
- package/src/version/index.js +2 -0
- package/src/version/version.d.ts +1 -0
- package/src/version/version.js +2 -0
- package/src/work/first.d.ts +11 -0
- package/src/work/first.js +91 -0
- package/src/work/index.d.ts +2 -0
- package/src/work/index.js +15 -0
- package/src/work/work.d.ts +20 -0
- package/src/work/work.js +136 -0
- package/src/ws/dial.d.ts +7 -0
- package/src/ws/dial.js +252 -0
- package/src/ws/dialing.d.ts +50 -0
- package/src/ws/dialing.js +72 -0
- package/src/ws/frame.d.ts +32 -0
- package/src/ws/frame.js +124 -0
- package/src/ws/handshake.d.ts +4 -0
- package/src/ws/handshake.js +27 -0
- package/src/ws/line.d.ts +45 -0
- package/src/ws/line.js +250 -0
- package/src/ws/listen.d.ts +42 -0
- package/src/ws/listen.js +272 -0
- package/src/ws/rfc6455.d.ts +18 -0
- package/src/ws/rfc6455.js +187 -0
package/src/ws/dial.js
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
3
|
+
import { request as httpRequest, } from 'node:http';
|
|
4
|
+
import { request as httpsRequest } from 'node:https';
|
|
5
|
+
import { Socket } from 'node:net';
|
|
6
|
+
import { BOX_SIZE, } from '@nervur.org/genome/seams';
|
|
7
|
+
import { addressOf, proofMessage, PROTOCOL, wardOf, } from './frame.js';
|
|
8
|
+
import { ask, BOUNDED_WHY, greet, lineOf, ping, REPLACED_WHY, replyOf, } from './line.js';
|
|
9
|
+
import { standing, PING, SILENT } from './dialing.js';
|
|
10
|
+
|
|
11
|
+
const GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
|
|
12
|
+
|
|
13
|
+
const down = (dialing , held , line , why = '') => {
|
|
14
|
+
if (held.line !== line) return;
|
|
15
|
+
if (held.pinger !== null) clearInterval(held.pinger);
|
|
16
|
+
held.pinger = null;
|
|
17
|
+
held.line = null;
|
|
18
|
+
held.challenge = null;
|
|
19
|
+
held.request = null;
|
|
20
|
+
held.up = false;
|
|
21
|
+
held.proved = false;
|
|
22
|
+
if (held.letGo !== null) clearTimeout(held.letGo);
|
|
23
|
+
held.letGo = null;
|
|
24
|
+
const newest = dialing.lines.get(held.address) ?? held;
|
|
25
|
+
newest.older = newest.older.filter((one) => one !== held);
|
|
26
|
+
if (newest.told && standing(newest) === null) {
|
|
27
|
+
newest.told = false;
|
|
28
|
+
dialing.held(held.address, false);
|
|
29
|
+
}
|
|
30
|
+
if (!held.open) return;
|
|
31
|
+
const { last } = dialing.settings;
|
|
32
|
+
if (why === REPLACED_WHY) held.wait = last;
|
|
33
|
+
const delay = held.wait * (0.5 + Math.random());
|
|
34
|
+
held.wait = Math.min(held.wait * 2, last);
|
|
35
|
+
held.redial = setTimeout(() => {
|
|
36
|
+
held.redial = null;
|
|
37
|
+
if (held.open && held.line === null) dial(dialing, held);
|
|
38
|
+
}, delay);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const keep = (dialing , held , line ) => {
|
|
42
|
+
held.pinger = setInterval(() => {
|
|
43
|
+
if (line.silent >= SILENT) {
|
|
44
|
+
dialing.redialed += 1;
|
|
45
|
+
dialing.counted();
|
|
46
|
+
line.socket.destroy();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
ping(line);
|
|
50
|
+
}, held.ping);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const upgraded = (
|
|
54
|
+
dialing ,
|
|
55
|
+
held ,
|
|
56
|
+
key ,
|
|
57
|
+
response ,
|
|
58
|
+
socket ,
|
|
59
|
+
head ,
|
|
60
|
+
) => {
|
|
61
|
+
const accepted = createHash('sha1')
|
|
62
|
+
.update(key + GUID)
|
|
63
|
+
.digest('base64');
|
|
64
|
+
if (
|
|
65
|
+
!held.open ||
|
|
66
|
+
response.headers['sec-websocket-accept'] !== accepted ||
|
|
67
|
+
response.headers['sec-websocket-protocol'] !== PROTOCOL
|
|
68
|
+
) {
|
|
69
|
+
socket.destroy();
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
socket.setNoDelay(true);
|
|
73
|
+
socket.setTimeout(0);
|
|
74
|
+
const line = lineOf(
|
|
75
|
+
socket,
|
|
76
|
+
true,
|
|
77
|
+
dialing.exchanges,
|
|
78
|
+
dialing.arrived,
|
|
79
|
+
new Uint8Array(0),
|
|
80
|
+
(closed, why) => {
|
|
81
|
+
if (!held.up && held.line === closed) dialing.missed(held.address, why === BOUNDED_WHY);
|
|
82
|
+
down(dialing, held, closed, why);
|
|
83
|
+
},
|
|
84
|
+
(greeted, greeting) => {
|
|
85
|
+
upOn(dialing, held, greeted);
|
|
86
|
+
challengedOn(dialing, held, greeted, greeting);
|
|
87
|
+
},
|
|
88
|
+
);
|
|
89
|
+
held.line = line;
|
|
90
|
+
held.request = null;
|
|
91
|
+
keep(dialing, held, line);
|
|
92
|
+
if (head.length > 0) socket.unshift(head);
|
|
93
|
+
return true;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const upOn = (dialing , held , line ) => {
|
|
97
|
+
if (held.up || held.line !== line) return;
|
|
98
|
+
held.up = true;
|
|
99
|
+
held.told = true;
|
|
100
|
+
held.wait = dialing.settings.first;
|
|
101
|
+
dialing.held(held.address, true);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const challengedOn = (dialing , held , line , greeting ) => {
|
|
105
|
+
if (greeting.kind !== 'challenge' || held.challenge?.line === line || held.wards.length === 0) return;
|
|
106
|
+
held.challenge = { line, challenge: greeting.challenge };
|
|
107
|
+
dialing.challenged(held.address, greeting.challenge);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const dial = (dialing , held ) => {
|
|
111
|
+
const url = addressOf(held.address);
|
|
112
|
+
if (url === null) return;
|
|
113
|
+
const secure = url.protocol === 'wss:';
|
|
114
|
+
const key = randomBytes(16).toString('base64');
|
|
115
|
+
const request = (secure ? httpsRequest : httpRequest)({
|
|
116
|
+
hostname: url.hostname.replace(/^\[|\]$/g, ''),
|
|
117
|
+
port: url.port === '' ? (secure ? 443 : 80) : Number(url.port),
|
|
118
|
+
path: `${url.pathname}${url.search}`,
|
|
119
|
+
headers: {
|
|
120
|
+
Connection: 'Upgrade',
|
|
121
|
+
Upgrade: 'websocket',
|
|
122
|
+
'Sec-WebSocket-Version': '13',
|
|
123
|
+
'Sec-WebSocket-Key': key,
|
|
124
|
+
'Sec-WebSocket-Protocol': PROTOCOL,
|
|
125
|
+
},
|
|
126
|
+
timeout: 10_000,
|
|
127
|
+
});
|
|
128
|
+
held.request = request;
|
|
129
|
+
let over = false;
|
|
130
|
+
const failed = () => {
|
|
131
|
+
if (over) return;
|
|
132
|
+
over = true;
|
|
133
|
+
request.destroy();
|
|
134
|
+
if (held.request !== request) return;
|
|
135
|
+
dialing.missed(held.address, false);
|
|
136
|
+
down(dialing, held, null);
|
|
137
|
+
};
|
|
138
|
+
request.on('timeout', () => failed());
|
|
139
|
+
request.on('error', () => failed());
|
|
140
|
+
request.on('response', (response) => {
|
|
141
|
+
response.resume();
|
|
142
|
+
failed();
|
|
143
|
+
});
|
|
144
|
+
request.on('upgrade', (response, socket, head) => {
|
|
145
|
+
if (over || !(socket instanceof Socket) || !upgraded(dialing, held, key, response, socket, head)) failed();
|
|
146
|
+
else over = true;
|
|
147
|
+
});
|
|
148
|
+
request.end();
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const stop = (held ) => {
|
|
152
|
+
held.open = false;
|
|
153
|
+
if (held.redial !== null) clearTimeout(held.redial);
|
|
154
|
+
held.redial = null;
|
|
155
|
+
held.request?.destroy();
|
|
156
|
+
if (held.letGo !== null) clearTimeout(held.letGo);
|
|
157
|
+
held.letGo = null;
|
|
158
|
+
held.line?.socket.destroy();
|
|
159
|
+
for (const older of held.older) stop(older);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const replacedBy = (before ) => {
|
|
163
|
+
before.open = false;
|
|
164
|
+
if (before.redial !== null) clearTimeout(before.redial);
|
|
165
|
+
before.redial = null;
|
|
166
|
+
before.request?.destroy();
|
|
167
|
+
if (before.letGo !== null) clearTimeout(before.letGo);
|
|
168
|
+
before.letGo = null;
|
|
169
|
+
const older = before.older;
|
|
170
|
+
before.older = [];
|
|
171
|
+
if (!before.proved) {
|
|
172
|
+
before.line?.socket.destroy();
|
|
173
|
+
return older;
|
|
174
|
+
}
|
|
175
|
+
before.told = false;
|
|
176
|
+
return [...older, before];
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const same = (held , wards , pinged ) =>
|
|
180
|
+
held.ping === pinged && held.wards.length === wards.length && held.wards.every((ward, at) => ward === wards[at]);
|
|
181
|
+
|
|
182
|
+
export const holdOf =
|
|
183
|
+
(dialing ) =>
|
|
184
|
+
(lines ) => {
|
|
185
|
+
const refused = lines.filter((one) => addressOf(one.address) === null).map((one) => one.address);
|
|
186
|
+
const wanted = new Map(lines.filter((one) => !refused.includes(one.address)).map((one) => [one.address, one]));
|
|
187
|
+
for (const [address, held] of dialing.lines) {
|
|
188
|
+
if (wanted.has(address)) continue;
|
|
189
|
+
stop(held);
|
|
190
|
+
dialing.lines.delete(address);
|
|
191
|
+
}
|
|
192
|
+
for (const [address, one] of wanted) {
|
|
193
|
+
const wards = [...new Set(one.wards)];
|
|
194
|
+
const pinged = one.ping ?? PING;
|
|
195
|
+
const before = dialing.lines.get(address);
|
|
196
|
+
if (before !== undefined && same(before, wards, pinged)) continue;
|
|
197
|
+
const held = {
|
|
198
|
+
address,
|
|
199
|
+
wards,
|
|
200
|
+
challenge: null,
|
|
201
|
+
ping: pinged,
|
|
202
|
+
open: true,
|
|
203
|
+
up: false,
|
|
204
|
+
proved: false,
|
|
205
|
+
told: before?.told ?? false,
|
|
206
|
+
older: before === undefined ? [] : replacedBy(before),
|
|
207
|
+
letGo: null,
|
|
208
|
+
line: null,
|
|
209
|
+
request: null,
|
|
210
|
+
wait: dialing.settings.first,
|
|
211
|
+
redial: null,
|
|
212
|
+
pinger: null,
|
|
213
|
+
};
|
|
214
|
+
dialing.lines.set(address, held);
|
|
215
|
+
dial(dialing, held);
|
|
216
|
+
}
|
|
217
|
+
return refused;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
export const provedOf =
|
|
221
|
+
(dialing ) =>
|
|
222
|
+
(address , nonce , proven ) => {
|
|
223
|
+
const held = dialing.lines.get(address);
|
|
224
|
+
const asked = held?.challenge;
|
|
225
|
+
if (held === undefined || asked == null || asked.line.socket.destroyed) return;
|
|
226
|
+
const sent = asked.challenge.nonce;
|
|
227
|
+
if (sent.length !== nonce.length || !sent.every((byte, at) => byte === nonce[at])) return;
|
|
228
|
+
const named = proven.filter(({ ward }) => held.wards.includes(ward));
|
|
229
|
+
const message = proofMessage(named);
|
|
230
|
+
if (message === null) return;
|
|
231
|
+
greet(asked.line, message);
|
|
232
|
+
held.proved = named.length > 0;
|
|
233
|
+
if (!held.proved || held.older.length === 0) return;
|
|
234
|
+
held.letGo = setTimeout(() => {
|
|
235
|
+
held.letGo = null;
|
|
236
|
+
for (const older of held.older) older.line?.socket.destroy();
|
|
237
|
+
}, dialing.settings.wait);
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
export const replyOn = (dialing ) => replyOf(dialing.exchanges);
|
|
241
|
+
|
|
242
|
+
export const sendOf =
|
|
243
|
+
(dialing ) =>
|
|
244
|
+
(address , bytes , wait , wardText ) => {
|
|
245
|
+
const held = dialing.lines.get(address);
|
|
246
|
+
const ward = wardOf(wardText);
|
|
247
|
+
const line = held === undefined ? null : standing(held);
|
|
248
|
+
if (line === null) return Promise.resolve({ why: `no line to ${address} is up` });
|
|
249
|
+
if (ward === null) return Promise.resolve({ why: 'an ask over a line names its ward, 128 hex' });
|
|
250
|
+
if (bytes.length > BOX_SIZE) return Promise.resolve({ why: `${bytes.length} bytes is more than a box holds` });
|
|
251
|
+
return ask(line, ward, bytes, wait);
|
|
252
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Challenge, Exchange } from '@nervur.org/genome/seams';
|
|
2
|
+
import { type Exchanges, type Line } from './line.js';
|
|
3
|
+
import type { ClientRequest } from 'node:http';
|
|
4
|
+
export type Wanted = {
|
|
5
|
+
readonly address: string;
|
|
6
|
+
readonly wards: readonly string[];
|
|
7
|
+
readonly ping?: number;
|
|
8
|
+
};
|
|
9
|
+
export type Settings = {
|
|
10
|
+
readonly first: number;
|
|
11
|
+
readonly last: number;
|
|
12
|
+
readonly flight: number;
|
|
13
|
+
readonly wait: number;
|
|
14
|
+
};
|
|
15
|
+
export declare const SETTINGS: Settings;
|
|
16
|
+
export declare const PING = 25000;
|
|
17
|
+
export declare const SILENT = 2;
|
|
18
|
+
export type Held = {
|
|
19
|
+
readonly address: string;
|
|
20
|
+
readonly wards: readonly string[];
|
|
21
|
+
challenge: {
|
|
22
|
+
readonly line: Line;
|
|
23
|
+
readonly challenge: Challenge;
|
|
24
|
+
} | null;
|
|
25
|
+
readonly ping: number;
|
|
26
|
+
open: boolean;
|
|
27
|
+
up: boolean;
|
|
28
|
+
proved: boolean;
|
|
29
|
+
told: boolean;
|
|
30
|
+
older: Held[];
|
|
31
|
+
letGo: ReturnType<typeof setTimeout> | null;
|
|
32
|
+
line: Line | null;
|
|
33
|
+
request: ClientRequest | null;
|
|
34
|
+
wait: number;
|
|
35
|
+
redial: ReturnType<typeof setTimeout> | null;
|
|
36
|
+
pinger: ReturnType<typeof setInterval> | null;
|
|
37
|
+
};
|
|
38
|
+
export type Dialing = {
|
|
39
|
+
readonly lines: Map<string, Held>;
|
|
40
|
+
readonly exchanges: Exchanges;
|
|
41
|
+
readonly settings: Settings;
|
|
42
|
+
redialed: number;
|
|
43
|
+
readonly arrived: (exchange: Exchange, bytes: Uint8Array, ward: string) => void;
|
|
44
|
+
readonly held: (address: string, up: boolean) => void;
|
|
45
|
+
readonly counted: () => void;
|
|
46
|
+
readonly missed: (address: string, bounded: boolean) => void;
|
|
47
|
+
readonly challenged: (address: string, challenge: Challenge) => void;
|
|
48
|
+
};
|
|
49
|
+
export declare const dialingOf: (arrived: Dialing['arrived'], held: Dialing['held'], challenged: Dialing['challenged'], counted?: () => void, settings?: Settings, missed?: Dialing['missed']) => Dialing;
|
|
50
|
+
export declare const standing: (held: Held) => Line | null;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
|
|
3
|
+
import { BOUNDS } from '../tcp/listen.js';
|
|
4
|
+
import { exchangesOf, } from './line.js';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export const SETTINGS = { first: 1000, last: 60_000, flight: BOUNDS.flight, wait: BOUNDS.wait };
|
|
17
|
+
export const PING = 25_000;
|
|
18
|
+
export const SILENT = 2;
|
|
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
|
+
export const dialingOf = (
|
|
53
|
+
arrived ,
|
|
54
|
+
held ,
|
|
55
|
+
challenged ,
|
|
56
|
+
counted = () => undefined,
|
|
57
|
+
settings = SETTINGS,
|
|
58
|
+
missed = () => undefined,
|
|
59
|
+
) => ({
|
|
60
|
+
lines: new Map(),
|
|
61
|
+
exchanges: exchangesOf(settings.flight, settings.wait, counted),
|
|
62
|
+
settings,
|
|
63
|
+
redialed: 0,
|
|
64
|
+
arrived,
|
|
65
|
+
held,
|
|
66
|
+
counted,
|
|
67
|
+
missed,
|
|
68
|
+
challenged,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
export const standing = (held ) =>
|
|
72
|
+
held.up ? held.line : (held.older.findLast(({ up }) => up)?.line ?? null);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Challenge, type CryptoSeam, type Proven } from '@nervur.org/genome/seams';
|
|
2
|
+
import { type Frame } from '../tcp/frame.js';
|
|
3
|
+
export declare const PROTOCOL = "quo";
|
|
4
|
+
export declare const BOUNDED = 1013;
|
|
5
|
+
export declare const LARGEST: number;
|
|
6
|
+
export declare const messageOf: (frame: Frame) => Uint8Array;
|
|
7
|
+
export declare const frameOfMessage: (message: Uint8Array) => Frame | null;
|
|
8
|
+
export declare const wardOf: (ward: string | undefined) => Uint8Array | null;
|
|
9
|
+
export declare const MOST_PROVEN: number;
|
|
10
|
+
export type Greeting = {
|
|
11
|
+
readonly kind: 'challenge';
|
|
12
|
+
readonly challenge: Challenge;
|
|
13
|
+
} | {
|
|
14
|
+
readonly kind: 'proof';
|
|
15
|
+
readonly proven: readonly Proven[];
|
|
16
|
+
} | {
|
|
17
|
+
readonly kind: 'beat';
|
|
18
|
+
readonly span: number;
|
|
19
|
+
} | {
|
|
20
|
+
readonly kind: 'echo';
|
|
21
|
+
readonly span: number;
|
|
22
|
+
};
|
|
23
|
+
export declare const isGreeting: (message: Uint8Array) => boolean;
|
|
24
|
+
export declare const beatMessage: (span: number) => Uint8Array;
|
|
25
|
+
export declare const ECHO_ASKED = "nervur-beat";
|
|
26
|
+
export declare const ECHO_ANSWER = "nervur-beat-back";
|
|
27
|
+
export declare const echoMessage: (span: number) => Uint8Array;
|
|
28
|
+
export declare const challengeMessage: ({ nonce, identity }: Challenge) => Uint8Array;
|
|
29
|
+
export declare const proofMessage: (proven: readonly Proven[]) => Uint8Array | null;
|
|
30
|
+
export declare const greetingOf: (message: Uint8Array) => Greeting | null;
|
|
31
|
+
export declare const provenOf: (crypto: Pick<CryptoSeam, 'ed25519Verify'>, challenge: Challenge, proven: readonly Proven[]) => readonly string[];
|
|
32
|
+
export declare const addressOf: (address: string) => URL | null;
|
package/src/ws/frame.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import {
|
|
3
|
+
BOX_SIZE,
|
|
4
|
+
CHALLENGE_BYTES,
|
|
5
|
+
lineProven,
|
|
6
|
+
PROOF_BYTES,
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
} from '@nervur.org/genome/seams';
|
|
11
|
+
import { hex, unhex } from '@nervur.org/genome/standard';
|
|
12
|
+
import { bodyOf, frameOf, WARD, } from '../tcp/frame.js';
|
|
13
|
+
|
|
14
|
+
export const PROTOCOL = 'quo';
|
|
15
|
+
|
|
16
|
+
export const BOUNDED = 1013;
|
|
17
|
+
|
|
18
|
+
const HEAD = 5;
|
|
19
|
+
export const LARGEST = HEAD + WARD + BOX_SIZE;
|
|
20
|
+
|
|
21
|
+
export const messageOf = (frame ) => frameOf(frame).subarray(4);
|
|
22
|
+
|
|
23
|
+
export const frameOfMessage = (message ) =>
|
|
24
|
+
message.length < HEAD || message.length > LARGEST + 1 ? null : bodyOf(message, message.length > LARGEST);
|
|
25
|
+
|
|
26
|
+
const HEX = /^[0-9a-f]{128}$/;
|
|
27
|
+
|
|
28
|
+
export const wardOf = (ward ) => {
|
|
29
|
+
const read = ward === undefined || !HEX.test(ward) ? null : unhex(ward);
|
|
30
|
+
return read === null || 'why' in read ? null : read.bytes;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const CHALLENGE = 3;
|
|
34
|
+
const PROOF = 4;
|
|
35
|
+
const BEAT = 5;
|
|
36
|
+
const ECHO = 6;
|
|
37
|
+
const BEAT_BYTES = 5;
|
|
38
|
+
const PAIR = WARD + PROOF_BYTES;
|
|
39
|
+
|
|
40
|
+
export const MOST_PROVEN = Math.floor((LARGEST - 1) / PAIR);
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
export const isGreeting = (message ) =>
|
|
49
|
+
message[0] === CHALLENGE || message[0] === PROOF || message[0] === BEAT || message[0] === ECHO;
|
|
50
|
+
|
|
51
|
+
export const beatMessage = (span ) => {
|
|
52
|
+
const bytes = new Uint8Array(BEAT_BYTES);
|
|
53
|
+
bytes[0] = BEAT;
|
|
54
|
+
new DataView(bytes.buffer).setUint32(1, span);
|
|
55
|
+
return bytes;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const ECHO_ASKED = 'nervur-beat';
|
|
59
|
+
export const ECHO_ANSWER = 'nervur-beat-back';
|
|
60
|
+
|
|
61
|
+
export const echoMessage = (span ) => {
|
|
62
|
+
const bytes = beatMessage(span);
|
|
63
|
+
bytes[0] = ECHO;
|
|
64
|
+
return bytes;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const challengeMessage = ({ nonce, identity } ) => {
|
|
68
|
+
const bytes = new Uint8Array(1 + 2 * CHALLENGE_BYTES);
|
|
69
|
+
bytes[0] = CHALLENGE;
|
|
70
|
+
bytes.set(nonce, 1);
|
|
71
|
+
bytes.set(identity, 1 + CHALLENGE_BYTES);
|
|
72
|
+
return bytes;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const proofMessage = (proven ) => {
|
|
76
|
+
if (proven.length > MOST_PROVEN) return null;
|
|
77
|
+
const bytes = new Uint8Array(1 + proven.length * PAIR);
|
|
78
|
+
bytes[0] = PROOF;
|
|
79
|
+
for (const [at, { ward, proof }] of proven.entries()) {
|
|
80
|
+
const key = wardOf(ward);
|
|
81
|
+
if (key === null || proof.length !== PROOF_BYTES) return null;
|
|
82
|
+
bytes.set(key, 1 + at * PAIR);
|
|
83
|
+
bytes.set(proof, 1 + at * PAIR + WARD);
|
|
84
|
+
}
|
|
85
|
+
return bytes;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const greetingOf = (message ) => {
|
|
89
|
+
if ((message[0] === BEAT || message[0] === ECHO) && message.length === BEAT_BYTES)
|
|
90
|
+
return {
|
|
91
|
+
kind: message[0] === BEAT ? 'beat' : 'echo',
|
|
92
|
+
span: new DataView(message.buffer, message.byteOffset).getUint32(1),
|
|
93
|
+
};
|
|
94
|
+
if (message[0] === CHALLENGE && message.length === 1 + 2 * CHALLENGE_BYTES)
|
|
95
|
+
return {
|
|
96
|
+
kind: 'challenge',
|
|
97
|
+
challenge: { nonce: message.slice(1, 1 + CHALLENGE_BYTES), identity: message.slice(1 + CHALLENGE_BYTES) },
|
|
98
|
+
};
|
|
99
|
+
if (message[0] !== PROOF || (message.length - 1) % PAIR !== 0) return null;
|
|
100
|
+
const proven = [];
|
|
101
|
+
for (let at = 1; at < message.length; at += PAIR)
|
|
102
|
+
proven.push({ ward: hex(message.subarray(at, at + WARD)), proof: message.slice(at + WARD, at + PAIR) });
|
|
103
|
+
return { kind: 'proof', proven };
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const provenOf = (
|
|
107
|
+
crypto ,
|
|
108
|
+
challenge ,
|
|
109
|
+
proven ,
|
|
110
|
+
) => [
|
|
111
|
+
...new Set(proven.filter(({ ward, proof }) => lineProven(crypto, ward, challenge, proof)).map(({ ward }) => ward)),
|
|
112
|
+
];
|
|
113
|
+
|
|
114
|
+
export const addressOf = (address ) => {
|
|
115
|
+
if (!URL.canParse(address)) return null;
|
|
116
|
+
const url = new URL(address);
|
|
117
|
+
const ok =
|
|
118
|
+
(url.protocol === 'ws:' || url.protocol === 'wss:') &&
|
|
119
|
+
url.hostname !== '' &&
|
|
120
|
+
url.username === '' &&
|
|
121
|
+
url.password === '' &&
|
|
122
|
+
url.hash === '';
|
|
123
|
+
return ok && !address.includes('#') ? url : null;
|
|
124
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Socket } from 'node:net';
|
|
2
|
+
export declare const refused: (socket: Socket, status: string) => void;
|
|
3
|
+
export declare const switching: (key: string, protocol: string) => string;
|
|
4
|
+
export declare const putOut: (socket: Socket, key: string, protocol: string, code: number) => void;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
|
|
4
|
+
import { encode, GUID, OPCODE } from './rfc6455.js';
|
|
5
|
+
|
|
6
|
+
export const refused = (socket , status ) => {
|
|
7
|
+
socket.end(`HTTP/1.1 ${status}\r\nConnection: close\r\nContent-Length: 0\r\n\r\n`);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const switching = (key , protocol ) => {
|
|
11
|
+
const accept = createHash('sha1')
|
|
12
|
+
.update(key + GUID)
|
|
13
|
+
.digest('base64');
|
|
14
|
+
return `HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: ${accept}\r\nSec-WebSocket-Protocol: ${protocol}\r\n\r\n`;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const PUT_OUT_SPAN = 1000;
|
|
18
|
+
|
|
19
|
+
export const putOut = (socket , key , protocol , code ) => {
|
|
20
|
+
const payload = new Uint8Array(2);
|
|
21
|
+
new DataView(payload.buffer).setUint16(0, code);
|
|
22
|
+
const timer = setTimeout(() => socket.destroy(), PUT_OUT_SPAN);
|
|
23
|
+
socket.on('error', () => socket.destroy());
|
|
24
|
+
socket.on('close', () => clearTimeout(timer));
|
|
25
|
+
socket.resume();
|
|
26
|
+
socket.end(Buffer.concat([Buffer.from(switching(key, protocol), 'latin1'), encode(OPCODE.close, payload, false)]));
|
|
27
|
+
};
|
package/src/ws/line.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Socket } from 'node:net';
|
|
2
|
+
import { type Exchange } from '@nervur.org/genome/seams';
|
|
3
|
+
import { type Greeting } from './frame.js';
|
|
4
|
+
export type Answer = {
|
|
5
|
+
readonly reply: Uint8Array | null;
|
|
6
|
+
} | {
|
|
7
|
+
readonly why: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const REPLACED = 4000;
|
|
10
|
+
export declare const REPLACED_WHY = "replaced";
|
|
11
|
+
export declare const BOUNDED_WHY = "put out at a bound";
|
|
12
|
+
export type Line = {
|
|
13
|
+
readonly socket: Socket;
|
|
14
|
+
readonly masked: boolean;
|
|
15
|
+
readonly asks: Map<number, (answer: Answer) => void>;
|
|
16
|
+
readonly flight: Set<Exchange>;
|
|
17
|
+
ending: boolean;
|
|
18
|
+
next: number;
|
|
19
|
+
silent: number;
|
|
20
|
+
pinged: boolean;
|
|
21
|
+
};
|
|
22
|
+
type Held = {
|
|
23
|
+
readonly line: Line;
|
|
24
|
+
readonly id: number;
|
|
25
|
+
readonly timer: ReturnType<typeof setTimeout>;
|
|
26
|
+
};
|
|
27
|
+
export type Exchanges = {
|
|
28
|
+
readonly held: Map<Exchange, Held>;
|
|
29
|
+
flight: number;
|
|
30
|
+
wait: number;
|
|
31
|
+
next: Exchange;
|
|
32
|
+
unreplied: number;
|
|
33
|
+
readonly counted: () => void;
|
|
34
|
+
readonly quiet: (line: Line) => void;
|
|
35
|
+
};
|
|
36
|
+
export declare const exchangesOf: (flight: number, wait: number, counted?: () => void, quiet?: (line: Line) => void) => Exchanges;
|
|
37
|
+
export declare const lineOf: (socket: Socket, masked: boolean, exchanges: Exchanges, arrived: (exchange: Exchange, bytes: Uint8Array, ward: string) => void, head: Uint8Array, closed: (line: Line, why: string) => void, greeted: (line: Line, greeting: Greeting) => void) => Line;
|
|
38
|
+
export declare const replaced: (line: Line) => void;
|
|
39
|
+
export declare const ask: (line: Line, ward: Uint8Array, bytes: Uint8Array, wait: number) => Promise<Answer>;
|
|
40
|
+
export declare const replyOf: (exchanges: Exchanges) => (exchange: Exchange, bytes: Uint8Array | null) => void;
|
|
41
|
+
export declare const greet: (line: Line, message: Uint8Array) => void;
|
|
42
|
+
export declare const ping: (line: Line) => void;
|
|
43
|
+
export declare const BEATS = 24;
|
|
44
|
+
export declare const beatenOf: (line: Line, idle: number) => ReturnType<typeof setInterval>;
|
|
45
|
+
export {};
|