fix node equal check (location)

This commit is contained in:
Martin/Geno 2018-07-27 13:40:04 +02:00
parent 21c398ca42
commit 9fbdd5a798
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
2 changed files with 16 additions and 12 deletions

View File

@ -1,6 +1,7 @@
package runtime package runtime
import ( import (
"fmt"
"net" "net"
"strings" "strings"
@ -80,9 +81,11 @@ func (n *Node) IsEqual(node *Node) bool {
if n.NodeID != node.NodeID { if n.NodeID != node.NodeID {
return false return false
} }
if n.Address != node.Address { /*
return false if n.Address != node.Address {
} return false
}
*/
if n.Hostname != node.Hostname { if n.Hostname != node.Hostname {
return false return false
} }
@ -98,16 +101,20 @@ func (n *Node) IsEqual(node *Node) bool {
return true return true
} }
const LOCATION_EQUAL_FORMAT_STRING = "%.6f"
func locationEqual(a, b yanicData.Location) bool { func locationEqual(a, b yanicData.Location) bool {
if a.Latitude != b.Latitude { if fmt.Sprintf(LOCATION_EQUAL_FORMAT_STRING, a.Latitude) != fmt.Sprintf(LOCATION_EQUAL_FORMAT_STRING, b.Latitude) {
return false return false
} }
if a.Longitude != b.Longitude { if fmt.Sprintf(LOCATION_EQUAL_FORMAT_STRING, a.Longitude) != fmt.Sprintf(LOCATION_EQUAL_FORMAT_STRING, b.Longitude) {
return false return false
} }
if a.Altitude != b.Altitude { if a.Altitude != b.Altitude {
return false return false
} }
return true return true
} }

View File

@ -49,16 +49,17 @@ func (conn *YanicDB) InsertNode(n *runtimeYanic.Node) {
//"StatsClients": node.StatsClients, //"StatsClients": node.StatsClients,
"Address": node.Address, "Address": node.Address,
}) })
conn.sendNode(node, false)
if lNode.Blacklist { if lNode.Blacklist {
logger.Debug("on blacklist") logger.Debug("on blacklist")
return return
} }
conn.sendNode(node, false)
if !node.IsEqual(&lNode) { if !node.IsEqual(&lNode) {
lNode.SSHUpdate(conn.ssh, node) lNode.SSHUpdate(conn.ssh, node)
logger.Debug("run sshupdate again") logger.Debug("yanic trigger sshupdate again")
} else {
logger.Debug("yanic update")
} }
logger.Debug("yanic update")
return return
} }
@ -71,10 +72,6 @@ func (conn *YanicDB) InsertNode(n *runtimeYanic.Node) {
} }
conn.db.Create(&node) conn.db.Create(&node)
conn.sendNode(node, true) conn.sendNode(node, true)
if err == nil {
lNode.SSHUpdate(conn.ssh, node)
logger.Debug("run sshupdate")
}
} }
func (conn *YanicDB) InsertLink(link *runtimeYanic.Link, time time.Time) { func (conn *YanicDB) InsertLink(link *runtimeYanic.Link, time time.Time) {