Browse Source

move function to features

Darien Raymond 7 years ago
parent
commit
abf0cb1ec4

+ 2 - 2
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)

+ 2 - 1
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 {

+ 6 - 0
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{}) }

+ 7 - 0
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()
+}

+ 1 - 0
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)
 }

+ 1 - 0
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)
 }

+ 1 - 0
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)
 }

+ 1 - 0
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)
 }

+ 1 - 0
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)
 }

+ 0 - 4
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()
-}

+ 2 - 1
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

+ 1 - 1
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