dsh-mobile-plugin 0.5.81 → 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.
Files changed (55) hide show
  1. package/lib/frpc/provision.cjs +21 -17
  2. package/lib/frpc/runner.cjs +193 -165
  3. package/lib/impl.js +53 -80
  4. package/lib/mirror/pusher.cjs +60 -10
  5. package/lib/mobile/events.js +2 -1
  6. package/lib/mobile/feedback.js +6 -5
  7. package/lib/mobile/file-read.js +4 -2
  8. package/lib/mobile/mux.js +148 -21
  9. package/lib/mobile/paired-devices.js +2 -1
  10. package/lib/mobile/pairing.js +3 -2
  11. package/lib/mobile/relay-control.js +27 -33
  12. package/lib/mobile/session-changes.js +8 -2
  13. package/lib/mobile/session-delivery.js +5 -1
  14. package/lib/mobile/session-file.js +46 -25
  15. package/lib/mobile/session-head.js +7 -3
  16. package/lib/mobile/session-snapshot.js +5 -1
  17. package/lib/mobile/session-step.js +13 -7
  18. package/lib/mobile/session-stop-summary.js +6 -1
  19. package/lib/mobile/stream-registry.js +48 -53
  20. package/lib/mobile/stream.js +17 -2
  21. package/lib/mobile/uploads.js +190 -163
  22. package/lib/p2p/session.cjs +169 -70
  23. package/lib/p2p/wiring.cjs +4 -2
  24. package/lib/panel/index.html +17 -15
  25. package/lib/relay/blob-upload.cjs +103 -0
  26. package/lib/relay/config-store.js +81 -0
  27. package/lib/relay/control.js +94 -46
  28. package/lib/relay/core.js +9 -13
  29. package/lib/relay/lan-proxy.js +44 -7
  30. package/lib/relay/pairing-payload.cjs +14 -5
  31. package/lib/relay/preview-webapp.cjs +150 -0
  32. package/lib/relay/preview.js +35 -8
  33. package/lib/relay/protocol.js +6 -4
  34. package/lib/relay/relay-probe.js +112 -21
  35. package/lib/relay/tunnel-forwarder.cjs +4 -2
  36. package/lib/relay/tunnel.js +39 -8
  37. package/lib/remote/controller.cjs +33 -3
  38. package/lib/remote/host-control.cjs +11 -2
  39. package/lib/remote/router.cjs +83 -33
  40. package/lib/remote/transport.cjs +32 -5
  41. package/lib/remote/tunnel-helper.cjs +51 -25
  42. package/lib/remote/tunnels.cjs +27 -3
  43. package/lib/routes/control-plane.js +25 -17
  44. package/lib/routes/mobile-api.js +21 -18
  45. package/lib/shared/fresh-request.js +32 -1
  46. package/lib/shared/route-order.cjs +118 -132
  47. package/lib/shared/sse-write.js +29 -10
  48. package/lib/shared/via-header.js +5 -12
  49. package/lib/shell/transport-host.js +9 -1
  50. package/lib/sidecar-facade-worker.cjs +156 -112
  51. package/lib/sidecar-facade.cjs +6 -1
  52. package/lib/sidecar-lifecycle.cjs +6 -2
  53. package/lib/tailcat/host-process.cjs +32 -8
  54. package/lib/tailcat/session.cjs +27 -10
  55. package/package.json +6 -6
@@ -36,6 +36,10 @@ const HEALTH_POLL_INTERVAL_MS = 10000;
36
36
  */
37
37
  function createSidecarLifecycle(deps = {}) {
38
38
  const { ctx } = deps;
39
+ // 父进程端口在构造时取一次就缓存。自重启常发生在换代之后,那时旧 context 已 inactive,
40
+ // 再读 ctx.webServer 会抛 "cannot get required service webServer in inactive context",
41
+ // 让整个重启失败——隧道、frpc(TCP 直连)和 P2P 助手都跟着起不来。同一进程里端口不会变。
42
+ const parentPort = ctx.webServer.port;
39
43
  // 传输进程归**稳定外壳**持有时,配置来源会在每一次换代后由新的一代重新注入:所以这里
40
44
  // 做成可变对象,构造期给的值只是初值(外壳起的那一次用)。换代只 `setProviders`+`sync`,
41
45
  // 配置签名不变 → worker 的 configure 不重建隧道、不重建局域网,连接跨代存活。
@@ -127,7 +131,7 @@ function createSidecarLifecycle(deps = {}) {
127
131
  // 同一份历史里「择路选中了非队首」这件事也在这条路上报上来,写回由装配层订阅。
128
132
  noteRouteAdopted(message.tunnel.route)
129
133
  }
130
- let sidecar = new SidecarFacade({ parentPort: ctx.webServer.port, token: sidecarToken, onDown: markSidecarDown, onState: applyTunnelState })
134
+ let sidecar = new SidecarFacade({ parentPort, token: sidecarToken, onDown: markSidecarDown, onState: applyTunnelState })
131
135
  // sidecar 自重启的账:几次、什么时候、上次成没成。自重启是运维动作(改完代码不想
132
136
  // 逼用户重启整个 DSH),出问题时「刚才那次重启到底把哪一段换掉了」必须查得到。
133
137
  let sidecarRestarts = 0
@@ -221,7 +225,7 @@ function createSidecarLifecycle(deps = {}) {
221
225
  // 重新 require 的是 facade 及其依赖(relay/tunnel 等)——缓存已清,拿到的
222
226
  // 是磁盘上的新代码。worker 更是直接 re-fork,天然是新的。
223
227
  const Fresh = require('./sidecar-facade.cjs').SidecarFacade
224
- sidecar = new Fresh({ parentPort: ctx.webServer.port, token: sidecarToken, onDown: markSidecarDown, onState: applyTunnelState })
228
+ sidecar = new Fresh({ parentPort, token: sidecarToken, onDown: markSidecarDown, onState: applyTunnelState })
225
229
  sidecarState = 'starting'
226
230
  await sidecar.start()
227
231
  await syncSidecar()
@@ -1,3 +1,4 @@
1
+ // 助手重启读取当前已持久身份与白名单,按 peer 保留 IPC 生命周期。
1
2
  'use strict';
2
3
 
3
4
  /**
@@ -60,6 +61,7 @@ const EVENT_KEYS = {
60
61
  const OPTIONAL_EVENT_KEYS = {
61
62
  p2pReady: ['peerKey'],
62
63
  p2pStatus: ['peerKey'],
64
+ p2pStopped: ['peerKey'],
63
65
  };
64
66
 
65
67
  const ADDRESS = /^tc[\x21-\x7e]{0,4095}$/;
@@ -130,6 +132,10 @@ function createTailcatHost(options) {
130
132
  let restartTimer;
131
133
  let ready = false;
132
134
  let address = '';
135
+ let currentState = options.state === undefined ? null : options.state;
136
+ let currentAllowed = Array.isArray(options.allowedClients) ? [...options.allowedClients] : [];
137
+ const pendingPersists = new Map();
138
+ const launchProcess = options.spawn || spawn;
133
139
 
134
140
  const status = () => ({ available: Boolean(binary), running: Boolean(child), ready, address, restarts });
135
141
 
@@ -150,7 +156,10 @@ function createTailcatHost(options) {
150
156
  if (typeof kind !== 'string' || !EVENT_KEYS[kind]) return;
151
157
  const keys = Object.keys(value);
152
158
  const fields = EVENT_KEYS[kind];
153
- // 必填键一个不许少;可选键(目前只有 `peerKey`)可以没有,但有了也必须是这一格。
159
+ // 已发布的旧助手只回 running:false;仅这一个空形态补齐,运行态仍须完整。
160
+ if (kind === 'p2pStatus' && value.running === false) {
161
+ value = { url: '', path: 'unknown', active: false, detail: '', candidates: [], ...value };
162
+ }
154
163
  if (fields.some(field => !(field in value))) return;
155
164
  const optional = OPTIONAL_EVENT_KEYS[kind] || [];
156
165
  const extra = keys.filter(key => key !== 'event' && !fields.includes(key) && !optional.includes(key));
@@ -170,6 +179,7 @@ function createTailcatHost(options) {
170
179
  } else if (kind === 'persist') {
171
180
  if (typeof value.id !== 'string' || value.id.length > 32) return;
172
181
  if (!Array.isArray(value.allowedClients)) return;
182
+ pendingPersists.set(value.id, { state: value.state, allowed: [...value.allowedClients] });
173
183
  } else if (kind === 'error') {
174
184
  if (typeof value.code !== 'string') return;
175
185
  // 助手的失败原因可能是底层网络 / 证书报错这类长串(例如取 DERP 地图时 x509 证书校验失败,
@@ -197,7 +207,7 @@ function createTailcatHost(options) {
197
207
  if (closed || !binary) return;
198
208
  let proc;
199
209
  try {
200
- proc = spawn(binary, [], { stdio: ['pipe', 'pipe', 'ignore'], windowsHide: true });
210
+ proc = launchProcess(binary, [], { stdio: ['pipe', 'pipe', 'ignore'], windowsHide: true });
201
211
  } catch {
202
212
  scheduleRestart();
203
213
  return;
@@ -225,12 +235,19 @@ function createTailcatHost(options) {
225
235
  address = '';
226
236
  if (!closed) scheduleRestart();
227
237
  });
238
+ pendingPersists.clear();
239
+ // 外壳跨实现代存活:每次拉起都以插件当前存储为准。
240
+ const latest = typeof options.readState === 'function' ? options.readState() : null;
241
+ if (latest) {
242
+ currentState = latest.identity === undefined ? currentState : latest.identity;
243
+ if (Array.isArray(latest.allowed)) currentAllowed = [...latest.allowed];
244
+ }
228
245
  write({
229
246
  version: IPC_VERSION,
230
247
  localPort: options.localPort,
231
248
  name: String(options.name || os.hostname()).slice(0, 64),
232
- state: options.state === undefined ? null : options.state,
233
- allowedClients: Array.isArray(options.allowedClients) ? options.allowedClients : [],
249
+ state: currentState,
250
+ allowedClients: currentAllowed,
234
251
  });
235
252
  }
236
253
 
@@ -249,10 +266,17 @@ function createTailcatHost(options) {
249
266
  },
250
267
  /** 换白名单(吊销手机就走这条)。 */
251
268
  setAllowed(allowedClients) {
252
- write({ command: 'setAllowed', allowedClients: allowedClients || [] });
269
+ currentAllowed = Array.isArray(allowedClients) ? [...allowedClients] : [];
270
+ write({ command: 'setAllowed', allowedClients: currentAllowed });
253
271
  },
254
- /** 回执:state 存住了没有。 */
272
+ /** 只有存储确认成功的身份可用于下一次拉起。 */
255
273
  ack(id, ok) {
274
+ const pending = pendingPersists.get(id);
275
+ pendingPersists.delete(id);
276
+ if (ok && pending) {
277
+ if (typeof pending.state === 'string' && pending.state) currentState = pending.state;
278
+ currentAllowed = pending.allowed;
279
+ }
256
280
  write({ command: 'ack', id, ok: Boolean(ok) });
257
281
  },
258
282
  /**
@@ -274,8 +298,8 @@ function createTailcatHost(options) {
274
298
  p2pTargetPort: Number(options.targetPort) || 0,
275
299
  });
276
300
  },
277
- stopP2P() {
278
- write({ command: 'p2pStop' });
301
+ stopP2P(peerKey) {
302
+ write({ command: 'p2pStop', ...(peerKey ? { p2pPeerKey: String(peerKey) } : {}) });
279
303
  },
280
304
  statusP2P() {
281
305
  write({ command: 'p2pStatus' });
@@ -1,3 +1,4 @@
1
+ // 身份由存储确认后复用,吊销中的新白名单不接受旧助手回执覆盖。
1
2
  'use strict';
2
3
 
3
4
  /**
@@ -62,9 +63,12 @@ function createTailcatSession(options) {
62
63
  */
63
64
  let binary = options.host && !options.resolveBinary ? 'injected' : findBinary();
64
65
  let host = null;
66
+ let hostGeneration = 0;
65
67
  let lastError = '';
66
68
  /** 正在等窗口的那次请求(一次只开一个窗口)。 */
67
69
  let pendingWindow = null;
70
+ let desiredAllowed = null;
71
+ const sameAllowed = (left, right) => JSON.stringify([...left].sort()) === JSON.stringify([...right].sort());
68
72
 
69
73
  function snapshot() {
70
74
  try {
@@ -112,18 +116,21 @@ function createTailcatSession(options) {
112
116
  });
113
117
  break;
114
118
  case 'paired': {
115
- // 助手已经把手机加进白名单;存下来,并让二维码作废(码里那把钥匙只服务这一次)。
116
- const state = snapshot();
117
- const allowed = state.allowed.includes(event.client) ? state.allowed : [...state.allowed, event.client];
118
- persist({ [STATE.allowed]: allowed });
119
+ // 配对成功之前已完成 persist/ack;这里不能把后来吊销的设备再加回来。
119
120
  settlePairingWindow(null);
120
121
  break;
121
122
  }
122
123
  case 'persist': {
123
- // 助手的身份(私钥 / 预共享密钥 / 区域)与白名单都落在这里;存住了才回执。
124
- const patch = { [STATE.allowed]: event.allowedClients };
125
- if (typeof event.state === 'string' && event.state) patch[STATE.identity] = event.state;
126
- const ok = persist(patch);
124
+ const state = snapshot();
125
+ const allowed = Array.isArray(event.allowedClients) ? event.allowedClients : [];
126
+ const stale = desiredAllowed !== null && !sameAllowed(allowed, desiredAllowed);
127
+ // 首次持久身份仍可收下,但旧白名单必须拒绝,让队列处理最新 setAllowed。
128
+ const patch = stale ? {} : { [STATE.allowed]: allowed };
129
+ if (typeof event.state === 'string' && event.state
130
+ && (!stale || !state.identity)) patch[STATE.identity] = event.state;
131
+ const saved = Object.keys(patch).length === 0 || persist(patch);
132
+ const ok = saved && !stale;
133
+ if (ok) desiredAllowed = null;
127
134
  host && host.ack(event.id, ok);
128
135
  break;
129
136
  }
@@ -162,12 +169,19 @@ function createTailcatSession(options) {
162
169
  if (lastError === 'helper-missing') lastError = '';
163
170
  const state = snapshot();
164
171
  if (!state.enabled) return;
165
- host = options.host || createTailcatHost({
172
+ const generation = ++hostGeneration;
173
+ desiredAllowed = null;
174
+ host = options.host || (options.createHost || createTailcatHost)({
166
175
  localPort: options.localPort,
167
176
  name: typeof options.hostName === 'function' ? options.hostName() : undefined,
168
177
  state: state.identity,
169
178
  allowedClients: state.allowed,
170
- onEvent: handleEvent,
179
+ readState: () => {
180
+ // 进程内自动重拉同样换代:启动配置已取最新存储,不继承上一进程的确认门。
181
+ if (generation === hostGeneration) desiredAllowed = null;
182
+ return snapshot();
183
+ },
184
+ onEvent: event => { if (generation === hostGeneration) handleEvent(event); },
171
185
  });
172
186
  host.start();
173
187
  }
@@ -176,6 +190,8 @@ function createTailcatSession(options) {
176
190
  settlePairingWindow(null);
177
191
  const current = host;
178
192
  host = null;
193
+ hostGeneration += 1;
194
+ desiredAllowed = null;
179
195
  if (current) return current.close();
180
196
  return Promise.resolve();
181
197
  }
@@ -263,6 +279,7 @@ function createTailcatSession(options) {
263
279
  function setAllowed(allowedClients) {
264
280
  const allowed = Array.isArray(allowedClients) ? allowedClients : [];
265
281
  if (!persist({ [STATE.allowed]: allowed })) return false;
282
+ desiredAllowed = host?.status().running ? [...allowed] : null;
266
283
  host && host.setAllowed(allowed);
267
284
  return true;
268
285
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mobile-plugin",
3
- "version": "0.5.81",
3
+ "version": "0.5.82",
4
4
  "description": "Mobile API (/api/mobile/v1) and relay client for the DSH mobile app — desktop profile build (dsh 0.2.x, peers resolved by the host)",
5
5
  "license": "MIT",
6
6
  "icon": "./icon.png",
@@ -82,11 +82,11 @@
82
82
  "dsh-mobile-shell-linux-arm64": "0.1.2",
83
83
  "dsh-mobile-shell-linux-x64": "0.1.2",
84
84
  "dsh-mobile-shell-win32-x64": "0.1.2",
85
- "dsh-mobile-tailcat-darwin-arm64": "1.1.4",
86
- "dsh-mobile-tailcat-darwin-x64": "1.1.4",
87
- "dsh-mobile-tailcat-linux-arm64": "1.1.4",
88
- "dsh-mobile-tailcat-linux-x64": "1.1.4",
89
- "dsh-mobile-tailcat-win32-x64": "1.1.4"
85
+ "dsh-mobile-tailcat-darwin-arm64": "1.1.5",
86
+ "dsh-mobile-tailcat-darwin-x64": "1.1.5",
87
+ "dsh-mobile-tailcat-linux-arm64": "1.1.5",
88
+ "dsh-mobile-tailcat-linux-x64": "1.1.5",
89
+ "dsh-mobile-tailcat-win32-x64": "1.1.5"
90
90
  },
91
91
  "peerDependencies": {
92
92
  "@deepseek-ai/cordis": ">=4.0.1",