1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-25 21:36:13 -04:00

Move unnecessary functions to internal

This commit is contained in:
v2ray 2016-01-02 23:08:36 +01:00
parent 1c4c9bffad
commit 54ce82fbfa
11 changed files with 90 additions and 77 deletions

View File

@ -5,8 +5,8 @@ import (
"github.com/v2ray/v2ray-core/app"
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/internal"
"github.com/v2ray/v2ray-core/transport/ray"
)
@ -31,7 +31,7 @@ func (this *BlackHole) Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) e
}
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
}); err != nil {
panic(err)

View File

@ -2,12 +2,12 @@ package dokodemo
import (
"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/internal"
)
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)
return NewDokodemoDoor(space, config), nil
}); err != nil {

View File

@ -2,12 +2,12 @@ package freedom
import (
"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/internal"
)
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
}); err != nil {
panic(err)

View File

@ -2,12 +2,12 @@ package http
import (
"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/internal"
)
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
}); err != nil {
panic(err)

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

View File

@ -3,67 +3,15 @@
package proxy
import (
"errors"
"github.com/v2ray/v2ray-core/app"
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
"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) {
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)
return internal.CreateInboundConnectionHandler(name, space, rawConfig)
}
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)
return internal.CreateOutboundConnectionHandler(name, space, rawConfig)
}

View File

@ -2,12 +2,12 @@ package socks
import (
"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/internal"
)
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
}); err != nil {
panic(err)

View File

@ -3,7 +3,6 @@ package testing
import (
"fmt"
"github.com/v2ray/v2ray-core/proxy"
"github.com/v2ray/v2ray-core/proxy/internal"
)
@ -17,8 +16,8 @@ func randomString() string {
func RegisterInboundConnectionHandlerCreator(prefix string, creator internal.InboundConnectionHandlerCreator) (string, error) {
for {
name := prefix + randomString()
err := proxy.RegisterInboundConnectionHandlerFactory(name, creator)
if err != proxy.ErrorNameExists {
err := internal.RegisterInboundConnectionHandlerFactory(name, creator)
if err != internal.ErrorNameExists {
return name, err
}
}
@ -27,8 +26,8 @@ func RegisterInboundConnectionHandlerCreator(prefix string, creator internal.Inb
func RegisterOutboundConnectionHandlerCreator(prefix string, creator internal.OutboundConnectionHandlerCreator) (string, error) {
for {
name := prefix + randomString()
err := proxy.RegisterOutboundConnectionHandlerFactory(name, creator)
if err != proxy.ErrorNameExists {
err := internal.RegisterOutboundConnectionHandlerFactory(name, creator)
if err != internal.ErrorNameExists {
return name, err
}
}

View File

@ -12,8 +12,8 @@ import (
"github.com/v2ray/v2ray-core/common/log"
v2net "github.com/v2ray/v2ray-core/common/net"
"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/internal"
"github.com/v2ray/v2ray-core/proxy/vmess"
"github.com/v2ray/v2ray-core/proxy/vmess/protocol"
"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() {
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)
allowedClients := user.NewTimedUserSet()

View File

@ -6,7 +6,7 @@ import (
"github.com/v2ray/v2ray-core/common/log"
v2net "github.com/v2ray/v2ray-core/common/net"
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"
jsonconfig "github.com/v2ray/v2ray-core/proxy/internal/config/json"
"github.com/v2ray/v2ray-core/proxy/vmess"
@ -31,12 +31,12 @@ func (t *ConfigTarget) UnmarshalJSON(data []byte) error {
}
if len(rawConfig.Users) == 0 {
log.Error("0 user configured for VMess outbound.")
return proxy.ErrorBadConfiguration
return internal.ErrorBadConfiguration
}
t.Users = rawConfig.Users
if rawConfig.Address == nil {
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)
return nil
@ -57,7 +57,7 @@ func (this *Outbound) UnmarshalJSON(data []byte) error {
}
if len(rawOutbound.TargetList) == 0 {
log.Error("0 VMess receiver configured.")
return proxy.ErrorBadConfiguration
return internal.ErrorBadConfiguration
}
this.TargetList = rawOutbound.TargetList
return nil

View File

@ -11,8 +11,8 @@ import (
v2crypto "github.com/v2ray/v2ray-core/common/crypto"
"github.com/v2ray/v2ray-core/common/log"
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/internal"
"github.com/v2ray/v2ray-core/proxy/vmess/protocol"
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
"github.com/v2ray/v2ray-core/transport/ray"
@ -197,7 +197,7 @@ func (this *VMessOutboundHandlerFactory) Create(space app.Space, rawConfig inter
}
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)
return &VMessOutboundHandler{
space: space,