dsh-mobile-plugin 0.5.80 → 0.5.82
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/docs/extension-authoring.md +32 -0
- package/lib/frpc/provision.cjs +21 -17
- package/lib/frpc/runner.cjs +193 -165
- package/lib/impl.js +66 -81
- package/lib/mirror/pusher.cjs +60 -10
- package/lib/mobile/auth.js +20 -5
- package/lib/mobile/claim-identity.js +116 -0
- package/lib/mobile/events.js +2 -1
- package/lib/mobile/feedback.js +6 -5
- package/lib/mobile/file-read.js +4 -2
- package/lib/mobile/mux.js +148 -21
- package/lib/mobile/paired-devices.js +2 -1
- package/lib/mobile/pairing.js +3 -2
- package/lib/mobile/permissions.js +2 -0
- package/lib/mobile/relay-control.js +27 -33
- package/lib/mobile/session-changes.js +8 -2
- package/lib/mobile/session-delivery.js +5 -1
- package/lib/mobile/session-file.js +46 -25
- package/lib/mobile/session-head.js +7 -3
- package/lib/mobile/session-snapshot.js +5 -1
- package/lib/mobile/session-step.js +13 -7
- package/lib/mobile/session-stop-summary.js +6 -1
- package/lib/mobile/stream-registry.js +48 -53
- package/lib/mobile/stream.js +17 -2
- package/lib/mobile/uploads.js +190 -163
- package/lib/p2p/session.cjs +169 -70
- package/lib/p2p/wiring.cjs +4 -2
- package/lib/panel/index.html +17 -15
- package/lib/relay/blob-upload.cjs +103 -0
- package/lib/relay/config-store.js +81 -0
- package/lib/relay/control.js +132 -48
- package/lib/relay/core.js +34 -14
- package/lib/relay/identity-rotate.cjs +27 -0
- package/lib/relay/lan-proxy.js +71 -12
- package/lib/relay/pairing-payload.cjs +14 -5
- package/lib/relay/preview-webapp.cjs +150 -0
- package/lib/relay/preview.js +35 -8
- package/lib/relay/protocol.js +6 -4
- package/lib/relay/relay-probe.js +112 -21
- package/lib/relay/tunnel-forwarder.cjs +4 -2
- package/lib/relay/tunnel.js +39 -8
- package/lib/remote/controller.cjs +33 -3
- package/lib/remote/host-control.cjs +11 -2
- package/lib/remote/router.cjs +83 -33
- package/lib/remote/transport.cjs +32 -5
- package/lib/remote/tunnel-helper.cjs +51 -25
- package/lib/remote/tunnels.cjs +27 -3
- package/lib/routes/control-plane.js +25 -17
- package/lib/routes/mobile-api.js +32 -18
- package/lib/shared/fresh-request.js +32 -1
- package/lib/shared/route-order.cjs +118 -132
- package/lib/shared/sse-write.js +29 -10
- package/lib/shared/via-header.js +5 -12
- package/lib/shell/transport-host.js +15 -1
- package/lib/sidecar-facade-worker.cjs +176 -118
- package/lib/sidecar-facade.cjs +6 -1
- package/lib/sidecar-lifecycle.cjs +6 -2
- package/lib/tailcat/host-process.cjs +32 -8
- package/lib/tailcat/session.cjs +27 -10
- package/package.json +6 -6
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// blob 分片逐片等落盘回执,背压保留当前片,关闭时拒绝未决上传。
|
|
2
|
+
'use strict';
|
|
3
|
+
const { performance } = require('node:perf_hooks');
|
|
4
|
+
const { T } = require('./protocol.js');
|
|
5
|
+
|
|
6
|
+
const CHUNK_BYTES = 48 * 1024;
|
|
7
|
+
const ACK_TIMEOUT_MS = 90_000;
|
|
8
|
+
const BUFFER_WAIT_MS = 30_000;
|
|
9
|
+
const LOW_WATER_BYTES = 8 * 1024 * 1024;
|
|
10
|
+
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
11
|
+
|
|
12
|
+
class BlobUpload {
|
|
13
|
+
constructor(tunnel) {
|
|
14
|
+
this.tunnel = tunnel;
|
|
15
|
+
this.capability = null;
|
|
16
|
+
this.active = null;
|
|
17
|
+
this.nextId = 0;
|
|
18
|
+
this.generation = 0;
|
|
19
|
+
}
|
|
20
|
+
configure(value) {
|
|
21
|
+
this.close('blob connection changed');
|
|
22
|
+
this.capability = value && Number.isSafeInteger(value.maxChunkBytes) && value.maxChunkBytes > 0
|
|
23
|
+
&& Number.isSafeInteger(value.maxBlobBytes) && value.maxBlobBytes > 0
|
|
24
|
+
? { maxChunkBytes: Math.min(CHUNK_BYTES, value.maxChunkBytes), maxBlobBytes: value.maxBlobBytes } : null;
|
|
25
|
+
}
|
|
26
|
+
close(reason = 'blob tunnel closed') {
|
|
27
|
+
this.generation += 1;
|
|
28
|
+
this.capability = null;
|
|
29
|
+
this.active?.reject?.(new Error(reason));
|
|
30
|
+
this.active = null;
|
|
31
|
+
}
|
|
32
|
+
onAck(id, value) {
|
|
33
|
+
const active = this.active;
|
|
34
|
+
if (!active || active.id !== id || !active.resolve) return;
|
|
35
|
+
if (!value || value.ok !== true) {
|
|
36
|
+
active.reject(new Error(value?.error || 'blob upload rejected'));
|
|
37
|
+
} else if (value.nextOffset !== active.expected || value.done !== active.final) {
|
|
38
|
+
active.reject(new Error('invalid blob upload acknowledgement'));
|
|
39
|
+
} else active.resolve(value);
|
|
40
|
+
}
|
|
41
|
+
async send(frame) {
|
|
42
|
+
if (this.active) throw new Error('blob upload already in progress');
|
|
43
|
+
if (!this.tunnel.connected) throw new Error('blob tunnel not connected');
|
|
44
|
+
// 凭据刷新与旧节点保持原id0语义;sent仍只表示旧协议入socket,不伪称落盘确认。
|
|
45
|
+
if (!this.capability || frame.cipher === '') {
|
|
46
|
+
if (this.tunnel.trySendJson(T.blobPut, 0, frame) !== 'sent') throw new Error('blob send backpressure or closed');
|
|
47
|
+
return { ok: true, legacy: true };
|
|
48
|
+
}
|
|
49
|
+
if (typeof frame.cipher !== 'string' || !/^[A-Za-z0-9_-]+={0,2}$/.test(frame.cipher)) throw new Error('invalid blob cipher');
|
|
50
|
+
const bytes = Buffer.from(frame.cipher, 'base64url');
|
|
51
|
+
const capability = this.capability;
|
|
52
|
+
if (!bytes.length || bytes.length > capability.maxBlobBytes) throw new Error('blob exceeds relay limit');
|
|
53
|
+
this.nextId = this.nextId >= 0xffffffff ? 1 : this.nextId + 1;
|
|
54
|
+
const active = { id: this.nextId, resolve: null, reject: null };
|
|
55
|
+
this.active = active;
|
|
56
|
+
const generation = this.generation;
|
|
57
|
+
try {
|
|
58
|
+
for (let offset = 0; offset < bytes.length;) {
|
|
59
|
+
const end = Math.min(bytes.length, offset + capability.maxChunkBytes);
|
|
60
|
+
const final = end === bytes.length;
|
|
61
|
+
const chunk = { offset, total: bytes.length, final, cipher: bytes.subarray(offset, end).toString('base64url') };
|
|
62
|
+
if (offset === 0) Object.assign(chunk, { scope: frame.scope, key: frame.key, creds: frame.creds });
|
|
63
|
+
await this.sendChunk(active, chunk, end, final, generation);
|
|
64
|
+
offset = end;
|
|
65
|
+
// 每片交还事件循环,HTTP/WS泵和控制帧都有发送机会。
|
|
66
|
+
await delay(0);
|
|
67
|
+
}
|
|
68
|
+
return { ok: true, done: true };
|
|
69
|
+
} finally {
|
|
70
|
+
if (this.active === active) this.active = null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async sendChunk(active, chunk, expected, final, generation) {
|
|
74
|
+
const deadline = performance.now() + BUFFER_WAIT_MS;
|
|
75
|
+
active.waiting = true;
|
|
76
|
+
while (true) {
|
|
77
|
+
if (generation !== this.generation || !this.tunnel.connected) throw new Error('blob tunnel closed');
|
|
78
|
+
if (performance.now() >= deadline) throw new Error('blob send backpressure timeout');
|
|
79
|
+
if (Number(this.tunnel.ws?.bufferedAmount || 0) > LOW_WATER_BYTES) { await delay(25); continue; }
|
|
80
|
+
// 先挂回执再发,允许同进程测试/快速回执;未发送的片没有丢失或前移offset。
|
|
81
|
+
let timer;
|
|
82
|
+
const ack = new Promise((resolve, reject) => {
|
|
83
|
+
active.expected = expected;
|
|
84
|
+
active.final = final;
|
|
85
|
+
active.resolve = resolve;
|
|
86
|
+
active.reject = reject;
|
|
87
|
+
timer = setTimeout(() => reject(new Error('blob acknowledgement timeout')), ACK_TIMEOUT_MS);
|
|
88
|
+
});
|
|
89
|
+
const result = this.tunnel.trySendJson(T.blobPut, active.id, chunk);
|
|
90
|
+
if (result === 'sent') {
|
|
91
|
+
active.waiting = false;
|
|
92
|
+
try { return await ack; }
|
|
93
|
+
finally { clearTimeout(timer); active.resolve = null; active.reject = null; }
|
|
94
|
+
}
|
|
95
|
+
clearTimeout(timer);
|
|
96
|
+
active.resolve = null;
|
|
97
|
+
active.reject = null;
|
|
98
|
+
if (result !== 'backpressure') throw new Error('blob send failed');
|
|
99
|
+
await delay(25);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
module.exports = { BlobUpload, CHUNK_BYTES };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// 远程控制配置的 schema 与投影:装配层从这里取,不把实现搬回去(状态仓外壳仍在 impl.js)。
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const z = require('@deepseek-ai/schemastery');
|
|
5
|
+
const core = require('./core.js');
|
|
6
|
+
const pairingApproval = require('./pairing-policy.js');
|
|
7
|
+
const permissions = require('../mobile/permissions.js');
|
|
8
|
+
|
|
9
|
+
const RemoteControlSettingsSchema = z.object({
|
|
10
|
+
enabled: z.boolean().default(false),
|
|
11
|
+
relayUrl: z.string().default(''),
|
|
12
|
+
// 完整的中转地址列表,`relayUrls[0]` 恒等于 `relayUrl`(见 docs/relay-multi-address.md)。
|
|
13
|
+
// 宿主从列表选择并注册一条线路,中选地址写回首项;手机只跟随当前注册线路。
|
|
14
|
+
relayUrls: z.array(z.string()).default([]),
|
|
15
|
+
lanEnabled: z.boolean().default(true),
|
|
16
|
+
lanPort: z.number().step(1).min(1024).max(65535).default(18787),
|
|
17
|
+
name: z.string().default(''),
|
|
18
|
+
// Pairing approval policy; see lib/relay/pairing-policy.js for the two modes and
|
|
19
|
+
// why 'code' is not the old popup. Kept in the config schema so /api/relay/config
|
|
20
|
+
// can change it, and so an unknown value is rejected on write.
|
|
21
|
+
pairingPolicy: z.union(pairingApproval.POLICIES.map(value => z.const(value))).default(pairingApproval.DEFAULT_POLICY),
|
|
22
|
+
// 新配对设备的权限档位(只读 / 可答审批 / 全权)。配对时在电脑侧选定,展开成 permissions
|
|
23
|
+
// 写进凭据记录(见 lib/mobile/permissions.js)。缺省 full = 与今天单 token 全给等价。
|
|
24
|
+
pairingTier: z.union(permissions.TIER_NAMES.map(t => z.const(t))).default(permissions.DEFAULT_TIER), approvalAutoReview: z.boolean().default(false), // 审批自动审阅档(默认关,见 mobile/auto-review.js)
|
|
25
|
+
// 是否把本机网络地址加密上报给「总控」(地址目录)。默认开 = 与历史行为一致;
|
|
26
|
+
// 关掉后宿主不再跑总控上报客户端,手机换网后拿不到这台电脑的新地址(见 relay/control.js)。
|
|
27
|
+
controlReportEnabled: z.boolean().default(true),
|
|
28
|
+
// 桌面设置页那两颗侧边栏图标(手机 / 电脑)的可见性。默认全开;老 relay.json 没这两格时
|
|
29
|
+
// 由 configOf 收成 true,界面不会在升级后突然少一颗。只给桌面控制面写,手机端配置口不收。
|
|
30
|
+
desktopPhoneIcon: z.boolean().default(true),
|
|
31
|
+
desktopComputerIcon: z.boolean().default(true),
|
|
32
|
+
// 中转注册密钥(对偶于中转的 TUNNEL_REGISTER_SECRET)。桌面版拿不到 shell
|
|
33
|
+
// 环境变量,所以它和其他配置一样存在 relay.json(0600),由 /api/relay/config
|
|
34
|
+
// 在回环上写入;status / pairing / 二维码都不回显它。
|
|
35
|
+
registerSecret: z.string().max(512).default(''),
|
|
36
|
+
// 手机优先用哪条地址:空 = 不指定(按宿主网卡优先级排)。选择只挪候选顺序、不删候选,
|
|
37
|
+
// 理由与边界见 relay/lan-network.cjs 的 orderCandidates 与 relay.json 那条地图条目。
|
|
38
|
+
preferredLanAddress: z.string().max(64).default(''),
|
|
39
|
+
// 用户手填的直连地址(`manualLanUrl`,内网穿透域名)也随二维码一起走,见 lan-network.cjs。
|
|
40
|
+
manualLanUrl: z.string().max(200).default(''),
|
|
41
|
+
// 用户手填的 IPv6 直连地址(`manualIpv6Url`,形如 `http://[240e::1]:18787`):与上一条并列,
|
|
42
|
+
// 只是拨的是 IPv6;网卡扫不到的那条固定地址靠它兜底,候选口径见 lan-network.cjs。
|
|
43
|
+
manualIpv6Url: z.string().max(200).default(''),
|
|
44
|
+
// 用户手填的「TCP 直连」目标(`manualTcpUrl`,形如 `主机:端口` / `http://主机:端口`,IPv6 方括号)。
|
|
45
|
+
// 与上面两条并列、同样不进 sidecar;它只决定手机用裸 TCP 拨哪个目标(详见 lan-network.cjs)。
|
|
46
|
+
manualTcpUrl: z.string().max(200).default(''),
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
function configOf(state) {
|
|
51
|
+
// 两格必须一起算:`relayUrls` 是完整列表、`relayUrl` 是它的首项(契约见
|
|
52
|
+
// docs/relay-multi-address.md),任何一处只写一个都会让读的一方看到矛盾的两份值。
|
|
53
|
+
const relay = core.relayAddressesOf(state)
|
|
54
|
+
return {
|
|
55
|
+
enabled: Boolean(state.enabled),
|
|
56
|
+
relayUrl: relay.relayUrl,
|
|
57
|
+
relayUrls: relay.relayUrls,
|
|
58
|
+
lanEnabled: Boolean(state.lanEnabled),
|
|
59
|
+
lanPort: Number.isInteger(state.lanPort) ? state.lanPort : 18787,
|
|
60
|
+
name: typeof state.name === 'string' ? state.name : '',
|
|
61
|
+
// The schema rejects anything outside the enum, so in practice this only
|
|
62
|
+
// ever normalises a value written before pairingPolicy existed.
|
|
63
|
+
pairingPolicy: pairingApproval.normalize(state.pairingPolicy),
|
|
64
|
+
pairingTier: permissions.isKnownTier(state.pairingTier) ? state.pairingTier : permissions.DEFAULT_TIER, // 未知值收敛回 full
|
|
65
|
+
approvalAutoReview: state.approvalAutoReview === true, // 非 true 一律当关
|
|
66
|
+
// 只有明确写成 false 才算关;老状态文件没这一格时按开(与历史行为一致)。
|
|
67
|
+
controlReportEnabled: state.controlReportEnabled !== false,
|
|
68
|
+
// 没写过的老配置按显示处理:这两颗是入口,不因为升级就凭空消失。
|
|
69
|
+
desktopPhoneIcon: state.desktopPhoneIcon !== false,
|
|
70
|
+
desktopComputerIcon: state.desktopComputerIcon !== false,
|
|
71
|
+
// 密钥只往 sidecar 和状态文件走:status() / pairingPayload() 都单独取字段,
|
|
72
|
+
// 不会把它回显给手机、二维码或日志。
|
|
73
|
+
registerSecret: typeof state.registerSecret === 'string' ? state.registerSecret : '',
|
|
74
|
+
preferredLanAddress: typeof state.preferredLanAddress === 'string' ? state.preferredLanAddress : '',
|
|
75
|
+
manualLanUrl: typeof state.manualLanUrl === 'string' ? state.manualLanUrl : '',
|
|
76
|
+
manualIpv6Url: typeof state.manualIpv6Url === 'string' ? state.manualIpv6Url : '',
|
|
77
|
+
manualTcpUrl: typeof state.manualTcpUrl === 'string' ? state.manualTcpUrl : '',
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = { RemoteControlSettingsSchema, configOf };
|
package/lib/relay/control.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// 加密上报真实可用地址,并用握手期限与协议心跳维护总控连接。
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -16,6 +17,8 @@
|
|
|
16
17
|
* 总控地址是内置常量,可用 `DSH_CONTROL_URL` 覆盖(本地联调用)。
|
|
17
18
|
*/
|
|
18
19
|
|
|
20
|
+
const WebSocket = require('ws');
|
|
21
|
+
const { performance } = require('node:perf_hooks');
|
|
19
22
|
const {
|
|
20
23
|
advertisedCandidates,
|
|
21
24
|
phoneCandidates,
|
|
@@ -23,11 +26,13 @@ const {
|
|
|
23
26
|
withManualIpv6Candidate,
|
|
24
27
|
tcpDirectTarget,
|
|
25
28
|
} = require('./lan-network.cjs');
|
|
26
|
-
const { relayAddressesOf } = require('./core.js');
|
|
27
29
|
const { sealHistoryBlob } = require('../mirror/history-blob.cjs');
|
|
28
30
|
|
|
29
31
|
// 内置总控入口(与 APP 侧常量一致)。末尾斜杠去掉,拼接时统一。
|
|
30
32
|
const CONTROL_BASE_URL = (process.env.DSH_CONTROL_URL || 'https://ai-hub.wnluo.com/findme').replace(/\/+$/, '');
|
|
33
|
+
const HANDSHAKE_TIMEOUT_MS = 10_000;
|
|
34
|
+
const HEARTBEAT_INTERVAL_MS = 15_000;
|
|
35
|
+
const PONG_TIMEOUT_MS = 45_000;
|
|
31
36
|
|
|
32
37
|
/** https→wss、http→ws。总控的 WebSocket 端点挂在同一前缀下。 */
|
|
33
38
|
function controlWsUrl(base = CONTROL_BASE_URL) {
|
|
@@ -36,24 +41,16 @@ function controlWsUrl(base = CONTROL_BASE_URL) {
|
|
|
36
41
|
|
|
37
42
|
/**
|
|
38
43
|
* 折出本机要上报的全部连接地址(明文,上送前再加密)。
|
|
39
|
-
*
|
|
40
|
-
* IPv6 走 `ipv6Candidates`
|
|
44
|
+
* 中转只取当前实际注册的线路;局域网走 `phoneCandidates(advertisedCandidates)`;
|
|
45
|
+
* IPv6 走 `ipv6Candidates` 并缀上手填那条,与局域网开关独立;端口未监听时不发布。
|
|
41
46
|
* 「TCP 直连」目标(`manualTcpUrl`)单独一条,**不受 `lanEnabled` 影响**:它不挂在局域网监听上,
|
|
42
47
|
* 是一条独立的裸 TCP 出站通道。这一格必须报上来——配了 TCP(或手填直连)时公用中转会被规则关掉,
|
|
43
48
|
* 而 TCP 又替换不了「宿主地址」在手机上的同步:手机离开局域网后连不上宿主,只能靠总控把 TCP
|
|
44
49
|
* 目标补给它。漏了这一格,总控这条兜底就等于空转。
|
|
45
50
|
*/
|
|
46
|
-
function controlAddresses(state, port) {
|
|
51
|
+
function controlAddresses(state, port, connectedRelay = '') {
|
|
47
52
|
const out = [];
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
relay = relayAddressesOf(state);
|
|
51
|
-
} catch {
|
|
52
|
-
relay = { relayUrls: [] };
|
|
53
|
-
}
|
|
54
|
-
for (const url of relay.relayUrls || []) {
|
|
55
|
-
if (typeof url === 'string' && url) out.push({ kind: 'relay', url });
|
|
56
|
-
}
|
|
53
|
+
if (typeof connectedRelay === 'string' && /^https?:\/\//i.test(connectedRelay)) out.push({ kind: 'relay', url: connectedRelay });
|
|
57
54
|
const lanPort = Number.isInteger(port) ? port : 0;
|
|
58
55
|
if (state.lanEnabled && lanPort > 0) {
|
|
59
56
|
try {
|
|
@@ -65,6 +62,8 @@ function controlAddresses(state, port) {
|
|
|
65
62
|
} catch {
|
|
66
63
|
/* 网卡扫不出来只是少几条 LAN 候选,不影响上报主链路 */
|
|
67
64
|
}
|
|
65
|
+
}
|
|
66
|
+
if (lanPort > 0) {
|
|
68
67
|
try {
|
|
69
68
|
const v6 = withManualIpv6Candidate(ipv6Candidates(lanPort), state.manualIpv6Url);
|
|
70
69
|
for (const c of v6) if (c && c.url) out.push({ kind: 'ipv6', url: c.url });
|
|
@@ -98,8 +97,8 @@ function controlAddresses(state, port) {
|
|
|
98
97
|
* 不知道,新手机才用。connectedRelay 取宿主写回的当前主用(`relayUrl` 就是「当前接上了
|
|
99
98
|
* 哪一条」,见 docs/relay-multi-address.md),不是配置里随便挑的一条。
|
|
100
99
|
*/
|
|
101
|
-
function controlMeta(state, connected = false) {
|
|
102
|
-
const raw = typeof
|
|
100
|
+
function controlMeta(state, connected = false, connectedRelay) {
|
|
101
|
+
const raw = connected === true && typeof connectedRelay === 'string' ? connectedRelay.trim().replace(/\/+$/, '') : '';
|
|
103
102
|
return {
|
|
104
103
|
connectedRelay: /^https?:\/\//i.test(raw) ? raw : '',
|
|
105
104
|
relayConnected: connected === true,
|
|
@@ -118,23 +117,54 @@ function controlMeta(state, connected = false) {
|
|
|
118
117
|
* @param {(msg: string, ...rest: any[]) => void} [deps.log]
|
|
119
118
|
*/
|
|
120
119
|
function createControlClient(options = {}) {
|
|
121
|
-
const { persist, getPort, getHistoryKey, getAddresses, getRelayConnected, log = () => {} } = options
|
|
120
|
+
const { persist, getPort, getHistoryKey, getAddresses, getRelayConnected, getConnectedRelay, log = () => {}, onIdentityConflict = null } = options
|
|
122
121
|
// `getState` 让控制客户端读到**当前这一代**的状态(换代后状态对象会换一份):老的直接传
|
|
123
122
|
// `state` 的用法保留为兜底,测试与旧调用方行为不变。
|
|
124
123
|
const getState = typeof options.getState === 'function' ? options.getState : () => options.state
|
|
125
124
|
const build = typeof getAddresses === 'function'
|
|
126
125
|
? getAddresses
|
|
127
|
-
: (s) => controlAddresses(s, typeof getPort === 'function' ? getPort() : undefined);
|
|
126
|
+
: (s) => controlAddresses(s, typeof getPort === 'function' ? getPort() : undefined, typeof getConnectedRelay === 'function' ? getConnectedRelay() : '');
|
|
128
127
|
const connectedOf = typeof getRelayConnected === 'function' ? getRelayConnected : () => false;
|
|
129
128
|
|
|
130
129
|
let sock = null;
|
|
131
130
|
let running = false;
|
|
132
131
|
let connected = false;
|
|
132
|
+
// 建客户端那一刻的令牌只是初值:稳定外壳先 createControlClient、稍后才经 setProviders
|
|
133
|
+
// 注入真正的状态(见 shell/transport-host.js),那时这里读到的还是空对象。所以每次
|
|
134
|
+
// 拨号前都要从当前状态重取一次,否则会用空令牌去注册,被总控当成冒充而触发换身份。
|
|
133
135
|
let token = typeof getState().controlToken === 'string' ? getState().controlToken : '';
|
|
134
136
|
let lastSent = '';
|
|
137
|
+
let hasPublished = false;
|
|
135
138
|
let attempt = 0;
|
|
136
139
|
let reconnectTimer = null;
|
|
137
140
|
let tickTimer = null;
|
|
141
|
+
let releaseSocket = null;
|
|
142
|
+
// 「身份冲突」连续计数:同一台机器被别处占了令牌时会持续收到 identity_conflict。
|
|
143
|
+
// 累计到阈值(且都在一个窗口内)就触发一次换身份,把本机换成新号从冲突里出来;
|
|
144
|
+
// 换完若还冲突,靠冷却期避免反复触发放大(换身份本身会重连,别在里头死循环)。
|
|
145
|
+
let identityConflictStreak = 0;
|
|
146
|
+
let lastIdentityConflictAt = 0;
|
|
147
|
+
let identityConflictCooldownUntil = 0;
|
|
148
|
+
const IDENTITY_CONFLICT_THRESHOLD = 3;
|
|
149
|
+
const IDENTITY_CONFLICT_WINDOW_MS = 60_000;
|
|
150
|
+
const IDENTITY_CONFLICT_COOLDOWN_MS = 10 * 60_000;
|
|
151
|
+
|
|
152
|
+
/** 记一次身份冲突;够阈值就调一次 onIdentityConflict(换身份),并进入冷却。 */
|
|
153
|
+
function noteIdentityConflict() {
|
|
154
|
+
if (typeof onIdentityConflict !== 'function') return;
|
|
155
|
+
const now = Date.now();
|
|
156
|
+
if (now < identityConflictCooldownUntil) return;
|
|
157
|
+
if (now - lastIdentityConflictAt > IDENTITY_CONFLICT_WINDOW_MS) identityConflictStreak = 0;
|
|
158
|
+
lastIdentityConflictAt = now;
|
|
159
|
+
identityConflictStreak += 1;
|
|
160
|
+
if (identityConflictStreak < IDENTITY_CONFLICT_THRESHOLD) return;
|
|
161
|
+
identityConflictStreak = 0;
|
|
162
|
+
identityConflictCooldownUntil = now + IDENTITY_CONFLICT_COOLDOWN_MS;
|
|
163
|
+
try {
|
|
164
|
+
const pending = onIdentityConflict();
|
|
165
|
+
if (pending && typeof pending.catch === 'function') pending.catch(() => {});
|
|
166
|
+
} catch { /* 换身份失败就让退避继续,不在这里抛 */ }
|
|
167
|
+
}
|
|
138
168
|
|
|
139
169
|
// `at` 是采样时刻,每次 tick 都会变;不进 canonical,否则每分钟都会白推一次 update。
|
|
140
170
|
const canonical = (list, meta) => JSON.stringify([
|
|
@@ -175,7 +205,13 @@ function createControlClient(options = {}) {
|
|
|
175
205
|
attempt += 1;
|
|
176
206
|
const delay = Math.min(30_000, 1_000 * 2 ** Math.min(attempt - 1, 5));
|
|
177
207
|
clearTimeout(reconnectTimer);
|
|
178
|
-
|
|
208
|
+
const timer = setTimeout(() => {
|
|
209
|
+
if (reconnectTimer !== timer) return;
|
|
210
|
+
reconnectTimer = null;
|
|
211
|
+
connect();
|
|
212
|
+
}, delay);
|
|
213
|
+
reconnectTimer = timer;
|
|
214
|
+
timer.unref?.();
|
|
179
215
|
}
|
|
180
216
|
|
|
181
217
|
function connect() {
|
|
@@ -184,35 +220,82 @@ function createControlClient(options = {}) {
|
|
|
184
220
|
// 用户在面板关掉了「自动上报网络地址」:立刻不连(sync/stop 会把已在连的这条也收掉)。
|
|
185
221
|
if (getState().controlReportEnabled === false) return;
|
|
186
222
|
const addresses = build(getState());
|
|
187
|
-
if (!Array.isArray(addresses) || addresses.length === 0) {
|
|
223
|
+
if (!Array.isArray(addresses) || (addresses.length === 0 && !hasPublished)) {
|
|
188
224
|
connected = false;
|
|
189
225
|
return;
|
|
190
226
|
}
|
|
191
|
-
const meta = controlMeta(getState(), connectedOf());
|
|
227
|
+
const meta = controlMeta(getState(), addresses.length > 0 && connectedOf(), typeof getConnectedRelay === 'function' ? getConnectedRelay() : '');
|
|
192
228
|
const payload = seal(addresses, meta);
|
|
193
229
|
if (!payload) {
|
|
194
230
|
connected = false;
|
|
195
231
|
return;
|
|
196
232
|
}
|
|
233
|
+
// 拨号前重取一次令牌(见文件上方 `token` 初值的说明):外壳注入状态晚于建客户端,
|
|
234
|
+
// 只在建时读一次会一直用空令牌去注册,被总控判成身份冲突后误触发换身份。
|
|
235
|
+
const storedToken = getState().controlToken;
|
|
236
|
+
if (typeof storedToken === 'string') token = storedToken;
|
|
197
237
|
const tokenQuery = token ? `&token=${encodeURIComponent(token)}` : '';
|
|
198
238
|
const url = `${controlWsUrl()}/ws/device?instanceId=${encodeURIComponent(getState().instanceId || '')}${tokenQuery}`;
|
|
199
239
|
let ws;
|
|
200
240
|
try {
|
|
201
241
|
ws = new WebSocket(url);
|
|
202
242
|
} catch (error) {
|
|
203
|
-
log('control: dial failed'
|
|
243
|
+
log('control: dial failed');
|
|
204
244
|
scheduleReconnect();
|
|
205
245
|
return;
|
|
206
246
|
}
|
|
207
247
|
sock = ws;
|
|
208
248
|
connected = false;
|
|
209
249
|
lastSent = '';
|
|
210
|
-
|
|
250
|
+
let handshakeTimer = null;
|
|
251
|
+
let heartbeatTimer = null;
|
|
252
|
+
let lastPong = 0;
|
|
253
|
+
const retire = (retry = true) => {
|
|
254
|
+
clearTimeout(handshakeTimer);
|
|
255
|
+
clearTimeout(heartbeatTimer);
|
|
256
|
+
handshakeTimer = null;
|
|
257
|
+
heartbeatTimer = null;
|
|
211
258
|
if (sock !== ws) return;
|
|
212
|
-
|
|
259
|
+
connected = false;
|
|
260
|
+
sock = null;
|
|
261
|
+
releaseSocket = null;
|
|
262
|
+
try { ws.terminate(); } catch { /* 已关闭 */ }
|
|
263
|
+
if (retry) scheduleReconnect();
|
|
264
|
+
};
|
|
265
|
+
releaseSocket = retire;
|
|
266
|
+
handshakeTimer = setTimeout(() => {
|
|
267
|
+
if (handshakeTimer && sock === ws) retire();
|
|
268
|
+
}, HANDSHAKE_TIMEOUT_MS);
|
|
269
|
+
handshakeTimer.unref?.();
|
|
270
|
+
const scheduleHeartbeat = () => {
|
|
271
|
+
const timer = setTimeout(() => {
|
|
272
|
+
if (heartbeatTimer !== timer || sock !== ws || !running) return;
|
|
273
|
+
heartbeatTimer = null;
|
|
274
|
+
if (ws.readyState !== 1 || performance.now() - lastPong >= PONG_TIMEOUT_MS) { retire(); return; }
|
|
275
|
+
try { ws.ping(); } catch { retire(); return; }
|
|
276
|
+
scheduleHeartbeat();
|
|
277
|
+
}, HEARTBEAT_INTERVAL_MS);
|
|
278
|
+
heartbeatTimer = timer;
|
|
279
|
+
timer.unref?.();
|
|
280
|
+
};
|
|
281
|
+
ws.on('pong', () => { if (sock === ws && connected) lastPong = performance.now(); });
|
|
282
|
+
ws.addEventListener('open', () => {
|
|
283
|
+
if (sock !== ws || !running) return;
|
|
284
|
+
clearTimeout(handshakeTimer);
|
|
285
|
+
handshakeTimer = null;
|
|
286
|
+
// 注意:这里**不**清零退避。连上不等于能用——服务端可能刚连上就以 unauthorized 断开;
|
|
287
|
+
// 若在 open 就清零,每次被拒后都按最短 1 秒重连,等于把「被拒」放大成每秒一次的热循环。
|
|
288
|
+
// 退避在收到 registered(真正注册成功)时再清零,见 message 处理。
|
|
213
289
|
connected = true;
|
|
214
|
-
|
|
215
|
-
|
|
290
|
+
lastPong = performance.now();
|
|
291
|
+
scheduleHeartbeat();
|
|
292
|
+
const currentAddresses = build(getState());
|
|
293
|
+
const currentMeta = controlMeta(getState(), currentAddresses.length > 0 && connectedOf(), typeof getConnectedRelay === 'function' ? getConnectedRelay() : '');
|
|
294
|
+
const currentPayload = seal(currentAddresses, currentMeta);
|
|
295
|
+
if (!currentPayload) { retire(); return; }
|
|
296
|
+
send({ type: 'register', payload: currentPayload });
|
|
297
|
+
lastSent = canonical(currentAddresses, currentMeta);
|
|
298
|
+
hasPublished = true;
|
|
216
299
|
});
|
|
217
300
|
ws.addEventListener('message', (event) => {
|
|
218
301
|
if (sock !== ws) return;
|
|
@@ -223,32 +306,34 @@ function createControlClient(options = {}) {
|
|
|
223
306
|
} catch {
|
|
224
307
|
return;
|
|
225
308
|
}
|
|
226
|
-
if (msg && msg.type === 'registered'
|
|
227
|
-
|
|
309
|
+
if (msg && msg.type === 'registered') {
|
|
310
|
+
// 真正注册成功,链路可用,退避清零。
|
|
311
|
+
attempt = 0;
|
|
312
|
+
identityConflictStreak = 0;
|
|
313
|
+
if (typeof msg.token === 'string' && msg.token !== token) {
|
|
228
314
|
token = msg.token;
|
|
229
315
|
getState().controlToken = msg.token;
|
|
230
316
|
try { persist?.(); } catch { /* 落盘失败下次注册还会拿到同一枚,不必打断 */ }
|
|
231
317
|
}
|
|
232
318
|
} else if (msg && msg.type === 'error') {
|
|
233
|
-
|
|
319
|
+
// 包括 unauthorized(同一 instanceId 被别处占了令牌、或令牌对不上):断开后按指数退避重连,
|
|
320
|
+
// 不在 open 时清零,所以最多退到 30 秒一次,不会再每秒硬撞。
|
|
321
|
+
// 明确的 identity_conflict 额外累计,够次数就触发换身份(换到唯一的新号)。
|
|
322
|
+
if (String(msg.message || '') === 'identity_conflict') noteIdentityConflict();
|
|
323
|
+
log('control: server error');
|
|
324
|
+
retire();
|
|
234
325
|
}
|
|
235
326
|
});
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
connected = false;
|
|
239
|
-
sock = null;
|
|
240
|
-
scheduleReconnect();
|
|
241
|
-
};
|
|
242
|
-
ws.addEventListener('close', done);
|
|
243
|
-
ws.addEventListener('error', () => { try { ws.close(); } catch { /* ignore */ } });
|
|
327
|
+
ws.addEventListener('close', () => retire());
|
|
328
|
+
ws.addEventListener('error', () => retire());
|
|
244
329
|
}
|
|
245
330
|
|
|
246
331
|
/** 复核地址与健康有没有变,变了就重新加密并 update。 */
|
|
247
332
|
function tick() {
|
|
248
333
|
if (!connected || !sock) return;
|
|
249
334
|
const addresses = build(getState());
|
|
250
|
-
if (!Array.isArray(addresses)
|
|
251
|
-
const meta = controlMeta(getState(), connectedOf());
|
|
335
|
+
if (!Array.isArray(addresses)) return;
|
|
336
|
+
const meta = controlMeta(getState(), addresses.length > 0 && connectedOf(), typeof getConnectedRelay === 'function' ? getConnectedRelay() : '');
|
|
252
337
|
const signature = canonical(addresses, meta);
|
|
253
338
|
if (signature !== lastSent) {
|
|
254
339
|
const payload = seal(addresses, meta);
|
|
@@ -265,11 +350,13 @@ function createControlClient(options = {}) {
|
|
|
265
350
|
function start() {
|
|
266
351
|
if (!running) {
|
|
267
352
|
running = true;
|
|
353
|
+
// 每 30 秒重读一次本机网卡(开销只是本地接口枚举,`tick` 只在地址签名真变了才推 update)。
|
|
354
|
+
// 光猫重启 / 运营商换 IPv6 前缀后,新地址最多半分钟就上报总控,手机在外网重连更快拿到。
|
|
268
355
|
clearInterval(tickTimer);
|
|
269
|
-
tickTimer = setInterval(tick,
|
|
356
|
+
tickTimer = setInterval(tick, 30_000);
|
|
270
357
|
if (tickTimer.unref) tickTimer.unref();
|
|
271
358
|
}
|
|
272
|
-
if (getState().enabled && getState().controlReportEnabled !== false && !sock) connect();
|
|
359
|
+
if (getState().enabled && getState().controlReportEnabled !== false && !sock && !reconnectTimer) connect();
|
|
273
360
|
return snapshot();
|
|
274
361
|
}
|
|
275
362
|
|
|
@@ -280,16 +367,13 @@ function createControlClient(options = {}) {
|
|
|
280
367
|
reconnectTimer = null;
|
|
281
368
|
clearInterval(tickTimer);
|
|
282
369
|
tickTimer = null;
|
|
283
|
-
|
|
284
|
-
try { sock.close(); } catch { /* ignore */ }
|
|
285
|
-
sock = null;
|
|
286
|
-
}
|
|
370
|
+
releaseSocket?.(false);
|
|
287
371
|
attempt = 0;
|
|
288
372
|
}
|
|
289
373
|
|
|
290
|
-
/**
|
|
374
|
+
/** 配置变更后复核;已发布的地址变空也要沿现有连接清空目录。 */
|
|
291
375
|
function sync() {
|
|
292
|
-
if (!getState().enabled || getState().controlReportEnabled === false ||
|
|
376
|
+
if (!getState().enabled || getState().controlReportEnabled === false || !hk()) {
|
|
293
377
|
stop();
|
|
294
378
|
return;
|
|
295
379
|
}
|
|
@@ -297,11 +381,11 @@ function createControlClient(options = {}) {
|
|
|
297
381
|
start();
|
|
298
382
|
return;
|
|
299
383
|
}
|
|
300
|
-
if (!sock) connect();
|
|
384
|
+
if (!sock && !reconnectTimer) connect();
|
|
301
385
|
else tick();
|
|
302
386
|
}
|
|
303
387
|
|
|
304
|
-
return { start, stop, sync, snapshot };
|
|
388
|
+
return { start, stop, sync, snapshot, get targetUrl() { return CONTROL_BASE_URL; } };
|
|
305
389
|
}
|
|
306
390
|
|
|
307
391
|
module.exports = { CONTROL_BASE_URL, controlWsUrl, controlAddresses, controlMeta, createControlClient };
|
package/lib/relay/core.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// 中转地址收敛保留禁用意图,启用且无公网替代时补回公用清单。
|
|
1
2
|
/**
|
|
2
3
|
* relay.json 的状态形状与读写,外加实例 ID / 配对码 / 隧道地址这几个纯函数。
|
|
3
4
|
*
|
|
@@ -122,6 +123,30 @@ function rotatePairing(state) {
|
|
|
122
123
|
return { pairingCode: state.pairingCode, pairingTicket: state.pairingTicket };
|
|
123
124
|
}
|
|
124
125
|
|
|
126
|
+
/**
|
|
127
|
+
* 换身份:把本机实例号换成新的一枚(32 位 hex),配对码 / 票据一并作废。
|
|
128
|
+
*
|
|
129
|
+
* **HK 不动**:控制载荷那层加密的 AAD 里带着 instanceId,但密钥(HK)本身与 id 无关;
|
|
130
|
+
* 换 id 后两端只要用**同一个新 id** 当 AAD,载荷照样解得开(手机从心跳 / 升级回包拿到新 id)。
|
|
131
|
+
*
|
|
132
|
+
* **旧号留在 `previousInstanceId`**:一台电脑可能配过好几台手机,不是每台都能在同一刻
|
|
133
|
+
* 换到新 id。过渡期内本机要同时认「新号」和「旧号」两个身份(鉴权、凭据、局域网发现),
|
|
134
|
+
* 让还没更新的手机照常能连;等它们都换过来再收掉旧号。这里只负责记住旧号,认不认由鉴权层决定。
|
|
135
|
+
*
|
|
136
|
+
* 改 id 只碰这些状态;凭据重签、总控重报、局域网令牌重签、mDNS、推送这些由装配层在拿到
|
|
137
|
+
* 返回值后按序做——它们依赖进程里的其它服务,不属于这份纯状态变更。
|
|
138
|
+
*/
|
|
139
|
+
function rotateIdentity(state) {
|
|
140
|
+
const previous = typeof state.instanceId === 'string' ? state.instanceId : '';
|
|
141
|
+
state.instanceId = genInstanceId();
|
|
142
|
+
if (previous) state.previousInstanceId = previous;
|
|
143
|
+
else delete state.previousInstanceId;
|
|
144
|
+
state.pairingCode = genPairingCode();
|
|
145
|
+
state.pairingTicket = genPairingTicket();
|
|
146
|
+
saveState(state);
|
|
147
|
+
return { instanceId: state.instanceId, previousInstanceId: state.previousInstanceId || '' };
|
|
148
|
+
}
|
|
149
|
+
|
|
125
150
|
function saveState(state) {
|
|
126
151
|
normalizeRelayAddresses(state);
|
|
127
152
|
fs.mkdirSync(path.dirname(STATE_FILE), { recursive: true });
|
|
@@ -268,10 +293,10 @@ function verifyLanToken(secret, token, instanceId) { return sharedToken.verifyLa
|
|
|
268
293
|
* App `services/viewmodels/public-relay.ts` 的 `PUBLIC_RELAY_URLS` 保持一致** —— 三处各有一份,
|
|
269
294
|
* 加一台公用中转要三处一起补,少补一处那台上的设备就会被漏判。
|
|
270
295
|
*
|
|
271
|
-
*
|
|
272
|
-
* `expandDefaultPublicRelays
|
|
296
|
+
* 这里除了拿来判「是不是公用」,还是「老设备配置里缺公用地址时补齐成整份」的地址来源(见
|
|
297
|
+
* `expandDefaultPublicRelays`):宿主必须自己握着这条 URL,否则补不出来。
|
|
273
298
|
*/
|
|
274
|
-
const PUBLIC_RELAY_URLS = ['https://ai-hub-de-1.wnluo.com'
|
|
299
|
+
const PUBLIC_RELAY_URLS = ['https://ai-hub-de-1.wnluo.com'];
|
|
275
300
|
/** 按 host 比:协议、默认端口、尾斜杠的差异都不影响它是不是公用。 */
|
|
276
301
|
const PUBLIC_RELAY_HOSTS = new Set(PUBLIC_RELAY_URLS.map((url) => {
|
|
277
302
|
try { return new URL(url).host.toLowerCase(); } catch { return ''; }
|
|
@@ -320,21 +345,16 @@ function stripPublicRelay(next) {
|
|
|
320
345
|
}
|
|
321
346
|
|
|
322
347
|
/**
|
|
323
|
-
*
|
|
324
|
-
* 读盘时就补成整份内置清单,让电脑能选/失败切换到另外两台(2026-11-19 用户口径:要把流量自动
|
|
325
|
-
* 分到别人维护的那两台上)。
|
|
348
|
+
* 纯公用地址补齐内置清单,让电脑能选路并在失败时切到其它公用中转。
|
|
326
349
|
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
* - 确实缺着内置清单里的某几台(缺才补,已经齐了就一字不动)。
|
|
331
|
-
* 补齐时保留原有顺序在前(现有的主用不被挤下去),缺的按内置清单顺序追加在后面;`relayUrl` 恒为首项。
|
|
332
|
-
* **不碰任何非公用地址**。
|
|
350
|
+
* 没有公网自建替代时,空清单只在 `enabled === true` 时回补:临时直连清掉后恢复兜底,
|
|
351
|
+
* 已关闭或尚未启用的中转保持关闭。非空清单仍只补纯公用地址,不碰自建地址。
|
|
352
|
+
* 补齐保留原有主用顺序,缺项按内置清单顺序追加;`relayUrl` 恒为首项,不改变启用开关。
|
|
333
353
|
*/
|
|
334
354
|
function expandDefaultPublicRelays(state) {
|
|
335
355
|
if (!state || typeof state !== 'object') return false;
|
|
336
356
|
const urls = relayAddressesOf(state).relayUrls;
|
|
337
|
-
if (!urls.length) return false;
|
|
357
|
+
if (!urls.length && state.enabled !== true) return false;
|
|
338
358
|
if (!urls.every((url) => isPublicRelayUrl(url))) return false;
|
|
339
359
|
if (publicRelayBlocked(state)) return false;
|
|
340
360
|
const hostOf = (url) => { try { return new URL(url).host.toLowerCase(); } catch { return ''; } };
|
|
@@ -353,7 +373,7 @@ function expandDefaultPublicRelays(state) {
|
|
|
353
373
|
}
|
|
354
374
|
|
|
355
375
|
module.exports = {
|
|
356
|
-
STATE_FILE, MOBILE_TOKEN_TTL_SEC, MOBILE_BEARER_TTL_SEC, defaultState, loadState, saveState, rotatePairing, genInstanceId, genPairingCode, genPairingTicket, genHistoryKey, ensureHistoryKey,
|
|
376
|
+
STATE_FILE, MOBILE_TOKEN_TTL_SEC, MOBILE_BEARER_TTL_SEC, defaultState, loadState, saveState, rotatePairing, rotateIdentity, genInstanceId, genPairingCode, genPairingTicket, genHistoryKey, ensureHistoryKey,
|
|
357
377
|
tunnelWsUrl, normalizeRelayUrl, normalizeRelayUrlList, normalizeRelayAddresses, relayAddressesOf, applyRelayAddressPatch, signLanToken, verifyLanToken,
|
|
358
378
|
isPublicRelayUrl, publicRelayBlocked, stripPublicRelay, expandDefaultPublicRelays, PUBLIC_RELAY_URLS, MAX_RELAY_ADDRESSES,
|
|
359
379
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 身份冲突时「换身份」的实装。
|
|
5
|
+
*
|
|
6
|
+
* 连续收到身份冲突(同一 instanceId 被别处占了令牌)后触发一次:生成新号 → 落盘 → 让 sidecar
|
|
7
|
+
* 用新号重下配置 → 总控用新号重连。新号唯一,换完就不再有冲突;重入保护避免并发触发。
|
|
8
|
+
*
|
|
9
|
+
* 放在这里而不是装配层:装配层只把它挂上,不许多长实现(见 `test/assembly-layer.test.cjs`)。
|
|
10
|
+
*/
|
|
11
|
+
function createIdentityRotator({ state, rotateIdentity, saveState, syncSidecar, syncControl }) {
|
|
12
|
+
let rotating = false;
|
|
13
|
+
return async function rotateIdentityNow() {
|
|
14
|
+
if (rotating) return;
|
|
15
|
+
rotating = true;
|
|
16
|
+
try {
|
|
17
|
+
rotateIdentity(state);
|
|
18
|
+
saveState(state);
|
|
19
|
+
try { await syncSidecar(); } catch { /* 配置下发失败不影响重连,下次 sync 再补 */ }
|
|
20
|
+
try { syncControl(); } catch { /* ignore */ }
|
|
21
|
+
} finally {
|
|
22
|
+
rotating = false;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = { createIdentityRotator };
|