1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-02 22:21:19 +00:00

isolate router settings synthesis

This commit is contained in:
Shelikhoo 2021-06-19 13:28:20 +01:00
parent 41b54ff61e
commit 39b3866774
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316
24 changed files with 91 additions and 128 deletions

View File

@ -3,6 +3,7 @@ package conf
import ( import (
"encoding/json" "encoding/json"
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon"
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/loader"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
@ -43,8 +44,8 @@ func (v *BlackholeConfig) Build() (proto.Message, error) {
return config, nil return config, nil
} }
var configLoader = NewJSONConfigLoader( var configLoader = loader.NewJSONConfigLoader(
ConfigCreatorCache{ loader.ConfigCreatorCache{
"none": func() interface{} { return new(NoneResponse) }, "none": func() interface{} { return new(NoneResponse) },
"http": func() interface{} { return new(HTTPResponse) }, "http": func() interface{} { return new(HTTPResponse) },
}, },

View File

@ -2,6 +2,7 @@ package conf_test
import ( import (
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon"
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist"
"testing" "testing"
"github.com/v2fly/v2ray-core/v4/common/serial" "github.com/v2fly/v2ray-core/v4/common/serial"
@ -14,21 +15,21 @@ func TestHTTPResponseJSON(t *testing.T) {
return new(BlackholeConfig) return new(BlackholeConfig)
} }
runMultiTestCase(t, []TestCase{ testassist.RunMultiTestCase(t, []testassist.TestCase{
{ {
Input: `{ Input: `{
"response": { "response": {
"type": "http" "type": "http"
} }
}`, }`,
Parser: loadJSON(creator), Parser: testassist.LoadJSON(creator),
Output: &blackhole.Config{ Output: &blackhole.Config{
Response: serial.ToTypedMessage(&blackhole.HTTPResponse{}), Response: serial.ToTypedMessage(&blackhole.HTTPResponse{}),
}, },
}, },
{ {
Input: `{}`, Input: `{}`,
Parser: loadJSON(creator), Parser: testassist.LoadJSON(creator),
Output: &blackhole.Config{}, Output: &blackhole.Config{},
}, },
}) })

View File

@ -1,10 +1,12 @@
package conf package loader
import ( import (
"encoding/json" "encoding/json"
"strings" "strings"
) )
//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen
type ConfigCreator func() interface{} type ConfigCreator func() interface{}
type ConfigCreatorCache map[string]ConfigCreator type ConfigCreatorCache map[string]ConfigCreator

View File

@ -1,4 +1,4 @@
package conf_test package testassist
import ( import (
"encoding/json" "encoding/json"
@ -10,7 +10,7 @@ import (
"github.com/v2fly/v2ray-core/v4/common" "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) { return func(s string) (proto.Message, error) {
instance := creator() instance := creator()
if err := json.Unmarshal([]byte(s), instance); err != nil { if err := json.Unmarshal([]byte(s), instance); err != nil {
@ -26,7 +26,7 @@ type TestCase struct {
Output proto.Message Output proto.Message
} }
func runMultiTestCase(t *testing.T, testCases []TestCase) { func RunMultiTestCase(t *testing.T, testCases []TestCase) {
for _, testCase := range testCases { for _, testCase := range testCases {
actual, err := testCase.Parser(testCase.Input) actual, err := testCase.Parser(testCase.Input)
common.Must(err) common.Must(err)

View File

@ -2,6 +2,7 @@ package conf_test
import ( import (
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon"
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist"
"testing" "testing"
"github.com/v2fly/v2ray-core/v4/common/net" "github.com/v2fly/v2ray-core/v4/common/net"
@ -14,14 +15,14 @@ func TestDnsProxyConfig(t *testing.T) {
return new(DNSOutboundConfig) return new(DNSOutboundConfig)
} }
runMultiTestCase(t, []TestCase{ testassist.RunMultiTestCase(t, []testassist.TestCase{
{ {
Input: `{ Input: `{
"address": "8.8.8.8", "address": "8.8.8.8",
"port": 53, "port": 53,
"network": "tcp" "network": "tcp"
}`, }`,
Parser: loadJSON(creator), Parser: testassist.LoadJSON(creator),
Output: &dns.Config{ Output: &dns.Config{
Server: &net.Endpoint{ Server: &net.Endpoint{
Network: net.Network_TCP, Network: net.Network_TCP,

View File

@ -3,6 +3,7 @@ package conf_test
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist"
"io/fs" "io/fs"
"os" "os"
"path/filepath" "path/filepath"
@ -58,7 +59,7 @@ func TestDNSConfigParsing(t *testing.T) {
} }
} }
runMultiTestCase(t, []TestCase{ testassist.RunMultiTestCase(t, []testassist.TestCase{
{ {
Input: `{ Input: `{
"servers": [{ "servers": [{

View File

@ -2,6 +2,7 @@ package conf_test
import ( import (
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon"
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist"
"testing" "testing"
"github.com/v2fly/v2ray-core/v4/common/net" "github.com/v2fly/v2ray-core/v4/common/net"
@ -14,7 +15,7 @@ func TestDokodemoConfig(t *testing.T) {
return new(DokodemoConfig) return new(DokodemoConfig)
} }
runMultiTestCase(t, []TestCase{ testassist.RunMultiTestCase(t, []testassist.TestCase{
{ {
Input: `{ Input: `{
"address": "8.8.8.8", "address": "8.8.8.8",
@ -24,7 +25,7 @@ func TestDokodemoConfig(t *testing.T) {
"followRedirect": true, "followRedirect": true,
"userLevel": 1 "userLevel": 1
}`, }`,
Parser: loadJSON(creator), Parser: testassist.LoadJSON(creator),
Output: &dokodemo.Config{ Output: &dokodemo.Config{
Address: &net.IPOrDomain{ Address: &net.IPOrDomain{
Address: &net.IPOrDomain_Ip{ Address: &net.IPOrDomain_Ip{

View File

@ -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)
}
}

View File

@ -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))
}
}

View File

@ -2,6 +2,7 @@ package conf_test
import ( import (
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon"
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist"
"testing" "testing"
"github.com/v2fly/v2ray-core/v4/common/net" "github.com/v2fly/v2ray-core/v4/common/net"
@ -15,7 +16,7 @@ func TestFreedomConfig(t *testing.T) {
return new(FreedomConfig) return new(FreedomConfig)
} }
runMultiTestCase(t, []TestCase{ testassist.RunMultiTestCase(t, []testassist.TestCase{
{ {
Input: `{ Input: `{
"domainStrategy": "AsIs", "domainStrategy": "AsIs",
@ -23,7 +24,7 @@ func TestFreedomConfig(t *testing.T) {
"redirect": "127.0.0.1:3366", "redirect": "127.0.0.1:3366",
"userLevel": 1 "userLevel": 1
}`, }`,
Parser: loadJSON(creator), Parser: testassist.LoadJSON(creator),
Output: &freedom.Config{ Output: &freedom.Config{
DomainStrategy: freedom.Config_AS_IS, DomainStrategy: freedom.Config_AS_IS,
Timeout: 10, Timeout: 10,

View File

@ -2,6 +2,7 @@ package conf_test
import ( import (
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon"
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist"
"testing" "testing"
. "github.com/v2fly/v2ray-core/v4/infra/conf" . "github.com/v2fly/v2ray-core/v4/infra/conf"
@ -13,7 +14,7 @@ func TestHTTPServerConfig(t *testing.T) {
return new(HTTPServerConfig) return new(HTTPServerConfig)
} }
runMultiTestCase(t, []TestCase{ testassist.RunMultiTestCase(t, []testassist.TestCase{
{ {
Input: `{ Input: `{
"timeout": 10, "timeout": 10,
@ -26,7 +27,7 @@ func TestHTTPServerConfig(t *testing.T) {
"allowTransparent": true, "allowTransparent": true,
"userLevel": 1 "userLevel": 1
}`, }`,
Parser: loadJSON(creator), Parser: testassist.LoadJSON(creator),
Output: &http.ServerConfig{ Output: &http.ServerConfig{
Accounts: map[string]string{ Accounts: map[string]string{
"my-username": "my-password", "my-username": "my-password",

View File

@ -7,6 +7,7 @@ import (
"github.com/v2fly/v2ray-core/v4/app/observatory/multiObservatory" "github.com/v2fly/v2ray-core/v4/app/observatory/multiObservatory"
"github.com/v2fly/v2ray-core/v4/common/serial" "github.com/v2fly/v2ray-core/v4/common/serial"
"github.com/v2fly/v2ray-core/v4/common/taggedfeatures" "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/app/observatory"
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/duration" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/duration"
@ -25,7 +26,7 @@ func (o *ObservatoryConfig) Build() (proto.Message, error) {
type BurstObservatoryConfig struct { type BurstObservatoryConfig struct {
SubjectSelector []string `json:"subjectSelector"` SubjectSelector []string `json:"subjectSelector"`
// health check settings // health check settings
HealthCheck *healthCheckSettings `json:"pingConfig,omitempty"` HealthCheck *router.HealthCheckSettings `json:"pingConfig,omitempty"`
} }
func (b BurstObservatoryConfig) Build() (proto.Message, error) { func (b BurstObservatoryConfig) Build() (proto.Message, error) {

View File

@ -2,6 +2,7 @@ package conf_test
import ( import (
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon"
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist"
"testing" "testing"
"github.com/v2fly/v2ray-core/v4/app/reverse" "github.com/v2fly/v2ray-core/v4/app/reverse"
@ -13,7 +14,7 @@ func TestReverseConfig(t *testing.T) {
return new(conf.ReverseConfig) return new(conf.ReverseConfig)
} }
runMultiTestCase(t, []TestCase{ testassist.RunMultiTestCase(t, []testassist.TestCase{
{ {
Input: `{ Input: `{
"bridges": [{ "bridges": [{
@ -21,7 +22,7 @@ func TestReverseConfig(t *testing.T) {
"domain": "test.v2fly.org" "domain": "test.v2fly.org"
}] }]
}`, }`,
Parser: loadJSON(creator), Parser: testassist.LoadJSON(creator),
Output: &reverse.Config{ Output: &reverse.Config{
BridgeConfig: []*reverse.BridgeConfig{ BridgeConfig: []*reverse.BridgeConfig{
{Tag: "test", Domain: "test.v2fly.org"}, {Tag: "test", Domain: "test.v2fly.org"},
@ -35,7 +36,7 @@ func TestReverseConfig(t *testing.T) {
"domain": "test.v2fly.org" "domain": "test.v2fly.org"
}] }]
}`, }`,
Parser: loadJSON(creator), Parser: testassist.LoadJSON(creator),
Output: &reverse.Config{ Output: &reverse.Config{
PortalConfig: []*reverse.PortalConfig{ PortalConfig: []*reverse.PortalConfig{
{Tag: "test", Domain: "test.v2fly.org"}, {Tag: "test", Domain: "test.v2fly.org"},

View File

@ -2,6 +2,7 @@ package conf_test
import ( import (
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon"
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist"
"testing" "testing"
"github.com/v2fly/v2ray-core/v4/common/net" "github.com/v2fly/v2ray-core/v4/common/net"
@ -16,13 +17,13 @@ func TestShadowsocksServerConfigParsing(t *testing.T) {
return new(ShadowsocksServerConfig) return new(ShadowsocksServerConfig)
} }
runMultiTestCase(t, []TestCase{ testassist.RunMultiTestCase(t, []testassist.TestCase{
{ {
Input: `{ Input: `{
"method": "aes-256-GCM", "method": "aes-256-GCM",
"password": "v2ray-password" "password": "v2ray-password"
}`, }`,
Parser: loadJSON(creator), Parser: testassist.LoadJSON(creator),
Output: &shadowsocks.ServerConfig{ Output: &shadowsocks.ServerConfig{
User: &protocol.User{ User: &protocol.User{
Account: serial.ToTypedMessage(&shadowsocks.Account{ Account: serial.ToTypedMessage(&shadowsocks.Account{

View File

@ -2,6 +2,7 @@ package conf_test
import ( import (
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon"
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist"
"testing" "testing"
"github.com/v2fly/v2ray-core/v4/common/net" "github.com/v2fly/v2ray-core/v4/common/net"
@ -16,7 +17,7 @@ func TestSocksInboundConfig(t *testing.T) {
return new(SocksServerConfig) return new(SocksServerConfig)
} }
runMultiTestCase(t, []TestCase{ testassist.RunMultiTestCase(t, []testassist.TestCase{
{ {
Input: `{ Input: `{
"auth": "password", "auth": "password",
@ -31,7 +32,7 @@ func TestSocksInboundConfig(t *testing.T) {
"timeout": 5, "timeout": 5,
"userLevel": 1 "userLevel": 1
}`, }`,
Parser: loadJSON(creator), Parser: testassist.LoadJSON(creator),
Output: &socks.ServerConfig{ Output: &socks.ServerConfig{
AuthType: socks.AuthType_PASSWORD, AuthType: socks.AuthType_PASSWORD,
Accounts: map[string]string{ Accounts: map[string]string{
@ -55,7 +56,7 @@ func TestSocksOutboundConfig(t *testing.T) {
return new(SocksClientConfig) return new(SocksClientConfig)
} }
runMultiTestCase(t, []TestCase{ testassist.RunMultiTestCase(t, []testassist.TestCase{
{ {
Input: `{ Input: `{
"servers": [{ "servers": [{
@ -66,7 +67,7 @@ func TestSocksOutboundConfig(t *testing.T) {
] ]
}] }]
}`, }`,
Parser: loadJSON(creator), Parser: testassist.LoadJSON(creator),
Output: &socks.ClientConfig{ Output: &socks.ClientConfig{
Server: []*protocol.ServerEndpoint{ Server: []*protocol.ServerEndpoint{
{ {

View File

@ -1,4 +1,6 @@
package conf package router
//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen
import ( import (
"context" "context"
@ -50,7 +52,7 @@ func (r *BalancingRule) Build() (*router.BalancingRule, error) {
case strategyLeastLoad: case strategyLeastLoad:
strategy = strategyLeastLoad strategy = strategyLeastLoad
case strategyLeastPing: case strategyLeastPing:
strategy = "leastPing" strategy = "leastping"
default: default:
return nil, newError("unknown balancing strategy: " + r.Strategy.Type) return nil, newError("unknown balancing strategy: " + r.Strategy.Type)
} }

View File

@ -1,8 +1,10 @@
package conf package router
import ( import (
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/v2fly/v2ray-core/v4/app/observatory/burst" "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" "github.com/v2fly/v2ray-core/v4/app/router"
) )
@ -14,7 +16,7 @@ const (
) )
var ( var (
strategyConfigLoader = NewJSONConfigLoader(ConfigCreatorCache{ strategyConfigLoader = loader.NewJSONConfigLoader(loader.ConfigCreatorCache{
strategyRandom: func() interface{} { return new(strategyEmptyConfig) }, strategyRandom: func() interface{} { return new(strategyEmptyConfig) },
strategyLeastLoad: func() interface{} { return new(strategyLeastLoadConfig) }, strategyLeastLoad: func() interface{} { return new(strategyLeastLoadConfig) },
strategyLeastPing: func() interface{} { return new(strategyLeastPingConfig) }, strategyLeastPing: func() interface{} { return new(strategyLeastPingConfig) },
@ -32,27 +34,27 @@ type strategyLeastLoadConfig struct {
// weight settings // weight settings
Costs []*router.StrategyWeight `json:"costs,omitempty"` Costs []*router.StrategyWeight `json:"costs,omitempty"`
// ping rtt baselines // ping rtt baselines
Baselines []Duration `json:"baselines,omitempty"` Baselines []duration.Duration `json:"baselines,omitempty"`
// expected nodes count to select // expected nodes count to select
Expected int32 `json:"expected,omitempty"` Expected int32 `json:"expected,omitempty"`
// max acceptable rtt, filter away high delay nodes. defalut 0 // max acceptable rtt, filter away high delay nodes. defalut 0
MaxRTT Duration `json:"maxRTT,omitempty"` MaxRTT duration.Duration `json:"maxRTT,omitempty"`
// acceptable failure rate // acceptable failure rate
Tolerance float64 `json:"tolerance,omitempty"` Tolerance float64 `json:"tolerance,omitempty"`
ObserverTag string `json:"observerTag,omitempty"` ObserverTag string `json:"observerTag,omitempty"`
} }
// healthCheckSettings holds settings for health Checker // HealthCheckSettings holds settings for health Checker
type healthCheckSettings struct { type HealthCheckSettings struct {
Destination string `json:"destination"` Destination string `json:"destination"`
Connectivity string `json:"connectivity"` Connectivity string `json:"connectivity"`
Interval Duration `json:"interval"` Interval duration.Duration `json:"interval"`
SamplingCount int `json:"sampling"` SamplingCount int `json:"sampling"`
Timeout Duration `json:"timeout"` Timeout duration.Duration `json:"timeout"`
} }
func (h healthCheckSettings) Build() (proto.Message, error) { func (h HealthCheckSettings) Build() (proto.Message, error) {
return &burst.HealthPingConfig{ return &burst.HealthPingConfig{
Destination: h.Destination, Destination: h.Destination,
Connectivity: h.Connectivity, Connectivity: h.Connectivity,

View File

@ -1,7 +1,9 @@
package conf_test package router_test
import ( import (
"encoding/json" "encoding/json"
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist"
router2 "github.com/v2fly/v2ray-core/v4/infra/conf/synthetic/router"
"testing" "testing"
"time" "time"
_ "unsafe" _ "unsafe"
@ -11,13 +13,16 @@ import (
"github.com/v2fly/v2ray-core/v4/app/router" "github.com/v2fly/v2ray-core/v4/app/router"
"github.com/v2fly/v2ray-core/v4/common/net" "github.com/v2fly/v2ray-core/v4/common/net"
"github.com/v2fly/v2ray-core/v4/common/serial" "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) { func TestRouterConfig(t *testing.T) {
createParser := func() func(string) (proto.Message, error) { createParser := func() func(string) (proto.Message, error) {
return func(s 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 { if err := json.Unmarshal([]byte(s), config); err != nil {
return nil, err return nil, err
} }
@ -25,7 +30,7 @@ func TestRouterConfig(t *testing.T) {
} }
} }
runMultiTestCase(t, []TestCase{ testassist.RunMultiTestCase(t, []testassist.TestCase{
{ {
Input: `{ Input: `{
"strategy": "rules", "strategy": "rules",

View File

@ -3,6 +3,7 @@ package conf
import ( import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/loader"
"strings" "strings"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
@ -23,7 +24,7 @@ import (
) )
var ( var (
kcpHeaderLoader = NewJSONConfigLoader(ConfigCreatorCache{ kcpHeaderLoader = loader.NewJSONConfigLoader(loader.ConfigCreatorCache{
"none": func() interface{} { return new(NoOpAuthenticator) }, "none": func() interface{} { return new(NoOpAuthenticator) },
"srtp": func() interface{} { return new(SRTPAuthenticator) }, "srtp": func() interface{} { return new(SRTPAuthenticator) },
"utp": func() interface{} { return new(UTPAuthenticator) }, "utp": func() interface{} { return new(UTPAuthenticator) },
@ -32,7 +33,7 @@ var (
"wireguard": func() interface{} { return new(WireguardAuthenticator) }, "wireguard": func() interface{} { return new(WireguardAuthenticator) },
}, "type", "") }, "type", "")
tcpHeaderLoader = NewJSONConfigLoader(ConfigCreatorCache{ tcpHeaderLoader = loader.NewJSONConfigLoader(loader.ConfigCreatorCache{
"none": func() interface{} { return new(NoOpConnectionAuthenticator) }, "none": func() interface{} { return new(NoOpConnectionAuthenticator) },
"http": func() interface{} { return new(Authenticator) }, "http": func() interface{} { return new(Authenticator) },
}, "type", "") }, "type", "")

View File

@ -2,6 +2,7 @@ package conf_test
import ( import (
"encoding/json" "encoding/json"
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist"
"testing" "testing"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
@ -31,7 +32,7 @@ func TestSocketConfig(t *testing.T) {
} }
} }
runMultiTestCase(t, []TestCase{ testassist.RunMultiTestCase(t, []testassist.TestCase{
{ {
Input: `{ Input: `{
"mark": 1, "mark": 1,
@ -57,7 +58,7 @@ func TestTransportConfig(t *testing.T) {
} }
} }
runMultiTestCase(t, []TestCase{ testassist.RunMultiTestCase(t, []testassist.TestCase{
{ {
Input: `{ Input: `{
"tcpSettings": { "tcpSettings": {

View File

@ -2,6 +2,8 @@ package conf
import ( import (
"encoding/json" "encoding/json"
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/loader"
"github.com/v2fly/v2ray-core/v4/infra/conf/synthetic/router"
"strings" "strings"
core "github.com/v2fly/v2ray-core/v4" core "github.com/v2fly/v2ray-core/v4"
@ -13,7 +15,7 @@ import (
) )
var ( var (
inboundConfigLoader = NewJSONConfigLoader(ConfigCreatorCache{ inboundConfigLoader = loader.NewJSONConfigLoader(loader.ConfigCreatorCache{
"dokodemo-door": func() interface{} { return new(DokodemoConfig) }, "dokodemo-door": func() interface{} { return new(DokodemoConfig) },
"http": func() interface{} { return new(HTTPServerConfig) }, "http": func() interface{} { return new(HTTPServerConfig) },
"shadowsocks": func() interface{} { return new(ShadowsocksServerConfig) }, "shadowsocks": func() interface{} { return new(ShadowsocksServerConfig) },
@ -23,7 +25,7 @@ var (
"trojan": func() interface{} { return new(TrojanServerConfig) }, "trojan": func() interface{} { return new(TrojanServerConfig) },
}, "protocol", "settings") }, "protocol", "settings")
outboundConfigLoader = NewJSONConfigLoader(ConfigCreatorCache{ outboundConfigLoader = loader.NewJSONConfigLoader(loader.ConfigCreatorCache{
"blackhole": func() interface{} { return new(BlackholeConfig) }, "blackhole": func() interface{} { return new(BlackholeConfig) },
"freedom": func() interface{} { return new(FreedomConfig) }, "freedom": func() interface{} { return new(FreedomConfig) },
"http": func() interface{} { return new(HTTPClientConfig) }, "http": func() interface{} { return new(HTTPClientConfig) },
@ -339,7 +341,7 @@ type Config struct {
OutboundDetours []OutboundDetourConfig `json:"outboundDetour"` OutboundDetours []OutboundDetourConfig `json:"outboundDetour"`
LogConfig *LogConfig `json:"log"` LogConfig *LogConfig `json:"log"`
RouterConfig *RouterConfig `json:"routing"` RouterConfig *router.RouterConfig `json:"routing"`
DNSConfig *DNSConfig `json:"dns"` DNSConfig *DNSConfig `json:"dns"`
InboundConfigs []InboundDetourConfig `json:"inbounds"` InboundConfigs []InboundDetourConfig `json:"inbounds"`
OutboundConfigs []OutboundDetourConfig `json:"outbounds"` OutboundConfigs []OutboundDetourConfig `json:"outbounds"`

View File

@ -2,6 +2,7 @@ package conf_test
import ( import (
"encoding/json" "encoding/json"
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist"
"reflect" "reflect"
"testing" "testing"
@ -40,7 +41,7 @@ func TestV2RayConfig(t *testing.T) {
} }
} }
runMultiTestCase(t, []TestCase{ testassist.RunMultiTestCase(t, []testassist.TestCase{
{ {
Input: `{ Input: `{
"outbound": { "outbound": {

View File

@ -2,6 +2,7 @@ package conf_test
import ( import (
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon"
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist"
"testing" "testing"
"github.com/v2fly/v2ray-core/v4/common/net" "github.com/v2fly/v2ray-core/v4/common/net"
@ -18,7 +19,7 @@ func TestVLessOutbound(t *testing.T) {
return new(VLessOutboundConfig) return new(VLessOutboundConfig)
} }
runMultiTestCase(t, []TestCase{ testassist.RunMultiTestCase(t, []testassist.TestCase{
{ {
Input: `{ Input: `{
"vnext": [{ "vnext": [{
@ -33,7 +34,7 @@ func TestVLessOutbound(t *testing.T) {
] ]
}] }]
}`, }`,
Parser: loadJSON(creator), Parser: testassist.LoadJSON(creator),
Output: &outbound.Config{ Output: &outbound.Config{
Vnext: []*protocol.ServerEndpoint{ Vnext: []*protocol.ServerEndpoint{
{ {
@ -64,7 +65,7 @@ func TestVLessInbound(t *testing.T) {
return new(VLessInboundConfig) return new(VLessInboundConfig)
} }
runMultiTestCase(t, []TestCase{ testassist.RunMultiTestCase(t, []testassist.TestCase{
{ {
Input: `{ Input: `{
"clients": [ "clients": [
@ -90,7 +91,7 @@ func TestVLessInbound(t *testing.T) {
} }
] ]
}`, }`,
Parser: loadJSON(creator), Parser: testassist.LoadJSON(creator),
Output: &inbound.Config{ Output: &inbound.Config{
Clients: []*protocol.User{ Clients: []*protocol.User{
{ {

View File

@ -2,6 +2,7 @@ package conf_test
import ( import (
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon"
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist"
"testing" "testing"
"github.com/v2fly/v2ray-core/v4/common/net" "github.com/v2fly/v2ray-core/v4/common/net"
@ -18,7 +19,7 @@ func TestVMessOutbound(t *testing.T) {
return new(VMessOutboundConfig) return new(VMessOutboundConfig)
} }
runMultiTestCase(t, []TestCase{ testassist.RunMultiTestCase(t, []testassist.TestCase{
{ {
Input: `{ Input: `{
"vnext": [{ "vnext": [{
@ -33,7 +34,7 @@ func TestVMessOutbound(t *testing.T) {
] ]
}] }]
}`, }`,
Parser: loadJSON(creator), Parser: testassist.LoadJSON(creator),
Output: &outbound.Config{ Output: &outbound.Config{
Receiver: []*protocol.ServerEndpoint{ Receiver: []*protocol.ServerEndpoint{
{ {
@ -68,7 +69,7 @@ func TestVMessInbound(t *testing.T) {
return new(VMessInboundConfig) return new(VMessInboundConfig)
} }
runMultiTestCase(t, []TestCase{ testassist.RunMultiTestCase(t, []testassist.TestCase{
{ {
Input: `{ Input: `{
"clients": [ "clients": [
@ -89,7 +90,7 @@ func TestVMessInbound(t *testing.T) {
}, },
"disableInsecureEncryption": true "disableInsecureEncryption": true
}`, }`,
Parser: loadJSON(creator), Parser: testassist.LoadJSON(creator),
Output: &inbound.Config{ Output: &inbound.Config{
User: []*protocol.User{ User: []*protocol.User{
{ {