Debian Codegraph @

app/router/condition.go

raw symbols SCIP
1 // +build !confonly
2
3 package routerscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/
4
5 import (
6 "stringsscip-go gomod github.com/golang/go/src go1.15 strings/"
7
8 "go.starlark.net/starlarkscip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/starlark`/"
9 "go.starlark.net/syntaxscip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/syntax`/"
10 "v2ray.com/core/common/netscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/"
11 "v2ray.com/core/common/strmatcherscip-go gomod v2ray.com/core . `v2ray.com/core/common/strmatcher`/"
12 "v2ray.com/core/features/routingscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/"
13 )
14
15 type Conditionscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/Condition# interface {
16 Applyscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/Condition#Apply.(ctx routingscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/.Contextscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/Context#) bool
17 }
18
19 type ConditionChanscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/ConditionChan# []Conditionscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/Condition#
20
21 func NewConditionChanscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/NewConditionChan().() *ConditionChanscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/ConditionChan# {
22 var condChan ConditionChanscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/ConditionChan# = make([]Conditionscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/Condition#, 0, 8)
23 return &condChan
24 }
25
26 func (v *ConditionChanscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/ConditionChan#) Addscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/ConditionChan#Add().(cond Conditionscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/Condition#) *ConditionChanscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/ConditionChan# {
27 *v = append(*v, cond)
28 return v
29 }
30
31 // Apply applies all conditions registered in this chan.
32 func (v *ConditionChanscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/ConditionChan#) Applyscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/ConditionChan#Apply().(ctx routingscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/.Contextscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/Context#) bool {
33 for _, cond := range *v {
34 if !cond.Applyscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/Condition#Apply.(ctx) {
35 return false
36 }
37 }
38 return true
39 }
40
41 func (v *ConditionChanscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/ConditionChan#) Lenscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/ConditionChan#Len().() int {
42 return len(*v)
43 }
44
45 var matcherTypeMapscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/matcherTypeMap. = map[Domain_Typescip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/Domain_Type#]strmatcherscip-go gomod v2ray.com/core . `v2ray.com/core/common/strmatcher`/.Typescip-go gomod v2ray.com/core . `v2ray.com/core/common/strmatcher`/Type#{
46 Domain_Plainscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/Domain_Plain.: strmatcherscip-go gomod v2ray.com/core . `v2ray.com/core/common/strmatcher`/.Substrscip-go gomod v2ray.com/core . `v2ray.com/core/common/strmatcher`/Substr.,
47 Domain_Regexscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/Domain_Regex.: strmatcherscip-go gomod v2ray.com/core . `v2ray.com/core/common/strmatcher`/.Regexscip-go gomod v2ray.com/core . `v2ray.com/core/common/strmatcher`/Regex.,
48 Domain_Domainscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/Domain_Domain.: strmatcherscip-go gomod v2ray.com/core . `v2ray.com/core/common/strmatcher`/.Domainscip-go gomod v2ray.com/core . `v2ray.com/core/common/strmatcher`/Domain.,
49 Domain_Fullscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/Domain_Full.: strmatcherscip-go gomod v2ray.com/core . `v2ray.com/core/common/strmatcher`/.Fullscip-go gomod v2ray.com/core . `v2ray.com/core/common/strmatcher`/Full.,
50 }
51
52 func domainToMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/domainToMatcher().(domain *Domainscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/Domain#) (strmatcherscip-go gomod v2ray.com/core . `v2ray.com/core/common/strmatcher`/.Matcherscip-go gomod v2ray.com/core . `v2ray.com/core/common/strmatcher`/Matcher#, error) {
53 matcherType, f := matcherTypeMapscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/matcherTypeMap.[domain.Typescip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/Domain#Type.]
54 if !f {
55 return nil, newErrorscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/newError().("unsupported domain type", domain.Typescip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/Domain#Type.)
56 }
57
58 matcher, err := matcherType.Newscip-go gomod v2ray.com/core . `v2ray.com/core/common/strmatcher`/Type#New().(domain.Valuescip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/Domain#Value.)
59 if err != nil {
60 return nil, newErrorscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/newError().("failed to create domain matcher").Basescip-go gomod v2ray.com/core . `v2ray.com/core/common/errors`/Error#Base().(err)
61 }
62
63 return matcher, nil
64 }
65
66 type DomainMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/DomainMatcher# struct {
67 matchersscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/DomainMatcher#matchers. strmatcherscip-go gomod v2ray.com/core . `v2ray.com/core/common/strmatcher`/.IndexMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/common/strmatcher`/IndexMatcher#
68 }
69
70 func NewDomainMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/NewDomainMatcher().(domains []*Domainscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/Domain#) (*DomainMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/DomainMatcher#, error) {
71 g := new(strmatcherscip-go gomod v2ray.com/core . `v2ray.com/core/common/strmatcher`/.MatcherGroupscip-go gomod v2ray.com/core . `v2ray.com/core/common/strmatcher`/MatcherGroup#)
72 for _, d := range domains {
73 m, err := domainToMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/domainToMatcher().(d)
74 if err != nil {
75 return nil, err
76 }
77 g.Addscip-go gomod v2ray.com/core . `v2ray.com/core/common/strmatcher`/MatcherGroup#Add().(m)
78 }
79
80 return &DomainMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/DomainMatcher#{
81 matchersscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/DomainMatcher#matchers.: g,
82 }, nil
83 }
84
85 func (m *DomainMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/DomainMatcher#) ApplyDomainscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/DomainMatcher#ApplyDomain().(domain string) bool {
86 return len(m.matchersscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/DomainMatcher#matchers..Matchscip-go gomod v2ray.com/core . `v2ray.com/core/common/strmatcher`/IndexMatcher#Match.(domain)) > 0
87 }
88
89 // Apply implements Condition.
90 func (m *DomainMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/DomainMatcher#) Applyscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/DomainMatcher#Apply().(ctx routingscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/.Contextscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/Context#) bool {
91 domain := ctx.GetTargetDomainscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/Context#GetTargetDomain.()
92 if len(domain) == 0 {
93 return false
94 }
95 return m.ApplyDomainscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/DomainMatcher#ApplyDomain().(domain)
96 }
97
98 type MultiGeoIPMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/MultiGeoIPMatcher# struct {
99 matchersscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/MultiGeoIPMatcher#matchers. []*GeoIPMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/GeoIPMatcher#
100 onSourcescip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/MultiGeoIPMatcher#onSource. bool
101 }
102
103 func NewMultiGeoIPMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/NewMultiGeoIPMatcher().(geoips []*GeoIPscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/GeoIP#, onSource bool) (*MultiGeoIPMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/MultiGeoIPMatcher#, error) {
104 var matchers []*GeoIPMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/GeoIPMatcher#
105 for _, geoip := range geoips {
106 matcher, err := globalGeoIPContainerscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/globalGeoIPContainer..Addscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/GeoIPMatcherContainer#Add().(geoip)
107 if err != nil {
108 return nil, err
109 }
110 matchers = append(matchers, matcher)
111 }
112
113 matcher := &MultiGeoIPMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/MultiGeoIPMatcher#{
114 matchersscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/MultiGeoIPMatcher#matchers.: matchers,
115 onSourcescip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/MultiGeoIPMatcher#onSource.: onSource,
116 }
117
118 return matcher, nil
119 }
120
121 // Apply implements Condition.
122 func (m *MultiGeoIPMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/MultiGeoIPMatcher#) Applyscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/MultiGeoIPMatcher#Apply().(ctx routingscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/.Contextscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/Context#) bool {
123 var ips []netscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/.IPscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/IP#
124 if m.onSourcescip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/MultiGeoIPMatcher#onSource. {
125 ips = ctx.GetSourceIPsscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/Context#GetSourceIPs.()
126 } else {
127 ips = ctx.GetTargetIPsscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/Context#GetTargetIPs.()
128 }
129 for _, ip := range ips {
130 for _, matcher := range m.matchersscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/MultiGeoIPMatcher#matchers. {
131 if matcher.Matchscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/GeoIPMatcher#Match().(ip) {
132 return true
133 }
134 }
135 }
136 return false
137 }
138
139 type PortMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/PortMatcher# struct {
140 portscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/PortMatcher#port. netscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/.MemoryPortListscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/MemoryPortList#
141 onSourcescip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/PortMatcher#onSource. bool
142 }
143
144 // NewPortMatcher create a new port matcher that can match source or destination port
145 func NewPortMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/NewPortMatcher().(list *netscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/.PortListscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/PortList#, onSource bool) *PortMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/PortMatcher# {
146 return &PortMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/PortMatcher#{
147 portscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/PortMatcher#port.: netscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/.PortListFromProtoscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/PortListFromProto().(list),
148 onSourcescip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/PortMatcher#onSource.: onSource,
149 }
150 }
151
152 // Apply implements Condition.
153 func (v *PortMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/PortMatcher#) Applyscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/PortMatcher#Apply().(ctx routingscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/.Contextscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/Context#) bool {
154 if v.onSourcescip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/PortMatcher#onSource. {
155 return v.portscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/PortMatcher#port..Containsscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/MemoryPortList#Contains().(ctx.GetSourcePortscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/Context#GetSourcePort.())
156 }
157 return v.portscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/PortMatcher#port..Containsscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/MemoryPortList#Contains().(ctx.GetTargetPortscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/Context#GetTargetPort.())
158 }
159
160 type NetworkMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/NetworkMatcher# struct {
161 listscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/NetworkMatcher#list. [8]bool
162 }
163
164 func NewNetworkMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/NewNetworkMatcher().(network []netscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/.Networkscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Network#) NetworkMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/NetworkMatcher# {
165 var matcher NetworkMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/NetworkMatcher#
166 for _, n := range network {
167 matcher.listscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/NetworkMatcher#list.[int(n)] = true
168 }
169 return matcher
170 }
171
172 // Apply implements Condition.
173 func (v NetworkMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/NetworkMatcher#) Applyscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/NetworkMatcher#Apply().(ctx routingscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/.Contextscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/Context#) bool {
174 return v.listscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/NetworkMatcher#list.[int(ctx.GetNetworkscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/Context#GetNetwork.())]
175 }
176
177 type UserMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/UserMatcher# struct {
178 userscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/UserMatcher#user. []string
179 }
180
181 func NewUserMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/NewUserMatcher().(users []string) *UserMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/UserMatcher# {
182 usersCopy := make([]string, 0, len(users))
183 for _, user := range users {
184 if len(user) > 0 {
185 usersCopy = append(usersCopy, user)
186 }
187 }
188 return &UserMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/UserMatcher#{
189 userscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/UserMatcher#user.: usersCopy,
190 }
191 }
192
193 // Apply implements Condition.
194 func (v *UserMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/UserMatcher#) Applyscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/UserMatcher#Apply().(ctx routingscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/.Contextscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/Context#) bool {
195 user := ctx.GetUserscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/Context#GetUser.()
196 if len(user) == 0 {
197 return false
198 }
199 for _, u := range v.userscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/UserMatcher#user. {
200 if u == user {
201 return true
202 }
203 }
204 return false
205 }
206
207 type InboundTagMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/InboundTagMatcher# struct {
208 tagsscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/InboundTagMatcher#tags. []string
209 }
210
211 func NewInboundTagMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/NewInboundTagMatcher().(tags []string) *InboundTagMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/InboundTagMatcher# {
212 tagsCopy := make([]string, 0, len(tags))
213 for _, tag := range tags {
214 if len(tag) > 0 {
215 tagsCopy = append(tagsCopy, tag)
216 }
217 }
218 return &InboundTagMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/InboundTagMatcher#{
219 tagsscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/InboundTagMatcher#tags.: tagsCopy,
220 }
221 }
222
223 // Apply implements Condition.
224 func (v *InboundTagMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/InboundTagMatcher#) Applyscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/InboundTagMatcher#Apply().(ctx routingscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/.Contextscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/Context#) bool {
225 tag := ctx.GetInboundTagscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/Context#GetInboundTag.()
226 if len(tag) == 0 {
227 return false
228 }
229 for _, t := range v.tagsscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/InboundTagMatcher#tags. {
230 if t == tag {
231 return true
232 }
233 }
234 return false
235 }
236
237 type ProtocolMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/ProtocolMatcher# struct {
238 protocolsscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/ProtocolMatcher#protocols. []string
239 }
240
241 func NewProtocolMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/NewProtocolMatcher().(protocols []string) *ProtocolMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/ProtocolMatcher# {
242 pCopy := make([]string, 0, len(protocols))
243
244 for _, p := range protocols {
245 if len(p) > 0 {
246 pCopy = append(pCopy, p)
247 }
248 }
249
250 return &ProtocolMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/ProtocolMatcher#{
251 protocolsscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/ProtocolMatcher#protocols.: pCopy,
252 }
253 }
254
255 // Apply implements Condition.
256 func (m *ProtocolMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/ProtocolMatcher#) Applyscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/ProtocolMatcher#Apply().(ctx routingscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/.Contextscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/Context#) bool {
257 protocol := ctx.GetProtocolscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/Context#GetProtocol.()
258 if len(protocol) == 0 {
259 return false
260 }
261 for _, p := range m.protocolsscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/ProtocolMatcher#protocols. {
262 if stringsscip-go gomod github.com/golang/go/src go1.15 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.15 strings/HasPrefix().(protocol, p) {
263 return true
264 }
265 }
266 return false
267 }
268
269 type AttributeMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/AttributeMatcher# struct {
270 programscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/AttributeMatcher#program. *starlarkscip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/starlark`/.Programscip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/starlark`/Program#
271 }
272
273 func NewAttributeMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/NewAttributeMatcher().(code string) (*AttributeMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/AttributeMatcher#, error) {
274 starFile, err := syntaxscip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/syntax`/.Parsescip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/syntax`/Parse().("attr.star", "satisfied=("+code+")", 0)
275 if err != nil {
276 return nil, newErrorscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/newError().("attr rule").Basescip-go gomod v2ray.com/core . `v2ray.com/core/common/errors`/Error#Base().(err)
277 }
278 p, err := starlarkscip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/starlark`/.FileProgramscip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/starlark`/FileProgram().(starFile, func(name string) bool {
279 return name == "attrs"
280 })
281 if err != nil {
282 return nil, err
283 }
284 return &AttributeMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/AttributeMatcher#{
285 programscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/AttributeMatcher#program.: p,
286 }, nil
287 }
288
289 // Match implements attributes matching.
290 func (m *AttributeMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/AttributeMatcher#) Matchscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/AttributeMatcher#Match().(attrs map[string]string) bool {
291 attrsDict := new(starlarkscip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/starlark`/.Dictscip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/starlark`/Dict#)
292 for key, value := range attrs {
293 attrsDict.SetKeyscip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/starlark`/Dict#SetKey().(starlarkscip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/starlark`/.Stringscip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/starlark`/String#(key), starlarkscip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/starlark`/.Stringscip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/starlark`/String#(value))
294 }
295
296 predefined := make(starlarkscip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/starlark`/.StringDictscip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/starlark`/StringDict#)
297 predefined["attrs"] = attrsDict
298
299 thread := &starlarkscip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/starlark`/.Threadscip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/starlark`/Thread#{
300 Namescip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/starlark`/Thread#Name.: "matcher",
301 }
302 results, err := m.programscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/AttributeMatcher#program..Initscip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/starlark`/Program#Init().(thread, predefined)
303 if err != nil {
304 newErrorscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/newError().("attr matcher").Basescip-go gomod v2ray.com/core . `v2ray.com/core/common/errors`/Error#Base().(err).WriteToLogscip-go gomod v2ray.com/core . `v2ray.com/core/common/errors`/Error#WriteToLog().()
305 }
306 satisfied := results["satisfied"]
307 return satisfied != nil && bool(satisfied.Truthscip-go gomod go.starlark.net e81fc95f7bd5 `go.starlark.net/starlark`/Value#Truth().())
308 }
309
310 // Apply implements Condition.
311 func (m *AttributeMatcherscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/AttributeMatcher#) Applyscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/AttributeMatcher#Apply().(ctx routingscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/.Contextscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/Context#) bool {
312 attributes := ctx.GetAttributesscip-go gomod v2ray.com/core . `v2ray.com/core/features/routing`/Context#GetAttributes.()
313 if attributes == nil {
314 return false
315 }
316 return m.Matchscip-go gomod v2ray.com/core . `v2ray.com/core/app/router`/AttributeMatcher#Match().(attributes)
317 }