mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6515] [MERGED] fix(xray): place the freedom domain strategy where the core reads it #6321
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#6321
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/6515
Author: @BlindMaster24
Created: 9/14/2026
Status: ✅ Merged
Merged: 9/14/2026
Merged by: @MHSanaei
Base:
main← Head:fix/freedom-domain-strategy-placement📝 Commits (3)
5e2dc65fix(xray): place the freedom domain strategy where the core reads ita2e19d9test(database): seed the template row the seeder test needs63eee52fix(xray): keep one strategy control per outbound, seed the row in tests📊 Changes
14 files changed (+897 additions, -61 deletions)
View changed files
📝
frontend/src/lib/xray/outbound-form-adapter.ts(+50 -10)📝
frontend/src/pages/xray/basics/BasicsTab.tsx(+3 -24)📝
frontend/src/pages/xray/basics/constants.ts(+3 -1)📝
frontend/src/pages/xray/basics/helpers.ts(+42 -0)📝
frontend/src/pages/xray/outbounds/OutboundFormModal.tsx(+15 -8)📝
frontend/src/pages/xray/outbounds/transport/sockopt.tsx(+24 -12)➕
frontend/src/test/basics-freedom-strategy.test.ts(+98 -0)➕
frontend/src/test/freedom-strategy-placement.test.ts(+154 -0)📝
frontend/src/test/outbound-form-adapter.test.ts(+8 -4)📝
frontend/src/test/outbound-form-modal.test.tsx(+48 -0)📝
internal/database/db.go(+120 -1)➕
internal/database/freedom_domain_strategy_migration_test.go(+295 -0)📝
internal/web/service/config.json(+0 -1)➕
internal/web/service/default_template_freedom_test.go(+37 -0)📄 Description
Summary
Freedom's domain strategy is now written where xray-core actually reads it —
streamSettings.sockopt.domainStrategy— instead of the two legacy keys thepanel used (
settings.domainStrategyand the outbound-roottargetStrategy),and a one-shot seeder moves the keys for configs already stored in the database.
Why
Refs #6482. The pinned core migrates both legacy placements and warns on every
config load (
infra/conf/xray.go:345-368):and
proxy/freedom/freedom.go:54-58is what consumes it at runtime(
h.resolveStrategy = streamSettings.SocketSettings.DomainStrategy) — thelegacy keys only ever feed that migration, they never resolve anything
themselves.
The panel emitted both of them, in four places:
settings.domainStrategyon thedirectoutbound.(through
freedomToWire), and the shared Target Strategy field above itwrote the outbound-root one — two knobs the core folds into a single value,
with the root key silently winning.
settings.domainStrategy: "UseIPv4"on theIPv4outbound that service/domain rules bind to (ipv4Settings).internal/web/service/config.json) carriedsettings.domainStrategy: "AsIs".User story: on a fresh install I pick
UseIPv4in the Freedom Protocol Strategyselect — or I just tick a service rule, which creates the
IPv4outbound for me.From then on, every xray start writes the deprecation warning into the panel log
and keeps writing it after every upgrade, with nothing in the UI explaining why
and no way to silence it short of hand-editing the config JSON.
What changed
freedomDomainStrategyFromWirereads the strategy in the loader's ownprecedence (root
targetStrategy→settings.targetStrategy→settings.domainStrategy→ existing sockopt), so the card keeps showing thevalue the core would run with rather than one it is about to discard.
formValuesToWirePayloadhoists the chosen strategy intostreamSettings.sockopt.domainStrategyand deletes both legacy keys, so asingle save cleans up a config that older panels wrote.
AsIs(and an emptyfield) removes the key instead of emitting an inert value.
core migrates that key into the very same sockopt value the card writes, so
offering both would be two controls for one setting.
ipv4Settingsandthe shipped default template no longer carry them.
FreedomDomainStrategyFix(a seeder in theOutboundRemovedKeysFixfamily)rewrites an existing
xrayTemplateConfigonce on upgrade: it moves the valueto sockopt using the same precedence the loader uses, and drops the legacy
keys. A value the core refuses to load is dropped rather than migrated, since
sockopt.domainStrategyrejects it too.Type of change
Areas affected
How was this tested?
Frontend,
npx vitest runon the four touched files (55 tests, all passing):freedom-strategy-placement.test.ts(new, 11): the round trip that matters —the card's strategy lands in sockopt, neither legacy key survives, a legacy
root key is migrated, a legacy
AsIsalias does not mask a real sockopt value,a cleared field drops the key, an existing sockopt spelling is normalized, and
the root
targetStrategystill rides at the root for non-freedom protocols.basics-freedom-strategy.test.ts(new, 6): the Basics select writes sockopt,clears both legacy keys, keeps sibling sockopt keys, and reads back the value
the core would resolve.
outbound-form-adapter.test.ts+outbound-form-modal.test.tsx(updated): theexisting targetStrategy pins now expect the sockopt placement, and the modal
test switches protocol to freedom and asserts the root field is gone.
Red before green: reverting the hoist in
formValuesToWirePayloadmakes 6 ofthe 11 placement tests fail with the pre-fix payload
(
settings.domainStrategy), and re-addingsettings.domainStrategyto theshipped template fails the new Go template test with
freedom outbound direct carries the deprecated settings.domainStrategy.Backend:
internal/database/freedom_domain_strategy_migration_test.gohas atable over the rewrite (root key wins over the settings key, settings
targetStrategywins overdomainStrategy,AsIsleaves an existing sockoptvalue alone, unknown spellings are dropped, other protocols untouched), plus
TestRewriteFreedomDomainStrategySatisfiesCore, which drives the real vendoredcore: it validates the legacy outbound, asserts the core's own warning was
emitted (captured through
log.RegisterHandler), rewrites, and asserts therewritten outbound is accepted and no longer warns. That test is red without
the rewrite.
Local caveat worth stating: this machine has no C compiler, so I verified with
CGO_ENABLED=0 go vet ./...plus a local-overlaybuild that stubs the onecgo-only call in
db.go(sqlite3.SQLiteConn.Backup); no PR file issubstituted. Under that build
go test ./internal/database/ -run FreedomDomainStrategyis green and the seeder test skips itself explicitly(
sqlite needs cgo), so the DB-backed path — the seeder runs against athrowaway database and asserts the stored template changed, then re-seeds a
legacy template and runs the real seeder list to prove the recorded seeder does
not rewrite it again — is exercised by CI, where gcc is present.
npm run typecheck,npm run lint,npm run format:checkandnpx vite buildare clean.(The two unrelated failures I see locally are environment-only: the
input-number-guardtestexecFileSyncs./node_modules/.bin/oxlint, which isnot directly executable on Windows, and
language-scopetrips the 5s timeout.)Screenshots / recordings
N/A — no new UI, one field is hidden for a single protocol; the modal test
covers it.
Breaking changes
None for users. Existing
xrayTemplateConfigvalues are migrated once onupgrade by the seeder, and the strategy keeps its value — it only moves to the
placement the core itself migrates it to, so behavior is unchanged on every core
that emits the warning in the first place.
Checklist
go build ./...and the test suite pass locally. (See the cgo caveat above: verified cgo-free with an overlay that only stubs the cgo-only driver call; CI runs the full build and the DB-backed test.)npm run lint,npm run typecheck, andnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.