mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #3735] [MERGED] feat: implement 'last IP wins' policy for IP limitation #5517
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#5517
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/3735
Author: @AungYeZawDev
Created: 2/2/2026
Status: ✅ Merged
Merged: 2/3/2026
Merged by: @MHSanaei
Base:
main← Head:feat/last-ip-wins-limitation📝 Commits (2)
430e644feat: implement 'last IP wins' policy for IP limitationcd90174Merge branch 'main' into feat/last-ip-wins-limitation📊 Changes
2 files changed (+325 additions, -38 deletions)
View changed files
➕
.github/copilot-instructions.md(+155 -0)📝
web/job/check_client_ip_job.go(+170 -38)📄 Description
Implement "last IP wins" policy for IP limitation
What is the pull request?
This PR implements a "last IP wins" policy for the IP limitation feature. When a client exceeds their configured IP limit, the system now automatically disconnects connections from the oldest IPs and keeps only the most recent connections active.
Key improvements:
Previous behavior:
New behavior:
Which part of the application is affected by the change?
Files modified:
web/job/check_client_ip_job.go- Complete rewrite of IP limitation logic.github/copilot-instructions.md- Added (new documentation for AI coding assistants)Type of Changes
This is both a new feature (active disconnection mechanism) and a refactoring (improved IP tracking logic)
Technical Details
Database Format Change
Old format (simple IP array):
New format (IP with timestamp):
Disconnection Mechanism
When limit exceeded:
xrayAPI.RemoveUser(tag, email)- Disconnect ALL connectionstime.Sleep(100ms)- Wait for cleanupxrayAPI.AddUser(tag, config)- Re-add user (allows new IPs only)Implementation Changes
Added:
IPWithTimestampstruct for tracking IPs with timestampsdisconnectClientTemporarily()function for active connection terminationModified:
processLogFile()- Now extracts and stores timestampsaddInboundClientIps()- Accepts[]IPWithTimestampinstead of[]stringupdateInboundClientIps()- Complete rewrite with active disconnection logicLog Output Example
Use Cases
Perfect for VPN Providers
Example Scenarios
Scenario 1: Account Sharing Prevention
LimitIP=1: Friend's connection succeeds, user disconnectsScenario 2: Network Switching (Legitimate Use)
LimitIP=1: WiFi connection drops, mobile stays activeScenario 3: Same ISP Reconnection
LimitIP=1: No problem, no disconnectionTesting Recommendations
Basic Test:
Log Verification:
Database Inspection:
Edge Cases:
Backward Compatibility
✅ Fully backward compatible
Performance Considerations
Security Implications
✅ Improves Security:
⚠️ Considerations:
xrayApiPortsetting)Breaking Changes
None - This is a pure enhancement. The feature:
LimitIPconfigurationLimitIPsetDocumentation Updates
.github/copilot-instructions.mdwith comprehensive development guideFuture Enhancements (Not in This PR)
Screenshots
Not applicable - Backend functionality only (log-based verification)
Summary
This PR transforms IP limitation from a passive logging system into an active enforcement mechanism that benefits both VPN providers and end users. It prevents account sharing while gracefully handling legitimate network switching scenarios.
Ready for Review ✅
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.