dsh-remote-vs 0.28.0 → 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/README.en.md +63 -7
- package/README.md +51 -7
- package/lib/client.js +393 -112
- package/lib/index.js +2271 -160
- package/lib/p2-router-fs.js +1 -1
- package/lib/types/changes/recorder.d.ts +65 -10
- package/lib/types/changes/status.d.ts +48 -3
- package/lib/types/client/ConnectionsSection.d.ts +73 -0
- package/lib/types/client/HostsView.d.ts +139 -2
- package/lib/types/client/api.d.ts +65 -2
- package/lib/types/client/connection.d.ts +28 -1
- package/lib/types/client/scm/actions.d.ts +25 -1
- package/lib/types/forward.d.ts +11 -1
- package/lib/types/p2/helper-rpc.d.ts +48 -0
- package/lib/types/p2/worlds.d.ts +28 -0
- package/lib/types/pool.d.ts +337 -8
- package/lib/types/protocol.d.ts +218 -0
- package/lib/types/proxy.d.ts +136 -0
- package/lib/types/store.d.ts +81 -1
- package/lib/types/tools.d.ts +3 -0
- package/lib/{worlds-RG8K5eom.js → worlds-CRRZMZhg.js} +85 -6
- package/package.json +1 -1
- package/src/changes/recorder.ts +151 -15
- package/src/changes/status.ts +59 -4
- package/src/client/ConnectionStatus.tsx +19 -5
- package/src/client/ConnectionsSection.tsx +359 -0
- package/src/client/HostsView.tsx +552 -11
- package/src/client/MonitorView.tsx +14 -0
- package/src/client/PortsView.tsx +16 -0
- package/src/client/SettingsHosts.tsx +132 -6
- package/src/client/api.ts +102 -4
- package/src/client/connection.ts +76 -2
- package/src/client/i18n.ts +152 -2
- package/src/client/scm/actions.ts +63 -12
- package/src/client/vsc/vsc.css +281 -0
- package/src/forward.ts +38 -2
- package/src/importers.ts +125 -13
- package/src/keygen.ts +8 -1
- package/src/p2/helper-rpc.ts +73 -5
- package/src/p2/worlds.ts +48 -0
- package/src/pool.ts +1120 -100
- package/src/protocol.ts +228 -0
- package/src/proxy.ts +673 -0
- package/src/routes.ts +139 -5
- package/src/store.ts +335 -0
- package/src/tools.ts +47 -2
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper RPC over an ssh2 exec channel: the Windows-native transport for the
|
|
3
|
+
* official helper wire protocol. Speaks stdio RPC (SshRpcPeer + official
|
|
4
|
+
* schemas) to the deployed `dsh-ssh-helper` binary — no OpenSSH CLI, no POSIX
|
|
5
|
+
* gates. One connection per host alias; heartbeats keep the helper lease alive.
|
|
6
|
+
*/
|
|
7
|
+
import { Client } from 'ssh2';
|
|
1
8
|
import { z } from 'zod';
|
|
2
9
|
import type { RemoteHostEntry } from '../protocol.ts';
|
|
10
|
+
import type { RoutedDial } from '../pool.ts';
|
|
3
11
|
export interface RpcDialOpts {
|
|
4
12
|
entry: RemoteHostEntry;
|
|
5
13
|
/** Absolute remote path of the helper executable. */
|
|
@@ -9,6 +17,26 @@ export interface RpcDialOpts {
|
|
|
9
17
|
/** Remote default workspace for the hello handshake. */
|
|
10
18
|
workspace: string;
|
|
11
19
|
leaseMs?: number;
|
|
20
|
+
/**
|
|
21
|
+
* The HOST's routed transport for this alias (proxy tunnel / jump-host channel),
|
|
22
|
+
* optional so a caller without a pool still dials directly.
|
|
23
|
+
*
|
|
24
|
+
* Without it this transport is a BARE direct connection: a host reachable only
|
|
25
|
+
* through a proxy or jump host would answer exec/SFTP (the pool honours the
|
|
26
|
+
* route) and fail every file/Git fast path — the "some features work, some do
|
|
27
|
+
* not" report. The pool supplies it via `openRoutedSocket`; the returned
|
|
28
|
+
* `release` is called here (once) on failure, close, reconnect and dispose.
|
|
29
|
+
*/
|
|
30
|
+
openSocket?: () => Promise<RoutedDial>;
|
|
31
|
+
/**
|
|
32
|
+
* The ssh2 client factory.
|
|
33
|
+
*
|
|
34
|
+
* A seam, not a preference — the same one `RemotePool.makeClient` has: the only
|
|
35
|
+
* way a self-check can observe what this transport hands ssh2 (`{sock}` with no
|
|
36
|
+
* `host`/`port` for a routed dial, the reverse for a direct one) without a real
|
|
37
|
+
* server. Production never overrides it.
|
|
38
|
+
*/
|
|
39
|
+
makeClient?: () => Client;
|
|
12
40
|
}
|
|
13
41
|
export interface RpcHello {
|
|
14
42
|
protocol: number;
|
|
@@ -63,6 +91,17 @@ export declare class RpcConnection {
|
|
|
63
91
|
* grow host memory.
|
|
64
92
|
*/
|
|
65
93
|
private stderrTail;
|
|
94
|
+
/**
|
|
95
|
+
* Teardown of the ROUTED transport this attempt rides (proxy socket / jump-host
|
|
96
|
+
* tunnel), or undefined for a direct dial.
|
|
97
|
+
*
|
|
98
|
+
* It lives on the instance because the release has to outlive the handshake: the
|
|
99
|
+
* tunnel must stay open exactly as long as the SSH connection rides it, so the
|
|
100
|
+
* call belongs in `teardownTransport` (dispose, reconnect, failed open) rather
|
|
101
|
+
* than in the dial promise. The pool's release is idempotent, so calling it from
|
|
102
|
+
* a failure path AND from the teardown is safe.
|
|
103
|
+
*/
|
|
104
|
+
private releaseRoute;
|
|
66
105
|
/** Per-connection in-flight cap; see MAX_IN_FLIGHT. */
|
|
67
106
|
private readonly gate;
|
|
68
107
|
constructor(opts: RpcDialOpts);
|
|
@@ -70,6 +109,15 @@ export declare class RpcConnection {
|
|
|
70
109
|
get alive(): boolean;
|
|
71
110
|
/** Whatever the helper last wrote to stderr — empty when it said nothing. */
|
|
72
111
|
get diagnostics(): string;
|
|
112
|
+
/**
|
|
113
|
+
* How many helper calls are in flight right now.
|
|
114
|
+
*
|
|
115
|
+
* Read-only diagnostics for the monitor: the helper caps itself at its own
|
|
116
|
+
* gate, so a saturated helper shows up as a number here instead of looking
|
|
117
|
+
* like an idle connection. It is NOT a queue — a call waits inside the gate
|
|
118
|
+
* before it counts, so this number never exceeds the gate's ceiling.
|
|
119
|
+
*/
|
|
120
|
+
get inFlight(): number;
|
|
73
121
|
get ready(): Promise<RpcHello>;
|
|
74
122
|
/** Send one helper operation (mirrors SshConnection.request for fs-ssh). */
|
|
75
123
|
request<T>(method: string, params: unknown, schema: z.ZodType<T>, signal?: AbortSignal): Promise<T>;
|
package/lib/types/p2/worlds.d.ts
CHANGED
|
@@ -36,6 +36,17 @@ export declare class RemoteWorlds {
|
|
|
36
36
|
private readonly ctx;
|
|
37
37
|
private readonly deps;
|
|
38
38
|
private readonly rpcs;
|
|
39
|
+
/**
|
|
40
|
+
* Aliases whose helper connection is still being dialed.
|
|
41
|
+
*
|
|
42
|
+
* `rpcs` holds the PROMISE, so a caller that awaits it waits for the whole
|
|
43
|
+
* dial (up to `CONNECT_READY_TIMEOUT_MS`, 45 s through a proxy or a jump host).
|
|
44
|
+
* The monitor polls `helperLane` every few seconds and must never inherit that
|
|
45
|
+
* wait — the route is read-only and would report the previous sample for the
|
|
46
|
+
* whole dial, or hold the client's single-flight guard. A name in this set is
|
|
47
|
+
* therefore "cannot say yet", which the client already renders as no row.
|
|
48
|
+
*/
|
|
49
|
+
private readonly dialingRpc;
|
|
39
50
|
private readonly fsViews;
|
|
40
51
|
private readonly fsReady;
|
|
41
52
|
private readonly procs;
|
|
@@ -162,6 +173,23 @@ export declare class RemoteWorlds {
|
|
|
162
173
|
sweepSpillRoot(alias: string, home: string, ttlDays: number): Promise<void>;
|
|
163
174
|
/** Remove one session's spill directory when it is older than the TTL (best effort). */
|
|
164
175
|
sweepSpillDir(alias: string, dir: string, ttlDays: number): Promise<void>;
|
|
176
|
+
/**
|
|
177
|
+
* The helper connection of one alias, for the monitor's fifth lane.
|
|
178
|
+
*
|
|
179
|
+
* The helper dials its OWN SSH connection (see `RpcConnection`), so the pool
|
|
180
|
+
* cannot report it — this is the only place that knows. Read-only by
|
|
181
|
+
* contract: it awaits a record that already exists and never starts a dial, a
|
|
182
|
+
* deploy or a reconnect, because the monitor polls this every few seconds and
|
|
183
|
+
* a diagnostic must not be able to bring a helper up (or keep a dead one
|
|
184
|
+
* alive). `undefined` means "cannot say": no record, a record still dialing, or
|
|
185
|
+
* a record the router is about to replace — the client then omits the row
|
|
186
|
+
* rather than claiming the helper is closed.
|
|
187
|
+
*/
|
|
188
|
+
helperLane(alias: string): Promise<{
|
|
189
|
+
open: boolean;
|
|
190
|
+
channels: number;
|
|
191
|
+
held: number;
|
|
192
|
+
} | undefined>;
|
|
165
193
|
/** Drop one host's RPC + fs view + proc runtime (call after host update/delete). */
|
|
166
194
|
dropHost(alias: string): Promise<void>;
|
|
167
195
|
dispose(): Promise<void>;
|
package/lib/types/pool.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { Duplex } from 'node:stream';
|
|
1
2
|
import { type ClientChannel, type SFTPWrapper } from 'ssh2';
|
|
2
3
|
import type { RemoteStore } from './store.ts';
|
|
3
4
|
import { DeadlineError } from './timeouts.ts';
|
|
4
|
-
import type { RemoteConnectionStatus, RemoteExecResult } from './protocol.ts';
|
|
5
|
+
import type { RemoteConnectionStatus, RemoteExecResult, RemoteHostPoolStats } from './protocol.ts';
|
|
5
6
|
/**
|
|
6
7
|
* The budget-out type lives in `timeouts.ts` (both halves need it); re-exported
|
|
7
8
|
* here because existing callers and the browse gate import it from the pool.
|
|
@@ -27,11 +28,44 @@ export interface ExecOptions {
|
|
|
27
28
|
* recurse into the machinery that dispatched them.
|
|
28
29
|
*/
|
|
29
30
|
bare?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Which channel budget this command spends. Omitted means the shared exec
|
|
33
|
+
* budget — every caller that predates the split keeps that behaviour.
|
|
34
|
+
*
|
|
35
|
+
* `'network'` is for `git fetch/pull/push/sync`: those can hold a channel for
|
|
36
|
+
* the whole network timeout (20 minutes by default), so they get
|
|
37
|
+
* {@link NET_CHANNEL_LIMIT} slots of their own instead of eating the exec slots
|
|
38
|
+
* the rest of the app (status polls, monitor, agent tools) depends on.
|
|
39
|
+
*
|
|
40
|
+
* `'git'` is for GIT COMMANDS — the repository reads (`git status/diff/log`, the
|
|
41
|
+
* session ledger's scans) AND the local writes the SCM panel runs (`commit`,
|
|
42
|
+
* `stage`, `discard`, branch verbs, `merge`): a big tree's `git status` is
|
|
43
|
+
* allowed 300 s, so these get {@link GIT_CHANNEL_LIMIT} slots — otherwise one
|
|
44
|
+
* slow command parks an exec slot for minutes and the monitor/process panel/
|
|
45
|
+
* agent tools queue behind it.
|
|
46
|
+
*/
|
|
47
|
+
lane?: 'exec' | 'network' | 'git';
|
|
30
48
|
}
|
|
31
49
|
export interface ShellOptions {
|
|
32
50
|
cols?: number;
|
|
33
51
|
rows?: number;
|
|
34
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* The transport one configured route hands to an ssh2 dial (see `openRoutedSocket`).
|
|
55
|
+
*
|
|
56
|
+
* `sock` is absent for a direct route, where ssh2 dials the target itself. When it
|
|
57
|
+
* IS present ssh2 must be given `{ sock }` and NOT `host`/`port`: supplying both
|
|
58
|
+
* lets ssh2 choose between "dial this host myself" and "ride the tunnel", and the
|
|
59
|
+
* choice is an implementation detail, not a feature.
|
|
60
|
+
*
|
|
61
|
+
* `release` is idempotent and is the OWNER's to call — a proxy socket has to be
|
|
62
|
+
* destroyed and a jump-host tunnel has to close its channel and give the jump
|
|
63
|
+
* host's hold back, or the next dial finds a pinned connection.
|
|
64
|
+
*/
|
|
65
|
+
export interface RoutedDial {
|
|
66
|
+
sock?: Duplex;
|
|
67
|
+
release: () => void;
|
|
68
|
+
}
|
|
35
69
|
export interface SftpOptions {
|
|
36
70
|
/**
|
|
37
71
|
* Wall-clock cap for the callback body. `0` disables it for an operation that
|
|
@@ -63,12 +97,94 @@ export declare class RemotePool {
|
|
|
63
97
|
* that refuses extra connections still gets a working terminal.
|
|
64
98
|
*/
|
|
65
99
|
private readonly shellConns;
|
|
100
|
+
/**
|
|
101
|
+
* Dedicated connections for `ssh -L` port forwards (one per alias).
|
|
102
|
+
*
|
|
103
|
+
* The other half of the same argument: a forwarded channel carries arbitrary
|
|
104
|
+
* TCP (a database, an SSH tunnel, a whole browser page), so it is long-lived
|
|
105
|
+
* and can move a lot of data. Multiplexed onto the shared connection it would
|
|
106
|
+
* queue ahead of exec/SFTP channels (SSH has no per-channel priority), and a
|
|
107
|
+
* remote service that stalls would hold the window `git status` needs. A
|
|
108
|
+
* terminal already gets its own connection (`shellConns`); forward traffic gets
|
|
109
|
+
* its own for exactly the same reason.
|
|
110
|
+
*
|
|
111
|
+
* Cost: one extra handshake per alias that actually receives a forwarded
|
|
112
|
+
* connection, plus one held TCP connection while any of its forward channels is
|
|
113
|
+
* open (the 30-minute idle eviction applies once the last one closes).
|
|
114
|
+
* `forwardOut` falls back to the shared connection when this one cannot be
|
|
115
|
+
* established (e.g. the server refuses extra connections), so a forward never
|
|
116
|
+
* stops working because of it — it only loses the isolation.
|
|
117
|
+
*/
|
|
118
|
+
private readonly forwardConns;
|
|
119
|
+
/**
|
|
120
|
+
* Dedicated connections for FILE operations (one per alias).
|
|
121
|
+
*
|
|
122
|
+
* The third instance of the same argument. Browse/read/write/upload/download
|
|
123
|
+
* used to ride the shared connection, which meant a `git status` burst or a
|
|
124
|
+
* long exec could sit in front of a directory refresh (SSH offers no
|
|
125
|
+
* per-channel priority), AND that the shared link's channel budget was shared
|
|
126
|
+
* with file I/O: a few in-flight git/search commands and the explorer could not
|
|
127
|
+
* open a channel at all. A file operation is exactly the traffic a user is
|
|
128
|
+
* watching (a folder must open, a save must land), so it gets its own
|
|
129
|
+
* connection and its own channel budget (`sftpSlots`).
|
|
130
|
+
*
|
|
131
|
+
* Cost: one extra handshake per alias that touches files, plus one held TCP
|
|
132
|
+
* connection while any of its channels is open (the 30-minute idle eviction
|
|
133
|
+
* applies once the last one ends). `acquireSftp` falls back to the
|
|
134
|
+
* shared connection when this one cannot be established — a host that refuses
|
|
135
|
+
* extra connections still serves files, it only loses the isolation.
|
|
136
|
+
*/
|
|
137
|
+
private readonly sftpConns;
|
|
138
|
+
/** Aliases whose dedicated-SFTP downgrade was already logged (once per alias). */
|
|
139
|
+
private readonly sftpFallbackNoted;
|
|
140
|
+
/** alias -> timestamp until which the dedicated SFTP connection is skipped. */
|
|
141
|
+
private readonly sftpBlocked;
|
|
142
|
+
/**
|
|
143
|
+
* Aliases whose file operations are DOWNGRADED right now (sticky until a
|
|
144
|
+
* dedicated connection succeeds again or the host is edited).
|
|
145
|
+
*
|
|
146
|
+
* Purely diagnostic: `stats()` reports it so the monitor page can say "these
|
|
147
|
+
* files are riding the shared connection" instead of leaving the user to
|
|
148
|
+
* wonder why a browse refresh still queues behind git.
|
|
149
|
+
*/
|
|
150
|
+
private readonly sftpFallback;
|
|
151
|
+
/** Aliases whose dedicated-forward downgrade was already logged (once per alias). */
|
|
152
|
+
private readonly forwardFallbackNoted;
|
|
153
|
+
/** alias -> timestamp until which the dedicated forward connection is skipped. */
|
|
154
|
+
private readonly forwardBlocked;
|
|
66
155
|
/** TOFU fingerprints observed this process (alias -> sha256). */
|
|
67
156
|
private readonly hostKeys;
|
|
68
157
|
/** Per-alias `setsid --wait` capability, probed once (see supportsSetsid). */
|
|
69
158
|
private readonly setsidProbes;
|
|
70
|
-
/**
|
|
159
|
+
/**
|
|
160
|
+
* Channel slots of the SHARED connection (see acquireSlot), and of the
|
|
161
|
+
* dedicated SFTP connection.
|
|
162
|
+
*
|
|
163
|
+
* Two tables because the budget is per connection (`MaxSessions` counts
|
|
164
|
+
* channels on one link): a fallback SFTP operation counts against the shared
|
|
165
|
+
* table — the connection it really rides — and never against both.
|
|
166
|
+
*/
|
|
71
167
|
private readonly slots;
|
|
168
|
+
private readonly sftpSlots;
|
|
169
|
+
/**
|
|
170
|
+
* Channel budget of the NETWORK verbs (see {@link NET_CHANNEL_LIMIT}).
|
|
171
|
+
*
|
|
172
|
+
* A third table on the SHARED connection: unlike the SFTP lane this is not about
|
|
173
|
+
* isolating bytes, it is about isolating TIME. A `git push` holds its channel
|
|
174
|
+
* for minutes, and the failure mode it caused — a full exec table, so every
|
|
175
|
+
* status refresh answered "host is busy" after 30 s — came from the two kinds
|
|
176
|
+
* sharing one ceiling.
|
|
177
|
+
*/
|
|
178
|
+
private readonly netSlots;
|
|
179
|
+
/**
|
|
180
|
+
* Channel budget of the GIT COMMANDS (see {@link GIT_CHANNEL_LIMIT}).
|
|
181
|
+
*
|
|
182
|
+
* A fourth table on the SHARED connection, for the same reason as the network
|
|
183
|
+
* one — hold TIME, not traffic: a `git status` on a big tree may run for
|
|
184
|
+
* minutes, and a git command must not be the reason a monitor sample or an agent
|
|
185
|
+
* tool waits.
|
|
186
|
+
*/
|
|
187
|
+
private readonly gitSlots;
|
|
72
188
|
/** Per-alias BROWSE SFTP session (see withBrowseSftp). */
|
|
73
189
|
private readonly browsed;
|
|
74
190
|
/** Per-alias connection health for the browser's status chip (see status). */
|
|
@@ -94,6 +210,37 @@ export declare class RemotePool {
|
|
|
94
210
|
* indicator's poll never creates a connection as a side effect.
|
|
95
211
|
*/
|
|
96
212
|
status(): RemoteConnectionStatus[];
|
|
213
|
+
/**
|
|
214
|
+
* Live pool shape per host: connections, channels, and channel-budget
|
|
215
|
+
* occupancy (see `RemoteHostPoolStats`).
|
|
216
|
+
*
|
|
217
|
+
* Same contract as `status()`: read-only and dial-free, so the monitor's poll
|
|
218
|
+
* reports what the pool already knows instead of creating work. Answers every
|
|
219
|
+
* alias the store knows PLUS every alias the pool holds something for — a host
|
|
220
|
+
* removed from the store still has a connection for a moment, and a page that
|
|
221
|
+
* shows connections must not hide exactly those.
|
|
222
|
+
*/
|
|
223
|
+
stats(): RemoteHostPoolStats[];
|
|
224
|
+
/** One lane of one host: dialed or not, its open channels, its pinned rounds. */
|
|
225
|
+
private laneOf;
|
|
226
|
+
/** One channel budget, as reported (a budget nobody touched is empty, not absent). */
|
|
227
|
+
private slotsOf;
|
|
228
|
+
/**
|
|
229
|
+
* The egress of the alias' LIVE connection, whichever class owns it.
|
|
230
|
+
*
|
|
231
|
+
* All four classes open through the same resolved route, so the first one that
|
|
232
|
+
* is up answers for the alias; the shared connection is preferred because it is
|
|
233
|
+
* the one exec/browse (the surface the chip describes) rides.
|
|
234
|
+
*/
|
|
235
|
+
private liveEgress;
|
|
236
|
+
/**
|
|
237
|
+
* The route the stored configuration resolves to, for an alias with NO live
|
|
238
|
+
* connection. Pure observation, and absorbed: a dangling jump chain or a
|
|
239
|
+
* half-configured proxy makes `resolveProxy` throw, and a status poll must
|
|
240
|
+
* answer "the stored route is broken, here is why" instead of failing — the
|
|
241
|
+
* chip still has to render, and a 500 would hide the reason it exists to show.
|
|
242
|
+
*/
|
|
243
|
+
private configuredEgress;
|
|
97
244
|
/** Record a successful dial or transport-level operation. */
|
|
98
245
|
private markOk;
|
|
99
246
|
/** Record a connection-level failure the status chip should show. */
|
|
@@ -139,13 +286,31 @@ export declare class RemotePool {
|
|
|
139
286
|
* of queueing. The pool's own housekeeping (`bare`: the setsid probe and the
|
|
140
287
|
* group kill) is exempt — a kill that waits behind user traffic would be a
|
|
141
288
|
* worse bug than the one it fixes.
|
|
289
|
+
*
|
|
290
|
+
* `opts.lane` picks the budget: network verbs (`git fetch/pull/push/sync`) have
|
|
291
|
+
* their own small one, so a 20-minute push cannot starve the exec slots.
|
|
292
|
+
* Acquisition and release read the SAME table — a mismatch would leak a slot on
|
|
293
|
+
* one budget and double-count on the other.
|
|
142
294
|
*/
|
|
143
295
|
exec(alias: string, command: string, opts?: ExecOptions): Promise<RemoteExecResult>;
|
|
296
|
+
/** The channel budget an exec spends, by lane (see `ExecOptions.lane`). */
|
|
297
|
+
private execBudget;
|
|
144
298
|
/** The exec body, run while the caller already holds a channel slot. */
|
|
145
299
|
private runExec;
|
|
146
300
|
/** Open an interactive PTY shell. The caller owns the channel lifecycle. */
|
|
147
301
|
shell(alias: string, opts?: ShellOptions): Promise<ClientChannel>;
|
|
148
|
-
/**
|
|
302
|
+
/**
|
|
303
|
+
* Open one exec channel. The caller owns the channel lifecycle.
|
|
304
|
+
*
|
|
305
|
+
* This channel spends an EXEC SLOT (same budget as `runExec`): it is a real
|
|
306
|
+
* `conn.exec` session on the shared connection, so `MaxSessions` counts it
|
|
307
|
+
* whether the pool does or not. The subprocess runtime opens these for every
|
|
308
|
+
* command it runs (`p2/ssh-proc.ts`) and can have several in flight, which used
|
|
309
|
+
* to be the one way to push the shared connection past its ceiling: sshd then
|
|
310
|
+
* refuses the extra channel HARD — no retry, and the operation fails looking
|
|
311
|
+
* like a broken host. A slot makes the surplus WAIT instead: bounded queue, then
|
|
312
|
+
* a readable "busy" message naming the cause.
|
|
313
|
+
*/
|
|
149
314
|
execChannel(alias: string, command: string): Promise<ClientChannel>;
|
|
150
315
|
/**
|
|
151
316
|
* Open one direct-tcpip channel to a TCP target reachable FROM the remote
|
|
@@ -164,7 +329,22 @@ export declare class RemotePool {
|
|
|
164
329
|
* debug their network. Real transport failures still arrive through the
|
|
165
330
|
* pooled connection's own close/error events.
|
|
166
331
|
*/
|
|
167
|
-
forwardOut(alias: string, dstHost: string, dstPort: number, srcPort?: number
|
|
332
|
+
forwardOut(alias: string, dstHost: string, dstPort: number, srcPort?: number, opts?: {
|
|
333
|
+
dedicated?: boolean;
|
|
334
|
+
}): Promise<{
|
|
335
|
+
channel: ClientChannel;
|
|
336
|
+
dedicated: boolean;
|
|
337
|
+
}>;
|
|
338
|
+
/**
|
|
339
|
+
* Is this alias's dedicated forward connection in its short cooldown?
|
|
340
|
+
*
|
|
341
|
+
* Expired entries are dropped eagerly so the map cannot grow per alias forever.
|
|
342
|
+
*/
|
|
343
|
+
private forwardCoolingDown;
|
|
344
|
+
/** Park the dedicated connection for one alias and log the downgrade, once. */
|
|
345
|
+
private blockForward;
|
|
346
|
+
/** Log one alias's forward downgrade to the shared connection, once. */
|
|
347
|
+
private noteForwardFallback;
|
|
168
348
|
/** Run one callback with a fresh SFTP session (closed afterwards). */
|
|
169
349
|
withSftp<T>(alias: string, fn: (sftp: SFTPWrapper) => Promise<T>, opts?: SftpOptions): Promise<T>;
|
|
170
350
|
/**
|
|
@@ -231,6 +411,9 @@ export declare class RemotePool {
|
|
|
231
411
|
* place that can still see the session, and a late one would otherwise leak a
|
|
232
412
|
* server-side channel that no slot or hold accounts for (the caller has long
|
|
233
413
|
* returned its own and moved on).
|
|
414
|
+
*
|
|
415
|
+
* `alias`/`map` name the connection the session rides, so the channel it holds
|
|
416
|
+
* is counted on the right lane (see `countChannel`).
|
|
234
417
|
*/
|
|
235
418
|
private openSession;
|
|
236
419
|
/**
|
|
@@ -244,6 +427,10 @@ export declare class RemotePool {
|
|
|
244
427
|
/**
|
|
245
428
|
* Open the browse session: a channel slot + a connection hold + the SFTP
|
|
246
429
|
* session itself, all released together by evictBrowse().
|
|
430
|
+
*
|
|
431
|
+
* The lane is chosen HERE, once per session, and recorded on the state: the
|
|
432
|
+
* eviction path must give the slot and the hold back to the connection that
|
|
433
|
+
* actually served the session (dedicated SFTP, or the shared fallback).
|
|
247
434
|
*/
|
|
248
435
|
private openBrowse;
|
|
249
436
|
/** One completed browse operation: idle-close the channel when it is unused. */
|
|
@@ -260,11 +447,25 @@ export declare class RemotePool {
|
|
|
260
447
|
private evictBrowse;
|
|
261
448
|
private browseState;
|
|
262
449
|
/**
|
|
263
|
-
* Take one channel slot for `alias
|
|
264
|
-
* The wait is bounded: waiting forever behind a peer
|
|
265
|
-
* worse than a readable error naming the cause
|
|
450
|
+
* Take one channel slot for `alias` on the budget `slots` names, waiting FIFO
|
|
451
|
+
* when the limit is reached. The wait is bounded: waiting forever behind a peer
|
|
452
|
+
* that never finishes is worse than a readable error naming the cause.
|
|
453
|
+
*
|
|
454
|
+
* `slots` defaults to the SHARED connection's exec budget — the table every
|
|
455
|
+
* caller meant before the lanes existed; dedicated-lane callers pass theirs.
|
|
266
456
|
*/
|
|
267
457
|
private acquireSlot;
|
|
458
|
+
/**
|
|
459
|
+
* The ceiling and the wording of one budget.
|
|
460
|
+
*
|
|
461
|
+
* The TABLE is the budget's identity: a caller that hands in a table gets that
|
|
462
|
+
* budget's own ceiling AND its own nouns, so a full network lane says "2
|
|
463
|
+
* network operations already hold channels" and a full git lane says "2 git
|
|
464
|
+
* commands already hold channels" instead of borrowing the exec sentence — a
|
|
465
|
+
* user reading "5 operations" about a two-slot lane would go looking for
|
|
466
|
+
* operations that do not exist. A new budget is described here, once.
|
|
467
|
+
*/
|
|
468
|
+
private budgetOf;
|
|
268
469
|
/**
|
|
269
470
|
* Take one channel slot only if one is free RIGHT NOW; never queue.
|
|
270
471
|
*
|
|
@@ -276,7 +477,7 @@ export declare class RemotePool {
|
|
|
276
477
|
* would just move the wait.
|
|
277
478
|
*/
|
|
278
479
|
private tryAcquireSlot;
|
|
279
|
-
/** Give a slot back, handing it straight to the longest
|
|
480
|
+
/** Give a slot back to its budget, handing it straight to the longest waiter. */
|
|
280
481
|
private releaseSlot;
|
|
281
482
|
private slotState;
|
|
282
483
|
/**
|
|
@@ -305,10 +506,78 @@ export declare class RemotePool {
|
|
|
305
506
|
private hold;
|
|
306
507
|
private holdIn;
|
|
307
508
|
private release;
|
|
509
|
+
/**
|
|
510
|
+
* Count one SSH channel that is now open on a pooled connection, and give the
|
|
511
|
+
* number back when the channel closes.
|
|
512
|
+
*
|
|
513
|
+
* `held` is NOT this number (see `Pooled.channels`): a jump tunnel pins the
|
|
514
|
+
* jump host twice for its single channel, and `stats()` reports both, so the
|
|
515
|
+
* monitor page never prints a hold count as a channel count. The close listener
|
|
516
|
+
* mutates the entry OBJECT it was registered on, so a channel that outlives its
|
|
517
|
+
* entry cannot decrement the counter of a successor entry.
|
|
518
|
+
*
|
|
519
|
+
* The entry is looked up when the channel is COUNTED, so a session that answers
|
|
520
|
+
* pathologically late (after `drop()` and a fresh dial) is charged to the
|
|
521
|
+
* successor entry and given back when it closes. Accepted: the window needs a
|
|
522
|
+
* reply that outlives a host edit, the number is diagnostic, and the pair is
|
|
523
|
+
* still symmetric (one increment, one decrement).
|
|
524
|
+
*/
|
|
525
|
+
private countChannel;
|
|
308
526
|
private releaseIn;
|
|
309
527
|
private acquire;
|
|
310
528
|
/** `acquire` for the dedicated PTY connection map. */
|
|
311
529
|
private acquireShell;
|
|
530
|
+
/**
|
|
531
|
+
* `acquire` for the dedicated port-forward connection map.
|
|
532
|
+
*
|
|
533
|
+
* `quiet`: a dedicated forward connection is an OPTIMIZATION. If the server
|
|
534
|
+
* refuses it (MaxStartups, `MaxSessions`, a per-source limit) the forward still
|
|
535
|
+
* works over the shared connection, so the shared link is healthy — painting
|
|
536
|
+
* the connection chip red here would send the user to debug a network that is
|
|
537
|
+
* fine (and `forwardOut` reports the rule's own error separately).
|
|
538
|
+
*
|
|
539
|
+
* The dial also gets its OWN short budget ({@link FORWARD_DEDICATED_BUDGET_MS}):
|
|
540
|
+
* a server that silently drops the extra connection would otherwise make every
|
|
541
|
+
* forward channel wait the full connect watchdog before falling back. The
|
|
542
|
+
* abandoned dial keeps running — if it eventually succeeds the connection is
|
|
543
|
+
* pooled and the next channel uses it; its failure is already handled inside
|
|
544
|
+
* `acquireIn`.
|
|
545
|
+
*/
|
|
546
|
+
private acquireForward;
|
|
547
|
+
/**
|
|
548
|
+
* Take the connection a FILE operation should ride: the dedicated SFTP one,
|
|
549
|
+
* else the shared one (recorded as the fallback).
|
|
550
|
+
*
|
|
551
|
+
* Same three-part shape as the PTY/forward precedents, for the same reasons:
|
|
552
|
+
*
|
|
553
|
+
* 1. `quiet` on the dial — a dedicated connection is an optional isolation, so
|
|
554
|
+
* the server refusing it (MaxStartups, a per-user limit) says nothing about
|
|
555
|
+
* the shared link and must not paint the connection chip red.
|
|
556
|
+
* 2. A short own budget ({@link SFTP_DEDICATED_BUDGET_MS}) — browsing is one
|
|
557
|
+
* request per folder, so waiting out the 45 s connect watchdog before falling
|
|
558
|
+
* back would freeze the explorer. The abandoned dial keeps running: if it
|
|
559
|
+
* eventually succeeds the connection is pooled and the next request uses it.
|
|
560
|
+
* 3. A cooldown ({@link SFTP_DEDICATED_BLOCK_MS}) — without it every browse
|
|
561
|
+
* request would pay that budget again. A success or `drop()` clears it.
|
|
562
|
+
*
|
|
563
|
+
* The shared fallback's own dial failure is NOT quiet (it is a real link
|
|
564
|
+
* failure and `acquire` reports it as one).
|
|
565
|
+
*/
|
|
566
|
+
private acquireSftp;
|
|
567
|
+
/** The pooled map behind a lane: the dedicated SFTP connection, or the shared one. */
|
|
568
|
+
private laneConns;
|
|
569
|
+
/** The channel budget behind a lane: each connection has its own `MaxSessions`. */
|
|
570
|
+
private laneSlots;
|
|
571
|
+
/**
|
|
572
|
+
* Is this alias's dedicated SFTP connection in its short cooldown?
|
|
573
|
+
*
|
|
574
|
+
* Expired entries are dropped eagerly so the map cannot grow per alias forever.
|
|
575
|
+
*/
|
|
576
|
+
private sftpCoolingDown;
|
|
577
|
+
/** Park the dedicated SFTP connection for one alias and log the downgrade, once. */
|
|
578
|
+
private blockSftp;
|
|
579
|
+
/** Log one alias's file-operation downgrade to the shared connection, once. */
|
|
580
|
+
private noteSftpFallback;
|
|
312
581
|
private acquireIn;
|
|
313
582
|
/** Evict ONE alias from ONE map (host removal drops both maps explicitly). */
|
|
314
583
|
private evictFrom;
|
|
@@ -321,5 +590,65 @@ export declare class RemotePool {
|
|
|
321
590
|
* overrides it.
|
|
322
591
|
*/
|
|
323
592
|
private makeClient;
|
|
593
|
+
/**
|
|
594
|
+
* Open the transport `alias`'s configured route requires, WITHOUT dialing SSH.
|
|
595
|
+
*
|
|
596
|
+
* This is the part of {@link dial} that turns a `ResolvedProxy` decision into a
|
|
597
|
+
* socket: nothing for a direct route, a tunnel socket for a proxy, and a
|
|
598
|
+
* `direct-tcpip` channel riding the jump host's pooled connection for a jump.
|
|
599
|
+
* Extracted so a SECOND ssh2 dialer — p2's helper transport, which owns its own
|
|
600
|
+
* `Client` — takes exactly the same route instead of a bare direct connection
|
|
601
|
+
* (otherwise a host reachable only through a proxy or jump host answers exec and
|
|
602
|
+
* SFTP but fails every file/Git fast path).
|
|
603
|
+
*
|
|
604
|
+
* `route` may be passed in when the caller has already resolved it and needs the
|
|
605
|
+
* decision for its own purposes (`dial` reports the egress it settled on): the
|
|
606
|
+
* default resolves it from the store.
|
|
607
|
+
*
|
|
608
|
+
* The returned `release` is IDEMPOTENT and belongs to the caller: it tears down
|
|
609
|
+
* the tunnel (destroys the proxy socket / closes the channel and gives the jump
|
|
610
|
+
* host's hold back). It must be called exactly once by whoever owns the socket —
|
|
611
|
+
* on failure, on close, and on dispose. A direct route has nothing to release,
|
|
612
|
+
* so it gets a no-op.
|
|
613
|
+
*/
|
|
614
|
+
private openRoute;
|
|
615
|
+
/**
|
|
616
|
+
* The routed transport for `alias`, for a caller that dials its OWN ssh2 client.
|
|
617
|
+
*
|
|
618
|
+
* Same decision, same error layering (`proxy auth failed: …`, `jump host "x"
|
|
619
|
+
* failed: …`), same socket as a pooled connection would ride — p2's helper
|
|
620
|
+
* transport uses this so "reachable only through the jump host" stops meaning
|
|
621
|
+
* "exec works, files do not".
|
|
622
|
+
*
|
|
623
|
+
* **The caller owns the result**: when `sock` is set, ssh2 must be given `{ sock }`
|
|
624
|
+
* and NOT `host`/`port` (both together let ssh2 choose between dialing the target
|
|
625
|
+
* itself and riding the tunnel). `release` must be called exactly once — on
|
|
626
|
+
* failure, on the connection's close, and on dispose — or the jump host's hold
|
|
627
|
+
* leaks and the proxy socket stays open.
|
|
628
|
+
*/
|
|
629
|
+
openRoutedSocket(alias: string): Promise<RoutedDial>;
|
|
630
|
+
/**
|
|
631
|
+
* Open one SSH connection, through whatever route the store resolves.
|
|
632
|
+
*
|
|
633
|
+
* Three routes, and only the first is the pre-proxy code path:
|
|
634
|
+
* - `direct`: unchanged (`host` / `port` in the connect config);
|
|
635
|
+
* - `proxy`: the proxy module builds the tunnel and ssh2 rides the returned
|
|
636
|
+
* socket (`sock`), so `host`/`port` are deliberately omitted (ssh2 ignores
|
|
637
|
+
* them when `sock` is present);
|
|
638
|
+
* - `jump`: the tunnel is a `direct-tcpip` channel on the JUMP host's pooled
|
|
639
|
+
* connection, held for as long as the client lives. Its close/error handlers
|
|
640
|
+
* close that channel and give the hold back — a leak here would pin the jump
|
|
641
|
+
* host's connection forever.
|
|
642
|
+
*
|
|
643
|
+
* Every failure is a DIAL failure, so it keeps the existing `markError`
|
|
644
|
+
* semantics; only the message is layered, so the user can tell which hop broke:
|
|
645
|
+
* `proxy auth failed: …`, `proxy refused: …`, `jump host "x" failed: …`.
|
|
646
|
+
*
|
|
647
|
+
* `report` receives the route this dial ACTUALLY settled on, once and only on
|
|
648
|
+
* success — a caller that asked "did this go through the jump host?" must not
|
|
649
|
+
* be answered from a configuration that may have changed since. It is a
|
|
650
|
+
* callback rather than a wider return type so the seam keeps returning the
|
|
651
|
+
* `Client` the existing callers (and gates) hand around.
|
|
652
|
+
*/
|
|
324
653
|
private dial;
|
|
325
654
|
}
|