mirror of
https://github.com/fatedier/frp.git
synced 2025-07-27 15:45:39 +00:00
feat(nathole): use serverUDPPort in nathole discovery when available (#3382)
This commit is contained in:
@@ -53,8 +53,12 @@ var natholeDiscoveryCmd = &cobra.Command{
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
serverAddr := ""
|
||||
if cfg.ServerUDPPort != 0 {
|
||||
serverAddr = net.JoinHostPort(cfg.ServerAddr, strconv.Itoa(cfg.ServerUDPPort))
|
||||
}
|
||||
addresses, err := nathole.Discover(
|
||||
net.JoinHostPort(cfg.ServerAddr, strconv.Itoa(cfg.ServerUDPPort)),
|
||||
serverAddr,
|
||||
[]string{cfg.NatHoleSTUNServer},
|
||||
[]byte(cfg.Token),
|
||||
)
|
||||
@@ -62,6 +66,10 @@ var natholeDiscoveryCmd = &cobra.Command{
|
||||
fmt.Println("discover error:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if len(addresses) < 2 {
|
||||
fmt.Printf("discover error: can not get enough addresses, need 2, got: %v\n", addresses)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
natType, behavior, err := nathole.ClassifyNATType(addresses)
|
||||
if err != nil {
|
||||
@@ -79,8 +87,5 @@ func validateForNatHoleDiscovery(cfg config.ClientCommonConf) error {
|
||||
if cfg.NatHoleSTUNServer == "" {
|
||||
return fmt.Errorf("nat_hole_stun_server can not be empty")
|
||||
}
|
||||
if cfg.ServerUDPPort == 0 {
|
||||
return fmt.Errorf("server udp port can not be empty")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user