mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 15:36:41 -05:00
added buildV5 interface to dns and router
This commit is contained in:
parent
40d75fab73
commit
62f71c80ca
@ -70,6 +70,10 @@ 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) {
|
||||||
|
c.cfgctx = ctx
|
||||||
|
return c.Build()
|
||||||
|
}
|
||||||
|
|
||||||
func (c *NameServerConfig) Build() (*dns.NameServer, error) {
|
func (c *NameServerConfig) Build() (*dns.NameServer, error) {
|
||||||
cfgctx := c.cfgctx
|
cfgctx := c.cfgctx
|
||||||
|
@ -89,6 +89,8 @@ type RouterConfig struct {
|
|||||||
Balancers []*BalancingRule `json:"balancers"`
|
Balancers []*BalancingRule `json:"balancers"`
|
||||||
|
|
||||||
DomainMatcher string `json:"domainMatcher"`
|
DomainMatcher string `json:"domainMatcher"`
|
||||||
|
|
||||||
|
cfgctx context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RouterConfig) getDomainStrategy() router.Config_DomainStrategy {
|
func (c *RouterConfig) getDomainStrategy() router.Config_DomainStrategy {
|
||||||
@ -111,21 +113,28 @@ 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) {
|
func (c *RouterConfig) Build() (*router.Config, error) {
|
||||||
config := new(router.Config)
|
config := new(router.Config)
|
||||||
config.DomainStrategy = c.getDomainStrategy()
|
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 {
|
geoloadername := platform.NewEnvFlag("v2ray.conf.geoloader").GetValue(func() string {
|
||||||
return "standard"
|
return "standard"
|
||||||
})
|
})
|
||||||
|
|
||||||
if loader, err := geodata.GetGeoDataLoader(geoloadername); err == nil {
|
if loader, err := geodata.GetGeoDataLoader(geoloadername); err == nil {
|
||||||
cfgcommon.SetGeoDataLoader(cfgctx, loader)
|
cfgcommon.SetGeoDataLoader(c.cfgctx, loader)
|
||||||
} else {
|
} else {
|
||||||
return nil, newError("unable to create geo data loader ").Base(err)
|
return nil, newError("unable to create geo data loader ").Base(err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var rawRuleList []json.RawMessage
|
var rawRuleList []json.RawMessage
|
||||||
if c != nil {
|
if c != nil {
|
||||||
@ -137,7 +146,7 @@ func (c *RouterConfig) Build() (*router.Config, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, rawRule := range rawRuleList {
|
for _, rawRule := range rawRuleList {
|
||||||
rule, err := rule2.ParseRule(cfgctx, rawRule)
|
rule, err := rule2.ParseRule(c.cfgctx, rawRule)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user