Repository navigation
feat(cluster): 扩展节点直连通道(kin-slot-gate,TLS),槽位请求不再挤在 SSH 长连接里 - #614
Merged
Merged
Conversation
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
摘要
扩展节点上的远程槽,所有 kernel / worker 请求都在控制面到节点的一条 SSH 长连接里各开一个通道。实测(美国控制面 → 日本节点,RTT 约 120ms)这条长连接平时只有零碎小包,偶尔一个几百 KB 的请求正文,拥塞控制把它的发送速率压在约 17KB/s(
ss -ti:bbr bw 110–140kbps、cwnd 8),而同一线路新建连接下载能跑到 340–370KB/s。整台节点的请求都排在这条连接后面:同为 Opus、缓存命中 ≥90% 的请求,首字中位数本地槽 4.2s、远程槽 12.8s。集群页的“链路延迟”也因此在 120ms 和 1–2s 之间跳。本 PR 加一条可选的直连通道:节点上跑一个很小的
kin-slot-gate,控制面对每个槽位请求新建一条 TLS 连接直达它,每条连接各自从慢启动开始,不再共用一个被压低的拥塞窗口。Docker、终端、健康检查仍走 SSH;直连不通时自动退回 SSH。变更
worker/cmd/kin-slot-gate(internal/slotgate,只用标准库)tls_dir(私钥 0600),重启沿用。KSG1 <token> <vm> <kernel|worker|ping>\n,5 秒内完成握手+前言;令牌按 SHA-256 常量时间比较。<root>/vms/<vm>/run/{kernel,worker}.sock;vm id 白名单;最后一段以O_PATH|O_NOFOLLOW打开、确认是 socket 后经/proc/self/fd连接,不跟随槽内植入的符号链接,也没有二次路径查找。src/lib/cluster/direct-link.mjs:在节点上建 / 刷新kin-slot-gate容器(宿主网络、只读根、CapDrop ALL,root 登录时只留DAC_OVERRIDE;<root>/vms只读挂载,仅gate/tls可写),借用节点上已有的槽位镜像运行静态二进制;容器 spec 摘要不变则不动。OK由控制面剥掉;建连只比 SSH 通道多一个 TLS 往返。SocketRelay增加可选dialDirect:直连成功就用直连,否则走原来的direct-streamlocal;槽 socket 不存在时与原来一样直接断开本地连接。cluster_node_direct_links(迁移 039,ON DELETE CASCADE),令牌经maybeEncrypt;令牌和指纹不出现在任何响应里。PUT / DELETE /api/panel/cluster/nodes/:id/direct-link({ address, port? },只收 IP 字面量,端口默认 7790)。npm run build:gate;Dockerfile、arm64 Dockerfile(节点用 amd64:KIN_CLUSTER_GATE_BIN)、入口ensure_bin、Release 附件kin-slot-gate、.gitattributes、docs/BUILD.md、docs/PANEL_API.md、CHANGELOG「未发布」。自检
go vet/gofmt/go test -race:internal/slotgate6 项(TLS 转发与半关闭、坏前言 / 错令牌 / 路径越界 / 缺 socket、符号链接不跟随、证书重启不变且丢失后重建、明文客户端拿不到 OK、配置校验),另编成 linux/arm64 在 Linux 容器里跑过同一组(覆盖O_PATH分支)。test/unit/cluster-direct-link.test.mjs7 项:TLS 假 gate 下正文先于 OK 发出且 OK 被剥掉、证书不符时零字节发出、拒绝码与超时、容器 spec(权限、可写目录)、SocketRelay直连 / 回退 SSH / 缺 socket、令牌与指纹在编辑后保留且不外泄、各种失败的退避与 ping 恢复、删除节点级联。cluster-node-edit.test.mjs的测试库补跑 039。kin-slot-gate二进制 + 控制面SocketRelay,5MB 正文经 TLS 半关闭完整送达;错令牌gate_auth、路径越界gate_bad_request、错指纹gate_cert_mismatch。test/unit全量:本分支与 main 失败的 13 个文件名单完全相同(本地 macOS 环境),其余全过;webformat:check/tsc -b/ eslint /vitest(459 项)全过;biome 无改动。未做