Skip to content

Commit

Permalink
Config: Remove legacy config fields again (#3782)
Browse files Browse the repository at this point in the history
* Remove more lecacy fields

* Patch missing bracket

* Fix tests

* Fix missing comma

* Fix buried test bomb

* Cleanup test after removed legacy test content
  • Loading branch information
KobeArthurScofield authored Sep 11, 2024
1 parent c90affe commit 6b1bf31
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 135 deletions.
12 changes: 0 additions & 12 deletions infra/conf/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ import (
"google.golang.org/protobuf/proto"
)

type RouterRulesConfig struct {
RuleList []json.RawMessage `json:"rules"`
DomainStrategy string `json:"domainStrategy"`
}

// StrategyConfig represents a strategy config
type StrategyConfig struct {
Type string `json:"type"`
Expand Down Expand Up @@ -76,7 +71,6 @@ func (r *BalancingRule) Build() (*router.BalancingRule, error) {
}

type RouterConfig struct {
Settings *RouterRulesConfig `json:"settings"` // Deprecated
RuleList []json.RawMessage `json:"rules"`
DomainStrategy *string `json:"domainStrategy"`
Balancers []*BalancingRule `json:"balancers"`
Expand All @@ -88,8 +82,6 @@ func (c *RouterConfig) getDomainStrategy() router.Config_DomainStrategy {
ds := ""
if c.DomainStrategy != nil {
ds = *c.DomainStrategy
} else if c.Settings != nil {
ds = c.Settings.DomainStrategy
}

switch strings.ToLower(ds) {
Expand All @@ -111,10 +103,6 @@ func (c *RouterConfig) Build() (*router.Config, error) {
var rawRuleList []json.RawMessage
if c != nil {
rawRuleList = c.RuleList
if c.Settings != nil {
c.RuleList = append(c.RuleList, c.Settings.RuleList...)
rawRuleList = c.RuleList
}
}

for _, rawRule := range rawRuleList {
Expand Down
127 changes: 29 additions & 98 deletions infra/conf/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,36 +64,33 @@ func TestRouterConfig(t *testing.T) {
runMultiTestCase(t, []TestCase{
{
Input: `{
"strategy": "rules",
"settings": {
"domainStrategy": "AsIs",
"rules": [
{
"type": "field",
"domain": [
"baidu.com",
"qq.com"
],
"outboundTag": "direct"
},
{
"type": "field",
"ip": [
"10.0.0.0/8",
"::1/128"
],
"outboundTag": "test"
},{
"type": "field",
"port": "53, 443, 1000-2000",
"outboundTag": "test"
},{
"type": "field",
"port": 123,
"outboundTag": "test"
}
]
},
"domainStrategy": "AsIs",
"rules": [
{
"type": "field",
"domain": [
"baidu.com",
"qq.com"
],
"outboundTag": "direct"
},
{
"type": "field",
"ip": [
"10.0.0.0/8",
"::1/128"
],
"outboundTag": "test"
},{
"type": "field",
"port": "53, 443, 1000-2000",
"outboundTag": "test"
},{
"type": "field",
"port": 123,
"outboundTag": "test"
}
],
"balancers": [
{
"tag": "b1",
Expand Down Expand Up @@ -225,73 +222,7 @@ func TestRouterConfig(t *testing.T) {
},
{
Input: `{
"strategy": "rules",
"settings": {
"domainStrategy": "IPIfNonMatch",
"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_IpIfNonMatch,
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",
},
},
},
},
},
{
Input: `{
"domainStrategy": "AsIs",
"domainStrategy": "IPIfNonMatch",
"rules": [
{
"type": "field",
Expand All @@ -313,7 +244,7 @@ func TestRouterConfig(t *testing.T) {
}`,
Parser: createParser(),
Output: &router.Config{
DomainStrategy: router.Config_AsIs,
DomainStrategy: router.Config_IpIfNonMatch,
Rule: []*router.RoutingRule{
{
Domain: []*router.Domain{
Expand Down
13 changes: 0 additions & 13 deletions infra/conf/xray.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,6 @@ func (c *StatsConfig) Build() (*stats.Config, error) {
}

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
// left for returning error
Transport map[string]json.RawMessage `json:"transport"`
Expand Down Expand Up @@ -597,14 +592,6 @@ func (c *Config) Build() (*core.Config, error) {
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 {
return nil, errors.New("Global transport config is deprecated")
}
Expand Down
21 changes: 9 additions & 12 deletions infra/conf/xray_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,15 @@ func TestXrayConfig(t *testing.T) {
}
}],
"routing": {
"strategy": "rules",
"settings": {
"rules": [
{
"ip": [
"10.0.0.0/8"
],
"type": "field",
"outboundTag": "blocked"
}
]
}
"rules": [
{
"ip": [
"10.0.0.0/8"
],
"type": "field",
"outboundTag": "blocked"
}
]
}
}`,
Parser: createParser(),
Expand Down

0 comments on commit 6b1bf31

Please sign in to comment.