mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6765] [CLOSED] feat(mtproto): relay mode - ServerHello splitting (client-mss) for MTProto inbounds #6445
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6445
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6765
Author: @AndreyOsipuk
Created: 10/7/2026
Status: ❌ Closed
Base:
main← Head:feat/mtproto-relay📝 Commits (10+)
e6bfe52feat(mtproto): secured (dd) clients and warm DC pool options93f885cfeat(sub): add dd links for secured MTProto inboundsb7ec51cfeat(frontend): secured and warm DC pool settings for MTProto inboundsb7a7bb1feat(mtproto): expose the remaining mtg-multi options for MTProto inbounds6c2b49bfeat(sub): add tg://webproxy links for MTProto inbounds in WEB mode38bf58efeat(frontend): advanced mtg settings for MTProto inboundsd0e4b95fix(mtproto): say which mtg-multi build serves secured and WEB linksc8cb2c2style(mtproto): keep comment blocks to two lines4e747c0Merge branch 'main' into feat/mtproto-secured-dcpool8049e30fix(mtproto): gate secured and WEB on a confirmed mtg-multi build, drop the DC list📊 Changes
35 files changed (+4845 additions, -52 deletions)
View changed files
📝
docs/content/docs/en/config/inbounds.mdx(+31 -0)📝
docs/content/docs/ru/config/inbounds.mdx(+34 -0)📝
frontend/src/lib/xray/inbound-link.ts(+82 -23)📝
frontend/src/lib/xray/link-label.tsx(+5 -1)📝
frontend/src/pages/inbounds/form/protocols/mtproto.tsx(+406 -2)📝
frontend/src/schemas/forms/inbound-form.ts(+10 -3)📝
frontend/src/schemas/protocols/inbound/mtproto.ts(+196 -0)📝
frontend/src/test/link-label.test.ts(+7 -0)📝
frontend/src/test/mtproto-clients-link.test.ts(+54 -2)➕
frontend/src/test/mtproto-options.test.tsx(+421 -0)📝
go.mod(+1 -1)📝
internal/database/model/model.go(+23 -0)📝
internal/database/model/model_mtproto_test.go(+34 -0)📝
internal/mtproto/manager.go(+116 -10)📝
internal/mtproto/manager_test.go(+164 -1)➕
internal/mtproto/options.go(+772 -0)➕
internal/mtproto/options_test.go(+506 -0)📝
internal/sub/service.go(+23 -8)📝
internal/sub/service_mtproto_test.go(+127 -1)📝
internal/web/service/inbound.go(+8 -0)...and 15 more files
📄 Description
Summary
Lets an MTProto inbound work as a relay inside a censored network: mtg sends its FakeTLS ServerHello in small TCP segments towards clients, and reaches Telegram through an Xray outbound (for example a tunnel to a server abroad).
Problem
On a Russian ISP's DPI (TSPU), mtg's FakeTLS is recognised by the ServerHello when it leaves in full-size TCP segments, and the proxy's IP:port is then banned. We hit this with a relay inside the country that forwarded the TCP stream to an mtg abroad:
client-mss = 92,client-mss-bulk = 1400, Telegram reached through a tunnel abroadHolding a small MSS for the whole session is not an option (throughput collapses), so only the ServerHello is split. MHSanaei/mtg-multi#10 adds this as
[network] client-mss/client-mss-bulk.Relay scenario with the panel
92(session MSS left empty = mtg's 1400).Step 3 uses the existing "Route through Xray" feature: the panel adds a loopback SOCKS inbound tagged with the inbound's tag, points mtg's
[network] proxiesat it, and puts ainboundTag -> outboundTag(orbalancerTag) rule first in the routing. This PR does not change it; it only ties the two pieces together in the form and docs.Changes
internal/mtproto/options.go):network.clientMssandnetwork.clientMssBulk(pointer, so an explicit0is kept apart from "unset").clientMss0 or 48..1460;clientMssBulk0 or 536..65495 and greater thanclientMss; withclientMssBulk = 0(whole session atclientMss, set on the socket)clientMssmust be at least 88, the kernel's minimum forTCP_MAXSEG.[network]only whenclientMssis set;client-mss-bulkonly next to it (mtg ignores it alone). Unset = nothing rendered, so existing inbounds keep a byte-identical config.[network] client-mssorclient-mss-bulkfails and names the key. Either source alone still works; for raw payloads the render keeps the field value.internal/web/service/inbound_mtproto.go,internal/mtproto/manager.go): a routed inbound saved without an IP preference storesprefer-ipv4, and mtg getsprefer-ipv4for such settings from older data too. An explicit preference is kept; unrouted inbounds are unchanged. The form setsprefer-ipv4when routing is switched on with no preference and warns aboutprefer-ipv6/only-ipv6and about ad-tagged clients through the bridge; saving logs the same warnings.config/inbounds(en, ru).Limits of the relay egress (SOCKS bridge)
Checked in the mtg-multi and Xray sources:
proxy/socks: handshake, then dispatch). mtg therefore cannot fall back to the next DC address: a connection to an IPv6 DC address through an outbound without IPv6 fails for that client. mtg's default isprefer-ipv6, so a routed inbound with no IP preference now getsprefer-ipv4, and the form warns aboutprefer-ipv6/only-ipv6(fine only when the outbound has IPv6). The form note and the docs say so.client-mssis Linux only; on other systems mtg ignores it.Compatibility with mtg-multi builds
mtg-multi decodes its config with go-toml in non-strict mode, so a build without #10 ignores the new keys. I rendered relay configs from the panel (
client-mss = 92;92+client-mss-bulk = 1400;120+client-mss-bulk = 0, each together with the Xray bridgeproxies) and ranmtg-multi runon Linux:mhsanaei/mtg-multimain: starts with every config and ignores the keys (as a control, it also starts with an invalidclient-mss = 87/ bulk0).network.client-mss must be at least 88 when network.client-mss-bulk = 0. The accepted connections reportmss:108andmss:1388for120/0and92/1400(configured value minus the 12-byte timestamp option), so the setting reaches the socket.Until #10 is released the fields have no effect; the form note says that an mtg-multi build with client-mss support is needed.
Tests
internal/mtproto):0; bulk without client-mss renders nothing; together with the Xray bridge both land in one[network]table;AddInbound), either alone is accepted;prefer-ipv4, an explicit one is kept, unrouted ones are unchanged; the IPv6 and ad-tag warnings.Each new assertion was checked to fail with the corresponding code reverted.
0vs cleared bulk, range errors, the two cross-field errors on the right field, the Relay section and its fields, theprefer-ipv4default and both warnings while routing through Xray (none for a direct inbound).Run locally:
go vet ./...,go test ./...,go test -race ./internal/mtproto/,golangci-lint run(0 issues),make gen(no diff), frontend on Node 26format:check,lint,typecheck,vitestunit + components (1796 tests),build, docstypecheck,lint,format:check,test,build. The Storybook (Chromium) project was not run locally; no stories changed.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.