mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
DNS: refine code (#1193)
This commit is contained in:
parent
73470e8dd8
commit
a783cd5f08
@ -32,7 +32,7 @@ type DNS struct {
|
|||||||
clients []*Client
|
clients []*Client
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
domainMatcher strmatcher.IndexMatcher
|
domainMatcher strmatcher.IndexMatcher
|
||||||
matcherInfos []DomainMatcherInfo
|
matcherInfos []*DomainMatcherInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
// DomainMatcherInfo contains information attached to index returned by Server.domainMatcher
|
// DomainMatcherInfo contains information attached to index returned by Server.domainMatcher
|
||||||
@ -92,7 +92,7 @@ func New(ctx context.Context, config *Config) (*DNS, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MatcherInfos is ensured to cover the maximum index domainMatcher could return, where matcher's index starts from 1
|
// MatcherInfos is ensured to cover the maximum index domainMatcher could return, where matcher's index starts from 1
|
||||||
matcherInfos := make([]DomainMatcherInfo, domainRuleCount+1)
|
matcherInfos := make([]*DomainMatcherInfo, domainRuleCount+1)
|
||||||
domainMatcher := &strmatcher.MatcherGroup{}
|
domainMatcher := &strmatcher.MatcherGroup{}
|
||||||
geoipContainer := router.GeoIPMatcherContainer{}
|
geoipContainer := router.GeoIPMatcherContainer{}
|
||||||
|
|
||||||
@ -107,9 +107,9 @@ func New(ctx context.Context, config *Config) (*DNS, error) {
|
|||||||
|
|
||||||
for _, ns := range config.NameServer {
|
for _, ns := range config.NameServer {
|
||||||
clientIdx := len(clients)
|
clientIdx := len(clients)
|
||||||
updateDomain := func(domainRule strmatcher.Matcher, originalRuleIdx int, matcherInfos []DomainMatcherInfo) error {
|
updateDomain := func(domainRule strmatcher.Matcher, originalRuleIdx int, matcherInfos []*DomainMatcherInfo) error {
|
||||||
midx := domainMatcher.Add(domainRule)
|
midx := domainMatcher.Add(domainRule)
|
||||||
matcherInfos[midx] = DomainMatcherInfo{
|
matcherInfos[midx] = &DomainMatcherInfo{
|
||||||
clientIdx: uint16(clientIdx),
|
clientIdx: uint16(clientIdx),
|
||||||
domainRuleIdx: uint16(originalRuleIdx),
|
domainRuleIdx: uint16(originalRuleIdx),
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ func NewServer(dest net.Destination, dispatcher routing.Dispatcher) (Server, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewClient creates a DNS client managing a name server with client IP, domain rules and expected IPs.
|
// NewClient creates a DNS client managing a name server with client IP, domain rules and expected IPs.
|
||||||
func NewClient(ctx context.Context, ns *NameServer, clientIP net.IP, container router.GeoIPMatcherContainer, matcherInfos *[]DomainMatcherInfo, updateDomainRule func(strmatcher.Matcher, int, []DomainMatcherInfo) error) (*Client, error) {
|
func NewClient(ctx context.Context, ns *NameServer, clientIP net.IP, container router.GeoIPMatcherContainer, matcherInfos *[]*DomainMatcherInfo, updateDomainRule func(strmatcher.Matcher, int, []*DomainMatcherInfo) error) (*Client, error) {
|
||||||
client := &Client{}
|
client := &Client{}
|
||||||
|
|
||||||
err := core.RequireFeatures(ctx, func(dispatcher routing.Dispatcher) error {
|
err := core.RequireFeatures(ctx, func(dispatcher routing.Dispatcher) error {
|
||||||
@ -92,7 +92,7 @@ func NewClient(ctx context.Context, ns *NameServer, clientIP net.IP, container r
|
|||||||
// https://github.com/v2fly/v2ray-core/issues/529
|
// https://github.com/v2fly/v2ray-core/issues/529
|
||||||
// https://github.com/v2fly/v2ray-core/issues/719
|
// https://github.com/v2fly/v2ray-core/issues/719
|
||||||
for i := 0; i < len(localTLDsAndDotlessDomains); i++ {
|
for i := 0; i < len(localTLDsAndDotlessDomains); i++ {
|
||||||
*matcherInfos = append(*matcherInfos, DomainMatcherInfo{
|
*matcherInfos = append(*matcherInfos, &DomainMatcherInfo{
|
||||||
clientIdx: uint16(0),
|
clientIdx: uint16(0),
|
||||||
domainRuleIdx: uint16(0),
|
domainRuleIdx: uint16(0),
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user