From f93b29993b487d83bfcf21b5eb67581bdc65a356 Mon Sep 17 00:00:00 2001 From: V2Ray Date: Fri, 30 Oct 2015 00:11:29 +0100 Subject: [PATCH] Move connection handler interfaces to proxy/common/connhandler --- app/point/point.go | 10 +++++----- proxy/blackhole/blackhole.go | 6 +++--- proxy/{ => common/connhandler}/inbound_connection.go | 2 +- .../{ => common/connhandler}/outbound_connection.go | 2 +- proxy/{ => common/connhandler}/proxy_cache.go | 2 +- proxy/freedom/freedom_test.go | 4 ++-- proxy/freedom/freedomfactory.go | 6 +++--- proxy/socks/socks_test.go | 12 ++++++------ proxy/socks/socksfactory.go | 6 +++--- proxy/vmess/vmess_test.go | 10 +++++----- proxy/vmess/vmessin.go | 6 +++--- proxy/vmess/vmessout.go | 6 +++--- testing/mocks/inboundhandler.go | 4 ++-- testing/mocks/outboundhandler.go | 4 ++-- 14 files changed, 40 insertions(+), 40 deletions(-) rename proxy/{ => common/connhandler}/inbound_connection.go (96%) rename proxy/{ => common/connhandler}/outbound_connection.go (96%) rename proxy/{ => common/connhandler}/proxy_cache.go (97%) diff --git a/app/point/point.go b/app/point/point.go index 9aba39cc3..844f59a3c 100644 --- a/app/point/point.go +++ b/app/point/point.go @@ -5,15 +5,15 @@ import ( v2net "github.com/v2ray/v2ray-core/common/net" "github.com/v2ray/v2ray-core/common/retry" "github.com/v2ray/v2ray-core/config" - "github.com/v2ray/v2ray-core/proxy" + "github.com/v2ray/v2ray-core/proxy/common/connhandler" "github.com/v2ray/v2ray-core/transport/ray" ) // Point is an single server in V2Ray system. type Point struct { port uint16 - ich proxy.InboundConnectionHandler - och proxy.OutboundConnectionHandler + ich connhandler.InboundConnectionHandler + och connhandler.OutboundConnectionHandler } // NewPoint returns a new Point server based on given configuration. @@ -22,7 +22,7 @@ func NewPoint(pConfig config.PointConfig) (*Point, error) { var vpoint = new(Point) vpoint.port = pConfig.Port() - ichFactory := proxy.GetInboundConnectionHandlerFactory(pConfig.InboundConfig().Protocol()) + ichFactory := connhandler.GetInboundConnectionHandlerFactory(pConfig.InboundConfig().Protocol()) if ichFactory == nil { log.Error("Unknown inbound connection handler factory %s", pConfig.InboundConfig().Protocol()) return nil, config.BadConfiguration @@ -35,7 +35,7 @@ func NewPoint(pConfig config.PointConfig) (*Point, error) { } vpoint.ich = ich - ochFactory := proxy.GetOutboundConnectionHandlerFactory(pConfig.OutboundConfig().Protocol()) + ochFactory := connhandler.GetOutboundConnectionHandlerFactory(pConfig.OutboundConfig().Protocol()) if ochFactory == nil { log.Error("Unknown outbound connection handler factory %s", pConfig.OutboundConfig().Protocol()) return nil, config.BadConfiguration diff --git a/proxy/blackhole/blackhole.go b/proxy/blackhole/blackhole.go index 16659e665..717dc9de7 100644 --- a/proxy/blackhole/blackhole.go +++ b/proxy/blackhole/blackhole.go @@ -4,7 +4,7 @@ import ( "io/ioutil" 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/transport/ray" ) @@ -31,10 +31,10 @@ func (bh *BlackHole) Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) err type BlackHoleFactory struct { } -func (factory BlackHoleFactory) Create(config interface{}) (proxy.OutboundConnectionHandler, error) { +func (factory BlackHoleFactory) Create(config interface{}) (connhandler.OutboundConnectionHandler, error) { return NewBlackHole(), nil } func init() { - proxy.RegisterOutboundConnectionHandlerFactory("blackhole", BlackHoleFactory{}) + connhandler.RegisterOutboundConnectionHandlerFactory("blackhole", BlackHoleFactory{}) } diff --git a/proxy/inbound_connection.go b/proxy/common/connhandler/inbound_connection.go similarity index 96% rename from proxy/inbound_connection.go rename to proxy/common/connhandler/inbound_connection.go index 2ad25595c..6afb3bb52 100644 --- a/proxy/inbound_connection.go +++ b/proxy/common/connhandler/inbound_connection.go @@ -1,4 +1,4 @@ -package proxy +package connhandler import ( "github.com/v2ray/v2ray-core/app" diff --git a/proxy/outbound_connection.go b/proxy/common/connhandler/outbound_connection.go similarity index 96% rename from proxy/outbound_connection.go rename to proxy/common/connhandler/outbound_connection.go index 67fd89964..651321e59 100644 --- a/proxy/outbound_connection.go +++ b/proxy/common/connhandler/outbound_connection.go @@ -1,4 +1,4 @@ -package proxy +package connhandler import ( v2net "github.com/v2ray/v2ray-core/common/net" diff --git a/proxy/proxy_cache.go b/proxy/common/connhandler/proxy_cache.go similarity index 97% rename from proxy/proxy_cache.go rename to proxy/common/connhandler/proxy_cache.go index 004b49d84..40957a834 100644 --- a/proxy/proxy_cache.go +++ b/proxy/common/connhandler/proxy_cache.go @@ -1,4 +1,4 @@ -package proxy +package connhandler var ( inboundFactories = make(map[string]InboundConnectionHandlerFactory) diff --git a/proxy/freedom/freedom_test.go b/proxy/freedom/freedom_test.go index 7d424bebd..99544cff3 100644 --- a/proxy/freedom/freedom_test.go +++ b/proxy/freedom/freedom_test.go @@ -11,7 +11,7 @@ import ( "github.com/v2ray/v2ray-core/app/point" "github.com/v2ray/v2ray-core/common/alloc" v2net "github.com/v2ray/v2ray-core/common/net" - v2proxy "github.com/v2ray/v2ray-core/proxy" + "github.com/v2ray/v2ray-core/proxy/common/connhandler" _ "github.com/v2ray/v2ray-core/proxy/socks" "github.com/v2ray/v2ray-core/proxy/socks/config/json" "github.com/v2ray/v2ray-core/testing/mocks" @@ -43,7 +43,7 @@ func TestUDPSend(t *testing.T) { DataReturned: bytes.NewBuffer(make([]byte, 0, 1024)), } - v2proxy.RegisterInboundConnectionHandlerFactory("mock_ich", ich) + connhandler.RegisterInboundConnectionHandlerFactory("mock_ich", ich) pointPort := uint16(38724) config := mocks.Config{ diff --git a/proxy/freedom/freedomfactory.go b/proxy/freedom/freedomfactory.go index e1b2612dc..96eef339d 100644 --- a/proxy/freedom/freedomfactory.go +++ b/proxy/freedom/freedomfactory.go @@ -1,16 +1,16 @@ package freedom import ( - "github.com/v2ray/v2ray-core/proxy" + "github.com/v2ray/v2ray-core/proxy/common/connhandler" ) type FreedomFactory struct { } -func (factory FreedomFactory) Create(config interface{}) (proxy.OutboundConnectionHandler, error) { +func (factory FreedomFactory) Create(config interface{}) (connhandler.OutboundConnectionHandler, error) { return NewFreedomConnection(), nil } func init() { - proxy.RegisterOutboundConnectionHandlerFactory("freedom", FreedomFactory{}) + connhandler.RegisterOutboundConnectionHandlerFactory("freedom", FreedomFactory{}) } diff --git a/proxy/socks/socks_test.go b/proxy/socks/socks_test.go index 8975be41c..228e5bb33 100644 --- a/proxy/socks/socks_test.go +++ b/proxy/socks/socks_test.go @@ -9,7 +9,7 @@ import ( "golang.org/x/net/proxy" "github.com/v2ray/v2ray-core/app/point" - v2proxy "github.com/v2ray/v2ray-core/proxy" + "github.com/v2ray/v2ray-core/proxy/common/connhandler" "github.com/v2ray/v2ray-core/proxy/socks/config/json" "github.com/v2ray/v2ray-core/testing/mocks" "github.com/v2ray/v2ray-core/testing/unit" @@ -24,7 +24,7 @@ func TestSocksTcpConnect(t *testing.T) { Data2Return: []byte("The data to be returned to socks server."), } - v2proxy.RegisterOutboundConnectionHandlerFactory("mock_och", och) + connhandler.RegisterOutboundConnectionHandlerFactory("mock_och", och) config := mocks.Config{ PortValue: port, @@ -77,7 +77,7 @@ func TestSocksTcpConnectWithUserPass(t *testing.T) { Data2Return: []byte("The data to be returned to socks server."), } - v2proxy.RegisterOutboundConnectionHandlerFactory("mock_och", och) + connhandler.RegisterOutboundConnectionHandlerFactory("mock_och", och) config := mocks.Config{ PortValue: port, @@ -136,7 +136,7 @@ func TestSocksTcpConnectWithWrongUserPass(t *testing.T) { Data2Return: []byte("The data to be returned to socks server."), } - v2proxy.RegisterOutboundConnectionHandlerFactory("mock_och", och) + connhandler.RegisterOutboundConnectionHandlerFactory("mock_och", och) config := mocks.Config{ PortValue: port, @@ -181,7 +181,7 @@ func TestSocksTcpConnectWithWrongAuthMethod(t *testing.T) { Data2Return: []byte("The data to be returned to socks server."), } - v2proxy.RegisterOutboundConnectionHandlerFactory("mock_och", och) + connhandler.RegisterOutboundConnectionHandlerFactory("mock_och", och) config := mocks.Config{ PortValue: port, @@ -226,7 +226,7 @@ func TestSocksUdpSend(t *testing.T) { Data2Return: []byte("The data to be returned to socks server."), } - v2proxy.RegisterOutboundConnectionHandlerFactory("mock_och", och) + connhandler.RegisterOutboundConnectionHandlerFactory("mock_och", och) config := mocks.Config{ PortValue: port, diff --git a/proxy/socks/socksfactory.go b/proxy/socks/socksfactory.go index 0fd3e161b..0682f8870 100644 --- a/proxy/socks/socksfactory.go +++ b/proxy/socks/socksfactory.go @@ -2,19 +2,19 @@ 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/socks/config/json" ) type SocksServerFactory struct { } -func (factory SocksServerFactory) Create(dispatcher app.PacketDispatcher, rawConfig interface{}) (proxy.InboundConnectionHandler, error) { +func (factory SocksServerFactory) Create(dispatcher app.PacketDispatcher, rawConfig interface{}) (connhandler.InboundConnectionHandler, error) { config := rawConfig.(*json.SocksConfig) config.Initialize() return NewSocksServer(dispatcher, config), nil } func init() { - proxy.RegisterInboundConnectionHandlerFactory("socks", SocksServerFactory{}) + connhandler.RegisterInboundConnectionHandlerFactory("socks", SocksServerFactory{}) } diff --git a/proxy/vmess/vmess_test.go b/proxy/vmess/vmess_test.go index 5bb5dc916..ffd20495e 100644 --- a/proxy/vmess/vmess_test.go +++ b/proxy/vmess/vmess_test.go @@ -7,7 +7,7 @@ import ( "github.com/v2ray/v2ray-core/app/point" "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/common/connhandler" "github.com/v2ray/v2ray-core/proxy/vmess/config" "github.com/v2ray/v2ray-core/proxy/vmess/config/json" "github.com/v2ray/v2ray-core/testing/mocks" @@ -27,7 +27,7 @@ func TestVMessInAndOut(t *testing.T) { DataReturned: bytes.NewBuffer(make([]byte, 0, 1024)), } - proxy.RegisterInboundConnectionHandlerFactory("mock_ich", ich) + connhandler.RegisterInboundConnectionHandlerFactory("mock_ich", ich) configA := mocks.Config{ PortValue: portA, @@ -64,7 +64,7 @@ func TestVMessInAndOut(t *testing.T) { Data2Return: []byte("The data to be returned to inbound server."), } - proxy.RegisterOutboundConnectionHandlerFactory("mock_och", och) + connhandler.RegisterOutboundConnectionHandlerFactory("mock_och", och) configB := mocks.Config{ PortValue: portB, @@ -107,7 +107,7 @@ func TestVMessInAndOutUDP(t *testing.T) { DataReturned: bytes.NewBuffer(make([]byte, 0, 1024)), } - proxy.RegisterInboundConnectionHandlerFactory("mock_ich", ich) + connhandler.RegisterInboundConnectionHandlerFactory("mock_ich", ich) configA := mocks.Config{ PortValue: portA, @@ -144,7 +144,7 @@ func TestVMessInAndOutUDP(t *testing.T) { Data2Return: []byte("The data to be returned to inbound server."), } - proxy.RegisterOutboundConnectionHandlerFactory("mock_och", och) + connhandler.RegisterOutboundConnectionHandlerFactory("mock_och", och) configB := mocks.Config{ PortValue: portB, diff --git a/proxy/vmess/vmessin.go b/proxy/vmess/vmessin.go index 8a14e0fe6..2ebc44122 100644 --- a/proxy/vmess/vmessin.go +++ b/proxy/vmess/vmessin.go @@ -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/common/retry" - "github.com/v2ray/v2ray-core/proxy" + "github.com/v2ray/v2ray-core/proxy/common/connhandler" "github.com/v2ray/v2ray-core/proxy/vmess/config" "github.com/v2ray/v2ray-core/proxy/vmess/protocol" "github.com/v2ray/v2ray-core/proxy/vmess/protocol/user" @@ -143,7 +143,7 @@ func handleOutput(request *protocol.VMessRequest, writer io.Writer, output <-cha type VMessInboundHandlerFactory struct { } -func (factory *VMessInboundHandlerFactory) Create(dispatcher app.PacketDispatcher, rawConfig interface{}) (proxy.InboundConnectionHandler, error) { +func (factory *VMessInboundHandlerFactory) Create(dispatcher app.PacketDispatcher, rawConfig interface{}) (connhandler.InboundConnectionHandler, error) { config := rawConfig.(config.Inbound) allowedClients := user.NewTimedUserSet() @@ -155,5 +155,5 @@ func (factory *VMessInboundHandlerFactory) Create(dispatcher app.PacketDispatche } func init() { - proxy.RegisterInboundConnectionHandlerFactory("vmess", &VMessInboundHandlerFactory{}) + connhandler.RegisterInboundConnectionHandlerFactory("vmess", &VMessInboundHandlerFactory{}) } diff --git a/proxy/vmess/vmessout.go b/proxy/vmess/vmessout.go index f1f34300e..eacf879a5 100644 --- a/proxy/vmess/vmessout.go +++ b/proxy/vmess/vmessout.go @@ -12,7 +12,7 @@ import ( v2io "github.com/v2ray/v2ray-core/common/io" "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/vmess/config" "github.com/v2ray/v2ray-core/proxy/vmess/protocol" "github.com/v2ray/v2ray-core/proxy/vmess/protocol/user" @@ -190,7 +190,7 @@ func handleResponse(conn net.Conn, request *protocol.VMessRequest, output chan<- type VMessOutboundHandlerFactory struct { } -func (factory *VMessOutboundHandlerFactory) Create(rawConfig interface{}) (proxy.OutboundConnectionHandler, error) { +func (factory *VMessOutboundHandlerFactory) Create(rawConfig interface{}) (connhandler.OutboundConnectionHandler, error) { vOutConfig := rawConfig.(config.Outbound) servers := make([]*config.OutboundTarget, 0, 16) udpServers := make([]*config.OutboundTarget, 0, 16) @@ -206,5 +206,5 @@ func (factory *VMessOutboundHandlerFactory) Create(rawConfig interface{}) (proxy } func init() { - proxy.RegisterOutboundConnectionHandlerFactory("vmess", &VMessOutboundHandlerFactory{}) + connhandler.RegisterOutboundConnectionHandlerFactory("vmess", &VMessOutboundHandlerFactory{}) } diff --git a/testing/mocks/inboundhandler.go b/testing/mocks/inboundhandler.go index e9f2af421..f7f417822 100644 --- a/testing/mocks/inboundhandler.go +++ b/testing/mocks/inboundhandler.go @@ -6,7 +6,7 @@ import ( "github.com/v2ray/v2ray-core/app" "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/common/connhandler" ) type InboundConnectionHandler struct { @@ -37,7 +37,7 @@ func (handler *InboundConnectionHandler) Communicate(packet v2net.Packet) error return nil } -func (handler *InboundConnectionHandler) Create(dispatcher app.PacketDispatcher, config interface{}) (proxy.InboundConnectionHandler, error) { +func (handler *InboundConnectionHandler) Create(dispatcher app.PacketDispatcher, config interface{}) (connhandler.InboundConnectionHandler, error) { handler.Dispatcher = dispatcher return handler, nil } diff --git a/testing/mocks/outboundhandler.go b/testing/mocks/outboundhandler.go index 08741882f..252095dfb 100644 --- a/testing/mocks/outboundhandler.go +++ b/testing/mocks/outboundhandler.go @@ -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/common/connhandler" "github.com/v2ray/v2ray-core/transport/ray" ) @@ -43,6 +43,6 @@ func (handler *OutboundConnectionHandler) Dispatch(packet v2net.Packet, ray ray. return nil } -func (handler *OutboundConnectionHandler) Create(config interface{}) (proxy.OutboundConnectionHandler, error) { +func (handler *OutboundConnectionHandler) Create(config interface{}) (connhandler.OutboundConnectionHandler, error) { return handler, nil }