From b47c1ca6094f1c90b25703fac16d96a566a3affa Mon Sep 17 00:00:00 2001 From: v2ray Date: Sun, 29 May 2016 16:37:52 +0200 Subject: [PATCH] get rid of annoying firewall warnings --- common/net/address.go | 1 + proxy/dokodemo/dokodemo.go | 18 ++++++++++-------- proxy/dokodemo/dokodemo_test.go | 4 ++-- proxy/http/server.go | 8 +++++--- proxy/http/server_test.go | 3 ++- proxy/proxy.go | 2 +- proxy/shadowsocks/server.go | 10 ++++++---- proxy/socks/server.go | 10 ++++++---- proxy/socks/server_test.go | 12 ++++++++---- proxy/socks/server_udp.go | 4 ++-- proxy/testing/mocks/inboundhandler.go | 4 +++- proxy/vmess/inbound/inbound.go | 8 +++++--- proxy/vmess/vmess_test.go | 6 ++++-- shell/point/config.go | 2 ++ shell/point/config_json.go | 17 +++++++++++++++++ shell/point/inbound_detour_always.go | 4 +++- shell/point/inbound_detour_dynamic.go | 2 +- shell/point/point.go | 4 +++- testing/scenarios/data/test_1_client.json | 1 + testing/scenarios/data/test_1_server.json | 6 +++--- testing/scenarios/data/test_2_client.json | 2 ++ testing/scenarios/data/test_2_server.json | 4 ++++ testing/scenarios/data/test_3_client.json | 6 +++--- testing/scenarios/data/test_3_server.json | 1 + testing/scenarios/data/test_4_client.json | 1 + testing/scenarios/data/test_4_server.json | 2 ++ testing/scenarios/data/test_5_client.json | 1 + testing/scenarios/data/test_5_server.json | 1 + testing/scenarios/data/test_6_server.json | 3 +++ testing/servers/http/http.go | 2 +- testing/servers/tcp/tcp.go | 2 +- testing/servers/udp/udp.go | 2 +- transport/hub/tcp.go | 4 ++-- transport/hub/udp.go | 4 ++-- 34 files changed, 110 insertions(+), 51 deletions(-) diff --git a/common/net/address.go b/common/net/address.go index d05244b7..181c20ea 100644 --- a/common/net/address.go +++ b/common/net/address.go @@ -9,6 +9,7 @@ import ( var ( LocalHostIP = IPAddress([]byte{127, 0, 0, 1}) + AnyIP = IPAddress([]byte{0, 0, 0, 0}) ) // Address represents a network address to be communicated with. It may be an IP address or domain diff --git a/proxy/dokodemo/dokodemo.go b/proxy/dokodemo/dokodemo.go index 121a2fa2..067cd21c 100644 --- a/proxy/dokodemo/dokodemo.go +++ b/proxy/dokodemo/dokodemo.go @@ -26,6 +26,7 @@ type DokodemoDoor struct { udpHub *hub.UDPHub udpServer *hub.UDPServer listeningPort v2net.Port + listeningAddress v2net.Address } func NewDokodemoDoor(config *Config, space app.Space) *DokodemoDoor { @@ -65,25 +66,26 @@ func (this *DokodemoDoor) Close() { } } -func (this *DokodemoDoor) Listen(port v2net.Port) error { +func (this *DokodemoDoor) Listen(address v2net.Address, port v2net.Port) error { if this.accepting { - if this.listeningPort == port { + if this.listeningPort == port && this.listeningAddress.Equals(address) { return nil } else { return proxy.ErrorAlreadyListening } } this.listeningPort = port + this.listeningAddress = address this.accepting = true if this.config.Network.HasNetwork(v2net.TCPNetwork) { - err := this.ListenTCP(port) + err := this.ListenTCP(address, port) if err != nil { return err } } if this.config.Network.HasNetwork(v2net.UDPNetwork) { - err := this.ListenUDP(port) + err := this.ListenUDP(address, port) if err != nil { return err } @@ -91,9 +93,9 @@ func (this *DokodemoDoor) Listen(port v2net.Port) error { return nil } -func (this *DokodemoDoor) ListenUDP(port v2net.Port) error { +func (this *DokodemoDoor) ListenUDP(address v2net.Address, port v2net.Port) error { this.udpServer = hub.NewUDPServer(this.packetDispatcher) - udpHub, err := hub.ListenUDP(port, this.handleUDPPackets) + udpHub, err := hub.ListenUDP(address, port, this.handleUDPPackets) if err != nil { log.Error("Dokodemo failed to listen on port ", port, ": ", err) return err @@ -118,8 +120,8 @@ func (this *DokodemoDoor) handleUDPResponse(dest v2net.Destination, payload *all this.udpHub.WriteTo(payload.Value, dest) } -func (this *DokodemoDoor) ListenTCP(port v2net.Port) error { - tcpListener, err := hub.ListenTCP(port, this.HandleTCPConnection, nil) +func (this *DokodemoDoor) ListenTCP(address v2net.Address, port v2net.Port) error { + tcpListener, err := hub.ListenTCP(address, port, this.HandleTCPConnection, nil) if err != nil { log.Error("Dokodemo: Failed to listen on port ", port, ": ", err) return err diff --git a/proxy/dokodemo/dokodemo_test.go b/proxy/dokodemo/dokodemo_test.go index a3748651..96c4cd25 100644 --- a/proxy/dokodemo/dokodemo_test.go +++ b/proxy/dokodemo/dokodemo_test.go @@ -53,7 +53,7 @@ func TestDokodemoTCP(t *testing.T) { assert.Error(space.Initialize()).IsNil() port := v2nettesting.PickPort() - err = dokodemo.Listen(port) + err = dokodemo.Listen(v2net.LocalHostIP, port) assert.Error(err).IsNil() assert.Port(port).Equals(dokodemo.Port()) @@ -111,7 +111,7 @@ func TestDokodemoUDP(t *testing.T) { assert.Error(space.Initialize()).IsNil() port := v2nettesting.PickPort() - err = dokodemo.Listen(port) + err = dokodemo.Listen(v2net.LocalHostIP, port) assert.Error(err).IsNil() assert.Port(port).Equals(dokodemo.Port()) diff --git a/proxy/http/server.go b/proxy/http/server.go index 3e58dea2..ceb05f00 100644 --- a/proxy/http/server.go +++ b/proxy/http/server.go @@ -29,6 +29,7 @@ type HttpProxyServer struct { config *Config tcpListener *hub.TCPHub listeningPort v2net.Port + listeningAddress v2net.Address } func NewHttpProxyServer(config *Config, packetDispatcher dispatcher.PacketDispatcher) *HttpProxyServer { @@ -52,21 +53,22 @@ func (this *HttpProxyServer) Close() { } } -func (this *HttpProxyServer) Listen(port v2net.Port) error { +func (this *HttpProxyServer) Listen(address v2net.Address, port v2net.Port) error { if this.accepting { - if this.listeningPort == port { + if this.listeningPort == port && this.listeningAddress.Equals(address) { return nil } else { return proxy.ErrorAlreadyListening } } this.listeningPort = port + this.listeningAddress = address var tlsConfig *tls.Config = nil if this.config.TlsConfig != nil { tlsConfig = this.config.TlsConfig.GetConfig() } - tcpListener, err := hub.ListenTCP(port, this.handleConnection, tlsConfig) + tcpListener, err := hub.ListenTCP(address, port, this.handleConnection, tlsConfig) if err != nil { log.Error("Http: Failed listen on port ", port, ": ", err) return err diff --git a/proxy/http/server_test.go b/proxy/http/server_test.go index 41dcff92..36c33b38 100644 --- a/proxy/http/server_test.go +++ b/proxy/http/server_test.go @@ -7,6 +7,7 @@ import ( "testing" testdispatcher "github.com/v2ray/v2ray-core/app/dispatcher/testing" + v2net "github.com/v2ray/v2ray-core/common/net" v2nettesting "github.com/v2ray/v2ray-core/common/net/testing" . "github.com/v2ray/v2ray-core/proxy/http" "github.com/v2ray/v2ray-core/testing/assert" @@ -55,7 +56,7 @@ func TestNormalGetRequest(t *testing.T) { defer httpProxy.Close() port := v2nettesting.PickPort() - err := httpProxy.Listen(port) + err := httpProxy.Listen(v2net.LocalHostIP, port) assert.Error(err).IsNil() assert.Port(port).Equals(httpProxy.Port()) diff --git a/proxy/proxy.go b/proxy/proxy.go index ac703f7f..862e0edb 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -17,7 +17,7 @@ const ( // An InboundHandler handles inbound network connections to V2Ray. type InboundHandler interface { // Listen starts a InboundHandler by listen on a specific port. - Listen(port v2net.Port) error + Listen(on v2net.Address, port v2net.Port) error // Close stops the handler to accepting anymore inbound connections. Close() // Port returns the port that the handler is listening on. diff --git a/proxy/shadowsocks/server.go b/proxy/shadowsocks/server.go index 5763ef9c..873d4d6d 100644 --- a/proxy/shadowsocks/server.go +++ b/proxy/shadowsocks/server.go @@ -23,6 +23,7 @@ type Server struct { packetDispatcher dispatcher.PacketDispatcher config *Config port v2net.Port + address v2net.Address accepting bool tcpHub *hub.TCPHub udpHub *hub.UDPHub @@ -55,16 +56,16 @@ func (this *Server) Close() { } -func (this *Server) Listen(port v2net.Port) error { +func (this *Server) Listen(address v2net.Address, port v2net.Port) error { if this.accepting { - if this.port == port { + if this.port == port && this.address.Equals(address) { return nil } else { return proxy.ErrorAlreadyListening } } - tcpHub, err := hub.ListenTCP(port, this.handleConnection, nil) + tcpHub, err := hub.ListenTCP(address, port, this.handleConnection, nil) if err != nil { log.Error("Shadowsocks: Failed to listen TCP on port ", port, ": ", err) return err @@ -73,7 +74,7 @@ func (this *Server) Listen(port v2net.Port) error { if this.config.UDP { this.udpServer = hub.NewUDPServer(this.packetDispatcher) - udpHub, err := hub.ListenUDP(port, this.handlerUDPPayload) + udpHub, err := hub.ListenUDP(address, port, this.handlerUDPPayload) if err != nil { log.Error("Shadowsocks: Failed to listen UDP on port ", port, ": ", err) return err @@ -82,6 +83,7 @@ func (this *Server) Listen(port v2net.Port) error { } this.port = port + this.address = address this.accepting = true return nil diff --git a/proxy/socks/server.go b/proxy/socks/server.go index a4998a71..1b165a64 100644 --- a/proxy/socks/server.go +++ b/proxy/socks/server.go @@ -34,6 +34,7 @@ type Server struct { udpAddress v2net.Destination udpServer *hub.UDPServer listeningPort v2net.Port + listeningAddress v2net.Address } // NewServer creates a new Server object. @@ -67,17 +68,18 @@ func (this *Server) Close() { } // Listen implements InboundHandler.Listen(). -func (this *Server) Listen(port v2net.Port) error { +func (this *Server) Listen(address v2net.Address, port v2net.Port) error { if this.accepting { - if this.listeningPort == port { + if this.listeningPort == port && this.listeningAddress.Equals(address) { return nil } else { return proxy.ErrorAlreadyListening } } this.listeningPort = port + this.listeningAddress = address - listener, err := hub.ListenTCP(port, this.handleConnection, nil) + listener, err := hub.ListenTCP(address, port, this.handleConnection, nil) if err != nil { log.Error("Socks: failed to listen on port ", port, ": ", err) return err @@ -87,7 +89,7 @@ func (this *Server) Listen(port v2net.Port) error { this.tcpListener = listener this.tcpMutex.Unlock() if this.config.UDPEnabled { - this.listenUDP(port) + this.listenUDP(address, port) } return nil } diff --git a/proxy/socks/server_test.go b/proxy/socks/server_test.go index ccfd2f15..4fa6b695 100644 --- a/proxy/socks/server_test.go +++ b/proxy/socks/server_test.go @@ -37,7 +37,8 @@ func TestSocksTcpConnect(t *testing.T) { assert.Error(err).IsNil() config := &point.Config{ - Port: port, + Port: port, + ListenOn: v2net.LocalHostIP, InboundConfig: &point.ConnectionConfig{ Protocol: "socks", Settings: []byte(` @@ -101,7 +102,8 @@ func TestSocksTcpConnectWithUserPass(t *testing.T) { assert.Error(err).IsNil() config := &point.Config{ - Port: port, + Port: port, + ListenOn: v2net.LocalHostIP, InboundConfig: &point.ConnectionConfig{ Protocol: "socks", Settings: []byte(` @@ -168,7 +170,8 @@ func TestSocksTcpConnectWithWrongUserPass(t *testing.T) { assert.Error(err).IsNil() config := &point.Config{ - Port: port, + Port: port, + ListenOn: v2net.LocalHostIP, InboundConfig: &point.ConnectionConfig{ Protocol: "socks", Settings: []byte(` @@ -221,7 +224,8 @@ func TestSocksTcpConnectWithWrongAuthMethod(t *testing.T) { assert.Error(err).IsNil() config := &point.Config{ - Port: port, + Port: port, + ListenOn: v2net.LocalHostIP, InboundConfig: &point.ConnectionConfig{ Protocol: "socks", Settings: []byte(` diff --git a/proxy/socks/server_udp.go b/proxy/socks/server_udp.go index 245dff96..bd748ff6 100644 --- a/proxy/socks/server_udp.go +++ b/proxy/socks/server_udp.go @@ -8,9 +8,9 @@ import ( "github.com/v2ray/v2ray-core/transport/hub" ) -func (this *Server) listenUDP(port v2net.Port) error { +func (this *Server) listenUDP(address v2net.Address, port v2net.Port) error { this.udpServer = hub.NewUDPServer(this.packetDispatcher) - udpHub, err := hub.ListenUDP(port, this.handleUDPPayload) + udpHub, err := hub.ListenUDP(address, port, this.handleUDPPayload) if err != nil { log.Error("Socks: Failed to listen on udp port ", port) return err diff --git a/proxy/testing/mocks/inboundhandler.go b/proxy/testing/mocks/inboundhandler.go index 37cfce0b..35bdfe90 100644 --- a/proxy/testing/mocks/inboundhandler.go +++ b/proxy/testing/mocks/inboundhandler.go @@ -11,13 +11,15 @@ import ( type InboundConnectionHandler struct { port v2net.Port + address v2net.Address PacketDispatcher dispatcher.PacketDispatcher ConnInput io.Reader ConnOutput io.Writer } -func (this *InboundConnectionHandler) Listen(port v2net.Port) error { +func (this *InboundConnectionHandler) Listen(address v2net.Address, port v2net.Port) error { this.port = port + this.address = address return nil } diff --git a/proxy/vmess/inbound/inbound.go b/proxy/vmess/inbound/inbound.go index 091b3c0a..6a708403 100644 --- a/proxy/vmess/inbound/inbound.go +++ b/proxy/vmess/inbound/inbound.go @@ -73,6 +73,7 @@ type VMessInboundHandler struct { listener *hub.TCPHub features *FeaturesConfig listeningPort v2net.Port + listeningAddress v2net.Address } func (this *VMessInboundHandler) Port() v2net.Port { @@ -97,17 +98,18 @@ func (this *VMessInboundHandler) GetUser(email string) *protocol.User { return user } -func (this *VMessInboundHandler) Listen(port v2net.Port) error { +func (this *VMessInboundHandler) Listen(address v2net.Address, port v2net.Port) error { if this.accepting { - if this.listeningPort == port { + if this.listeningPort == port && this.listeningAddress.Equals(address) { return nil } else { return proxy.ErrorAlreadyListening } } this.listeningPort = port + this.listeningAddress = address - tcpListener, err := hub.ListenTCP(port, this.HandleConnection, nil) + tcpListener, err := hub.ListenTCP(address, port, this.HandleConnection, nil) if err != nil { log.Error("Unable to listen tcp port ", port, ": ", err) return err diff --git a/proxy/vmess/vmess_test.go b/proxy/vmess/vmess_test.go index 370a41ad..e76b277f 100644 --- a/proxy/vmess/vmess_test.go +++ b/proxy/vmess/vmess_test.go @@ -45,7 +45,8 @@ func TestVMessInAndOut(t *testing.T) { assert.Error(err).IsNil() configA := &point.Config{ - Port: portA, + Port: portA, + ListenOn: v2net.LocalHostIP, DNSConfig: &dns.Config{ NameServers: []v2net.Destination{ v2net.UDPDestination(v2net.DomainAddress("localhost"), v2net.Port(53)), @@ -90,7 +91,8 @@ func TestVMessInAndOut(t *testing.T) { assert.Error(err).IsNil() configB := &point.Config{ - Port: portB, + Port: portB, + ListenOn: v2net.LocalHostIP, DNSConfig: &dns.Config{ NameServers: []v2net.Destination{ v2net.UDPDestination(v2net.DomainAddress("localhost"), v2net.Port(53)), diff --git a/shell/point/config.go b/shell/point/config.go index eee982fd..d8a96e51 100644 --- a/shell/point/config.go +++ b/shell/point/config.go @@ -33,6 +33,7 @@ type InboundDetourAllocationConfig struct { type InboundDetourConfig struct { Protocol string PortRange v2net.PortRange + ListenOn v2net.Address Tag string Allocation *InboundDetourAllocationConfig Settings []byte @@ -46,6 +47,7 @@ type OutboundDetourConfig struct { type Config struct { Port v2net.Port + ListenOn v2net.Address LogConfig *LogConfig RouterConfig *router.Config DNSConfig *dns.Config diff --git a/shell/point/config_json.go b/shell/point/config_json.go index fc319ffe..82a3038a 100644 --- a/shell/point/config_json.go +++ b/shell/point/config_json.go @@ -4,6 +4,7 @@ package point import ( "encoding/json" + "errors" "io/ioutil" "os" "strings" @@ -21,6 +22,7 @@ const ( func (this *Config) UnmarshalJSON(data []byte) error { type JsonConfig struct { Port v2net.Port `json:"port"` // Port of this Point server. + ListenOn *v2net.AddressJson `json:"listen"` LogConfig *LogConfig `json:"log"` RouterConfig *router.Config `json:"routing"` DNSConfig *dns.Config `json:"dns"` @@ -34,6 +36,13 @@ func (this *Config) UnmarshalJSON(data []byte) error { return err } this.Port = jsonConfig.Port + this.ListenOn = v2net.AnyIP + if jsonConfig.ListenOn != nil { + if jsonConfig.ListenOn.Address.IsDomain() { + return errors.New("Point: Unable to listen on domain address: " + jsonConfig.ListenOn.Address.Domain()) + } + this.ListenOn = jsonConfig.ListenOn.Address + } this.LogConfig = jsonConfig.LogConfig this.RouterConfig = jsonConfig.RouterConfig this.InboundConfig = jsonConfig.InboundConfig @@ -125,6 +134,7 @@ func (this *InboundDetourConfig) UnmarshalJSON(data []byte) error { type JsonInboundDetourConfig struct { Protocol string `json:"protocol"` PortRange *v2net.PortRange `json:"port"` + ListenOn *v2net.AddressJson `json:"listen"` Settings json.RawMessage `json:"settings"` Tag string `json:"tag"` Allocation *InboundDetourAllocationConfig `json:"allocate"` @@ -137,6 +147,13 @@ func (this *InboundDetourConfig) UnmarshalJSON(data []byte) error { log.Error("Point: Port range not specified in InboundDetour.") return ErrorBadConfiguration } + this.ListenOn = v2net.AnyIP + if jsonConfig.ListenOn != nil { + if jsonConfig.ListenOn.Address.IsDomain() { + return errors.New("Point: Unable to listen on domain address: " + jsonConfig.ListenOn.Address.Domain()) + } + this.ListenOn = jsonConfig.ListenOn.Address + } this.Protocol = jsonConfig.Protocol this.PortRange = *jsonConfig.PortRange this.Settings = jsonConfig.Settings diff --git a/shell/point/inbound_detour_always.go b/shell/point/inbound_detour_always.go index e16053a5..984a0579 100644 --- a/shell/point/inbound_detour_always.go +++ b/shell/point/inbound_detour_always.go @@ -12,6 +12,7 @@ import ( type InboundConnectionHandlerWithPort struct { port v2net.Port + listen v2net.Address handler proxy.InboundHandler } @@ -39,6 +40,7 @@ func NewInboundDetourHandlerAlways(space app.Space, config *InboundDetourConfig) handler.ich = append(handler.ich, &InboundConnectionHandlerWithPort{ port: i, handler: ich, + listen: config.ListenOn, }) } return handler, nil @@ -59,7 +61,7 @@ func (this *InboundDetourHandlerAlways) Close() { func (this *InboundDetourHandlerAlways) Start() error { for _, ich := range this.ich { err := retry.Timed(100 /* times */, 100 /* ms */).On(func() error { - err := ich.handler.Listen(ich.port) + err := ich.handler.Listen(ich.listen, ich.port) if err != nil { log.Error("Failed to start inbound detour on port ", ich.port, ": ", err) return err diff --git a/shell/point/inbound_detour_dynamic.go b/shell/point/inbound_detour_dynamic.go index d1656a69..d5e50d63 100644 --- a/shell/point/inbound_detour_dynamic.go +++ b/shell/point/inbound_detour_dynamic.go @@ -91,7 +91,7 @@ func (this *InboundDetourHandlerDynamic) refresh() error { ich.Close() err := retry.Timed(100 /* times */, 1000 /* ms */).On(func() error { port := this.pickUnusedPort() - err := ich.Listen(port) + err := ich.Listen(this.config.ListenOn, port) if err != nil { log.Error("Point: Failed to start inbound detour on port ", port, ": ", err) return err diff --git a/shell/point/point.go b/shell/point/point.go index b8deb5cc..d131bcbb 100644 --- a/shell/point/point.go +++ b/shell/point/point.go @@ -21,6 +21,7 @@ import ( // Point shell of V2Ray. type Point struct { port v2net.Port + listen v2net.Address ich proxy.InboundHandler och proxy.OutboundHandler idh []InboundDetourHandler @@ -35,6 +36,7 @@ type Point struct { func NewPoint(pConfig *Config) (*Point, error) { var vpoint = new(Point) vpoint.port = pConfig.Port + vpoint.listen = pConfig.ListenOn if pConfig.LogConfig != nil { logConfig := pConfig.LogConfig @@ -167,7 +169,7 @@ func (this *Point) Start() error { } err := retry.Timed(100 /* times */, 100 /* ms */).On(func() error { - err := this.ich.Listen(this.port) + err := this.ich.Listen(this.listen, this.port) if err != nil { return err } diff --git a/testing/scenarios/data/test_1_client.json b/testing/scenarios/data/test_1_client.json index c51fc14a..5b338691 100644 --- a/testing/scenarios/data/test_1_client.json +++ b/testing/scenarios/data/test_1_client.json @@ -1,5 +1,6 @@ { "port": 50000, + "listen": "127.0.0.1", "inbound": { "protocol": "socks", "settings": { diff --git a/testing/scenarios/data/test_1_server.json b/testing/scenarios/data/test_1_server.json index 92edb66f..1d4f940b 100644 --- a/testing/scenarios/data/test_1_server.json +++ b/testing/scenarios/data/test_1_server.json @@ -1,9 +1,8 @@ { "port": 50001, + "listen": "127.0.0.1", "log": { - "access": "/tmp/v2ray_access.log", - "error": "/tmp/v2ray_error.log", - "loglevel": "error" + "loglevel": "none" }, "inbound": { "protocol": "vmess", @@ -29,6 +28,7 @@ "inboundDetour": [ { "protocol": "vmess", + "listen": "127.0.0.1", "port": "50005-50009", "tag": "detour", "settings": { diff --git a/testing/scenarios/data/test_2_client.json b/testing/scenarios/data/test_2_client.json index 84e81a2e..e9e20649 100644 --- a/testing/scenarios/data/test_2_client.json +++ b/testing/scenarios/data/test_2_client.json @@ -1,5 +1,6 @@ { "port": 50010, + "listen": "127.0.0.1", "inbound": { "protocol": "socks", "settings": { @@ -25,6 +26,7 @@ "inboundDetour": [ { "protocol": "dokodemo-door", + "listen": "127.0.0.1", "port": "50011-50015", "settings": { "address": "127.0.0.1", diff --git a/testing/scenarios/data/test_2_server.json b/testing/scenarios/data/test_2_server.json index 3efc9fb9..59ef59f0 100644 --- a/testing/scenarios/data/test_2_server.json +++ b/testing/scenarios/data/test_2_server.json @@ -1,5 +1,9 @@ { "port": 50017, + "listen": "127.0.0.1", + "log": { + "loglevel": "none" + }, "inbound": { "protocol": "vmess", "settings": { diff --git a/testing/scenarios/data/test_3_client.json b/testing/scenarios/data/test_3_client.json index b07bfe10..ea5627e0 100644 --- a/testing/scenarios/data/test_3_client.json +++ b/testing/scenarios/data/test_3_client.json @@ -1,9 +1,8 @@ { "port": 50020, + "listen": "127.0.0.1", "log": { - "access": "/tmp/v2ray_access_1.log", - "error": "/tmp/v2ray_error_1.log", - "loglevel": "error" + "loglevel": "none" }, "inbound": { "protocol": "dokodemo-door", @@ -32,6 +31,7 @@ { "protocol": "dokodemo-door", "port": 50022, + "listen": "127.0.0.1", "settings": { "address": "127.0.0.1", "port": 50025, diff --git a/testing/scenarios/data/test_3_server.json b/testing/scenarios/data/test_3_server.json index d3f21ea6..3345cea1 100644 --- a/testing/scenarios/data/test_3_server.json +++ b/testing/scenarios/data/test_3_server.json @@ -1,5 +1,6 @@ { "port": 50021, + "listen": "127.0.0.1", "inbound": { "protocol": "vmess", "settings": { diff --git a/testing/scenarios/data/test_4_client.json b/testing/scenarios/data/test_4_client.json index 38db452b..0c4801a7 100644 --- a/testing/scenarios/data/test_4_client.json +++ b/testing/scenarios/data/test_4_client.json @@ -1,5 +1,6 @@ { "port": 50030, + "listen": "127.0.0.1", "inbound": { "protocol": "dokodemo-door", "settings": { diff --git a/testing/scenarios/data/test_4_server.json b/testing/scenarios/data/test_4_server.json index ed1c2c4d..44891d0e 100644 --- a/testing/scenarios/data/test_4_server.json +++ b/testing/scenarios/data/test_4_server.json @@ -1,5 +1,6 @@ { "port": 50031, + "listen": "127.0.0.1", "log": { "loglevel": "warning" }, @@ -27,6 +28,7 @@ "inboundDetour": [ { "protocol": "vmess", + "listen": "127.0.0.1", "port": "50035-50039", "tag": "detour", "settings": {}, diff --git a/testing/scenarios/data/test_5_client.json b/testing/scenarios/data/test_5_client.json index 7b3615d1..6d5cb218 100644 --- a/testing/scenarios/data/test_5_client.json +++ b/testing/scenarios/data/test_5_client.json @@ -1,5 +1,6 @@ { "port": 50040, + "listen": "127.0.0.1", "inbound": { "protocol": "http", "settings": {} diff --git a/testing/scenarios/data/test_5_server.json b/testing/scenarios/data/test_5_server.json index 2908d7a7..f8e9149c 100644 --- a/testing/scenarios/data/test_5_server.json +++ b/testing/scenarios/data/test_5_server.json @@ -1,5 +1,6 @@ { "port": 50041, + "listen": "127.0.0.1", "inbound": { "protocol": "vmess", "settings": { diff --git a/testing/scenarios/data/test_6_server.json b/testing/scenarios/data/test_6_server.json index 25c4088e..2744bfd3 100644 --- a/testing/scenarios/data/test_6_server.json +++ b/testing/scenarios/data/test_6_server.json @@ -1,5 +1,6 @@ { "port": 50051, + "listen": "127.0.0.1", "inbound": { "protocol": "shadowsocks", "settings": { @@ -11,6 +12,7 @@ { "protocol": "shadowsocks", "port": 50055, + "listen": "127.0.0.1", "settings": { "method": "aes-128-cfb", "password": "v2ray-another", @@ -20,6 +22,7 @@ { "protocol": "shadowsocks", "port": 50056, + "listen": "127.0.0.1", "settings": { "method": "chacha20", "password": "new-password", diff --git a/testing/servers/http/http.go b/testing/servers/http/http.go index a019d12d..bd041e40 100644 --- a/testing/servers/http/http.go +++ b/testing/servers/http/http.go @@ -27,7 +27,7 @@ func (server *Server) ServeHTTP(resp http.ResponseWriter, req *http.Request) { } func (server *Server) Start() (v2net.Destination, error) { - go http.ListenAndServe(":"+server.Port.String(), server) + go http.ListenAndServe("127.0.0.1:"+server.Port.String(), server) return v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(server.Port)), nil } diff --git a/testing/servers/tcp/tcp.go b/testing/servers/tcp/tcp.go index 62852144..ee90d715 100644 --- a/testing/servers/tcp/tcp.go +++ b/testing/servers/tcp/tcp.go @@ -17,7 +17,7 @@ type Server struct { func (server *Server) Start() (v2net.Destination, error) { listener, err := net.ListenTCP("tcp", &net.TCPAddr{ - IP: []byte{0, 0, 0, 0}, + IP: []byte{127, 0, 0, 1}, Port: int(server.Port), Zone: "", }) diff --git a/testing/servers/udp/udp.go b/testing/servers/udp/udp.go index 8cbf3bb9..54da2e04 100644 --- a/testing/servers/udp/udp.go +++ b/testing/servers/udp/udp.go @@ -16,7 +16,7 @@ type Server struct { func (server *Server) Start() (v2net.Destination, error) { conn, err := net.ListenUDP("udp", &net.UDPAddr{ - IP: []byte{0, 0, 0, 0}, + IP: []byte{127, 0, 0, 1}, Port: int(server.Port), Zone: "", }) diff --git a/transport/hub/tcp.go b/transport/hub/tcp.go index 1487cffe..fce24c3c 100644 --- a/transport/hub/tcp.go +++ b/transport/hub/tcp.go @@ -19,9 +19,9 @@ type TCPHub struct { accepting bool } -func ListenTCP(port v2net.Port, callback ConnectionHandler, tlsConfig *tls.Config) (*TCPHub, error) { +func ListenTCP(address v2net.Address, port v2net.Port, callback ConnectionHandler, tlsConfig *tls.Config) (*TCPHub, error) { listener, err := net.ListenTCP("tcp", &net.TCPAddr{ - IP: []byte{0, 0, 0, 0}, + IP: address.IP(), Port: int(port), Zone: "", }) diff --git a/transport/hub/udp.go b/transport/hub/udp.go index 3b21a62e..2e69b834 100644 --- a/transport/hub/udp.go +++ b/transport/hub/udp.go @@ -15,9 +15,9 @@ type UDPHub struct { accepting bool } -func ListenUDP(port v2net.Port, callback UDPPayloadHandler) (*UDPHub, error) { +func ListenUDP(address v2net.Address, port v2net.Port, callback UDPPayloadHandler) (*UDPHub, error) { udpConn, err := net.ListenUDP("udp", &net.UDPAddr{ - IP: []byte{0, 0, 0, 0}, + IP: address.IP(), Port: int(port), }) if err != nil {