@@ -10,7 +10,6 @@ import (
1010 "github.com/xtls/xray-core/common/platform/filesystem"
1111 "github.com/xtls/xray-core/features/outbound"
1212 "github.com/xtls/xray-core/features/routing"
13- "google.golang.org/protobuf/proto"
1413)
1514
1615type Rule struct {
@@ -109,16 +108,6 @@ func (rr *RoutingRule) BuildCondition(domainMatcherPath string) (Condition, erro
109108 if len (rr .Domain ) > 0 {
110109 var matcher * DomainMatcher
111110 var err error
112-
113- domains := rr .Domain
114- if runtime .GOOS != "windows" && runtime .GOOS != "wasm" && domainMatcherPath == "" {
115- var err error
116- domains , err = GetDomainList (rr .Domain )
117- if err != nil {
118- return nil , errors .New ("failed to build domains from mmap" ).Base (err )
119- }
120- }
121-
122111 if domainMatcherPath != "" {
123112 matcher , err = GetDomainMathcerWithRuleTag (domainMatcherPath , rr .RuleTag )
124113 if err != nil {
@@ -196,89 +185,14 @@ func (br *BalancingRule) Build(ohm outbound.Manager, dispatcher routing.Dispatch
196185 }
197186}
198187
199- func GetGeoIPList (ips []* GeoIP ) ([]* GeoIP , error ) {
200- geoipList := []* GeoIP {}
201- for _ , ip := range ips {
202- if ip .CountryCode != "" {
203- val := strings .Split (ip .CountryCode , "_" )
204- fileName := "geoip.dat"
205- if len (val ) == 2 {
206- fileName = strings .ToLower (val [0 ])
207- }
208- bs , err := filesystem .ReadAsset (fileName )
209- if err != nil {
210- return nil , errors .New ("failed to load file: " , fileName ).Base (err )
211- }
212- bs = filesystem .Find (bs , []byte (ip .CountryCode ))
213-
214- var geoip GeoIP
215-
216- if err := proto .Unmarshal (bs , & geoip ); err != nil {
217- return nil , errors .New ("failed Unmarshal :" ).Base (err )
218- }
219- geoipList = append (geoipList , & geoip )
220-
221- } else {
222- geoipList = append (geoipList , ip )
223- }
224- }
225- return geoipList , nil
226-
227- }
228-
229- func GetDomainList (domains []* Domain ) ([]* Domain , error ) {
230- domainList := []* Domain {}
231- for _ , domain := range domains {
232- val := strings .Split (domain .Value , "_" )
233-
234- if len (val ) >= 2 {
235-
236- fileName := val [0 ]
237- code := val [1 ]
238-
239- bs , err := filesystem .ReadAsset (fileName )
240- if err != nil {
241- return nil , errors .New ("failed to load file: " , fileName ).Base (err )
242- }
243- bs = filesystem .Find (bs , []byte (code ))
244- var geosite GeoSite
245-
246- if err := proto .Unmarshal (bs , & geosite ); err != nil {
247- return nil , errors .New ("failed Unmarshal :" ).Base (err )
248- }
249-
250- // parse attr
251- if len (val ) == 3 {
252- siteWithAttr := strings .Split (val [2 ], "," )
253- attrs := ParseAttrs (siteWithAttr )
254-
255- if ! attrs .IsEmpty () {
256- filteredDomains := make ([]* Domain , 0 , len (domains ))
257- for _ , domain := range geosite .Domain {
258- if attrs .Match (domain ) {
259- filteredDomains = append (filteredDomains , domain )
260- }
261- }
262- geosite .Domain = filteredDomains
263- }
264-
265- }
266-
267- domainList = append (domainList , geosite .Domain ... )
268-
269- } else {
270- domainList = append (domainList , domain )
271- }
272- }
273- return domainList , nil
274- }
275-
276188func GetDomainMathcerWithRuleTag (domainMatcherPath string , ruleTag string ) (* DomainMatcher , error ) {
277- bs , err := filesystem .ReadFile (domainMatcherPath )
189+ f , err := filesystem .NewFileReader (domainMatcherPath )
278190 if err != nil {
279191 return nil , errors .New ("failed to load file: " , domainMatcherPath ).Base (err )
280192 }
281- g , err := LoadGeoSiteMatcher (bs , ruleTag )
193+ defer f .Close ()
194+
195+ g , err := LoadGeoSiteMatcher (f , ruleTag )
282196 if err != nil {
283197 return nil , errors .New ("failed to load file:" , domainMatcherPath ).Base (err )
284198 }
0 commit comments