dsh-plugin-mesh 0.5.15 → 0.5.16
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/lib/index.js +46 -6
- package/lib/index.js.ws.bak +4589 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -108,7 +108,7 @@ import { TsnetNode, channelKey, channelSignature } from "./tsnet/manager.js";
|
|
|
108
108
|
import { resolveTailnetChannels } from "./tsnet/channels.js";
|
|
109
109
|
import { tailnetFetch, tailnetOrigin, isTailnetAddress } from "./tsnet/bridge.js";
|
|
110
110
|
import { createWebProxy } from "./web-proxy.js";
|
|
111
|
-
import { planWebTarget, needsReachabilityProbe } from "./web-target.js";
|
|
111
|
+
import { planWebTarget, needsReachabilityProbe, isLoopbackHost } from "./web-target.js";
|
|
112
112
|
import { planSshTarget, sshDirectCandidates } from "./ssh-target.js";
|
|
113
113
|
import { createSecretReader } from "./desktop-auth.js";
|
|
114
114
|
import {
|
|
@@ -129,7 +129,7 @@ import {
|
|
|
129
129
|
export const name = "dsh-plugin-mesh";
|
|
130
130
|
export const inject = ["tools", "webServer"];
|
|
131
131
|
|
|
132
|
-
const VERSION = "0.5.
|
|
132
|
+
const VERSION = "0.5.16";
|
|
133
133
|
// 诊断用:进程启动时间 + 入口真实路径。磁盘上的版本**不在这里缓存** ——
|
|
134
134
|
// 升级之后进程还跑旧代码,版本号必须现读磁盘才能立刻反映出来(真踩过:
|
|
135
135
|
// 磁盘升到 0.5.1,进程还在 0.5.0,界面显示 0.5.0)。
|
|
@@ -4953,11 +4953,35 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
|
|
|
4953
4953
|
probeNote: direct.note,
|
|
4954
4954
|
});
|
|
4955
4955
|
if (plan.mode === "stream") {
|
|
4956
|
+
const passthrough = Boolean(plan.ticket);
|
|
4957
|
+
const upstreamHeaders = passthrough
|
|
4958
|
+
? { [plan.header || PEER_WEB_TICKET_HEADER]: plan.ticket, "x-dsh-mesh-token": currentSecret() }
|
|
4959
|
+
: {};
|
|
4960
|
+
// 快路:对端除了相对前缀,还把隧道的**局域网绝对地址**(tunnel.url)给了。
|
|
4961
|
+
// 同网段时直接打那个地址:sidecar 拨 tailnet 要多一跳,遇到 DERP 中继还会
|
|
4962
|
+
// 明显变慢——页面所有请求都吃这个延迟。拨不通再回落到 tailnet 出站流。
|
|
4963
|
+
const lanBase = lanTunnelBase(tunnel);
|
|
4964
|
+
if (lanBase) {
|
|
4965
|
+
const probe = await verifyWebBase(lanBase);
|
|
4966
|
+
if (probe.reachable !== false) {
|
|
4967
|
+
return {
|
|
4968
|
+
remoteBase: lanBase,
|
|
4969
|
+
pathPrefix: plan.prefix || "",
|
|
4970
|
+
passthrough,
|
|
4971
|
+
lanReachable: true,
|
|
4972
|
+
token,
|
|
4973
|
+
guiPort,
|
|
4974
|
+
guiBind,
|
|
4975
|
+
stream: null,
|
|
4976
|
+
upstreamHeaders,
|
|
4977
|
+
note: `经对端局域网 mesh 口隧道(${lanBase}${String(plan.prefix || "").replace(/^\//, "")})`,
|
|
4978
|
+
};
|
|
4979
|
+
}
|
|
4980
|
+
}
|
|
4956
4981
|
const opened = await openWebStream(target, plan.address);
|
|
4957
4982
|
if (opened.error) {
|
|
4958
4983
|
return { error: `${plan.note},但${opened.error}` };
|
|
4959
4984
|
}
|
|
4960
|
-
const passthrough = Boolean(plan.ticket);
|
|
4961
4985
|
return {
|
|
4962
4986
|
remoteBase: `http://127.0.0.1:${opened.port}/`,
|
|
4963
4987
|
pathPrefix: plan.prefix || "",
|
|
@@ -4967,9 +4991,7 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
|
|
|
4967
4991
|
guiPort,
|
|
4968
4992
|
guiBind,
|
|
4969
4993
|
stream: { address: plan.address, node: opened.node },
|
|
4970
|
-
upstreamHeaders
|
|
4971
|
-
? { [plan.header || PEER_WEB_TICKET_HEADER]: plan.ticket, "x-dsh-mesh-token": currentSecret() }
|
|
4972
|
-
: {},
|
|
4994
|
+
upstreamHeaders,
|
|
4973
4995
|
note: plan.note,
|
|
4974
4996
|
};
|
|
4975
4997
|
}
|
|
@@ -5007,6 +5029,24 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
|
|
|
5007
5029
|
}
|
|
5008
5030
|
}
|
|
5009
5031
|
|
|
5032
|
+
/**
|
|
5033
|
+
* 对端给的局域网绝对隧道地址(`tunnel.url`,形如 `http://192.168.1.5:45930/mesh/web/`)。
|
|
5034
|
+
*
|
|
5035
|
+
* 只取 `scheme://host:port/` 这一截:路径前缀由 pathPrefix 单独拼,避免拼两次。
|
|
5036
|
+
* 回环地址一律不用——那是"对端自己"的地址,拨过去只会打到本机。
|
|
5037
|
+
*/
|
|
5038
|
+
function lanTunnelBase(tunnel) {
|
|
5039
|
+
try {
|
|
5040
|
+
const raw = String(tunnel?.url ?? "").trim();
|
|
5041
|
+
if (!raw) return "";
|
|
5042
|
+
const u = new URL(raw);
|
|
5043
|
+
if (!u.hostname || isLoopbackHost(u.hostname)) return "";
|
|
5044
|
+
return `${u.protocol}//${u.host}/`;
|
|
5045
|
+
} catch {
|
|
5046
|
+
return "";
|
|
5047
|
+
}
|
|
5048
|
+
}
|
|
5049
|
+
|
|
5010
5050
|
/** 在对端名片的 tailnet 端点(100.64/10)上开会话出口。 */
|
|
5011
5051
|
async function openWebStream(target, address) {
|
|
5012
5052
|
const ep = orderedEndpoints(target).find((item) => item?.transport === "tsnet" && item.host);
|