mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5791] [Feature]: Per-inbound traffic multiplier for shared client quota #4024
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#4024
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?
Originally created by @arsham-gheibi on GitHub (Jul 4, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5791
Is your feature request related to a problem?
Yes.
I provide each client with multiple inbounds under the same email/client account. For example, one user may have access to 8 different inbounds, while all of them share the same total traffic quota.
However, one of these inbounds uses an additional Iran tunnel server and has approximately twice the infrastructure and bandwidth cost.
Currently, traffic generated through every inbound is counted equally. There is no way to make traffic from the tunnel inbound consume more of the user's shared quota.
Describe the solution you'd like
Please add an optional traffic multiplier to each inbound.
Example:
The user's billable traffic should be calculated as:
Billable traffic =
(inbound 1 traffic × 1.0) +
(inbound 2 traffic × 1.0) +
...
(Iran tunnel inbound traffic × 2.0)
For example:
The multiplier should only affect quota accounting. It should not modify the actual Xray traffic statistics.
The default multiplier should be 1.0, so existing installations and inbounds continue to work exactly as before.
Alternatives you've considered
This does not work because the same client can dynamically use both normal and tunnel inbounds.
This creates separate quotas and makes account and subscription management difficult.
This requires polling traffic statistics, storing previous values, calculating deltas, and disabling the client externally. Native panel support would be safer and more reliable.
Concrete use case
I give each user 8 inbounds with one shared traffic quota.
Seven inbounds connect normally and should use a 1.0 multiplier.
One inbound passes through an Iran tunnel server. This route consumes bandwidth and resources on both the Iran server and the destination server, so its traffic needs to be counted with a 2.0 multiplier.
Creating separate clients or separate quotas is not practical because all 8 configurations belong to the same user and must share one total quota.
Expected behavior
For a client with a 100 GB total quota:
It would be useful to display both values separately:
When the weighted quota usage reaches 100 GB, the client should be disabled across all associated inbounds.
Mockups, screenshots, or examples
No response
Which parts of the panel would this affect?
Frontend (UI / panel pages)
Are you willing to help?
Before submitting
@arsham-gheibi commented on GitHub (Jul 4, 2026):
I am aware of issue #4631.
However, that issue did not provide a detailed concrete use case or explain the expected behavior for a shared client quota across multiple inbounds.
My request specifically concerns a client who has access to 8 inbounds under one shared quota, where only one inbound uses an additional tunnel server and must consume the shared quota with a 2.0 multiplier.
The purpose of this issue is to clarify the expected accounting behavior and provide a practical implementation use case.
@github-actions[bot] commented on GitHub (Jul 4, 2026):
Thanks for the detailed spec. The current codebase already implements the "shared quota across inbounds" mechanism you describe, and there is no multiplier/coefficient concept anywhere in the traffic-accounting code today (confirmed by grep across
internal/).Related prior requests: this same idea has been proposed and closed as not planned twice before: #4631 ("Traffic coefficient for each inbound") and the node-level variant #5308. A related usage question, #5654, was closed inviting exactly this kind of detailed write-up (protocol/inbound + expected-behavior example). None of those threads are currently open, so this isn't treated as a duplicate, but it's worth linking for context since a maintainer will likely want to weigh this against that history.
How quota sharing works today (confirmed in source):
xray.ClientTraffic(internal/xray/client_traffic.go), withEmailunder a unique index — so a client attached to 8 inbounds (via theclient_inboundsjoin table,internal/database/model/model.go) really does share a singleUp/Down/Totalcounter, matching your description.disableInvalidClients(internal/web/service/inbound_disable.go) checksup + down >= totalon that row and, once depleted, disables the client on every inbound it's attached to (via aclients/client_inbounds/inboundsjoin). The "shared quota, disable everywhere" behavior you want already exists — it's just unweighted today.Inbound.Up/Down/Total(internal/database/model/model.go) already track a fully per-inbound cap, unrelated to any single client's shared quota.Open design question a PR would need to resolve: Xray-core's own stats API reports client traffic under the stat name
user>>>{email}>>>traffic>>>{uplink|downlink}(internal/xray/api.go, regex at line 47) — there is no inbound tag in that stat name. Xray-core aggregates a client's bytes across every inbound it's attached to before 3x-ui ever reads the counter.internal/web/job/xray_traffic_job.godocuments this same limitation for a related problem (attributing "online" status per inbound, see issue #4859), and only works around it with a same-poll-window heuristic, not exact byte splitting.Traffic is polled every 5 seconds (
cadenceXrayTraffic = "@every 5s",internal/web/web.go), so in practice:ClientTrafficrow.Schema-wise, adding a field is not a blocker: a new column on
Inbound(or a per-attachment weight onclient_inbounds) migrates additively via GORMAutoMigrate(internal/database/db.go), the same way fields likeSubSortIndexwere added — no hand-written SQL needed. The enforcement math would touchaddClientTraffic(internal/web/service/inbound_traffic.go) anddepletedClientsCond/disableInvalidClients(internal/web/service/inbound_disable.go), plusClientGlobalTraffic/NodeClientTrafficif multi-node quota sync is in scope. The frontend change (a numeric field alongsidetotalinfrontend/src/pages/inbounds/form/InboundFormModal.tsx) is straightforward and has direct precedent.Since you've volunteered to implement this, it would help to sketch your intended handling of the concurrent-multi-inbound case in this thread before opening a PR — that's the part most likely to need discussion.
This reply was generated automatically; a maintainer may follow up.
@arsham-gheibi commented on GitHub (Jul 5, 2026):
I agree that applying the highest active multiplier within a polling window would only be an approximation and could significantly overcount traffic when the same user is active on multiple inbounds at the same time.
A more accurate approach may be to avoid using the exact same Xray stats identity for the client on every inbound.
For example, one logical 3x-ui client could internally have a different Xray email/stat identity for each inbound:
These internal identities would still belong to one logical client account with one shared quota in 3x-ui.
Xray would then report traffic separately for each inbound-specific identity, allowing 3x-ui to calculate the weighted quota usage accurately:
weighted usage =
(inbound 1 traffic × 1.0) +
(inbound 2 traffic × 1.0) +
(Iran tunnel traffic × 2.0)
When the weighted shared quota is exhausted, 3x-ui would disable all inbound-specific identities associated with that logical client.
This would avoid the concurrent multi-inbound ambiguity because the traffic would no longer be merged under one Xray email before being read by 3x-ui.
I understand that this is a larger architectural change than simply adding a multiplier field. It would likely require separating:
It would also need to be handled correctly for traffic reset, client disabling, subscription generation, API responses, backup/restore, and multi-node synchronization.
Would this per-inbound internal stats identity approach be considered acceptable for a PR, or is preserving the same Xray email across every inbound a project requirement?
@APT-ZERO commented on GitHub (Sep 24, 2026):
+1
I have the same issue
It's very important to be able to set a multiplier for each Inbound
If an inbound is cheaper than your main subscription configs, you must be able to set a multiplier like 0.5, or even 0.0 to make it free (like an XDNS inbound)
@Albert-the-jit commented on GitHub (Oct 10, 2026):
Pls add this. 🙏
@APT-ZERO commented on GitHub (Oct 10, 2026):
This is already available in Nexora (paid panel made by MHSanaei and Alireza0) and will not be added to the main 3x-ui repo