From b37755d111eb1128e32f0c62f7fb7b069baaec33 Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Sat, 19 Jun 2021 13:41:32 +0100 Subject: [PATCH] isolate dns settings synthesis --- infra/conf/{ => synthetic/dns}/dns.go | 4 +++- infra/conf/{ => synthetic/dns}/dns_test.go | 9 +++++---- infra/conf/v2ray.go | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) rename infra/conf/{ => synthetic/dns}/dns.go (99%) rename infra/conf/{ => synthetic/dns}/dns_test.go (95%) diff --git a/infra/conf/dns.go b/infra/conf/synthetic/dns/dns.go similarity index 99% rename from infra/conf/dns.go rename to infra/conf/synthetic/dns/dns.go index ef4e19ebc..4e25970ee 100644 --- a/infra/conf/dns.go +++ b/infra/conf/synthetic/dns/dns.go @@ -1,4 +1,6 @@ -package conf +package dns + +//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen import ( "context" diff --git a/infra/conf/dns_test.go b/infra/conf/synthetic/dns/dns_test.go similarity index 95% rename from infra/conf/dns_test.go rename to infra/conf/synthetic/dns/dns_test.go index 7c92f8470..2e62216c4 100644 --- a/infra/conf/dns_test.go +++ b/infra/conf/synthetic/dns/dns_test.go @@ -1,4 +1,4 @@ -package conf_test +package dns_test import ( "encoding/json" @@ -15,8 +15,9 @@ import ( "github.com/v2fly/v2ray-core/v4/common" "github.com/v2fly/v2ray-core/v4/common/net" "github.com/v2fly/v2ray-core/v4/common/platform/filesystem" - "github.com/v2fly/v2ray-core/v4/infra/conf" _ "github.com/v2fly/v2ray-core/v4/infra/conf/geodata/standard" + + dns2 "github.com/v2fly/v2ray-core/v4/infra/conf/synthetic/dns" ) func init() { @@ -28,7 +29,7 @@ func init() { wd, err := os.Getwd() common.Must(err) - tempPath := filepath.Join(wd, "..", "..", "testing", "temp") + tempPath := filepath.Join(wd, "..", "..", "..", "..", "testing", "temp") geoipPath := filepath.Join(tempPath, "geoip.dat") geositePath := filepath.Join(tempPath, "geosite.dat") @@ -51,7 +52,7 @@ func init() { func TestDNSConfigParsing(t *testing.T) { parserCreator := func() func(string) (protoiface.MessageV1, error) { return func(s string) (protoiface.MessageV1, error) { - config := new(conf.DNSConfig) + config := new(dns2.DNSConfig) if err := json.Unmarshal([]byte(s), config); err != nil { return nil, err } diff --git a/infra/conf/v2ray.go b/infra/conf/v2ray.go index 4756710c0..80569c0db 100644 --- a/infra/conf/v2ray.go +++ b/infra/conf/v2ray.go @@ -3,6 +3,7 @@ package conf import ( "encoding/json" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/loader" + "github.com/v2fly/v2ray-core/v4/infra/conf/synthetic/dns" "github.com/v2fly/v2ray-core/v4/infra/conf/synthetic/log" "github.com/v2fly/v2ray-core/v4/infra/conf/synthetic/router" "strings" @@ -343,7 +344,7 @@ type Config struct { LogConfig *log.LogConfig `json:"log"` RouterConfig *router.RouterConfig `json:"routing"` - DNSConfig *DNSConfig `json:"dns"` + DNSConfig *dns.DNSConfig `json:"dns"` InboundConfigs []InboundDetourConfig `json:"inbounds"` OutboundConfigs []OutboundDetourConfig `json:"outbounds"` Transport *TransportConfig `json:"transport"`