diff --git a/app/dns/hosts.go b/app/dns/hosts.go index 3bc8d087..70e59299 100644 --- a/app/dns/hosts.go +++ b/app/dns/hosts.go @@ -1,10 +1,10 @@ package dns import ( - "v2ray.com/core" "v2ray.com/core/common" "v2ray.com/core/common/net" "v2ray.com/core/common/strmatcher" + "v2ray.com/core/features" ) type StaticHosts struct { @@ -39,7 +39,7 @@ func NewStaticHosts(hosts []*Config_HostMapping, legacy map[string]*net.IPOrDoma } if legacy != nil { - core.PrintDeprecatedFeatureWarning("simple host mapping") + features.PrintDeprecatedFeatureWarning("simple host mapping") for domain, ip := range legacy { matcher, err := strmatcher.Full.New(domain) diff --git a/app/dns/server.go b/app/dns/server.go index ce5afe34..4d75edd5 100644 --- a/app/dns/server.go +++ b/app/dns/server.go @@ -11,6 +11,7 @@ import ( "v2ray.com/core/common" "v2ray.com/core/common/net" "v2ray.com/core/common/strmatcher" + "v2ray.com/core/features" "v2ray.com/core/features/dns" ) @@ -62,7 +63,7 @@ func New(ctx context.Context, config *Config) (*Server, error) { } if len(config.NameServers) > 0 { - core.PrintDeprecatedFeatureWarning("simple DNS server") + features.PrintDeprecatedFeatureWarning("simple DNS server") } for _, destPB := range config.NameServers { diff --git a/features/errors.generated.go b/features/errors.generated.go new file mode 100644 index 00000000..3d416f4f --- /dev/null +++ b/features/errors.generated.go @@ -0,0 +1,6 @@ +package features + +import "v2ray.com/core/common/errors" + +type errPathObjHolder struct {} +func newError(values ...interface{}) *errors.Error { return errors.New(values...).WithPathObj(errPathObjHolder{}) } diff --git a/features/feature.go b/features/feature.go index 2ee1c0c7..ac7b77a7 100644 --- a/features/feature.go +++ b/features/feature.go @@ -2,9 +2,16 @@ package features import "v2ray.com/core/common" +//go:generate errorgen + // Feature is the interface for V2Ray 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) { + newError("You are using a deprecated feature: " + feature + ". Please update your config file with latest configuration format, or update your client software.").WriteToLog() +} diff --git a/features/outbound/outbound.go b/features/outbound/outbound.go index b79fcf4f..781ab0c9 100644 --- a/features/outbound/outbound.go +++ b/features/outbound/outbound.go @@ -29,6 +29,7 @@ type Manager interface { RemoveHandler(ctx context.Context, tag string) error } +// ManagerType returns the type of Manager interface. Can be used to implement common.HasType. func ManagerType() interface{} { return (*Manager)(nil) } diff --git a/features/policy/policy.go b/features/policy/policy.go index 65908815..a93f5b82 100644 --- a/features/policy/policy.go +++ b/features/policy/policy.go @@ -67,6 +67,7 @@ type Manager interface { ForSystem() System } +// ManagerType returns the type of Manager interface. Can be used to implement common.HasType. func ManagerType() interface{} { return (*Manager)(nil) } diff --git a/features/routing/dispatcher.go b/features/routing/dispatcher.go index 133043ea..62ec5599 100644 --- a/features/routing/dispatcher.go +++ b/features/routing/dispatcher.go @@ -17,6 +17,7 @@ type Dispatcher interface { Dispatch(ctx context.Context, dest net.Destination) (*vio.Link, error) } +// DispatcherType returns the type of Dispatcher interface. Can be used to implement common.HasType. func DispatcherType() interface{} { return (*Dispatcher)(nil) } diff --git a/features/routing/router.go b/features/routing/router.go index 748b6024..1276e25f 100644 --- a/features/routing/router.go +++ b/features/routing/router.go @@ -14,6 +14,7 @@ type Router interface { PickRoute(ctx context.Context) (string, error) } +// RouterType return the type of Router interface. Can be used to implement common.HasType. func RouterType() interface{} { return (*Router)(nil) } diff --git a/features/stats/stats.go b/features/stats/stats.go index e1e00891..13c84baf 100644 --- a/features/stats/stats.go +++ b/features/stats/stats.go @@ -25,6 +25,7 @@ func GetOrRegisterCounter(m Manager, name string) (Counter, error) { return m.RegisterCounter(name) } +// ManagerType returns the type of Manager interface. Can be used to implement common.HasType. func ManagerType() interface{} { return (*Manager)(nil) } diff --git a/functions.go b/functions.go index bea82dcc..65cbe745 100644 --- a/functions.go +++ b/functions.go @@ -33,7 +33,3 @@ func StartInstance(configFormat string, configBytes []byte) (*Instance, error) { } return instance, nil } - -func PrintDeprecatedFeatureWarning(feature string) { - newError("You are using a deprecated feature: " + feature + ". Please update your config file with latest configuration format, or update your client software.").WriteToLog() -} diff --git a/proxy/socks/server.go b/proxy/socks/server.go index 11c2338b..3dd30d11 100644 --- a/proxy/socks/server.go +++ b/proxy/socks/server.go @@ -14,6 +14,7 @@ import ( "v2ray.com/core/common/session" "v2ray.com/core/common/signal" "v2ray.com/core/common/task" + "v2ray.com/core/features" "v2ray.com/core/features/policy" "v2ray.com/core/features/routing" "v2ray.com/core/transport/internet" @@ -40,7 +41,7 @@ func (s *Server) policy() policy.Session { config := s.config p := s.v.PolicyManager().ForLevel(config.UserLevel) if config.Timeout > 0 { - core.PrintDeprecatedFeatureWarning("Socks timeout") + features.PrintDeprecatedFeatureWarning("Socks timeout") } if config.Timeout > 0 && config.UserLevel == 0 { p.Timeouts.ConnectionIdle = time.Duration(config.Timeout) * time.Second diff --git a/v2ray.go b/v2ray.go index 22b22486..64ce8b24 100755 --- a/v2ray.go +++ b/v2ray.go @@ -47,7 +47,7 @@ func New(config *Config) (*Instance, error) { } if config.Transport != nil { - PrintDeprecatedFeatureWarning("global transport settings") + features.PrintDeprecatedFeatureWarning("global transport settings") } if err := config.Transport.Apply(); err != nil { return nil, err