From 39b3866774bf1626aed2f8fdf3967b0a2608a6c2 Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Sat, 19 Jun 2021 13:28:20 +0100 Subject: [PATCH] isolate router settings synthesis --- infra/conf/blackhole.go | 5 +-- infra/conf/blackhole_test.go | 7 ++-- infra/conf/{ => cfgcommon/loader}/loader.go | 4 ++- .../testassist/general.go} | 6 ++-- infra/conf/dns_proxy_test.go | 5 +-- infra/conf/dns_test.go | 3 +- infra/conf/dokodemo_test.go | 5 +-- infra/conf/duration.go | 33 ------------------- infra/conf/duration_test.go | 33 ------------------- infra/conf/freedom_test.go | 5 +-- infra/conf/http_test.go | 5 +-- infra/conf/observatory.go | 3 +- infra/conf/reverse_test.go | 7 ++-- infra/conf/shadowsocks_test.go | 5 +-- infra/conf/socks_test.go | 9 ++--- infra/conf/{ => synthetic/router}/router.go | 6 ++-- .../{ => synthetic/router}/router_strategy.go | 26 ++++++++------- .../{ => synthetic/router}/router_test.go | 13 +++++--- infra/conf/transport_internet.go | 5 +-- infra/conf/transport_test.go | 5 +-- infra/conf/v2ray.go | 8 +++-- infra/conf/v2ray_test.go | 3 +- infra/conf/vless_test.go | 9 ++--- infra/conf/vmess_test.go | 9 ++--- 24 files changed, 91 insertions(+), 128 deletions(-) rename infra/conf/{ => cfgcommon/loader}/loader.go (95%) rename infra/conf/{general_test.go => cfgcommon/testassist/general.go} (84%) delete mode 100644 infra/conf/duration.go delete mode 100644 infra/conf/duration_test.go rename infra/conf/{ => synthetic/router}/router.go (97%) rename infra/conf/{ => synthetic/router}/router_strategy.go (74%) rename infra/conf/{ => synthetic/router}/router_test.go (94%) diff --git a/infra/conf/blackhole.go b/infra/conf/blackhole.go index 3b4380ace..019681d6a 100644 --- a/infra/conf/blackhole.go +++ b/infra/conf/blackhole.go @@ -3,6 +3,7 @@ package conf import ( "encoding/json" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/loader" "github.com/golang/protobuf/proto" @@ -43,8 +44,8 @@ func (v *BlackholeConfig) Build() (proto.Message, error) { return config, nil } -var configLoader = NewJSONConfigLoader( - ConfigCreatorCache{ +var configLoader = loader.NewJSONConfigLoader( + loader.ConfigCreatorCache{ "none": func() interface{} { return new(NoneResponse) }, "http": func() interface{} { return new(HTTPResponse) }, }, diff --git a/infra/conf/blackhole_test.go b/infra/conf/blackhole_test.go index 56583071a..ebc30743f 100644 --- a/infra/conf/blackhole_test.go +++ b/infra/conf/blackhole_test.go @@ -2,6 +2,7 @@ package conf_test import ( "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" "testing" "github.com/v2fly/v2ray-core/v4/common/serial" @@ -14,21 +15,21 @@ func TestHTTPResponseJSON(t *testing.T) { return new(BlackholeConfig) } - runMultiTestCase(t, []TestCase{ + testassist.RunMultiTestCase(t, []testassist.TestCase{ { Input: `{ "response": { "type": "http" } }`, - Parser: loadJSON(creator), + Parser: testassist.LoadJSON(creator), Output: &blackhole.Config{ Response: serial.ToTypedMessage(&blackhole.HTTPResponse{}), }, }, { Input: `{}`, - Parser: loadJSON(creator), + Parser: testassist.LoadJSON(creator), Output: &blackhole.Config{}, }, }) diff --git a/infra/conf/loader.go b/infra/conf/cfgcommon/loader/loader.go similarity index 95% rename from infra/conf/loader.go rename to infra/conf/cfgcommon/loader/loader.go index 51f268a3e..5030c3689 100644 --- a/infra/conf/loader.go +++ b/infra/conf/cfgcommon/loader/loader.go @@ -1,10 +1,12 @@ -package conf +package loader import ( "encoding/json" "strings" ) +//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen + type ConfigCreator func() interface{} type ConfigCreatorCache map[string]ConfigCreator diff --git a/infra/conf/general_test.go b/infra/conf/cfgcommon/testassist/general.go similarity index 84% rename from infra/conf/general_test.go rename to infra/conf/cfgcommon/testassist/general.go index f9f739dd1..534520d4d 100644 --- a/infra/conf/general_test.go +++ b/infra/conf/cfgcommon/testassist/general.go @@ -1,4 +1,4 @@ -package conf_test +package testassist import ( "encoding/json" @@ -10,7 +10,7 @@ import ( "github.com/v2fly/v2ray-core/v4/common" ) -func loadJSON(creator func() cfgcommon.Buildable) func(string) (proto.Message, error) { +func LoadJSON(creator func() cfgcommon.Buildable) func(string) (proto.Message, error) { return func(s string) (proto.Message, error) { instance := creator() if err := json.Unmarshal([]byte(s), instance); err != nil { @@ -26,7 +26,7 @@ type TestCase struct { Output proto.Message } -func runMultiTestCase(t *testing.T, testCases []TestCase) { +func RunMultiTestCase(t *testing.T, testCases []TestCase) { for _, testCase := range testCases { actual, err := testCase.Parser(testCase.Input) common.Must(err) diff --git a/infra/conf/dns_proxy_test.go b/infra/conf/dns_proxy_test.go index 0d1d1d6f0..fac488987 100644 --- a/infra/conf/dns_proxy_test.go +++ b/infra/conf/dns_proxy_test.go @@ -2,6 +2,7 @@ package conf_test import ( "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" "testing" "github.com/v2fly/v2ray-core/v4/common/net" @@ -14,14 +15,14 @@ func TestDnsProxyConfig(t *testing.T) { return new(DNSOutboundConfig) } - runMultiTestCase(t, []TestCase{ + testassist.RunMultiTestCase(t, []testassist.TestCase{ { Input: `{ "address": "8.8.8.8", "port": 53, "network": "tcp" }`, - Parser: loadJSON(creator), + Parser: testassist.LoadJSON(creator), Output: &dns.Config{ Server: &net.Endpoint{ Network: net.Network_TCP, diff --git a/infra/conf/dns_test.go b/infra/conf/dns_test.go index ef7b7c953..7c92f8470 100644 --- a/infra/conf/dns_test.go +++ b/infra/conf/dns_test.go @@ -3,6 +3,7 @@ package conf_test import ( "encoding/json" "errors" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" "io/fs" "os" "path/filepath" @@ -58,7 +59,7 @@ func TestDNSConfigParsing(t *testing.T) { } } - runMultiTestCase(t, []TestCase{ + testassist.RunMultiTestCase(t, []testassist.TestCase{ { Input: `{ "servers": [{ diff --git a/infra/conf/dokodemo_test.go b/infra/conf/dokodemo_test.go index d5e945c56..c56c85c0d 100644 --- a/infra/conf/dokodemo_test.go +++ b/infra/conf/dokodemo_test.go @@ -2,6 +2,7 @@ package conf_test import ( "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" "testing" "github.com/v2fly/v2ray-core/v4/common/net" @@ -14,7 +15,7 @@ func TestDokodemoConfig(t *testing.T) { return new(DokodemoConfig) } - runMultiTestCase(t, []TestCase{ + testassist.RunMultiTestCase(t, []testassist.TestCase{ { Input: `{ "address": "8.8.8.8", @@ -24,7 +25,7 @@ func TestDokodemoConfig(t *testing.T) { "followRedirect": true, "userLevel": 1 }`, - Parser: loadJSON(creator), + Parser: testassist.LoadJSON(creator), Output: &dokodemo.Config{ Address: &net.IPOrDomain{ Address: &net.IPOrDomain_Ip{ diff --git a/infra/conf/duration.go b/infra/conf/duration.go deleted file mode 100644 index a033751ea..000000000 --- a/infra/conf/duration.go +++ /dev/null @@ -1,33 +0,0 @@ -package conf - -import ( - "encoding/json" - "fmt" - "time" -) - -type Duration int64 - -func (d *Duration) MarshalJSON() ([]byte, error) { - dr := time.Duration(*d) - return json.Marshal(dr.String()) -} - -func (d *Duration) UnmarshalJSON(b []byte) error { - var v interface{} - if err := json.Unmarshal(b, &v); err != nil { - return err - } - switch value := v.(type) { - case string: - var err error - dr, err := time.ParseDuration(value) - if err != nil { - return err - } - *d = Duration(dr) - return nil - default: - return fmt.Errorf("invalid duration: %v", v) - } -} diff --git a/infra/conf/duration_test.go b/infra/conf/duration_test.go deleted file mode 100644 index 95add1d23..000000000 --- a/infra/conf/duration_test.go +++ /dev/null @@ -1,33 +0,0 @@ -package conf_test - -import ( - "encoding/json" - "testing" - "time" - - "github.com/v2fly/v2ray-core/v4/infra/conf" -) - -type testWithDuration struct { - Duration conf.Duration -} - -func TestDurationJSON(t *testing.T) { - expected := &testWithDuration{ - Duration: conf.Duration(time.Hour), - } - data, err := json.Marshal(expected) - if err != nil { - t.Error(err) - return - } - actual := &testWithDuration{} - err = json.Unmarshal(data, &actual) - if err != nil { - t.Error(err) - return - } - if actual.Duration != expected.Duration { - t.Errorf("expected: %s, actual: %s", time.Duration(expected.Duration), time.Duration(actual.Duration)) - } -} diff --git a/infra/conf/freedom_test.go b/infra/conf/freedom_test.go index 3ce74ef35..b8d1e80d4 100644 --- a/infra/conf/freedom_test.go +++ b/infra/conf/freedom_test.go @@ -2,6 +2,7 @@ package conf_test import ( "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" "testing" "github.com/v2fly/v2ray-core/v4/common/net" @@ -15,7 +16,7 @@ func TestFreedomConfig(t *testing.T) { return new(FreedomConfig) } - runMultiTestCase(t, []TestCase{ + testassist.RunMultiTestCase(t, []testassist.TestCase{ { Input: `{ "domainStrategy": "AsIs", @@ -23,7 +24,7 @@ func TestFreedomConfig(t *testing.T) { "redirect": "127.0.0.1:3366", "userLevel": 1 }`, - Parser: loadJSON(creator), + Parser: testassist.LoadJSON(creator), Output: &freedom.Config{ DomainStrategy: freedom.Config_AS_IS, Timeout: 10, diff --git a/infra/conf/http_test.go b/infra/conf/http_test.go index 597063d9e..fc096bfa5 100644 --- a/infra/conf/http_test.go +++ b/infra/conf/http_test.go @@ -2,6 +2,7 @@ package conf_test import ( "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" "testing" . "github.com/v2fly/v2ray-core/v4/infra/conf" @@ -13,7 +14,7 @@ func TestHTTPServerConfig(t *testing.T) { return new(HTTPServerConfig) } - runMultiTestCase(t, []TestCase{ + testassist.RunMultiTestCase(t, []testassist.TestCase{ { Input: `{ "timeout": 10, @@ -26,7 +27,7 @@ func TestHTTPServerConfig(t *testing.T) { "allowTransparent": true, "userLevel": 1 }`, - Parser: loadJSON(creator), + Parser: testassist.LoadJSON(creator), Output: &http.ServerConfig{ Accounts: map[string]string{ "my-username": "my-password", diff --git a/infra/conf/observatory.go b/infra/conf/observatory.go index 2857213ac..4cbe3405a 100644 --- a/infra/conf/observatory.go +++ b/infra/conf/observatory.go @@ -7,6 +7,7 @@ import ( "github.com/v2fly/v2ray-core/v4/app/observatory/multiObservatory" "github.com/v2fly/v2ray-core/v4/common/serial" "github.com/v2fly/v2ray-core/v4/common/taggedfeatures" + "github.com/v2fly/v2ray-core/v4/infra/conf/synthetic/router" "github.com/v2fly/v2ray-core/v4/app/observatory" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/duration" @@ -25,7 +26,7 @@ func (o *ObservatoryConfig) Build() (proto.Message, error) { type BurstObservatoryConfig struct { SubjectSelector []string `json:"subjectSelector"` // health check settings - HealthCheck *healthCheckSettings `json:"pingConfig,omitempty"` + HealthCheck *router.HealthCheckSettings `json:"pingConfig,omitempty"` } func (b BurstObservatoryConfig) Build() (proto.Message, error) { diff --git a/infra/conf/reverse_test.go b/infra/conf/reverse_test.go index 8290e3ec3..57271beb6 100644 --- a/infra/conf/reverse_test.go +++ b/infra/conf/reverse_test.go @@ -2,6 +2,7 @@ package conf_test import ( "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" "testing" "github.com/v2fly/v2ray-core/v4/app/reverse" @@ -13,7 +14,7 @@ func TestReverseConfig(t *testing.T) { return new(conf.ReverseConfig) } - runMultiTestCase(t, []TestCase{ + testassist.RunMultiTestCase(t, []testassist.TestCase{ { Input: `{ "bridges": [{ @@ -21,7 +22,7 @@ func TestReverseConfig(t *testing.T) { "domain": "test.v2fly.org" }] }`, - Parser: loadJSON(creator), + Parser: testassist.LoadJSON(creator), Output: &reverse.Config{ BridgeConfig: []*reverse.BridgeConfig{ {Tag: "test", Domain: "test.v2fly.org"}, @@ -35,7 +36,7 @@ func TestReverseConfig(t *testing.T) { "domain": "test.v2fly.org" }] }`, - Parser: loadJSON(creator), + Parser: testassist.LoadJSON(creator), Output: &reverse.Config{ PortalConfig: []*reverse.PortalConfig{ {Tag: "test", Domain: "test.v2fly.org"}, diff --git a/infra/conf/shadowsocks_test.go b/infra/conf/shadowsocks_test.go index 1d41ffca5..dc057fe82 100644 --- a/infra/conf/shadowsocks_test.go +++ b/infra/conf/shadowsocks_test.go @@ -2,6 +2,7 @@ package conf_test import ( "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" "testing" "github.com/v2fly/v2ray-core/v4/common/net" @@ -16,13 +17,13 @@ func TestShadowsocksServerConfigParsing(t *testing.T) { return new(ShadowsocksServerConfig) } - runMultiTestCase(t, []TestCase{ + testassist.RunMultiTestCase(t, []testassist.TestCase{ { Input: `{ "method": "aes-256-GCM", "password": "v2ray-password" }`, - Parser: loadJSON(creator), + Parser: testassist.LoadJSON(creator), Output: &shadowsocks.ServerConfig{ User: &protocol.User{ Account: serial.ToTypedMessage(&shadowsocks.Account{ diff --git a/infra/conf/socks_test.go b/infra/conf/socks_test.go index 8acb2bd24..122b06c9f 100644 --- a/infra/conf/socks_test.go +++ b/infra/conf/socks_test.go @@ -2,6 +2,7 @@ package conf_test import ( "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" "testing" "github.com/v2fly/v2ray-core/v4/common/net" @@ -16,7 +17,7 @@ func TestSocksInboundConfig(t *testing.T) { return new(SocksServerConfig) } - runMultiTestCase(t, []TestCase{ + testassist.RunMultiTestCase(t, []testassist.TestCase{ { Input: `{ "auth": "password", @@ -31,7 +32,7 @@ func TestSocksInboundConfig(t *testing.T) { "timeout": 5, "userLevel": 1 }`, - Parser: loadJSON(creator), + Parser: testassist.LoadJSON(creator), Output: &socks.ServerConfig{ AuthType: socks.AuthType_PASSWORD, Accounts: map[string]string{ @@ -55,7 +56,7 @@ func TestSocksOutboundConfig(t *testing.T) { return new(SocksClientConfig) } - runMultiTestCase(t, []TestCase{ + testassist.RunMultiTestCase(t, []testassist.TestCase{ { Input: `{ "servers": [{ @@ -66,7 +67,7 @@ func TestSocksOutboundConfig(t *testing.T) { ] }] }`, - Parser: loadJSON(creator), + Parser: testassist.LoadJSON(creator), Output: &socks.ClientConfig{ Server: []*protocol.ServerEndpoint{ { diff --git a/infra/conf/router.go b/infra/conf/synthetic/router/router.go similarity index 97% rename from infra/conf/router.go rename to infra/conf/synthetic/router/router.go index f3be93385..7d2fff1f0 100644 --- a/infra/conf/router.go +++ b/infra/conf/synthetic/router/router.go @@ -1,4 +1,6 @@ -package conf +package router + +//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen import ( "context" @@ -50,7 +52,7 @@ func (r *BalancingRule) Build() (*router.BalancingRule, error) { case strategyLeastLoad: strategy = strategyLeastLoad case strategyLeastPing: - strategy = "leastPing" + strategy = "leastping" default: return nil, newError("unknown balancing strategy: " + r.Strategy.Type) } diff --git a/infra/conf/router_strategy.go b/infra/conf/synthetic/router/router_strategy.go similarity index 74% rename from infra/conf/router_strategy.go rename to infra/conf/synthetic/router/router_strategy.go index 5e7062991..3412e197b 100644 --- a/infra/conf/router_strategy.go +++ b/infra/conf/synthetic/router/router_strategy.go @@ -1,8 +1,10 @@ -package conf +package router import ( "github.com/golang/protobuf/proto" "github.com/v2fly/v2ray-core/v4/app/observatory/burst" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/duration" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/loader" "github.com/v2fly/v2ray-core/v4/app/router" ) @@ -14,7 +16,7 @@ const ( ) var ( - strategyConfigLoader = NewJSONConfigLoader(ConfigCreatorCache{ + strategyConfigLoader = loader.NewJSONConfigLoader(loader.ConfigCreatorCache{ strategyRandom: func() interface{} { return new(strategyEmptyConfig) }, strategyLeastLoad: func() interface{} { return new(strategyLeastLoadConfig) }, strategyLeastPing: func() interface{} { return new(strategyLeastPingConfig) }, @@ -32,27 +34,27 @@ type strategyLeastLoadConfig struct { // weight settings Costs []*router.StrategyWeight `json:"costs,omitempty"` // ping rtt baselines - Baselines []Duration `json:"baselines,omitempty"` + Baselines []duration.Duration `json:"baselines,omitempty"` // expected nodes count to select Expected int32 `json:"expected,omitempty"` // max acceptable rtt, filter away high delay nodes. defalut 0 - MaxRTT Duration `json:"maxRTT,omitempty"` + MaxRTT duration.Duration `json:"maxRTT,omitempty"` // acceptable failure rate Tolerance float64 `json:"tolerance,omitempty"` ObserverTag string `json:"observerTag,omitempty"` } -// healthCheckSettings holds settings for health Checker -type healthCheckSettings struct { - Destination string `json:"destination"` - Connectivity string `json:"connectivity"` - Interval Duration `json:"interval"` - SamplingCount int `json:"sampling"` - Timeout Duration `json:"timeout"` +// HealthCheckSettings holds settings for health Checker +type HealthCheckSettings struct { + Destination string `json:"destination"` + Connectivity string `json:"connectivity"` + Interval duration.Duration `json:"interval"` + SamplingCount int `json:"sampling"` + Timeout duration.Duration `json:"timeout"` } -func (h healthCheckSettings) Build() (proto.Message, error) { +func (h HealthCheckSettings) Build() (proto.Message, error) { return &burst.HealthPingConfig{ Destination: h.Destination, Connectivity: h.Connectivity, diff --git a/infra/conf/router_test.go b/infra/conf/synthetic/router/router_test.go similarity index 94% rename from infra/conf/router_test.go rename to infra/conf/synthetic/router/router_test.go index a0102a57c..d717ee090 100644 --- a/infra/conf/router_test.go +++ b/infra/conf/synthetic/router/router_test.go @@ -1,7 +1,9 @@ -package conf_test +package router_test import ( "encoding/json" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" + router2 "github.com/v2fly/v2ray-core/v4/infra/conf/synthetic/router" "testing" "time" _ "unsafe" @@ -11,13 +13,16 @@ import ( "github.com/v2fly/v2ray-core/v4/app/router" "github.com/v2fly/v2ray-core/v4/common/net" "github.com/v2fly/v2ray-core/v4/common/serial" - . "github.com/v2fly/v2ray-core/v4/infra/conf" + + // Geo loaders + _ "github.com/v2fly/v2ray-core/v4/infra/conf/geodata/memconservative" + _ "github.com/v2fly/v2ray-core/v4/infra/conf/geodata/standard" ) func TestRouterConfig(t *testing.T) { createParser := func() func(string) (proto.Message, error) { return func(s string) (proto.Message, error) { - config := new(RouterConfig) + config := new(router2.RouterConfig) if err := json.Unmarshal([]byte(s), config); err != nil { return nil, err } @@ -25,7 +30,7 @@ func TestRouterConfig(t *testing.T) { } } - runMultiTestCase(t, []TestCase{ + testassist.RunMultiTestCase(t, []testassist.TestCase{ { Input: `{ "strategy": "rules", diff --git a/infra/conf/transport_internet.go b/infra/conf/transport_internet.go index 2440650c2..13f1892a1 100644 --- a/infra/conf/transport_internet.go +++ b/infra/conf/transport_internet.go @@ -3,6 +3,7 @@ package conf import ( "encoding/base64" "encoding/json" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/loader" "strings" "github.com/golang/protobuf/proto" @@ -23,7 +24,7 @@ import ( ) var ( - kcpHeaderLoader = NewJSONConfigLoader(ConfigCreatorCache{ + kcpHeaderLoader = loader.NewJSONConfigLoader(loader.ConfigCreatorCache{ "none": func() interface{} { return new(NoOpAuthenticator) }, "srtp": func() interface{} { return new(SRTPAuthenticator) }, "utp": func() interface{} { return new(UTPAuthenticator) }, @@ -32,7 +33,7 @@ var ( "wireguard": func() interface{} { return new(WireguardAuthenticator) }, }, "type", "") - tcpHeaderLoader = NewJSONConfigLoader(ConfigCreatorCache{ + tcpHeaderLoader = loader.NewJSONConfigLoader(loader.ConfigCreatorCache{ "none": func() interface{} { return new(NoOpConnectionAuthenticator) }, "http": func() interface{} { return new(Authenticator) }, }, "type", "") diff --git a/infra/conf/transport_test.go b/infra/conf/transport_test.go index 7cb3cdb3d..52fed7993 100644 --- a/infra/conf/transport_test.go +++ b/infra/conf/transport_test.go @@ -2,6 +2,7 @@ package conf_test import ( "encoding/json" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" "testing" "github.com/golang/protobuf/proto" @@ -31,7 +32,7 @@ func TestSocketConfig(t *testing.T) { } } - runMultiTestCase(t, []TestCase{ + testassist.RunMultiTestCase(t, []testassist.TestCase{ { Input: `{ "mark": 1, @@ -57,7 +58,7 @@ func TestTransportConfig(t *testing.T) { } } - runMultiTestCase(t, []TestCase{ + testassist.RunMultiTestCase(t, []testassist.TestCase{ { Input: `{ "tcpSettings": { diff --git a/infra/conf/v2ray.go b/infra/conf/v2ray.go index e100b0a22..c9f2f4336 100644 --- a/infra/conf/v2ray.go +++ b/infra/conf/v2ray.go @@ -2,6 +2,8 @@ package conf import ( "encoding/json" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/loader" + "github.com/v2fly/v2ray-core/v4/infra/conf/synthetic/router" "strings" core "github.com/v2fly/v2ray-core/v4" @@ -13,7 +15,7 @@ import ( ) var ( - inboundConfigLoader = NewJSONConfigLoader(ConfigCreatorCache{ + inboundConfigLoader = loader.NewJSONConfigLoader(loader.ConfigCreatorCache{ "dokodemo-door": func() interface{} { return new(DokodemoConfig) }, "http": func() interface{} { return new(HTTPServerConfig) }, "shadowsocks": func() interface{} { return new(ShadowsocksServerConfig) }, @@ -23,7 +25,7 @@ var ( "trojan": func() interface{} { return new(TrojanServerConfig) }, }, "protocol", "settings") - outboundConfigLoader = NewJSONConfigLoader(ConfigCreatorCache{ + outboundConfigLoader = loader.NewJSONConfigLoader(loader.ConfigCreatorCache{ "blackhole": func() interface{} { return new(BlackholeConfig) }, "freedom": func() interface{} { return new(FreedomConfig) }, "http": func() interface{} { return new(HTTPClientConfig) }, @@ -339,7 +341,7 @@ type Config struct { OutboundDetours []OutboundDetourConfig `json:"outboundDetour"` LogConfig *LogConfig `json:"log"` - RouterConfig *RouterConfig `json:"routing"` + RouterConfig *router.RouterConfig `json:"routing"` DNSConfig *DNSConfig `json:"dns"` InboundConfigs []InboundDetourConfig `json:"inbounds"` OutboundConfigs []OutboundDetourConfig `json:"outbounds"` diff --git a/infra/conf/v2ray_test.go b/infra/conf/v2ray_test.go index b53465258..f6bd90217 100644 --- a/infra/conf/v2ray_test.go +++ b/infra/conf/v2ray_test.go @@ -2,6 +2,7 @@ package conf_test import ( "encoding/json" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" "reflect" "testing" @@ -40,7 +41,7 @@ func TestV2RayConfig(t *testing.T) { } } - runMultiTestCase(t, []TestCase{ + testassist.RunMultiTestCase(t, []testassist.TestCase{ { Input: `{ "outbound": { diff --git a/infra/conf/vless_test.go b/infra/conf/vless_test.go index 92b7cc065..17eef0a49 100644 --- a/infra/conf/vless_test.go +++ b/infra/conf/vless_test.go @@ -2,6 +2,7 @@ package conf_test import ( "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" "testing" "github.com/v2fly/v2ray-core/v4/common/net" @@ -18,7 +19,7 @@ func TestVLessOutbound(t *testing.T) { return new(VLessOutboundConfig) } - runMultiTestCase(t, []TestCase{ + testassist.RunMultiTestCase(t, []testassist.TestCase{ { Input: `{ "vnext": [{ @@ -33,7 +34,7 @@ func TestVLessOutbound(t *testing.T) { ] }] }`, - Parser: loadJSON(creator), + Parser: testassist.LoadJSON(creator), Output: &outbound.Config{ Vnext: []*protocol.ServerEndpoint{ { @@ -64,7 +65,7 @@ func TestVLessInbound(t *testing.T) { return new(VLessInboundConfig) } - runMultiTestCase(t, []TestCase{ + testassist.RunMultiTestCase(t, []testassist.TestCase{ { Input: `{ "clients": [ @@ -90,7 +91,7 @@ func TestVLessInbound(t *testing.T) { } ] }`, - Parser: loadJSON(creator), + Parser: testassist.LoadJSON(creator), Output: &inbound.Config{ Clients: []*protocol.User{ { diff --git a/infra/conf/vmess_test.go b/infra/conf/vmess_test.go index 743f88f5a..07af0e9fb 100644 --- a/infra/conf/vmess_test.go +++ b/infra/conf/vmess_test.go @@ -2,6 +2,7 @@ package conf_test import ( "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist" "testing" "github.com/v2fly/v2ray-core/v4/common/net" @@ -18,7 +19,7 @@ func TestVMessOutbound(t *testing.T) { return new(VMessOutboundConfig) } - runMultiTestCase(t, []TestCase{ + testassist.RunMultiTestCase(t, []testassist.TestCase{ { Input: `{ "vnext": [{ @@ -33,7 +34,7 @@ func TestVMessOutbound(t *testing.T) { ] }] }`, - Parser: loadJSON(creator), + Parser: testassist.LoadJSON(creator), Output: &outbound.Config{ Receiver: []*protocol.ServerEndpoint{ { @@ -68,7 +69,7 @@ func TestVMessInbound(t *testing.T) { return new(VMessInboundConfig) } - runMultiTestCase(t, []TestCase{ + testassist.RunMultiTestCase(t, []testassist.TestCase{ { Input: `{ "clients": [ @@ -89,7 +90,7 @@ func TestVMessInbound(t *testing.T) { }, "disableInsecureEncryption": true }`, - Parser: loadJSON(creator), + Parser: testassist.LoadJSON(creator), Output: &inbound.Config{ User: []*protocol.User{ {