mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 04:30:08 +00:00
修复xray内核vless协议bug,升级xray/sing内核
This commit is contained in:
@@ -126,25 +126,27 @@ func (l *Limiter) UpdateDynamicSpeedLimit(tag, uuid string, limit int, expire ti
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *Limiter) CheckLimit(uuid string, ip string, isTcp bool) (Bucket *ratelimit.Bucket, Reject bool) {
|
||||
func (l *Limiter) CheckLimit(taguuid string, ip string, isTcp bool) (Bucket *ratelimit.Bucket, Reject bool) {
|
||||
// ip and conn limiter
|
||||
if l.ConnLimiter.AddConnCount(uuid, ip, isTcp) {
|
||||
if l.ConnLimiter.AddConnCount(taguuid, ip, isTcp) {
|
||||
return nil, true
|
||||
}
|
||||
// check and gen speed limit Bucket
|
||||
nodeLimit := l.SpeedLimit
|
||||
userLimit := 0
|
||||
deviceLimit := 0
|
||||
if v, ok := l.UserLimitInfo.Load(uuid); ok {
|
||||
var uid int
|
||||
if v, ok := l.UserLimitInfo.Load(taguuid); ok {
|
||||
u := v.(*UserLimitInfo)
|
||||
deviceLimit = u.DeviceLimit
|
||||
uid = u.UID
|
||||
if u.ExpireTime < time.Now().Unix() && u.ExpireTime != 0 {
|
||||
if u.SpeedLimit != 0 {
|
||||
userLimit = u.SpeedLimit
|
||||
u.DynamicSpeedLimit = 0
|
||||
u.ExpireTime = 0
|
||||
} else {
|
||||
l.UserLimitInfo.Delete(uuid)
|
||||
l.UserLimitInfo.Delete(taguuid)
|
||||
}
|
||||
} else {
|
||||
userLimit = determineSpeedLimit(u.SpeedLimit, u.DynamicSpeedLimit)
|
||||
@@ -153,10 +155,9 @@ func (l *Limiter) CheckLimit(uuid string, ip string, isTcp bool) (Bucket *rateli
|
||||
|
||||
// Store online user for device limit
|
||||
ipMap := new(sync.Map)
|
||||
uid := l.UUIDtoUID[uuid]
|
||||
ipMap.Store(ip, uid)
|
||||
// If any device is online
|
||||
if v, ok := l.UserOnlineIP.LoadOrStore(uuid, ipMap); ok {
|
||||
if v, ok := l.UserOnlineIP.LoadOrStore(taguuid, ipMap); ok {
|
||||
ipMap := v.(*sync.Map)
|
||||
// If this is a new ip
|
||||
if _, ok := ipMap.LoadOrStore(ip, uid); !ok {
|
||||
@@ -175,10 +176,10 @@ func (l *Limiter) CheckLimit(uuid string, ip string, isTcp bool) (Bucket *rateli
|
||||
limit := int64(determineSpeedLimit(nodeLimit, userLimit)) * 1000000 / 8 // If you need the Speed limit
|
||||
if limit > 0 {
|
||||
Bucket = ratelimit.NewBucketWithQuantum(time.Second, limit, limit) // Byte/s
|
||||
if v, ok := l.SpeedLimiter.LoadOrStore(uuid, Bucket); ok {
|
||||
if v, ok := l.SpeedLimiter.LoadOrStore(taguuid, Bucket); ok {
|
||||
return v.(*ratelimit.Bucket), false
|
||||
} else {
|
||||
l.SpeedLimiter.Store(uuid, Bucket)
|
||||
l.SpeedLimiter.Store(taguuid, Bucket)
|
||||
return Bucket, false
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user