mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 08:47:35 +08:00
fixing logic for port setting
This commit is contained in:
@@ -42,6 +42,11 @@ func JoinNetwork(cfg *config.ClientConfig, privateKey string) error {
|
|||||||
if cfg.Node.Password == "" {
|
if cfg.Node.Password == "" {
|
||||||
cfg.Node.Password = logic.GenKey()
|
cfg.Node.Password = logic.GenKey()
|
||||||
}
|
}
|
||||||
|
manualPort := false
|
||||||
|
if cfg.Node.ListenPort != 0 {
|
||||||
|
cfg.Node.UDPHolePunch = "no"
|
||||||
|
manualPort = true
|
||||||
|
}
|
||||||
var trafficPubKey, trafficPrivKey, errT = box.GenerateKey(rand.Reader) // generate traffic keys
|
var trafficPubKey, trafficPrivKey, errT = box.GenerateKey(rand.Reader) // generate traffic keys
|
||||||
if errT != nil {
|
if errT != nil {
|
||||||
return errT
|
return errT
|
||||||
@@ -164,10 +169,11 @@ func JoinNetwork(cfg *config.ClientConfig, privateKey string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.Log(1, "node created on remote server...updating configs")
|
logger.Log(1, "node created on remote server...updating configs")
|
||||||
// keep track of the old listenport value
|
|
||||||
oldListenPort := node.ListenPort
|
|
||||||
cfg.Node = node
|
cfg.Node = node
|
||||||
setListenPort(oldListenPort, cfg)
|
logger.Log(0, "UDP Hole Punch: "+cfg.Node.UDPHolePunch)
|
||||||
|
if !manualPort && (cfg.Node.UDPHolePunch == "no") {
|
||||||
|
setListenPort(cfg)
|
||||||
|
}
|
||||||
err = config.ModConfig(&cfg.Node)
|
err = config.ModConfig(&cfg.Node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -215,11 +221,9 @@ func formatName(node models.Node) string {
|
|||||||
return node.Name
|
return node.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func setListenPort(oldListenPort int32, cfg *config.ClientConfig) {
|
func setListenPort(cfg *config.ClientConfig) {
|
||||||
// keep track of the returned listenport value
|
// keep track of the returned listenport value
|
||||||
newListenPort := cfg.Node.ListenPort
|
newListenPort := cfg.Node.ListenPort
|
||||||
|
|
||||||
if newListenPort != oldListenPort {
|
|
||||||
var errN error
|
var errN error
|
||||||
// get free port based on returned default listen port
|
// get free port based on returned default listen port
|
||||||
cfg.Node.ListenPort, errN = ncutils.GetFreePort(cfg.Node.ListenPort)
|
cfg.Node.ListenPort, errN = ncutils.GetFreePort(cfg.Node.ListenPort)
|
||||||
@@ -233,4 +237,3 @@ func setListenPort(oldListenPort int32, cfg *config.ClientConfig) {
|
|||||||
PublishNodeUpdate(cfg)
|
PublishNodeUpdate(cfg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user