Skip to content

XMC finalmask: Make startup paddings configurable (direction, length and delay) - #6769

Merged
RPRXX merged 5 commits into
XTLS:mainfrom
spr334-a:xmc-padding-config
Nov 14, 2026
Merged

RPRXX merged 5 commits into
XTLS:mainfrom
spr334-a:xmc-padding-config

Conversation

@spr334-a

@spr334-a spr334-a commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor
Follow-up to #6487, covering the startup-padding part of #6732.

Adds an optional `padding` array to XMC settings with configurable direction per turn:

```json
{
  "padding": [
    {"length": "44", "direction": "c2s"},
    {"length": "64-128", "direction": "s2c"},
    {"length": "25", "direction": "c2s"},
    {"length": "32768-49152", "direction": "s2c"}
  ]
}

Each entry specifies a fixed length or inclusive range, plus direction ("c2s" for client-to-server or "s2c" for server-to-client; full names "client-to-server" and "server-to-client" are also accepted). Turns can be in any order and direction, including consecutive same-direction turns. Both endpoints need the same array. The first length includes Login Acknowledged's two bytes; invalid ranges and directions are rejected during config loading and connection setup.

Omitting the padding field entirely preserves the existing 26.1.2 preset. Custom turns have no intentional delays. Data framing, keep-alives, and mask ordering are unchanged. No new dependency or wire-format change.

This deliberately leaves profile registries, version negotiation, and ongoing traffic scheduling for separate discussion. In particular, existing length checks are not a configuration-fingerprint handshake and do not detect every endpoint mismatch; the documentation calls this out.

Tests cover range validation, direction validation, prefix and VarInt boundaries, default-preset preservation, and encrypted bidirectional round trips with single, odd, and even turn counts.

Checked on Windows with Go 1.27.0:

go test -count=20 ./transport/internet/finalmask/xmc
go test -race -count=1 ./transport/internet/finalmask/xmc
go test -count=1 ./infra/conf
go test -count=1 ./transport/internet/finalmask/...
go vet ./transport/internet/finalmask/...
go build ./main
go run ./infra/vformat/main.go -mode check -pwd ./

go vet ./infra/conf reports existing unreachable code at infra/conf/xray.go:606, also reproduced on the base commit.

@RPRX

RPRX commented Sep 17, 2026

Copy link
Copy Markdown
Member

@Fangliding 你先看一下吧

@BolTun-prog

Copy link
Copy Markdown

Sounds interesting

if turn == nil || turn.LengthMin < 1 || turn.LengthMax < turn.LengthMin || turn.LengthMax > maxPaddingTurnLength {
return nil, fmt.Errorf("invalid padding length range at turn %d", i)
}
direction := paddingClientToServer

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, that switch case better use for this business logic

Password: password, RsaPrivateKey: privateKey, RsaPublicKey: publicKey,
Hostname: "localhost", Padding: padding,
Profiles: []*Profile{{
Username: profile.Username, Uuid: profile.UUID[:],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Username: profile.Username, Uuid: profile.UUID[:],
Uuid: profile.UUID[:],

Why are you using slice splice, I think, you shoud use copy for profile.UUID

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think a copy is needed here ,uuid isnt modified later in this test

@RPRX

RPRX commented Sep 20, 2026

Copy link
Copy Markdown
Member

@spr334-a ready 了吗,给文档开个 PR

@RPRX

RPRX commented Sep 28, 2026

Copy link
Copy Markdown
Member

所以这个 padding 是否符合“两端配置一样、对端有检查”?这是通过单/双来区分哪个端的?客户端不能连发两个 padding?

@BolTun-prog

Copy link
Copy Markdown

@spr334-a Are you merging it?

@RPRX

RPRX commented Oct 5, 2026

Copy link
Copy Markdown
Member

需要做到“客户端能连发两个 padding”才会合并

Add direction field to Padding protobuf message to allow users to specify whether each padding turn goes from client to server (1) or server to client (2). This removes the previous limitation where padding turns had to alternate directions.

Changes:
- Add direction field to Padding message in config.proto
- Update config.go to read direction from config instead of alternating
- Remove validation that prevented consecutive same-direction turns
- Update all tests to specify direction explicitly
- Add test case for consecutive same-direction padding
@spr334-a
spr334-a force-pushed the xmc-padding-config branch from d23bf4d to 7eaa1dd Compare October 5, 2026 12:41
@BolTun-prog

Copy link
Copy Markdown

需要做到“客户端能连发两个 padding”才会合并

Sorry, the translation from Chinese to English is not very good, could ypu explain on English?

@spr334-a

spr334-a commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Sorry, the translation from Chinese to English is not very good, could ypu explain on English?

Client need to support sending two or more padding at once before merging

@BolTun-prog

Copy link
Copy Markdown

Sorry, the translation from Chinese to English is not very good, could ypu explain on English?

Client need to support sending two or more padding at once before merging

Do you make this?

@BolTun-prog

Copy link
Copy Markdown

Or you want my features?

@spr334-a

spr334-a commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Or you want my features?

Wdym?

@BolTun-prog

Copy link
Copy Markdown

Or you want my features?

Wdym?

Rework your PR

@spr334-a

spr334-a commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Sorry, the translation from Chinese to English is not very good, could ypu explain on English?

Client need to support sending two or more padding at once before merging

Do you make this?

I committed the changes before you asked

@BolTun-prog BolTun-prog left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good

@BolTun-prog

Copy link
Copy Markdown

@RPRX Can we merge?

@RPRX

RPRX commented Oct 8, 2026

Copy link
Copy Markdown
Member

@spr334-a 最好再支持一下加延迟吧,更新 PR 配置示例和 README,另外原先的默认 padding 参数改成基于新配置的缺省值

Parse direction field and use explicit object format.
@spr334-a
spr334-a force-pushed the xmc-padding-config branch from e144fea to 50d8ed4 Compare October 8, 2026 12:32
@RPRX

RPRX commented Oct 10, 2026

Copy link
Copy Markdown
Member

@spr334-a 数组一般加 s,所以叫 paddings 吧,里面加一个配置项 delay,单位为毫秒

Per rprx's request: array fields use plural form, and add configurable delay in milliseconds after each turn.
@RPRX

RPRX commented Oct 12, 2026

Copy link
Copy Markdown
Member

@spr334-a 修一下 test

@RPRX

RPRX commented Oct 12, 2026

Copy link
Copy Markdown
Member

@spr334-a delay 也要为 string,支持 range,对端等待 min value 后再开始检查下一个 padding 是否到达

@RPRX

RPRX commented Oct 29, 2026

Copy link
Copy Markdown
Member

@spr334-a rebase 并把 delay 改为 string 即可合并

@RPRXX

RPRXX commented Nov 14, 2026

Copy link
Copy Markdown
Member

#7401 (comment) 然而刚发现这个 PR 还没开允许修改,只能合并后再 fmt 了,由于要 force-push,这下不得不用唯一小号了

解释一下:我从不从我的设备连接到 XTLS 仓库,习惯使然,以防哪次没注意泄露了本地 Git 信息,最初甚至只能 Upload files

@RPRXX RPRXX changed the title XMC: make startup padding lengths configurable XMC finalmask: Make startup paddings configurable (direction, length and delay) Nov 14, 2026
@RPRXX
RPRXX merged commit cc9be37 into XTLS:main Nov 14, 2026
20 of 24 checks passed
@RPRXX

RPRXX commented Nov 14, 2026

Copy link
Copy Markdown
Member

5d17b87 fmt 了,并把 xmc 文件夹下 README.md 和 *_test.go 删了,AI 喜欢写没必要的 tests,接下来交给 @yandujun363

@RPRXX

RPRXX commented Nov 14, 2026

Copy link
Copy Markdown
Member

另外导致大号“codespaces 本月配额无端耗完了”的原因,昨天只看到是 15GB 空间耗完,后来想到了应该是因为有几次在 VSC 中安装了 Go 插件,自动把 Xray 那些依赖全 pull 下来了,并且还会安装些工具,这下这个月的 force-push 只能靠这个小号了

以前都是随时开个 codespace、用完删掉,看来以后需要安装 Go 插件的话得开个常驻的了,还有些想公开记录的,突然忘了

yandujun363 added a commit to yandujun363/Xray-core that referenced this pull request Nov 15, 2026
Sync with the squashed XTLS#6769 merge and keep the follow-up delay-range
change. Follow the maintainer's cleanup of XTLS#6769 and drop the XMC
README/*_test.go files it removed; the unrelated XMC tests deleted by
that squash are not restored here.

The XMC delay implementation, its validation, and the infra/conf delay
parsing tests remain.

Assisted-by: DeepSeek (AI)
@RPRX RPRX mentioned this pull request Nov 16, 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