Skip to content

XTLS Vision: Refactor code to use DispatchLink() in VLESS inbound - #5076

Merged
RPRX merged 3 commits into
mainfrom
pipe
Sep 1, 2025
Merged

RPRX merged 3 commits into
mainfrom
pipe

Conversation

@yuhan6665

Copy link
Copy Markdown
Member

@RPRX 来了 需要人帮忙测试

@RPRX

RPRX commented Sep 1, 2025

Copy link
Copy Markdown
Member

我自己用几天试试

@RPRX

RPRX commented Sep 1, 2025

Copy link
Copy Markdown
Member

入站 sessionPolicy 开始那一段也可以删了

@RPRX

RPRX commented Sep 1, 2025

Copy link
Copy Markdown
Member

入站 reader 需要套上 TimeoutWrapperReader 不然会影响 sniffer,rebase 一下

另外改成 DispatchLink() 貌似会影响 Mux,你找下是啥原因?

@RPRX

RPRX commented Sep 1, 2025

Copy link
Copy Markdown
Member

Wait,我在 force

@RPRX

RPRX commented Sep 1, 2025

Copy link
Copy Markdown
Member

Mux 那个你试一下吧,我还没找到是啥原因,我这里测试 main 那三个入站是能套 Mux 的,但 CPU 100%

@RPRX

RPRX commented Sep 1, 2025

Copy link
Copy Markdown
Member

搞快点的话明天可以再发个版

@yuhan6665

Copy link
Copy Markdown
Member Author

Mux 那个你试一下吧,我还没找到是啥原因,我这里测试 main 那三个入站是能套 Mux 的,但 CPU 100%

Mux 还没搞懂跟 pipe 的关系 准备/可能先跑路 有空再回来研究

@Fangliding

Copy link
Copy Markdown
Member

我之前测了没复现出来
在配置里加个

"metrics": {
    "tag": "Metrics",
    "listen": "127.0.0.1:11111"
}

就可以 go tool pprof http://localhost:11111/debug/pprof/profile?seconds=10 了

@RPRX

RPRX commented Sep 1, 2025

Copy link
Copy Markdown
Member

那我先合了这个 PR 自己测测吧,还有要改的吗

@yuhan6665

Copy link
Copy Markdown
Member Author

那我先合了这个 PR 自己测测吧,还有要改的吗

行吧 目前没啥要改的

@RPRX

RPRX commented Sep 1, 2025

Copy link
Copy Markdown
Member

rebase

- Move more logic to VisionReader/Writer
- Remove XtlsWrite()
- XtlsRead now only handle splice at the outbound
- This helps VLESS inbound to have simple buf.copy() so that we can remove pipe next
@RPRX RPRX changed the title Xtls: code refactor XTLS Vision: Refactor code to use DispatchLink() in VLESS inbound Sep 1, 2025
@RPRX
RPRX merged commit 4064f8d into main Sep 1, 2025
@wyx2685

wyx2685 commented Sep 2, 2025

Copy link
Copy Markdown
Contributor

DispatchLink()导致不能套SizeStatWriter,stats流量统计失效
尝试修改DispatchLink()只能操作outbound.Writer,可以统计下载流量,上传暂时无解?

@RPRX

RPRX commented Sep 3, 2025

Copy link
Copy Markdown
Member

我之前测了没复现出来

坏了,我给 VLESS 开 Mux 也没复现出来,似乎没有问题

@RPRX
RPRX deleted the pipe branch September 3, 2025 00:38
@RPRX

RPRX commented Sep 3, 2025

Copy link
Copy Markdown
Member

DispatchLink()导致不能套SizeStatWriter,stats流量统计失效 尝试修改DispatchLink()只能操作outbound.Writer,可以统计下载流量,上传暂时无解?

这个是什么问题,流量统计是套了个 Conn,不会被绕过啊,ReadV/Splice 也是专门处理了流量统计

@wyx2685

wyx2685 commented Sep 3, 2025

Copy link
Copy Markdown
Contributor

stats的流量统计是在getlink()里面对writer包了一层
不走getlink ()就不会包

@RPRX

RPRX commented Sep 3, 2025

Copy link
Copy Markdown
Member

我看了下 SizeStatWriter 是统计单用户流量是吧,修这个简单,但有个问题就是 Splice 什么的好像也给它绕过了?

@RPRX

RPRX commented Sep 3, 2025

Copy link
Copy Markdown
Member

看了下代码,Splice 专门处理了 SizeStatWriter

我在想加个 SizeStatReader 还是

@RPRX

RPRX commented Sep 3, 2025

Copy link
Copy Markdown
Member

我把 TimeoutWrapperReader 扩展一下带上流量统计的功能吧,然后 DispatchLink 时自动带上,再写写 Splice

@RPRX

RPRX commented Sep 3, 2025

Copy link
Copy Markdown
Member

不过还得把 mux 也改成 dispatchLink()

@yuhan6665

yuhan6665 commented Sep 3, 2025 •

Copy link
Copy Markdown
Member Author

我把 TimeoutWrapperReader 扩展一下带上流量统计的功能吧,然后 DispatchLink 时自动带上,再写写 Splice

yes that might be the best

statWriter.Counter.Add(w) // user stats

When inbound receive first packet, it doesn't know about the user yet. So should be handled later. If we add stats in DispatchLink(), splice can probably be left as is.

@yuhan6665

Copy link
Copy Markdown
Member Author

不过还得把 mux 也改成 dispatchLink()

I can take a look at the other inbounds later

@RPRX

RPRX commented Sep 3, 2025

Copy link
Copy Markdown
Member

@yuhan6665 mux 那个有点麻烦,你改下其它入站的吧,都改成 dispatchLink 就好了

本来今天想发个版庆祝一下,结果这流量统计看起来得 v25.9.5 了

@yuhan6665

Copy link
Copy Markdown
Member Author

没事小问题 当时加 splice 这个 user stats 坏了半年才有人反馈

@RPRX

RPRX commented Sep 3, 2025

Copy link
Copy Markdown
Member

@yuhan6665 有空的话你先改一下吧,我不确定是 DispatchLink() 内给 TimeoutWrapperReader 加还是,可能在外面加好一点就先不用改 mux 了,因为入站实际上是先跑到 mux 再由它调用 default 的 DispatchLink()

@RPRX

RPRX commented Sep 3, 2025

Copy link
Copy Markdown
Member

倒是可以先扩展下 TimeoutWrapperReader 的功能,然后 DispatchLink() 内再把那个值给填上

@RPRX

RPRX commented Sep 3, 2025

Copy link
Copy Markdown
Member

不过如果 mux 不要求 timeout 的功能的话其实可以统一 default DispatchLink() 内再套上 wrapper,我简单看了下应该是不要求的

RPRX added a commit that referenced this pull request Sep 3, 2025
@RPRX

RPRX commented Sep 3, 2025

Copy link
Copy Markdown
Member

d20397c 先这样吧,到处改改,quick fix,反正很快要重构把这些乱七八糟的理清楚

除了 reverse 那处断言我不确定外应该没问题

@RPRX

RPRX commented Sep 3, 2025

Copy link
Copy Markdown
Member

@wyx2685 你测下还有没有问题

@RPRX

RPRX commented Sep 3, 2025

Copy link
Copy Markdown
Member

Splice 那里我看了现在是只自动处理了下行流量,所以逻辑不用改

@wyx2685

wyx2685 commented Sep 4, 2025

Copy link
Copy Markdown
Contributor

@wyx2685 你测下还有没有问题

测了下xray统计应该是修好了
我这边魔改还得搏斗一下

@BrewTestBot BrewTestBot mentioned this pull request Sep 5, 2025
1 task done
@RPRX RPRX mentioned this pull request Sep 5, 2025
5 tasks done
@qh-wells qh-wells mentioned this pull request Oct 22, 2025
5 tasks done
it2konst pushed a commit to it2konst/game-tun that referenced this pull request Mar 1, 2026
…LS#5076)

* Xtls: code refactor

- Move more logic to VisionReader/Writer
- Remove XtlsWrite()
- XtlsRead now only handle splice at the outbound
- This helps VLESS inbound to have simple buf.copy() so that we can remove pipe next

* Add bufferFlushNext; Use DispatchLink() in VLESS inbound

* Use TimeoutWrapperReader; clean up timer/buffer
it2konst pushed a commit to it2konst/game-tun that referenced this pull request Mar 1, 2026
drovosek229 pushed a commit to drovosek229/Xray-core that referenced this pull request Mar 16, 2026
…LS#5076)

* Xtls: code refactor

- Move more logic to VisionReader/Writer
- Remove XtlsWrite()
- XtlsRead now only handle splice at the outbound
- This helps VLESS inbound to have simple buf.copy() so that we can remove pipe next

* Add bufferFlushNext; Use DispatchLink() in VLESS inbound

* Use TimeoutWrapperReader; clean up timer/buffer
drovosek229 pushed a commit to drovosek229/Xray-core that referenced this pull request Mar 16, 2026
wyusgw pushed a commit to wyusgw/Xray-core that referenced this pull request Sep 15, 2026
@makirov03 makirov03 mentioned this pull request Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants