mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 10:08:15 -05:00
Merge branch 'master' of https://github.com/v2ray/v2ray-core
This commit is contained in:
commit
798c870069
@ -10,6 +10,7 @@ import (
|
|||||||
. "github.com/v2ray/v2ray-core/app/dns"
|
. "github.com/v2ray/v2ray-core/app/dns"
|
||||||
"github.com/v2ray/v2ray-core/app/proxyman"
|
"github.com/v2ray/v2ray-core/app/proxyman"
|
||||||
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/freedom"
|
"github.com/v2ray/v2ray-core/proxy/freedom"
|
||||||
"github.com/v2ray/v2ray-core/testing/assert"
|
"github.com/v2ray/v2ray-core/testing/assert"
|
||||||
)
|
)
|
||||||
@ -20,7 +21,7 @@ func TestDnsAdd(t *testing.T) {
|
|||||||
space := app.NewSpace()
|
space := app.NewSpace()
|
||||||
|
|
||||||
outboundHandlerManager := proxyman.NewDefaultOutboundHandlerManager()
|
outboundHandlerManager := proxyman.NewDefaultOutboundHandlerManager()
|
||||||
outboundHandlerManager.SetDefaultHandler(freedom.NewFreedomConnection(&freedom.Config{}, space, v2net.AnyIP))
|
outboundHandlerManager.SetDefaultHandler(freedom.NewFreedomConnection(&freedom.Config{}, space, &proxy.OutboundHandlerMeta{Address: v2net.AnyIP}))
|
||||||
space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, outboundHandlerManager)
|
space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, outboundHandlerManager)
|
||||||
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
|
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
|
||||||
|
|
||||||
|
@ -11,10 +11,13 @@ import (
|
|||||||
|
|
||||||
// BlackHole is an outbound connection that sliently swallow the entire payload.
|
// BlackHole is an outbound connection that sliently swallow the entire payload.
|
||||||
type BlackHole struct {
|
type BlackHole struct {
|
||||||
|
meta *proxy.OutboundHandlerMeta
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBlackHole() *BlackHole {
|
func NewBlackHole(space app.Space, config *Config, meta *proxy.OutboundHandlerMeta) *BlackHole {
|
||||||
return &BlackHole{}
|
return &BlackHole{
|
||||||
|
meta: meta,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *BlackHole) Dispatch(destination v2net.Destination, payload *alloc.Buffer, ray ray.OutboundRay) error {
|
func (this *BlackHole) Dispatch(destination v2net.Destination, payload *alloc.Buffer, ray ray.OutboundRay) error {
|
||||||
@ -31,7 +34,7 @@ func (this *BlackHole) Dispatch(destination v2net.Destination, payload *alloc.Bu
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
internal.MustRegisterOutboundHandlerCreator("blackhole",
|
internal.MustRegisterOutboundHandlerCreator("blackhole",
|
||||||
func(space app.Space, config interface{}, sendThrough v2net.Address) (proxy.OutboundHandler, error) {
|
func(space app.Space, config interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
|
||||||
return NewBlackHole(), nil
|
return NewBlackHole(space, config.(*Config), meta), nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -25,17 +25,15 @@ type DokodemoDoor struct {
|
|||||||
tcpListener *hub.TCPHub
|
tcpListener *hub.TCPHub
|
||||||
udpHub *hub.UDPHub
|
udpHub *hub.UDPHub
|
||||||
udpServer *hub.UDPServer
|
udpServer *hub.UDPServer
|
||||||
listeningPort v2net.Port
|
meta *proxy.InboundHandlerMeta
|
||||||
listeningAddress v2net.Address
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDokodemoDoor(config *Config, space app.Space, listen v2net.Address, port v2net.Port) *DokodemoDoor {
|
func NewDokodemoDoor(config *Config, space app.Space, meta *proxy.InboundHandlerMeta) *DokodemoDoor {
|
||||||
d := &DokodemoDoor{
|
d := &DokodemoDoor{
|
||||||
config: config,
|
config: config,
|
||||||
address: config.Address,
|
address: config.Address,
|
||||||
port: config.Port,
|
port: config.Port,
|
||||||
listeningAddress: listen,
|
meta: meta,
|
||||||
listeningPort: port,
|
|
||||||
}
|
}
|
||||||
space.InitializeApplication(func() error {
|
space.InitializeApplication(func() error {
|
||||||
if !space.HasApp(dispatcher.APP_ID) {
|
if !space.HasApp(dispatcher.APP_ID) {
|
||||||
@ -49,7 +47,7 @@ func NewDokodemoDoor(config *Config, space app.Space, listen v2net.Address, port
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *DokodemoDoor) Port() v2net.Port {
|
func (this *DokodemoDoor) Port() v2net.Port {
|
||||||
return this.listeningPort
|
return this.meta.Port
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *DokodemoDoor) Close() {
|
func (this *DokodemoDoor) Close() {
|
||||||
@ -75,13 +73,13 @@ func (this *DokodemoDoor) Start() error {
|
|||||||
this.accepting = true
|
this.accepting = true
|
||||||
|
|
||||||
if this.config.Network.HasNetwork(v2net.TCPNetwork) {
|
if this.config.Network.HasNetwork(v2net.TCPNetwork) {
|
||||||
err := this.ListenTCP(this.listeningAddress, this.listeningPort)
|
err := this.ListenTCP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if this.config.Network.HasNetwork(v2net.UDPNetwork) {
|
if this.config.Network.HasNetwork(v2net.UDPNetwork) {
|
||||||
err := this.ListenUDP(this.listeningAddress, this.listeningPort)
|
err := this.ListenUDP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -89,11 +87,11 @@ func (this *DokodemoDoor) Start() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *DokodemoDoor) ListenUDP(address v2net.Address, port v2net.Port) error {
|
func (this *DokodemoDoor) ListenUDP() error {
|
||||||
this.udpServer = hub.NewUDPServer(this.packetDispatcher)
|
this.udpServer = hub.NewUDPServer(this.packetDispatcher)
|
||||||
udpHub, err := hub.ListenUDP(address, port, this.handleUDPPackets)
|
udpHub, err := hub.ListenUDP(this.meta.Address, this.meta.Port, this.handleUDPPackets)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Dokodemo failed to listen on port ", port, ": ", err)
|
log.Error("Dokodemo failed to listen on ", this.meta.Address, ":", this.meta.Port, ": ", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
this.udpMutex.Lock()
|
this.udpMutex.Lock()
|
||||||
@ -116,10 +114,10 @@ func (this *DokodemoDoor) handleUDPResponse(dest v2net.Destination, payload *all
|
|||||||
this.udpHub.WriteTo(payload.Value, dest)
|
this.udpHub.WriteTo(payload.Value, dest)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *DokodemoDoor) ListenTCP(address v2net.Address, port v2net.Port) error {
|
func (this *DokodemoDoor) ListenTCP() error {
|
||||||
tcpListener, err := hub.ListenTCP(address, port, this.HandleTCPConnection, nil)
|
tcpListener, err := hub.ListenTCP(this.meta.Address, this.meta.Port, this.HandleTCPConnection, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Dokodemo: Failed to listen on port ", port, ": ", err)
|
log.Error("Dokodemo: Failed to listen on ", this.meta.Address, ":", this.meta.Port, ": ", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
this.tcpMutex.Lock()
|
this.tcpMutex.Lock()
|
||||||
@ -164,7 +162,7 @@ func (this *DokodemoDoor) HandleTCPConnection(conn *hub.Connection) {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
internal.MustRegisterInboundHandlerCreator("dokodemo-door",
|
internal.MustRegisterInboundHandlerCreator("dokodemo-door",
|
||||||
func(space app.Space, rawConfig interface{}, listen v2net.Address, port v2net.Port) (proxy.InboundHandler, error) {
|
func(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
|
||||||
return NewDokodemoDoor(rawConfig.(*Config), space, listen, port), nil
|
return NewDokodemoDoor(rawConfig.(*Config), space, meta), nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/v2ray/v2ray-core/app/proxyman"
|
"github.com/v2ray/v2ray-core/app/proxyman"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy"
|
||||||
. "github.com/v2ray/v2ray-core/proxy/dokodemo"
|
. "github.com/v2ray/v2ray-core/proxy/dokodemo"
|
||||||
"github.com/v2ray/v2ray-core/proxy/freedom"
|
"github.com/v2ray/v2ray-core/proxy/freedom"
|
||||||
"github.com/v2ray/v2ray-core/testing/assert"
|
"github.com/v2ray/v2ray-core/testing/assert"
|
||||||
@ -37,7 +38,9 @@ func TestDokodemoTCP(t *testing.T) {
|
|||||||
space := app.NewSpace()
|
space := app.NewSpace()
|
||||||
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
|
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
|
||||||
ohm := proxyman.NewDefaultOutboundHandlerManager()
|
ohm := proxyman.NewDefaultOutboundHandlerManager()
|
||||||
ohm.SetDefaultHandler(freedom.NewFreedomConnection(&freedom.Config{}, space, v2net.LocalHostIP))
|
ohm.SetDefaultHandler(
|
||||||
|
freedom.NewFreedomConnection(
|
||||||
|
&freedom.Config{}, space, &proxy.OutboundHandlerMeta{Address: v2net.LocalHostIP}))
|
||||||
space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, ohm)
|
space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, ohm)
|
||||||
|
|
||||||
data2Send := "Data to be sent to remote."
|
data2Send := "Data to be sent to remote."
|
||||||
@ -48,7 +51,7 @@ func TestDokodemoTCP(t *testing.T) {
|
|||||||
Port: tcpServer.Port,
|
Port: tcpServer.Port,
|
||||||
Network: v2net.TCPNetwork.AsList(),
|
Network: v2net.TCPNetwork.AsList(),
|
||||||
Timeout: 600,
|
Timeout: 600,
|
||||||
}, space, v2net.LocalHostIP, port)
|
}, space, &proxy.InboundHandlerMeta{Address: v2net.LocalHostIP, Port: port})
|
||||||
defer dokodemo.Close()
|
defer dokodemo.Close()
|
||||||
|
|
||||||
assert.Error(space.Initialize()).IsNil()
|
assert.Error(space.Initialize()).IsNil()
|
||||||
@ -95,7 +98,9 @@ func TestDokodemoUDP(t *testing.T) {
|
|||||||
space := app.NewSpace()
|
space := app.NewSpace()
|
||||||
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
|
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
|
||||||
ohm := proxyman.NewDefaultOutboundHandlerManager()
|
ohm := proxyman.NewDefaultOutboundHandlerManager()
|
||||||
ohm.SetDefaultHandler(freedom.NewFreedomConnection(&freedom.Config{}, space, v2net.AnyIP))
|
ohm.SetDefaultHandler(
|
||||||
|
freedom.NewFreedomConnection(
|
||||||
|
&freedom.Config{}, space, &proxy.OutboundHandlerMeta{Address: v2net.AnyIP}))
|
||||||
space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, ohm)
|
space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, ohm)
|
||||||
|
|
||||||
data2Send := "Data to be sent to remote."
|
data2Send := "Data to be sent to remote."
|
||||||
@ -106,7 +111,7 @@ func TestDokodemoUDP(t *testing.T) {
|
|||||||
Port: udpServer.Port,
|
Port: udpServer.Port,
|
||||||
Network: v2net.UDPNetwork.AsList(),
|
Network: v2net.UDPNetwork.AsList(),
|
||||||
Timeout: 600,
|
Timeout: 600,
|
||||||
}, space, v2net.LocalHostIP, port)
|
}, space, &proxy.InboundHandlerMeta{Address: v2net.LocalHostIP, Port: port})
|
||||||
defer dokodemo.Close()
|
defer dokodemo.Close()
|
||||||
|
|
||||||
assert.Error(space.Initialize()).IsNil()
|
assert.Error(space.Initialize()).IsNil()
|
||||||
|
@ -23,14 +23,14 @@ type FreedomConnection struct {
|
|||||||
domainStrategy DomainStrategy
|
domainStrategy DomainStrategy
|
||||||
timeout uint32
|
timeout uint32
|
||||||
dns dns.Server
|
dns dns.Server
|
||||||
sendThrough v2net.Address
|
meta *proxy.OutboundHandlerMeta
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFreedomConnection(config *Config, space app.Space, sendThrough v2net.Address) *FreedomConnection {
|
func NewFreedomConnection(config *Config, space app.Space, meta *proxy.OutboundHandlerMeta) *FreedomConnection {
|
||||||
f := &FreedomConnection{
|
f := &FreedomConnection{
|
||||||
domainStrategy: config.DomainStrategy,
|
domainStrategy: config.DomainStrategy,
|
||||||
timeout: config.Timeout,
|
timeout: config.Timeout,
|
||||||
sendThrough: sendThrough,
|
meta: meta,
|
||||||
}
|
}
|
||||||
space.InitializeApplication(func() error {
|
space.InitializeApplication(func() error {
|
||||||
if config.DomainStrategy == DomainStrategyUseIP {
|
if config.DomainStrategy == DomainStrategyUseIP {
|
||||||
@ -80,7 +80,7 @@ func (this *FreedomConnection) Dispatch(destination v2net.Destination, payload *
|
|||||||
destination = this.ResolveIP(destination)
|
destination = this.ResolveIP(destination)
|
||||||
}
|
}
|
||||||
err := retry.Timed(5, 100).On(func() error {
|
err := retry.Timed(5, 100).On(func() error {
|
||||||
rawConn, err := hub.DialWithoutCache(this.sendThrough, destination)
|
rawConn, err := hub.DialWithoutCache(this.meta.Address, destination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -140,7 +140,7 @@ func (this *FreedomConnection) Dispatch(destination v2net.Destination, payload *
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
internal.MustRegisterOutboundHandlerCreator("freedom",
|
internal.MustRegisterOutboundHandlerCreator("freedom",
|
||||||
func(space app.Space, config interface{}, sendThrough v2net.Address) (proxy.OutboundHandler, error) {
|
func(space app.Space, config interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
|
||||||
return NewFreedomConnection(config.(*Config), space, sendThrough), nil
|
return NewFreedomConnection(config.(*Config), space, meta), nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,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"
|
||||||
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy"
|
||||||
. "github.com/v2ray/v2ray-core/proxy/freedom"
|
. "github.com/v2ray/v2ray-core/proxy/freedom"
|
||||||
"github.com/v2ray/v2ray-core/testing/assert"
|
"github.com/v2ray/v2ray-core/testing/assert"
|
||||||
"github.com/v2ray/v2ray-core/testing/servers/tcp"
|
"github.com/v2ray/v2ray-core/testing/servers/tcp"
|
||||||
@ -37,7 +38,7 @@ func TestSinglePacket(t *testing.T) {
|
|||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
|
||||||
space := app.NewSpace()
|
space := app.NewSpace()
|
||||||
freedom := NewFreedomConnection(&Config{}, space, v2net.AnyIP)
|
freedom := NewFreedomConnection(&Config{}, space, &proxy.OutboundHandlerMeta{Address: v2net.AnyIP})
|
||||||
space.Initialize()
|
space.Initialize()
|
||||||
|
|
||||||
traffic := ray.NewRay()
|
traffic := ray.NewRay()
|
||||||
@ -57,7 +58,7 @@ func TestSinglePacket(t *testing.T) {
|
|||||||
func TestUnreachableDestination(t *testing.T) {
|
func TestUnreachableDestination(t *testing.T) {
|
||||||
assert := assert.On(t)
|
assert := assert.On(t)
|
||||||
|
|
||||||
freedom := NewFreedomConnection(&Config{}, app.NewSpace(), v2net.AnyIP)
|
freedom := NewFreedomConnection(&Config{}, app.NewSpace(), &proxy.OutboundHandlerMeta{Address: v2net.AnyIP})
|
||||||
traffic := ray.NewRay()
|
traffic := ray.NewRay()
|
||||||
data2Send := "Data to be sent to remote"
|
data2Send := "Data to be sent to remote"
|
||||||
payload := alloc.NewSmallBuffer().Clear().Append([]byte(data2Send))
|
payload := alloc.NewSmallBuffer().Clear().Append([]byte(data2Send))
|
||||||
@ -81,7 +82,10 @@ func TestIPResolution(t *testing.T) {
|
|||||||
})
|
})
|
||||||
space.BindApp(dns.APP_ID, dnsServer)
|
space.BindApp(dns.APP_ID, dnsServer)
|
||||||
|
|
||||||
freedom := NewFreedomConnection(&Config{DomainStrategy: DomainStrategyUseIP}, space, v2net.AnyIP)
|
freedom := NewFreedomConnection(
|
||||||
|
&Config{DomainStrategy: DomainStrategyUseIP},
|
||||||
|
space,
|
||||||
|
&proxy.OutboundHandlerMeta{Address: v2net.AnyIP})
|
||||||
|
|
||||||
space.Initialize()
|
space.Initialize()
|
||||||
|
|
||||||
|
@ -29,21 +29,19 @@ type Server struct {
|
|||||||
packetDispatcher dispatcher.PacketDispatcher
|
packetDispatcher dispatcher.PacketDispatcher
|
||||||
config *Config
|
config *Config
|
||||||
tcpListener *hub.TCPHub
|
tcpListener *hub.TCPHub
|
||||||
listeningPort v2net.Port
|
meta *proxy.InboundHandlerMeta
|
||||||
listeningAddress v2net.Address
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer(config *Config, packetDispatcher dispatcher.PacketDispatcher, listen v2net.Address, port v2net.Port) *Server {
|
func NewServer(config *Config, packetDispatcher dispatcher.PacketDispatcher, meta *proxy.InboundHandlerMeta) *Server {
|
||||||
return &Server{
|
return &Server{
|
||||||
packetDispatcher: packetDispatcher,
|
packetDispatcher: packetDispatcher,
|
||||||
config: config,
|
config: config,
|
||||||
listeningAddress: listen,
|
meta: meta,
|
||||||
listeningPort: port,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Server) Port() v2net.Port {
|
func (this *Server) Port() v2net.Port {
|
||||||
return this.listeningPort
|
return this.meta.Port
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Server) Close() {
|
func (this *Server) Close() {
|
||||||
@ -65,9 +63,9 @@ func (this *Server) Start() error {
|
|||||||
if this.config.TLSConfig != nil {
|
if this.config.TLSConfig != nil {
|
||||||
tlsConfig = this.config.TLSConfig.GetConfig()
|
tlsConfig = this.config.TLSConfig.GetConfig()
|
||||||
}
|
}
|
||||||
tcpListener, err := hub.ListenTCP(this.listeningAddress, this.listeningPort, this.handleConnection, tlsConfig)
|
tcpListener, err := hub.ListenTCP(this.meta.Address, this.meta.Port, this.handleConnection, tlsConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("HTTP: Failed listen on port ", this.listeningPort, ": ", err)
|
log.Error("HTTP: Failed listen on ", this.meta.Address, ":", this.meta.Port, ": ", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
this.Lock()
|
this.Lock()
|
||||||
@ -272,14 +270,13 @@ func (this *Server) handlePlainHTTP(request *http.Request, dest v2net.Destinatio
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
internal.MustRegisterInboundHandlerCreator("http",
|
internal.MustRegisterInboundHandlerCreator("http",
|
||||||
func(space app.Space, rawConfig interface{}, listen v2net.Address, port v2net.Port) (proxy.InboundHandler, error) {
|
func(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
|
||||||
if !space.HasApp(dispatcher.APP_ID) {
|
if !space.HasApp(dispatcher.APP_ID) {
|
||||||
return nil, internal.ErrorBadConfiguration
|
return nil, internal.ErrorBadConfiguration
|
||||||
}
|
}
|
||||||
return NewServer(
|
return NewServer(
|
||||||
rawConfig.(*Config),
|
rawConfig.(*Config),
|
||||||
space.GetApp(dispatcher.APP_ID).(dispatcher.PacketDispatcher),
|
space.GetApp(dispatcher.APP_ID).(dispatcher.PacketDispatcher),
|
||||||
listen,
|
meta), nil
|
||||||
port), nil
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
testdispatcher "github.com/v2ray/v2ray-core/app/dispatcher/testing"
|
testdispatcher "github.com/v2ray/v2ray-core/app/dispatcher/testing"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
||||||
|
"github.com/v2ray/v2ray-core/proxy"
|
||||||
. "github.com/v2ray/v2ray-core/proxy/http"
|
. "github.com/v2ray/v2ray-core/proxy/http"
|
||||||
"github.com/v2ray/v2ray-core/testing/assert"
|
"github.com/v2ray/v2ray-core/testing/assert"
|
||||||
)
|
)
|
||||||
@ -53,7 +54,7 @@ func TestNormalGetRequest(t *testing.T) {
|
|||||||
testPacketDispatcher := testdispatcher.NewTestPacketDispatcher(nil)
|
testPacketDispatcher := testdispatcher.NewTestPacketDispatcher(nil)
|
||||||
|
|
||||||
port := v2nettesting.PickPort()
|
port := v2nettesting.PickPort()
|
||||||
httpProxy := NewServer(&Config{}, testPacketDispatcher, v2net.LocalHostIP, port)
|
httpProxy := NewServer(&Config{}, testPacketDispatcher, &proxy.InboundHandlerMeta{Address: v2net.LocalHostIP, Port: port})
|
||||||
defer httpProxy.Close()
|
defer httpProxy.Close()
|
||||||
|
|
||||||
err := httpProxy.Start()
|
err := httpProxy.Start()
|
||||||
|
@ -2,9 +2,8 @@ package internal
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/v2ray/v2ray-core/app"
|
"github.com/v2ray/v2ray-core/app"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
|
||||||
"github.com/v2ray/v2ray-core/proxy"
|
"github.com/v2ray/v2ray-core/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
type InboundHandlerCreator func(space app.Space, config interface{}, listenOn v2net.Address, port v2net.Port) (proxy.InboundHandler, error)
|
type InboundHandlerCreator func(space app.Space, config interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error)
|
||||||
type OutboundHandlerCreator func(space app.Space, config interface{}, sendThrough v2net.Address) (proxy.OutboundHandler, error)
|
type OutboundHandlerCreator func(space app.Space, config interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error)
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core/app"
|
"github.com/v2ray/v2ray-core/app"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
|
||||||
"github.com/v2ray/v2ray-core/proxy"
|
"github.com/v2ray/v2ray-core/proxy"
|
||||||
"github.com/v2ray/v2ray-core/proxy/internal/config"
|
"github.com/v2ray/v2ray-core/proxy/internal/config"
|
||||||
)
|
)
|
||||||
@ -46,7 +45,7 @@ func MustRegisterOutboundHandlerCreator(name string, creator OutboundHandlerCrea
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateInboundHandler(name string, space app.Space, rawConfig []byte, listen v2net.Address, port v2net.Port) (proxy.InboundHandler, error) {
|
func CreateInboundHandler(name string, space app.Space, rawConfig []byte, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
|
||||||
creator, found := inboundFactories[name]
|
creator, found := inboundFactories[name]
|
||||||
if !found {
|
if !found {
|
||||||
return nil, ErrorProxyNotFound
|
return nil, ErrorProxyNotFound
|
||||||
@ -56,12 +55,12 @@ func CreateInboundHandler(name string, space app.Space, rawConfig []byte, listen
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return creator(space, proxyConfig, listen, port)
|
return creator(space, proxyConfig, meta)
|
||||||
}
|
}
|
||||||
return creator(space, nil, listen, port)
|
return creator(space, nil, meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateOutboundHandler(name string, space app.Space, rawConfig []byte, sendThrough v2net.Address) (proxy.OutboundHandler, error) {
|
func CreateOutboundHandler(name string, space app.Space, rawConfig []byte, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
|
||||||
creator, found := outboundFactories[name]
|
creator, found := outboundFactories[name]
|
||||||
if !found {
|
if !found {
|
||||||
return nil, ErrorNameExists
|
return nil, ErrorNameExists
|
||||||
@ -72,8 +71,8 @@ func CreateOutboundHandler(name string, space app.Space, rawConfig []byte, sendT
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return creator(space, proxyConfig, sendThrough)
|
return creator(space, proxyConfig, meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
return creator(space, nil, sendThrough)
|
return creator(space, nil, meta)
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,17 @@ const (
|
|||||||
HandlerStateRunning = HandlerState(1)
|
HandlerStateRunning = HandlerState(1)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type InboundHandlerMeta struct {
|
||||||
|
Tag string
|
||||||
|
Address v2net.Address
|
||||||
|
Port v2net.Port
|
||||||
|
}
|
||||||
|
|
||||||
|
type OutboundHandlerMeta struct {
|
||||||
|
Tag string
|
||||||
|
Address v2net.Address
|
||||||
|
}
|
||||||
|
|
||||||
// An InboundHandler handles inbound network connections to V2Ray.
|
// An InboundHandler handles inbound network connections to V2Ray.
|
||||||
type InboundHandler interface {
|
type InboundHandler interface {
|
||||||
// Listen starts a InboundHandler.
|
// Listen starts a InboundHandler.
|
||||||
|
@ -2,15 +2,14 @@ package repo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/v2ray/v2ray-core/app"
|
"github.com/v2ray/v2ray-core/app"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
|
||||||
"github.com/v2ray/v2ray-core/proxy"
|
"github.com/v2ray/v2ray-core/proxy"
|
||||||
"github.com/v2ray/v2ray-core/proxy/internal"
|
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateInboundHandler(name string, space app.Space, rawConfig []byte, listen v2net.Address, port v2net.Port) (proxy.InboundHandler, error) {
|
func CreateInboundHandler(name string, space app.Space, rawConfig []byte, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
|
||||||
return internal.CreateInboundHandler(name, space, rawConfig, listen, port)
|
return internal.CreateInboundHandler(name, space, rawConfig, meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateOutboundHandler(name string, space app.Space, rawConfig []byte, sendThrough v2net.Address) (proxy.OutboundHandler, error) {
|
func CreateOutboundHandler(name string, space app.Space, rawConfig []byte, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
|
||||||
return internal.CreateOutboundHandler(name, space, rawConfig, sendThrough)
|
return internal.CreateOutboundHandler(name, space, rawConfig, meta)
|
||||||
}
|
}
|
||||||
|
@ -22,25 +22,23 @@ import (
|
|||||||
type Server struct {
|
type Server struct {
|
||||||
packetDispatcher dispatcher.PacketDispatcher
|
packetDispatcher dispatcher.PacketDispatcher
|
||||||
config *Config
|
config *Config
|
||||||
port v2net.Port
|
meta *proxy.InboundHandlerMeta
|
||||||
address v2net.Address
|
|
||||||
accepting bool
|
accepting bool
|
||||||
tcpHub *hub.TCPHub
|
tcpHub *hub.TCPHub
|
||||||
udpHub *hub.UDPHub
|
udpHub *hub.UDPHub
|
||||||
udpServer *hub.UDPServer
|
udpServer *hub.UDPServer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer(config *Config, packetDispatcher dispatcher.PacketDispatcher, listen v2net.Address, port v2net.Port) *Server {
|
func NewServer(config *Config, packetDispatcher dispatcher.PacketDispatcher, meta *proxy.InboundHandlerMeta) *Server {
|
||||||
return &Server{
|
return &Server{
|
||||||
config: config,
|
config: config,
|
||||||
packetDispatcher: packetDispatcher,
|
packetDispatcher: packetDispatcher,
|
||||||
address: listen,
|
meta: meta,
|
||||||
port: port,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Server) Port() v2net.Port {
|
func (this *Server) Port() v2net.Port {
|
||||||
return this.port
|
return this.meta.Port
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Server) Close() {
|
func (this *Server) Close() {
|
||||||
@ -63,18 +61,18 @@ func (this *Server) Start() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
tcpHub, err := hub.ListenTCP(this.address, this.port, this.handleConnection, nil)
|
tcpHub, err := hub.ListenTCP(this.meta.Address, this.meta.Port, this.handleConnection, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Shadowsocks: Failed to listen TCP on port ", this.port, ": ", err)
|
log.Error("Shadowsocks: Failed to listen TCP on ", this.meta.Address, ":", this.meta.Port, ": ", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
this.tcpHub = tcpHub
|
this.tcpHub = tcpHub
|
||||||
|
|
||||||
if this.config.UDP {
|
if this.config.UDP {
|
||||||
this.udpServer = hub.NewUDPServer(this.packetDispatcher)
|
this.udpServer = hub.NewUDPServer(this.packetDispatcher)
|
||||||
udpHub, err := hub.ListenUDP(this.address, this.port, this.handlerUDPPayload)
|
udpHub, err := hub.ListenUDP(this.meta.Address, this.meta.Port, this.handlerUDPPayload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Shadowsocks: Failed to listen UDP on port ", this.port, ": ", err)
|
log.Error("Shadowsocks: Failed to listen UDP on ", this.meta.Address, ":", this.meta.Port, ": ", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
this.udpHub = udpHub
|
this.udpHub = udpHub
|
||||||
@ -252,14 +250,13 @@ func (this *Server) handleConnection(conn *hub.Connection) {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
internal.MustRegisterInboundHandlerCreator("shadowsocks",
|
internal.MustRegisterInboundHandlerCreator("shadowsocks",
|
||||||
func(space app.Space, rawConfig interface{}, listen v2net.Address, port v2net.Port) (proxy.InboundHandler, error) {
|
func(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
|
||||||
if !space.HasApp(dispatcher.APP_ID) {
|
if !space.HasApp(dispatcher.APP_ID) {
|
||||||
return nil, internal.ErrorBadConfiguration
|
return nil, internal.ErrorBadConfiguration
|
||||||
}
|
}
|
||||||
return NewServer(
|
return NewServer(
|
||||||
rawConfig.(*Config),
|
rawConfig.(*Config),
|
||||||
space.GetApp(dispatcher.APP_ID).(dispatcher.PacketDispatcher),
|
space.GetApp(dispatcher.APP_ID).(dispatcher.PacketDispatcher),
|
||||||
listen,
|
meta), nil
|
||||||
port), nil
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -33,23 +33,21 @@ type Server struct {
|
|||||||
udpHub *hub.UDPHub
|
udpHub *hub.UDPHub
|
||||||
udpAddress v2net.Destination
|
udpAddress v2net.Destination
|
||||||
udpServer *hub.UDPServer
|
udpServer *hub.UDPServer
|
||||||
listeningPort v2net.Port
|
meta *proxy.InboundHandlerMeta
|
||||||
listeningAddress v2net.Address
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServer creates a new Server object.
|
// NewServer creates a new Server object.
|
||||||
func NewServer(config *Config, packetDispatcher dispatcher.PacketDispatcher, listen v2net.Address, port v2net.Port) *Server {
|
func NewServer(config *Config, packetDispatcher dispatcher.PacketDispatcher, meta *proxy.InboundHandlerMeta) *Server {
|
||||||
return &Server{
|
return &Server{
|
||||||
config: config,
|
config: config,
|
||||||
packetDispatcher: packetDispatcher,
|
packetDispatcher: packetDispatcher,
|
||||||
listeningAddress: listen,
|
meta: meta,
|
||||||
listeningPort: port,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Port implements InboundHandler.Port().
|
// Port implements InboundHandler.Port().
|
||||||
func (this *Server) Port() v2net.Port {
|
func (this *Server) Port() v2net.Port {
|
||||||
return this.listeningPort
|
return this.meta.Port
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close implements InboundHandler.Close().
|
// Close implements InboundHandler.Close().
|
||||||
@ -76,12 +74,12 @@ func (this *Server) Start() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
listener, err := hub.ListenTCP(
|
listener, err := hub.ListenTCP(
|
||||||
this.listeningAddress,
|
this.meta.Address,
|
||||||
this.listeningPort,
|
this.meta.Port,
|
||||||
this.handleConnection,
|
this.handleConnection,
|
||||||
nil)
|
nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Socks: failed to listen on port ", this.listeningPort, ": ", err)
|
log.Error("Socks: failed to listen on ", this.meta.Address, ":", this.meta.Port, ": ", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
this.accepting = true
|
this.accepting = true
|
||||||
@ -89,7 +87,7 @@ func (this *Server) Start() error {
|
|||||||
this.tcpListener = listener
|
this.tcpListener = listener
|
||||||
this.tcpMutex.Unlock()
|
this.tcpMutex.Unlock()
|
||||||
if this.config.UDPEnabled {
|
if this.config.UDPEnabled {
|
||||||
this.listenUDP(this.listeningAddress, this.listeningPort)
|
this.listenUDP()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -301,14 +299,13 @@ func (this *Server) transport(reader io.Reader, writer io.Writer, destination v2
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
internal.MustRegisterInboundHandlerCreator("socks",
|
internal.MustRegisterInboundHandlerCreator("socks",
|
||||||
func(space app.Space, rawConfig interface{}, listen v2net.Address, port v2net.Port) (proxy.InboundHandler, error) {
|
func(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
|
||||||
if !space.HasApp(dispatcher.APP_ID) {
|
if !space.HasApp(dispatcher.APP_ID) {
|
||||||
return nil, internal.ErrorBadConfiguration
|
return nil, internal.ErrorBadConfiguration
|
||||||
}
|
}
|
||||||
return NewServer(
|
return NewServer(
|
||||||
rawConfig.(*Config),
|
rawConfig.(*Config),
|
||||||
space.GetApp(dispatcher.APP_ID).(dispatcher.PacketDispatcher),
|
space.GetApp(dispatcher.APP_ID).(dispatcher.PacketDispatcher),
|
||||||
listen,
|
meta), nil
|
||||||
port), nil
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ func TestSocksTcpConnect(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och",
|
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och",
|
||||||
func(space app.Space, config interface{}, sendThrough v2net.Address) (v2proxy.OutboundHandler, error) {
|
func(space app.Space, config interface{}, meta *v2proxy.OutboundHandlerMeta) (v2proxy.OutboundHandler, error) {
|
||||||
return och, nil
|
return och, nil
|
||||||
})
|
})
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
@ -98,7 +98,7 @@ func TestSocksTcpConnectWithUserPass(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och",
|
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och",
|
||||||
func(space app.Space, config interface{}, sendThrough v2net.Address) (v2proxy.OutboundHandler, error) {
|
func(space app.Space, config interface{}, meta *v2proxy.OutboundHandlerMeta) (v2proxy.OutboundHandler, error) {
|
||||||
return och, nil
|
return och, nil
|
||||||
})
|
})
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
@ -167,7 +167,7 @@ func TestSocksTcpConnectWithWrongUserPass(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och",
|
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och",
|
||||||
func(space app.Space, config interface{}, sendThrough v2net.Address) (v2proxy.OutboundHandler, error) {
|
func(space app.Space, config interface{}, meta *v2proxy.OutboundHandlerMeta) (v2proxy.OutboundHandler, error) {
|
||||||
return och, nil
|
return och, nil
|
||||||
})
|
})
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
@ -222,7 +222,7 @@ func TestSocksTcpConnectWithWrongAuthMethod(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och",
|
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och",
|
||||||
func(space app.Space, config interface{}, sendThrough v2net.Address) (v2proxy.OutboundHandler, error) {
|
func(space app.Space, config interface{}, meta *v2proxy.OutboundHandlerMeta) (v2proxy.OutboundHandler, error) {
|
||||||
return och, nil
|
return och, nil
|
||||||
})
|
})
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
@ -8,15 +8,15 @@ import (
|
|||||||
"github.com/v2ray/v2ray-core/transport/hub"
|
"github.com/v2ray/v2ray-core/transport/hub"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (this *Server) listenUDP(address v2net.Address, port v2net.Port) error {
|
func (this *Server) listenUDP() error {
|
||||||
this.udpServer = hub.NewUDPServer(this.packetDispatcher)
|
this.udpServer = hub.NewUDPServer(this.packetDispatcher)
|
||||||
udpHub, err := hub.ListenUDP(address, port, this.handleUDPPayload)
|
udpHub, err := hub.ListenUDP(this.meta.Address, this.meta.Port, this.handleUDPPayload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Socks: Failed to listen on udp port ", port)
|
log.Error("Socks: Failed to listen on udp ", this.meta.Address, ":", this.meta.Port)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
this.udpMutex.Lock()
|
this.udpMutex.Lock()
|
||||||
this.udpAddress = v2net.UDPDestination(this.config.Address, port)
|
this.udpAddress = v2net.UDPDestination(this.config.Address, this.meta.Port)
|
||||||
this.udpHub = udpHub
|
this.udpHub = udpHub
|
||||||
this.udpMutex.Unlock()
|
this.udpMutex.Unlock()
|
||||||
return nil
|
return nil
|
||||||
|
@ -74,12 +74,11 @@ type VMessInboundHandler struct {
|
|||||||
accepting bool
|
accepting bool
|
||||||
listener *hub.TCPHub
|
listener *hub.TCPHub
|
||||||
detours *DetourConfig
|
detours *DetourConfig
|
||||||
listeningPort v2net.Port
|
meta *proxy.InboundHandlerMeta
|
||||||
listeningAddress v2net.Address
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *VMessInboundHandler) Port() v2net.Port {
|
func (this *VMessInboundHandler) Port() v2net.Port {
|
||||||
return this.listeningPort
|
return this.meta.Port
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *VMessInboundHandler) Close() {
|
func (this *VMessInboundHandler) Close() {
|
||||||
@ -107,9 +106,9 @@ func (this *VMessInboundHandler) Start() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
tcpListener, err := hub.ListenTCP(this.listeningAddress, this.listeningPort, this.HandleConnection, nil)
|
tcpListener, err := hub.ListenTCP(this.meta.Address, this.meta.Port, this.HandleConnection, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Unable to listen tcp port ", this.listeningPort, ": ", err)
|
log.Error("Unable to listen tcp ", this.meta.Address, ":", this.meta.Port, ": ", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
this.accepting = true
|
this.accepting = true
|
||||||
@ -220,7 +219,7 @@ func (this *VMessInboundHandler) HandleConnection(connection *hub.Connection) {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
internal.MustRegisterInboundHandlerCreator("vmess",
|
internal.MustRegisterInboundHandlerCreator("vmess",
|
||||||
func(space app.Space, rawConfig interface{}, listen v2net.Address, port v2net.Port) (proxy.InboundHandler, error) {
|
func(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
|
||||||
if !space.HasApp(dispatcher.APP_ID) {
|
if !space.HasApp(dispatcher.APP_ID) {
|
||||||
return nil, internal.ErrorBadConfiguration
|
return nil, internal.ErrorBadConfiguration
|
||||||
}
|
}
|
||||||
@ -236,8 +235,7 @@ func init() {
|
|||||||
clients: allowedClients,
|
clients: allowedClients,
|
||||||
detours: config.DetourConfig,
|
detours: config.DetourConfig,
|
||||||
usersByEmail: NewUserByEmail(config.AllowedUsers, config.Defaults),
|
usersByEmail: NewUserByEmail(config.AllowedUsers, config.Defaults),
|
||||||
listeningAddress: listen,
|
meta: meta,
|
||||||
listeningPort: port,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if space.HasApp(proxyman.APP_ID_INBOUND_MANAGER) {
|
if space.HasApp(proxyman.APP_ID_INBOUND_MANAGER) {
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
|
|
||||||
type VMessOutboundHandler struct {
|
type VMessOutboundHandler struct {
|
||||||
receiverManager *ReceiverManager
|
receiverManager *ReceiverManager
|
||||||
sendThrough v2net.Address
|
meta *proxy.OutboundHandlerMeta
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *alloc.Buffer, ray ray.OutboundRay) error {
|
func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *alloc.Buffer, ray ray.OutboundRay) error {
|
||||||
@ -43,7 +43,7 @@ func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *al
|
|||||||
Option: protocol.RequestOptionChunkStream,
|
Option: protocol.RequestOptionChunkStream,
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err := hub.Dial(this.sendThrough, destination)
|
conn, err := hub.Dial(this.meta.Address, destination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to open ", destination, ": ", err)
|
log.Error("Failed to open ", destination, ": ", err)
|
||||||
return err
|
return err
|
||||||
@ -143,11 +143,11 @@ func (this *VMessOutboundHandler) handleResponse(session *raw.ClientSession, con
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
internal.MustRegisterOutboundHandlerCreator("vmess",
|
internal.MustRegisterOutboundHandlerCreator("vmess",
|
||||||
func(space app.Space, rawConfig interface{}, sendThrough v2net.Address) (proxy.OutboundHandler, error) {
|
func(space app.Space, rawConfig interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
|
||||||
vOutConfig := rawConfig.(*Config)
|
vOutConfig := rawConfig.(*Config)
|
||||||
return &VMessOutboundHandler{
|
return &VMessOutboundHandler{
|
||||||
receiverManager: NewReceiverManager(vOutConfig.Receivers),
|
receiverManager: NewReceiverManager(vOutConfig.Receivers),
|
||||||
sendThrough: sendThrough,
|
meta: meta,
|
||||||
}, nil
|
}, nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -39,9 +39,9 @@ func TestVMessInAndOut(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protocol, err := proxytesting.RegisterInboundConnectionHandlerCreator("mock_ich",
|
protocol, err := proxytesting.RegisterInboundConnectionHandlerCreator("mock_ich",
|
||||||
func(space app.Space, config interface{}, listen v2net.Address, port v2net.Port) (proxy.InboundHandler, error) {
|
func(space app.Space, config interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
|
||||||
ich.ListeningAddress = listen
|
ich.ListeningAddress = meta.Address
|
||||||
ich.ListeningPort = port
|
ich.ListeningPort = meta.Port
|
||||||
ich.PacketDispatcher = space.GetApp(dispatcher.APP_ID).(dispatcher.PacketDispatcher)
|
ich.PacketDispatcher = space.GetApp(dispatcher.APP_ID).(dispatcher.PacketDispatcher)
|
||||||
return ich, nil
|
return ich, nil
|
||||||
})
|
})
|
||||||
@ -89,7 +89,7 @@ func TestVMessInAndOut(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protocol, err = proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och",
|
protocol, err = proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och",
|
||||||
func(space app.Space, config interface{}, sendThrough v2net.Address) (proxy.OutboundHandler, error) {
|
func(space app.Space, config interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
|
||||||
return och, nil
|
return och, nil
|
||||||
})
|
})
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
@ -4,23 +4,16 @@ import (
|
|||||||
"github.com/v2ray/v2ray-core/app"
|
"github.com/v2ray/v2ray-core/app"
|
||||||
"github.com/v2ray/v2ray-core/common/dice"
|
"github.com/v2ray/v2ray-core/common/dice"
|
||||||
"github.com/v2ray/v2ray-core/common/log"
|
"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/common/retry"
|
||||||
"github.com/v2ray/v2ray-core/proxy"
|
"github.com/v2ray/v2ray-core/proxy"
|
||||||
proxyrepo "github.com/v2ray/v2ray-core/proxy/repo"
|
proxyrepo "github.com/v2ray/v2ray-core/proxy/repo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type InboundConnectionHandlerWithPort struct {
|
|
||||||
port v2net.Port
|
|
||||||
listen v2net.Address
|
|
||||||
handler proxy.InboundHandler
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handler for inbound detour connections.
|
// Handler for inbound detour connections.
|
||||||
type InboundDetourHandlerAlways struct {
|
type InboundDetourHandlerAlways struct {
|
||||||
space app.Space
|
space app.Space
|
||||||
config *InboundDetourConfig
|
config *InboundDetourConfig
|
||||||
ich []*InboundConnectionHandlerWithPort
|
ich []proxy.InboundHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewInboundDetourHandlerAlways(space app.Space, config *InboundDetourConfig) (*InboundDetourHandlerAlways, error) {
|
func NewInboundDetourHandlerAlways(space app.Space, config *InboundDetourConfig) (*InboundDetourHandlerAlways, error) {
|
||||||
@ -29,31 +22,30 @@ func NewInboundDetourHandlerAlways(space app.Space, config *InboundDetourConfig)
|
|||||||
config: config,
|
config: config,
|
||||||
}
|
}
|
||||||
ports := config.PortRange
|
ports := config.PortRange
|
||||||
handler.ich = make([]*InboundConnectionHandlerWithPort, 0, ports.To-ports.From+1)
|
handler.ich = make([]proxy.InboundHandler, 0, ports.To-ports.From+1)
|
||||||
for i := ports.From; i <= ports.To; i++ {
|
for i := ports.From; i <= ports.To; i++ {
|
||||||
ichConfig := config.Settings
|
ichConfig := config.Settings
|
||||||
ich, err := proxyrepo.CreateInboundHandler(config.Protocol, space, ichConfig, config.ListenOn, i)
|
ich, err := proxyrepo.CreateInboundHandler(config.Protocol, space, ichConfig, &proxy.InboundHandlerMeta{
|
||||||
|
Address: config.ListenOn,
|
||||||
|
Port: i,
|
||||||
|
Tag: config.Tag})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to create inbound connection handler: ", err)
|
log.Error("Failed to create inbound connection handler: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
handler.ich = append(handler.ich, &InboundConnectionHandlerWithPort{
|
handler.ich = append(handler.ich, ich)
|
||||||
port: i,
|
|
||||||
handler: ich,
|
|
||||||
listen: config.ListenOn,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
return handler, nil
|
return handler, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *InboundDetourHandlerAlways) GetConnectionHandler() (proxy.InboundHandler, 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, this.config.Allocation.Refresh
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *InboundDetourHandlerAlways) Close() {
|
func (this *InboundDetourHandlerAlways) Close() {
|
||||||
for _, ich := range this.ich {
|
for _, ich := range this.ich {
|
||||||
ich.handler.Close()
|
ich.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,9 +53,9 @@ func (this *InboundDetourHandlerAlways) Close() {
|
|||||||
func (this *InboundDetourHandlerAlways) Start() error {
|
func (this *InboundDetourHandlerAlways) Start() error {
|
||||||
for _, ich := range this.ich {
|
for _, ich := range this.ich {
|
||||||
err := retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
|
err := retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
|
||||||
err := ich.handler.Start()
|
err := ich.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to start inbound detour on port ", ich.port, ": ", err)
|
log.Error("Failed to start inbound detour:", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -30,7 +30,10 @@ func NewInboundDetourHandlerDynamic(space app.Space, config *InboundDetourConfig
|
|||||||
handler.ichs = make([]proxy.InboundHandler, config.Allocation.Concurrency)
|
handler.ichs = make([]proxy.InboundHandler, config.Allocation.Concurrency)
|
||||||
|
|
||||||
// To test configuration
|
// To test configuration
|
||||||
ich, err := proxyrepo.CreateInboundHandler(config.Protocol, space, config.Settings, config.ListenOn, 0)
|
ich, err := proxyrepo.CreateInboundHandler(config.Protocol, space, config.Settings, &proxy.InboundHandlerMeta{
|
||||||
|
Address: config.ListenOn,
|
||||||
|
Port: 0,
|
||||||
|
Tag: config.Tag})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Point: Failed to create inbound connection handler: ", err)
|
log.Error("Point: Failed to create inbound connection handler: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -80,7 +83,8 @@ func (this *InboundDetourHandlerDynamic) refresh() error {
|
|||||||
|
|
||||||
for idx, _ := range newIchs {
|
for idx, _ := range newIchs {
|
||||||
port := this.pickUnusedPort()
|
port := this.pickUnusedPort()
|
||||||
ich, err := proxyrepo.CreateInboundHandler(config.Protocol, this.space, config.Settings, config.ListenOn, port)
|
ich, err := proxyrepo.CreateInboundHandler(config.Protocol, this.space, config.Settings, &proxy.InboundHandlerMeta{
|
||||||
|
Address: config.ListenOn, Port: port, Tag: config.Tag})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Point: Failed to create inbound connection handler: ", err)
|
log.Error("Point: Failed to create inbound connection handler: ", err)
|
||||||
return err
|
return err
|
||||||
|
@ -91,7 +91,11 @@ func NewPoint(pConfig *Config) (*Point, error) {
|
|||||||
vpoint.space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(vpoint.space))
|
vpoint.space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(vpoint.space))
|
||||||
|
|
||||||
ichConfig := pConfig.InboundConfig.Settings
|
ichConfig := pConfig.InboundConfig.Settings
|
||||||
ich, err := proxyrepo.CreateInboundHandler(pConfig.InboundConfig.Protocol, vpoint.space, ichConfig, pConfig.InboundConfig.ListenOn, vpoint.port)
|
ich, err := proxyrepo.CreateInboundHandler(
|
||||||
|
pConfig.InboundConfig.Protocol, vpoint.space, ichConfig, &proxy.InboundHandlerMeta{
|
||||||
|
Tag: "system.inbound",
|
||||||
|
Address: pConfig.InboundConfig.ListenOn,
|
||||||
|
Port: vpoint.port})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to create inbound connection handler: ", err)
|
log.Error("Failed to create inbound connection handler: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -99,7 +103,10 @@ func NewPoint(pConfig *Config) (*Point, error) {
|
|||||||
vpoint.ich = ich
|
vpoint.ich = ich
|
||||||
|
|
||||||
ochConfig := pConfig.OutboundConfig.Settings
|
ochConfig := pConfig.OutboundConfig.Settings
|
||||||
och, err := proxyrepo.CreateOutboundHandler(pConfig.OutboundConfig.Protocol, vpoint.space, ochConfig, pConfig.OutboundConfig.SendThrough)
|
och, err := proxyrepo.CreateOutboundHandler(
|
||||||
|
pConfig.OutboundConfig.Protocol, vpoint.space, ochConfig, &proxy.OutboundHandlerMeta{
|
||||||
|
Tag: "system.outbound",
|
||||||
|
Address: pConfig.OutboundConfig.SendThrough})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to create outbound connection handler: ", err)
|
log.Error("Failed to create outbound connection handler: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -144,7 +151,10 @@ func NewPoint(pConfig *Config) (*Point, error) {
|
|||||||
if len(outboundDetours) > 0 {
|
if len(outboundDetours) > 0 {
|
||||||
vpoint.odh = make(map[string]proxy.OutboundHandler)
|
vpoint.odh = make(map[string]proxy.OutboundHandler)
|
||||||
for _, detourConfig := range outboundDetours {
|
for _, detourConfig := range outboundDetours {
|
||||||
detourHandler, err := proxyrepo.CreateOutboundHandler(detourConfig.Protocol, vpoint.space, detourConfig.Settings, detourConfig.SendThrough)
|
detourHandler, err := proxyrepo.CreateOutboundHandler(
|
||||||
|
detourConfig.Protocol, vpoint.space, detourConfig.Settings, &proxy.OutboundHandlerMeta{
|
||||||
|
Tag: detourConfig.Tag,
|
||||||
|
Address: detourConfig.SendThrough})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Point: Failed to create detour outbound connection handler: ", err)
|
log.Error("Point: Failed to create detour outbound connection handler: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user