mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-12 07:19:01 -05:00
Move unnecessary functions to internal
This commit is contained in:
parent
1c4c9bffad
commit
54ce82fbfa
@ -5,8 +5,8 @@ import (
|
|||||||
|
|
||||||
"github.com/v2ray/v2ray-core/app"
|
"github.com/v2ray/v2ray-core/app"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
"github.com/v2ray/v2ray-core/proxy"
|
|
||||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||||
"github.com/v2ray/v2ray-core/transport/ray"
|
"github.com/v2ray/v2ray-core/transport/ray"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ func (this *BlackHole) Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) e
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if err := proxy.RegisterOutboundConnectionHandlerFactory("blackhole", func(space app.Space, config interface{}) (connhandler.OutboundConnectionHandler, error) {
|
if err := internal.RegisterOutboundConnectionHandlerFactory("blackhole", func(space app.Space, config interface{}) (connhandler.OutboundConnectionHandler, error) {
|
||||||
return NewBlackHole(), nil
|
return NewBlackHole(), nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -2,12 +2,12 @@ package dokodemo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/v2ray/v2ray-core/app"
|
"github.com/v2ray/v2ray-core/app"
|
||||||
"github.com/v2ray/v2ray-core/proxy"
|
|
||||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if err := proxy.RegisterInboundConnectionHandlerFactory("dokodemo-door", func(space app.Space, rawConfig interface{}) (connhandler.InboundConnectionHandler, error) {
|
if err := internal.RegisterInboundConnectionHandlerFactory("dokodemo-door", func(space app.Space, rawConfig interface{}) (connhandler.InboundConnectionHandler, error) {
|
||||||
config := rawConfig.(Config)
|
config := rawConfig.(Config)
|
||||||
return NewDokodemoDoor(space, config), nil
|
return NewDokodemoDoor(space, config), nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
@ -2,12 +2,12 @@ package freedom
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/v2ray/v2ray-core/app"
|
"github.com/v2ray/v2ray-core/app"
|
||||||
"github.com/v2ray/v2ray-core/proxy"
|
|
||||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if err := proxy.RegisterOutboundConnectionHandlerFactory("freedom", func(space app.Space, config interface{}) (connhandler.OutboundConnectionHandler, error) {
|
if err := internal.RegisterOutboundConnectionHandlerFactory("freedom", func(space app.Space, config interface{}) (connhandler.OutboundConnectionHandler, error) {
|
||||||
return &FreedomConnection{space: space}, nil
|
return &FreedomConnection{space: space}, nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -2,12 +2,12 @@ package http
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/v2ray/v2ray-core/app"
|
"github.com/v2ray/v2ray-core/app"
|
||||||
"github.com/v2ray/v2ray-core/proxy"
|
|
||||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if err := proxy.RegisterInboundConnectionHandlerFactory("http", func(space app.Space, rawConfig interface{}) (connhandler.InboundConnectionHandler, error) {
|
if err := internal.RegisterInboundConnectionHandlerFactory("http", func(space app.Space, rawConfig interface{}) (connhandler.InboundConnectionHandler, error) {
|
||||||
return NewHttpProxyServer(space, rawConfig.(Config)), nil
|
return NewHttpProxyServer(space, rawConfig.(Config)), nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
66
proxy/internal/handler_cache.go
Normal file
66
proxy/internal/handler_cache.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/v2ray/v2ray-core/app"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy/internal/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
inboundFactories = make(map[string]InboundConnectionHandlerCreator)
|
||||||
|
outboundFactories = make(map[string]OutboundConnectionHandlerCreator)
|
||||||
|
|
||||||
|
ErrorProxyNotFound = errors.New("Proxy not found.")
|
||||||
|
ErrorNameExists = errors.New("Proxy with the same name already exists.")
|
||||||
|
ErrorBadConfiguration = errors.New("Bad proxy configuration.")
|
||||||
|
)
|
||||||
|
|
||||||
|
func RegisterInboundConnectionHandlerFactory(name string, creator InboundConnectionHandlerCreator) error {
|
||||||
|
if _, found := inboundFactories[name]; found {
|
||||||
|
return ErrorNameExists
|
||||||
|
}
|
||||||
|
inboundFactories[name] = creator
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterOutboundConnectionHandlerFactory(name string, creator OutboundConnectionHandlerCreator) error {
|
||||||
|
if _, found := outboundFactories[name]; found {
|
||||||
|
return ErrorNameExists
|
||||||
|
}
|
||||||
|
outboundFactories[name] = creator
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateInboundConnectionHandler(name string, space app.Space, rawConfig []byte) (connhandler.InboundConnectionHandler, error) {
|
||||||
|
creator, found := inboundFactories[name]
|
||||||
|
if !found {
|
||||||
|
return nil, ErrorProxyNotFound
|
||||||
|
}
|
||||||
|
if len(rawConfig) > 0 {
|
||||||
|
proxyConfig, err := config.CreateInboundConnectionConfig(name, rawConfig)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return creator(space, proxyConfig)
|
||||||
|
}
|
||||||
|
return creator(space, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateOutboundConnectionHandler(name string, space app.Space, rawConfig []byte) (connhandler.OutboundConnectionHandler, error) {
|
||||||
|
creator, found := outboundFactories[name]
|
||||||
|
if !found {
|
||||||
|
return nil, ErrorNameExists
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(rawConfig) > 0 {
|
||||||
|
proxyConfig, err := config.CreateOutboundConnectionConfig(name, rawConfig)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return creator(space, proxyConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
return creator(space, nil)
|
||||||
|
}
|
@ -3,67 +3,15 @@
|
|||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core/app"
|
"github.com/v2ray/v2ray-core/app"
|
||||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||||
"github.com/v2ray/v2ray-core/proxy/internal"
|
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||||
"github.com/v2ray/v2ray-core/proxy/internal/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
inboundFactories = make(map[string]internal.InboundConnectionHandlerCreator)
|
|
||||||
outboundFactories = make(map[string]internal.OutboundConnectionHandlerCreator)
|
|
||||||
|
|
||||||
ErrorProxyNotFound = errors.New("Proxy not found.")
|
|
||||||
ErrorNameExists = errors.New("Proxy with the same name already exists.")
|
|
||||||
ErrorBadConfiguration = errors.New("Bad proxy configuration.")
|
|
||||||
)
|
|
||||||
|
|
||||||
func RegisterInboundConnectionHandlerFactory(name string, creator internal.InboundConnectionHandlerCreator) error {
|
|
||||||
if _, found := inboundFactories[name]; found {
|
|
||||||
return ErrorNameExists
|
|
||||||
}
|
|
||||||
inboundFactories[name] = creator
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterOutboundConnectionHandlerFactory(name string, creator internal.OutboundConnectionHandlerCreator) error {
|
|
||||||
if _, found := outboundFactories[name]; found {
|
|
||||||
return ErrorNameExists
|
|
||||||
}
|
|
||||||
outboundFactories[name] = creator
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func CreateInboundConnectionHandler(name string, space app.Space, rawConfig []byte) (connhandler.InboundConnectionHandler, error) {
|
func CreateInboundConnectionHandler(name string, space app.Space, rawConfig []byte) (connhandler.InboundConnectionHandler, error) {
|
||||||
creator, found := inboundFactories[name]
|
return internal.CreateInboundConnectionHandler(name, space, rawConfig)
|
||||||
if !found {
|
|
||||||
return nil, ErrorProxyNotFound
|
|
||||||
}
|
|
||||||
if len(rawConfig) > 0 {
|
|
||||||
proxyConfig, err := config.CreateInboundConnectionConfig(name, rawConfig)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return creator(space, proxyConfig)
|
|
||||||
}
|
|
||||||
return creator(space, nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateOutboundConnectionHandler(name string, space app.Space, rawConfig []byte) (connhandler.OutboundConnectionHandler, error) {
|
func CreateOutboundConnectionHandler(name string, space app.Space, rawConfig []byte) (connhandler.OutboundConnectionHandler, error) {
|
||||||
creator, found := outboundFactories[name]
|
return internal.CreateOutboundConnectionHandler(name, space, rawConfig)
|
||||||
if !found {
|
|
||||||
return nil, ErrorNameExists
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(rawConfig) > 0 {
|
|
||||||
proxyConfig, err := config.CreateOutboundConnectionConfig(name, rawConfig)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return creator(space, proxyConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
return creator(space, nil)
|
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,12 @@ package socks
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/v2ray/v2ray-core/app"
|
"github.com/v2ray/v2ray-core/app"
|
||||||
"github.com/v2ray/v2ray-core/proxy"
|
|
||||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if err := proxy.RegisterInboundConnectionHandlerFactory("socks", func(space app.Space, rawConfig interface{}) (connhandler.InboundConnectionHandler, error) {
|
if err := internal.RegisterInboundConnectionHandlerFactory("socks", func(space app.Space, rawConfig interface{}) (connhandler.InboundConnectionHandler, error) {
|
||||||
return NewSocksServer(space, rawConfig.(Config)), nil
|
return NewSocksServer(space, rawConfig.(Config)), nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -3,7 +3,6 @@ package testing
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core/proxy"
|
|
||||||
"github.com/v2ray/v2ray-core/proxy/internal"
|
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -17,8 +16,8 @@ func randomString() string {
|
|||||||
func RegisterInboundConnectionHandlerCreator(prefix string, creator internal.InboundConnectionHandlerCreator) (string, error) {
|
func RegisterInboundConnectionHandlerCreator(prefix string, creator internal.InboundConnectionHandlerCreator) (string, error) {
|
||||||
for {
|
for {
|
||||||
name := prefix + randomString()
|
name := prefix + randomString()
|
||||||
err := proxy.RegisterInboundConnectionHandlerFactory(name, creator)
|
err := internal.RegisterInboundConnectionHandlerFactory(name, creator)
|
||||||
if err != proxy.ErrorNameExists {
|
if err != internal.ErrorNameExists {
|
||||||
return name, err
|
return name, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -27,8 +26,8 @@ func RegisterInboundConnectionHandlerCreator(prefix string, creator internal.Inb
|
|||||||
func RegisterOutboundConnectionHandlerCreator(prefix string, creator internal.OutboundConnectionHandlerCreator) (string, error) {
|
func RegisterOutboundConnectionHandlerCreator(prefix string, creator internal.OutboundConnectionHandlerCreator) (string, error) {
|
||||||
for {
|
for {
|
||||||
name := prefix + randomString()
|
name := prefix + randomString()
|
||||||
err := proxy.RegisterOutboundConnectionHandlerFactory(name, creator)
|
err := internal.RegisterOutboundConnectionHandlerFactory(name, creator)
|
||||||
if err != proxy.ErrorNameExists {
|
if err != internal.ErrorNameExists {
|
||||||
return name, err
|
return name, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ import (
|
|||||||
"github.com/v2ray/v2ray-core/common/log"
|
"github.com/v2ray/v2ray-core/common/log"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
"github.com/v2ray/v2ray-core/common/retry"
|
"github.com/v2ray/v2ray-core/common/retry"
|
||||||
"github.com/v2ray/v2ray-core/proxy"
|
|
||||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess"
|
"github.com/v2ray/v2ray-core/proxy/vmess"
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/protocol"
|
"github.com/v2ray/v2ray-core/proxy/vmess/protocol"
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
|
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
|
||||||
@ -141,7 +141,7 @@ func handleOutput(request *protocol.VMessRequest, writer io.Writer, output <-cha
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if err := proxy.RegisterInboundConnectionHandlerFactory("vmess", func(space app.Space, rawConfig interface{}) (connhandler.InboundConnectionHandler, error) {
|
if err := internal.RegisterInboundConnectionHandlerFactory("vmess", func(space app.Space, rawConfig interface{}) (connhandler.InboundConnectionHandler, error) {
|
||||||
config := rawConfig.(Config)
|
config := rawConfig.(Config)
|
||||||
|
|
||||||
allowedClients := user.NewTimedUserSet()
|
allowedClients := user.NewTimedUserSet()
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/v2ray/v2ray-core/common/log"
|
"github.com/v2ray/v2ray-core/common/log"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
v2netjson "github.com/v2ray/v2ray-core/common/net/json"
|
v2netjson "github.com/v2ray/v2ray-core/common/net/json"
|
||||||
"github.com/v2ray/v2ray-core/proxy"
|
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||||
proxyconfig "github.com/v2ray/v2ray-core/proxy/internal/config"
|
proxyconfig "github.com/v2ray/v2ray-core/proxy/internal/config"
|
||||||
jsonconfig "github.com/v2ray/v2ray-core/proxy/internal/config/json"
|
jsonconfig "github.com/v2ray/v2ray-core/proxy/internal/config/json"
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess"
|
"github.com/v2ray/v2ray-core/proxy/vmess"
|
||||||
@ -31,12 +31,12 @@ func (t *ConfigTarget) UnmarshalJSON(data []byte) error {
|
|||||||
}
|
}
|
||||||
if len(rawConfig.Users) == 0 {
|
if len(rawConfig.Users) == 0 {
|
||||||
log.Error("0 user configured for VMess outbound.")
|
log.Error("0 user configured for VMess outbound.")
|
||||||
return proxy.ErrorBadConfiguration
|
return internal.ErrorBadConfiguration
|
||||||
}
|
}
|
||||||
t.Users = rawConfig.Users
|
t.Users = rawConfig.Users
|
||||||
if rawConfig.Address == nil {
|
if rawConfig.Address == nil {
|
||||||
log.Error("Address is not set in VMess outbound config.")
|
log.Error("Address is not set in VMess outbound config.")
|
||||||
return proxy.ErrorBadConfiguration
|
return internal.ErrorBadConfiguration
|
||||||
}
|
}
|
||||||
t.Destination = v2net.TCPDestination(rawConfig.Address.Address(), rawConfig.Port)
|
t.Destination = v2net.TCPDestination(rawConfig.Address.Address(), rawConfig.Port)
|
||||||
return nil
|
return nil
|
||||||
@ -57,7 +57,7 @@ func (this *Outbound) UnmarshalJSON(data []byte) error {
|
|||||||
}
|
}
|
||||||
if len(rawOutbound.TargetList) == 0 {
|
if len(rawOutbound.TargetList) == 0 {
|
||||||
log.Error("0 VMess receiver configured.")
|
log.Error("0 VMess receiver configured.")
|
||||||
return proxy.ErrorBadConfiguration
|
return internal.ErrorBadConfiguration
|
||||||
}
|
}
|
||||||
this.TargetList = rawOutbound.TargetList
|
this.TargetList = rawOutbound.TargetList
|
||||||
return nil
|
return nil
|
||||||
|
@ -11,8 +11,8 @@ import (
|
|||||||
v2crypto "github.com/v2ray/v2ray-core/common/crypto"
|
v2crypto "github.com/v2ray/v2ray-core/common/crypto"
|
||||||
"github.com/v2ray/v2ray-core/common/log"
|
"github.com/v2ray/v2ray-core/common/log"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
"github.com/v2ray/v2ray-core/proxy"
|
|
||||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/protocol"
|
"github.com/v2ray/v2ray-core/proxy/vmess/protocol"
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
|
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
|
||||||
"github.com/v2ray/v2ray-core/transport/ray"
|
"github.com/v2ray/v2ray-core/transport/ray"
|
||||||
@ -197,7 +197,7 @@ func (this *VMessOutboundHandlerFactory) Create(space app.Space, rawConfig inter
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if err := proxy.RegisterOutboundConnectionHandlerFactory("vmess", func(space app.Space, rawConfig interface{}) (connhandler.OutboundConnectionHandler, error) {
|
if err := internal.RegisterOutboundConnectionHandlerFactory("vmess", func(space app.Space, rawConfig interface{}) (connhandler.OutboundConnectionHandler, error) {
|
||||||
vOutConfig := rawConfig.(Config)
|
vOutConfig := rawConfig.(Config)
|
||||||
return &VMessOutboundHandler{
|
return &VMessOutboundHandler{
|
||||||
space: space,
|
space: space,
|
||||||
|
Loading…
Reference in New Issue
Block a user