Repository navigation
VLESS Multiplex, Reverse Proxy: Refactor to move code into VLESS; Mux only uses settings.multiplex in VLESS/VMess outbound - #7364
Conversation
…rough Since 5745dea the workers' common.Interrupt(link.Writer) reaches a MutexWriter, which embeds only buf.Writer, and does nothing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Let VLESS own the configured Mux and XUDP pools and feed Mux frames through the VLESS codecs without the carrier pipe bridge. Keep legacy factories for other outbounds and preserve the existing logical link handoff. Close the carrier independently of frame writes and retire the pools and preconnections with their handler. Preserve first-flight processing and final bytes returned with a terminal read error.
Abort an XDrive transport independently of a blocked frame writer while preserving graceful EOF for an idle carrier. Cancel the owned storage session and announcement, reject writes that reach admission after cancellation, and keep graceful WAL drain behavior for live sessions. Exercise a full unacknowledged slot ring through the direct VLESS Mux handler, idle peer EOF, slot and WAL admission, and cancellation of a pending announcement.
|
没什么必要继续穿透封装 这里不会有多大开销的 |
|
@svlavr rebase main #7355 (comment) 的意思是把 Mux 的代码移到 其它出站不给开 mux.cool 了,入站的话就 VMess 留一个兼容吧,且等新 Mux 稳定后出站不需要 |
|
This is a draft, still under development. I reworked it around your clarification: move Mux into VLESS and remove the old generic connection path. Mux now lives in On the transmit side, frames go directly through the VLESS codec. The receive side retains one existing I compared several alternatives:
The bounded writes follow your concern in #7345. The receive buffer addresses the separate read/parse overlap measured above. Direct writes also require an interruptible XDrive connection, so stopping Mux can unblock a write waiting on a full ring. A quiescent connection still closes with EOF. VLESS now closes its owned Mux pools and cancels unfinished connection creation during shutdown. The original receive-buffer thresholds are retained: 64 KiB for ordinary Mux and 16 KiB for Reverse. I compared both updated endpoints with main
Single-stream results varied substantially. These local measurements do not establish a speedup for every workload or transport. The fixes from #7359 and #7375 are preserved. Ordinary transports default to concurrency 8 and keep explicit positive values. XDrive retains the minimum of 128. XUDP settings are unchanged. Retirement of The full PR diff against main This is the first working version. I am still working on it. Comments, suggestions, |
|
@svlavr 原有的 mux 文件夹全删了,outbound 不要新开一个文件,直接改新 mux 文件夹,reverse 调用 mux 的方式也改 |
|
一步到位再弄个 |
|
类似 reverse,配置方式是 |
|
Updated the draft following your latest comments. Removed Added Direct writes and one receive pipe are retained. The fixes from #7359 and #7375 are preserved. I am continuing to optimize the implementation and compare alternatives. |
|
|
|
I am continuing to simplify the draft. In commit 2abab46, I included a small reduction that preserves the existing functionality, after comparing several ways to remove pipes and change how Link is used. I removed the unused response buffer from the Reverse control session. It was created for replies, but nobody read from it. Incoming data on that side is now released through I also removed duplicate Bridge and Portal initialization. The shared constructors are now Five unreachable lines following the error for the removed This commit touches 10 functions and one struct field:
In a separate construction/close measurement, the Reverse control worker went from 89 to 78 allocations, with allocated bytes falling from approximately 13,647 to 13,032 bytes per operation. This measures control-worker construction and cleanup. Alternatives compared:
For now, direct transmission and one receive pipe remain. The other buffers have separate responsibilities, including backpressure, session termination and XUDP reassociation. This commit: 6 files, +16/-40, net -24 lines. The full PR against main This remains a draft, and I am continuing to work on it. Comments, suggestions, |
|
|
|
This is the first working version for review, updated in Mux now lives in Client and server share frame parsing and connection lifecycle code. The old generic Mux connection machinery and duplicate shutdown paths are removed. Ordinary child responses go through One receive pipe remains on each outgoing carrier so transport reads can proceed independently of frame parsing and delivery. The original thresholds remain: 64 KiB for ordinary connections and 16 KiB for Reverse. XUDP retains its own association queues for reconnection; the old binding stops reading before the new binding takes over. No new server session-count or rate limit is introduced. Reverse no longer has duplicate initialization, the unused control-response buffer or a periodic collector for completed Portal handlers. Closing a handler removes that exact handler. Heartbeats and reconnection are retained. Close and interruption now pass through the reader and UDP destination-override wrappers. Native timeout-capable readers use their existing timeout mechanism without an extra reader goroutine. Canceling a blocked XDrive write unblocks it; normal shutdown of an idle connection retains EOF. Incoming VMess Mux compatibility is retained. The existing VMess UDP-cone path through Local Windows loopback measurements used both matching endpoints, six paired runs per workload, and byte-verified echo traffic. The single-stream workload transferred 512 MiB; the mixed workload transferred 1 GiB across eight bulk streams, with a small request/response stream sharing the carrier. Medians were:
Non-generated production Go code against upstream Comments, suggestions, |
|
I’m working on removing the remaining |
vmess出都要删? 这是vmess的东西的东西啊甚至有mux的协议指令 |
#4231 (comment) 本来就不会是原版 mux 了, 真要继续支持的话无非是加个调用加些参数的事,但有什么必要,一年前 Reverse 只留 VLESS 了也没人说还要给 VMess 留着 |
|
如果真是一个全新东西那break都炸 如果兼容老的那么本质还是一样的 |
… only uses `settings.multiplex` in VLESS/VMess outbound (#7364) #6748 (comment) #7240 (comment) #4231 (comment) #7355 (comment) #7359 (comment) #7364 (comment) #7364 (comment) #7364 (comment) #4231 (comment) #7364 (comment) #7364 (comment) #7364 (comment) --------- Co-authored-by: Codex <[email protected]> Co-authored-by: RPRX <[email protected]>
|
这个 PR 终于告一段落,不过我这两天可能会趁热打铁参照 XMUX 给 Mux 实现 #4231 等参数,@svlavr 相比于简化 VMess 代码,你先把 proxy 乃至整个 core 里没用 DispatchLink() 的改为它并把 Dispatch() 彻底删掉 #5143 (comment) ,我会给它实现 #7346 (comment) 所述的发现 UDP destination 不同时重新看一下路由,对于 TCP 则是需要重新弄回 writev #6110 (comment) 服务端也可以配置 Mux 参数主要是多用户共用参数,此时不允许 plain TCP/UDP 连上以便强制 padding,XHTTP 会解锁 Mux 以缓解这种问题 #6755 (comment) ,
|
|
v2rayN&G 已全面删掉 vnext、users 所以很快可以彻底 break 掉一些旧配置, |
|
以及对 core 旧架构的重构 #7470 (comment) ,我打算先从底层架构下手(先不动 common),方便实现单连接控制 #5844 等 |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
|
This comment was marked as off-topic.
This comment was marked as off-topic.
|
|
|
合并 #7467 前想到这个 drop UDP/443 也得重新弄应该会弄个全局 ban,补充进 #7467 (comment) 吧路由加选项 @Fangliding |
|
然后大概把 Mux、Vision 等处单独选项去掉,或许弄 Seed #5102 时再改,又涉及 testseed、testpre, |
This comment was marked as outdated.
This comment was marked as outdated.
|
@RPRX, am I understanding the next task correctly?
|
|
@svlavr 大多数入站的 TCP 已经是 DispatchLink() 了(弄回 writev #6110 (comment) ),主要是改 UDP,不过你别弄逐包路由 针对 cone UDP 中途不同 destination 的路由看 @Fangliding 有无兴趣 #7346 (comment) #7467 (comment) #7364 (comment) |
…ide, instead of blocking it at server side #7364 (comment) #6755 (comment) #6755 (comment)
|
由于改 c5ccb35 所以看了 core 的一些代码,给我的感觉就是,因为 *ray 底层架构和接口的过度设计、不当设计和混乱(多年屎山),导致在它之上的代码(尤其是 proxy 文件夹内的)也只能写成一坨,比如首先就是我几年来多次批评的一个功能动不动就搞注册和回调增加代码成本,光看代码都不知道谁调谁,真想骂人他妈的设计成一串线性下来清清楚楚的会死吗,但是线性的话也存在有些塞 ctx 里有些靠一路传参到底的问题,不是,太混乱了,我觉得要么就弄个结构体把上文都安排进去要么就全塞 ctx 里(好吧本质上也是结构体),光到这里还不够毕竟这还是有的塞的,还有高手比如 TCP worker callback proxy inbound handler 竟然只传 conn 不传 ctx,?离了个大谱我他妈震惊,后面的代码若想干点啥高级的不就只能写成一坨吗,当初 v2ray 设计成这样可能是因为一开始没搞底层传输、后来只作为 proxy 的插件但插得比较混乱,光是底层传输自身代码内都绕来绕去,不是,至少得把 TCP/UDP worker 啥的 merge 进来并梳理清晰吧,公共组件的话 buf 和 pipe 还算有点用(缓存 readv/writev)虽然但是 pipe 塞 transport 文件夹里是何意味,而 pb 配置完全就是败笔非要 json 转一层,属于没清干净,
|
|
上文 TCP worker callback 那里指的是传输层子连接的 ctx 没传进 proxy inbound handler, |
|
I agree. I tried to solve a similar problem in my fork. I wanted to see directly from Go which node each flow was routed through, whether it was actually carrying traffic, and close selected flows on a particular node when needed. Closing a flow was the easy part. The harder part was tracing where the flow lives and which component owns its resources. For example, a single UDP session can send packets through different nodes. Traffic needs to be accounted for per node, and closing the session should leave unrelated sessions alone. In the end, tracking and controlling flows added more than three thousand lines of code, excluding tests. I looked at how a few other proxy cores handle this. Their main connection-tracking and control code is a few hundred lines, and it is easy to follow the path to the component that closes the connection. So I agree that Xray should start by passing the context from the transport to the handler and making it clear who owns the connection from open to close. |
…axReuseTimes is unlimited; Automatically enable Mux at client side; Reject non-Mux/Rvs requests at server side #7358 (comment) #7208 (comment) #7364 (comment)
This PR moves Multiplex to
proxy/vless/multiplexand VLESS Reverse toproxy/vless/reverse. VLESS, VMess, and Reverse share the same Multiplex implementation. These paths pass decoded traffic throughDispatchLinkwithout intermediatepipelinks.Protocol support
Outbound Multiplex is available for VLESS and VMess. Other outbound protocols use ordinary connections. VMess uses the shared implementation for inbound and outbound Mux. Ordinary VMess TCP and UDP keep the direct path from #5143. Reverse now uses the VLESS implementation, and the old standalone Reverse application has been removed.
VLESS and VMess outbound configuration
Add
multiplexunderoutbounds[].settings, alongside the protocol's other settings. This fragment enables the shared pool for up to eight active streams per connection.{ "settings": { "multiplex": { "concurrency": 8, "xudpConcurrency": 0, "xudpProxyUDP443": "reject" } } }concurrencyenables the shared pool. A positivexudpConcurrencyenables a separate XUDP pool. If onlyxudpConcurrencyis positive, TCP uses ordinary connections. WithxudpConcurrencyomitted or zero, UDP uses the shared pool when available.multiplexor leave both counts at zero to use ordinary connections. An empty object{}also leaves Multiplex off. The oldenabledproperty has no effect. Negative counts are rejected.xudpProxyUDP443applies when there is a pool for UDP/443. The defaultrejectreportsXUDP rejected UDP/443 traffic.skipuses the ordinary path, andallowuses the pool. UDP/443 uses the ordinary path when there is no applicable pool.concurrencyunless Reverse opens its own carrier. The shared XDrive pool uses a minimum concurrency of128.Legacy settings and API
Xray ignores the top-level
outbounds[].muxkey. During JSON loading it writes one warning to standard output per outbound containing that key, including whensettings.multiplexis also present. The new settings determine whether Multiplex is enabled.API clients set
multiplexin the VLESS or VMess outbound protocol configuration. The oldSenderConfig.multiplex_settingsfield is ignored.