Skip to content

Commit 8416e52

Browse files
Meo597Exclude0122
authored andcommitted
Xray-core: Refactor geodata (XTLS#5814)
XTLS#4422 (comment) Breaking changes XTLS#5569 Reverts XTLS#5505 Closes XTLS#643
1 parent fbb80bb commit 8416e52

73 files changed

Lines changed: 5420 additions & 4443 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/dns/config.go

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,24 @@ package dns
22

33
import (
44
"github.com/xtls/xray-core/common/errors"
5+
"github.com/xtls/xray-core/common/geodata"
56
"github.com/xtls/xray-core/common/net"
6-
"github.com/xtls/xray-core/common/strmatcher"
77
"github.com/xtls/xray-core/common/uuid"
88
)
99

10-
var typeMap = map[DomainMatchingType]strmatcher.Type{
11-
DomainMatchingType_Full: strmatcher.Full,
12-
DomainMatchingType_Subdomain: strmatcher.Domain,
13-
DomainMatchingType_Keyword: strmatcher.Substr,
14-
DomainMatchingType_Regex: strmatcher.Regex,
15-
}
16-
1710
// References:
1811
// https://www.iana.org/assignments/special-use-domain-names/special-use-domain-names.xhtml
1912
// https://unix.stackexchange.com/questions/92441/whats-the-difference-between-local-home-and-lan
20-
var localTLDsAndDotlessDomains = []*NameServer_PriorityDomain{
21-
{Type: DomainMatchingType_Regex, Domain: "^[^.]+$"}, // This will only match domains without any dot
22-
{Type: DomainMatchingType_Subdomain, Domain: "local"},
23-
{Type: DomainMatchingType_Subdomain, Domain: "localdomain"},
24-
{Type: DomainMatchingType_Subdomain, Domain: "localhost"},
25-
{Type: DomainMatchingType_Subdomain, Domain: "lan"},
26-
{Type: DomainMatchingType_Subdomain, Domain: "home.arpa"},
27-
{Type: DomainMatchingType_Subdomain, Domain: "example"},
28-
{Type: DomainMatchingType_Subdomain, Domain: "invalid"},
29-
{Type: DomainMatchingType_Subdomain, Domain: "test"},
30-
}
31-
32-
var localTLDsAndDotlessDomainsRule = &NameServer_OriginalRule{
33-
Rule: "geosite:private",
34-
Size: uint32(len(localTLDsAndDotlessDomains)),
35-
}
36-
37-
func toStrMatcher(t DomainMatchingType, domain string) (strmatcher.Matcher, error) {
38-
strMType, f := typeMap[t]
39-
if !f {
40-
return nil, errors.New("unknown mapping type", t).AtWarning()
41-
}
42-
matcher, err := strMType.New(domain)
43-
if err != nil {
44-
return nil, errors.New("failed to create str matcher").Base(err)
45-
}
46-
return matcher, nil
13+
var localTLDsAndDotlessDomainsRules = []*geodata.DomainRule{
14+
{Value: &geodata.DomainRule_Custom{Custom: &geodata.Domain{Type: geodata.Domain_Regex, Value: "^[^.]+$"}}}, // This will only match domains without any dot
15+
{Value: &geodata.DomainRule_Custom{Custom: &geodata.Domain{Type: geodata.Domain_Domain, Value: "local"}}},
16+
{Value: &geodata.DomainRule_Custom{Custom: &geodata.Domain{Type: geodata.Domain_Domain, Value: "localdomain"}}},
17+
{Value: &geodata.DomainRule_Custom{Custom: &geodata.Domain{Type: geodata.Domain_Domain, Value: "localhost"}}},
18+
{Value: &geodata.DomainRule_Custom{Custom: &geodata.Domain{Type: geodata.Domain_Domain, Value: "lan"}}},
19+
{Value: &geodata.DomainRule_Custom{Custom: &geodata.Domain{Type: geodata.Domain_Domain, Value: "home.arpa"}}},
20+
{Value: &geodata.DomainRule_Custom{Custom: &geodata.Domain{Type: geodata.Domain_Domain, Value: "example"}}},
21+
{Value: &geodata.DomainRule_Custom{Custom: &geodata.Domain{Type: geodata.Domain_Domain, Value: "invalid"}}},
22+
{Value: &geodata.DomainRule_Custom{Custom: &geodata.Domain{Type: geodata.Domain_Domain, Value: "test"}}},
4723
}
4824

4925
func toNetIP(addrs []net.Address) ([]net.IP, error) {

0 commit comments

Comments
 (0)