mirror of https://github.com/v2ray/v2ray-core
rename InboundConnectionHandler to InboundHandler
parent
4817f8ab1f
commit
9fe8178e4a
|
@ -5,5 +5,5 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type InboundHandlerManager interface {
|
type InboundHandlerManager interface {
|
||||||
GetHandler(tag string) (proxy.InboundConnectionHandler, int)
|
GetHandler(tag string) (proxy.InboundHandler, int)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type InboundHandlerManagerWithContext interface {
|
type InboundHandlerManagerWithContext interface {
|
||||||
GetHandler(context app.Context, tag string) (proxy.InboundConnectionHandler, int)
|
GetHandler(context app.Context, tag string) (proxy.InboundHandler, int)
|
||||||
}
|
}
|
||||||
|
|
||||||
type inboundHandlerManagerWithContext struct {
|
type inboundHandlerManagerWithContext struct {
|
||||||
|
@ -14,6 +14,6 @@ type inboundHandlerManagerWithContext struct {
|
||||||
manager InboundHandlerManagerWithContext
|
manager InboundHandlerManagerWithContext
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *inboundHandlerManagerWithContext) GetHandler(tag string) (proxy.InboundConnectionHandler, int) {
|
func (this *inboundHandlerManagerWithContext) GetHandler(tag string) (proxy.InboundHandler, int) {
|
||||||
return this.manager.GetHandler(this.context, tag)
|
return this.manager.GetHandler(this.context, tag)
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ func (this *BlackHole) Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) e
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
internal.MustRegisterOutboundConnectionHandlerCreator("blackhole",
|
internal.MustRegisterOutboundConnectionHandlerCreator("blackhole",
|
||||||
func(space app.Space, config interface{}) (proxy.OutboundConnectionHandler, error) {
|
func(space app.Space, config interface{}) (proxy.OutboundHandler, error) {
|
||||||
return NewBlackHole(), nil
|
return NewBlackHole(), nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
internal.MustRegisterInboundConnectionHandlerCreator("dokodemo-door",
|
internal.MustRegisterInboundConnectionHandlerCreator("dokodemo-door",
|
||||||
func(space app.Space, rawConfig interface{}) (proxy.InboundConnectionHandler, error) {
|
func(space app.Space, rawConfig interface{}) (proxy.InboundHandler, error) {
|
||||||
config := rawConfig.(*Config)
|
config := rawConfig.(*Config)
|
||||||
return NewDokodemoDoor(space, config), nil
|
return NewDokodemoDoor(space, config), nil
|
||||||
})
|
})
|
||||||
|
|
|
@ -48,7 +48,7 @@ func TestUDPSend(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol, err := proxytesting.RegisterInboundConnectionHandlerCreator("mock_ich",
|
protocol, err := proxytesting.RegisterInboundConnectionHandlerCreator("mock_ich",
|
||||||
func(space app.Space, config interface{}) (v2proxy.InboundConnectionHandler, error) {
|
func(space app.Space, config interface{}) (v2proxy.InboundHandler, error) {
|
||||||
ich.Space = space
|
ich.Space = space
|
||||||
return ich, nil
|
return ich, nil
|
||||||
})
|
})
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
internal.MustRegisterOutboundConnectionHandlerCreator("freedom",
|
internal.MustRegisterOutboundConnectionHandlerCreator("freedom",
|
||||||
func(space app.Space, config interface{}) (proxy.OutboundConnectionHandler, error) {
|
func(space app.Space, config interface{}) (proxy.OutboundHandler, error) {
|
||||||
return &FreedomConnection{space: space}, nil
|
return &FreedomConnection{space: space}, nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
internal.MustRegisterInboundConnectionHandlerCreator("http",
|
internal.MustRegisterInboundConnectionHandlerCreator("http",
|
||||||
func(space app.Space, rawConfig interface{}) (proxy.InboundConnectionHandler, error) {
|
func(space app.Space, rawConfig interface{}) (proxy.InboundHandler, error) {
|
||||||
return NewHttpProxyServer(space, rawConfig.(*Config)), nil
|
return NewHttpProxyServer(space, rawConfig.(*Config)), nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,5 +5,5 @@ import (
|
||||||
"github.com/v2ray/v2ray-core/proxy"
|
"github.com/v2ray/v2ray-core/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
type InboundConnectionHandlerCreator func(space app.Space, config interface{}) (proxy.InboundConnectionHandler, error)
|
type InboundConnectionHandlerCreator func(space app.Space, config interface{}) (proxy.InboundHandler, error)
|
||||||
type OutboundConnectionHandlerCreator func(space app.Space, config interface{}) (proxy.OutboundConnectionHandler, error)
|
type OutboundConnectionHandlerCreator func(space app.Space, config interface{}) (proxy.OutboundHandler, error)
|
||||||
|
|
|
@ -45,7 +45,7 @@ func MustRegisterOutboundConnectionHandlerCreator(name string, creator OutboundC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateInboundConnectionHandler(name string, space app.Space, rawConfig []byte) (proxy.InboundConnectionHandler, error) {
|
func CreateInboundConnectionHandler(name string, space app.Space, rawConfig []byte) (proxy.InboundHandler, error) {
|
||||||
creator, found := inboundFactories[name]
|
creator, found := inboundFactories[name]
|
||||||
if !found {
|
if !found {
|
||||||
return nil, ErrorProxyNotFound
|
return nil, ErrorProxyNotFound
|
||||||
|
@ -60,7 +60,7 @@ func CreateInboundConnectionHandler(name string, space app.Space, rawConfig []by
|
||||||
return creator(space, nil)
|
return creator(space, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateOutboundConnectionHandler(name string, space app.Space, rawConfig []byte) (proxy.OutboundConnectionHandler, error) {
|
func CreateOutboundConnectionHandler(name string, space app.Space, rawConfig []byte) (proxy.OutboundHandler, error) {
|
||||||
creator, found := outboundFactories[name]
|
creator, found := outboundFactories[name]
|
||||||
if !found {
|
if !found {
|
||||||
return nil, ErrorNameExists
|
return nil, ErrorNameExists
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// A InboundConnectionHandler handles inbound network connections to V2Ray.
|
// A InboundConnectionHandler handles inbound network connections to V2Ray.
|
||||||
type InboundConnectionHandler interface {
|
type InboundHandler interface {
|
||||||
// Listen starts a InboundConnectionHandler by listen on a specific port.
|
// Listen starts a InboundConnectionHandler by listen on a specific port.
|
||||||
Listen(port v2net.Port) error
|
Listen(port v2net.Port) error
|
||||||
// Close stops the handler to accepting anymore inbound connections.
|
// Close stops the handler to accepting anymore inbound connections.
|
||||||
|
@ -18,7 +18,7 @@ type InboundConnectionHandler interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// An OutboundConnectionHandler handles outbound network connection for V2Ray.
|
// An OutboundConnectionHandler handles outbound network connection for V2Ray.
|
||||||
type OutboundConnectionHandler interface {
|
type OutboundHandler interface {
|
||||||
// Dispatch sends one or more Packets to its destination.
|
// Dispatch sends one or more Packets to its destination.
|
||||||
Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) error
|
Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) error
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,10 @@ import (
|
||||||
"github.com/v2ray/v2ray-core/proxy/internal"
|
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateInboundConnectionHandler(name string, space app.Space, rawConfig []byte) (proxy.InboundConnectionHandler, error) {
|
func CreateInboundConnectionHandler(name string, space app.Space, rawConfig []byte) (proxy.InboundHandler, error) {
|
||||||
return internal.CreateInboundConnectionHandler(name, space, rawConfig)
|
return internal.CreateInboundConnectionHandler(name, space, rawConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateOutboundConnectionHandler(name string, space app.Space, rawConfig []byte) (proxy.OutboundConnectionHandler, error) {
|
func CreateOutboundConnectionHandler(name string, space app.Space, rawConfig []byte) (proxy.OutboundHandler, error) {
|
||||||
return internal.CreateOutboundConnectionHandler(name, space, rawConfig)
|
return internal.CreateOutboundConnectionHandler(name, space, rawConfig)
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ func TestSocksTcpConnect(t *testing.T) {
|
||||||
ConnInput: bytes.NewReader(connInput),
|
ConnInput: bytes.NewReader(connInput),
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (v2proxy.OutboundConnectionHandler, error) {
|
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (v2proxy.OutboundHandler, error) {
|
||||||
return och, nil
|
return och, nil
|
||||||
})
|
})
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
@ -89,7 +89,7 @@ func TestSocksTcpConnectWithUserPass(t *testing.T) {
|
||||||
ConnOutput: connOutput,
|
ConnOutput: connOutput,
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (v2proxy.OutboundConnectionHandler, error) {
|
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (v2proxy.OutboundHandler, error) {
|
||||||
return och, nil
|
return och, nil
|
||||||
})
|
})
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
@ -151,7 +151,7 @@ func TestSocksTcpConnectWithWrongUserPass(t *testing.T) {
|
||||||
ConnOutput: connOutput,
|
ConnOutput: connOutput,
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (v2proxy.OutboundConnectionHandler, error) {
|
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (v2proxy.OutboundHandler, error) {
|
||||||
return och, nil
|
return och, nil
|
||||||
})
|
})
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
@ -199,7 +199,7 @@ func TestSocksTcpConnectWithWrongAuthMethod(t *testing.T) {
|
||||||
ConnOutput: connOutput,
|
ConnOutput: connOutput,
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (v2proxy.OutboundConnectionHandler, error) {
|
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (v2proxy.OutboundHandler, error) {
|
||||||
return och, nil
|
return och, nil
|
||||||
})
|
})
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
@ -248,7 +248,7 @@ func TestSocksUdpSend(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och",
|
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och",
|
||||||
func(space app.Space, config interface{}) (v2proxy.OutboundConnectionHandler, error) {
|
func(space app.Space, config interface{}) (v2proxy.OutboundHandler, error) {
|
||||||
return och, nil
|
return och, nil
|
||||||
})
|
})
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
internal.MustRegisterInboundConnectionHandlerCreator("socks",
|
internal.MustRegisterInboundConnectionHandlerCreator("socks",
|
||||||
func(space app.Space, rawConfig interface{}) (proxy.InboundConnectionHandler, error) {
|
func(space app.Space, rawConfig interface{}) (proxy.InboundHandler, error) {
|
||||||
return NewSocksServer(space, rawConfig.(*Config)), nil
|
return NewSocksServer(space, rawConfig.(*Config)), nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,6 @@ func (this *OutboundConnectionHandler) Dispatch(packet v2net.Packet, ray ray.Out
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *OutboundConnectionHandler) Create(space app.Space, config interface{}) (proxy.OutboundConnectionHandler, error) {
|
func (this *OutboundConnectionHandler) Create(space app.Space, config interface{}) (proxy.OutboundHandler, error) {
|
||||||
return this, nil
|
return this, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,7 +175,7 @@ func handleOutput(request *protocol.VMessRequest, writer io.Writer, output <-cha
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
internal.MustRegisterInboundConnectionHandlerCreator("vmess",
|
internal.MustRegisterInboundConnectionHandlerCreator("vmess",
|
||||||
func(space app.Space, rawConfig interface{}) (proxy.InboundConnectionHandler, error) {
|
func(space app.Space, rawConfig interface{}) (proxy.InboundHandler, error) {
|
||||||
config := rawConfig.(*Config)
|
config := rawConfig.(*Config)
|
||||||
|
|
||||||
allowedClients := protocol.NewTimedUserSet()
|
allowedClients := protocol.NewTimedUserSet()
|
||||||
|
|
|
@ -191,7 +191,7 @@ func (this *VMessOutboundHandler) handleResponse(conn net.Conn, request *protoco
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
internal.MustRegisterOutboundConnectionHandlerCreator("vmess",
|
internal.MustRegisterOutboundConnectionHandlerCreator("vmess",
|
||||||
func(space app.Space, rawConfig interface{}) (proxy.OutboundConnectionHandler, error) {
|
func(space app.Space, rawConfig interface{}) (proxy.OutboundHandler, error) {
|
||||||
vOutConfig := rawConfig.(*Config)
|
vOutConfig := rawConfig.(*Config)
|
||||||
return &VMessOutboundHandler{
|
return &VMessOutboundHandler{
|
||||||
space: space,
|
space: space,
|
||||||
|
|
|
@ -37,7 +37,7 @@ func TestVMessInAndOut(t *testing.T) {
|
||||||
ConnOutput: ichConnOutput,
|
ConnOutput: ichConnOutput,
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol, err := proxytesting.RegisterInboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (proxy.InboundConnectionHandler, error) {
|
protocol, err := proxytesting.RegisterInboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (proxy.InboundHandler, error) {
|
||||||
ich.Space = space
|
ich.Space = space
|
||||||
return ich, nil
|
return ich, nil
|
||||||
})
|
})
|
||||||
|
@ -78,7 +78,7 @@ func TestVMessInAndOut(t *testing.T) {
|
||||||
ConnOutput: ochConnOutput,
|
ConnOutput: ochConnOutput,
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol, err = proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (proxy.OutboundConnectionHandler, error) {
|
protocol, err = proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (proxy.OutboundHandler, error) {
|
||||||
return och, nil
|
return och, nil
|
||||||
})
|
})
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
|
|
@ -7,5 +7,5 @@ import (
|
||||||
type InboundDetourHandler interface {
|
type InboundDetourHandler interface {
|
||||||
Start() error
|
Start() error
|
||||||
Close()
|
Close()
|
||||||
GetConnectionHandler() (proxy.InboundConnectionHandler, int)
|
GetConnectionHandler() (proxy.InboundHandler, int)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
|
|
||||||
type InboundConnectionHandlerWithPort struct {
|
type InboundConnectionHandlerWithPort struct {
|
||||||
port v2net.Port
|
port v2net.Port
|
||||||
handler proxy.InboundConnectionHandler
|
handler proxy.InboundHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler for inbound detour connections.
|
// Handler for inbound detour connections.
|
||||||
|
@ -44,7 +44,7 @@ func NewInboundDetourHandlerAlways(space app.Space, config *InboundDetourConfig)
|
||||||
return handler, nil
|
return handler, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *InboundDetourHandlerAlways) GetConnectionHandler() (proxy.InboundConnectionHandler, int) {
|
func (this *InboundDetourHandlerAlways) GetConnectionHandler() (proxy.InboundHandler, int) {
|
||||||
ich := this.ich[dice.Roll(len(this.ich))]
|
ich := this.ich[dice.Roll(len(this.ich))]
|
||||||
return ich.handler, this.config.Allocation.Refresh
|
return ich.handler, this.config.Allocation.Refresh
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ func (this *InboundDetourHandlerDynamic) pickUnusedPort() v2net.Port {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *InboundDetourHandlerDynamic) GetConnectionHandler() (proxy.InboundConnectionHandler, int) {
|
func (this *InboundDetourHandlerDynamic) GetConnectionHandler() (proxy.InboundHandler, int) {
|
||||||
this.RLock()
|
this.RLock()
|
||||||
defer this.RUnlock()
|
defer this.RUnlock()
|
||||||
ich := this.ichInUse[dice.Roll(len(this.ichInUse))]
|
ich := this.ichInUse[dice.Roll(len(this.ichInUse))]
|
||||||
|
|
|
@ -19,11 +19,11 @@ import (
|
||||||
// Point shell of V2Ray.
|
// Point shell of V2Ray.
|
||||||
type Point struct {
|
type Point struct {
|
||||||
port v2net.Port
|
port v2net.Port
|
||||||
ich proxy.InboundConnectionHandler
|
ich proxy.InboundHandler
|
||||||
och proxy.OutboundConnectionHandler
|
och proxy.OutboundHandler
|
||||||
idh []InboundDetourHandler
|
idh []InboundDetourHandler
|
||||||
taggedIdh map[string]InboundDetourHandler
|
taggedIdh map[string]InboundDetourHandler
|
||||||
odh map[string]proxy.OutboundConnectionHandler
|
odh map[string]proxy.OutboundHandler
|
||||||
router router.Router
|
router router.Router
|
||||||
space *controller.SpaceController
|
space *controller.SpaceController
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ func NewPoint(pConfig *Config) (*Point, error) {
|
||||||
|
|
||||||
outboundDetours := pConfig.OutboundDetours
|
outboundDetours := pConfig.OutboundDetours
|
||||||
if len(outboundDetours) > 0 {
|
if len(outboundDetours) > 0 {
|
||||||
vpoint.odh = make(map[string]proxy.OutboundConnectionHandler)
|
vpoint.odh = make(map[string]proxy.OutboundHandler)
|
||||||
for _, detourConfig := range outboundDetours {
|
for _, detourConfig := range outboundDetours {
|
||||||
detourHandler, err := proxyrepo.CreateOutboundConnectionHandler(detourConfig.Protocol, vpoint.space.ForContext(detourConfig.Tag), detourConfig.Settings)
|
detourHandler, err := proxyrepo.CreateOutboundConnectionHandler(detourConfig.Protocol, vpoint.space.ForContext(detourConfig.Tag), detourConfig.Settings)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -190,7 +190,7 @@ func (this *Point) DispatchToOutbound(context app.Context, packet v2net.Packet)
|
||||||
return direct
|
return direct
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Point) FilterPacketAndDispatch(packet v2net.Packet, link ray.OutboundRay, dispatcher proxy.OutboundConnectionHandler) {
|
func (this *Point) FilterPacketAndDispatch(packet v2net.Packet, link ray.OutboundRay, dispatcher proxy.OutboundHandler) {
|
||||||
// Filter empty packets
|
// Filter empty packets
|
||||||
chunk := packet.Chunk()
|
chunk := packet.Chunk()
|
||||||
moreChunks := packet.MoreChunks()
|
moreChunks := packet.MoreChunks()
|
||||||
|
@ -212,7 +212,7 @@ func (this *Point) FilterPacketAndDispatch(packet v2net.Packet, link ray.Outboun
|
||||||
dispatcher.Dispatch(packet, link)
|
dispatcher.Dispatch(packet, link)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Point) GetHandler(context app.Context, tag string) (proxy.InboundConnectionHandler, int) {
|
func (this *Point) GetHandler(context app.Context, tag string) (proxy.InboundHandler, int) {
|
||||||
handler, found := this.taggedIdh[tag]
|
handler, found := this.taggedIdh[tag]
|
||||||
if !found {
|
if !found {
|
||||||
return nil, 0
|
return nil, 0
|
||||||
|
|
Loading…
Reference in New Issue