mirror of https://github.com/v2ray/v2ray-core
move function to features
parent
2440d276f1
commit
abf0cb1ec4
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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{}) }
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
2
v2ray.go
2
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
|
||||
|
|
Loading…
Reference in New Issue