mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 09:36:34 -05:00
get rid of annoying firewall warnings
This commit is contained in:
parent
c3aa839227
commit
b47c1ca609
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
LocalHostIP = IPAddress([]byte{127, 0, 0, 1})
|
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
|
// Address represents a network address to be communicated with. It may be an IP address or domain
|
||||||
|
@ -26,6 +26,7 @@ type DokodemoDoor struct {
|
|||||||
udpHub *hub.UDPHub
|
udpHub *hub.UDPHub
|
||||||
udpServer *hub.UDPServer
|
udpServer *hub.UDPServer
|
||||||
listeningPort v2net.Port
|
listeningPort v2net.Port
|
||||||
|
listeningAddress v2net.Address
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDokodemoDoor(config *Config, space app.Space) *DokodemoDoor {
|
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.accepting {
|
||||||
if this.listeningPort == port {
|
if this.listeningPort == port && this.listeningAddress.Equals(address) {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
return proxy.ErrorAlreadyListening
|
return proxy.ErrorAlreadyListening
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.listeningPort = port
|
this.listeningPort = port
|
||||||
|
this.listeningAddress = address
|
||||||
this.accepting = true
|
this.accepting = true
|
||||||
|
|
||||||
if this.config.Network.HasNetwork(v2net.TCPNetwork) {
|
if this.config.Network.HasNetwork(v2net.TCPNetwork) {
|
||||||
err := this.ListenTCP(port)
|
err := this.ListenTCP(address, port)
|
||||||
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(port)
|
err := this.ListenUDP(address, port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -91,9 +93,9 @@ func (this *DokodemoDoor) Listen(port v2net.Port) error {
|
|||||||
return nil
|
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)
|
this.udpServer = hub.NewUDPServer(this.packetDispatcher)
|
||||||
udpHub, err := hub.ListenUDP(port, this.handleUDPPackets)
|
udpHub, err := hub.ListenUDP(address, 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 port ", port, ": ", err)
|
||||||
return err
|
return err
|
||||||
@ -118,8 +120,8 @@ 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(port v2net.Port) error {
|
func (this *DokodemoDoor) ListenTCP(address v2net.Address, port v2net.Port) error {
|
||||||
tcpListener, err := hub.ListenTCP(port, this.HandleTCPConnection, nil)
|
tcpListener, err := hub.ListenTCP(address, 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 port ", port, ": ", err)
|
||||||
return err
|
return err
|
||||||
|
@ -53,7 +53,7 @@ func TestDokodemoTCP(t *testing.T) {
|
|||||||
assert.Error(space.Initialize()).IsNil()
|
assert.Error(space.Initialize()).IsNil()
|
||||||
|
|
||||||
port := v2nettesting.PickPort()
|
port := v2nettesting.PickPort()
|
||||||
err = dokodemo.Listen(port)
|
err = dokodemo.Listen(v2net.LocalHostIP, port)
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
assert.Port(port).Equals(dokodemo.Port())
|
assert.Port(port).Equals(dokodemo.Port())
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ func TestDokodemoUDP(t *testing.T) {
|
|||||||
assert.Error(space.Initialize()).IsNil()
|
assert.Error(space.Initialize()).IsNil()
|
||||||
|
|
||||||
port := v2nettesting.PickPort()
|
port := v2nettesting.PickPort()
|
||||||
err = dokodemo.Listen(port)
|
err = dokodemo.Listen(v2net.LocalHostIP, port)
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
assert.Port(port).Equals(dokodemo.Port())
|
assert.Port(port).Equals(dokodemo.Port())
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ type HttpProxyServer struct {
|
|||||||
config *Config
|
config *Config
|
||||||
tcpListener *hub.TCPHub
|
tcpListener *hub.TCPHub
|
||||||
listeningPort v2net.Port
|
listeningPort v2net.Port
|
||||||
|
listeningAddress v2net.Address
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHttpProxyServer(config *Config, packetDispatcher dispatcher.PacketDispatcher) *HttpProxyServer {
|
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.accepting {
|
||||||
if this.listeningPort == port {
|
if this.listeningPort == port && this.listeningAddress.Equals(address) {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
return proxy.ErrorAlreadyListening
|
return proxy.ErrorAlreadyListening
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.listeningPort = port
|
this.listeningPort = port
|
||||||
|
this.listeningAddress = address
|
||||||
|
|
||||||
var tlsConfig *tls.Config = nil
|
var tlsConfig *tls.Config = nil
|
||||||
if this.config.TlsConfig != nil {
|
if this.config.TlsConfig != nil {
|
||||||
tlsConfig = this.config.TlsConfig.GetConfig()
|
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 {
|
if err != nil {
|
||||||
log.Error("Http: Failed listen on port ", port, ": ", err)
|
log.Error("Http: Failed listen on port ", port, ": ", err)
|
||||||
return err
|
return err
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
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"
|
||||||
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
||||||
. "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"
|
||||||
@ -55,7 +56,7 @@ func TestNormalGetRequest(t *testing.T) {
|
|||||||
defer httpProxy.Close()
|
defer httpProxy.Close()
|
||||||
|
|
||||||
port := v2nettesting.PickPort()
|
port := v2nettesting.PickPort()
|
||||||
err := httpProxy.Listen(port)
|
err := httpProxy.Listen(v2net.LocalHostIP, port)
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
assert.Port(port).Equals(httpProxy.Port())
|
assert.Port(port).Equals(httpProxy.Port())
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ const (
|
|||||||
// 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 by listen on a specific port.
|
// 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 stops the handler to accepting anymore inbound connections.
|
||||||
Close()
|
Close()
|
||||||
// Port returns the port that the handler is listening on.
|
// Port returns the port that the handler is listening on.
|
||||||
|
@ -23,6 +23,7 @@ type Server struct {
|
|||||||
packetDispatcher dispatcher.PacketDispatcher
|
packetDispatcher dispatcher.PacketDispatcher
|
||||||
config *Config
|
config *Config
|
||||||
port v2net.Port
|
port v2net.Port
|
||||||
|
address v2net.Address
|
||||||
accepting bool
|
accepting bool
|
||||||
tcpHub *hub.TCPHub
|
tcpHub *hub.TCPHub
|
||||||
udpHub *hub.UDPHub
|
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.accepting {
|
||||||
if this.port == port {
|
if this.port == port && this.address.Equals(address) {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
return proxy.ErrorAlreadyListening
|
return proxy.ErrorAlreadyListening
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tcpHub, err := hub.ListenTCP(port, this.handleConnection, nil)
|
tcpHub, err := hub.ListenTCP(address, port, this.handleConnection, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Shadowsocks: Failed to listen TCP on port ", port, ": ", err)
|
log.Error("Shadowsocks: Failed to listen TCP on port ", port, ": ", err)
|
||||||
return err
|
return err
|
||||||
@ -73,7 +74,7 @@ func (this *Server) Listen(port v2net.Port) error {
|
|||||||
|
|
||||||
if this.config.UDP {
|
if this.config.UDP {
|
||||||
this.udpServer = hub.NewUDPServer(this.packetDispatcher)
|
this.udpServer = hub.NewUDPServer(this.packetDispatcher)
|
||||||
udpHub, err := hub.ListenUDP(port, this.handlerUDPPayload)
|
udpHub, err := hub.ListenUDP(address, port, this.handlerUDPPayload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Shadowsocks: Failed to listen UDP on port ", port, ": ", err)
|
log.Error("Shadowsocks: Failed to listen UDP on port ", port, ": ", err)
|
||||||
return err
|
return err
|
||||||
@ -82,6 +83,7 @@ func (this *Server) Listen(port v2net.Port) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.port = port
|
this.port = port
|
||||||
|
this.address = address
|
||||||
this.accepting = true
|
this.accepting = true
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -34,6 +34,7 @@ type Server struct {
|
|||||||
udpAddress v2net.Destination
|
udpAddress v2net.Destination
|
||||||
udpServer *hub.UDPServer
|
udpServer *hub.UDPServer
|
||||||
listeningPort v2net.Port
|
listeningPort v2net.Port
|
||||||
|
listeningAddress v2net.Address
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServer creates a new Server object.
|
// NewServer creates a new Server object.
|
||||||
@ -67,17 +68,18 @@ func (this *Server) Close() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Listen implements InboundHandler.Listen().
|
// 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.accepting {
|
||||||
if this.listeningPort == port {
|
if this.listeningPort == port && this.listeningAddress.Equals(address) {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
return proxy.ErrorAlreadyListening
|
return proxy.ErrorAlreadyListening
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.listeningPort = port
|
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 {
|
if err != nil {
|
||||||
log.Error("Socks: failed to listen on port ", port, ": ", err)
|
log.Error("Socks: failed to listen on port ", port, ": ", err)
|
||||||
return err
|
return err
|
||||||
@ -87,7 +89,7 @@ func (this *Server) Listen(port v2net.Port) error {
|
|||||||
this.tcpListener = listener
|
this.tcpListener = listener
|
||||||
this.tcpMutex.Unlock()
|
this.tcpMutex.Unlock()
|
||||||
if this.config.UDPEnabled {
|
if this.config.UDPEnabled {
|
||||||
this.listenUDP(port)
|
this.listenUDP(address, port)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,8 @@ func TestSocksTcpConnect(t *testing.T) {
|
|||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
|
||||||
config := &point.Config{
|
config := &point.Config{
|
||||||
Port: port,
|
Port: port,
|
||||||
|
ListenOn: v2net.LocalHostIP,
|
||||||
InboundConfig: &point.ConnectionConfig{
|
InboundConfig: &point.ConnectionConfig{
|
||||||
Protocol: "socks",
|
Protocol: "socks",
|
||||||
Settings: []byte(`
|
Settings: []byte(`
|
||||||
@ -101,7 +102,8 @@ func TestSocksTcpConnectWithUserPass(t *testing.T) {
|
|||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
|
||||||
config := &point.Config{
|
config := &point.Config{
|
||||||
Port: port,
|
Port: port,
|
||||||
|
ListenOn: v2net.LocalHostIP,
|
||||||
InboundConfig: &point.ConnectionConfig{
|
InboundConfig: &point.ConnectionConfig{
|
||||||
Protocol: "socks",
|
Protocol: "socks",
|
||||||
Settings: []byte(`
|
Settings: []byte(`
|
||||||
@ -168,7 +170,8 @@ func TestSocksTcpConnectWithWrongUserPass(t *testing.T) {
|
|||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
|
||||||
config := &point.Config{
|
config := &point.Config{
|
||||||
Port: port,
|
Port: port,
|
||||||
|
ListenOn: v2net.LocalHostIP,
|
||||||
InboundConfig: &point.ConnectionConfig{
|
InboundConfig: &point.ConnectionConfig{
|
||||||
Protocol: "socks",
|
Protocol: "socks",
|
||||||
Settings: []byte(`
|
Settings: []byte(`
|
||||||
@ -221,7 +224,8 @@ func TestSocksTcpConnectWithWrongAuthMethod(t *testing.T) {
|
|||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
|
||||||
config := &point.Config{
|
config := &point.Config{
|
||||||
Port: port,
|
Port: port,
|
||||||
|
ListenOn: v2net.LocalHostIP,
|
||||||
InboundConfig: &point.ConnectionConfig{
|
InboundConfig: &point.ConnectionConfig{
|
||||||
Protocol: "socks",
|
Protocol: "socks",
|
||||||
Settings: []byte(`
|
Settings: []byte(`
|
||||||
|
@ -8,9 +8,9 @@ import (
|
|||||||
"github.com/v2ray/v2ray-core/transport/hub"
|
"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)
|
this.udpServer = hub.NewUDPServer(this.packetDispatcher)
|
||||||
udpHub, err := hub.ListenUDP(port, this.handleUDPPayload)
|
udpHub, err := hub.ListenUDP(address, 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 port ", port)
|
||||||
return err
|
return err
|
||||||
|
@ -11,13 +11,15 @@ import (
|
|||||||
|
|
||||||
type InboundConnectionHandler struct {
|
type InboundConnectionHandler struct {
|
||||||
port v2net.Port
|
port v2net.Port
|
||||||
|
address v2net.Address
|
||||||
PacketDispatcher dispatcher.PacketDispatcher
|
PacketDispatcher dispatcher.PacketDispatcher
|
||||||
ConnInput io.Reader
|
ConnInput io.Reader
|
||||||
ConnOutput io.Writer
|
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.port = port
|
||||||
|
this.address = address
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,6 +73,7 @@ type VMessInboundHandler struct {
|
|||||||
listener *hub.TCPHub
|
listener *hub.TCPHub
|
||||||
features *FeaturesConfig
|
features *FeaturesConfig
|
||||||
listeningPort v2net.Port
|
listeningPort v2net.Port
|
||||||
|
listeningAddress v2net.Address
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *VMessInboundHandler) Port() v2net.Port {
|
func (this *VMessInboundHandler) Port() v2net.Port {
|
||||||
@ -97,17 +98,18 @@ func (this *VMessInboundHandler) GetUser(email string) *protocol.User {
|
|||||||
return 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.accepting {
|
||||||
if this.listeningPort == port {
|
if this.listeningPort == port && this.listeningAddress.Equals(address) {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
return proxy.ErrorAlreadyListening
|
return proxy.ErrorAlreadyListening
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.listeningPort = port
|
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 {
|
if err != nil {
|
||||||
log.Error("Unable to listen tcp port ", port, ": ", err)
|
log.Error("Unable to listen tcp port ", port, ": ", err)
|
||||||
return err
|
return err
|
||||||
|
@ -45,7 +45,8 @@ func TestVMessInAndOut(t *testing.T) {
|
|||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
|
||||||
configA := &point.Config{
|
configA := &point.Config{
|
||||||
Port: portA,
|
Port: portA,
|
||||||
|
ListenOn: v2net.LocalHostIP,
|
||||||
DNSConfig: &dns.Config{
|
DNSConfig: &dns.Config{
|
||||||
NameServers: []v2net.Destination{
|
NameServers: []v2net.Destination{
|
||||||
v2net.UDPDestination(v2net.DomainAddress("localhost"), v2net.Port(53)),
|
v2net.UDPDestination(v2net.DomainAddress("localhost"), v2net.Port(53)),
|
||||||
@ -90,7 +91,8 @@ func TestVMessInAndOut(t *testing.T) {
|
|||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
|
||||||
configB := &point.Config{
|
configB := &point.Config{
|
||||||
Port: portB,
|
Port: portB,
|
||||||
|
ListenOn: v2net.LocalHostIP,
|
||||||
DNSConfig: &dns.Config{
|
DNSConfig: &dns.Config{
|
||||||
NameServers: []v2net.Destination{
|
NameServers: []v2net.Destination{
|
||||||
v2net.UDPDestination(v2net.DomainAddress("localhost"), v2net.Port(53)),
|
v2net.UDPDestination(v2net.DomainAddress("localhost"), v2net.Port(53)),
|
||||||
|
@ -33,6 +33,7 @@ type InboundDetourAllocationConfig struct {
|
|||||||
type InboundDetourConfig struct {
|
type InboundDetourConfig struct {
|
||||||
Protocol string
|
Protocol string
|
||||||
PortRange v2net.PortRange
|
PortRange v2net.PortRange
|
||||||
|
ListenOn v2net.Address
|
||||||
Tag string
|
Tag string
|
||||||
Allocation *InboundDetourAllocationConfig
|
Allocation *InboundDetourAllocationConfig
|
||||||
Settings []byte
|
Settings []byte
|
||||||
@ -46,6 +47,7 @@ type OutboundDetourConfig struct {
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Port v2net.Port
|
Port v2net.Port
|
||||||
|
ListenOn v2net.Address
|
||||||
LogConfig *LogConfig
|
LogConfig *LogConfig
|
||||||
RouterConfig *router.Config
|
RouterConfig *router.Config
|
||||||
DNSConfig *dns.Config
|
DNSConfig *dns.Config
|
||||||
|
@ -4,6 +4,7 @@ package point
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@ -21,6 +22,7 @@ const (
|
|||||||
func (this *Config) UnmarshalJSON(data []byte) error {
|
func (this *Config) UnmarshalJSON(data []byte) error {
|
||||||
type JsonConfig struct {
|
type JsonConfig struct {
|
||||||
Port v2net.Port `json:"port"` // Port of this Point server.
|
Port v2net.Port `json:"port"` // Port of this Point server.
|
||||||
|
ListenOn *v2net.AddressJson `json:"listen"`
|
||||||
LogConfig *LogConfig `json:"log"`
|
LogConfig *LogConfig `json:"log"`
|
||||||
RouterConfig *router.Config `json:"routing"`
|
RouterConfig *router.Config `json:"routing"`
|
||||||
DNSConfig *dns.Config `json:"dns"`
|
DNSConfig *dns.Config `json:"dns"`
|
||||||
@ -34,6 +36,13 @@ func (this *Config) UnmarshalJSON(data []byte) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
this.Port = jsonConfig.Port
|
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.LogConfig = jsonConfig.LogConfig
|
||||||
this.RouterConfig = jsonConfig.RouterConfig
|
this.RouterConfig = jsonConfig.RouterConfig
|
||||||
this.InboundConfig = jsonConfig.InboundConfig
|
this.InboundConfig = jsonConfig.InboundConfig
|
||||||
@ -125,6 +134,7 @@ func (this *InboundDetourConfig) UnmarshalJSON(data []byte) error {
|
|||||||
type JsonInboundDetourConfig struct {
|
type JsonInboundDetourConfig struct {
|
||||||
Protocol string `json:"protocol"`
|
Protocol string `json:"protocol"`
|
||||||
PortRange *v2net.PortRange `json:"port"`
|
PortRange *v2net.PortRange `json:"port"`
|
||||||
|
ListenOn *v2net.AddressJson `json:"listen"`
|
||||||
Settings json.RawMessage `json:"settings"`
|
Settings json.RawMessage `json:"settings"`
|
||||||
Tag string `json:"tag"`
|
Tag string `json:"tag"`
|
||||||
Allocation *InboundDetourAllocationConfig `json:"allocate"`
|
Allocation *InboundDetourAllocationConfig `json:"allocate"`
|
||||||
@ -137,6 +147,13 @@ func (this *InboundDetourConfig) UnmarshalJSON(data []byte) error {
|
|||||||
log.Error("Point: Port range not specified in InboundDetour.")
|
log.Error("Point: Port range not specified in InboundDetour.")
|
||||||
return ErrorBadConfiguration
|
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.Protocol = jsonConfig.Protocol
|
||||||
this.PortRange = *jsonConfig.PortRange
|
this.PortRange = *jsonConfig.PortRange
|
||||||
this.Settings = jsonConfig.Settings
|
this.Settings = jsonConfig.Settings
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
type InboundConnectionHandlerWithPort struct {
|
type InboundConnectionHandlerWithPort struct {
|
||||||
port v2net.Port
|
port v2net.Port
|
||||||
|
listen v2net.Address
|
||||||
handler proxy.InboundHandler
|
handler proxy.InboundHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,6 +40,7 @@ func NewInboundDetourHandlerAlways(space app.Space, config *InboundDetourConfig)
|
|||||||
handler.ich = append(handler.ich, &InboundConnectionHandlerWithPort{
|
handler.ich = append(handler.ich, &InboundConnectionHandlerWithPort{
|
||||||
port: i,
|
port: i,
|
||||||
handler: ich,
|
handler: ich,
|
||||||
|
listen: config.ListenOn,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return handler, nil
|
return handler, nil
|
||||||
@ -59,7 +61,7 @@ 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.Listen(ich.port)
|
err := ich.handler.Listen(ich.listen, ich.port)
|
||||||
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 on port ", ich.port, ": ", err)
|
||||||
return err
|
return err
|
||||||
|
@ -91,7 +91,7 @@ func (this *InboundDetourHandlerDynamic) refresh() error {
|
|||||||
ich.Close()
|
ich.Close()
|
||||||
err := retry.Timed(100 /* times */, 1000 /* ms */).On(func() error {
|
err := retry.Timed(100 /* times */, 1000 /* ms */).On(func() error {
|
||||||
port := this.pickUnusedPort()
|
port := this.pickUnusedPort()
|
||||||
err := ich.Listen(port)
|
err := ich.Listen(this.config.ListenOn, port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Point: Failed to start inbound detour on port ", port, ": ", err)
|
log.Error("Point: Failed to start inbound detour on port ", port, ": ", err)
|
||||||
return err
|
return err
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
// Point shell of V2Ray.
|
// Point shell of V2Ray.
|
||||||
type Point struct {
|
type Point struct {
|
||||||
port v2net.Port
|
port v2net.Port
|
||||||
|
listen v2net.Address
|
||||||
ich proxy.InboundHandler
|
ich proxy.InboundHandler
|
||||||
och proxy.OutboundHandler
|
och proxy.OutboundHandler
|
||||||
idh []InboundDetourHandler
|
idh []InboundDetourHandler
|
||||||
@ -35,6 +36,7 @@ type Point struct {
|
|||||||
func NewPoint(pConfig *Config) (*Point, error) {
|
func NewPoint(pConfig *Config) (*Point, error) {
|
||||||
var vpoint = new(Point)
|
var vpoint = new(Point)
|
||||||
vpoint.port = pConfig.Port
|
vpoint.port = pConfig.Port
|
||||||
|
vpoint.listen = pConfig.ListenOn
|
||||||
|
|
||||||
if pConfig.LogConfig != nil {
|
if pConfig.LogConfig != nil {
|
||||||
logConfig := pConfig.LogConfig
|
logConfig := pConfig.LogConfig
|
||||||
@ -167,7 +169,7 @@ func (this *Point) Start() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
err := retry.Timed(100 /* times */, 100 /* ms */).On(func() 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"port": 50000,
|
"port": 50000,
|
||||||
|
"listen": "127.0.0.1",
|
||||||
"inbound": {
|
"inbound": {
|
||||||
"protocol": "socks",
|
"protocol": "socks",
|
||||||
"settings": {
|
"settings": {
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
{
|
{
|
||||||
"port": 50001,
|
"port": 50001,
|
||||||
|
"listen": "127.0.0.1",
|
||||||
"log": {
|
"log": {
|
||||||
"access": "/tmp/v2ray_access.log",
|
"loglevel": "none"
|
||||||
"error": "/tmp/v2ray_error.log",
|
|
||||||
"loglevel": "error"
|
|
||||||
},
|
},
|
||||||
"inbound": {
|
"inbound": {
|
||||||
"protocol": "vmess",
|
"protocol": "vmess",
|
||||||
@ -29,6 +28,7 @@
|
|||||||
"inboundDetour": [
|
"inboundDetour": [
|
||||||
{
|
{
|
||||||
"protocol": "vmess",
|
"protocol": "vmess",
|
||||||
|
"listen": "127.0.0.1",
|
||||||
"port": "50005-50009",
|
"port": "50005-50009",
|
||||||
"tag": "detour",
|
"tag": "detour",
|
||||||
"settings": {
|
"settings": {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"port": 50010,
|
"port": 50010,
|
||||||
|
"listen": "127.0.0.1",
|
||||||
"inbound": {
|
"inbound": {
|
||||||
"protocol": "socks",
|
"protocol": "socks",
|
||||||
"settings": {
|
"settings": {
|
||||||
@ -25,6 +26,7 @@
|
|||||||
"inboundDetour": [
|
"inboundDetour": [
|
||||||
{
|
{
|
||||||
"protocol": "dokodemo-door",
|
"protocol": "dokodemo-door",
|
||||||
|
"listen": "127.0.0.1",
|
||||||
"port": "50011-50015",
|
"port": "50011-50015",
|
||||||
"settings": {
|
"settings": {
|
||||||
"address": "127.0.0.1",
|
"address": "127.0.0.1",
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
{
|
{
|
||||||
"port": 50017,
|
"port": 50017,
|
||||||
|
"listen": "127.0.0.1",
|
||||||
|
"log": {
|
||||||
|
"loglevel": "none"
|
||||||
|
},
|
||||||
"inbound": {
|
"inbound": {
|
||||||
"protocol": "vmess",
|
"protocol": "vmess",
|
||||||
"settings": {
|
"settings": {
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
{
|
{
|
||||||
"port": 50020,
|
"port": 50020,
|
||||||
|
"listen": "127.0.0.1",
|
||||||
"log": {
|
"log": {
|
||||||
"access": "/tmp/v2ray_access_1.log",
|
"loglevel": "none"
|
||||||
"error": "/tmp/v2ray_error_1.log",
|
|
||||||
"loglevel": "error"
|
|
||||||
},
|
},
|
||||||
"inbound": {
|
"inbound": {
|
||||||
"protocol": "dokodemo-door",
|
"protocol": "dokodemo-door",
|
||||||
@ -32,6 +31,7 @@
|
|||||||
{
|
{
|
||||||
"protocol": "dokodemo-door",
|
"protocol": "dokodemo-door",
|
||||||
"port": 50022,
|
"port": 50022,
|
||||||
|
"listen": "127.0.0.1",
|
||||||
"settings": {
|
"settings": {
|
||||||
"address": "127.0.0.1",
|
"address": "127.0.0.1",
|
||||||
"port": 50025,
|
"port": 50025,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"port": 50021,
|
"port": 50021,
|
||||||
|
"listen": "127.0.0.1",
|
||||||
"inbound": {
|
"inbound": {
|
||||||
"protocol": "vmess",
|
"protocol": "vmess",
|
||||||
"settings": {
|
"settings": {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"port": 50030,
|
"port": 50030,
|
||||||
|
"listen": "127.0.0.1",
|
||||||
"inbound": {
|
"inbound": {
|
||||||
"protocol": "dokodemo-door",
|
"protocol": "dokodemo-door",
|
||||||
"settings": {
|
"settings": {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"port": 50031,
|
"port": 50031,
|
||||||
|
"listen": "127.0.0.1",
|
||||||
"log": {
|
"log": {
|
||||||
"loglevel": "warning"
|
"loglevel": "warning"
|
||||||
},
|
},
|
||||||
@ -27,6 +28,7 @@
|
|||||||
"inboundDetour": [
|
"inboundDetour": [
|
||||||
{
|
{
|
||||||
"protocol": "vmess",
|
"protocol": "vmess",
|
||||||
|
"listen": "127.0.0.1",
|
||||||
"port": "50035-50039",
|
"port": "50035-50039",
|
||||||
"tag": "detour",
|
"tag": "detour",
|
||||||
"settings": {},
|
"settings": {},
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"port": 50040,
|
"port": 50040,
|
||||||
|
"listen": "127.0.0.1",
|
||||||
"inbound": {
|
"inbound": {
|
||||||
"protocol": "http",
|
"protocol": "http",
|
||||||
"settings": {}
|
"settings": {}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"port": 50041,
|
"port": 50041,
|
||||||
|
"listen": "127.0.0.1",
|
||||||
"inbound": {
|
"inbound": {
|
||||||
"protocol": "vmess",
|
"protocol": "vmess",
|
||||||
"settings": {
|
"settings": {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"port": 50051,
|
"port": 50051,
|
||||||
|
"listen": "127.0.0.1",
|
||||||
"inbound": {
|
"inbound": {
|
||||||
"protocol": "shadowsocks",
|
"protocol": "shadowsocks",
|
||||||
"settings": {
|
"settings": {
|
||||||
@ -11,6 +12,7 @@
|
|||||||
{
|
{
|
||||||
"protocol": "shadowsocks",
|
"protocol": "shadowsocks",
|
||||||
"port": 50055,
|
"port": 50055,
|
||||||
|
"listen": "127.0.0.1",
|
||||||
"settings": {
|
"settings": {
|
||||||
"method": "aes-128-cfb",
|
"method": "aes-128-cfb",
|
||||||
"password": "v2ray-another",
|
"password": "v2ray-another",
|
||||||
@ -20,6 +22,7 @@
|
|||||||
{
|
{
|
||||||
"protocol": "shadowsocks",
|
"protocol": "shadowsocks",
|
||||||
"port": 50056,
|
"port": 50056,
|
||||||
|
"listen": "127.0.0.1",
|
||||||
"settings": {
|
"settings": {
|
||||||
"method": "chacha20",
|
"method": "chacha20",
|
||||||
"password": "new-password",
|
"password": "new-password",
|
||||||
|
@ -27,7 +27,7 @@ func (server *Server) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) Start() (v2net.Destination, error) {
|
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
|
return v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(server.Port)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ type Server struct {
|
|||||||
|
|
||||||
func (server *Server) Start() (v2net.Destination, error) {
|
func (server *Server) Start() (v2net.Destination, error) {
|
||||||
listener, err := net.ListenTCP("tcp", &net.TCPAddr{
|
listener, err := net.ListenTCP("tcp", &net.TCPAddr{
|
||||||
IP: []byte{0, 0, 0, 0},
|
IP: []byte{127, 0, 0, 1},
|
||||||
Port: int(server.Port),
|
Port: int(server.Port),
|
||||||
Zone: "",
|
Zone: "",
|
||||||
})
|
})
|
||||||
|
@ -16,7 +16,7 @@ type Server struct {
|
|||||||
|
|
||||||
func (server *Server) Start() (v2net.Destination, error) {
|
func (server *Server) Start() (v2net.Destination, error) {
|
||||||
conn, err := net.ListenUDP("udp", &net.UDPAddr{
|
conn, err := net.ListenUDP("udp", &net.UDPAddr{
|
||||||
IP: []byte{0, 0, 0, 0},
|
IP: []byte{127, 0, 0, 1},
|
||||||
Port: int(server.Port),
|
Port: int(server.Port),
|
||||||
Zone: "",
|
Zone: "",
|
||||||
})
|
})
|
||||||
|
@ -19,9 +19,9 @@ type TCPHub struct {
|
|||||||
accepting bool
|
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{
|
listener, err := net.ListenTCP("tcp", &net.TCPAddr{
|
||||||
IP: []byte{0, 0, 0, 0},
|
IP: address.IP(),
|
||||||
Port: int(port),
|
Port: int(port),
|
||||||
Zone: "",
|
Zone: "",
|
||||||
})
|
})
|
||||||
|
@ -15,9 +15,9 @@ type UDPHub struct {
|
|||||||
accepting bool
|
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{
|
udpConn, err := net.ListenUDP("udp", &net.UDPAddr{
|
||||||
IP: []byte{0, 0, 0, 0},
|
IP: address.IP(),
|
||||||
Port: int(port),
|
Port: int(port),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user