fix: detect modified user limits and refresh limiter state#13
Conversation
There was a problem hiding this comment.
💡 Codex Review
Lines 194 to 200 in 6c17ea8
When a user's Id changes but Uuid stays the same, this path marks the user as modified and skips c.server.AddUsers, so the core's UID mapping is never updated. In core/xray/user.go, uidMap is only rewritten inside AddUsers, and GetUserTrafficSlice reads that map to populate reported UID; as a result, traffic continues to be attributed to the old UID after an ID-only change. This commit introduces that mismatch because modified users now update limiter state but not the core user map.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
SpeedLimit / DeviceLimit 发生变化时归类为 modified。 |
Motivation
deleted/added,通过UUID+SpeedLimit判断变化会漏掉DeviceLimit或Id的变更,导致节点端 limiter 状态不同步。UUID为主键,增加modified分类并在 limiter 层刷新对应用户的限速 / 设备限制。Description
compareUserList从返回(deleted, added)升级为(deleted, added, modified),仅以Uuid为键,若SpeedLimit、DeviceLimit或Id发生变化则归类为modified(修改文件:node/user.go)。added仍走AddUsers,deleted仍走DelUsers,modified不再触发 add/del;当任一非空时调用c.limiter.UpdateUser(c.tag, added, deleted, modified)并在日志中输出三类计数(修改文件:node/task.go)。limiter.UpdateUser签名改为UpdateUser(tag string, added, deleted, modified []panel.UserInfo),保留原有 add/delete 逻辑并新增 modified 处理:就地更新UserLimitInfo的UID/SpeedLimit/DeviceLimit、刷新UUIDtoUID,并在 SpeedLimit 变更时删除对应的SpeedLimiterbucket 以迫使后续建立新桶;若记录不存在则按 added 逻辑补建(修改文件:limiter/limiter.go)。compareUserList单元测试覆盖无变化/新增/删除/SpeedLimit 变更/DeviceLimit 变更/相同 UUID 且限制不变不列为 modified(新增文件:node/user_test.go)。Testing
gofmt -w node/user.go node/task.go limiter/limiter.go node/user_test.go,格式化成功。go test ./...,测试通过(包含新增的compareUserList测试)。go build ./...,构建成功。Codex Task