diff --git a/app/handlers.go b/app/handlers.go index 9a3d14add..0fdc75a93 100644 --- a/app/handlers.go +++ b/app/handlers.go @@ -5,5 +5,5 @@ import ( ) type InboundHandlerManager interface { - GetHandler(tag string) (proxy.InboundConnectionHandler, int) + GetHandler(tag string) (proxy.InboundHandler, int) } diff --git a/app/internal/handlers.go b/app/internal/handlers.go index ae0812694..0399d7369 100644 --- a/app/internal/handlers.go +++ b/app/internal/handlers.go @@ -6,7 +6,7 @@ import ( ) type InboundHandlerManagerWithContext interface { - GetHandler(context app.Context, tag string) (proxy.InboundConnectionHandler, int) + GetHandler(context app.Context, tag string) (proxy.InboundHandler, int) } type inboundHandlerManagerWithContext struct { @@ -14,6 +14,6 @@ type inboundHandlerManagerWithContext struct { 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) } diff --git a/proxy/blackhole/blackhole.go b/proxy/blackhole/blackhole.go index ff6d6eb36..e10ebacc2 100644 --- a/proxy/blackhole/blackhole.go +++ b/proxy/blackhole/blackhole.go @@ -32,7 +32,7 @@ func (this *BlackHole) Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) e func init() { internal.MustRegisterOutboundConnectionHandlerCreator("blackhole", - func(space app.Space, config interface{}) (proxy.OutboundConnectionHandler, error) { + func(space app.Space, config interface{}) (proxy.OutboundHandler, error) { return NewBlackHole(), nil }) } diff --git a/proxy/dokodemo/dokodemo_factory.go b/proxy/dokodemo/dokodemo_factory.go index 19ac79544..299e3e2a9 100644 --- a/proxy/dokodemo/dokodemo_factory.go +++ b/proxy/dokodemo/dokodemo_factory.go @@ -8,7 +8,7 @@ import ( func init() { 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) return NewDokodemoDoor(space, config), nil }) diff --git a/proxy/freedom/freedom_test.go b/proxy/freedom/freedom_test.go index e97192876..2d227019c 100644 --- a/proxy/freedom/freedom_test.go +++ b/proxy/freedom/freedom_test.go @@ -48,7 +48,7 @@ func TestUDPSend(t *testing.T) { } 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 return ich, nil }) diff --git a/proxy/freedom/freedomfactory.go b/proxy/freedom/freedomfactory.go index b002857ef..e9142d550 100644 --- a/proxy/freedom/freedomfactory.go +++ b/proxy/freedom/freedomfactory.go @@ -8,7 +8,7 @@ import ( func init() { 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 }) } diff --git a/proxy/http/http_factory.go b/proxy/http/http_factory.go index 565845bdc..cfd6b5cdf 100644 --- a/proxy/http/http_factory.go +++ b/proxy/http/http_factory.go @@ -8,7 +8,7 @@ import ( func init() { 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 }) } diff --git a/proxy/internal/creator.go b/proxy/internal/creator.go index 8b085fc9c..39ebf3b4a 100644 --- a/proxy/internal/creator.go +++ b/proxy/internal/creator.go @@ -5,5 +5,5 @@ import ( "github.com/v2ray/v2ray-core/proxy" ) -type InboundConnectionHandlerCreator func(space app.Space, config interface{}) (proxy.InboundConnectionHandler, error) -type OutboundConnectionHandlerCreator func(space app.Space, config interface{}) (proxy.OutboundConnectionHandler, error) +type InboundConnectionHandlerCreator func(space app.Space, config interface{}) (proxy.InboundHandler, error) +type OutboundConnectionHandlerCreator func(space app.Space, config interface{}) (proxy.OutboundHandler, error) diff --git a/proxy/internal/handler_cache.go b/proxy/internal/handler_cache.go index 155b64f4c..31e2adb93 100644 --- a/proxy/internal/handler_cache.go +++ b/proxy/internal/handler_cache.go @@ -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] if !found { return nil, ErrorProxyNotFound @@ -60,7 +60,7 @@ func CreateInboundConnectionHandler(name string, space app.Space, rawConfig []by 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] if !found { return nil, ErrorNameExists diff --git a/proxy/proxy.go b/proxy/proxy.go index d488fa7fb..77b6ce2a0 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -8,7 +8,7 @@ import ( ) // 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(port v2net.Port) error // Close stops the handler to accepting anymore inbound connections. @@ -18,7 +18,7 @@ type InboundConnectionHandler interface { } // An OutboundConnectionHandler handles outbound network connection for V2Ray. -type OutboundConnectionHandler interface { +type OutboundHandler interface { // Dispatch sends one or more Packets to its destination. Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) error } diff --git a/proxy/repo/repo.go b/proxy/repo/repo.go index 509a0222f..e6ad1cc6c 100644 --- a/proxy/repo/repo.go +++ b/proxy/repo/repo.go @@ -6,10 +6,10 @@ import ( "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) } -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) } diff --git a/proxy/socks/socks_test.go b/proxy/socks/socks_test.go index 505c45ed1..5384b74f7 100644 --- a/proxy/socks/socks_test.go +++ b/proxy/socks/socks_test.go @@ -30,7 +30,7 @@ func TestSocksTcpConnect(t *testing.T) { 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 }) assert.Error(err).IsNil() @@ -89,7 +89,7 @@ func TestSocksTcpConnectWithUserPass(t *testing.T) { 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 }) assert.Error(err).IsNil() @@ -151,7 +151,7 @@ func TestSocksTcpConnectWithWrongUserPass(t *testing.T) { 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 }) assert.Error(err).IsNil() @@ -199,7 +199,7 @@ func TestSocksTcpConnectWithWrongAuthMethod(t *testing.T) { 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 }) assert.Error(err).IsNil() @@ -248,7 +248,7 @@ func TestSocksUdpSend(t *testing.T) { } 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 }) assert.Error(err).IsNil() diff --git a/proxy/socks/socksfactory.go b/proxy/socks/socksfactory.go index 848787eb0..d6e10d7af 100644 --- a/proxy/socks/socksfactory.go +++ b/proxy/socks/socksfactory.go @@ -8,7 +8,7 @@ import ( func init() { 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 }) } diff --git a/proxy/testing/mocks/outboundhandler.go b/proxy/testing/mocks/outboundhandler.go index 09d1e1e41..30613ce51 100644 --- a/proxy/testing/mocks/outboundhandler.go +++ b/proxy/testing/mocks/outboundhandler.go @@ -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{}) (proxy.OutboundConnectionHandler, error) { +func (this *OutboundConnectionHandler) Create(space app.Space, config interface{}) (proxy.OutboundHandler, error) { return this, nil } diff --git a/proxy/vmess/inbound/inbound.go b/proxy/vmess/inbound/inbound.go index 7a12cfc09..b3c4697bb 100644 --- a/proxy/vmess/inbound/inbound.go +++ b/proxy/vmess/inbound/inbound.go @@ -175,7 +175,7 @@ func handleOutput(request *protocol.VMessRequest, writer io.Writer, output <-cha func init() { internal.MustRegisterInboundConnectionHandlerCreator("vmess", - func(space app.Space, rawConfig interface{}) (proxy.InboundConnectionHandler, error) { + func(space app.Space, rawConfig interface{}) (proxy.InboundHandler, error) { config := rawConfig.(*Config) allowedClients := protocol.NewTimedUserSet() diff --git a/proxy/vmess/outbound/outbound.go b/proxy/vmess/outbound/outbound.go index d808b75f6..01a0353be 100644 --- a/proxy/vmess/outbound/outbound.go +++ b/proxy/vmess/outbound/outbound.go @@ -191,7 +191,7 @@ func (this *VMessOutboundHandler) handleResponse(conn net.Conn, request *protoco func init() { internal.MustRegisterOutboundConnectionHandlerCreator("vmess", - func(space app.Space, rawConfig interface{}) (proxy.OutboundConnectionHandler, error) { + func(space app.Space, rawConfig interface{}) (proxy.OutboundHandler, error) { vOutConfig := rawConfig.(*Config) return &VMessOutboundHandler{ space: space, diff --git a/proxy/vmess/vmess_test.go b/proxy/vmess/vmess_test.go index 4bcb76a2a..09a923c4d 100644 --- a/proxy/vmess/vmess_test.go +++ b/proxy/vmess/vmess_test.go @@ -37,7 +37,7 @@ func TestVMessInAndOut(t *testing.T) { 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 return ich, nil }) @@ -78,7 +78,7 @@ func TestVMessInAndOut(t *testing.T) { 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 }) assert.Error(err).IsNil() diff --git a/shell/point/inbound_detour.go b/shell/point/inbound_detour.go index d4b170d20..3e9bdcf1c 100644 --- a/shell/point/inbound_detour.go +++ b/shell/point/inbound_detour.go @@ -7,5 +7,5 @@ import ( type InboundDetourHandler interface { Start() error Close() - GetConnectionHandler() (proxy.InboundConnectionHandler, int) + GetConnectionHandler() (proxy.InboundHandler, int) } diff --git a/shell/point/inbound_detour_always.go b/shell/point/inbound_detour_always.go index dbcf2f841..807e50ef8 100644 --- a/shell/point/inbound_detour_always.go +++ b/shell/point/inbound_detour_always.go @@ -12,7 +12,7 @@ import ( type InboundConnectionHandlerWithPort struct { port v2net.Port - handler proxy.InboundConnectionHandler + handler proxy.InboundHandler } // Handler for inbound detour connections. @@ -44,7 +44,7 @@ func NewInboundDetourHandlerAlways(space app.Space, config *InboundDetourConfig) 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))] return ich.handler, this.config.Allocation.Refresh } diff --git a/shell/point/inbound_detour_dynamic.go b/shell/point/inbound_detour_dynamic.go index cd186c6df..e0bca356d 100644 --- a/shell/point/inbound_detour_dynamic.go +++ b/shell/point/inbound_detour_dynamic.go @@ -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() defer this.RUnlock() ich := this.ichInUse[dice.Roll(len(this.ichInUse))] diff --git a/shell/point/point.go b/shell/point/point.go index f7d3923ec..8eb220755 100644 --- a/shell/point/point.go +++ b/shell/point/point.go @@ -19,11 +19,11 @@ import ( // Point shell of V2Ray. type Point struct { port v2net.Port - ich proxy.InboundConnectionHandler - och proxy.OutboundConnectionHandler + ich proxy.InboundHandler + och proxy.OutboundHandler idh []InboundDetourHandler taggedIdh map[string]InboundDetourHandler - odh map[string]proxy.OutboundConnectionHandler + odh map[string]proxy.OutboundHandler router router.Router space *controller.SpaceController } @@ -107,7 +107,7 @@ func NewPoint(pConfig *Config) (*Point, error) { outboundDetours := pConfig.OutboundDetours if len(outboundDetours) > 0 { - vpoint.odh = make(map[string]proxy.OutboundConnectionHandler) + vpoint.odh = make(map[string]proxy.OutboundHandler) for _, detourConfig := range outboundDetours { detourHandler, err := proxyrepo.CreateOutboundConnectionHandler(detourConfig.Protocol, vpoint.space.ForContext(detourConfig.Tag), detourConfig.Settings) if err != nil { @@ -190,7 +190,7 @@ func (this *Point) DispatchToOutbound(context app.Context, packet v2net.Packet) 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 chunk := packet.Chunk() moreChunks := packet.MoreChunks() @@ -212,7 +212,7 @@ func (this *Point) FilterPacketAndDispatch(packet v2net.Packet, link ray.Outboun 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] if !found { return nil, 0