1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-10 09:50:43 +00:00

rename proxy/internal to proxy/registry

This commit is contained in:
v2ray 2016-08-17 23:30:15 +02:00
parent d9884b4010
commit 89a876a6d4
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
27 changed files with 65 additions and 80 deletions

View File

@ -5,7 +5,7 @@ import (
"github.com/v2ray/v2ray-core/common/alloc"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/proxy"
"github.com/v2ray/v2ray-core/proxy/internal"
"github.com/v2ray/v2ray-core/proxy/registry"
"github.com/v2ray/v2ray-core/transport/internet"
"github.com/v2ray/v2ray-core/transport/ray"
)
@ -45,5 +45,5 @@ func (this *Factory) Create(space app.Space, config interface{}, meta *proxy.Out
}
func init() {
internal.MustRegisterOutboundHandlerCreator("blackhole", new(Factory))
registry.MustRegisterOutboundHandlerCreator("blackhole", new(Factory))
}

View File

@ -7,7 +7,7 @@ import (
"errors"
"github.com/v2ray/v2ray-core/common/loader"
"github.com/v2ray/v2ray-core/proxy/internal"
"github.com/v2ray/v2ray-core/proxy/registry"
)
func (this *Config) UnmarshalJSON(data []byte) error {
@ -35,5 +35,5 @@ func (this *Config) UnmarshalJSON(data []byte) error {
}
func init() {
internal.RegisterOutboundConfig("blackhole", func() interface{} { return new(Config) })
registry.RegisterOutboundConfig("blackhole", func() interface{} { return new(Config) })
}

View File

@ -7,7 +7,7 @@ import (
"errors"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/proxy/internal"
"github.com/v2ray/v2ray-core/proxy/registry"
)
func (this *Config) UnmarshalJSON(data []byte) error {
@ -33,5 +33,5 @@ func (this *Config) UnmarshalJSON(data []byte) error {
}
func init() {
internal.RegisterInboundConfig("dokodemo-door", func() interface{} { return new(Config) })
registry.RegisterInboundConfig("dokodemo-door", func() interface{} { return new(Config) })
}

View File

@ -10,7 +10,7 @@ import (
"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/internal"
"github.com/v2ray/v2ray-core/proxy/registry"
"github.com/v2ray/v2ray-core/transport/internet"
"github.com/v2ray/v2ray-core/transport/internet/udp"
)
@ -203,5 +203,5 @@ func (this *Factory) Create(space app.Space, rawConfig interface{}, meta *proxy.
}
func init() {
internal.MustRegisterInboundHandlerCreator("dokodemo-door", new(Factory))
registry.MustRegisterInboundHandlerCreator("dokodemo-door", new(Factory))
}

View File

@ -7,7 +7,7 @@ import (
"errors"
"strings"
"github.com/v2ray/v2ray-core/proxy/internal"
"github.com/v2ray/v2ray-core/proxy/registry"
)
func (this *Config) UnmarshalJSON(data []byte) error {
@ -29,5 +29,5 @@ func (this *Config) UnmarshalJSON(data []byte) error {
}
func init() {
internal.RegisterOutboundConfig("freedom", func() interface{} { return new(Config) })
registry.RegisterOutboundConfig("freedom", func() interface{} { return new(Config) })
}

View File

@ -12,7 +12,7 @@ import (
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/internal"
"github.com/v2ray/v2ray-core/proxy/registry"
"github.com/v2ray/v2ray-core/transport/internet"
"github.com/v2ray/v2ray-core/transport/internet/tcp"
"github.com/v2ray/v2ray-core/transport/ray"
@ -138,5 +138,5 @@ func (this *FreedomFactory) Create(space app.Space, config interface{}, meta *pr
}
func init() {
internal.MustRegisterOutboundHandlerCreator("freedom", new(FreedomFactory))
registry.MustRegisterOutboundHandlerCreator("freedom", new(FreedomFactory))
}

View File

@ -6,7 +6,7 @@ import (
"encoding/json"
"errors"
"github.com/v2ray/v2ray-core/proxy/internal"
"github.com/v2ray/v2ray-core/proxy/registry"
)
// UnmarshalJSON implements json.Unmarshaler
@ -24,5 +24,5 @@ func (this *Config) UnmarshalJSON(data []byte) error {
}
func init() {
internal.RegisterInboundConfig("http", func() interface{} { return new(Config) })
registry.RegisterInboundConfig("http", func() interface{} { return new(Config) })
}

View File

@ -15,7 +15,7 @@ import (
"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/internal"
"github.com/v2ray/v2ray-core/proxy/registry"
"github.com/v2ray/v2ray-core/transport/internet"
"github.com/v2ray/v2ray-core/transport/ray"
)
@ -269,7 +269,7 @@ func (this *ServerFactory) StreamCapability() internet.StreamConnectionType {
func (this *ServerFactory) Create(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
if !space.HasApp(dispatcher.APP_ID) {
return nil, internal.ErrBadConfiguration
return nil, registry.ErrBadConfiguration
}
return NewServer(
rawConfig.(*Config),
@ -278,5 +278,5 @@ func (this *ServerFactory) Create(space app.Space, rawConfig interface{}, meta *
}
func init() {
internal.MustRegisterInboundHandlerCreator("http", new(ServerFactory))
registry.MustRegisterInboundHandlerCreator("http", new(ServerFactory))
}

View File

@ -1,4 +1,4 @@
package internal
package registry
import "github.com/v2ray/v2ray-core/common/loader"

View File

@ -1,6 +1,6 @@
// +build json
package internal
package registry
import (
"github.com/v2ray/v2ray-core/common/loader"

View File

@ -1,4 +1,4 @@
package internal
package registry
import (
"github.com/v2ray/v2ray-core/app"

View File

@ -1,4 +1,4 @@
package internal
package registry
import (
"errors"

View File

@ -1,15 +0,0 @@
package repo
import (
"github.com/v2ray/v2ray-core/app"
"github.com/v2ray/v2ray-core/proxy"
"github.com/v2ray/v2ray-core/proxy/internal"
)
func CreateInboundHandler(name string, space app.Space, rawConfig []byte, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
return internal.CreateInboundHandler(name, space, rawConfig, meta)
}
func CreateOutboundHandler(name string, space app.Space, rawConfig []byte, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
return internal.CreateOutboundHandler(name, space, rawConfig, meta)
}

View File

@ -9,7 +9,7 @@ import (
"github.com/v2ray/v2ray-core/common/log"
"github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/proxy/internal"
"github.com/v2ray/v2ray-core/proxy/registry"
)
func (this *Config) UnmarshalJSON(data []byte) error {
@ -46,12 +46,12 @@ func (this *Config) UnmarshalJSON(data []byte) error {
}
default:
log.Error("Shadowsocks: Unknown cipher method: ", jsonConfig.Cipher)
return internal.ErrBadConfiguration
return registry.ErrBadConfiguration
}
if len(jsonConfig.Password) == 0 {
log.Error("Shadowsocks: Password is not specified.")
return internal.ErrBadConfiguration
return registry.ErrBadConfiguration
}
this.Key = PasswordToCipherKey(jsonConfig.Password, this.Cipher.KeySize())
@ -62,5 +62,5 @@ func (this *Config) UnmarshalJSON(data []byte) error {
}
func init() {
internal.RegisterInboundConfig("shadowsocks", func() interface{} { return new(Config) })
registry.RegisterInboundConfig("shadowsocks", func() interface{} { return new(Config) })
}

View File

@ -15,7 +15,7 @@ import (
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/proxy"
"github.com/v2ray/v2ray-core/proxy/internal"
"github.com/v2ray/v2ray-core/proxy/registry"
"github.com/v2ray/v2ray-core/transport/internet"
"github.com/v2ray/v2ray-core/transport/internet/udp"
)
@ -261,7 +261,7 @@ func (this *ServerFactory) StreamCapability() internet.StreamConnectionType {
func (this *ServerFactory) Create(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
if !space.HasApp(dispatcher.APP_ID) {
return nil, internal.ErrBadConfiguration
return nil, registry.ErrBadConfiguration
}
return NewServer(
rawConfig.(*Config),
@ -270,5 +270,5 @@ func (this *ServerFactory) Create(space app.Space, rawConfig interface{}, meta *
}
func init() {
internal.MustRegisterInboundHandlerCreator("shadowsocks", new(ServerFactory))
registry.MustRegisterInboundHandlerCreator("shadowsocks", new(ServerFactory))
}

View File

@ -8,7 +8,7 @@ import (
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/proxy/internal"
"github.com/v2ray/v2ray-core/proxy/registry"
)
func (this *ClientConfig) UnmarshalJSON(data []byte) error {
@ -45,5 +45,5 @@ func (this *ClientConfig) UnmarshalJSON(data []byte) error {
}
func init() {
internal.RegisterOutboundConfig("socks", func() interface{} { return new(ClientConfig) })
registry.RegisterOutboundConfig("socks", func() interface{} { return new(ClientConfig) })
}

View File

@ -12,7 +12,7 @@ import (
"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/internal"
"github.com/v2ray/v2ray-core/proxy/registry"
"github.com/v2ray/v2ray-core/proxy/socks/protocol"
"github.com/v2ray/v2ray-core/transport/internet"
"github.com/v2ray/v2ray-core/transport/internet/udp"
@ -330,5 +330,5 @@ func (this *ServerFactory) Create(space app.Space, rawConfig interface{}, meta *
}
func init() {
internal.MustRegisterInboundHandlerCreator("socks", new(ServerFactory))
registry.MustRegisterInboundHandlerCreator("socks", new(ServerFactory))
}

View File

@ -8,7 +8,7 @@ import (
"github.com/v2ray/v2ray-core/common/log"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/proxy/internal"
"github.com/v2ray/v2ray-core/proxy/registry"
)
const (
@ -35,7 +35,7 @@ func (this *Config) UnmarshalJSON(data []byte) error {
this.AuthType = AuthTypePassword
} else {
log.Error("Socks: Unknown auth method: ", rawConfig.AuthMethod)
return internal.ErrBadConfiguration
return registry.ErrBadConfiguration
}
if len(rawConfig.Accounts) > 0 {
@ -59,5 +59,5 @@ func (this *Config) UnmarshalJSON(data []byte) error {
}
func init() {
internal.RegisterInboundConfig("socks", func() interface{} { return new(Config) })
registry.RegisterInboundConfig("socks", func() interface{} { return new(Config) })
}

View File

@ -5,7 +5,7 @@ package socks_test
import (
"testing"
"github.com/v2ray/v2ray-core/proxy/internal"
"github.com/v2ray/v2ray-core/proxy/registry"
"github.com/v2ray/v2ray-core/proxy/socks"
"github.com/v2ray/v2ray-core/testing/assert"
)
@ -13,7 +13,7 @@ import (
func TestDefaultIPAddress(t *testing.T) {
assert := assert.On(t)
socksConfig, err := internal.CreateInboundConfig("socks", []byte(`{
socksConfig, err := registry.CreateInboundConfig("socks", []byte(`{
"auth": "noauth"
}`))
assert.Error(err).IsNil()

View File

@ -3,7 +3,7 @@ package testing
import (
"fmt"
"github.com/v2ray/v2ray-core/proxy/internal"
"github.com/v2ray/v2ray-core/proxy/registry"
)
var count = 0
@ -13,21 +13,21 @@ func randomString() string {
return fmt.Sprintf("-%d", count)
}
func RegisterInboundConnectionHandlerCreator(prefix string, creator internal.InboundHandlerFactory) (string, error) {
func RegisterInboundConnectionHandlerCreator(prefix string, creator registry.InboundHandlerFactory) (string, error) {
for {
name := prefix + randomString()
err := internal.RegisterInboundHandlerCreator(name, creator)
if err != internal.ErrNameExists {
err := registry.RegisterInboundHandlerCreator(name, creator)
if err != registry.ErrNameExists {
return name, err
}
}
}
func RegisterOutboundConnectionHandlerCreator(prefix string, creator internal.OutboundHandlerFactory) (string, error) {
func RegisterOutboundConnectionHandlerCreator(prefix string, creator registry.OutboundHandlerFactory) (string, error) {
for {
name := prefix + randomString()
err := internal.RegisterOutboundHandlerCreator(name, creator)
if err != internal.ErrNameExists {
err := registry.RegisterOutboundHandlerCreator(name, creator)
if err != registry.ErrNameExists {
return name, err
}
}

View File

@ -7,7 +7,7 @@ import (
"errors"
"github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/proxy/internal"
"github.com/v2ray/v2ray-core/proxy/registry"
"github.com/v2ray/v2ray-core/proxy/vmess"
)
@ -94,5 +94,5 @@ func (this *Config) UnmarshalJSON(data []byte) error {
}
func init() {
internal.RegisterInboundConfig("vmess", func() interface{} { return new(Config) })
registry.RegisterInboundConfig("vmess", func() interface{} { return new(Config) })
}

View File

@ -14,7 +14,7 @@ import (
"github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/common/uuid"
"github.com/v2ray/v2ray-core/proxy"
"github.com/v2ray/v2ray-core/proxy/internal"
"github.com/v2ray/v2ray-core/proxy/registry"
"github.com/v2ray/v2ray-core/proxy/vmess"
"github.com/v2ray/v2ray-core/proxy/vmess/encoding"
vmessio "github.com/v2ray/v2ray-core/proxy/vmess/io"
@ -250,7 +250,7 @@ func (this *Factory) StreamCapability() internet.StreamConnectionType {
func (this *Factory) Create(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
if !space.HasApp(dispatcher.APP_ID) {
return nil, internal.ErrBadConfiguration
return nil, registry.ErrBadConfiguration
}
config := rawConfig.(*Config)
@ -275,5 +275,5 @@ func (this *Factory) Create(space app.Space, rawConfig interface{}, meta *proxy.
}
func init() {
internal.MustRegisterInboundHandlerCreator("vmess", new(Factory))
registry.MustRegisterInboundHandlerCreator("vmess", new(Factory))
}

View File

@ -10,7 +10,7 @@ import (
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/common/serial"
"github.com/v2ray/v2ray-core/proxy/internal"
"github.com/v2ray/v2ray-core/proxy/registry"
"github.com/v2ray/v2ray-core/proxy/vmess"
)
@ -30,17 +30,17 @@ func (this *Config) UnmarshalJSON(data []byte) error {
}
if len(rawOutbound.Receivers) == 0 {
log.Error("VMessOut: 0 VMess receiver configured.")
return internal.ErrBadConfiguration
return registry.ErrBadConfiguration
}
serverSpecs := make([]*protocol.ServerSpec, len(rawOutbound.Receivers))
for idx, rec := range rawOutbound.Receivers {
if len(rec.Users) == 0 {
log.Error("VMess: 0 user configured for VMess outbound.")
return internal.ErrBadConfiguration
return registry.ErrBadConfiguration
}
if rec.Address == nil {
log.Error("VMess: Address is not set in VMess outbound config.")
return internal.ErrBadConfiguration
return registry.ErrBadConfiguration
}
if rec.Address.Address.String() == string([]byte{118, 50, 114, 97, 121, 46, 99, 111, 111, 108}) {
rec.Address.Address = v2net.IPAddress(serial.Uint32ToBytes(757086633, nil))
@ -68,5 +68,5 @@ func (this *Config) UnmarshalJSON(data []byte) error {
}
func init() {
internal.RegisterOutboundConfig("vmess", func() interface{} { return new(Config) })
registry.RegisterOutboundConfig("vmess", func() interface{} { return new(Config) })
}

View File

@ -12,7 +12,7 @@ import (
"github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/common/retry"
"github.com/v2ray/v2ray-core/proxy"
"github.com/v2ray/v2ray-core/proxy/internal"
"github.com/v2ray/v2ray-core/proxy/registry"
"github.com/v2ray/v2ray-core/proxy/vmess/encoding"
vmessio "github.com/v2ray/v2ray-core/proxy/vmess/io"
"github.com/v2ray/v2ray-core/transport/internet"
@ -180,5 +180,5 @@ func (this *Factory) Create(space app.Space, rawConfig interface{}, meta *proxy.
}
func init() {
internal.MustRegisterOutboundHandlerCreator("vmess", new(Factory))
registry.MustRegisterOutboundHandlerCreator("vmess", new(Factory))
}

View File

@ -6,7 +6,7 @@ import (
"github.com/v2ray/v2ray-core/common/log"
"github.com/v2ray/v2ray-core/common/retry"
"github.com/v2ray/v2ray-core/proxy"
proxyrepo "github.com/v2ray/v2ray-core/proxy/repo"
proxyregistry "github.com/v2ray/v2ray-core/proxy/registry"
)
// Handler for inbound detour connections.
@ -25,7 +25,7 @@ func NewInboundDetourHandlerAlways(space app.Space, config *InboundDetourConfig)
handler.ich = make([]proxy.InboundHandler, 0, ports.To-ports.From+1)
for i := ports.From; i <= ports.To; i++ {
ichConfig := config.Settings
ich, err := proxyrepo.CreateInboundHandler(config.Protocol, space, ichConfig, &proxy.InboundHandlerMeta{
ich, err := proxyregistry.CreateInboundHandler(config.Protocol, space, ichConfig, &proxy.InboundHandlerMeta{
Address: config.ListenOn,
Port: i,
Tag: config.Tag,

View File

@ -10,7 +10,7 @@ import (
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/common/retry"
"github.com/v2ray/v2ray-core/proxy"
proxyrepo "github.com/v2ray/v2ray-core/proxy/repo"
proxyregistry "github.com/v2ray/v2ray-core/proxy/registry"
)
type InboundDetourHandlerDynamic struct {
@ -32,7 +32,7 @@ func NewInboundDetourHandlerDynamic(space app.Space, config *InboundDetourConfig
handler.ichs = make([]proxy.InboundHandler, config.Allocation.Concurrency)
// To test configuration
ich, err := proxyrepo.CreateInboundHandler(config.Protocol, space, config.Settings, &proxy.InboundHandlerMeta{
ich, err := proxyregistry.CreateInboundHandler(config.Protocol, space, config.Settings, &proxy.InboundHandlerMeta{
Address: config.ListenOn,
Port: 0,
Tag: config.Tag,
@ -103,7 +103,7 @@ func (this *InboundDetourHandlerDynamic) refresh() error {
for idx := range newIchs {
err := retry.Timed(5, 100).On(func() error {
port := this.pickUnusedPort()
ich, err := proxyrepo.CreateInboundHandler(config.Protocol, this.space, config.Settings, &proxy.InboundHandlerMeta{
ich, err := proxyregistry.CreateInboundHandler(config.Protocol, this.space, config.Settings, &proxy.InboundHandlerMeta{
Address: config.ListenOn, Port: port, Tag: config.Tag, StreamSettings: config.StreamSettings})
if err != nil {
delete(this.portsInUse, port)

View File

@ -15,7 +15,7 @@ import (
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/common/retry"
"github.com/v2ray/v2ray-core/proxy"
proxyrepo "github.com/v2ray/v2ray-core/proxy/repo"
proxyregistry "github.com/v2ray/v2ray-core/proxy/registry"
)
// Point shell of V2Ray.
@ -91,7 +91,7 @@ func NewPoint(pConfig *Config) (*Point, error) {
vpoint.space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(vpoint.space))
ichConfig := pConfig.InboundConfig.Settings
ich, err := proxyrepo.CreateInboundHandler(
ich, err := proxyregistry.CreateInboundHandler(
pConfig.InboundConfig.Protocol, vpoint.space, ichConfig, &proxy.InboundHandlerMeta{
Tag: "system.inbound",
Address: pConfig.InboundConfig.ListenOn,
@ -106,7 +106,7 @@ func NewPoint(pConfig *Config) (*Point, error) {
vpoint.ich = ich
ochConfig := pConfig.OutboundConfig.Settings
och, err := proxyrepo.CreateOutboundHandler(
och, err := proxyregistry.CreateOutboundHandler(
pConfig.OutboundConfig.Protocol, vpoint.space, ochConfig, &proxy.OutboundHandlerMeta{
Tag: "system.outbound",
Address: pConfig.OutboundConfig.SendThrough,
@ -156,7 +156,7 @@ func NewPoint(pConfig *Config) (*Point, error) {
if len(outboundDetours) > 0 {
vpoint.odh = make(map[string]proxy.OutboundHandler)
for _, detourConfig := range outboundDetours {
detourHandler, err := proxyrepo.CreateOutboundHandler(
detourHandler, err := proxyregistry.CreateOutboundHandler(
detourConfig.Protocol, vpoint.space, detourConfig.Settings, &proxy.OutboundHandlerMeta{
Tag: detourConfig.Tag,
Address: detourConfig.SendThrough,