@fnndsc/calypso 0.29.15 → 0.30.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/dist/calypso.js +19 -8
- package/dist/calypso.js.map +1 -1
- package/dist/daemon/attachFile.d.ts +26 -19
- package/dist/daemon/attachFile.js +42 -51
- package/dist/daemon/attachFile.js.map +1 -1
- package/dist/daemon/attachOrigin.d.ts +69 -0
- package/dist/daemon/attachOrigin.js +125 -0
- package/dist/daemon/attachOrigin.js.map +1 -0
- package/dist/daemon/berth.d.ts +265 -26
- package/dist/daemon/berth.js +521 -158
- package/dist/daemon/berth.js.map +1 -1
- package/dist/daemon/claims.js +19 -9
- package/dist/daemon/claims.js.map +1 -1
- package/dist/daemon/commandLane.d.ts +317 -0
- package/dist/daemon/commandLane.js +409 -0
- package/dist/daemon/commandLane.js.map +1 -0
- package/dist/daemon/console.d.ts +0 -2
- package/dist/daemon/console.js +7 -10
- package/dist/daemon/console.js.map +1 -1
- package/dist/daemon/consoleSession.js +4 -1
- package/dist/daemon/consoleSession.js.map +1 -1
- package/dist/daemon/elevation.d.ts +0 -3
- package/dist/daemon/elevation.js +1 -3
- package/dist/daemon/elevation.js.map +1 -1
- package/dist/daemon/face.d.ts +18 -4
- package/dist/daemon/face.js +77 -32
- package/dist/daemon/face.js.map +1 -1
- package/dist/daemon/hostControl.d.ts +114 -1
- package/dist/daemon/hostControl.js +104 -4
- package/dist/daemon/hostControl.js.map +1 -1
- package/dist/daemon/hostPtyRelay.d.ts +118 -0
- package/dist/daemon/hostPtyRelay.js +186 -0
- package/dist/daemon/hostPtyRelay.js.map +1 -0
- package/dist/daemon/httpRoutes.d.ts +257 -0
- package/dist/daemon/httpRoutes.js +537 -0
- package/dist/daemon/httpRoutes.js.map +1 -0
- package/dist/daemon/instance.d.ts +37 -0
- package/dist/daemon/instance.js +59 -0
- package/dist/daemon/instance.js.map +1 -0
- package/dist/daemon/launch.d.ts +17 -0
- package/dist/daemon/launch.js +198 -194
- package/dist/daemon/launch.js.map +1 -1
- package/dist/daemon/launchBanner.d.ts +76 -0
- package/dist/daemon/launchBanner.js +80 -0
- package/dist/daemon/launchBanner.js.map +1 -0
- package/dist/daemon/rival.d.ts +65 -0
- package/dist/daemon/rival.js +67 -0
- package/dist/daemon/rival.js.map +1 -0
- package/dist/daemon/server.d.ts +104 -190
- package/dist/daemon/server.js +358 -866
- package/dist/daemon/server.js.map +1 -1
- package/dist/daemon/settings.d.ts +42 -0
- package/dist/daemon/settings.js +43 -0
- package/dist/daemon/settings.js.map +1 -0
- package/dist/daemon/surface.d.ts +103 -0
- package/dist/daemon/surface.js +71 -0
- package/dist/daemon/surface.js.map +1 -0
- package/dist/daemon/surfaceReplies.d.ts +109 -0
- package/dist/daemon/surfaceReplies.js +108 -0
- package/dist/daemon/surfaceReplies.js.map +1 -0
- package/dist/daemon/terminals.js +5 -2
- package/dist/daemon/terminals.js.map +1 -1
- package/dist/daemon/token.d.ts +41 -5
- package/dist/daemon/token.js +43 -12
- package/dist/daemon/token.js.map +1 -1
- package/dist/daemon/uploadHold.d.ts +85 -0
- package/dist/daemon/uploadHold.js +205 -0
- package/dist/daemon/uploadHold.js.map +1 -0
- package/dist/daemon/vfsHeaders.d.ts +11 -0
- package/dist/daemon/vfsHeaders.js +60 -0
- package/dist/daemon/vfsHeaders.js.map +1 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/notes.json +1 -1
- package/package.json +9 -4
- package/dist/daemon/discovery.d.ts +0 -23
- package/dist/daemon/discovery.js +0 -57
- package/dist/daemon/discovery.js.map +0 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The requests a daemon has open on its surfaces, and the replies that settle them.
|
|
3
|
+
*
|
|
4
|
+
* A running command asks its surface for things only the surface can do: a person's answer, a pipeline segment, a
|
|
5
|
+
* host shell, an edit, a delivered file, a line in the surface's own language. Each kind is one request broker
|
|
6
|
+
* (broker.ts), which owns the correlation: ids, the close guard, settles checked against the asking socket. This
|
|
7
|
+
* module holds the six and routes each surface reply to its broker.
|
|
8
|
+
*
|
|
9
|
+
* Key components:
|
|
10
|
+
* - SurfaceReplies: the six brokers and `reply_settle`.
|
|
11
|
+
* - EditOutcome: the result of a surface's local edit.
|
|
12
|
+
* - DeliverOutcome: where a delivered file landed.
|
|
13
|
+
*
|
|
14
|
+
* Typical usage:
|
|
15
|
+
* ```ts
|
|
16
|
+
* const replies: SurfaceReplies = new SurfaceReplies();
|
|
17
|
+
* const answer: string = await replies.prompts.open(socket, (promptId: string): void => { ask(promptId); });
|
|
18
|
+
* if (replies.reply_settle(socket, message)) return;
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Dependencies: broker.ts; the client messages of `@fnndsc/menu`; ws for the socket a reply came on.
|
|
22
|
+
*
|
|
23
|
+
* @module
|
|
24
|
+
*/
|
|
25
|
+
import { RequestBroker } from './broker.js';
|
|
26
|
+
/**
|
|
27
|
+
* The requests open on surfaces, one broker per kind. The broker owns the
|
|
28
|
+
* whole correlation lifecycle uniformly: id generation, close-guard,
|
|
29
|
+
* origin-validated settles, listener cleanup. See broker.ts.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const replies: SurfaceReplies = new SurfaceReplies();
|
|
34
|
+
* replies.reply_settle(socket, { type: 'promptAnswer', promptId: 'p1', answer: 'yes' });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export class SurfaceReplies {
|
|
38
|
+
/** Questions to a person. */
|
|
39
|
+
prompts = new RequestBroker('p', 'surface disconnected before answering');
|
|
40
|
+
/** Pipeline segments run on a surface. */
|
|
41
|
+
pipes = new RequestBroker('x', 'surface disconnected before returning pipe output');
|
|
42
|
+
/** Host shell commands run on a surface. */
|
|
43
|
+
shells = new RequestBroker('h', 'surface disconnected before returning the shell result');
|
|
44
|
+
/** Edits in a surface's own editor. */
|
|
45
|
+
edits = new RequestBroker('e', 'surface disconnected before returning the edit');
|
|
46
|
+
/** Lines run by a surface's own language, by the surface that claims them. */
|
|
47
|
+
surfaceLines = new RequestBroker('l', 'the surface that answers for this line went away before answering');
|
|
48
|
+
/** Files delivered to a surface's machine. */
|
|
49
|
+
deliveries = new RequestBroker('d', 'surface disconnected before the file was delivered');
|
|
50
|
+
/**
|
|
51
|
+
* Settles the request a surface's reply answers, or fails it with the surface's reason.
|
|
52
|
+
*
|
|
53
|
+
* @param socket - The socket the reply came on; only the asked surface settles its request.
|
|
54
|
+
* @param message - The surface's message.
|
|
55
|
+
* @returns False when the message is not a reply.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* if (replies.reply_settle(socket, value)) return;
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
reply_settle(socket, message) {
|
|
63
|
+
switch (message.type) {
|
|
64
|
+
case 'promptAnswer':
|
|
65
|
+
this.prompts.settle(socket, message.promptId, message.answer);
|
|
66
|
+
return true;
|
|
67
|
+
case 'promptError':
|
|
68
|
+
this.prompts.fail(socket, message.promptId, message.reason);
|
|
69
|
+
return true;
|
|
70
|
+
case 'pipeResult':
|
|
71
|
+
this.pipes.settle(socket, message.pipeId, Buffer.from(message.output, 'base64'));
|
|
72
|
+
return true;
|
|
73
|
+
case 'pipeError':
|
|
74
|
+
this.pipes.fail(socket, message.pipeId, message.reason);
|
|
75
|
+
return true;
|
|
76
|
+
case 'shellResult':
|
|
77
|
+
this.shells.settle(socket, message.shellId, message.exitCode);
|
|
78
|
+
return true;
|
|
79
|
+
case 'shellError':
|
|
80
|
+
this.shells.fail(socket, message.shellId, message.reason);
|
|
81
|
+
return true;
|
|
82
|
+
case 'editResult':
|
|
83
|
+
this.edits.settle(socket, message.editId, {
|
|
84
|
+
content: message.content,
|
|
85
|
+
changed: message.changed,
|
|
86
|
+
...(message.opened === undefined ? {} : { opened: message.opened }),
|
|
87
|
+
});
|
|
88
|
+
return true;
|
|
89
|
+
case 'editError':
|
|
90
|
+
this.edits.fail(socket, message.editId, message.reason);
|
|
91
|
+
return true;
|
|
92
|
+
case 'deliverResult':
|
|
93
|
+
this.deliveries.settle(socket, message.deliverId, { location: message.location, bytes: message.bytes });
|
|
94
|
+
return true;
|
|
95
|
+
case 'deliverError':
|
|
96
|
+
this.deliveries.fail(socket, message.deliverId, message.reason);
|
|
97
|
+
return true;
|
|
98
|
+
case 'surfaceLineResult':
|
|
99
|
+
this.surfaceLines.settle(socket, message.lineId, { rendered: message.rendered, status: message.status });
|
|
100
|
+
return true;
|
|
101
|
+
case 'surfaceLineError':
|
|
102
|
+
this.surfaceLines.fail(socket, message.lineId, message.reason);
|
|
103
|
+
return true;
|
|
104
|
+
default: return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=surfaceReplies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"surfaceReplies.js","sourceRoot":"","sources":["../../src/daemon/surfaceReplies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAKH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAiD5C;;;;;;;;;;GAUG;AACH,MAAM,OAAO,cAAc;IACzB,6BAA6B;IACb,OAAO,GAA0B,IAAI,aAAa,CAAS,GAAG,EAAE,uCAAuC,CAAC,CAAC;IACzH,0CAA0C;IAC1B,KAAK,GAA0B,IAAI,aAAa,CAAS,GAAG,EAAE,mDAAmD,CAAC,CAAC;IACnI,4CAA4C;IAC5B,MAAM,GAA0B,IAAI,aAAa,CAAS,GAAG,EAAE,wDAAwD,CAAC,CAAC;IACzI,uCAAuC;IACvB,KAAK,GAA+B,IAAI,aAAa,CAAc,GAAG,EAAE,gDAAgD,CAAC,CAAC;IAC1I,8EAA8E;IAC9D,YAAY,GAAqC,IAAI,aAAa,CAAoB,GAAG,EAAE,mEAAmE,C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QACxB,CAAC;IACH,CAAC;CACF"}
|
package/dist/daemon/terminals.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
* @module
|
|
24
24
|
*/
|
|
25
25
|
import { randomBytes } from 'node:crypto';
|
|
26
|
+
import { ATTACH_TOKEN_ENV, TERMINAL_ID_ENV } from '@fnndsc/menu';
|
|
26
27
|
/** The recent output a terminal keeps for a reattach: about a megabyte. */
|
|
27
28
|
export const TERMINAL_BUFFER_LIMIT = 1024 * 1024;
|
|
28
29
|
/** How long a terminal nobody is attached to lives: fifteen minutes. */
|
|
@@ -185,7 +186,9 @@ export class Terminals {
|
|
|
185
186
|
terminal_start(cols, rows) {
|
|
186
187
|
const { launch, target } = this.options;
|
|
187
188
|
const id = randomBytes(12).toString('hex');
|
|
188
|
-
const pty = this.options.spawn(launch.exec,
|
|
189
|
+
const pty = this.options.spawn(launch.exec,
|
|
190
|
+
// The token goes in the environment, never on the command line, which `ps` shows to every user of this host.
|
|
191
|
+
[...launch.prefixArgs, '--remote', target.identity, '--attach', target.url], {
|
|
189
192
|
name: 'xterm-256color',
|
|
190
193
|
cols,
|
|
191
194
|
rows,
|
|
@@ -193,7 +196,7 @@ export class Terminals {
|
|
|
193
196
|
// A terminal draws colour, whatever the daemon's own environment said;
|
|
194
197
|
// CHELL_TERMINAL names the terminal, so the chell can say on attach
|
|
195
198
|
// whose console it is.
|
|
196
|
-
env: { ...process.env, TERM: 'xterm-256color', COLORTERM: 'truecolor', FORCE_COLOR: '3',
|
|
199
|
+
env: { ...process.env, TERM: 'xterm-256color', COLORTERM: 'truecolor', FORCE_COLOR: '3', [TERMINAL_ID_ENV]: id, [ATTACH_TOKEN_ENV]: target.token },
|
|
197
200
|
});
|
|
198
201
|
const terminal = { id, pty, buffer: [], bufferSize: 0, viewer: null, idle: null, exited: false };
|
|
199
202
|
pty.onData((data) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"terminals.js","sourceRoot":"","sources":["../../src/daemon/ter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EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACjF,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACK,SAAS,CAAC,QAAkB;QAClC,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI;YAAE,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACxD,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC;IACvB,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa;IACjC,IAAI,CAAC;QACH,MAAM,IAAI,GAAW,UAAU,CAAC;QAChC,MAAM,MAAM,GAAyD,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,CAAyD,CAAC;QAClJ,OAAO,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,OAAO,EAAE,KAAK,IAAI,IAAI,CAAC;IACvD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/dist/daemon/token.d.ts
CHANGED
|
@@ -4,14 +4,50 @@
|
|
|
4
4
|
* @returns The token string.
|
|
5
5
|
*/
|
|
6
6
|
export declare function token_generate(): string;
|
|
7
|
+
/** How a token is written into lines a daemon prints. */
|
|
8
|
+
export interface TokenWords {
|
|
9
|
+
/** For a line that states the token. */
|
|
10
|
+
readonly token: string;
|
|
11
|
+
/** For the end of a web address: `?token=…`, or nothing. */
|
|
12
|
+
readonly query: string;
|
|
13
|
+
/** For a command line: `--token …`. */
|
|
14
|
+
readonly flag: string;
|
|
15
|
+
/** What to add after a web address that was printed without its token; empty when it carries it. */
|
|
16
|
+
readonly aside: string;
|
|
17
|
+
}
|
|
7
18
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
19
|
+
* The words a printed line uses for a token: the token itself where the
|
|
20
|
+
* output is a terminal somebody is reading, and where it is kept, never the
|
|
21
|
+
* token, where the output is anything else.
|
|
10
22
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
23
|
+
* A daemon's banner is the one place its operator reads the token off the
|
|
24
|
+
* screen. The same lines sent to a file or a pipe (`> daemon.log`, a
|
|
25
|
+
* service's journal) are a credential in a log. There the lines name the
|
|
26
|
+
* berth's own record, which holds the token at mode 0600.
|
|
27
|
+
*
|
|
28
|
+
* @param token - The attach token.
|
|
29
|
+
* @param terminal - Whether the output is a terminal.
|
|
30
|
+
* @param kept - The path of the record that holds the token.
|
|
31
|
+
* @returns The words.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const words: TokenWords = tokenWords_say(token, process.stdout.isTTY === true, berth_path(identity));
|
|
36
|
+
* console.log(`token: ${words.token}`);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function tokenWords_say(token: string, terminal: boolean, kept: string): TokenWords;
|
|
40
|
+
/**
|
|
41
|
+
* The lines that say how to attach to one berth.
|
|
42
|
+
*
|
|
43
|
+
* @param identity - The berth's identity.
|
|
44
|
+
* @param url - Its wire address.
|
|
45
|
+
* @param token - Its token.
|
|
46
|
+
* @param terminal - Whether the lines go to a terminal.
|
|
47
|
+
* @param kept - The record this berth was read from.
|
|
48
|
+
* @returns The identity line, the ARGUS line and the attach line, uncoloured.
|
|
13
49
|
*/
|
|
14
|
-
export declare function
|
|
50
|
+
export declare function berthLines_say(identity: string, url: string, token: string, terminal: boolean, kept: string): [string, string, string];
|
|
15
51
|
/**
|
|
16
52
|
* Compares a provided token against the expected one in constant time, so a
|
|
17
53
|
* mismatch reveals nothing through timing. Unequal lengths fail fast (and are
|
package/dist/daemon/token.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file The attach token: generation
|
|
3
|
-
* comparison.
|
|
2
|
+
* @file The attach token: generation and constant-time comparison.
|
|
4
3
|
*
|
|
5
4
|
* The daemon's attach perimeter is the proven local-daemon model: a random
|
|
6
5
|
* token generated at startup, required in every attach handshake, compared in
|
|
7
|
-
* constant time.
|
|
8
|
-
* a same-user surface can discover it without it crossing an untrusted
|
|
9
|
-
* channel. Remote access is an operator concern (an SSH tunnel or TLS proxy
|
|
6
|
+
* constant time. Remote access is an operator concern (an SSH tunnel or TLS proxy
|
|
10
7
|
* in front, with the token still gating attach inside it).
|
|
11
8
|
*
|
|
12
9
|
* @module
|
|
13
10
|
*/
|
|
14
11
|
import { randomBytes, timingSafeEqual } from 'node:crypto';
|
|
15
|
-
import { writeFileSync } from 'node:fs';
|
|
16
12
|
/**
|
|
17
13
|
* Generates a fresh attach token: 256 bits of randomness, hex-encoded.
|
|
18
14
|
*
|
|
@@ -22,14 +18,49 @@ export function token_generate() {
|
|
|
22
18
|
return randomBytes(32).toString('hex');
|
|
23
19
|
}
|
|
24
20
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
21
|
+
* The words a printed line uses for a token: the token itself where the
|
|
22
|
+
* output is a terminal somebody is reading, and where it is kept, never the
|
|
23
|
+
* token, where the output is anything else.
|
|
27
24
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
25
|
+
* A daemon's banner is the one place its operator reads the token off the
|
|
26
|
+
* screen. The same lines sent to a file or a pipe (`> daemon.log`, a
|
|
27
|
+
* service's journal) are a credential in a log. There the lines name the
|
|
28
|
+
* berth's own record, which holds the token at mode 0600.
|
|
29
|
+
*
|
|
30
|
+
* @param token - The attach token.
|
|
31
|
+
* @param terminal - Whether the output is a terminal.
|
|
32
|
+
* @param kept - The path of the record that holds the token.
|
|
33
|
+
* @returns The words.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const words: TokenWords = tokenWords_say(token, process.stdout.isTTY === true, berth_path(identity));
|
|
38
|
+
* console.log(`token: ${words.token}`);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export function tokenWords_say(token, terminal, kept) {
|
|
42
|
+
if (terminal)
|
|
43
|
+
return { token, query: `?token=${token}`, flag: `--token ${token}`, aside: '' };
|
|
44
|
+
return {
|
|
45
|
+
token: `not printed, since this output is not a terminal; it is kept in ${kept}`,
|
|
46
|
+
query: '',
|
|
47
|
+
flag: `--token <the token kept in ${kept}>`,
|
|
48
|
+
aside: ` (its token is kept in ${kept})`,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The lines that say how to attach to one berth.
|
|
53
|
+
*
|
|
54
|
+
* @param identity - The berth's identity.
|
|
55
|
+
* @param url - Its wire address.
|
|
56
|
+
* @param token - Its token.
|
|
57
|
+
* @param terminal - Whether the lines go to a terminal.
|
|
58
|
+
* @param kept - The record this berth was read from.
|
|
59
|
+
* @returns The identity line, the ARGUS line and the attach line, uncoloured.
|
|
30
60
|
*/
|
|
31
|
-
export function
|
|
32
|
-
|
|
61
|
+
export function berthLines_say(identity, url, token, terminal, kept) {
|
|
62
|
+
const words = tokenWords_say(token, terminal, kept);
|
|
63
|
+
return [identity, ` ARGUS: ${url.replace(/^ws/, 'http')}/${words.query}${words.aside}`, ` attach: chell --remote --attach ${url} ${words.flag}`];
|
|
33
64
|
}
|
|
34
65
|
/**
|
|
35
66
|
* Compares a provided token against the expected one in constant time, so a
|
package/dist/daemon/token.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../src/daemon/token.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../src/daemon/token.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE3D;;;;GAIG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC;AAcD;;;;;;;;;;;;;;;;;;;;GA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/**
|
|
2
|
+
* @file How many bytes of uploads a daemon holds at once.
|
|
3
|
+
*
|
|
4
|
+
* A posted file is held in memory until the store has it. One request is
|
|
5
|
+
* capped, but any number may arrive together, so the daemon keeps a count
|
|
6
|
+
* of the bytes it holds for uploads in flight and refuses one that would
|
|
7
|
+
* take the count past a ceiling. The refusal says to come back: nothing
|
|
8
|
+
* was wrong with the file.
|
|
9
|
+
*
|
|
10
|
+
* A request that states its length reserves that many bytes before one is
|
|
11
|
+
* read and is filled in place, so it is held once. A request that states
|
|
12
|
+
* none is gathered in pieces and joined, which holds it twice for a
|
|
13
|
+
* moment, and is counted twice for that reason.
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
import type { IncomingMessage } from 'node:http';
|
|
18
|
+
/** The ceiling when none is set: bytes of uploads held at once. */
|
|
19
|
+
export declare const UPLOAD_HELD_DEFAULT: number;
|
|
20
|
+
/** How long a refused upload is told to wait, in seconds. */
|
|
21
|
+
export declare const UPLOAD_RETRY_SECONDS: number;
|
|
22
|
+
/**
|
|
23
|
+
* Reads the ceiling from the environment (`CALYPSO_UPLOAD_HELD`, bytes).
|
|
24
|
+
*
|
|
25
|
+
* @param env - The environment.
|
|
26
|
+
* @returns The ceiling; the default when the variable is unset or is not a positive whole number.
|
|
27
|
+
*/
|
|
28
|
+
export declare function uploadCeiling_read(env: NodeJS.ProcessEnv): number;
|
|
29
|
+
/** The count of bytes held for uploads in flight, under a ceiling. */
|
|
30
|
+
export declare class UploadHold {
|
|
31
|
+
readonly ceiling: number;
|
|
32
|
+
private heldNow;
|
|
33
|
+
/**
|
|
34
|
+
* @param ceiling - The most bytes held at once.
|
|
35
|
+
*/
|
|
36
|
+
constructor(ceiling: number);
|
|
37
|
+
/** The bytes held now. */
|
|
38
|
+
get held(): number;
|
|
39
|
+
/**
|
|
40
|
+
* Reserves bytes, when they fit under the ceiling.
|
|
41
|
+
*
|
|
42
|
+
* @param bytes - How many.
|
|
43
|
+
* @returns Whether they were reserved.
|
|
44
|
+
*/
|
|
45
|
+
reserve(bytes: number): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Gives bytes back.
|
|
48
|
+
*
|
|
49
|
+
* @param bytes - How many.
|
|
50
|
+
*/
|
|
51
|
+
release(bytes: number): void;
|
|
52
|
+
}
|
|
53
|
+
/** An upload's body, held, with the way to give its bytes back. */
|
|
54
|
+
export interface UploadTaken {
|
|
55
|
+
/** The body, whole. */
|
|
56
|
+
readonly bytes: Buffer;
|
|
57
|
+
/** Gives the reservation back. Safe to call more than once; it releases once. */
|
|
58
|
+
readonly release: () => void;
|
|
59
|
+
}
|
|
60
|
+
/** Why an upload's body was not taken. */
|
|
61
|
+
export interface UploadRefusal {
|
|
62
|
+
/** The HTTP status to answer with. */
|
|
63
|
+
readonly status: number;
|
|
64
|
+
/** The line to answer with. */
|
|
65
|
+
readonly message: string;
|
|
66
|
+
/** Seconds after which the same upload may be tried again, when the refusal is for room. */
|
|
67
|
+
readonly retryAfter?: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Takes one upload's body under the ceiling.
|
|
71
|
+
*
|
|
72
|
+
* Nothing is allocated before the stated length has been checked against
|
|
73
|
+
* the request's own limit and reserved. A body longer or shorter than it
|
|
74
|
+
* stated is refused. Whatever was reserved for a body that is refused, or
|
|
75
|
+
* whose reading fails, is given back before this returns; a body that is
|
|
76
|
+
* taken keeps its reservation until the caller calls `release`.
|
|
77
|
+
*
|
|
78
|
+
* @param request - The request whose body is the file.
|
|
79
|
+
* @param hold - The daemon's count of bytes held.
|
|
80
|
+
* @param limit - The most bytes one request may carry.
|
|
81
|
+
* @returns The body and its release, or why it was not taken.
|
|
82
|
+
*/
|
|
83
|
+
export declare function upload_take(request: IncomingMessage, hold: UploadHold, limit: number): Promise<UploadTaken | {
|
|
84
|
+
refusal: UploadRefusal;
|
|
85
|
+
}>;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { UPLOAD_HELD_ENV } from './settings.js';
|
|
2
|
+
/** The ceiling when none is set: bytes of uploads held at once. */
|
|
3
|
+
export const UPLOAD_HELD_DEFAULT = 512 * 1024 * 1024;
|
|
4
|
+
/** How long a refused upload is told to wait, in seconds. */
|
|
5
|
+
export const UPLOAD_RETRY_SECONDS = 5;
|
|
6
|
+
/**
|
|
7
|
+
* Reads the ceiling from the environment (`CALYPSO_UPLOAD_HELD`, bytes).
|
|
8
|
+
*
|
|
9
|
+
* @param env - The environment.
|
|
10
|
+
* @returns The ceiling; the default when the variable is unset or is not a positive whole number.
|
|
11
|
+
*/
|
|
12
|
+
export function uploadCeiling_read(env) {
|
|
13
|
+
const text = env[UPLOAD_HELD_ENV];
|
|
14
|
+
if (text === undefined || !/^[0-9]+$/.test(text))
|
|
15
|
+
return UPLOAD_HELD_DEFAULT;
|
|
16
|
+
const ceiling = Number(text);
|
|
17
|
+
return Number.isSafeInteger(ceiling) && ceiling > 0 ? ceiling : UPLOAD_HELD_DEFAULT;
|
|
18
|
+
}
|
|
19
|
+
/** The count of bytes held for uploads in flight, under a ceiling. */
|
|
20
|
+
export class UploadHold {
|
|
21
|
+
ceiling;
|
|
22
|
+
heldNow = 0;
|
|
23
|
+
/**
|
|
24
|
+
* @param ceiling - The most bytes held at once.
|
|
25
|
+
*/
|
|
26
|
+
constructor(ceiling) {
|
|
27
|
+
this.ceiling = ceiling;
|
|
28
|
+
}
|
|
29
|
+
/** The bytes held now. */
|
|
30
|
+
get held() {
|
|
31
|
+
return this.heldNow;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Reserves bytes, when they fit under the ceiling.
|
|
35
|
+
*
|
|
36
|
+
* @param bytes - How many.
|
|
37
|
+
* @returns Whether they were reserved.
|
|
38
|
+
*/
|
|
39
|
+
reserve(bytes) {
|
|
40
|
+
if (this.heldNow + bytes > this.ceiling)
|
|
41
|
+
return false;
|
|
42
|
+
this.heldNow += bytes;
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Gives bytes back.
|
|
47
|
+
*
|
|
48
|
+
* @param bytes - How many.
|
|
49
|
+
*/
|
|
50
|
+
release(bytes) {
|
|
51
|
+
this.heldNow = Math.max(0, this.heldNow - bytes);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Reads the length a request states.
|
|
56
|
+
*
|
|
57
|
+
* @param request - The request.
|
|
58
|
+
* @returns The length; null when none is stated; a refusal when what is stated is no length.
|
|
59
|
+
*/
|
|
60
|
+
function lengthStated_read(request) {
|
|
61
|
+
const header = request.headers['content-length'];
|
|
62
|
+
if (header === undefined)
|
|
63
|
+
return null;
|
|
64
|
+
if (!/^[0-9]+$/.test(header))
|
|
65
|
+
return { status: 400, message: 'the stated length is not a length' };
|
|
66
|
+
const length = Number(header);
|
|
67
|
+
return Number.isSafeInteger(length) ? length : { status: 400, message: 'the stated length is not a length' };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Copies a fixed-length upload chunk into `whole` or returns a length-overflow refusal.
|
|
71
|
+
*
|
|
72
|
+
* @param whole - Destination buffer of stated length.
|
|
73
|
+
* @param received - Bytes already copied into `whole`.
|
|
74
|
+
* @param part - Incoming chunk.
|
|
75
|
+
* @returns An overflow refusal, or null when copied.
|
|
76
|
+
*/
|
|
77
|
+
function fixedChunk_append(whole, received, part) {
|
|
78
|
+
if (received + part.length > whole.length)
|
|
79
|
+
return { status: 400, message: 'the body is longer than its stated length' };
|
|
80
|
+
part.copy(whole, received);
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Appends a chunked upload piece into `state.pieces`, reserving twice its length under `hold` before pushing.
|
|
85
|
+
*
|
|
86
|
+
* @param state - Mutable upload read state.
|
|
87
|
+
* @param part - Incoming chunk.
|
|
88
|
+
* @param limit - Per-request byte limit.
|
|
89
|
+
* @param hold - Upload hold budget.
|
|
90
|
+
* @returns A refusal when the chunk cannot be taken, or null.
|
|
91
|
+
*/
|
|
92
|
+
function unstatedChunk_append(state, part, limit, hold) {
|
|
93
|
+
if (state.received + part.length > limit) {
|
|
94
|
+
return { status: 413, message: `file too large: this route takes at most ${String(limit)} bytes` };
|
|
95
|
+
}
|
|
96
|
+
// Held twice while it is joined: once in its pieces, once in the whole.
|
|
97
|
+
if (!hold.reserve(2 * part.length)) {
|
|
98
|
+
return {
|
|
99
|
+
status: 503,
|
|
100
|
+
message: `the session is holding as many uploaded bytes as it may (${String(hold.ceiling)}): try again shortly`,
|
|
101
|
+
retryAfter: UPLOAD_RETRY_SECONDS,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
state.reserved += 2 * part.length;
|
|
105
|
+
state.pieces.push(part);
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Normalizes a stream chunk into a `Buffer`.
|
|
110
|
+
*
|
|
111
|
+
* @param chunk - Chunk yielded by `request.iterator`.
|
|
112
|
+
* @returns The chunk as a `Buffer`.
|
|
113
|
+
*/
|
|
114
|
+
function chunkBuffer_coerce(chunk) {
|
|
115
|
+
return Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Maps a stream or allocation error during upload reading into an `UploadRefusal`.
|
|
119
|
+
*
|
|
120
|
+
* @param error - Thrown error.
|
|
121
|
+
* @returns The corresponding `UploadRefusal`.
|
|
122
|
+
*/
|
|
123
|
+
function uploadReadError_classify(error) {
|
|
124
|
+
return error instanceof RangeError
|
|
125
|
+
? { status: 503, message: 'the session could not hold the body: try again shortly', retryAfter: UPLOAD_RETRY_SECONDS }
|
|
126
|
+
: { status: 400, message: 'could not read the request body' };
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Validates and reserves the `content-length` header when present.
|
|
130
|
+
*
|
|
131
|
+
* @param request - Incoming HTTP request.
|
|
132
|
+
* @param hold - Upload hold budget.
|
|
133
|
+
* @param limit - Per-request byte limit.
|
|
134
|
+
* @returns The stated length and reserved byte count, or a refusal.
|
|
135
|
+
*/
|
|
136
|
+
function statedReservation_open(request, hold, limit) {
|
|
137
|
+
const stated = lengthStated_read(request);
|
|
138
|
+
if (typeof stated === 'object' && stated !== null)
|
|
139
|
+
return { refusal: stated };
|
|
140
|
+
if (stated === null)
|
|
141
|
+
return { stated: null, reserved: 0 };
|
|
142
|
+
if (stated > limit)
|
|
143
|
+
return { refusal: { status: 413, message: `file too large: this route takes at most ${String(limit)} bytes` } };
|
|
144
|
+
if (!hold.reserve(stated)) {
|
|
145
|
+
return {
|
|
146
|
+
refusal: {
|
|
147
|
+
status: 503,
|
|
148
|
+
message: `the session is holding as many uploaded bytes as it may (${String(hold.ceiling)}): try again shortly`,
|
|
149
|
+
retryAfter: UPLOAD_RETRY_SECONDS,
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
return { stated, reserved: stated };
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Takes one upload's body under the ceiling.
|
|
157
|
+
*
|
|
158
|
+
* Nothing is allocated before the stated length has been checked against
|
|
159
|
+
* the request's own limit and reserved. A body longer or shorter than it
|
|
160
|
+
* stated is refused. Whatever was reserved for a body that is refused, or
|
|
161
|
+
* whose reading fails, is given back before this returns; a body that is
|
|
162
|
+
* taken keeps its reservation until the caller calls `release`.
|
|
163
|
+
*
|
|
164
|
+
* @param request - The request whose body is the file.
|
|
165
|
+
* @param hold - The daemon's count of bytes held.
|
|
166
|
+
* @param limit - The most bytes one request may carry.
|
|
167
|
+
* @returns The body and its release, or why it was not taken.
|
|
168
|
+
*/
|
|
169
|
+
export async function upload_take(request, hold, limit) {
|
|
170
|
+
const opened = statedReservation_open(request, hold, limit);
|
|
171
|
+
if ('refusal' in opened)
|
|
172
|
+
return opened;
|
|
173
|
+
const { stated } = opened;
|
|
174
|
+
const state = { reserved: opened.reserved, received: 0, pieces: [] };
|
|
175
|
+
const give = () => { hold.release(state.reserved); state.reserved = 0; };
|
|
176
|
+
let refusal = null;
|
|
177
|
+
// Everything from here to the return can fail after bytes were reserved,
|
|
178
|
+
// the allocations included: whatever happens, what is not handed to the
|
|
179
|
+
// caller with its release is given back.
|
|
180
|
+
try {
|
|
181
|
+
const whole = stated !== null ? Buffer.allocUnsafe(stated) : null;
|
|
182
|
+
// Leaving the loop early must leave the request alone: a request that is
|
|
183
|
+
// destroyed takes its socket with it, and the refusal could not be sent.
|
|
184
|
+
for await (const chunk of request.iterator({ destroyOnReturn: false })) {
|
|
185
|
+
const part = chunkBuffer_coerce(chunk);
|
|
186
|
+
refusal = whole !== null
|
|
187
|
+
? fixedChunk_append(whole, state.received, part)
|
|
188
|
+
: unstatedChunk_append(state, part, limit, hold);
|
|
189
|
+
if (refusal !== null)
|
|
190
|
+
break;
|
|
191
|
+
state.received += part.length;
|
|
192
|
+
}
|
|
193
|
+
if (refusal === null && whole !== null && state.received !== whole.length) {
|
|
194
|
+
refusal = { status: 400, message: 'the body is shorter than its stated length' };
|
|
195
|
+
}
|
|
196
|
+
if (refusal === null)
|
|
197
|
+
return { bytes: whole ?? Buffer.concat(state.pieces, state.received), release: give };
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
refusal = uploadReadError_classify(error);
|
|
201
|
+
}
|
|
202
|
+
give();
|
|
203
|
+
return { refusal };
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=uploadHold.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploadHold.js","sourceRoot":"","sources":["../../src/daemon/uploadHold.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,mEAAmE;AACnE,MAAM,CAAC,MAAM,mBAAmB,GAAW,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAE7D,6DAA6D;AAC7D,MAAM,CAAC,MAAM,oBAAoB,GAAW,CAAC,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,UAAU,kB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,CAAC;gBAChD,CAAC,CAAC,oBAAoB,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;YACnD,IAAI,OAAO,KAAK,IAAI;gBAAE,MAAM;YAC5B,KAAK,CAAC,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC;QAChC,CAAC;QACD,IAAI,OAAO,KAAK,IAAI,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,QAAQ,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC;YAC1E,OAAO,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,4CAA4C,EAAE,CAAC;QACnF,CAAC;QACD,IAAI,OAAO,KAAK,IAAI;YAAE,OAAO,EAAE,KAAK,EAAE,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC9G,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,OAAO,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;IACD,IAAI,EAAE,CAAC;IACP,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** What a document made of these bytes may do: nothing. */
|
|
2
|
+
export declare const VFS_CONTENT_POLICY: string;
|
|
3
|
+
/**
|
|
4
|
+
* The headers for one file's bytes on `/vfs`.
|
|
5
|
+
*
|
|
6
|
+
* @param filePath - The path served; its extension decides.
|
|
7
|
+
* @param download - Whether the surface asked for a save (`download=1`).
|
|
8
|
+
* @param size - The length in bytes, when it is known.
|
|
9
|
+
* @returns The response headers.
|
|
10
|
+
*/
|
|
11
|
+
export declare function vfsHeaders_build(filePath: string, download: boolean, size?: number): Record<string, string | number>;
|