[PR #5005] [MERGED] feat(nodes): multi-hop node attribution for chained sub-nodes (#4983) #5753

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5005
Author: @MHSanaei
Created: 6/6/2026
Status: ✅ Merged
Merged: 6/6/2026
Merged by: @MHSanaei

Base: main ← Head: feat/multi-hop-node-attribution


📝 Commits (6)

  • 3a3f4d7 feat(nodes): add stable panel GUID identity (multi-hop phase 0)
  • 3d7fd8b feat(nodes): attribute inbounds to their origin node by GUID (multi-hop phase 1)
  • 66bb2df feat(nodes): key online status by node GUID end-to-end (multi-hop phase 2)
  • e07dd9d feat(nodes): surface transitive sub-nodes on the master (multi-hop phase 3a)
  • 8afd571 feat(nodes): render transitive sub-nodes nested + read-only on the Nodes page (multi-hop phase 3b)
  • cb90fed i18n(nodes): translate subNode/subNodeTip across all locales

📊 Changes

37 files changed (+1002 additions, -222 deletions)

View changed files

📝 database/model/model.go (+41 -0)
📝 frontend/public/openapi.json (+49 -7)
📝 frontend/src/api/queryKeys.ts (+1 -1)
📝 frontend/src/models/dbinbound.ts (+3 -0)
📝 frontend/src/pages/api-docs/endpoints.ts (+11 -5)
📝 frontend/src/pages/inbounds/useInbounds.ts (+40 -34)
📝 frontend/src/pages/nodes/NodeList.tsx (+72 -15)
📝 frontend/src/schemas/node.ts (+5 -0)
📝 web/controller/client.go (+4 -4)
📝 web/controller/node.go (+1 -1)
📝 web/controller/server.go (+9 -0)
📝 web/job/node_heartbeat_job.go (+11 -1)
📝 web/job/node_traffic_sync_job.go (+2 -2)
📝 web/job/xray_traffic_job.go (+2 -2)
📝 web/runtime/remote.go (+39 -7)
📝 web/service/inbound.go (+123 -9)
📝 web/service/node.go (+28 -15)
➕ web/service/node_origin_guid_test.go (+71 -0)
➕ web/service/node_tree.go (+226 -0)
➕ web/service/node_tree_test.go (+81 -0)

...and 17 more files

📄 Description

Summary

Adds end-to-end attribution and read-only surfacing of chained sub-nodes (Node1 → Node2 → Node3). Clients and inbounds hosted several hops down a node chain are now attributed to the node that physically hosts them, instead of the intermediate node they sync through, and a node's downstream sub-nodes are shown read-only on the Nodes page.

Why

Closes #4983 (dup #4984).

Per-node online status was keyed by each panel's local autoincrement node id, which is meaningless one hop away. So in a chained topology the master attributed clients running on Node3 to Node2 (the node it syncs through), and Node3 was not visible on the master at all. This change introduces a stable, panel-local panelGuid as the cross-hop identity so attribution is correct at any depth.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

What changed (by phase)

  • Phase 0 — panelGuid (settings, get-or-create like GetSecret), returned in panel/api/server/status; the master learns each node's GUID via heartbeat into a new Node.Guid column. Guarded so an old-build node or a failed probe never clears a known GUID.
  • Phase 1 — Inbound.OriginNodeGuid: the GUID of the panel that physically hosts an inbound. Empty = local (filled with the panel's own GUID at serve time); set during SetRemoteTraffic, preserving a value the node forwarded from its own sub-node so a transitive inbound stays attributed to the deepest node.
  • Phase 2 — online status keyed by GUID end-to-end, replacing node-id keying. New POST /panel/api/clients/onlinesByGuid (was /onlinesByNode); FetchTrafficSnapshot falls back to the flat /onlines for old-build nodes; WS onlineByGuid field; the inbounds-page rollup scopes by originNodeGuid.
  • Phase 3a — GET /panel/api/server/descendants (node API token) publishes a panel's direct nodes; the heartbeat caches them and GetNodeTree surfaces transitive sub-nodes as read-only model.Node projections with per-GUID recounts.
  • Phase 3b — the Nodes page renders transitive sub-nodes indented and read-only under their parent (no toggle / probe / edit / delete / select / history), with a Sub-node tag. Locale keys translated across all 13 languages.

How was this tested?

  • Unit tests (all green): xray/online_test.go (GUID-tree merge/scoping), web/service/node_tree_test.go (transitive surfacing), web/service/node_origin_guid_test.go (origin attribution). Full go build ./... + go test pass; frontend tsc / lint / vitest (408) pass.
  • Docker E2E, real Node1 → Node2 → Node3 chain: created a VMess inbound on Node2 assigned to Node3, drove real traffic through Node3's xray, and confirmed node3user was attributed to Node3's GUID at every hop (Node3 → Node2 → master /clients/onlinesByGuid); the master listed Node3 as a transitive node under Node2 (transitive:true, node3.onlineCount=1, node2.onlineCount=0, node3.inboundCount=1), and the inbound carried originNodeGuid = <node3 guid>.
  • Verified identically on a Postgres-backed master as well as SQLite.

UI note: on the Nodes page, downstream sub-nodes now appear as indented, read-only rows directly under the node they are reached through, tagged Sub-node with a tooltip naming the parent.

Breaking changes

None. Two new nullable columns (nodes.guid, inbounds.origin_node_guid) are added via AutoMigrate. Old-build nodes that don't report a GUID degrade gracefully to the previous flat behavior via a synthetic node:<id> key, so a mixed-version fleet keeps working.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 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/5005 **Author:** [@MHSanaei](https://github.com/MHSanaei) **Created:** 6/6/2026 **Status:** ✅ Merged **Merged:** 6/6/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `feat/multi-hop-node-attribution` --- ### 📝 Commits (6) - [`3a3f4d7`](https://github.com/MHSanaei/3x-ui/commit/3a3f4d7f5768148d42173b7129678322bf68b46e) feat(nodes): add stable panel GUID identity (multi-hop phase 0) - [`3d7fd8b`](https://github.com/MHSanaei/3x-ui/commit/3d7fd8b0fd93593af74f6625140f52820649a1f3) feat(nodes): attribute inbounds to their origin node by GUID (multi-hop phase 1) - [`66bb2df`](https://github.com/MHSanaei/3x-ui/commit/66bb2df959223504e50e89bfbebb30813f0aa853) feat(nodes): key online status by node GUID end-to-end (multi-hop phase 2) - [`e07dd9d`](https://github.com/MHSanaei/3x-ui/commit/e07dd9d3b136c525841c8b3f985787f6aa2a9aee) feat(nodes): surface transitive sub-nodes on the master (multi-hop phase 3a) - [`8afd571`](https://github.com/MHSanaei/3x-ui/commit/8afd5718550c6b884ce80b5c8e4ff6cbb19aa4e3) feat(nodes): render transitive sub-nodes nested + read-only on the Nodes page (multi-hop phase 3b) - [`cb90fed`](https://github.com/MHSanaei/3x-ui/commit/cb90fed68175c1baa6cf9344a46f9dc2263dac57) i18n(nodes): translate subNode/subNodeTip across all locales ### 📊 Changes **37 files changed** (+1002 additions, -222 deletions) <details> <summary>View changed files</summary> 📝 `database/model/model.go` (+41 -0) 📝 `frontend/public/openapi.json` (+49 -7) 📝 `frontend/src/api/queryKeys.ts` (+1 -1) 📝 `frontend/src/models/dbinbound.ts` (+3 -0) 📝 `frontend/src/pages/api-docs/endpoints.ts` (+11 -5) 📝 `frontend/src/pages/inbounds/useInbounds.ts` (+40 -34) 📝 `frontend/src/pages/nodes/NodeList.tsx` (+72 -15) 📝 `frontend/src/schemas/node.ts` (+5 -0) 📝 `web/controller/client.go` (+4 -4) 📝 `web/controller/node.go` (+1 -1) 📝 `web/controller/server.go` (+9 -0) 📝 `web/job/node_heartbeat_job.go` (+11 -1) 📝 `web/job/node_traffic_sync_job.go` (+2 -2) 📝 `web/job/xray_traffic_job.go` (+2 -2) 📝 `web/runtime/remote.go` (+39 -7) 📝 `web/service/inbound.go` (+123 -9) 📝 `web/service/node.go` (+28 -15) ➕ `web/service/node_origin_guid_test.go` (+71 -0) ➕ `web/service/node_tree.go` (+226 -0) ➕ `web/service/node_tree_test.go` (+81 -0) _...and 17 more files_ </details> ### 📄 Description ## Summary Adds end-to-end attribution and read-only surfacing of **chained sub-nodes** (Node1 → Node2 → Node3). Clients and inbounds hosted several hops down a node chain are now attributed to the node that physically hosts them, instead of the intermediate node they sync through, and a node's downstream sub-nodes are shown read-only on the Nodes page. ## Why Closes #4983 (dup #4984). Per-node online status was keyed by each panel's local autoincrement node id, which is meaningless one hop away. So in a chained topology the master attributed clients running on **Node3** to **Node2** (the node it syncs through), and Node3 was not visible on the master at all. This change introduces a stable, panel-local **`panelGuid`** as the cross-hop identity so attribution is correct at any depth. ## Type of change - [x] Bug fix - [x] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [x] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) - [ ] Xray config generation - [ ] Subscription (share links / Clash / JSON) - [x] Statistics / traffic counters - [x] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [x] Multi-node (sub-nodes) - [ ] Telegram bot ### What changed (by phase) - **Phase 0** — `panelGuid` (settings, get-or-create like `GetSecret`), returned in `panel/api/server/status`; the master learns each node's GUID via heartbeat into a new `Node.Guid` column. Guarded so an old-build node or a failed probe never clears a known GUID. - **Phase 1** — `Inbound.OriginNodeGuid`: the GUID of the panel that physically hosts an inbound. Empty = local (filled with the panel's own GUID at serve time); set during `SetRemoteTraffic`, preserving a value the node forwarded from its own sub-node so a transitive inbound stays attributed to the deepest node. - **Phase 2** — online status keyed by GUID **end-to-end**, replacing node-id keying. New `POST /panel/api/clients/onlinesByGuid` (was `/onlinesByNode`); `FetchTrafficSnapshot` falls back to the flat `/onlines` for old-build nodes; WS `onlineByGuid` field; the inbounds-page rollup scopes by `originNodeGuid`. - **Phase 3a** — `GET /panel/api/server/descendants` (node API token) publishes a panel's direct nodes; the heartbeat caches them and `GetNodeTree` surfaces transitive sub-nodes as read-only `model.Node` projections with per-GUID recounts. - **Phase 3b** — the Nodes page renders transitive sub-nodes indented and read-only under their parent (no toggle / probe / edit / delete / select / history), with a `Sub-node` tag. Locale keys translated across all 13 languages. ## How was this tested? - **Unit tests** (all green): `xray/online_test.go` (GUID-tree merge/scoping), `web/service/node_tree_test.go` (transitive surfacing), `web/service/node_origin_guid_test.go` (origin attribution). Full `go build ./...` + `go test` pass; frontend `tsc` / `lint` / `vitest` (408) pass. - **Docker E2E, real Node1 → Node2 → Node3 chain:** created a VMess inbound on Node2 assigned to Node3, drove real traffic through Node3's xray, and confirmed `node3user` was attributed to **Node3's GUID at every hop** (Node3 → Node2 → master `/clients/onlinesByGuid`); the master listed Node3 as a transitive node under Node2 (`transitive:true`, `node3.onlineCount=1`, `node2.onlineCount=0`, `node3.inboundCount=1`), and the inbound carried `originNodeGuid = <node3 guid>`. - Verified identically on a **Postgres-backed master** as well as SQLite. > UI note: on the Nodes page, downstream sub-nodes now appear as indented, read-only rows directly under the node they are reached through, tagged `Sub-node` with a tooltip naming the parent. ## Breaking changes None. Two new nullable columns (`nodes.guid`, `inbounds.origin_node_guid`) are added via AutoMigrate. Old-build nodes that don't report a GUID degrade gracefully to the previous flat behavior via a synthetic `node:<id>` key, so a mixed-version fleet keeps working. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [x] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [x] I updated the Wiki / README / API docs if user-facing behavior changed. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:03:50 +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#5753
No description provided.