mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 04:30:08 +00:00
add protocol rule,fix limit not work
This commit is contained in:
@@ -49,7 +49,7 @@ func (l *Limiter) AddInboundLimiter(tag string, nodeInfo *api.NodeInfo, userList
|
||||
if (*userList)[i].DeviceLimit == 0 {
|
||||
(*userList)[i].DeviceLimit = nodeInfo.DeviceLimit
|
||||
}
|
||||
userMap.Store(fmt.Sprintf("%s|%d|%d", tag, (*userList)[i].Port, (*userList)[i].UID), UserInfo{
|
||||
userMap.Store(fmt.Sprintf("%s|%s|%d", tag, (*userList)[i].GetUserEmail(), (*userList)[i].UID), UserInfo{
|
||||
UID: (*userList)[i].UID,
|
||||
SpeedLimit: (*userList)[i].SpeedLimit,
|
||||
DeviceLimit: (*userList)[i].DeviceLimit,
|
||||
|
||||
@@ -14,12 +14,14 @@ import (
|
||||
|
||||
type Rule struct {
|
||||
InboundRule *sync.Map // Key: Tag, Value: []api.DetectRule
|
||||
InboundProtocolRule *sync.Map // Key: Tag, Value: []string
|
||||
InboundDetectResult *sync.Map // key: Tag, Value: mapset.NewSet []api.DetectResult
|
||||
}
|
||||
|
||||
func New() *Rule {
|
||||
return &Rule{
|
||||
InboundRule: new(sync.Map),
|
||||
InboundProtocolRule: new(sync.Map),
|
||||
InboundDetectResult: new(sync.Map),
|
||||
}
|
||||
}
|
||||
@@ -34,6 +36,16 @@ func (r *Rule) UpdateRule(tag string, newRuleList []api.DetectRule) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Rule) UpdateProtocolRule(tag string, ruleList []string) error {
|
||||
if value, ok := r.InboundProtocolRule.LoadOrStore(tag, ruleList); ok {
|
||||
old := value.([]string)
|
||||
if !reflect.DeepEqual(old, ruleList) {
|
||||
r.InboundProtocolRule.Store(tag, ruleList)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Rule) GetDetectResult(tag string) (*[]api.DetectResult, error) {
|
||||
detectResult := make([]api.DetectResult, 0)
|
||||
if value, ok := r.InboundDetectResult.LoadAndDelete(tag); ok {
|
||||
@@ -80,3 +92,14 @@ func (r *Rule) Detect(tag string, destination string, email string) (reject bool
|
||||
}
|
||||
return reject
|
||||
}
|
||||
func (r *Rule) ProtocolDetect(tag string, protocol string) bool {
|
||||
if value, ok := r.InboundProtocolRule.Load(tag); ok {
|
||||
ruleList := value.([]string)
|
||||
for _, r := range ruleList {
|
||||
if r == protocol {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user