From fe3a0cf95436e1ebbd45fc590bee998fb9d3868a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=81=E3=82=BB?= <123655015+chise0713@users.noreply.github.com> Date: Wed, 20 Mar 2024 13:22:56 +0800 Subject: [PATCH] Chore: Clean up legacy `field` usage --- infra/conf/router.go | 52 +------------------------------------------- 1 file changed, 1 insertion(+), 51 deletions(-) diff --git a/infra/conf/router.go b/infra/conf/router.go index 9c7ce789..5a6ca8fe 100644 --- a/infra/conf/router.go +++ b/infra/conf/router.go @@ -8,8 +8,8 @@ import ( "github.com/xtls/xray-core/app/router" "github.com/xtls/xray-core/common/net" - "github.com/xtls/xray-core/common/serial" "github.com/xtls/xray-core/common/platform/filesystem" + "github.com/xtls/xray-core/common/serial" "google.golang.org/protobuf/proto" ) @@ -663,55 +663,5 @@ func ParseRule(msg json.RawMessage) (*router.RoutingRule, error) { } return fieldrule, nil } - if strings.EqualFold(rawRule.Type, "chinaip") { - chinaiprule, err := parseChinaIPRule(msg) - if err != nil { - return nil, newError("invalid chinaip rule").Base(err) - } - return chinaiprule, nil - } - if strings.EqualFold(rawRule.Type, "chinasites") { - chinasitesrule, err := parseChinaSitesRule(msg) - if err != nil { - return nil, newError("invalid chinasites rule").Base(err) - } - return chinasitesrule, nil - } return nil, newError("unknown router rule type: ", rawRule.Type) } - -func parseChinaIPRule(data []byte) (*router.RoutingRule, error) { - rawRule := new(RouterRule) - err := json.Unmarshal(data, rawRule) - if err != nil { - return nil, newError("invalid router rule").Base(err) - } - chinaIPs, err := loadGeoIP("CN") - if err != nil { - return nil, newError("failed to load geoip:cn").Base(err) - } - return &router.RoutingRule{ - TargetTag: &router.RoutingRule_Tag{ - Tag: rawRule.OutboundTag, - }, - Cidr: chinaIPs, - }, nil -} - -func parseChinaSitesRule(data []byte) (*router.RoutingRule, error) { - rawRule := new(RouterRule) - err := json.Unmarshal(data, rawRule) - if err != nil { - return nil, newError("invalid router rule").Base(err).AtError() - } - domains, err := loadGeositeWithAttr("geosite.dat", "CN") - if err != nil { - return nil, newError("failed to load geosite:cn.").Base(err) - } - return &router.RoutingRule{ - TargetTag: &router.RoutingRule_Tag{ - Tag: rawRule.OutboundTag, - }, - Domain: domains, - }, nil -}