[GH-ISSUE #5791] [Feature]: Per-inbound traffic multiplier for shared client quota #4024

Open
opened 2026-10-31 20:36:37 +07:00 by bsakaguchi · 6 comments
Owner

Originally created by @arsham-gheibi on GitHub (Jul 4, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5791

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:

  • Inbound 1: multiplier 1.0
  • Inbound 2: multiplier 1.0
  • Inbound 3: multiplier 1.0
  • Iran tunnel inbound: multiplier 2.0

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:

  • 5 GB through a normal inbound should deduct 5 GB from the quota.
  • 5 GB through the tunnel inbound with multiplier 2.0 should deduct 10 GB from the quota.

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

  1. Dividing the client's quota manually.

This does not work because the same client can dynamically use both normal and tunnel inbounds.

  1. Creating a separate client for the tunnel inbound

This creates separate quotas and makes account and subscription management difficult.

  1. Using an external script

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:

  • 20 GB used through normal inbounds should count as 20 GB.
  • 20 GB used through the tunnel inbound with multiplier 2.0 should count as 40 GB.
  • The total quota usage should therefore be 60 GB.

It would be useful to display both values separately:

  • Actual traffic: 40 GB
  • Quota usage: 60 GB

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?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and reviewed issue #4631 before submitting this more detailed use case.
  • This feature request is written in English.
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: - Inbound 1: multiplier 1.0 - Inbound 2: multiplier 1.0 - Inbound 3: multiplier 1.0 - Iran tunnel inbound: multiplier 2.0 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: - 5 GB through a normal inbound should deduct 5 GB from the quota. - 5 GB through the tunnel inbound with multiplier 2.0 should deduct 10 GB from the quota. 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 1. Dividing the client's quota manually. This does not work because the same client can dynamically use both normal and tunnel inbounds. 2. Creating a separate client for the tunnel inbound This creates separate quotas and makes account and subscription management difficult. 3. Using an external script 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: - 20 GB used through normal inbounds should count as 20 GB. - 20 GB used through the tunnel inbound with multiplier 2.0 should count as 40 GB. - The total quota usage should therefore be 60 GB. It would be useful to display both values separately: - Actual traffic: 40 GB - Quota usage: 60 GB 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? - [x] I'd like to implement this feature myself and open a PR. - [x] I can help test once a PR is open. ### Before submitting - [x] I searched existing issues and reviewed issue #4631 before submitting this more detailed use case. - [x] This feature request is written in English.
Author
Owner

@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.

<!-- gh-comment-id:4883479237 --> @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.
Author
Owner

@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):

  • A client's traffic/quota is tracked in one row per email, xray.ClientTraffic (internal/xray/client_traffic.go), with Email under a unique index — so a client attached to 8 inbounds (via the client_inbounds join table, internal/database/model/model.go) really does share a single Up/Down/Total counter, matching your description.
  • disableInvalidClients (internal/web/service/inbound_disable.go) checks up + down >= total on that row and, once depleted, disables the client on every inbound it's attached to (via a clients/client_inbounds/inbounds join). The "shared quota, disable everywhere" behavior you want already exists — it's just unweighted today.
  • Separately, 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.go documents 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:

  • If the tunnel inbound and the normal inbounds are never used concurrently by the same client within a given 5s window, a multiplier is unambiguous: whichever single inbound moved bytes that poll, multiply by its factor before adding to the shared ClientTraffic row.
  • If the same client is simultaneously active on two differently-weighted inbounds within the same poll window, xray-core hands back one already-merged delta for that email with no way to tell which inbound contributed how much — an exact weighted split isn't achievable with xray-core's current stats granularity. A PR would need an explicit policy for that case (e.g. apply the highest active multiplier that poll, or document it as an accepted approximation).

Schema-wise, adding a field is not a blocker: a new column on Inbound (or a per-attachment weight on client_inbounds) migrates additively via GORM AutoMigrate (internal/database/db.go), the same way fields like SubSortIndex were added — no hand-written SQL needed. The enforcement math would touch addClientTraffic (internal/web/service/inbound_traffic.go) and depletedClientsCond/disableInvalidClients (internal/web/service/inbound_disable.go), plus ClientGlobalTraffic/NodeClientTraffic if multi-node quota sync is in scope. The frontend change (a numeric field alongside total in frontend/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.

<!-- gh-comment-id:4883488015 --> @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): - A client's traffic/quota is tracked in one row per email, `xray.ClientTraffic` (`internal/xray/client_traffic.go`), with `Email` under a unique index — so a client attached to 8 inbounds (via the `client_inbounds` join table, `internal/database/model/model.go`) really does share a single `Up`/`Down`/`Total` counter, matching your description. - `disableInvalidClients` (`internal/web/service/inbound_disable.go`) checks `up + down >= total` on that row and, once depleted, disables the client on every inbound it's attached to (via a `clients`/`client_inbounds`/`inbounds` join). The "shared quota, disable everywhere" behavior you want already exists — it's just unweighted today. - Separately, `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.go` documents 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: - If the tunnel inbound and the normal inbounds are never used concurrently by the same client within a given 5s window, a multiplier is unambiguous: whichever single inbound moved bytes that poll, multiply by its factor before adding to the shared `ClientTraffic` row. - If the same client is simultaneously active on two differently-weighted inbounds within the same poll window, xray-core hands back one already-merged delta for that email with no way to tell which inbound contributed how much — an exact weighted split isn't achievable with xray-core's current stats granularity. A PR would need an explicit policy for that case (e.g. apply the highest active multiplier that poll, or document it as an accepted approximation). Schema-wise, adding a field is not a blocker: a new column on `Inbound` (or a per-attachment weight on `client_inbounds`) migrates additively via GORM `AutoMigrate` (`internal/database/db.go`), the same way fields like `SubSortIndex` were added — no hand-written SQL needed. The enforcement math would touch `addClientTraffic` (`internal/web/service/inbound_traffic.go`) and `depletedClientsCond`/`disableInvalidClients` (`internal/web/service/inbound_disable.go`), plus `ClientGlobalTraffic`/`NodeClientTraffic` if multi-node quota sync is in scope. The frontend change (a numeric field alongside `total` in `frontend/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.*
Author
Owner

@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:

  • user@example.com__inbound_1
  • user@example.com__inbound_2
  • user@example.com__iran_tunnel

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:

  • The logical client identity used by 3x-ui and subscriptions
  • The internal Xray stats identity used per inbound

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?

<!-- gh-comment-id:4885669309 --> @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: - user@example.com__inbound_1 - user@example.com__inbound_2 - user@example.com__iran_tunnel 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: * The logical client identity used by 3x-ui and subscriptions * The internal Xray stats identity used per inbound 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?
Author
Owner

@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)

<!-- gh-comment-id:5815212991 --> @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)
Author
Owner

@Albert-the-jit commented on GitHub (Oct 10, 2026):

Pls add this. 🙏

<!-- gh-comment-id:6100839893 --> @Albert-the-jit commented on GitHub (Oct 10, 2026): Pls add this. 🙏
Author
Owner

@APT-ZERO commented on GitHub (Oct 10, 2026):

9. Pls add this. 🙏

This is already available in Nexora (paid panel made by MHSanaei and Alireza0) and will not be added to the main 3x-ui repo

<!-- gh-comment-id:6101764662 --> @APT-ZERO commented on GitHub (Oct 10, 2026): > 9\. Pls add this. 🙏 This is already available in Nexora (paid panel made by MHSanaei and Alireza0) and will not be added to the main 3x-ui repo
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#4024
No description provided.