dsh-mobile-plugin 0.5.81 → 0.5.83
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.md +4 -0
- package/dsh-mobile-credentials/lib/credentials.js +5 -0
- package/lib/client.js +171 -5
- package/lib/frpc/provision.cjs +21 -17
- package/lib/frpc/runner.cjs +231 -168
- package/lib/impl.js +77 -107
- package/lib/index.js +1 -1
- package/lib/mirror/pusher.cjs +60 -10
- package/lib/mobile/approval-memory.js +2 -55
- package/lib/mobile/approvals.js +6 -82
- 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/host-bridge.js +12 -1
- package/lib/mobile/mux.js +148 -21
- package/lib/mobile/paired-devices.js +2 -1
- package/lib/mobile/pairing.js +8 -7
- package/lib/mobile/relay-control.js +33 -38
- 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 +44 -24
- package/lib/relay/blob-upload.cjs +103 -0
- package/lib/relay/config-store.js +79 -0
- package/lib/relay/control.js +131 -52
- package/lib/relay/core.js +55 -17
- package/lib/relay/lan-discovery.cjs +22 -14
- package/lib/relay/lan-port-policy.cjs +8 -2
- package/lib/relay/lan-proxy.js +47 -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/status.js +4 -7
- 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 +41 -53
- package/lib/routes/mobile-api.js +21 -31
- 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 +9 -1
- package/lib/shell/updater.js +18 -6
- package/lib/sidecar-facade-worker.cjs +165 -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
- package/lib/mobile/auto-review.js +0 -178
package/lib/p2p/session.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// P2P 启动按 peer 串行,候选由各自 ready 确认,查询与停止回执独立。
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -109,13 +110,12 @@ function createP2PSession(options) {
|
|
|
109
110
|
/**
|
|
110
111
|
* 按手机公钥的那张表:每把公钥一套 `{ ...tunnel, runningCandidates, dialing, stamp }`。
|
|
111
112
|
*
|
|
112
|
-
* `runningCandidates`
|
|
113
|
+
* `runningCandidates` 仅由 ready 确认后更新:「隧道在跑」不等于「跑的就是你现在
|
|
113
114
|
* 这份候选」。电脑第一次往往是在手机还没报出候选时以「只听不打」起来的;之后手机把真实
|
|
114
115
|
* 候选报上来,若只判公钥,就永远复用一个没有对端地址的隧道 —— 永远不往手机打,公网永远
|
|
115
116
|
* 不通(局域网能通只因为手机摸得到电脑的内网地址、先打过来了)。
|
|
116
117
|
*
|
|
117
|
-
* `dialing
|
|
118
|
-
* 两条 `p2pStart`,两条各自开一次 socket、洞白开。
|
|
118
|
+
* `dialing`:当前 peer 的启动命令已发出、尚未收到 ready;后续候选在 opens 表里排队。
|
|
119
119
|
*
|
|
120
120
|
* `stamp`:最近一次被动到的顺序。`status()` 那几格老字段取「最近活跃的那条」,靠它排。
|
|
121
121
|
*
|
|
@@ -123,6 +123,8 @@ function createP2PSession(options) {
|
|
|
123
123
|
* 公钥时,事件落在它上面。它不进 `status().peers` 的详单。
|
|
124
124
|
*/
|
|
125
125
|
const peers = new Map();
|
|
126
|
+
// 每个 peer 同时只向助手发送一条启动;失败后的 stop 回执是下一条启动的边界。
|
|
127
|
+
const opens = new Map();
|
|
126
128
|
let stampSeq = 0;
|
|
127
129
|
|
|
128
130
|
function ensurePeer(key) {
|
|
@@ -207,17 +209,12 @@ function createP2PSession(options) {
|
|
|
207
209
|
}
|
|
208
210
|
|
|
209
211
|
/**
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
* 多台手机之后这里要按公钥分道:两台同时会合时,A 那条 `p2pReady` 绝不能拿去回 B ——
|
|
213
|
-
* 拿着别人的地址当自己的,B 会往一个自己够不到的 URL 上走。所以等待者按公钥认领,
|
|
214
|
-
* 只唤醒「等这一台的」与「不挑的」(轮询)。
|
|
215
|
-
*
|
|
216
|
-
* `key` 为空串是**认不出是哪台**的情况(老助手的事件里没有公钥):这时一律广播 ——
|
|
217
|
-
* 老助手一条进程只有一条隧道,它报的就是「有隧道起来了」,分道反而会把等着的那台饿死。
|
|
212
|
+
* 等待者同时按操作和 peer 认领;查询不能提前确认启动或停止。
|
|
213
|
+
* 老助手缺 peerKey 时仅在同类操作内广播,错误与总收尾才结束所有操作。
|
|
218
214
|
*/
|
|
219
|
-
function settle(value, key = '') {
|
|
215
|
+
function settle(value, key = '', type) {
|
|
220
216
|
for (const done of [...waiters]) {
|
|
217
|
+
if (type && done.type !== type) continue;
|
|
221
218
|
if (key && done.key && done.key !== key) continue;
|
|
222
219
|
waiters.delete(done);
|
|
223
220
|
clearTimeout(done.timer);
|
|
@@ -225,21 +222,14 @@ function createP2PSession(options) {
|
|
|
225
222
|
}
|
|
226
223
|
}
|
|
227
224
|
|
|
228
|
-
/**
|
|
229
|
-
|
|
230
|
-
*
|
|
231
|
-
* `key` 是这台手机的公钥(不挑就留空)。超时那一支还要顺手把这一格的「正在发起」清掉 ——
|
|
232
|
-
* 不清的话,那一格永远是 dialing,下一轮同候选的会合会被判成「已经在起,复用」,
|
|
233
|
-
* 于是这台就再也不会重新发起(看起来像「隧道卡住了、怎么等都不动」)。
|
|
234
|
-
*/
|
|
235
|
-
function await_(resolve, key = '') {
|
|
225
|
+
/** 查询与停止按操作及 peer 等待;超时只摘掉自己的等待位。 */
|
|
226
|
+
function await_(resolve, key = '', type = 'status') {
|
|
236
227
|
const done = {
|
|
237
228
|
key,
|
|
229
|
+
type,
|
|
238
230
|
resolve,
|
|
239
231
|
timer: setTimeout(() => {
|
|
240
232
|
waiters.delete(done);
|
|
241
|
-
const entry = key ? peers.get(key) : null;
|
|
242
|
-
if (entry) entry.dialing = false;
|
|
243
233
|
resolve(null);
|
|
244
234
|
}, P2P_TIMEOUT_MS),
|
|
245
235
|
};
|
|
@@ -252,26 +242,51 @@ function createP2PSession(options) {
|
|
|
252
242
|
case 'p2pReady': {
|
|
253
243
|
lastError = '';
|
|
254
244
|
const key = routeKey(event);
|
|
245
|
+
const owner = opens.get(key);
|
|
246
|
+
if (owner && (!owner.active || owner.draining)) break;
|
|
255
247
|
const entry = ensurePeer(key);
|
|
256
248
|
entry.running = true;
|
|
257
249
|
entry.dialing = false;
|
|
258
250
|
entry.url = typeof event.url === 'string' ? event.url : '';
|
|
259
251
|
entry.candidates = candidateList(event.candidates);
|
|
260
|
-
|
|
261
|
-
|
|
252
|
+
const job = owner?.active;
|
|
253
|
+
if (job) {
|
|
254
|
+
clearTimeout(job.timer);
|
|
255
|
+
owner.active = null;
|
|
256
|
+
entry.runningCandidates = job.wanted;
|
|
257
|
+
job.resolve({ ok: true, url: entry.url, candidates: entry.candidates, publicKey: job.publicKey });
|
|
258
|
+
watch();
|
|
259
|
+
queueMicrotask(() => pumpOpen(key, owner));
|
|
260
|
+
}
|
|
262
261
|
break;
|
|
263
262
|
}
|
|
264
263
|
case 'p2pStatus': {
|
|
264
|
+
if (event.running === false && !event.peerKey) {
|
|
265
|
+
// 这可能是较早发出的查询回执;只清已确认旧事实,保留后来登记的启动及其候选。
|
|
266
|
+
for (const [key, entry] of peers) {
|
|
267
|
+
if (entry.dialing) Object.assign(entry, emptyTunnel());
|
|
268
|
+
else peers.delete(key);
|
|
269
|
+
}
|
|
270
|
+
if (!peers.has(lastPeer)) lastPeer = '';
|
|
271
|
+
// 助手已恢复到可答查询的空状态;重发未确认的停止建立新边界,不能直接放行旧 ready。
|
|
272
|
+
for (const [key, owner] of opens) {
|
|
273
|
+
if (owner.draining && !owner.stopPromise) drainPeer(key, owner);
|
|
274
|
+
}
|
|
275
|
+
settle({ ok: true, ...emptyTunnel() }, '', 'status');
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
265
278
|
const key = routeKey(event);
|
|
266
279
|
const entry = ensurePeer(key);
|
|
267
|
-
|
|
268
|
-
entry.dialing
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
280
|
+
// 启动中的同 peer 也可能先收到旧查询;查询不能确认新启动或覆盖它的候选。
|
|
281
|
+
if (!entry.dialing && !opens.get(key)?.draining) {
|
|
282
|
+
entry.running = Boolean(event.running);
|
|
283
|
+
entry.url = typeof event.url === 'string' ? event.url : '';
|
|
284
|
+
entry.path = normalizePath(event.path);
|
|
285
|
+
entry.active = event.active === true;
|
|
286
|
+
entry.detail = typeof event.detail === 'string' ? event.detail : '';
|
|
287
|
+
entry.candidates = candidateList(event.candidates);
|
|
288
|
+
}
|
|
289
|
+
settle({ ok: true, ...pick(entry), candidates: entry.candidates }, key, 'status');
|
|
275
290
|
break;
|
|
276
291
|
}
|
|
277
292
|
case 'p2pKeys':
|
|
@@ -279,7 +294,6 @@ function createP2PSession(options) {
|
|
|
279
294
|
if (typeof event.private === 'string' && typeof event.public === 'string') {
|
|
280
295
|
persist({ [STATE.privateKey]: event.private, [STATE.publicKey]: event.public });
|
|
281
296
|
}
|
|
282
|
-
settle({ ok: true, publicKey: typeof event.public === 'string' ? event.public : '' });
|
|
283
297
|
break;
|
|
284
298
|
case 'p2pStopped': {
|
|
285
299
|
const announced = typeof event.peerKey === 'string' ? event.peerKey.trim() : '';
|
|
@@ -290,16 +304,19 @@ function createP2PSession(options) {
|
|
|
290
304
|
// 老助手:它一条进程只有一条隧道,回的就是「全停了」。
|
|
291
305
|
peers.clear();
|
|
292
306
|
}
|
|
293
|
-
settle({ ok: true, running: false });
|
|
307
|
+
settle({ ok: true, running: false }, announced, 'stop');
|
|
294
308
|
break;
|
|
295
309
|
}
|
|
296
|
-
case 'error':
|
|
310
|
+
case 'error': {
|
|
297
311
|
lastError = event.code;
|
|
298
|
-
//
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
312
|
+
// 旧 IPC 错误不带 peer;仅有一个在飞操作时才可明确归属,否则各 peer 自己超时收尾。
|
|
313
|
+
const pending = [...opens.entries()].filter(([, owner]) => owner.active || owner.draining);
|
|
314
|
+
if (pending.length === 1 && pending[0][1].active) {
|
|
315
|
+
const [key, owner] = pending[0];
|
|
316
|
+
failOpen(key, owner, owner.active, { ok: false, code: event.code });
|
|
317
|
+
}
|
|
302
318
|
break;
|
|
319
|
+
}
|
|
303
320
|
default:
|
|
304
321
|
break;
|
|
305
322
|
}
|
|
@@ -359,6 +376,16 @@ function createP2PSession(options) {
|
|
|
359
376
|
everOpened = false;
|
|
360
377
|
lastPeer = '';
|
|
361
378
|
peers.clear();
|
|
379
|
+
for (const owner of opens.values()) {
|
|
380
|
+
if (owner.active) {
|
|
381
|
+
clearTimeout(owner.active.timer);
|
|
382
|
+
owner.active.resolve(null);
|
|
383
|
+
}
|
|
384
|
+
discardQueued(owner);
|
|
385
|
+
}
|
|
386
|
+
opens.clear();
|
|
387
|
+
settle(null);
|
|
388
|
+
refreshing = null;
|
|
362
389
|
const current = host;
|
|
363
390
|
host = null;
|
|
364
391
|
if (current) return current.close();
|
|
@@ -469,6 +496,58 @@ function createP2PSession(options) {
|
|
|
469
496
|
* 判据从「全局唯一那个对端」变成「**这台手机自己那一份**」:多台共存之后,两台手机各判
|
|
470
497
|
* 各的,一台候选变了不会连累另一台。
|
|
471
498
|
*/
|
|
499
|
+
function pumpOpen(key, owner) {
|
|
500
|
+
if (opens.get(key) !== owner || owner.active || owner.draining || !host) return;
|
|
501
|
+
const job = owner.queue.shift();
|
|
502
|
+
if (!job) return;
|
|
503
|
+
owner.active = job;
|
|
504
|
+
const entry = ensurePeer(key);
|
|
505
|
+
Object.assign(entry, emptyTunnel());
|
|
506
|
+
entry.dialing = true;
|
|
507
|
+
if (key && key !== lastPeer) persist({ [STATE.peerKey]: key });
|
|
508
|
+
if (key) lastPeer = key;
|
|
509
|
+
job.timer = setTimeout(() => failOpen(key, owner, job, null), P2P_TIMEOUT_MS);
|
|
510
|
+
job.timer.unref?.();
|
|
511
|
+
host.startP2P(job.command);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function discardQueued(owner) {
|
|
515
|
+
for (const job of owner.queue.splice(0)) job.resolve(null);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
function drainPeer(key, owner) {
|
|
519
|
+
if (owner.stopPromise) return owner.stopPromise;
|
|
520
|
+
owner.draining = true;
|
|
521
|
+
owner.stopPromise = new Promise(resolve => {
|
|
522
|
+
await_(reply => {
|
|
523
|
+
owner.stopPromise = null;
|
|
524
|
+
if (opens.get(key) === owner) {
|
|
525
|
+
if (reply?.ok) {
|
|
526
|
+
owner.draining = false;
|
|
527
|
+
queueMicrotask(() => pumpOpen(key, owner));
|
|
528
|
+
} else {
|
|
529
|
+
// 边界未确认时仍隔离旧 ready;本轮请求有界结束,下次会合或助手空状态可重试 stop。
|
|
530
|
+
discardQueued(owner);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
resolve(reply);
|
|
534
|
+
}, key, 'stop');
|
|
535
|
+
host?.stopP2P(key);
|
|
536
|
+
});
|
|
537
|
+
return owner.stopPromise;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function failOpen(key, owner, job, reply) {
|
|
541
|
+
if (owner.active !== job) return;
|
|
542
|
+
clearTimeout(job.timer);
|
|
543
|
+
owner.active = null;
|
|
544
|
+
const entry = peers.get(key);
|
|
545
|
+
if (entry) entry.dialing = false;
|
|
546
|
+
job.resolve(reply);
|
|
547
|
+
// 旧启动可能在超时后才完成;先等同 peer 的停止回执排空,不能拿它的 ready 回下一组候选。
|
|
548
|
+
drainPeer(key, owner);
|
|
549
|
+
}
|
|
550
|
+
|
|
472
551
|
function open(options = {}) {
|
|
473
552
|
everOpened = true;
|
|
474
553
|
const current = start();
|
|
@@ -508,7 +587,13 @@ function createP2PSession(options) {
|
|
|
508
587
|
// **候选也得一起判**:电脑第一次往往是在手机还没报出候选时以「只听不打」起来的,之后
|
|
509
588
|
// 手机把真实候选报上来;只判公钥就一直复用那个没有对端地址的隧道,电脑永远不往手机打。
|
|
510
589
|
// 局域网还好(手机摸得到内网地址、从那边打过来了),一到公网就只剩下「等待」。
|
|
511
|
-
|
|
590
|
+
let owner = opens.get(peerKey);
|
|
591
|
+
if (owner) {
|
|
592
|
+
const matching = [owner.active, ...owner.queue].find(job => job && sameCandidates(job.wanted, wantedCandidates));
|
|
593
|
+
if (matching) return matching.promise;
|
|
594
|
+
}
|
|
595
|
+
if ((!owner || !owner.active && !owner.draining && !owner.queue.length)
|
|
596
|
+
&& peerKey && seen && seen.running && seen.path !== 'failed'
|
|
512
597
|
&& sameCandidates(wantedCandidates, seen.runningCandidates)) {
|
|
513
598
|
return Promise.resolve({
|
|
514
599
|
ok: true,
|
|
@@ -522,42 +607,55 @@ function createP2PSession(options) {
|
|
|
522
607
|
});
|
|
523
608
|
}
|
|
524
609
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
610
|
+
if (!owner) {
|
|
611
|
+
owner = { active: null, queue: [], draining: false, stopPromise: null };
|
|
612
|
+
opens.set(peerKey, owner);
|
|
613
|
+
}
|
|
614
|
+
let resolve;
|
|
615
|
+
const promise = new Promise(done => { resolve = done; });
|
|
616
|
+
owner.queue.push({ wanted: wantedCandidates, publicKey: state.publicKey, resolve, promise,
|
|
617
|
+
command: {
|
|
618
|
+
privateKey: state.privateKey, peerKey, peerPublic: candidates, peerLocal: localCandidates,
|
|
619
|
+
listenPort: P2P_PORT, targetPort: Number(options.targetPort) || 0,
|
|
620
|
+
} });
|
|
621
|
+
if (owner.draining) drainPeer(peerKey, owner);
|
|
622
|
+
else pumpOpen(peerKey, owner);
|
|
623
|
+
return promise;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/** 单 peer 收尾不影响助手与其他手机。 */
|
|
627
|
+
function stopPeer(peerKey) {
|
|
628
|
+
const key = typeof peerKey === 'string' ? peerKey.trim() : '';
|
|
629
|
+
if (!key || !host) return Promise.resolve(null);
|
|
630
|
+
let owner = opens.get(key);
|
|
631
|
+
if (!owner) {
|
|
632
|
+
owner = { active: null, queue: [], draining: false, stopPromise: null };
|
|
633
|
+
opens.set(key, owner);
|
|
634
|
+
}
|
|
635
|
+
discardQueued(owner);
|
|
636
|
+
if (owner.active) {
|
|
637
|
+
clearTimeout(owner.active.timer);
|
|
638
|
+
owner.active.resolve(null);
|
|
639
|
+
owner.active = null;
|
|
640
|
+
}
|
|
641
|
+
const entry = peers.get(key);
|
|
642
|
+
if (entry) entry.dialing = false;
|
|
643
|
+
return drainPeer(key, owner);
|
|
552
644
|
}
|
|
553
645
|
|
|
554
|
-
|
|
646
|
+
let refreshing = null;
|
|
647
|
+
/** 问一次「打通了没有」;无回执时不每两秒叠加等待者。 */
|
|
555
648
|
function refresh() {
|
|
556
649
|
if (!host) return Promise.resolve(null);
|
|
557
|
-
|
|
650
|
+
if (refreshing) return refreshing;
|
|
651
|
+
const current = host;
|
|
652
|
+
const work = new Promise((resolve) => {
|
|
558
653
|
await_(resolve);
|
|
559
|
-
|
|
654
|
+
current.statusP2P();
|
|
560
655
|
});
|
|
656
|
+
refreshing = work;
|
|
657
|
+
void work.finally(() => { if (refreshing === work) refreshing = null; });
|
|
658
|
+
return work;
|
|
561
659
|
}
|
|
562
660
|
|
|
563
661
|
/**
|
|
@@ -593,6 +691,7 @@ function createP2PSession(options) {
|
|
|
593
691
|
return {
|
|
594
692
|
start,
|
|
595
693
|
stop,
|
|
694
|
+
stopPeer,
|
|
596
695
|
status,
|
|
597
696
|
open,
|
|
598
697
|
refresh,
|
package/lib/p2p/wiring.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// 装配点对点隧道,固定经带 P2P 来源标记的既有落点代理。
|
|
1
2
|
'use strict';
|
|
2
3
|
// 隧道始终走独立的带来源标记入口,不依赖局域网监听。
|
|
3
4
|
// 落点代理转给宿主时跟随宿主实际绑定地址(见 relay/tunnel-forwarder.cjs)。
|
|
@@ -54,12 +55,12 @@ function mountP2P(options) {
|
|
|
54
55
|
// listen 已经晚了一步。
|
|
55
56
|
const forwarder = typeof lanEnabled === 'function'
|
|
56
57
|
? mount('点对点隧道落点代理', () =>
|
|
57
|
-
createTunnelForwarder({ upstreamPort: webPort, upstreamHost: webHost, log: message => warn(message) }),
|
|
58
|
+
createTunnelForwarder({ upstreamPort: webPort, upstreamHost: webHost, via: 'p2p', log: message => warn(message) }),
|
|
58
59
|
)
|
|
59
60
|
: null;
|
|
60
61
|
if (forwarder) void forwarder.start();
|
|
61
62
|
const resolvedTargetPort = typeof lanEnabled === 'function'
|
|
62
|
-
? chooseP2PTarget({ lanEnabled, lanPort, tunnelPort: () => (forwarder ? forwarder.port() : 0) })
|
|
63
|
+
? chooseP2PTarget({ lanEnabled: () => false, lanPort, tunnelPort: () => (forwarder ? forwarder.port() : 0) })
|
|
63
64
|
: localPort;
|
|
64
65
|
/**
|
|
65
66
|
* 端口是异步拿到的(`localPort()` 依赖 sidebar 起来),所以会话也是异步建好的。
|
|
@@ -79,6 +80,7 @@ function mountP2P(options) {
|
|
|
79
80
|
setEnabled: enabled => (session ? session.setEnabled(enabled) : false),
|
|
80
81
|
start: () => (session ? session.start() : null),
|
|
81
82
|
stop: () => (session ? session.stop() : Promise.resolve()),
|
|
83
|
+
stopPeer: key => (session ? session.stopPeer(key) : Promise.resolve(null)),
|
|
82
84
|
// 会合那一发要的「本机落点端口」:**每次现取**,不缓存。局域网开关与端口都会漂,
|
|
83
85
|
// 缓存一个数就会在关掉局域网之后继续往一个没人听的口转。
|
|
84
86
|
targetPort: () => Number(resolvedTargetPort()) || 0,
|