diff --git a/infra/conf/synthetic/dns/dns.go b/infra/conf/synthetic/dns/dns.go index 1c73eef31..dc5e004a6 100644 --- a/infra/conf/synthetic/dns/dns.go +++ b/infra/conf/synthetic/dns/dns.go @@ -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 diff --git a/infra/conf/synthetic/router/router.go b/infra/conf/synthetic/router/router.go index 7d2fff1f0..2a134e9a4 100644 --- a/infra/conf/synthetic/router/router.go +++ b/infra/conf/synthetic/router/router.go @@ -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 }