move function to features

This commit is contained in:
Darien Raymond 2018-10-13 15:15:49 +02:00
parent 2440d276f1
commit abf0cb1ec4
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
12 changed files with 25 additions and 9 deletions

View File

@ -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)

View File

@ -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 {

View File

@ -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{}) }

View File

@ -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()
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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()
}

View File

@ -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

View File

@ -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