[GH-ISSUE #5660] [Feature]: Per-Node Traffic Limit for Subscriptions #3944

Open
opened 2026-10-31 20:36:04 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @hiradjaguar on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5660

It would be very useful to have the ability to define traffic limits separately for each node within a single subscription.

Describe the solution you'd like

For example:

Node 1 (Cloudflare): Unlimited traffic
Node 2 (Tunnel): 10 GB traffic

Currently, the traffic limit is applied to the entire subscription. It would be great if each node could have its own independent traffic quota.

This would allow users to use Cloudflare nodes without limitation while restricting bandwidth usage on more expensive or limited tunnel nodes.

When the traffic limit of one node is reached, only that specific node should become unavailable, while the other nodes in the subscription continue to work normally.

Alternatives you've considered

No response

Concrete use case

No response

Mockups, screenshots, or examples

No response

Which parts of the panel would this affect?

No response

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 this feature has not been requested.
  • This feature request is written in English.
Originally created by @hiradjaguar on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5660 ### Is your feature request related to a problem? It would be very useful to have the ability to define traffic limits separately for each node within a single subscription. ### Describe the solution you'd like For example: **Node 1 (Cloudflare):** Unlimited traffic **Node 2 (Tunnel):** 10 GB traffic Currently, the traffic limit is applied to the entire subscription. It would be great if each node could have its own independent traffic quota. This would allow users to use Cloudflare nodes without limitation while restricting bandwidth usage on more expensive or limited tunnel nodes. When the traffic limit of one node is reached, only that specific node should become unavailable, while the other nodes in the subscription continue to work normally. ### Alternatives you've considered _No response_ ### Concrete use case _No response_ ### Mockups, screenshots, or examples _No response_ ### Which parts of the panel would this affect? _No response_ ### 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 - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
Author
Owner

@github-actions[bot] commented on GitHub (Jun 29, 2026):

This is a valid feature request. The current codebase does not support per-node traffic limits; below is a summary of how traffic limits work today and what this proposal would require to implement.

Current architecture

Traffic limits are applied at two scopes:

  • Client scope (global): Each client has a single Total quota (stored in ClientTraffic.Total). In multi-node setups, the master panel aggregates per-node usage into client_global_traffics and pushes that aggregate to each node every ~30 seconds (internal/web/job/node_traffic_sync_job.go → maybePushGlobals). Nodes then enforce the limit against the combined global total, not just local usage.
  • Inbound scope: Each inbound has its own Total field (internal/database/model/model.go). When the inbound's cumulative traffic reaches that ceiling, the inbound is disabled as a whole.

There is no per-node traffic limit concept anywhere in the schema or enforcement logic. The node_client_traffics table (internal/database/model/node_client_traffic.go) stores per-node accounting baselines for delta calculation, but carries no quota field.

What implementing this would require

This feature does not map cleanly onto the current data model. A rough set of changes needed:

  1. Schema addition: A new table (or an extension of node_client_traffics) that stores a per-(node, client) quota, plus a migration in internal/database/db.go.
  2. Enforcement logic: internal/web/service/inbound_disable.go contains the depletion query (depletedClientsCond). It would need to evaluate per-node quotas against per-node usage, then disable a client only on the relevant node while leaving it active on others. The current design disables a client globally (across all inbounds on all nodes for that email).
  3. Global sync changes: internal/web/job/node_traffic_sync_job.go and internal/web/runtime/remote.go push/pull aggregate stats; they would need to carry per-node quota assignments to each node.
  4. Subscription exposure: The Subscription-Userinfo header (internal/sub/controller.go) reports a single global total value. Per-node limits would require a different representation or a node-specific subscription URL.
  5. UI and API: New fields in the inbound/client editor and in the OpenAPI spec.

This is a non-trivial architectural change, not an additive feature, because it requires disaggregating what is currently a global enforcement model.

Related prior work

  • #4519 (closed): per-node traffic statistics (display only) — distinct from this request.
  • #5490 (closed): traffic aggregation bugs in the existing multi-node model — confirms the complexity of this area.

A PR implementing this would be welcome; the PR welcomed label can be added if someone volunteers to take it on.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:4833661065 --> @github-actions[bot] commented on GitHub (Jun 29, 2026): This is a valid feature request. The current codebase does not support per-node traffic limits; below is a summary of how traffic limits work today and what this proposal would require to implement. **Current architecture** Traffic limits are applied at two scopes: - **Client scope (global):** Each client has a single `Total` quota (stored in `ClientTraffic.Total`). In multi-node setups, the master panel aggregates per-node usage into `client_global_traffics` and pushes that aggregate to each node every ~30 seconds (`internal/web/job/node_traffic_sync_job.go` → `maybePushGlobals`). Nodes then enforce the limit against the *combined* global total, not just local usage. - **Inbound scope:** Each inbound has its own `Total` field (`internal/database/model/model.go`). When the inbound's cumulative traffic reaches that ceiling, the inbound is disabled as a whole. There is no per-node traffic limit concept anywhere in the schema or enforcement logic. The `node_client_traffics` table (`internal/database/model/node_client_traffic.go`) stores per-node accounting baselines for delta calculation, but carries no quota field. **What implementing this would require** This feature does not map cleanly onto the current data model. A rough set of changes needed: 1. **Schema addition:** A new table (or an extension of `node_client_traffics`) that stores a per-(node, client) quota, plus a migration in `internal/database/db.go`. 2. **Enforcement logic:** `internal/web/service/inbound_disable.go` contains the depletion query (`depletedClientsCond`). It would need to evaluate per-node quotas against per-node usage, then disable a client *only on the relevant node* while leaving it active on others. The current design disables a client globally (across all inbounds on all nodes for that email). 3. **Global sync changes:** `internal/web/job/node_traffic_sync_job.go` and `internal/web/runtime/remote.go` push/pull aggregate stats; they would need to carry per-node quota assignments to each node. 4. **Subscription exposure:** The `Subscription-Userinfo` header (`internal/sub/controller.go`) reports a single global `total` value. Per-node limits would require a different representation or a node-specific subscription URL. 5. **UI and API:** New fields in the inbound/client editor and in the OpenAPI spec. This is a non-trivial architectural change, not an additive feature, because it requires disaggregating what is currently a global enforcement model. **Related prior work** - #4519 (closed): per-node traffic *statistics* (display only) — distinct from this request. - #5490 (closed): traffic aggregation bugs in the existing multi-node model — confirms the complexity of this area. A PR implementing this would be welcome; the `PR welcomed` label can be added if someone volunteers to take it on. *This reply was generated automatically; a maintainer may follow up.*
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#3944
No description provided.