1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-30 05:56:54 -05: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"
"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

View File

@ -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{})
}

View File

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

View File

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

View File

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

View File

@ -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{

View File

@ -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{})
}

View File

@ -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,

View File

@ -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{})
}

View File

@ -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,

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/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{})
}

View File

@ -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{})
}

View File

@ -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
}

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/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
}