Skip to content

Commit

Permalink
Add GeoDomain to DNS Nameserver in JSONv5
Browse files Browse the repository at this point in the history
  • Loading branch information
karelrooted committed Nov 29, 2023
1 parent 77978bc commit 816f26b
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 50 deletions.
121 changes: 71 additions & 50 deletions app/dns/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/dns/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,5 @@ message SimplifiedNameServer {
optional QueryStrategy query_strategy = 8;
optional CacheStrategy cache_strategy = 9;
optional FallbackStrategy fallback_strategy = 10;
repeated v2ray.core.app.router.routercommon.GeoSite geo_domain = 68001;
}
27 changes: 27 additions & 0 deletions app/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
core "github.com/v2fly/v2ray-core/v5"
"github.com/v2fly/v2ray-core/v5/app/dns/fakedns"
"github.com/v2fly/v2ray-core/v5/app/router"
"github.com/v2fly/v2ray-core/v5/app/router/routercommon"
"github.com/v2fly/v2ray-core/v5/common"
"github.com/v2fly/v2ray-core/v5/common/errors"
"github.com/v2fly/v2ray-core/v5/common/net"
Expand Down Expand Up @@ -389,6 +390,13 @@ func (s *DNS) formatClientNames(clientIdxs []int, option dns.IPOption) []string
return clientNames
}

var matcherTypeMap = map[routercommon.Domain_Type]DomainMatchingType{
routercommon.Domain_Plain: DomainMatchingType_Keyword,
routercommon.Domain_Regex: DomainMatchingType_Regex,
routercommon.Domain_RootDomain: DomainMatchingType_Subdomain,
routercommon.Domain_Full: DomainMatchingType_Full,
}

func init() {
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
return New(ctx, config.(*Config))
Expand Down Expand Up @@ -427,6 +435,25 @@ func init() {
}
}
}
for _, geo := range v.GeoDomain {
if geo.Code != "" {
filepath := "geosite.dat"
if geo.FilePath != "" {
filepath = geo.FilePath
}
var err error
geo.Domain, err = geoLoader.LoadGeoSiteWithAttr(filepath, geo.Code)
if err != nil {
return nil, newError("unable to load geodomain").Base(err)
}
}
for _, domain := range geo.Domain {
v.PrioritizedDomain = append(v.PrioritizedDomain, &SimplifiedNameServer_PriorityDomain{
Type: matcherTypeMap[domain.Type],
Domain: domain.Value,
})
}
}
}

var nameservers []*NameServer
Expand Down

0 comments on commit 816f26b

Please sign in to comment.