mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-15 09:19:21 +02:00
Config: Remove legacy config fields again (#3782)
* Remove more lecacy fields * Patch missing bracket * Fix tests * Fix missing comma * Fix buried test bomb * Cleanup test after removed legacy test content
This commit is contained in:
parent
c90affe7db
commit
6b1bf312d7
|
@ -14,11 +14,6 @@ import (
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RouterRulesConfig struct {
|
|
||||||
RuleList []json.RawMessage `json:"rules"`
|
|
||||||
DomainStrategy string `json:"domainStrategy"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// StrategyConfig represents a strategy config
|
// StrategyConfig represents a strategy config
|
||||||
type StrategyConfig struct {
|
type StrategyConfig struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
|
@ -76,7 +71,6 @@ func (r *BalancingRule) Build() (*router.BalancingRule, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type RouterConfig struct {
|
type RouterConfig struct {
|
||||||
Settings *RouterRulesConfig `json:"settings"` // Deprecated
|
|
||||||
RuleList []json.RawMessage `json:"rules"`
|
RuleList []json.RawMessage `json:"rules"`
|
||||||
DomainStrategy *string `json:"domainStrategy"`
|
DomainStrategy *string `json:"domainStrategy"`
|
||||||
Balancers []*BalancingRule `json:"balancers"`
|
Balancers []*BalancingRule `json:"balancers"`
|
||||||
|
@ -88,8 +82,6 @@ func (c *RouterConfig) getDomainStrategy() router.Config_DomainStrategy {
|
||||||
ds := ""
|
ds := ""
|
||||||
if c.DomainStrategy != nil {
|
if c.DomainStrategy != nil {
|
||||||
ds = *c.DomainStrategy
|
ds = *c.DomainStrategy
|
||||||
} else if c.Settings != nil {
|
|
||||||
ds = c.Settings.DomainStrategy
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch strings.ToLower(ds) {
|
switch strings.ToLower(ds) {
|
||||||
|
@ -111,10 +103,6 @@ func (c *RouterConfig) Build() (*router.Config, error) {
|
||||||
var rawRuleList []json.RawMessage
|
var rawRuleList []json.RawMessage
|
||||||
if c != nil {
|
if c != nil {
|
||||||
rawRuleList = c.RuleList
|
rawRuleList = c.RuleList
|
||||||
if c.Settings != nil {
|
|
||||||
c.RuleList = append(c.RuleList, c.Settings.RuleList...)
|
|
||||||
rawRuleList = c.RuleList
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, rawRule := range rawRuleList {
|
for _, rawRule := range rawRuleList {
|
||||||
|
|
|
@ -64,8 +64,6 @@ func TestRouterConfig(t *testing.T) {
|
||||||
runMultiTestCase(t, []TestCase{
|
runMultiTestCase(t, []TestCase{
|
||||||
{
|
{
|
||||||
Input: `{
|
Input: `{
|
||||||
"strategy": "rules",
|
|
||||||
"settings": {
|
|
||||||
"domainStrategy": "AsIs",
|
"domainStrategy": "AsIs",
|
||||||
"rules": [
|
"rules": [
|
||||||
{
|
{
|
||||||
|
@ -92,8 +90,7 @@ func TestRouterConfig(t *testing.T) {
|
||||||
"port": 123,
|
"port": 123,
|
||||||
"outboundTag": "test"
|
"outboundTag": "test"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
},
|
|
||||||
"balancers": [
|
"balancers": [
|
||||||
{
|
{
|
||||||
"tag": "b1",
|
"tag": "b1",
|
||||||
|
@ -225,8 +222,6 @@ func TestRouterConfig(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Input: `{
|
Input: `{
|
||||||
"strategy": "rules",
|
|
||||||
"settings": {
|
|
||||||
"domainStrategy": "IPIfNonMatch",
|
"domainStrategy": "IPIfNonMatch",
|
||||||
"rules": [
|
"rules": [
|
||||||
{
|
{
|
||||||
|
@ -246,7 +241,6 @@ func TestRouterConfig(t *testing.T) {
|
||||||
"outboundTag": "test"
|
"outboundTag": "test"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
|
||||||
}`,
|
}`,
|
||||||
Parser: createParser(),
|
Parser: createParser(),
|
||||||
Output: &router.Config{
|
Output: &router.Config{
|
||||||
|
@ -289,68 +283,5 @@ func TestRouterConfig(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Input: `{
|
|
||||||
"domainStrategy": "AsIs",
|
|
||||||
"rules": [
|
|
||||||
{
|
|
||||||
"type": "field",
|
|
||||||
"domain": [
|
|
||||||
"baidu.com",
|
|
||||||
"qq.com"
|
|
||||||
],
|
|
||||||
"outboundTag": "direct"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "field",
|
|
||||||
"ip": [
|
|
||||||
"10.0.0.0/8",
|
|
||||||
"::1/128"
|
|
||||||
],
|
|
||||||
"outboundTag": "test"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}`,
|
|
||||||
Parser: createParser(),
|
|
||||||
Output: &router.Config{
|
|
||||||
DomainStrategy: router.Config_AsIs,
|
|
||||||
Rule: []*router.RoutingRule{
|
|
||||||
{
|
|
||||||
Domain: []*router.Domain{
|
|
||||||
{
|
|
||||||
Type: router.Domain_Plain,
|
|
||||||
Value: "baidu.com",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Type: router.Domain_Plain,
|
|
||||||
Value: "qq.com",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
TargetTag: &router.RoutingRule_Tag{
|
|
||||||
Tag: "direct",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Geoip: []*router.GeoIP{
|
|
||||||
{
|
|
||||||
Cidr: []*router.CIDR{
|
|
||||||
{
|
|
||||||
Ip: []byte{10, 0, 0, 0},
|
|
||||||
Prefix: 8,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Ip: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
|
|
||||||
Prefix: 128,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
TargetTag: &router.RoutingRule_Tag{
|
|
||||||
Tag: "test",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -361,11 +361,6 @@ func (c *StatsConfig) Build() (*stats.Config, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
// Port of this Point server.
|
|
||||||
// Deprecated: Port exists for historical compatibility
|
|
||||||
// and should not be used.
|
|
||||||
Port uint16 `json:"port"`
|
|
||||||
|
|
||||||
// Deprecated: Global transport config is no longer used
|
// Deprecated: Global transport config is no longer used
|
||||||
// left for returning error
|
// left for returning error
|
||||||
Transport map[string]json.RawMessage `json:"transport"`
|
Transport map[string]json.RawMessage `json:"transport"`
|
||||||
|
@ -597,14 +592,6 @@ func (c *Config) Build() (*core.Config, error) {
|
||||||
inbounds = append(inbounds, c.InboundConfigs...)
|
inbounds = append(inbounds, c.InboundConfigs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backward compatibility.
|
|
||||||
if len(inbounds) > 0 && inbounds[0].PortList == nil && c.Port > 0 {
|
|
||||||
inbounds[0].PortList = &PortList{[]PortRange{{
|
|
||||||
From: uint32(c.Port),
|
|
||||||
To: uint32(c.Port),
|
|
||||||
}}}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(c.Transport) > 0 {
|
if len(c.Transport) > 0 {
|
||||||
return nil, errors.New("Global transport config is deprecated")
|
return nil, errors.New("Global transport config is deprecated")
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,8 +74,6 @@ func TestXrayConfig(t *testing.T) {
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
"routing": {
|
"routing": {
|
||||||
"strategy": "rules",
|
|
||||||
"settings": {
|
|
||||||
"rules": [
|
"rules": [
|
||||||
{
|
{
|
||||||
"ip": [
|
"ip": [
|
||||||
|
@ -86,7 +84,6 @@ func TestXrayConfig(t *testing.T) {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}`,
|
}`,
|
||||||
Parser: createParser(),
|
Parser: createParser(),
|
||||||
Output: &core.Config{
|
Output: &core.Config{
|
||||||
|
|
Loading…
Reference in New Issue