asyx 0.10.1 → 0.11.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/AGENTS.md +42 -0
- package/bin/asyx.js +1 -1
- package/package.json +3 -2
- package/src/commands/account.js +80 -71
- package/src/commands/app.js +317 -151
- package/src/commands/in-use-messages.js +47 -48
- package/src/commands/mqtt-broker.js +36 -49
- package/src/commands/mqtt.js +111 -149
- package/src/commands/name.js +24 -22
- package/src/commands/reject-messages.js +123 -123
- package/src/commands/setup.js +107 -131
- package/src/commands/sts.js +45 -61
- package/src/commands/tunnel.js +853 -932
- package/src/commands/validate-target-host.js +36 -59
- package/src/lib/aws-iot-config.js +26 -24
- package/src/lib/certs.js +15 -18
- package/src/lib/csr.js +107 -182
- package/src/lib/device.js +26 -37
- package/src/lib/ids.js +1 -2
- package/src/lib/naming.js +74 -68
- package/src/lib/pairing.js +10 -11
- package/src/lib/shared-transport.js +5 -9
- package/src/main.js +63 -53
- package/vendor/tunnel-core/dist/control-plane/MqttControlPlaneClient.js +25 -287
- package/vendor/tunnel-core/dist/control-plane/MqttControlPlaneTransport.js +0 -72
- package/vendor/tunnel-core/dist/control-plane/session.js +0 -20
- package/vendor/tunnel-core/dist/errors.js +0 -19
- package/vendor/tunnel-core/dist/flows/account.js +1 -6
- package/vendor/tunnel-core/dist/flows/goodbye.js +0 -4
- package/vendor/tunnel-core/dist/flows/http.js +24 -112
- package/vendor/tunnel-core/dist/flows/identity.js +11 -10
- package/vendor/tunnel-core/dist/flows/in-use.js +0 -6
- package/vendor/tunnel-core/dist/flows/reopen.js +0 -4
- package/vendor/tunnel-core/dist/flows/tcp.js +18 -84
- package/vendor/tunnel-core/dist/flows/udp.js +15 -52
- package/vendor/tunnel-core/dist/lib/fingerprint.js +38 -42
- package/vendor/tunnel-core/dist/lib/jwt-verifier.js +14 -67
- package/vendor/tunnel-core/dist/lib/logger.js +1 -9
- package/vendor/tunnel-core/dist/lib/refresh-helpers.js +1 -22
- package/vendor/tunnel-core/dist/lifecycle.js +1 -8
- package/vendor/tunnel-core/dist/mqtt/awaiter-map.js +1 -53
- package/vendor/tunnel-core/dist/mqtt/events/handlers.js +10 -64
- package/vendor/tunnel-core/dist/mqtt/events/index.js +3 -36
- package/vendor/tunnel-core/dist/mqtt/events/schemas.js +0 -1
- package/vendor/tunnel-core/dist/mqtt/ingress.js +0 -60
- package/vendor/tunnel-core/dist/state/assignment.js +6 -122
- package/vendor/tunnel-core/dist/state/instance-registry.js +0 -63
- package/vendor/tunnel-core/dist/tcp-v1/framing.js +2 -64
- package/vendor/tunnel-core/dist/tunnel/http-tunnel.js +64 -331
- package/vendor/tunnel-core/dist/tunnel/httpws-constants.js +5 -14
- package/vendor/tunnel-core/dist/tunnel/reconnect.js +10 -50
- package/vendor/tunnel-core/dist/tunnel/request-sink.js +0 -16
- package/vendor/tunnel-core/dist/tunnel/tcp-tunnel.js +32 -195
- package/vendor/tunnel-core/dist/tunnel/udp-tunnel.js +28 -153
- package/vendor/tunnel-core/dist/tunnel/ws-control.js +4 -39
- package/vendor/tunnel-core/dist/types.js +0 -2
- package/vendor/tunnel-core/dist/udp-v1/framing.js +2 -64
- package/vendor/tunnel-core/package.json +0 -25
- package/vendor/tunnel-core/dist/control-plane/MqttControlPlaneClient.d.ts +0 -273
- package/vendor/tunnel-core/dist/control-plane/MqttControlPlaneTransport.d.ts +0 -79
- package/vendor/tunnel-core/dist/control-plane/session.d.ts +0 -55
- package/vendor/tunnel-core/dist/errors.d.ts +0 -49
- package/vendor/tunnel-core/dist/flows/account.d.ts +0 -24
- package/vendor/tunnel-core/dist/flows/goodbye.d.ts +0 -10
- package/vendor/tunnel-core/dist/flows/http.d.ts +0 -61
- package/vendor/tunnel-core/dist/flows/identity.d.ts +0 -23
- package/vendor/tunnel-core/dist/flows/in-use.d.ts +0 -27
- package/vendor/tunnel-core/dist/flows/reopen.d.ts +0 -9
- package/vendor/tunnel-core/dist/flows/tcp.d.ts +0 -85
- package/vendor/tunnel-core/dist/flows/udp.d.ts +0 -52
- package/vendor/tunnel-core/dist/lib/adapt-logger.d.ts +0 -2
- package/vendor/tunnel-core/dist/lib/fingerprint.d.ts +0 -145
- package/vendor/tunnel-core/dist/lib/jwt-verifier.d.ts +0 -27
- package/vendor/tunnel-core/dist/lib/logger.d.ts +0 -9
- package/vendor/tunnel-core/dist/lib/refresh-helpers.d.ts +0 -16
- package/vendor/tunnel-core/dist/lifecycle.d.ts +0 -24
- package/vendor/tunnel-core/dist/mqtt/awaiter-map.d.ts +0 -56
- package/vendor/tunnel-core/dist/mqtt/events/handlers.d.ts +0 -60
- package/vendor/tunnel-core/dist/mqtt/events/index.d.ts +0 -1
- package/vendor/tunnel-core/dist/mqtt/events/schemas.d.ts +0 -498
- package/vendor/tunnel-core/dist/mqtt/ingress.d.ts +0 -63
- package/vendor/tunnel-core/dist/state/assignment.d.ts +0 -136
- package/vendor/tunnel-core/dist/state/instance-registry.d.ts +0 -88
- package/vendor/tunnel-core/dist/tcp-v1/framing.d.ts +0 -43
- package/vendor/tunnel-core/dist/tunnel/http-tunnel.d.ts +0 -140
- package/vendor/tunnel-core/dist/tunnel/httpws-constants.d.ts +0 -13
- package/vendor/tunnel-core/dist/tunnel/reconnect.d.ts +0 -76
- package/vendor/tunnel-core/dist/tunnel/request-sink.d.ts +0 -40
- package/vendor/tunnel-core/dist/tunnel/tcp-tunnel.d.ts +0 -92
- package/vendor/tunnel-core/dist/tunnel/udp-tunnel.d.ts +0 -93
- package/vendor/tunnel-core/dist/tunnel/ws-control.d.ts +0 -22
- package/vendor/tunnel-core/dist/types.d.ts +0 -24
- package/vendor/tunnel-core/dist/udp-v1/framing.d.ts +0 -41
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* @see relay/src/httpws-constants.js
|
|
8
|
-
*/
|
|
9
|
-
// S-3: Protocol constants alignment
|
|
10
|
-
export const HTTPWS_V2_TARGET_CHUNK_BYTES = 65_536; // 64 KiB target chunk size
|
|
11
|
-
export const HTTPWS_V2_MAX_CHUNK_BYTES = 262_144; // 256 KiB hard maximum chunk size
|
|
12
|
-
export const HTTPWS_V2_PROTOCOL_ERROR_CLOSE_CODE = 1002; // WebSocket close code for protocol errors
|
|
13
|
-
export const HTTPWS_V2_PROTOCOL_ERROR_REASON = 'httpws_v2_without_negotiation'; // Close reason string
|
|
14
|
-
export const HTTP_BODY_CHUNK = 0x20; // Frame type for HTTP body chunks (v2)
|
|
1
|
+
export const HTTPWS_V2_TARGET_CHUNK_BYTES = 65_536;
|
|
2
|
+
export const HTTPWS_V2_MAX_CHUNK_BYTES = 262_144;
|
|
3
|
+
export const HTTPWS_V2_PROTOCOL_ERROR_CLOSE_CODE = 1002;
|
|
4
|
+
export const HTTPWS_V2_PROTOCOL_ERROR_REASON = 'httpws_v2_without_negotiation';
|
|
5
|
+
export const HTTP_BODY_CHUNK = 0x20;
|
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
// Story 11.2: reconnect for TCP and UDP tunnels.
|
|
2
|
-
//
|
|
3
|
-
// When the relay connection of an established TCP or UDP tunnel drops, the tunnel
|
|
4
|
-
// reconnects to the same relay and lease with the newest assignment token instead
|
|
5
|
-
// of ending the CLI. Everything bound to the old connection (TCP streams and their
|
|
6
|
-
// local sockets, UDP flows and their sockets, partial frames) is discarded first,
|
|
7
|
-
// so traffic from before the drop can never be delivered on the new connection.
|
|
8
|
-
//
|
|
9
|
-
// Settings (environment):
|
|
10
|
-
// ASYX_TUNNEL_RECONNECT=0 disable (the tunnel ends on a drop, as before)
|
|
11
|
-
// ASYX_TUNNEL_RECONNECT_MAX_MS give up after this long without a connection (default 15 min)
|
|
12
|
-
// ASYX_TUNNEL_RECONNECT_MAX_DELAY_MS longest wait between attempts (default 5000)
|
|
13
1
|
export const DEFAULT_INITIAL_DELAY_MS = 250;
|
|
14
2
|
export const DEFAULT_MAX_DELAY_MS = 5000;
|
|
15
3
|
export const DEFAULT_MAX_OUTAGE_MS = 15 * 60 * 1000;
|
|
@@ -21,13 +9,6 @@ function envInt(env, name, fallback) {
|
|
|
21
9
|
const v = parseInt(env[name] ?? '', 10);
|
|
22
10
|
return Number.isFinite(v) && v > 0 ? v : fallback;
|
|
23
11
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Decide what an established connection's close means.
|
|
26
|
-
* Close code 4000 is the relay's application code: "lease_closed" (the control plane
|
|
27
|
-
* ended the lease) and "lease_reconnected" (another connection took the lease over)
|
|
28
|
-
* must not be fought; anything else (relay restart, network loss, 1006, 1001, 1011,
|
|
29
|
-
* protocol errors) is retried.
|
|
30
|
-
*/
|
|
31
12
|
export function classifyDrop(code, reason) {
|
|
32
13
|
const r = String(reason || '');
|
|
33
14
|
if (code === 4000 && r === 'lease_closed')
|
|
@@ -36,7 +17,6 @@ export function classifyDrop(code, reason) {
|
|
|
36
17
|
return { fatal: true, reason: 'replaced_by_another_connection' };
|
|
37
18
|
return { fatal: false, reason: `ws_close_${code}` };
|
|
38
19
|
}
|
|
39
|
-
/** HTTP status from a ws handshake error ("Unexpected server response: 403"). */
|
|
40
20
|
export function httpStatusOf(err) {
|
|
41
21
|
if (!err)
|
|
42
22
|
return null;
|
|
@@ -45,13 +25,6 @@ export function httpStatusOf(err) {
|
|
|
45
25
|
const m = /Unexpected server response: (\d{3})/.exec(err.message || '');
|
|
46
26
|
return m ? Number(m[1]) : null;
|
|
47
27
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Decide what a failed reconnect attempt means.
|
|
50
|
-
* 401/403 and token verification failures are counted as authorization failures
|
|
51
|
-
* (the token expired or the lease was closed); a few in a row end the tunnel.
|
|
52
|
-
* 409 means the relay still holds the old connection for the lease; retry.
|
|
53
|
-
* 400 means the request itself is malformed; retrying cannot help.
|
|
54
|
-
*/
|
|
55
28
|
export function classifyFailure(err) {
|
|
56
29
|
const status = httpStatusOf(err);
|
|
57
30
|
if (status === 400)
|
|
@@ -59,7 +32,6 @@ export function classifyFailure(err) {
|
|
|
59
32
|
if (status === 401 || status === 403)
|
|
60
33
|
return { fatal: false, auth: true, reason: `http_${status}` };
|
|
61
34
|
if (err && err.code === 'UDP_RELAY_UNAVAILABLE' && /JWT verification failed/.test(err.message || '')) {
|
|
62
|
-
// Failing to fetch the JWKS (network) is not a token problem: keep retrying
|
|
63
35
|
const cause = err.cause || {};
|
|
64
36
|
const fetchProblem = /JWKS|fetch|timeout|ECONN|ENOTFOUND|EAI_AGAIN|network/i.test(`${cause.code || ''} ${cause.message || ''}`)
|
|
65
37
|
&& !/expired|signature|claim/i.test(`${cause.code || ''} ${cause.message || ''}`);
|
|
@@ -69,7 +41,6 @@ export function classifyFailure(err) {
|
|
|
69
41
|
}
|
|
70
42
|
return { fatal: false, auth: false, reason: status ? `http_${status}` : (err?.code || 'connect_failed') };
|
|
71
43
|
}
|
|
72
|
-
/** Seconds-since-epoch exp claim of a JWT, or null. */
|
|
73
44
|
export function jwtExp(jwt) {
|
|
74
45
|
try {
|
|
75
46
|
const part = String(jwt).split('.')[1];
|
|
@@ -80,29 +51,19 @@ export function jwtExp(jwt) {
|
|
|
80
51
|
return null;
|
|
81
52
|
}
|
|
82
53
|
}
|
|
83
|
-
/**
|
|
84
|
-
* Runs the reconnect loop for one tunnel.
|
|
85
|
-
* connect(): Promise resolving when a new connection is open, rejecting otherwise.
|
|
86
|
-
* onGiveUp(reason): called once if the tunnel cannot be reconnected.
|
|
87
|
-
* onAuthFailure(): optional (Story 10.9). Called on the first authorization failure of a
|
|
88
|
-
* streak; it may fetch a new assignment (for example after the tenant moved to another
|
|
89
|
-
* relay, where the old token's relay no longer matches). If it returns true, the streak
|
|
90
|
-
* is reset and the next attempt uses the new assignment at once.
|
|
91
|
-
*/
|
|
92
54
|
export class Reconnector {
|
|
93
55
|
constructor({ kind, log, connect, onGiveUp, env = process.env, initialDelayMs = DEFAULT_INITIAL_DELAY_MS, maxDelayMs = envInt(env, 'ASYX_TUNNEL_RECONNECT_MAX_DELAY_MS', DEFAULT_MAX_DELAY_MS), maxOutageMs = envInt(env, 'ASYX_TUNNEL_RECONNECT_MAX_MS', DEFAULT_MAX_OUTAGE_MS), maxAuthFailures = DEFAULT_MAX_AUTH_FAILURES, onAuthFailure = null, now = () => Date.now(), sleep = (ms) => new Promise((r) => setTimeout(r, ms)), }) {
|
|
94
|
-
|
|
95
|
-
/** @type {string} */ this.kind = kind;
|
|
56
|
+
this.kind = kind;
|
|
96
57
|
this.log = log;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
58
|
+
this.connect = connect;
|
|
59
|
+
this.onGiveUp = onGiveUp;
|
|
60
|
+
this.initialDelayMs = initialDelayMs;
|
|
61
|
+
this.maxDelayMs = maxDelayMs;
|
|
62
|
+
this.maxOutageMs = maxOutageMs;
|
|
63
|
+
this.maxAuthFailures = maxAuthFailures;
|
|
64
|
+
this.onAuthFailure = onAuthFailure;
|
|
65
|
+
this.now = now;
|
|
66
|
+
this.sleep = sleep;
|
|
106
67
|
this.running = false;
|
|
107
68
|
this.stopped = false;
|
|
108
69
|
this.reconnects = 0;
|
|
@@ -113,7 +74,6 @@ export class Reconnector {
|
|
|
113
74
|
delayFor(attempt) {
|
|
114
75
|
return Math.min(this.maxDelayMs, this.initialDelayMs * 2 ** attempt);
|
|
115
76
|
}
|
|
116
|
-
/** Start reconnecting after a drop. Resolves when connected, given up or stopped. */
|
|
117
77
|
async run(dropReason) {
|
|
118
78
|
if (this.running || this.stopped)
|
|
119
79
|
return;
|
|
@@ -1,21 +1,8 @@
|
|
|
1
|
-
// Story 12.1 c3 (TypeScript in r3): where an HTTP tunnel sends the requests it receives from the relay.
|
|
2
|
-
//
|
|
3
|
-
// A request sink has one method:
|
|
4
|
-
// request({ method, path, headers }, onResponse) -> a writable request object with the
|
|
5
|
-
// http.ClientRequest surface the tunnel uses (write, end, on('error'), destroy), calling
|
|
6
|
-
// onResponse(res) with a readable response that has statusCode, headers and the stream events.
|
|
7
|
-
//
|
|
8
|
-
// LocalPortSink is the first implementation: it forwards to a service listening on localhost:<port>,
|
|
9
|
-
// which is what the CLI has always done. Handler mode (requests answered in-process by the
|
|
10
|
-
// developer's code, deferred to a later story) can implement the same interface without changing
|
|
11
|
-
// the tunnel or the SDK's API.
|
|
12
1
|
import http from 'node:http';
|
|
13
|
-
/** The only addresses a local-port sink connects to, in order: IPv4 loopback, then IPv6 loopback. */
|
|
14
2
|
export const LOOPBACK_ADDRESSES = Object.freeze([
|
|
15
3
|
{ address: '127.0.0.1', family: 4 },
|
|
16
4
|
{ address: '::1', family: 6 },
|
|
17
5
|
]);
|
|
18
|
-
/** dns.lookup replacement for the sink: ignores the name and returns loopback only. */
|
|
19
6
|
export function loopbackLookup(_hostname, options, callback) {
|
|
20
7
|
const cb = (typeof options === 'function' ? options : callback);
|
|
21
8
|
const all = typeof options === 'object' && options !== null && options.all;
|
|
@@ -30,9 +17,6 @@ export class LocalPortSink {
|
|
|
30
17
|
this.port = port;
|
|
31
18
|
}
|
|
32
19
|
request({ method, path, headers }, onResponse) {
|
|
33
|
-
// Defect 11.30: 'localhost' resolves to ::1 first on macOS with Node 18, so a service listening only on
|
|
34
|
-
// 127.0.0.1 refused the connection. Try 127.0.0.1, then ::1, within the same request (autoSelectFamily
|
|
35
|
-
// with a loopback-only lookup; Node 18.13+). Never any other address.
|
|
36
20
|
return http.request({ hostname: 'localhost', port: this.port, path, method, headers: headers,
|
|
37
21
|
lookup: loopbackLookup, autoSelectFamily: true }, onResponse);
|
|
38
22
|
}
|