Skip to content

Commit ae7967f

Browse files
committed
chore: the resolve and findProcess behaviors of Logic and SubRules follow the order and needs of the internal rules
1 parent 01f8f2d commit ae7967f

29 files changed

+122
-232
lines changed

constant/provider/interface.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ type RuleProvider interface {
9191
Provider
9292
Behavior() RuleBehavior
9393
Count() int
94-
Match(*constant.Metadata) bool
95-
ShouldResolveIP() bool
96-
ShouldFindProcess() bool
94+
Match(metadata *constant.Metadata, helper constant.RuleMatchHelper) bool
9795
Strategy() any
9896
}
9997

constant/rule.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,17 @@ func (rt RuleType) String() string {
111111

112112
type Rule interface {
113113
RuleType() RuleType
114-
Match(metadata *Metadata) (bool, string)
114+
Match(metadata *Metadata, helper RuleMatchHelper) (bool, string)
115115
Adapter() string
116116
Payload() string
117-
ShouldResolveIP() bool
118-
ShouldFindProcess() bool
119117
ProviderNames() []string
120118
}
121119

120+
type RuleMatchHelper struct {
121+
ResolveIP func()
122+
FindProcess func()
123+
}
124+
122125
type RuleGroup interface {
123126
Rule
124127
GetRecodeSize() int

rules/common/base.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ var (
2121
type Base struct {
2222
}
2323

24-
func (b *Base) ShouldFindProcess() bool {
25-
return false
26-
}
27-
28-
func (b *Base) ShouldResolveIP() bool {
29-
return false
30-
}
31-
3224
func (b *Base) ProviderNames() []string { return nil }
3325

3426
func ParseParams(params []string) (isSrc bool, noResolve bool) {

rules/common/domain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (d *Domain) RuleType() C.RuleType {
1717
return C.Domain
1818
}
1919

20-
func (d *Domain) Match(metadata *C.Metadata) (bool, string) {
20+
func (d *Domain) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
2121
return metadata.RuleHost() == d.domain, d.adapter
2222
}
2323

rules/common/domain_keyword.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (dk *DomainKeyword) RuleType() C.RuleType {
1717
return C.DomainKeyword
1818
}
1919

20-
func (dk *DomainKeyword) Match(metadata *C.Metadata) (bool, string) {
20+
func (dk *DomainKeyword) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
2121
domain := metadata.RuleHost()
2222
return strings.Contains(domain, dk.keyword), dk.adapter
2323
}

rules/common/domain_regex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (dr *DomainRegex) RuleType() C.RuleType {
1616
return C.DomainRegex
1717
}
1818

19-
func (dr *DomainRegex) Match(metadata *C.Metadata) (bool, string) {
19+
func (dr *DomainRegex) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
2020
domain := metadata.RuleHost()
2121
match, _ := dr.regex.MatchString(domain)
2222
return match, dr.adapter

rules/common/domain_suffix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (ds *DomainSuffix) RuleType() C.RuleType {
1717
return C.DomainSuffix
1818
}
1919

20-
func (ds *DomainSuffix) Match(metadata *C.Metadata) (bool, string) {
20+
func (ds *DomainSuffix) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
2121
domain := metadata.RuleHost()
2222
return strings.HasSuffix(domain, "."+ds.suffix) || domain == ds.suffix, ds.adapter
2323
}

rules/common/dscp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (d *DSCP) RuleType() C.RuleType {
1818
return C.DSCP
1919
}
2020

21-
func (d *DSCP) Match(metadata *C.Metadata) (bool, string) {
21+
func (d *DSCP) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
2222
return d.ranges.Check(metadata.DSCP), d.adapter
2323
}
2424

rules/common/final.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func (f *Match) RuleType() C.RuleType {
1313
return C.MATCH
1414
}
1515

16-
func (f *Match) Match(metadata *C.Metadata) (bool, string) {
16+
func (f *Match) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
1717
return true, f.adapter
1818
}
1919

rules/common/geoip.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ func (g *GEOIP) RuleType() C.RuleType {
3333
return C.GEOIP
3434
}
3535

36-
func (g *GEOIP) Match(metadata *C.Metadata) (bool, string) {
36+
func (g *GEOIP) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
37+
if !g.noResolveIP && !g.isSourceIP && helper.ResolveIP != nil {
38+
helper.ResolveIP()
39+
}
40+
3741
ip := metadata.DstIP
3842
if g.isSourceIP {
3943
ip = metadata.SrcIP
@@ -161,10 +165,6 @@ func (g *GEOIP) Payload() string {
161165
return g.country
162166
}
163167

164-
func (g *GEOIP) ShouldResolveIP() bool {
165-
return !g.noResolveIP
166-
}
167-
168168
func (g *GEOIP) GetCountry() string {
169169
return g.country
170170
}

0 commit comments

Comments
 (0)