1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-14 16:25:57 -05:00

register dns

This commit is contained in:
Shelikhoo 2021-09-07 08:00:17 +01:00
parent 9bb67daa69
commit aa17eacc8d
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316

View File

@ -9,6 +9,9 @@ package dns
import (
"context"
"fmt"
"github.com/v2fly/v2ray-core/v4/common/platform"
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon"
"github.com/v2fly/v2ray-core/v4/infra/conf/geodata"
"strings"
"sync"
@ -309,4 +312,50 @@ func init() {
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
return New(ctx, config.(*Config))
}))
common.Must(common.RegisterConfig((*SimplifiedConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
ctx = 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(ctx, loader)
} else {
return nil, newError("unable to create geo data loader ").Base(err)
}
cfgEnv := cfgcommon.GetConfigureLoadingEnvironment(ctx)
geoLoader := cfgEnv.GetGeoLoader()
simplifiedConfig := config.(*SimplifiedConfig)
for _, v := range simplifiedConfig.NameServer {
for _, geo := range v.Geoip {
if geo.Code != "" {
filepath := "geoip.dat"
if geo.FilePath != "" {
filepath = geo.FilePath
}
var err error
geo.Cidr, err = geoLoader.LoadIP(filepath, geo.Code)
if err != nil {
return nil, newError("unable to load geoip").Base(err)
}
}
}
}
fullConfig := &Config{
NameServer: simplifiedConfig.NameServer,
ClientIp: simplifiedConfig.ClientIp,
StaticHosts: simplifiedConfig.StaticHosts,
Tag: simplifiedConfig.Tag,
DisableCache: simplifiedConfig.DisableCache,
QueryStrategy: simplifiedConfig.QueryStrategy,
DisableFallback: simplifiedConfig.DisableFallback,
}
return common.CreateObject(ctx, fullConfig)
}))
}