[PR #6164] [MERGED] feat(inbounds): improve multi-node online attribution #6126

Closed
opened 2026-11-02 04:06:33 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6164
Author: @isultanov99
Created: 7/30/2026
Status: ✅ Merged
Merged: 8/15/2026
Merged by: @MHSanaei

Base: main ← Head: inbound-online-attribution


📝 Commits (1)

  • 5f1f09b feat(inbounds): improve multi-node online attribution

📊 Changes

5 files changed (+399 additions, -21 deletions)

View changed files

📝 internal/web/runtime/remote.go (+14 -2)
📝 internal/web/service/inbound_node.go (+99 -14)
📝 internal/web/service/node_origin_guid_test.go (+181 -0)
📝 internal/xray/online_test.go (+39 -0)
📝 internal/xray/process.go (+66 -5)

📄 Description

Summary

This PR improves online-client attribution on the inbounds page for multi-node setups.

Central panels already consume node-scoped online users through onlinesByGuid, but remote node sync did not carry the matching activeInbounds signal. As a result, the frontend could know that a client was online on a node, but not which inbounds on that node had recent traffic, so multi-inbound clients could appear online across too many inbounds.

The change makes node traffic snapshots include the existing /panel/api/clients/activeInbounds endpoint and keeps those active inbound tags in the same GUID-keyed in-memory tree model used for online users.

What Changed

  • Fetch remote activeInbounds during node traffic sync, best-effort and backward-compatible with older nodes.
  • Store remote active-inbound subtrees in the running Xray process state.
  • Merge local and remote active-inbound maps in GetActiveInboundsByGuid.
  • Remap cloned/shared node GUIDs for active-inbound trees the same way online trees are remapped.
  • Normalize node-local active inbound tags to the central panel's stored tags, including n<nodeID>- prefixed tags.
  • Clear stale active-inbound state when a node's online subtree is cleared.

Notes

This does not try to infer an exact client -> inbound pair because Xray exposes user traffic and inbound traffic as separate stats. The frontend can now gate online clients to active inbounds on the correct node, but when several inbounds on the same node are active in the same grace window, attribution remains best-effort.

Older nodes that do not expose activeInbounds keep the previous fallback behavior: the master still consumes their online users and simply skips active-inbound gating for that node.

Validation

go test ./internal/xray ./internal/web/runtime ./internal/web/service
go test ./internal/web/job
git diff --check

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6164 **Author:** [@isultanov99](https://github.com/isultanov99) **Created:** 7/30/2026 **Status:** ✅ Merged **Merged:** 8/15/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `inbound-online-attribution` --- ### 📝 Commits (1) - [`5f1f09b`](https://github.com/MHSanaei/3x-ui/commit/5f1f09b5228702de8261e150afc5522207f17bb0) feat(inbounds): improve multi-node online attribution ### 📊 Changes **5 files changed** (+399 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/runtime/remote.go` (+14 -2) 📝 `internal/web/service/inbound_node.go` (+99 -14) 📝 `internal/web/service/node_origin_guid_test.go` (+181 -0) 📝 `internal/xray/online_test.go` (+39 -0) 📝 `internal/xray/process.go` (+66 -5) </details> ### 📄 Description ## Summary This PR improves online-client attribution on the inbounds page for multi-node setups. Central panels already consume node-scoped online users through `onlinesByGuid`, but remote node sync did not carry the matching `activeInbounds` signal. As a result, the frontend could know that a client was online on a node, but not which inbounds on that node had recent traffic, so multi-inbound clients could appear online across too many inbounds. The change makes node traffic snapshots include the existing `/panel/api/clients/activeInbounds` endpoint and keeps those active inbound tags in the same GUID-keyed in-memory tree model used for online users. ## What Changed - Fetch remote `activeInbounds` during node traffic sync, best-effort and backward-compatible with older nodes. - Store remote active-inbound subtrees in the running Xray process state. - Merge local and remote active-inbound maps in `GetActiveInboundsByGuid`. - Remap cloned/shared node GUIDs for active-inbound trees the same way online trees are remapped. - Normalize node-local active inbound tags to the central panel's stored tags, including `n<nodeID>-` prefixed tags. - Clear stale active-inbound state when a node's online subtree is cleared. ## Notes This does not try to infer an exact `client -> inbound` pair because Xray exposes user traffic and inbound traffic as separate stats. The frontend can now gate online clients to active inbounds on the correct node, but when several inbounds on the same node are active in the same grace window, attribution remains best-effort. Older nodes that do not expose `activeInbounds` keep the previous fallback behavior: the master still consumes their online users and simply skips active-inbound gating for that node. ## Validation ```bash go test ./internal/xray ./internal/web/runtime ./internal/web/service go test ./internal/web/job git diff --check ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:06:33 +07:00
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#6126
No description provided.