Explorar el Código

frpc: add parameter nat_hole_server_addr (#3351)

fatedier hace 1 año
padre
commit
fccd518512
Se han modificado 4 ficheros con 17 adiciones y 2 borrados
  1. 5 1
      client/proxy/proxy.go
  2. 5 1
      client/visitor.go
  3. 4 0
      conf/frpc_full.ini
  4. 3 0
      pkg/config/client.go

+ 5 - 1
client/proxy/proxy.go

@@ -305,8 +305,12 @@ func (pxy *XTCPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
 		ProxyName: pxy.cfg.ProxyName,
 		Sid:       natHoleSidMsg.Sid,
 	}
+	serverAddr := pxy.clientCfg.NatHoleServerAddr
+	if serverAddr == "" {
+		serverAddr = pxy.clientCfg.ServerAddr
+	}
 	raddr, _ := net.ResolveUDPAddr("udp",
-		net.JoinHostPort(pxy.clientCfg.ServerAddr, strconv.Itoa(pxy.serverUDPPort)))
+		net.JoinHostPort(serverAddr, strconv.Itoa(pxy.serverUDPPort)))
 	clientConn, err := net.DialUDP("udp", nil, raddr)
 	if err != nil {
 		xl.Error("dial server udp addr error: %v", err)

+ 5 - 1
client/visitor.go

@@ -210,8 +210,12 @@ func (sv *XTCPVisitor) handleConn(userConn net.Conn) {
 		return
 	}
 
+	serverAddr := sv.ctl.clientCfg.NatHoleServerAddr
+	if serverAddr == "" {
+		serverAddr = sv.ctl.clientCfg.ServerAddr
+	}
 	raddr, err := net.ResolveUDPAddr("udp",
-		net.JoinHostPort(sv.ctl.clientCfg.ServerAddr, strconv.Itoa(sv.ctl.serverUDPPort)))
+		net.JoinHostPort(serverAddr, strconv.Itoa(sv.ctl.serverUDPPort)))
 	if err != nil {
 		xl.Error("resolve server UDP addr error")
 		return

+ 4 - 0
conf/frpc_full.ini

@@ -6,6 +6,10 @@
 server_addr = 0.0.0.0
 server_port = 7000
 
+# Specify another address of the server to connect for nat hole. By default, it's same with
+# server_addr.
+# nat_hole_server_addr = 0.0.0.0
+
 # The maximum amount of time a dial to server will wait for a connect to complete. Default value is 10 seconds.
 # dial_server_timeout = 10
 

+ 3 - 0
pkg/config/client.go

@@ -35,6 +35,9 @@ type ClientCommonConf struct {
 	// ServerAddr specifies the address of the server to connect to. By
 	// default, this value is "0.0.0.0".
 	ServerAddr string `ini:"server_addr" json:"server_addr"`
+	// Specify another address of the server to connect for nat hole. By default, it's same with
+	// ServerAddr.
+	NatHoleServerAddr string `ini:"nat_hole_server_addr" json:"nat_hole_server_addr"`
 	// ServerPort specifies the port to connect to the server on. By default,
 	// this value is 7000.
 	ServerPort int `ini:"server_port" json:"server_port"`