Repository navigation
Conversation
|
|
|
体积仅增加约 500KiB 只给 DNS 用看起来比较鸡肋,因为通过复杂的配置也可达成相同效果,且性能更佳 主要目的是接下来把其它模块都串起来,以满足一些特殊需求,比如:
|
|
重爆了这 主要是就为了一个dns引这玩意 |
有效代码 600 行,体积增大 500KiB
画个大饼 -- balancer 改变了出口时,修改 dns 的 ecsip
function on_balancer_change(balancerId, outbound)
dns.servers["default_proxy"].clientIp = ecs[outbound]
end-- balancer 入站 ip 粘性,每次使用都续期;连续 5 分钟未使用才过期,出口故障则立即重新选择。
function balance(inbound_ip)
local tag = sticky.get(inbound_ip)
if tag and outbound.is_alive(tag) then
sticky.touch(inbound_ip, "5m")
return tag
end
tag = balancer.select()
sticky.set(inbound_ip, tag, "5m")
return tag
end |
|
我看到上面说的二进制大小的膨胀了 不是只有这样重 还有加这玩意的额外逻辑和维护问题 |
|
如果只是为了选 DNS,确实没必要引入 Lua。 维护成本当然存在,但没有想象中那么重。暴露一个 API 或者 hook 只需要几十行代码比如 219f758 |
|
如果能够做到 lua 插拔自定义 mask 真的很酷,然后 core 里就只保留一些通用性强的 mask 我个人是支持这个的,但 #6718 的 0 vibe 纯手工重构已经把我精力耗光了,需要来个 gap year,以及后续需要写点 rust 找回之前写 c 的手感 (写了这么多 go 手感全无),如果有人能来主持 finalmask 会很好 |
|
虽然我从没看过 finalmask 的代码(甚至都没用过) 所以设计时也考虑了并发、内存和脚本的生命周期 比如 custom header 那个大号计算器,改用 Lua 后就能写条件分支、循环,保存连接里的变量 再往后,现在 fm 都是各干各的,想改点行为又得在 core vibe 一套 |
|
|
|
我设想把脚本分成三种生命周期:
三种脚本拥有相同的 Event 订阅和操作 Xray 的能力,区别只在于实例生命周期和适用的 Hook 点。 这样侵入的很小,就像现在这个 DNS 一样。
|
|
NEXT 架构大概是组件可任意串联,尤其是哪里都能塞路由/DNS,以及增强匹配/行为语法(比如这个 lua), |
|
|
|
我觉得这个功能可以剥离xray-core,只需要在xray-core里面留一个扩展接口/api,通过接口连接外置一个lua runtime二进制 |
…e IP slice userdata
|
剥离出去代码反而会变重,基本没法写 我先后试过 tengo yaegi wazero goja gopherlua 考虑接口暴露便利程度、并发安全、跨语言调用性能、内存开销、脚本自身执行性能、修改方便程度 lua 几乎是唯一解 |
跟 finalmask 难点一样,想要把 payload 完全读到脚本 vm 去做会有性能问题 最快的是 wazero 但它太太太重了 目前此 pr 已经是 ready 状态 |
Expose localdns.Client in xray.dns.Servers with the ID "localhost", so Lua scripts can use the same server API for both clients.
Prevent the idle slice's backing array from retaining discarded states.
|
@Meo597 再次 ready 了吗,文档先写一下 |
|
再次 ready 了 因为是热路径不能用反射,所以花了许多功夫优化,写的比较啰嗦 下个 PR 是一些 event 和对 xray 的一些操控,全局型的脚本 |
script for dns and routing
Upstream's Lua scripts (XTLS#6823) have two problems that keep them out of this fork for now: - common/lua.Pool creates one state (about 177 KiB plus the script's data) per concurrent call and only bounds idle states. With a script on an inbound that accepts unauthenticated connections, nothing caps the states or the factory runs. A plain semaphore is not a fix: a routing script whose DNS lookup re-enters routing holds one state while it waits for another, and a failed acquisition sends the connection to the default outbound, past the script. - Scripts load in Start, after the inbound manager starts, so the connections accepted first and the TUN DNS takeover probe see only the JSON rules. core.New now rejects a config that names a routing or DNS script while common/lua.ScriptsEnabled is false, which it always is outside tests. The check sits where each config is registered: an error from a deferred RequireFeatures callback can be lost, and this one must stop the instance. The upstream code stays compiled and tested, so later syncs merge without conflicts, and lifting the gate needs no revert. TestCoreRejects{Routing,DNS}ScriptWhileScriptsDisabled failed before this change: core.New accepted both configs. Review findings R1-1 and R1-3 on PR #33.
Maintainer decision on PR #33: the Lua scripts (XTLS#6823) ship as upstream ships them. This reverts 8d9977b, 6a6625a and 6562b8c, which made core.New refuse routing.script and dns.script. docs/FORK.md records the two risks accepted with this decision, review findings R1-1 and R1-3: the state pool has no bound on concurrent states, and scripts load after the inbound manager starts. The routing script still decides on the dispatcher's PickRouteTag path.
|
文档补了,即便有 AI 加持还是写的我人都麻了 |
|
备忘 写路由脚本的时候发现很多注入的参数其实用不到 以后有人觉得这里是瓶颈,可以改为初始化的时候脚本自己声明需要哪些参数 |
Sync the fork with upstream 7da5dae..v26.10.10 (13 commits). Conflict resolutions: - Routing and DNS Lua scripts (XTLS#6823): take them. The dispatcher picks routes through the fork's PickRouteTag, which bypassed the script hook upstream placed in PickRoute; PickRouteTag now runs the script too, and NeedsSniffingAttributes reports true while a script is loaded because a script can read attributes. Covered by script_fastpath_test.go and by upstream's TestRouterScriptDNSDispatcherReentry, which failed without it. - Logging: the Lua log module calls the fork's ShouldLog instead of upstream's GetSeverity; its tests save and restore the fork's handler snapshot and filter through Enabled. - Dispatcher: keep the ShouldLog guard and add upstream's error log for a failed route pick. - XDNS (XTLS#7095): take upstream's synchronous upload and its fragment manager without the per-client size counter. The fork's full-queue test becomes a test that every written packet reaches a resolver; the fragment-manager test checks entries only. - Hysteria (XTLS#7107): keep the fork's pool cleaner (docs/FORK.md); take only OmitMaxDatagramFrameSize: true, which the old date check already gave. - TLS client: keep session resumption in copyConfig and add upstream's GetClientCertificate bridge for MASQUE WARP. - go.mod: add gopher-lua (MIT), gopher-luar (MPL-2.0) and x509roots/fallback; keep golang.org/x/text v0.43.0. - Version stamp stays 26.10.6-2241 until the next fork release.
Upstream 8855145 (XTLS#6823, Lua `script` for dns and routing) binds app/dns into every routing script, and app/dns links the DoQ name server and with it github.com/apernet/quic-go. yue-node's check-profile-deps.sh forbids both in the VLESS role graph, so the rebased fork failed the consumer's profile boundary. The dns.RegisterLua call moves behind the profile tag: unchanged by default, and under yue_profile_vless a configured routing script is refused instead of running with a silently missing `dns` global. yue-node never configures a routing script. script_dns_vless_test.go asserts the refusal and that the VLESS app/router graph has neither app/dns nor quic-go; re-importing app/dns in the VLESS file turns it red. Co-Authored-By: Claude Opus 5.5 <[email protected]>
DNS 示例
{ "dns": { "script": "dns.lua", "tag": "dns-proxy", "servers": [ { "id": "cf", "address": "1.1.1.1" }, { "id": "google", "address": "8.8.8.8" }, { "id": "cn114", "address": "114.114.114.114", "tag": "dns-direct" }, { "id": "cn223", "address": "223.5.5.5", "tag": "dns-direct" }, { "id": "google-ecs", "address": "8.8.8.8", "clientIp": "222.85.85.85" }, { "id": "google-alt-ecs", "address": "8.8.4.4", "clientIp": "222.85.85.85" } ] } }Router 示例
{ "routing": { "script": "router.lua", "balancers": [ { "tag": "proxy", "selector": ["proxy-"], "strategy": { "type": "random" } } ] } }感觉这玩意更适合 finalmask 这个 vibe 重灾区
设计上尽量解耦,方便以后能挂在每条连接上,想咋玩就咋玩
预期是脚本能接入 dns inbound routing outbound balancer protocol finalmask
简单测了下性能可以接受,略吃内存,有待以后进一步优化call dns hook + dns client query 的耗时从 4714 ns 降为 1839 nscall dns hook 的内存从 816 B, 9 allocs 降为 16 B, 1 allocs经过多轮优化,目前是: