mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-05-27 22:39:09 -04:00
move connhandler to proxy
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
"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 := internal.RegisterOutboundConnectionHandlerFactory("blackhole", func(space app.Space, config interface{}) (connhandler.OutboundConnectionHandler, error) {
|
||||
if err := internal.RegisterOutboundConnectionHandlerFactory("blackhole", func(space app.Space, config interface{}) (proxy.OutboundConnectionHandler, error) {
|
||||
return NewBlackHole(), nil
|
||||
}); err != nil {
|
||||
panic(err)
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package connhandler
|
||||
|
||||
import (
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
)
|
||||
|
||||
// A InboundConnectionHandler handles inbound network connections to V2Ray.
|
||||
type InboundConnectionHandler interface {
|
||||
// Listen starts a InboundConnectionHandler by listen on a specific port. This method is called
|
||||
// exactly once during runtime.
|
||||
Listen(port v2net.Port) error
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package connhandler
|
||||
|
||||
import (
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/transport/ray"
|
||||
)
|
||||
|
||||
// An OutboundConnectionHandler handles outbound network connection for V2Ray.
|
||||
type OutboundConnectionHandler interface {
|
||||
// Dispatch sends one or more Packets to its destination.
|
||||
Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) error
|
||||
}
|
||||
@@ -2,12 +2,12 @@ package dokodemo
|
||||
|
||||
import (
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||
)
|
||||
|
||||
func init() {
|
||||
if err := internal.RegisterInboundConnectionHandlerFactory("dokodemo-door", func(space app.Space, rawConfig interface{}) (connhandler.InboundConnectionHandler, error) {
|
||||
if err := internal.RegisterInboundConnectionHandlerFactory("dokodemo-door", func(space app.Space, rawConfig interface{}) (proxy.InboundConnectionHandler, error) {
|
||||
config := rawConfig.(Config)
|
||||
return NewDokodemoDoor(space, config), nil
|
||||
}); err != nil {
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/v2ray/v2ray-core/common/alloc"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||
v2proxy "github.com/v2ray/v2ray-core/proxy"
|
||||
_ "github.com/v2ray/v2ray-core/proxy/socks"
|
||||
_ "github.com/v2ray/v2ray-core/proxy/socks/json"
|
||||
proxytesting "github.com/v2ray/v2ray-core/proxy/testing"
|
||||
@@ -49,7 +49,7 @@ func TestUDPSend(t *testing.T) {
|
||||
ConnOutput: connOutput,
|
||||
}
|
||||
|
||||
protocol, err := proxytesting.RegisterInboundConnectionHandlerCreator("mock_ich", func(space app.Space, config interface{}) (connhandler.InboundConnectionHandler, error) {
|
||||
protocol, err := proxytesting.RegisterInboundConnectionHandlerCreator("mock_ich", func(space app.Space, config interface{}) (v2proxy.InboundConnectionHandler, error) {
|
||||
ich.Space = space
|
||||
return ich, nil
|
||||
})
|
||||
|
||||
@@ -2,12 +2,12 @@ package freedom
|
||||
|
||||
import (
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||
)
|
||||
|
||||
func init() {
|
||||
if err := internal.RegisterOutboundConnectionHandlerFactory("freedom", func(space app.Space, config interface{}) (connhandler.OutboundConnectionHandler, error) {
|
||||
if err := internal.RegisterOutboundConnectionHandlerFactory("freedom", func(space app.Space, config interface{}) (proxy.OutboundConnectionHandler, error) {
|
||||
return &FreedomConnection{space: space}, nil
|
||||
}); err != nil {
|
||||
panic(err)
|
||||
|
||||
@@ -2,12 +2,12 @@ package http
|
||||
|
||||
import (
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||
)
|
||||
|
||||
func init() {
|
||||
if err := internal.RegisterInboundConnectionHandlerFactory("http", func(space app.Space, rawConfig interface{}) (connhandler.InboundConnectionHandler, error) {
|
||||
if err := internal.RegisterInboundConnectionHandlerFactory("http", func(space app.Space, rawConfig interface{}) (proxy.InboundConnectionHandler, error) {
|
||||
return NewHttpProxyServer(space, rawConfig.(Config)), nil
|
||||
}); err != nil {
|
||||
panic(err)
|
||||
|
||||
@@ -2,8 +2,8 @@ package internal
|
||||
|
||||
import (
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
)
|
||||
|
||||
type InboundConnectionHandlerCreator func(space app.Space, config interface{}) (connhandler.InboundConnectionHandler, error)
|
||||
type OutboundConnectionHandlerCreator func(space app.Space, config interface{}) (connhandler.OutboundConnectionHandler, error)
|
||||
type InboundConnectionHandlerCreator func(space app.Space, config interface{}) (proxy.InboundConnectionHandler, error)
|
||||
type OutboundConnectionHandlerCreator func(space app.Space, config interface{}) (proxy.OutboundConnectionHandler, error)
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"errors"
|
||||
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
"github.com/v2ray/v2ray-core/proxy/internal/config"
|
||||
)
|
||||
|
||||
@@ -33,7 +33,7 @@ func RegisterOutboundConnectionHandlerFactory(name string, creator OutboundConne
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateInboundConnectionHandler(name string, space app.Space, rawConfig []byte) (connhandler.InboundConnectionHandler, error) {
|
||||
func CreateInboundConnectionHandler(name string, space app.Space, rawConfig []byte) (proxy.InboundConnectionHandler, error) {
|
||||
creator, found := inboundFactories[name]
|
||||
if !found {
|
||||
return nil, ErrorProxyNotFound
|
||||
@@ -48,7 +48,7 @@ func CreateInboundConnectionHandler(name string, space app.Space, rawConfig []by
|
||||
return creator(space, nil)
|
||||
}
|
||||
|
||||
func CreateOutboundConnectionHandler(name string, space app.Space, rawConfig []byte) (connhandler.OutboundConnectionHandler, error) {
|
||||
func CreateOutboundConnectionHandler(name string, space app.Space, rawConfig []byte) (proxy.OutboundConnectionHandler, error) {
|
||||
creator, found := outboundFactories[name]
|
||||
if !found {
|
||||
return nil, ErrorNameExists
|
||||
|
||||
@@ -3,15 +3,19 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/transport/ray"
|
||||
)
|
||||
|
||||
func CreateInboundConnectionHandler(name string, space app.Space, rawConfig []byte) (connhandler.InboundConnectionHandler, error) {
|
||||
return internal.CreateInboundConnectionHandler(name, space, rawConfig)
|
||||
// A InboundConnectionHandler handles inbound network connections to V2Ray.
|
||||
type InboundConnectionHandler interface {
|
||||
// Listen starts a InboundConnectionHandler by listen on a specific port. This method is called
|
||||
// exactly once during runtime.
|
||||
Listen(port v2net.Port) error
|
||||
}
|
||||
|
||||
func CreateOutboundConnectionHandler(name string, space app.Space, rawConfig []byte) (connhandler.OutboundConnectionHandler, error) {
|
||||
return internal.CreateOutboundConnectionHandler(name, space, rawConfig)
|
||||
// An OutboundConnectionHandler handles outbound network connection for V2Ray.
|
||||
type OutboundConnectionHandler interface {
|
||||
// Dispatch sends one or more Packets to its destination.
|
||||
Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) error
|
||||
}
|
||||
|
||||
15
proxy/repo/repo.go
Normal file
15
proxy/repo/repo.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package repo
|
||||
|
||||
import (
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||
)
|
||||
|
||||
func CreateInboundConnectionHandler(name string, space app.Space, rawConfig []byte) (proxy.InboundConnectionHandler, error) {
|
||||
return internal.CreateInboundConnectionHandler(name, space, rawConfig)
|
||||
}
|
||||
|
||||
func CreateOutboundConnectionHandler(name string, space app.Space, rawConfig []byte) (proxy.OutboundConnectionHandler, error) {
|
||||
return internal.CreateOutboundConnectionHandler(name, space, rawConfig)
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||
v2proxy "github.com/v2ray/v2ray-core/proxy"
|
||||
_ "github.com/v2ray/v2ray-core/proxy/socks/json"
|
||||
proxytesting "github.com/v2ray/v2ray-core/proxy/testing"
|
||||
proxymocks "github.com/v2ray/v2ray-core/proxy/testing/mocks"
|
||||
@@ -32,7 +32,7 @@ func TestSocksTcpConnect(t *testing.T) {
|
||||
ConnInput: bytes.NewReader(connInput),
|
||||
}
|
||||
|
||||
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (connhandler.OutboundConnectionHandler, error) {
|
||||
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (v2proxy.OutboundConnectionHandler, error) {
|
||||
return och, nil
|
||||
})
|
||||
assert.Error(err).IsNil()
|
||||
@@ -91,7 +91,7 @@ func TestSocksTcpConnectWithUserPass(t *testing.T) {
|
||||
ConnOutput: connOutput,
|
||||
}
|
||||
|
||||
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (connhandler.OutboundConnectionHandler, error) {
|
||||
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (v2proxy.OutboundConnectionHandler, error) {
|
||||
return och, nil
|
||||
})
|
||||
assert.Error(err).IsNil()
|
||||
@@ -153,7 +153,7 @@ func TestSocksTcpConnectWithWrongUserPass(t *testing.T) {
|
||||
ConnOutput: connOutput,
|
||||
}
|
||||
|
||||
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (connhandler.OutboundConnectionHandler, error) {
|
||||
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (v2proxy.OutboundConnectionHandler, error) {
|
||||
return och, nil
|
||||
})
|
||||
assert.Error(err).IsNil()
|
||||
@@ -201,7 +201,7 @@ func TestSocksTcpConnectWithWrongAuthMethod(t *testing.T) {
|
||||
ConnOutput: connOutput,
|
||||
}
|
||||
|
||||
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (connhandler.OutboundConnectionHandler, error) {
|
||||
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (v2proxy.OutboundConnectionHandler, error) {
|
||||
return och, nil
|
||||
})
|
||||
assert.Error(err).IsNil()
|
||||
@@ -249,7 +249,7 @@ func TestSocksUdpSend(t *testing.T) {
|
||||
ConnOutput: connOutput,
|
||||
}
|
||||
|
||||
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (connhandler.OutboundConnectionHandler, error) {
|
||||
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (v2proxy.OutboundConnectionHandler, error) {
|
||||
return och, nil
|
||||
})
|
||||
assert.Error(err).IsNil()
|
||||
|
||||
@@ -2,12 +2,12 @@ package socks
|
||||
|
||||
import (
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||
)
|
||||
|
||||
func init() {
|
||||
if err := internal.RegisterInboundConnectionHandlerFactory("socks", func(space app.Space, rawConfig interface{}) (connhandler.InboundConnectionHandler, error) {
|
||||
if err := internal.RegisterInboundConnectionHandlerFactory("socks", func(space app.Space, rawConfig interface{}) (proxy.InboundConnectionHandler, error) {
|
||||
return NewSocksServer(space, rawConfig.(Config)), nil
|
||||
}); err != nil {
|
||||
panic(err)
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
"github.com/v2ray/v2ray-core/transport/ray"
|
||||
)
|
||||
|
||||
@@ -45,6 +45,6 @@ func (this *OutboundConnectionHandler) Dispatch(packet v2net.Packet, ray ray.Out
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *OutboundConnectionHandler) Create(space app.Space, config interface{}) (connhandler.OutboundConnectionHandler, error) {
|
||||
func (this *OutboundConnectionHandler) Create(space app.Space, config interface{}) (proxy.OutboundConnectionHandler, error) {
|
||||
return this, nil
|
||||
}
|
||||
|
||||
@@ -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/common/connhandler"
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||
"github.com/v2ray/v2ray-core/proxy/vmess"
|
||||
"github.com/v2ray/v2ray-core/proxy/vmess/protocol"
|
||||
@@ -141,7 +141,7 @@ func handleOutput(request *protocol.VMessRequest, writer io.Writer, output <-cha
|
||||
}
|
||||
|
||||
func init() {
|
||||
if err := internal.RegisterInboundConnectionHandlerFactory("vmess", func(space app.Space, rawConfig interface{}) (connhandler.InboundConnectionHandler, error) {
|
||||
if err := internal.RegisterInboundConnectionHandlerFactory("vmess", func(space app.Space, rawConfig interface{}) (proxy.InboundConnectionHandler, error) {
|
||||
config := rawConfig.(Config)
|
||||
|
||||
allowedClients := user.NewTimedUserSet()
|
||||
|
||||
@@ -11,7 +11,7 @@ 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/common/connhandler"
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||
"github.com/v2ray/v2ray-core/proxy/vmess/protocol"
|
||||
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
|
||||
@@ -188,7 +188,7 @@ func handleResponse(conn net.Conn, request *protocol.VMessRequest, output chan<-
|
||||
type VMessOutboundHandlerFactory struct {
|
||||
}
|
||||
|
||||
func (this *VMessOutboundHandlerFactory) Create(space app.Space, rawConfig interface{}) (connhandler.OutboundConnectionHandler, error) {
|
||||
func (this *VMessOutboundHandlerFactory) Create(space app.Space, rawConfig interface{}) (proxy.OutboundConnectionHandler, error) {
|
||||
vOutConfig := rawConfig.(Config)
|
||||
return &VMessOutboundHandler{
|
||||
space: space,
|
||||
@@ -197,7 +197,7 @@ func (this *VMessOutboundHandlerFactory) Create(space app.Space, rawConfig inter
|
||||
}
|
||||
|
||||
func init() {
|
||||
if err := internal.RegisterOutboundConnectionHandlerFactory("vmess", func(space app.Space, rawConfig interface{}) (connhandler.OutboundConnectionHandler, error) {
|
||||
if err := internal.RegisterOutboundConnectionHandlerFactory("vmess", func(space app.Space, rawConfig interface{}) (proxy.OutboundConnectionHandler, error) {
|
||||
vOutConfig := rawConfig.(Config)
|
||||
return &VMessOutboundHandler{
|
||||
space: space,
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
||||
"github.com/v2ray/v2ray-core/common/uuid"
|
||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
proxytesting "github.com/v2ray/v2ray-core/proxy/testing"
|
||||
proxymocks "github.com/v2ray/v2ray-core/proxy/testing/mocks"
|
||||
vmess "github.com/v2ray/v2ray-core/proxy/vmess"
|
||||
@@ -40,7 +40,7 @@ func TestVMessInAndOut(t *testing.T) {
|
||||
ConnOutput: ichConnOutput,
|
||||
}
|
||||
|
||||
protocol, err := proxytesting.RegisterInboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (connhandler.InboundConnectionHandler, error) {
|
||||
protocol, err := proxytesting.RegisterInboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (proxy.InboundConnectionHandler, error) {
|
||||
ich.Space = space
|
||||
return ich, nil
|
||||
})
|
||||
@@ -81,7 +81,7 @@ func TestVMessInAndOut(t *testing.T) {
|
||||
ConnOutput: ochConnOutput,
|
||||
}
|
||||
|
||||
protocol, err = proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (connhandler.OutboundConnectionHandler, error) {
|
||||
protocol, err = proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (proxy.OutboundConnectionHandler, error) {
|
||||
return och, nil
|
||||
})
|
||||
assert.Error(err).IsNil()
|
||||
|
||||
Reference in New Issue
Block a user