2023-05-15 21:15:29 -04:00
|
|
|
package limiter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
2023-05-21 22:36:10 -04:00
|
|
|
"regexp"
|
2023-05-15 21:15:29 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func (l *Limiter) CheckDomainRule(destination string) (reject bool) {
|
|
|
|
// have rule
|
|
|
|
for i := range l.Rules {
|
2023-05-21 22:36:10 -04:00
|
|
|
if l.Rules[i].MatchString(destination) {
|
2023-05-15 21:15:29 -04:00
|
|
|
reject = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Limiter) CheckProtocolRule(protocol string) (reject bool) {
|
|
|
|
for i := range l.ProtocolRules {
|
|
|
|
if l.ProtocolRules[i] == protocol {
|
|
|
|
reject = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-21 22:36:10 -04:00
|
|
|
func (l *Limiter) UpdateRule(newRuleList []*regexp.Regexp) error {
|
2023-05-15 21:15:29 -04:00
|
|
|
if !reflect.DeepEqual(l.Rules, newRuleList) {
|
|
|
|
l.Rules = newRuleList
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|