mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-10 17:48:25 +08:00
remove publish prior to registration with server
This commit is contained in:
parent
050da4ea74
commit
9578b72d5e
2 changed files with 16 additions and 33 deletions
|
@ -42,10 +42,9 @@ 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
|
//check if ListenPort was set on command line
|
||||||
if cfg.Node.ListenPort != 0 {
|
if cfg.Node.ListenPort != 0 {
|
||||||
cfg.Node.UDPHolePunch = "no"
|
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 {
|
||||||
|
@ -172,10 +171,6 @@ 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")
|
||||||
cfg.Node = node
|
cfg.Node = node
|
||||||
logger.Log(1, "turn on UDP hole punching (dynamic port setting)? "+cfg.Node.UDPHolePunch)
|
|
||||||
if !manualPort && (cfg.Node.UDPHolePunch == "no") {
|
|
||||||
setListenPort(cfg)
|
|
||||||
}
|
|
||||||
err = config.ModNodeConfig(&cfg.Node)
|
err = config.ModNodeConfig(&cfg.Node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -199,8 +194,10 @@ func JoinNetwork(cfg *config.ClientConfig, privateKey string) error {
|
||||||
if cfg.Server.Server == "" {
|
if cfg.Server.Server == "" {
|
||||||
return errors.New("did not recieve broker address from registration")
|
return errors.New("did not recieve broker address from registration")
|
||||||
}
|
}
|
||||||
|
// update server with latest data
|
||||||
_ = UpdateLocalListenPort(cfg)
|
if err := PublishNodeUpdate(cfg); err != nil {
|
||||||
|
logger.Log(0, "failed to publish update for join", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
if cfg.Daemon == "install" || ncutils.IsFreeBSD() {
|
if cfg.Daemon == "install" || ncutils.IsFreeBSD() {
|
||||||
err = daemon.InstallDaemon(cfg)
|
err = daemon.InstallDaemon(cfg)
|
||||||
|
@ -229,20 +226,3 @@ func formatName(node models.Node) string {
|
||||||
}
|
}
|
||||||
return node.Name
|
return node.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func setListenPort(cfg *config.ClientConfig) {
|
|
||||||
// keep track of the returned listenport value
|
|
||||||
newListenPort := cfg.Node.ListenPort
|
|
||||||
var errN error
|
|
||||||
// get free port based on returned default listen port
|
|
||||||
cfg.Node.ListenPort, errN = ncutils.GetFreePort(cfg.Node.ListenPort)
|
|
||||||
if errN != nil {
|
|
||||||
cfg.Node.ListenPort = newListenPort
|
|
||||||
logger.Log(1, "Error retrieving port: ", errN.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
// if newListenPort has been modified to find an available port, publish to server
|
|
||||||
if cfg.Node.ListenPort != newListenPort {
|
|
||||||
PublishNodeUpdate(cfg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -135,14 +135,14 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer wgclient.Close()
|
defer wgclient.Close()
|
||||||
modcfg, err := config.ReadConfig(node.Network)
|
cfg, err := config.ReadConfig(node.Network)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
nodecfg := modcfg.Node
|
//nodecfg := modcfg.Node
|
||||||
var ifacename string
|
var ifacename string
|
||||||
if nodecfg.Interface != "" {
|
if cfg.Node.Interface != "" {
|
||||||
ifacename = nodecfg.Interface
|
ifacename = cfg.Node.Interface
|
||||||
} else if node.Interface != "" {
|
} else if node.Interface != "" {
|
||||||
ifacename = node.Interface
|
ifacename = node.Interface
|
||||||
} else {
|
} else {
|
||||||
|
@ -151,11 +151,14 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
||||||
if node.PrimaryAddress() == "" {
|
if node.PrimaryAddress() == "" {
|
||||||
return fmt.Errorf("no address to configure")
|
return fmt.Errorf("no address to configure")
|
||||||
}
|
}
|
||||||
|
logger.Log(1, "turn on UDP hole punching (dynamic port setting)? "+cfg.Node.UDPHolePunch)
|
||||||
if node.UDPHolePunch == "yes" {
|
if node.UDPHolePunch == "yes" {
|
||||||
node.ListenPort = 0
|
node.ListenPort = 0
|
||||||
|
} else {
|
||||||
|
//get available port based on current default
|
||||||
|
node.ListenPort, err = ncutils.GetFreePort(node.ListenPort)
|
||||||
}
|
}
|
||||||
if err := WriteWgConfig(&modcfg.Node, key.String(), peers); err != nil {
|
if err := WriteWgConfig(&cfg.Node, key.String(), peers); err != nil {
|
||||||
logger.Log(1, "error writing wg conf file: ", err.Error())
|
logger.Log(1, "error writing wg conf file: ", err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -216,7 +219,7 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
||||||
|
|
||||||
//ipv4
|
//ipv4
|
||||||
if node.Address != "" {
|
if node.Address != "" {
|
||||||
_, cidr, cidrErr := net.ParseCIDR(modcfg.NetworkSettings.AddressRange)
|
_, cidr, cidrErr := net.ParseCIDR(cfg.NetworkSettings.AddressRange)
|
||||||
if cidrErr == nil {
|
if cidrErr == nil {
|
||||||
local.SetCIDRRoute(ifacename, node.Address, cidr)
|
local.SetCIDRRoute(ifacename, node.Address, cidr)
|
||||||
} else {
|
} else {
|
||||||
|
@ -226,7 +229,7 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
||||||
}
|
}
|
||||||
if node.Address6 != "" {
|
if node.Address6 != "" {
|
||||||
//ipv6
|
//ipv6
|
||||||
_, cidr, cidrErr := net.ParseCIDR(modcfg.NetworkSettings.AddressRange6)
|
_, cidr, cidrErr := net.ParseCIDR(cfg.NetworkSettings.AddressRange6)
|
||||||
if cidrErr == nil {
|
if cidrErr == nil {
|
||||||
local.SetCIDRRoute(ifacename, node.Address6, cidr)
|
local.SetCIDRRoute(ifacename, node.Address6, cidr)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue