update example, add realtime option, fix ip limit bug for packet protocol

This commit is contained in:
yuzuki999
2023-05-17 09:46:52 +08:00
parent c6658c2ce1
commit 48da83fc3d
9 changed files with 114 additions and 100 deletions

View File

@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/Yuzuki616/V2bX/api/panel"
"github.com/Yuzuki616/V2bX/conf"
"github.com/juju/ratelimit"
"github.com/xtls/xray-core/common/task"
"log"
@@ -18,10 +19,10 @@ func Init() {
limiter = map[string]*Limiter{}
c := task.Periodic{
Interval: time.Minute * 2,
Execute: ClearPacketOnlineIP,
Execute: ClearOnlineIP,
}
go func() {
log.Println("Limiter: ClearPacketOnlineIP started")
log.Println("Limiter: ClearOnlineIP started")
time.Sleep(time.Minute * 2)
c.Start()
}()
@@ -43,17 +44,11 @@ type UserLimitInfo struct {
ExpireTime int64
}
type LimitConfig struct {
SpeedLimit int
IpLimit int
ConnLimit int
}
func AddLimiter(tag string, l *LimitConfig, users []panel.UserInfo) *Limiter {
func AddLimiter(tag string, l *conf.LimitConfig, users []panel.UserInfo) *Limiter {
info := &Limiter{
SpeedLimit: l.SpeedLimit,
UserLimitInfo: new(sync.Map),
ConnLimiter: NewConnLimiter(l.ConnLimit, l.IpLimit),
ConnLimiter: NewConnLimiter(l.ConnLimit, l.IPLimit, l.EnableRealtime),
SpeedLimiter: new(sync.Map),
}
for i := range users {