mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 12:40:11 +00:00
support protocol rule
This commit is contained in:
@@ -3,15 +3,16 @@ package limiter
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/Yuzuki616/V2bX/api/panel"
|
||||
"github.com/Yuzuki616/V2bX/common/format"
|
||||
"github.com/Yuzuki616/V2bX/conf"
|
||||
"github.com/juju/ratelimit"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/xtls/xray-core/common/task"
|
||||
"regexp"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var limitLock sync.RWMutex
|
||||
@@ -32,7 +33,7 @@ func Init() {
|
||||
}
|
||||
|
||||
type Limiter struct {
|
||||
Rules []*regexp.Regexp
|
||||
DomainRules []*regexp.Regexp
|
||||
ProtocolRules []string
|
||||
SpeedLimit int
|
||||
UserLimitInfo *sync.Map // Key: Uid value: UserLimitInfo
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package limiter
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"regexp"
|
||||
|
||||
"github.com/Yuzuki616/V2bX/api/panel"
|
||||
)
|
||||
|
||||
func (l *Limiter) CheckDomainRule(destination string) (reject bool) {
|
||||
// have rule
|
||||
for i := range l.Rules {
|
||||
if l.Rules[i].MatchString(destination) {
|
||||
for i := range l.DomainRules {
|
||||
if l.DomainRules[i].MatchString(destination) {
|
||||
reject = true
|
||||
break
|
||||
}
|
||||
@@ -26,9 +27,11 @@ func (l *Limiter) CheckProtocolRule(protocol string) (reject bool) {
|
||||
return
|
||||
}
|
||||
|
||||
func (l *Limiter) UpdateRule(newRuleList []*regexp.Regexp) error {
|
||||
if !reflect.DeepEqual(l.Rules, newRuleList) {
|
||||
l.Rules = newRuleList
|
||||
func (l *Limiter) UpdateRule(rule *panel.Rules) error {
|
||||
l.DomainRules = make([]*regexp.Regexp, len(rule.Regexp))
|
||||
for i := range rule.Regexp {
|
||||
l.DomainRules[i] = regexp.MustCompile(rule.Regexp[i])
|
||||
}
|
||||
l.ProtocolRules = rule.Protocol
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user