1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-28 10:15:23 +00:00

Move connection handler interfaces to proxy/common/connhandler

This commit is contained in:
V2Ray 2015-10-30 00:11:29 +01:00
parent 361a22d74d
commit f93b29993b
14 changed files with 40 additions and 40 deletions

View File

@ -5,15 +5,15 @@ import (
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/config" "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" "github.com/v2ray/v2ray-core/transport/ray"
) )
// Point is an single server in V2Ray system. // Point is an single server in V2Ray system.
type Point struct { type Point struct {
port uint16 port uint16
ich proxy.InboundConnectionHandler ich connhandler.InboundConnectionHandler
och proxy.OutboundConnectionHandler och connhandler.OutboundConnectionHandler
} }
// NewPoint returns a new Point server based on given configuration. // 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) var vpoint = new(Point)
vpoint.port = pConfig.Port() vpoint.port = pConfig.Port()
ichFactory := proxy.GetInboundConnectionHandlerFactory(pConfig.InboundConfig().Protocol()) ichFactory := connhandler.GetInboundConnectionHandlerFactory(pConfig.InboundConfig().Protocol())
if ichFactory == nil { if ichFactory == nil {
log.Error("Unknown inbound connection handler factory %s", pConfig.InboundConfig().Protocol()) log.Error("Unknown inbound connection handler factory %s", pConfig.InboundConfig().Protocol())
return nil, config.BadConfiguration return nil, config.BadConfiguration
@ -35,7 +35,7 @@ func NewPoint(pConfig config.PointConfig) (*Point, error) {
} }
vpoint.ich = ich vpoint.ich = ich
ochFactory := proxy.GetOutboundConnectionHandlerFactory(pConfig.OutboundConfig().Protocol()) ochFactory := connhandler.GetOutboundConnectionHandlerFactory(pConfig.OutboundConfig().Protocol())
if ochFactory == nil { if ochFactory == nil {
log.Error("Unknown outbound connection handler factory %s", pConfig.OutboundConfig().Protocol()) log.Error("Unknown outbound connection handler factory %s", pConfig.OutboundConfig().Protocol())
return nil, config.BadConfiguration return nil, config.BadConfiguration

View File

@ -4,7 +4,7 @@ import (
"io/ioutil" "io/ioutil"
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/transport/ray" "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 { type BlackHoleFactory struct {
} }
func (factory BlackHoleFactory) Create(config interface{}) (proxy.OutboundConnectionHandler, error) { func (factory BlackHoleFactory) Create(config interface{}) (connhandler.OutboundConnectionHandler, error) {
return NewBlackHole(), nil return NewBlackHole(), nil
} }
func init() { func init() {
proxy.RegisterOutboundConnectionHandlerFactory("blackhole", BlackHoleFactory{}) connhandler.RegisterOutboundConnectionHandlerFactory("blackhole", BlackHoleFactory{})
} }

View File

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

View File

@ -1,4 +1,4 @@
package proxy package connhandler
import ( import (
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"

View File

@ -1,4 +1,4 @@
package proxy package connhandler
var ( var (
inboundFactories = make(map[string]InboundConnectionHandlerFactory) inboundFactories = make(map[string]InboundConnectionHandlerFactory)

View File

@ -11,7 +11,7 @@ import (
"github.com/v2ray/v2ray-core/app/point" "github.com/v2ray/v2ray-core/app/point"
"github.com/v2ray/v2ray-core/common/alloc" "github.com/v2ray/v2ray-core/common/alloc"
v2net "github.com/v2ray/v2ray-core/common/net" 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"
"github.com/v2ray/v2ray-core/proxy/socks/config/json" "github.com/v2ray/v2ray-core/proxy/socks/config/json"
"github.com/v2ray/v2ray-core/testing/mocks" "github.com/v2ray/v2ray-core/testing/mocks"
@ -43,7 +43,7 @@ func TestUDPSend(t *testing.T) {
DataReturned: bytes.NewBuffer(make([]byte, 0, 1024)), DataReturned: bytes.NewBuffer(make([]byte, 0, 1024)),
} }
v2proxy.RegisterInboundConnectionHandlerFactory("mock_ich", ich) connhandler.RegisterInboundConnectionHandlerFactory("mock_ich", ich)
pointPort := uint16(38724) pointPort := uint16(38724)
config := mocks.Config{ config := mocks.Config{

View File

@ -1,16 +1,16 @@
package freedom package freedom
import ( import (
"github.com/v2ray/v2ray-core/proxy" "github.com/v2ray/v2ray-core/proxy/common/connhandler"
) )
type FreedomFactory struct { type FreedomFactory struct {
} }
func (factory FreedomFactory) Create(config interface{}) (proxy.OutboundConnectionHandler, error) { func (factory FreedomFactory) Create(config interface{}) (connhandler.OutboundConnectionHandler, error) {
return NewFreedomConnection(), nil return NewFreedomConnection(), nil
} }
func init() { func init() {
proxy.RegisterOutboundConnectionHandlerFactory("freedom", FreedomFactory{}) connhandler.RegisterOutboundConnectionHandlerFactory("freedom", FreedomFactory{})
} }

View File

@ -9,7 +9,7 @@ import (
"golang.org/x/net/proxy" "golang.org/x/net/proxy"
"github.com/v2ray/v2ray-core/app/point" "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/proxy/socks/config/json"
"github.com/v2ray/v2ray-core/testing/mocks" "github.com/v2ray/v2ray-core/testing/mocks"
"github.com/v2ray/v2ray-core/testing/unit" "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."), Data2Return: []byte("The data to be returned to socks server."),
} }
v2proxy.RegisterOutboundConnectionHandlerFactory("mock_och", och) connhandler.RegisterOutboundConnectionHandlerFactory("mock_och", och)
config := mocks.Config{ config := mocks.Config{
PortValue: port, PortValue: port,
@ -77,7 +77,7 @@ func TestSocksTcpConnectWithUserPass(t *testing.T) {
Data2Return: []byte("The data to be returned to socks server."), Data2Return: []byte("The data to be returned to socks server."),
} }
v2proxy.RegisterOutboundConnectionHandlerFactory("mock_och", och) connhandler.RegisterOutboundConnectionHandlerFactory("mock_och", och)
config := mocks.Config{ config := mocks.Config{
PortValue: port, PortValue: port,
@ -136,7 +136,7 @@ func TestSocksTcpConnectWithWrongUserPass(t *testing.T) {
Data2Return: []byte("The data to be returned to socks server."), Data2Return: []byte("The data to be returned to socks server."),
} }
v2proxy.RegisterOutboundConnectionHandlerFactory("mock_och", och) connhandler.RegisterOutboundConnectionHandlerFactory("mock_och", och)
config := mocks.Config{ config := mocks.Config{
PortValue: port, PortValue: port,
@ -181,7 +181,7 @@ func TestSocksTcpConnectWithWrongAuthMethod(t *testing.T) {
Data2Return: []byte("The data to be returned to socks server."), Data2Return: []byte("The data to be returned to socks server."),
} }
v2proxy.RegisterOutboundConnectionHandlerFactory("mock_och", och) connhandler.RegisterOutboundConnectionHandlerFactory("mock_och", och)
config := mocks.Config{ config := mocks.Config{
PortValue: port, PortValue: port,
@ -226,7 +226,7 @@ func TestSocksUdpSend(t *testing.T) {
Data2Return: []byte("The data to be returned to socks server."), Data2Return: []byte("The data to be returned to socks server."),
} }
v2proxy.RegisterOutboundConnectionHandlerFactory("mock_och", och) connhandler.RegisterOutboundConnectionHandlerFactory("mock_och", och)
config := mocks.Config{ config := mocks.Config{
PortValue: port, PortValue: port,

View File

@ -2,19 +2,19 @@ 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/socks/config/json" "github.com/v2ray/v2ray-core/proxy/socks/config/json"
) )
type SocksServerFactory struct { 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 := rawConfig.(*json.SocksConfig)
config.Initialize() config.Initialize()
return NewSocksServer(dispatcher, config), nil return NewSocksServer(dispatcher, config), nil
} }
func init() { func init() {
proxy.RegisterInboundConnectionHandlerFactory("socks", SocksServerFactory{}) connhandler.RegisterInboundConnectionHandlerFactory("socks", SocksServerFactory{})
} }

View File

@ -7,7 +7,7 @@ import (
"github.com/v2ray/v2ray-core/app/point" "github.com/v2ray/v2ray-core/app/point"
"github.com/v2ray/v2ray-core/common/alloc" "github.com/v2ray/v2ray-core/common/alloc"
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/vmess/config" "github.com/v2ray/v2ray-core/proxy/vmess/config"
"github.com/v2ray/v2ray-core/proxy/vmess/config/json" "github.com/v2ray/v2ray-core/proxy/vmess/config/json"
"github.com/v2ray/v2ray-core/testing/mocks" "github.com/v2ray/v2ray-core/testing/mocks"
@ -27,7 +27,7 @@ func TestVMessInAndOut(t *testing.T) {
DataReturned: bytes.NewBuffer(make([]byte, 0, 1024)), DataReturned: bytes.NewBuffer(make([]byte, 0, 1024)),
} }
proxy.RegisterInboundConnectionHandlerFactory("mock_ich", ich) connhandler.RegisterInboundConnectionHandlerFactory("mock_ich", ich)
configA := mocks.Config{ configA := mocks.Config{
PortValue: portA, PortValue: portA,
@ -64,7 +64,7 @@ func TestVMessInAndOut(t *testing.T) {
Data2Return: []byte("The data to be returned to inbound server."), Data2Return: []byte("The data to be returned to inbound server."),
} }
proxy.RegisterOutboundConnectionHandlerFactory("mock_och", och) connhandler.RegisterOutboundConnectionHandlerFactory("mock_och", och)
configB := mocks.Config{ configB := mocks.Config{
PortValue: portB, PortValue: portB,
@ -107,7 +107,7 @@ func TestVMessInAndOutUDP(t *testing.T) {
DataReturned: bytes.NewBuffer(make([]byte, 0, 1024)), DataReturned: bytes.NewBuffer(make([]byte, 0, 1024)),
} }
proxy.RegisterInboundConnectionHandlerFactory("mock_ich", ich) connhandler.RegisterInboundConnectionHandlerFactory("mock_ich", ich)
configA := mocks.Config{ configA := mocks.Config{
PortValue: portA, PortValue: portA,
@ -144,7 +144,7 @@ func TestVMessInAndOutUDP(t *testing.T) {
Data2Return: []byte("The data to be returned to inbound server."), Data2Return: []byte("The data to be returned to inbound server."),
} }
proxy.RegisterOutboundConnectionHandlerFactory("mock_och", och) connhandler.RegisterOutboundConnectionHandlerFactory("mock_och", och)
configB := mocks.Config{ configB := mocks.Config{
PortValue: portB, PortValue: portB,

View File

@ -12,7 +12,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"
"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/vmess/config" "github.com/v2ray/v2ray-core/proxy/vmess/config"
"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"
@ -143,7 +143,7 @@ func handleOutput(request *protocol.VMessRequest, writer io.Writer, output <-cha
type VMessInboundHandlerFactory struct { 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) config := rawConfig.(config.Inbound)
allowedClients := user.NewTimedUserSet() allowedClients := user.NewTimedUserSet()
@ -155,5 +155,5 @@ func (factory *VMessInboundHandlerFactory) Create(dispatcher app.PacketDispatche
} }
func init() { func init() {
proxy.RegisterInboundConnectionHandlerFactory("vmess", &VMessInboundHandlerFactory{}) connhandler.RegisterInboundConnectionHandlerFactory("vmess", &VMessInboundHandlerFactory{})
} }

View File

@ -12,7 +12,7 @@ import (
v2io "github.com/v2ray/v2ray-core/common/io" v2io "github.com/v2ray/v2ray-core/common/io"
"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/vmess/config" "github.com/v2ray/v2ray-core/proxy/vmess/config"
"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"
@ -190,7 +190,7 @@ func handleResponse(conn net.Conn, request *protocol.VMessRequest, output chan<-
type VMessOutboundHandlerFactory struct { 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) vOutConfig := rawConfig.(config.Outbound)
servers := make([]*config.OutboundTarget, 0, 16) servers := make([]*config.OutboundTarget, 0, 16)
udpServers := make([]*config.OutboundTarget, 0, 16) udpServers := make([]*config.OutboundTarget, 0, 16)
@ -206,5 +206,5 @@ func (factory *VMessOutboundHandlerFactory) Create(rawConfig interface{}) (proxy
} }
func init() { func init() {
proxy.RegisterOutboundConnectionHandlerFactory("vmess", &VMessOutboundHandlerFactory{}) connhandler.RegisterOutboundConnectionHandlerFactory("vmess", &VMessOutboundHandlerFactory{})
} }

View File

@ -6,7 +6,7 @@ import (
"github.com/v2ray/v2ray-core/app" "github.com/v2ray/v2ray-core/app"
"github.com/v2ray/v2ray-core/common/alloc" "github.com/v2ray/v2ray-core/common/alloc"
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"
) )
type InboundConnectionHandler struct { type InboundConnectionHandler struct {
@ -37,7 +37,7 @@ func (handler *InboundConnectionHandler) Communicate(packet v2net.Packet) error
return nil 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 handler.Dispatcher = dispatcher
return handler, nil return handler, nil
} }

View File

@ -5,7 +5,7 @@ import (
"github.com/v2ray/v2ray-core/common/alloc" "github.com/v2ray/v2ray-core/common/alloc"
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/transport/ray" "github.com/v2ray/v2ray-core/transport/ray"
) )
@ -43,6 +43,6 @@ func (handler *OutboundConnectionHandler) Dispatch(packet v2net.Packet, ray ray.
return nil return nil
} }
func (handler *OutboundConnectionHandler) Create(config interface{}) (proxy.OutboundConnectionHandler, error) { func (handler *OutboundConnectionHandler) Create(config interface{}) (connhandler.OutboundConnectionHandler, error) {
return handler, nil return handler, nil
} }