mirror of
https://github.com/XrayR-project/XrayR.git
synced 2025-06-08 13:29:54 +00:00
reduce clear interval
This commit is contained in:
parent
9a06f78653
commit
be4f9cdac1
@ -61,7 +61,7 @@ func (l *Limiter) AddInboundLimiter(tag string, nodeSpeedLimit uint64, userList
|
|||||||
inboundInfo.GlobalLimit.config = globalLimit
|
inboundInfo.GlobalLimit.config = globalLimit
|
||||||
|
|
||||||
// init local store
|
// init local store
|
||||||
gs := goCacheStore.NewGoCache(goCache.New(time.Duration(globalLimit.Expiry)*time.Second, 10*time.Minute))
|
gs := goCacheStore.NewGoCache(goCache.New(time.Duration(globalLimit.Expiry)*time.Second, 1*time.Minute))
|
||||||
|
|
||||||
// init redis store
|
// init redis store
|
||||||
rs := redisStore.NewRedis(redis.NewClient(
|
rs := redisStore.NewRedis(redis.NewClient(
|
||||||
@ -196,9 +196,11 @@ func (l *Limiter) GetUserBucket(tag string, email string, ip string) (limiter *r
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GlobalLimit
|
// GlobalLimit
|
||||||
|
if inboundInfo.GlobalLimit.config != nil && inboundInfo.GlobalLimit.config.Enable {
|
||||||
if reject := globalLimit(inboundInfo, email, uid, ip, deviceLimit); reject {
|
if reject := globalLimit(inboundInfo, email, uid, ip, deviceLimit); reject {
|
||||||
return nil, false, true
|
return nil, false, true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Speed limit
|
// Speed limit
|
||||||
limit := determineRate(nodeLimit, userLimit) // Determine the speed limit rate
|
limit := determineRate(nodeLimit, userLimit) // Determine the speed limit rate
|
||||||
@ -221,18 +223,18 @@ func (l *Limiter) GetUserBucket(tag string, email string, ip string) (limiter *r
|
|||||||
|
|
||||||
// Global device limit
|
// Global device limit
|
||||||
func globalLimit(inboundInfo *InboundInfo, email string, uid int, ip string, deviceLimit int) bool {
|
func globalLimit(inboundInfo *InboundInfo, email string, uid int, ip string, deviceLimit int) bool {
|
||||||
if inboundInfo.GlobalLimit.config != nil && inboundInfo.GlobalLimit.config.Enable {
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(inboundInfo.GlobalLimit.config.Timeout)*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(inboundInfo.GlobalLimit.config.Timeout)*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
// reformat email for unique key
|
// reformat email for unique key
|
||||||
email := strings.Replace(email, inboundInfo.Tag, strconv.Itoa(deviceLimit), 1)
|
uniqueKey := strings.Replace(email, inboundInfo.Tag, strconv.Itoa(deviceLimit), 1)
|
||||||
|
|
||||||
v, err := inboundInfo.GlobalLimit.globalOnlineIP.Get(ctx, email, new(map[string]int))
|
v, err := inboundInfo.GlobalLimit.globalOnlineIP.Get(ctx, uniqueKey, new(map[string]int))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(*store.NotFound); ok {
|
if _, ok := err.(*store.NotFound); ok {
|
||||||
// If the email is a new device
|
// If the email is a new device
|
||||||
go pushIP(inboundInfo, email, &map[string]int{ip: uid})
|
go pushIP(inboundInfo, uniqueKey, &map[string]int{ip: uid})
|
||||||
} else {
|
} else {
|
||||||
newError("cache service").Base(err).AtError().WriteToLog()
|
newError("cache service").Base(err).AtError().WriteToLog()
|
||||||
}
|
}
|
||||||
@ -250,7 +252,6 @@ func globalLimit(inboundInfo *InboundInfo, email string, uid int, ip string, dev
|
|||||||
(*ipMap)[ip] = uid
|
(*ipMap)[ip] = uid
|
||||||
go pushIP(inboundInfo, email, ipMap)
|
go pushIP(inboundInfo, email, ipMap)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user