remove limit from UserList

This commit is contained in:
yuzuki999 2022-06-13 14:47:01 +08:00
parent 2d279aa202
commit 297d9cc618
3 changed files with 16 additions and 23 deletions

View File

@ -20,14 +20,14 @@ type TrojanUserInfo struct {
Password string `json:"password"` Password string `json:"password"`
} }
type UserInfo struct { type UserInfo struct {
DeviceLimit int `json:"device_limit"` /*DeviceLimit int `json:"device_limit"`
SpeedLimit uint64 `json:"speed_limit"` SpeedLimit uint64 `json:"speed_limit"`*/
UID int `json:"id"` UID int `json:"id"`
Port int `json:"port"` Port int `json:"port"`
Cipher string `json:"cipher"` Cipher string `json:"cipher"`
Secret string `json:"secret"` Secret string `json:"secret"`
V2rayUser *V2RayUserInfo `json:"v2ray_user"` V2rayUser *V2RayUserInfo `json:"v2ray_user"`
TrojanUser *TrojanUserInfo `json:"trojan_user"` TrojanUser *TrojanUserInfo `json:"trojan_user"`
} }
func (p *UserInfo) GetUserEmail() string { func (p *UserInfo) GetUserEmail() string {

View File

@ -490,13 +490,6 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.
// Check if domain and protocol hit the rule // Check if domain and protocol hit the rule
sessionInbound := session.InboundFromContext(ctx) sessionInbound := session.InboundFromContext(ctx)
// Whether the inbound connection contains a user // Whether the inbound connection contains a user
/*if protocol == "bittorrent" {
newError(fmt.Sprintf("User %s access %s reject by protocol rule", sessionInbound.User.Email, destination.String())).AtError().WriteToLog()
newError("destination is reject by protocol rule")
common.Close(link.Writer)
common.Interrupt(link.Reader)
return
}*/
if sessionInbound.User != nil { if sessionInbound.User != nil {
if d.RuleManager.ProtocolDetect(sessionInbound.Tag, protocol) { if d.RuleManager.ProtocolDetect(sessionInbound.Tag, protocol) {
newError(fmt.Sprintf("User %s access %s reject by protocol rule", sessionInbound.User.Email, destination.String())).AtError().WriteToLog() newError(fmt.Sprintf("User %s access %s reject by protocol rule", sessionInbound.User.Email, destination.String())).AtError().WriteToLog()

View File

@ -43,16 +43,16 @@ func (l *Limiter) AddInboundLimiter(tag string, nodeInfo *api.NodeInfo, userList
} }
userMap := new(sync.Map) userMap := new(sync.Map)
for i := range *userList { for i := range *userList {
if (*userList)[i].SpeedLimit == 0 { /*if (*userList)[i].SpeedLimit == 0 {
(*userList)[i].SpeedLimit = nodeInfo.SpeedLimit (*userList)[i].SpeedLimit = nodeInfo.SpeedLimit
} }
if (*userList)[i].DeviceLimit == 0 { if (*userList)[i].DeviceLimit == 0 {
(*userList)[i].DeviceLimit = nodeInfo.DeviceLimit (*userList)[i].DeviceLimit = nodeInfo.DeviceLimit
} }*/
userMap.Store(fmt.Sprintf("%s|%s|%d", tag, (*userList)[i].GetUserEmail(), (*userList)[i].UID), UserInfo{ userMap.Store(fmt.Sprintf("%s|%s|%d", tag, (*userList)[i].GetUserEmail(), (*userList)[i].UID), UserInfo{
UID: (*userList)[i].UID, UID: (*userList)[i].UID,
SpeedLimit: (*userList)[i].SpeedLimit, SpeedLimit: nodeInfo.SpeedLimit,
DeviceLimit: (*userList)[i].DeviceLimit, DeviceLimit: nodeInfo.DeviceLimit,
}) })
} }
inboundInfo.UserInfo = userMap inboundInfo.UserInfo = userMap
@ -66,16 +66,16 @@ func (l *Limiter) UpdateInboundLimiter(tag string, nodeInfo *api.NodeInfo, updat
inboundInfo := value.(*InboundInfo) inboundInfo := value.(*InboundInfo)
// Update User info // Update User info
for _, u := range *usersIndex { for _, u := range *usersIndex {
if (*updatedUserList)[u].SpeedLimit == 0 { /*if (*updatedUserList)[u].SpeedLimit == 0 {
(*updatedUserList)[u].SpeedLimit = nodeInfo.SpeedLimit (*updatedUserList)[u].SpeedLimit = nodeInfo.SpeedLimit
} }
if (*updatedUserList)[u].DeviceLimit == 0 { if (*updatedUserList)[u].DeviceLimit == 0 {
(*updatedUserList)[u].DeviceLimit = nodeInfo.DeviceLimit (*updatedUserList)[u].DeviceLimit = nodeInfo.DeviceLimit
} }*/
inboundInfo.UserInfo.Store(fmt.Sprintf("%s|%s|%d", tag, (*updatedUserList)[u].GetUserEmail(), (*updatedUserList)[u].UID), UserInfo{ inboundInfo.UserInfo.Store(fmt.Sprintf("%s|%s|%d", tag, (*updatedUserList)[u].GetUserEmail(), (*updatedUserList)[u].UID), UserInfo{
UID: (*updatedUserList)[u].UID, UID: (*updatedUserList)[u].UID,
SpeedLimit: (*updatedUserList)[u].SpeedLimit, SpeedLimit: nodeInfo.SpeedLimit,
DeviceLimit: (*updatedUserList)[u].DeviceLimit, DeviceLimit: nodeInfo.DeviceLimit,
}) })
inboundInfo.BucketHub.Delete(fmt.Sprintf("%s|%s|%d", tag, (*updatedUserList)[u].GetUserEmail(), (*updatedUserList)[u].UID)) // Delete old limiter bucket inboundInfo.BucketHub.Delete(fmt.Sprintf("%s|%s|%d", tag, (*updatedUserList)[u].GetUserEmail(), (*updatedUserList)[u].UID)) // Delete old limiter bucket
} }