diff --git a/app/dns/dns.go b/app/dns/dns.go index 4abc8b3309ff..f4802275987f 100644 --- a/app/dns/dns.go +++ b/app/dns/dns.go @@ -15,7 +15,6 @@ import ( "github.com/xtls/xray-core/common/net" "github.com/xtls/xray-core/common/session" "github.com/xtls/xray-core/common/strmatcher" - "github.com/xtls/xray-core/features" "github.com/xtls/xray-core/features/dns" ) @@ -96,7 +95,7 @@ func New(ctx context.Context, config *Config) (*DNS, error) { geoipContainer := router.GeoIPMatcherContainer{} for _, endpoint := range config.NameServers { - features.PrintDeprecatedFeatureWarning("simple DNS server") + errors.PrintDeprecatedFeatureWarning("simple DNS server", "") client, err := NewSimpleClient(ctx, endpoint, clientIP) if err != nil { return nil, errors.New("failed to create client").Base(err) diff --git a/app/dns/hosts.go b/app/dns/hosts.go index a60d2514685f..4dd01041c62d 100644 --- a/app/dns/hosts.go +++ b/app/dns/hosts.go @@ -7,7 +7,6 @@ import ( "github.com/xtls/xray-core/common/errors" "github.com/xtls/xray-core/common/net" "github.com/xtls/xray-core/common/strmatcher" - "github.com/xtls/xray-core/features" "github.com/xtls/xray-core/features/dns" ) @@ -26,7 +25,7 @@ func NewStaticHosts(hosts []*Config_HostMapping, legacy map[string]*net.IPOrDoma } if legacy != nil { - features.PrintDeprecatedFeatureWarning("simple host mapping") + errors.PrintDeprecatedFeatureWarning("simple host mapping", "") for domain, ip := range legacy { matcher, err := strmatcher.Full.New(domain) diff --git a/common/errors/feature_errors.go b/common/errors/feature_errors.go new file mode 100644 index 000000000000..ea9b4c03d0fc --- /dev/null +++ b/common/errors/feature_errors.go @@ -0,0 +1,25 @@ +package errors + +import ( + "context" +) + +// PrintDeprecatedFeatureWarning prints a warning for deprecated and going to be removed feature. +// Do not remove this function even there is no reference to it. +func PrintDeprecatedFeatureWarning(feature string, migrateFeature string) { + if len(migrateFeature) > 0 { + LogWarning(context.Background(), "This feature " + feature + " is deprecated and being migrated to " + migrateFeature + ". Please update your config(s) according to release note and documentation before removal.") + } else { + LogWarning(context.Background(), "This feature " + feature + " is deprecated. Please update your config(s) according to release note and documentation before removal.") + } +} + +// PrintRemovedFeatureError prints an error message for removed feature then return an error. And after long enough time the message can also be removed, uses as an indicator. +// Do not remove this function even there is no reference to it. +func PrintRemovedFeatureError(feature string, migrateFeature string) (error) { + if len(migrateFeature) > 0 { + return New("The feature " + feature + " has been removed and migrated to " + migrateFeature + ". Please update your config(s) according to release note and documentation.") + } else { + return New("The feature " + feature + " has been removed. Please update your config(s) according to release note and documentation.") + } +} diff --git a/features/feature.go b/features/feature.go index 4ed716009ff5..026b8fa5f926 100644 --- a/features/feature.go +++ b/features/feature.go @@ -1,27 +1,12 @@ package features import ( - "context" - "github.com/xtls/xray-core/common" - "github.com/xtls/xray-core/common/errors" ) -//go:generate go run github.com/xtls/xray-core/common/errors/errorgen - // Feature is the interface for Xray features. All features must implement this interface. // All existing features have an implementation in app directory. These features can be replaced by third-party ones. type Feature interface { common.HasType common.Runnable } - -// PrintDeprecatedFeatureWarning prints a warning for deprecated feature. -func PrintDeprecatedFeatureWarning(feature string) { - errors.LogWarning(context.Background(), "You are using a deprecated feature: " + feature + ". Please update your config file(s) with latest configuration format, or update your client software.") -} - -// PrintRemovedFeatureError prints an error message for removed feature. And after long enough time the message can also be removed, use as an indicator. -func PrintRemovedFeatureError(feature string) { - errors.New("The feature " + feature + " is removed. Please update your config file(s) according to release notes and documentations.") -} diff --git a/infra/conf/transport_internet.go b/infra/conf/transport_internet.go index 8cc057a8bf80..b61914ae9b8b 100644 --- a/infra/conf/transport_internet.go +++ b/infra/conf/transport_internet.go @@ -813,7 +813,7 @@ func (c *StreamConfig) Build() (*internet.StreamConfig, error) { config.SecuritySettings = append(config.SecuritySettings, tm) config.SecurityType = tm.Type case "xtls": - return nil, errors.New(`Please use VLESS flow "xtls-rprx-vision" with TLS or REALITY.`) + return nil, errors.PrintRemovedFeatureError(`Legacy XTLS`, `xtls-rprx-vision with TLS or REALITY`) default: return nil, errors.New(`Unknown security "` + c.Security + `".`) } diff --git a/infra/conf/trojan.go b/infra/conf/trojan.go index 13a1df7365ce..03ac6f46c39e 100644 --- a/infra/conf/trojan.go +++ b/infra/conf/trojan.go @@ -52,7 +52,7 @@ func (c *TrojanClientConfig) Build() (proto.Message, error) { return nil, errors.New("Trojan password is not specified.") } if rec.Flow != "" { - return nil, errors.New(`Trojan doesn't support "flow" anymore.`) + return nil, errors.PrintRemovedFeatureError(`Flow for Trojan`, ``) } config.Server[idx] = &protocol.ServerEndpoint{ @@ -106,7 +106,7 @@ func (c *TrojanServerConfig) Build() (proto.Message, error) { for idx, rawUser := range c.Clients { if rawUser.Flow != "" { - return nil, errors.New(`Trojan doesn't support "flow" anymore.`) + return nil, errors.PrintRemovedFeatureError(`Flow for Trojan`, ``) } config.Users[idx] = &protocol.User{ diff --git a/infra/conf/xray.go b/infra/conf/xray.go index 07f702734a96..0b5c60e66f7d 100644 --- a/infra/conf/xray.go +++ b/infra/conf/xray.go @@ -593,7 +593,7 @@ func (c *Config) Build() (*core.Config, error) { } if len(c.Transport) > 0 { - return nil, errors.New("Global transport config is deprecated") + return nil, errors.PrintRemovedFeatureError("Global transport config", "streamSettings in inbounds and outbounds") } for _, rawInboundConfig := range inbounds { diff --git a/proxy/socks/server.go b/proxy/socks/server.go index 571fabb2c547..2b7bca7bd500 100644 --- a/proxy/socks/server.go +++ b/proxy/socks/server.go @@ -16,7 +16,6 @@ import ( "github.com/xtls/xray-core/common/signal" "github.com/xtls/xray-core/common/task" "github.com/xtls/xray-core/core" - "github.com/xtls/xray-core/features" "github.com/xtls/xray-core/features/policy" "github.com/xtls/xray-core/features/routing" "github.com/xtls/xray-core/proxy/http" @@ -56,7 +55,7 @@ func (s *Server) policy() policy.Session { config := s.config p := s.policyManager.ForLevel(config.UserLevel) if config.Timeout > 0 { - features.PrintDeprecatedFeatureWarning("Socks timeout") + errors.PrintDeprecatedFeatureWarning("Socks timeout", "Policy level") } if config.Timeout > 0 && config.UserLevel == 0 { p.Timeouts.ConnectionIdle = time.Duration(config.Timeout) * time.Second