Skip to content

fix: detect modified user limits and refresh limiter state#13

Merged
besnow merged 2 commits into
dev_newfrom
codex/create-fix-branch-and-pr-for-user-limits
May 20, 2026
Merged

fix: detect modified user limits and refresh limiter state#13
besnow merged 2 commits into
dev_newfrom
codex/create-fix-branch-and-pr-for-user-limits

Conversation

@besnow
Copy link
Copy Markdown
Owner

@besnow besnow commented May 20, 2026

Motivation

  • 现有用户同步只分为 deleted / added,通过 UUID+SpeedLimit 判断变化会漏掉 DeviceLimitId 的变更,导致节点端 limiter 状态不同步。
  • 目标是最小改动修复:以 UUID 为主键,增加 modified 分类并在 limiter 层刷新对应用户的限速 / 设备限制。

Description

  • compareUserList 从返回 (deleted, added) 升级为 (deleted, added, modified),仅以 Uuid 为键,若 SpeedLimitDeviceLimitId 发生变化则归类为 modified(修改文件:node/user.go)。
  • 在用户同步流程中接收三类结果:added 仍走 AddUsersdeleted 仍走 DelUsersmodified 不再触发 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 处理:就地更新 UserLimitInfoUID/SpeedLimit/DeviceLimit、刷新 UUIDtoUID,并在 SpeedLimit 变更时删除对应的 SpeedLimiter bucket 以迫使后续建立新桶;若记录不存在则按 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

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

V2bX/node/task.go

Lines 194 to 200 in 6c17ea8

if len(added) > 0 {
// have added users
_, err = c.server.AddUsers(&vCore.AddUsersParams{
Tag: c.tag,
NodeInfo: c.info,
Users: added,
})

P1 Badge Refresh core UID mapping for modified users

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".

@besnow
Copy link
Copy Markdown
Owner Author

besnow commented May 20, 2026

SpeedLimit / DeviceLimit 发生变化时归类为 modified。
Id-only change 不归类为 modified,因为 V2Board 中 UUID -> user ID 是稳定映射。

@besnow besnow merged commit 3ce86ae into dev_new May 20, 2026
23 checks passed
@besnow besnow deleted the codex/create-fix-branch-and-pr-for-user-limits branch May 20, 2026 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant