support using specific address

This commit is contained in:
v2ray committed 2016-06-04 00:38:22 +02:00
1 parent 6c31ff91e6
commit a4d76dc394
48 files changed
+412 -301

No files matched your search

+9 -11
View File
@@ -88,6 +88,8 @@ func (this *VMessInboundHandler) Close() {
this.Lock()
this.listener.Close()
this.listener = nil
this.clients.Release()
this.clients = nil
this.Unlock()
}
}
@@ -100,20 +102,14 @@ func (this *VMessInboundHandler) GetUser(email string) *protocol.User {
return user
}
func (this *VMessInboundHandler) Listen(address v2net.Address, port v2net.Port) error {
func (this *VMessInboundHandler) Start() error {
if this.accepting {
if this.listeningPort == port && this.listeningAddress.Equals(address) {
return nil
} else {
return proxy.ErrorAlreadyListening
}
return nil
}
this.listeningPort = port
this.listeningAddress = address
tcpListener, err := hub.ListenTCP(address, port, this.HandleConnection, nil)
tcpListener, err := hub.ListenTCP(this.listeningAddress, this.listeningPort, this.HandleConnection, nil)
if err != nil {
log.Error("Unable to listen tcp port ", port, ": ", err)
log.Error("Unable to listen tcp port ", this.listeningPort, ": ", err)
return err
}
this.accepting = true
@@ -224,7 +220,7 @@ func (this *VMessInboundHandler) HandleConnection(connection *hub.Connection) {
func init() {
internal.MustRegisterInboundHandlerCreator("vmess",
func(space app.Space, rawConfig interface{}) (proxy.InboundHandler, error) {
func(space app.Space, rawConfig interface{}, listen v2net.Address, port v2net.Port) (proxy.InboundHandler, error) {
if !space.HasApp(dispatcher.APP_ID) {
return nil, internal.ErrorBadConfiguration
}
@@ -240,6 +236,8 @@ func init() {
clients: allowedClients,
detours: config.DetourConfig,
usersByEmail: NewUserByEmail(config.AllowedUsers, config.Defaults),
listeningAddress: listen,
listeningPort: port,
}
if space.HasApp(proxyman.APP_ID_INBOUND_MANAGER) {
+4 -2
View File
@@ -21,6 +21,7 @@ import (
type VMessOutboundHandler struct {
receiverManager *ReceiverManager
sendThrough v2net.Address
}
func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *alloc.Buffer, ray ray.OutboundRay) error {
@@ -42,7 +43,7 @@ func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *al
Option: protocol.RequestOptionChunkStream,
}
conn, err := hub.Dial(destination)
conn, err := hub.Dial(this.sendThrough, destination)
if err != nil {
log.Error("Failed to open ", destination, ": ", err)
return err
@@ -142,10 +143,11 @@ func (this *VMessOutboundHandler) handleResponse(session *raw.ClientSession, con
func init() {
internal.MustRegisterOutboundHandlerCreator("vmess",
func(space app.Space, rawConfig interface{}) (proxy.OutboundHandler, error) {
func(space app.Space, rawConfig interface{}, sendThrough v2net.Address) (proxy.OutboundHandler, error) {
vOutConfig := rawConfig.(*Config)
return &VMessOutboundHandler{
receiverManager: NewReceiverManager(vOutConfig.Receivers),
sendThrough: sendThrough,
}, nil
})
}
+19 -15
View File
@@ -38,25 +38,28 @@ func TestVMessInAndOut(t *testing.T) {
ConnOutput: ichConnOutput,
}
protocol, err := proxytesting.RegisterInboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (proxy.InboundHandler, error) {
ich.PacketDispatcher = space.GetApp(dispatcher.APP_ID).(dispatcher.PacketDispatcher)
return ich, nil
})
protocol, err := proxytesting.RegisterInboundConnectionHandlerCreator("mock_ich",
func(space app.Space, config interface{}, listen v2net.Address, port v2net.Port) (proxy.InboundHandler, error) {
ich.ListeningAddress = listen
ich.ListeningPort = port
ich.PacketDispatcher = space.GetApp(dispatcher.APP_ID).(dispatcher.PacketDispatcher)
return ich, nil
})
assert.Error(err).IsNil()
configA := &point.Config{
Port: portA,
ListenOn: v2net.LocalHostIP,
Port: portA,
DNSConfig: &dns.Config{
NameServers: []v2net.Destination{
v2net.UDPDestination(v2net.DomainAddress("localhost"), v2net.Port(53)),
},
},
InboundConfig: &point.ConnectionConfig{
InboundConfig: &point.InboundConnectionConfig{
Protocol: protocol,
ListenOn: v2net.LocalHostIP,
Settings: nil,
},
OutboundConfig: &point.ConnectionConfig{
OutboundConfig: &point.OutboundConnectionConfig{
Protocol: "vmess",
Settings: []byte(`{
"vnext": [
@@ -85,28 +88,29 @@ func TestVMessInAndOut(t *testing.T) {
ConnOutput: ochConnOutput,
}
protocol, err = proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (proxy.OutboundHandler, error) {
return och, nil
})
protocol, err = proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och",
func(space app.Space, config interface{}, sendThrough v2net.Address) (proxy.OutboundHandler, error) {
return och, nil
})
assert.Error(err).IsNil()
configB := &point.Config{
Port: portB,
ListenOn: v2net.LocalHostIP,
Port: portB,
DNSConfig: &dns.Config{
NameServers: []v2net.Destination{
v2net.UDPDestination(v2net.DomainAddress("localhost"), v2net.Port(53)),
},
},
InboundConfig: &point.ConnectionConfig{
InboundConfig: &point.InboundConnectionConfig{
Protocol: "vmess",
ListenOn: v2net.LocalHostIP,
Settings: []byte(`{
"clients": [
{"id": "` + testAccount.String() + `"}
]
}`),
},
OutboundConfig: &point.ConnectionConfig{
OutboundConfig: &point.OutboundConnectionConfig{
Protocol: protocol,
Settings: nil,
},