From 297d9cc6181c7956788038f73b7867a183e2807d Mon Sep 17 00:00:00 2001 From: yuzuki999 Date: Mon, 13 Jun 2022 14:47:01 +0800 Subject: [PATCH] remove limit from UserList --- api/user.go | 16 ++++++++-------- app/mydispatcher/default.go | 7 ------- common/limiter/limiter.go | 16 ++++++++-------- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/api/user.go b/api/user.go index 0e106ca..b01c1ba 100644 --- a/api/user.go +++ b/api/user.go @@ -20,14 +20,14 @@ type TrojanUserInfo struct { Password string `json:"password"` } type UserInfo struct { - DeviceLimit int `json:"device_limit"` - SpeedLimit uint64 `json:"speed_limit"` - UID int `json:"id"` - Port int `json:"port"` - Cipher string `json:"cipher"` - Secret string `json:"secret"` - V2rayUser *V2RayUserInfo `json:"v2ray_user"` - TrojanUser *TrojanUserInfo `json:"trojan_user"` + /*DeviceLimit int `json:"device_limit"` + SpeedLimit uint64 `json:"speed_limit"`*/ + UID int `json:"id"` + Port int `json:"port"` + Cipher string `json:"cipher"` + Secret string `json:"secret"` + V2rayUser *V2RayUserInfo `json:"v2ray_user"` + TrojanUser *TrojanUserInfo `json:"trojan_user"` } func (p *UserInfo) GetUserEmail() string { diff --git a/app/mydispatcher/default.go b/app/mydispatcher/default.go index 591e22e..891afe3 100644 --- a/app/mydispatcher/default.go +++ b/app/mydispatcher/default.go @@ -490,13 +490,6 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport. // Check if domain and protocol hit the rule sessionInbound := session.InboundFromContext(ctx) // 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 d.RuleManager.ProtocolDetect(sessionInbound.Tag, protocol) { newError(fmt.Sprintf("User %s access %s reject by protocol rule", sessionInbound.User.Email, destination.String())).AtError().WriteToLog() diff --git a/common/limiter/limiter.go b/common/limiter/limiter.go index c06800c..5df38b0 100644 --- a/common/limiter/limiter.go +++ b/common/limiter/limiter.go @@ -43,16 +43,16 @@ func (l *Limiter) AddInboundLimiter(tag string, nodeInfo *api.NodeInfo, userList } userMap := new(sync.Map) for i := range *userList { - if (*userList)[i].SpeedLimit == 0 { + /*if (*userList)[i].SpeedLimit == 0 { (*userList)[i].SpeedLimit = nodeInfo.SpeedLimit } if (*userList)[i].DeviceLimit == 0 { (*userList)[i].DeviceLimit = nodeInfo.DeviceLimit - } + }*/ userMap.Store(fmt.Sprintf("%s|%s|%d", tag, (*userList)[i].GetUserEmail(), (*userList)[i].UID), UserInfo{ UID: (*userList)[i].UID, - SpeedLimit: (*userList)[i].SpeedLimit, - DeviceLimit: (*userList)[i].DeviceLimit, + SpeedLimit: nodeInfo.SpeedLimit, + DeviceLimit: nodeInfo.DeviceLimit, }) } inboundInfo.UserInfo = userMap @@ -66,16 +66,16 @@ func (l *Limiter) UpdateInboundLimiter(tag string, nodeInfo *api.NodeInfo, updat inboundInfo := value.(*InboundInfo) // Update User info for _, u := range *usersIndex { - if (*updatedUserList)[u].SpeedLimit == 0 { + /*if (*updatedUserList)[u].SpeedLimit == 0 { (*updatedUserList)[u].SpeedLimit = nodeInfo.SpeedLimit } if (*updatedUserList)[u].DeviceLimit == 0 { (*updatedUserList)[u].DeviceLimit = nodeInfo.DeviceLimit - } + }*/ inboundInfo.UserInfo.Store(fmt.Sprintf("%s|%s|%d", tag, (*updatedUserList)[u].GetUserEmail(), (*updatedUserList)[u].UID), UserInfo{ UID: (*updatedUserList)[u].UID, - SpeedLimit: (*updatedUserList)[u].SpeedLimit, - DeviceLimit: (*updatedUserList)[u].DeviceLimit, + SpeedLimit: nodeInfo.SpeedLimit, + DeviceLimit: nodeInfo.DeviceLimit, }) inboundInfo.BucketHub.Delete(fmt.Sprintf("%s|%s|%d", tag, (*updatedUserList)[u].GetUserEmail(), (*updatedUserList)[u].UID)) // Delete old limiter bucket }