mirror of
https://github.com/v2fly/v2ray-core
synced 2024-02-27 03:18:06 +00:00
massive refactoring for kcp
This commit is contained in:
@@ -5,18 +5,19 @@ import (
|
||||
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
"github.com/v2ray/v2ray-core/transport/internet"
|
||||
)
|
||||
|
||||
var (
|
||||
inboundFactories = make(map[string]InboundHandlerCreator)
|
||||
outboundFactories = make(map[string]OutboundHandlerCreator)
|
||||
inboundFactories = make(map[string]InboundHandlerFactory)
|
||||
outboundFactories = make(map[string]OutboundHandlerFactory)
|
||||
|
||||
ErrorProxyNotFound = errors.New("Proxy not found.")
|
||||
ErrorNameExists = errors.New("Proxy with the same name already exists.")
|
||||
ErrorBadConfiguration = errors.New("Bad proxy configuration.")
|
||||
)
|
||||
|
||||
func RegisterInboundHandlerCreator(name string, creator InboundHandlerCreator) error {
|
||||
func RegisterInboundHandlerCreator(name string, creator InboundHandlerFactory) error {
|
||||
if _, found := inboundFactories[name]; found {
|
||||
return ErrorNameExists
|
||||
}
|
||||
@@ -24,13 +25,13 @@ func RegisterInboundHandlerCreator(name string, creator InboundHandlerCreator) e
|
||||
return nil
|
||||
}
|
||||
|
||||
func MustRegisterInboundHandlerCreator(name string, creator InboundHandlerCreator) {
|
||||
func MustRegisterInboundHandlerCreator(name string, creator InboundHandlerFactory) {
|
||||
if err := RegisterInboundHandlerCreator(name, creator); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func RegisterOutboundHandlerCreator(name string, creator OutboundHandlerCreator) error {
|
||||
func RegisterOutboundHandlerCreator(name string, creator OutboundHandlerFactory) error {
|
||||
if _, found := outboundFactories[name]; found {
|
||||
return ErrorNameExists
|
||||
}
|
||||
@@ -38,7 +39,7 @@ func RegisterOutboundHandlerCreator(name string, creator OutboundHandlerCreator)
|
||||
return nil
|
||||
}
|
||||
|
||||
func MustRegisterOutboundHandlerCreator(name string, creator OutboundHandlerCreator) {
|
||||
func MustRegisterOutboundHandlerCreator(name string, creator OutboundHandlerFactory) {
|
||||
if err := RegisterOutboundHandlerCreator(name, creator); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -49,14 +50,22 @@ func CreateInboundHandler(name string, space app.Space, rawConfig []byte, meta *
|
||||
if !found {
|
||||
return nil, ErrorProxyNotFound
|
||||
}
|
||||
if meta.StreamSettings == nil {
|
||||
meta.StreamSettings = &internet.StreamSettings{
|
||||
Type: creator.StreamCapability(),
|
||||
}
|
||||
} else {
|
||||
meta.StreamSettings.Type &= creator.StreamCapability()
|
||||
}
|
||||
|
||||
if len(rawConfig) > 0 {
|
||||
proxyConfig, err := CreateInboundConfig(name, rawConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return creator(space, proxyConfig, meta)
|
||||
return creator.Create(space, proxyConfig, meta)
|
||||
}
|
||||
return creator(space, nil, meta)
|
||||
return creator.Create(space, nil, meta)
|
||||
}
|
||||
|
||||
func CreateOutboundHandler(name string, space app.Space, rawConfig []byte, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
|
||||
@@ -64,14 +73,21 @@ func CreateOutboundHandler(name string, space app.Space, rawConfig []byte, meta
|
||||
if !found {
|
||||
return nil, ErrorProxyNotFound
|
||||
}
|
||||
if meta.StreamSettings == nil {
|
||||
meta.StreamSettings = &internet.StreamSettings{
|
||||
Type: creator.StreamCapability(),
|
||||
}
|
||||
} else {
|
||||
meta.StreamSettings.Type &= creator.StreamCapability()
|
||||
}
|
||||
|
||||
if len(rawConfig) > 0 {
|
||||
proxyConfig, err := CreateOutboundConfig(name, rawConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return creator(space, proxyConfig, meta)
|
||||
return creator.Create(space, proxyConfig, meta)
|
||||
}
|
||||
|
||||
return creator(space, nil, meta)
|
||||
return creator.Create(space, nil, meta)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user