1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 01:27:03 -05:00

added buildV5 interface to dns and router

This commit is contained in:
Shelikhoo 2021-09-04 21:44:10 +01:00
parent 40d75fab73
commit 62f71c80ca
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316
2 changed files with 22 additions and 9 deletions

View File

@ -70,6 +70,10 @@ func toDomainMatchingType(t router.Domain_Type) dns.DomainMatchingType {
panic("unknown domain type")
}
}
func (c *NameServerConfig) BuildV5(ctx context.Context) (*dns.NameServer, error) {
c.cfgctx = ctx
return c.Build()
}
func (c *NameServerConfig) Build() (*dns.NameServer, error) {
cfgctx := c.cfgctx

View File

@ -89,6 +89,8 @@ type RouterConfig struct {
Balancers []*BalancingRule `json:"balancers"`
DomainMatcher string `json:"domainMatcher"`
cfgctx context.Context
}
func (c *RouterConfig) getDomainStrategy() router.Config_DomainStrategy {
@ -111,20 +113,27 @@ func (c *RouterConfig) getDomainStrategy() router.Config_DomainStrategy {
}
}
func (c *RouterConfig) BuildV5(ctx context.Context) (*router.Config, error) {
c.cfgctx = ctx
return c.Build()
}
func (c *RouterConfig) Build() (*router.Config, error) {
config := new(router.Config)
config.DomainStrategy = c.getDomainStrategy()
cfgctx := cfgcommon.NewConfigureLoadingContext(context.Background())
if c.cfgctx == nil {
c.cfgctx = cfgcommon.NewConfigureLoadingContext(context.Background())
geoloadername := platform.NewEnvFlag("v2ray.conf.geoloader").GetValue(func() string {
return "standard"
})
geoloadername := platform.NewEnvFlag("v2ray.conf.geoloader").GetValue(func() string {
return "standard"
})
if loader, err := geodata.GetGeoDataLoader(geoloadername); err == nil {
cfgcommon.SetGeoDataLoader(cfgctx, loader)
} else {
return nil, newError("unable to create geo data loader ").Base(err)
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)
}
}
var rawRuleList []json.RawMessage
@ -137,7 +146,7 @@ func (c *RouterConfig) Build() (*router.Config, error) {
}
for _, rawRule := range rawRuleList {
rule, err := rule2.ParseRule(cfgctx, rawRule)
rule, err := rule2.ParseRule(c.cfgctx, rawRule)
if err != nil {
return nil, err
}