mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 08:47:35 +08:00
checkin logic updated
This commit is contained in:
@@ -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()
|
||||||
|
@@ -48,35 +48,35 @@ type Node struct {
|
|||||||
LastCheckIn int64 `json:"lastcheckin" bson:"lastcheckin" yaml:"lastcheckin"`
|
LastCheckIn int64 `json:"lastcheckin" bson:"lastcheckin" yaml:"lastcheckin"`
|
||||||
MacAddress string `json:"macaddress" bson:"macaddress" yaml:"macaddress" validate:"macaddress_unique"`
|
MacAddress string `json:"macaddress" bson:"macaddress" yaml:"macaddress" validate:"macaddress_unique"`
|
||||||
// checkin interval is depreciated at the network level. Set on server with CHECKIN_INTERVAL
|
// checkin interval is depreciated at the network level. Set on server with CHECKIN_INTERVAL
|
||||||
CheckInInterval int32 `json:"checkininterval" bson:"checkininterval" yaml:"checkininterval"`
|
CheckInInterval int32 `json:"checkininterval" bson:"checkininterval" yaml:"checkininterval"`
|
||||||
Password string `json:"password" bson:"password" yaml:"password" validate:"required,min=6"`
|
Password string `json:"password" bson:"password" yaml:"password" validate:"required,min=6"`
|
||||||
Network string `json:"network" bson:"network" yaml:"network" validate:"network_exists"`
|
Network string `json:"network" bson:"network" yaml:"network" validate:"network_exists"`
|
||||||
IsRelayed string `json:"isrelayed" bson:"isrelayed" yaml:"isrelayed"`
|
IsRelayed string `json:"isrelayed" bson:"isrelayed" yaml:"isrelayed"`
|
||||||
IsPending string `json:"ispending" bson:"ispending" yaml:"ispending"`
|
IsPending string `json:"ispending" bson:"ispending" yaml:"ispending"`
|
||||||
IsRelay string `json:"isrelay" bson:"isrelay" yaml:"isrelay" validate:"checkyesorno"`
|
IsRelay string `json:"isrelay" bson:"isrelay" yaml:"isrelay" validate:"checkyesorno"`
|
||||||
IsDocker string `json:"isdocker" bson:"isdocker" yaml:"isdocker" validate:"checkyesorno"`
|
IsDocker string `json:"isdocker" bson:"isdocker" yaml:"isdocker" validate:"checkyesorno"`
|
||||||
IsK8S string `json:"isk8s" bson:"isk8s" yaml:"isk8s" validate:"checkyesorno"`
|
IsK8S string `json:"isk8s" bson:"isk8s" yaml:"isk8s" validate:"checkyesorno"`
|
||||||
IsEgressGateway string `json:"isegressgateway" bson:"isegressgateway" yaml:"isegressgateway"`
|
IsEgressGateway string `json:"isegressgateway" bson:"isegressgateway" yaml:"isegressgateway"`
|
||||||
IsIngressGateway string `json:"isingressgateway" bson:"isingressgateway" yaml:"isingressgateway"`
|
IsIngressGateway string `json:"isingressgateway" bson:"isingressgateway" yaml:"isingressgateway"`
|
||||||
EgressGatewayRanges []string `json:"egressgatewayranges" bson:"egressgatewayranges" yaml:"egressgatewayranges"`
|
EgressGatewayRanges []string `json:"egressgatewayranges" bson:"egressgatewayranges" yaml:"egressgatewayranges"`
|
||||||
RelayAddrs []string `json:"relayaddrs" bson:"relayaddrs" yaml:"relayaddrs"`
|
RelayAddrs []string `json:"relayaddrs" bson:"relayaddrs" yaml:"relayaddrs"`
|
||||||
IngressGatewayRange string `json:"ingressgatewayrange" bson:"ingressgatewayrange" yaml:"ingressgatewayrange"`
|
IngressGatewayRange string `json:"ingressgatewayrange" bson:"ingressgatewayrange" yaml:"ingressgatewayrange"`
|
||||||
IsStatic string `json:"isstatic" bson:"isstatic" yaml:"isstatic" validate:"checkyesorno"`
|
IsStatic string `json:"isstatic" bson:"isstatic" yaml:"isstatic" validate:"checkyesorno"`
|
||||||
UDPHolePunch string `json:"udpholepunch" bson:"udpholepunch" yaml:"udpholepunch" validate:"checkyesorno"`
|
UDPHolePunch string `json:"udpholepunch" bson:"udpholepunch" yaml:"udpholepunch" validate:"checkyesorno"`
|
||||||
PullChanges string `json:"pullchanges" bson:"pullchanges" yaml:"pullchanges" validate:"checkyesorno"`
|
PullChanges string `json:"pullchanges" bson:"pullchanges" yaml:"pullchanges" validate:"checkyesorno"`
|
||||||
DNSOn string `json:"dnson" bson:"dnson" yaml:"dnson" validate:"checkyesorno"`
|
DNSOn string `json:"dnson" bson:"dnson" yaml:"dnson" validate:"checkyesorno"`
|
||||||
IsDualStack string `json:"isdualstack" bson:"isdualstack" yaml:"isdualstack" validate:"checkyesorno"`
|
IsDualStack string `json:"isdualstack" bson:"isdualstack" yaml:"isdualstack" validate:"checkyesorno"`
|
||||||
IsServer string `json:"isserver" bson:"isserver" yaml:"isserver" validate:"checkyesorno"`
|
IsServer string `json:"isserver" bson:"isserver" yaml:"isserver" validate:"checkyesorno"`
|
||||||
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"`
|
||||||
Version string `json:"version" bson:"version" yaml:"version"`
|
Version string `json:"version" bson:"version" yaml:"version"`
|
||||||
ExcludedAddrs []string `json:"excludedaddrs" bson:"excludedaddrs" yaml:"excludedaddrs"`
|
ExcludedAddrs []string `json:"excludedaddrs" bson:"excludedaddrs" yaml:"excludedaddrs"`
|
||||||
TrafficKeys TrafficKeys `json:"traffickeys" bson:"traffickeys" yaml:"traffickeys"`
|
TrafficKeys TrafficKeys `json:"traffickeys" bson:"traffickeys" yaml:"traffickeys"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NodesArray - used for node sorting
|
// NodesArray - used for node sorting
|
||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
@@ -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")
|
||||||
|
@@ -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 "+
|
||||||
|
@@ -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)
|
||||||
|
@@ -125,14 +125,14 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error {
|
|||||||
cfg.Node.Name = formatName(cfg.Node)
|
cfg.Node.Name = formatName(cfg.Node)
|
||||||
// differentiate between client/server here
|
// differentiate between client/server here
|
||||||
var node = models.Node{
|
var node = models.Node{
|
||||||
Password: cfg.Node.Password,
|
Password: cfg.Node.Password,
|
||||||
Address: cfg.Node.Address,
|
Address: cfg.Node.Address,
|
||||||
Address6: cfg.Node.Address6,
|
Address6: cfg.Node.Address6,
|
||||||
ID: cfg.Node.ID,
|
ID: cfg.Node.ID,
|
||||||
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,
|
||||||
|
Reference in New Issue
Block a user