checkin logic updated

This commit is contained in:
Matthew R. Kasun
2022-02-15 15:40:38 -05:00
parent 6c583567d4
commit e8a897f342
6 changed files with 57 additions and 57 deletions

View File

@@ -396,7 +396,7 @@ func SetNodeDefaults(node *models.Node) {
node.SetDefaultName() node.SetDefaultName()
node.SetLastCheckIn() node.SetLastCheckIn()
node.SetLastPeerUpdate() node.SetLastPeerUpdate()
node.SetRoamingDefault() //node.SetRoamingDefault()
node.SetPullChangesDefault() node.SetPullChangesDefault()
node.SetDefaultAction() node.SetDefaultAction()
node.SetIsServerDefault() node.SetIsServerDefault()

View File

@@ -70,7 +70,7 @@ type Node struct {
Action string `json:"action" bson:"action" yaml:"action"` Action string `json:"action" bson:"action" yaml:"action"`
IsLocal string `json:"islocal" bson:"islocal" yaml:"islocal" validate:"checkyesorno"` IsLocal string `json:"islocal" bson:"islocal" yaml:"islocal" validate:"checkyesorno"`
LocalRange string `json:"localrange" bson:"localrange" yaml:"localrange"` LocalRange string `json:"localrange" bson:"localrange" yaml:"localrange"`
Roaming string `json:"roaming" bson:"roaming" yaml:"roaming" validate:"checkyesorno"` //Roaming string `json:"roaming" bson:"roaming" yaml:"roaming" validate:"checkyesorno"`
IPForwarding string `json:"ipforwarding" bson:"ipforwarding" yaml:"ipforwarding" validate:"checkyesorno"` IPForwarding string `json:"ipforwarding" bson:"ipforwarding" yaml:"ipforwarding" validate:"checkyesorno"`
OS string `json:"os" bson:"os" yaml:"os"` OS string `json:"os" bson:"os" yaml:"os"`
MTU int32 `json:"mtu" bson:"mtu" yaml:"mtu"` MTU int32 `json:"mtu" bson:"mtu" yaml:"mtu"`
@@ -161,11 +161,11 @@ func (node *Node) SetDefaultAction() {
} }
// Node.SetRoamingDefault - sets default roaming status // Node.SetRoamingDefault - sets default roaming status
func (node *Node) SetRoamingDefault() { //func (node *Node) SetRoamingDefault() {
if node.Roaming == "" { // if node.Roaming == "" {
node.Roaming = "yes" // node.Roaming = "yes"
} // }
} //}
// Node.SetPullChangesDefault - sets default pull changes status // Node.SetPullChangesDefault - sets default pull changes status
func (node *Node) SetPullChangesDefault() { func (node *Node) SetPullChangesDefault() {
@@ -371,9 +371,9 @@ func (newNode *Node) Fill(currentNode *Node) {
if newNode.PullChanges == "" { if newNode.PullChanges == "" {
newNode.PullChanges = currentNode.PullChanges newNode.PullChanges = currentNode.PullChanges
} }
if newNode.Roaming == "" { //if newNode.Roaming == "" {
newNode.Roaming = currentNode.Roaming //newNode.Roaming = currentNode.Roaming
} //}
if newNode.Action == "" { if newNode.Action == "" {
newNode.Action = currentNode.Action newNode.Action = currentNode.Action
} }

View File

@@ -228,7 +228,7 @@ func GetCLIConfig(c *cli.Context) (ClientConfig, string, error) {
cfg.Node.LocalAddress = c.String("localaddress") cfg.Node.LocalAddress = c.String("localaddress")
cfg.Node.Address = c.String("address") cfg.Node.Address = c.String("address")
cfg.Node.Address6 = c.String("addressIPV6") cfg.Node.Address6 = c.String("addressIPV6")
cfg.Node.Roaming = c.String("roaming") //cfg.Node.Roaming = c.String("roaming")
cfg.Node.DNSOn = c.String("dnson") cfg.Node.DNSOn = c.String("dnson")
cfg.Node.IsLocal = c.String("islocal") cfg.Node.IsLocal = c.String("islocal")
cfg.Node.IsStatic = c.String("isstatic") cfg.Node.IsStatic = c.String("isstatic")

View File

@@ -28,11 +28,11 @@ func isDeleteError(err error) bool {
func checkIP(node *models.Node, servercfg config.ServerConfig, cliconf config.ClientConfig, network string) bool { func checkIP(node *models.Node, servercfg config.ServerConfig, cliconf config.ClientConfig, network string) bool {
ipchange := false ipchange := false
var err error var err error
if node.Roaming == "yes" && node.IsStatic != "yes" { if node.IsStatic != "yes" {
if node.IsLocal == "no" { if node.IsLocal == "no" {
extIP, err := ncutils.GetPublicIP() extIP, err := ncutils.GetPublicIP()
if err != nil { if err != nil {
ncutils.PrintLog("error encountered checking ip addresses: "+err.Error(), 1) ncutils.PrintLog("error encountered checking public ip addresses: "+err.Error(), 1)
} }
if node.Endpoint != extIP && extIP != "" { if node.Endpoint != extIP && extIP != "" {
ncutils.PrintLog("endpoint has changed from "+ ncutils.PrintLog("endpoint has changed from "+
@@ -43,7 +43,7 @@ func checkIP(node *models.Node, servercfg config.ServerConfig, cliconf config.Cl
} }
intIP, err := getPrivateAddr() intIP, err := getPrivateAddr()
if err != nil { if err != nil {
ncutils.PrintLog("error encountered checking ip addresses: "+err.Error(), 1) ncutils.PrintLog("error encountered checking private ip addresses: "+err.Error(), 1)
} }
if node.LocalAddress != intIP && intIP != "" { if node.LocalAddress != intIP && intIP != "" {
ncutils.PrintLog("local Address has changed from "+ ncutils.PrintLog("local Address has changed from "+
@@ -52,10 +52,10 @@ func checkIP(node *models.Node, servercfg config.ServerConfig, cliconf config.Cl
node.LocalAddress = intIP node.LocalAddress = intIP
ipchange = true ipchange = true
} }
} else { } else if node.IsLocal == "yes" && node.LocalRange != "" {
localIP, err := ncutils.GetLocalIP(node.LocalRange) localIP, err := ncutils.GetLocalIP(node.LocalRange)
if err != nil { if err != nil {
ncutils.PrintLog("error encountered checking ip addresses: "+err.Error(), 1) ncutils.PrintLog("error encountered checking local ip addresses: "+err.Error(), 1)
} }
if node.Endpoint != localIP && localIP != "" { if node.Endpoint != localIP && localIP != "" {
ncutils.PrintLog("endpoint has changed from "+ ncutils.PrintLog("endpoint has changed from "+

View File

@@ -436,10 +436,10 @@ func Checkin(ctx context.Context, wg *sync.WaitGroup, cfg *config.ClientConfig,
// ncutils.Log("Checkin running") // ncutils.Log("Checkin running")
//read latest config //read latest config
cfg.ReadConfig() cfg.ReadConfig()
if cfg.Node.Roaming == "yes" && cfg.Node.IsStatic != "yes" { if cfg.Node.IsStatic != "yes" {
extIP, err := ncutils.GetPublicIP() extIP, err := ncutils.GetPublicIP()
if err != nil { if err != nil {
ncutils.PrintLog("error encountered checking ip addresses: "+err.Error(), 1) ncutils.PrintLog("error encountered checking public ip addresses: "+err.Error(), 1)
} }
if cfg.Node.Endpoint != extIP && extIP != "" { if cfg.Node.Endpoint != extIP && extIP != "" {
ncutils.PrintLog("endpoint has changed from "+cfg.Node.Endpoint+" to "+extIP, 1) ncutils.PrintLog("endpoint has changed from "+cfg.Node.Endpoint+" to "+extIP, 1)
@@ -450,7 +450,7 @@ func Checkin(ctx context.Context, wg *sync.WaitGroup, cfg *config.ClientConfig,
} }
intIP, err := getPrivateAddr() intIP, err := getPrivateAddr()
if err != nil { if err != nil {
ncutils.PrintLog("error encountered checking ip addresses: "+err.Error(), 1) ncutils.PrintLog("error encountered checking private ip addresses: "+err.Error(), 1)
} }
if cfg.Node.LocalAddress != intIP && intIP != "" { if cfg.Node.LocalAddress != intIP && intIP != "" {
ncutils.PrintLog("local Address has changed from "+cfg.Node.LocalAddress+" to "+intIP, 1) ncutils.PrintLog("local Address has changed from "+cfg.Node.LocalAddress+" to "+intIP, 1)
@@ -459,10 +459,10 @@ func Checkin(ctx context.Context, wg *sync.WaitGroup, cfg *config.ClientConfig,
ncutils.Log("could not publish local address change") ncutils.Log("could not publish local address change")
} }
} }
} else { } else if cfg.Node.IsLocal == "yes" && cfg.Node.LocalRange != "" {
localIP, err := ncutils.GetLocalIP(cfg.Node.LocalRange) localIP, err := ncutils.GetLocalIP(cfg.Node.LocalRange)
if err != nil { if err != nil {
ncutils.PrintLog("error encountered checking ip addresses: "+err.Error(), 1) ncutils.PrintLog("error encountered checking local ip addresses: "+err.Error(), 1)
} }
if cfg.Node.Endpoint != localIP && localIP != "" { if cfg.Node.Endpoint != localIP && localIP != "" {
ncutils.PrintLog("endpoint has changed from "+cfg.Node.Endpoint+" to "+localIP, 1) ncutils.PrintLog("endpoint has changed from "+cfg.Node.Endpoint+" to "+localIP, 1)

View File

@@ -132,7 +132,7 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error {
MacAddress: cfg.Node.MacAddress, MacAddress: cfg.Node.MacAddress,
AccessKey: cfg.Server.AccessKey, AccessKey: cfg.Server.AccessKey,
IsStatic: cfg.Node.IsStatic, IsStatic: cfg.Node.IsStatic,
Roaming: cfg.Node.Roaming, //Roaming: cfg.Node.Roaming,
Network: cfg.Network, Network: cfg.Network,
ListenPort: cfg.Node.ListenPort, ListenPort: cfg.Node.ListenPort,
PostUp: cfg.Node.PostUp, PostUp: cfg.Node.PostUp,