fix(server): 补 #5 国内分流的 DNS 面 + 链路诊断端点(#12)

#5 只分了数据面(geoip/geosite-cn 路由 direct),DNS 仍 final:remote 全量经隧道
解析 → 国内域名解析到非 CN IP、漏过 geoip-cn 又走隧道(白盒实测国内 TLS
1000-1660ms;修后 ~50ms)。

- clientconfig.go: 开分流时 dns.rules 加 {rule_set:[geosite-cn]→local},国内域名
  用 local(223.5.5.5)直连解析 → 拿到真 CN IP → geoip-cn 命中直连
- main.go: PANGOLIN_PUBLIC_URL 缺失时启动告警(空则分流静默跳过,是隐蔽坑)
- nodes.go: connect 渲染加可观测日志(split_cn/rules_base/split_active/bytes)
- diag.go: 新增只读端点 GET /v1/diag/egress?host=X,节点侧量出海段耗时(白名单
  防 SSRF、只回耗时数字),供白盒拆「接入段 vs 出海段」

验证:go test(splitCN 开渲染 dns.rules→local、关无 dns.rules)+ go vet;cara
实测国内 TLS 1000ms+→~50ms、接入段占 TLS 握手 ~98%。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-06-22 14:12:31 +08:00
parent 43b25c8aa0
commit bc890974c0
5 changed files with 146 additions and 4 deletions
+18 -1
View File
@@ -61,11 +61,28 @@ func TestBuildClientConfigSplitCN(t *testing.T) {
t.Error("missing cn-direct route rule (rule_set→direct)")
}
// 关闭分流 → 无 rule_set
// DNS 面分流:开分流时国内域名(geosite-cn)用 local 解析,不走 remote(隧道)
var m map[string]any
_ = json.Unmarshal(cfg, &m)
dnsRules, ok := m["dns"].(map[string]any)["rules"].([]any)
if !ok || len(dnsRules) == 0 {
t.Fatalf("split on should have dns.rules (geosite-cn→local), got %v", m["dns"])
}
dr := dnsRules[0].(map[string]any)
if dr["server"] != "local" || dr["rule_set"] == nil {
t.Errorf("dns rule should route geosite-cn → local, got %v", dr)
}
// 关闭分流 → 无 rule_set,且 DNS 无分流规则(全量 remote)。
cfg2, _ := BuildClientConfig(testNode(), "uuid-1", "k", ClientConfigOpts{})
if _, ok := routeOf(t, cfg2)["rule_set"]; ok {
t.Error("split off should have no rule_set")
}
var m2 map[string]any
_ = json.Unmarshal(cfg2, &m2)
if _, ok := m2["dns"].(map[string]any)["rules"]; ok {
t.Error("split off should have no dns.rules")
}
// 开启但缺 base → 静默不分流(避免渲染出无效 rule_set URL)。
cfg3, _ := BuildClientConfig(testNode(), "uuid-1", "k", ClientConfigOpts{SplitCN: true})