1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 17:46:58 -05:00

added build context to dns

This commit is contained in:
Shelikhoo 2021-09-04 21:54:21 +01:00
parent ae46fb7b28
commit 45dae48d21
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316
2 changed files with 24 additions and 12 deletions

View File

@ -70,6 +70,7 @@ func toDomainMatchingType(t router.Domain_Type) dns.DomainMatchingType {
panic("unknown domain type") panic("unknown domain type")
} }
} }
func (c *NameServerConfig) BuildV5(ctx context.Context) (*dns.NameServer, error) { func (c *NameServerConfig) BuildV5(ctx context.Context) (*dns.NameServer, error) {
c.cfgctx = ctx c.cfgctx = ctx
return c.Build() return c.Build()
@ -146,6 +147,8 @@ type DNSConfig struct {
QueryStrategy string `json:"queryStrategy"` QueryStrategy string `json:"queryStrategy"`
DisableCache bool `json:"disableCache"` DisableCache bool `json:"disableCache"`
DisableFallback bool `json:"disableFallback"` DisableFallback bool `json:"disableFallback"`
cfgctx context.Context
} }
type HostAddress struct { type HostAddress struct {
@ -194,21 +197,30 @@ func getHostMapping(ha *HostAddress) *dns.Config_HostMapping {
} }
} }
func (c *DNSConfig) BuildV5(ctx context.Context) (*dns.Config, error) {
c.cfgctx = ctx
return c.Build()
}
// Build implements Buildable // Build implements Buildable
func (c *DNSConfig) Build() (*dns.Config, error) { func (c *DNSConfig) Build() (*dns.Config, error) {
cfgctx := cfgcommon.NewConfigureLoadingContext(context.Background())
geoloadername := platform.NewEnvFlag("v2ray.conf.geoloader").GetValue(func() string { if c.cfgctx == nil {
return "standard" c.cfgctx = cfgcommon.NewConfigureLoadingContext(context.Background())
})
geoloadername := platform.NewEnvFlag("v2ray.conf.geoloader").GetValue(func() string {
return "standard"
})
if loader, err := geodata.GetGeoDataLoader(geoloadername); err == nil {
cfgcommon.SetGeoDataLoader(c.cfgctx, loader)
} else {
return nil, newError("unable to create geo data loader ").Base(err)
}
if loader, err := geodata.GetGeoDataLoader(geoloadername); err == nil {
cfgcommon.SetGeoDataLoader(cfgctx, loader)
} else {
return nil, newError("unable to create geo data loader ").Base(err)
} }
cfgEnv := cfgcommon.GetConfigureLoadingEnvironment(cfgctx) cfgEnv := cfgcommon.GetConfigureLoadingEnvironment(c.cfgctx)
geoLoader := cfgEnv.GetGeoLoader() geoLoader := cfgEnv.GetGeoLoader()
config := &dns.Config{ config := &dns.Config{
@ -235,7 +247,7 @@ func (c *DNSConfig) Build() (*dns.Config, error) {
} }
for _, server := range c.Servers { for _, server := range c.Servers {
server.cfgctx = cfgctx server.cfgctx = c.cfgctx
ns, err := server.Build() ns, err := server.Build()
if err != nil { if err != nil {
return nil, newError("failed to build nameserver").Base(err) return nil, newError("failed to build nameserver").Base(err)

View File

@ -35,7 +35,7 @@ func (c RootConfig) BuildV5(ctx context.Context) (proto.Message, error) {
config.App = append([]*anypb.Any{logConfMsg}, config.App...) config.App = append([]*anypb.Any{logConfMsg}, config.App...)
if c.RouterConfig != nil { if c.RouterConfig != nil {
routerConfig, err := c.RouterConfig.Build() routerConfig, err := c.RouterConfig.BuildV5(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -43,7 +43,7 @@ func (c RootConfig) BuildV5(ctx context.Context) (proto.Message, error) {
} }
if c.DNSConfig != nil { if c.DNSConfig != nil {
dnsApp, err := c.DNSConfig.Build() dnsApp, err := c.DNSConfig.BuildV5(ctx)
if err != nil { if err != nil {
return nil, newError("failed to parse DNS config").Base(err) return nil, newError("failed to parse DNS config").Base(err)
} }