fix(node): keep a node's online and IP reports to its own clients

A node's online tree and both client-IP reports were stored as sent:
they could name any client of the master or another node, under any
panel's GUID, dated into the future, and in any number. That marked
master clients online, fed source addresses for clients the node does
not serve into the IP limit and its fail2ban log, and planted rows the
retention sweep never removed.

Each report is now cut to the clients linked to the node's inbounds and
to the node's own key and its sub-nodes' origins (never this panel's or
another node's GUID); timestamps are capped at now, and one client's
list from a node keeps at most its 256 newest entries.
This commit is contained in:
MHSanaei
2026-10-31 14:14:01 +01:00
parent 4d27313c5e
commit a69f2dee13
6 changed files with 233 additions and 3 deletions
@@ -142,6 +142,18 @@ func TestMergeClientIpsByGuid_RemapsClonedNodeSubtree(t *testing.T) {
t.Fatalf("create node: %v", err)
}
}
// A node reports only clients linked to its own inbounds.
nodeIb := &model.Inbound{UserId: 1, Tag: "a-in", Port: 41501, Protocol: model.VLESS, NodeID: &n1.Id, Settings: `{"clients":[]}`}
client := &model.ClientRecord{Email: "u@x", Enable: true, SubID: "s-u"}
if err := db.Create(nodeIb).Error; err != nil {
t.Fatalf("create inbound: %v", err)
}
if err := db.Create(client).Error; err != nil {
t.Fatalf("create client: %v", err)
}
if err := db.Create(&model.ClientInbound{ClientId: client.Id, InboundId: nodeIb.Id}).Error; err != nil {
t.Fatalf("link client: %v", err)
}
if err := svc.MergeClientIpsByGuid(n1, map[string]map[string][]model.ClientIpEntry{
"dup": {"u@x": {{IP: "1.1.1.1", Timestamp: now}}},