diff --git a/runtime/node.go b/runtime/node.go index 24d69fc..cd1bfcb 100644 --- a/runtime/node.go +++ b/runtime/node.go @@ -7,7 +7,6 @@ import ( "time" yanicData "github.com/FreifunkBremen/yanic/data" - "github.com/FreifunkBremen/yanic/lib/jsontime" yanicRuntime "github.com/FreifunkBremen/yanic/runtime" ) @@ -57,10 +56,10 @@ func GetWirelessSettings(node *yanicRuntime.Node) *WirelessSettings { } type Node struct { - Lastseen jsontime.Time `json:"lastseen" mapstructure:"-" gorm:"-"` - NodeID string `json:"node_id" gorm:"primary_key" mapstructure:"node_id"` - Blacklist *time.Time `json:"-"` - Address string `json:"ip"` + Lastseen time.Time `json:"lastseen" mapstructure:"-" gorm:"lastseen"` + NodeID string `json:"node_id" gorm:"primary_key" mapstructure:"node_id"` + Blacklist *time.Time `json:"-"` + Address string `json:"ip"` Hostname string `json:"hostname"` HostnameRespondd string `json:"hostname_respondd" gorm:"-"` @@ -104,7 +103,7 @@ func (n *Node) Update(node *yanicRuntime.Node, ipPrefix string) { if node == nil { return } - n.Lastseen = jsontime.Now() + n.Lastseen = time.Now() if nodeinfo := node.Nodeinfo; nodeinfo != nil { n.HostnameRespondd = nodeinfo.Hostname diff --git a/runtime/ping.go b/runtime/ping.go index 8c31d31..d1a0636 100644 --- a/runtime/ping.go +++ b/runtime/ping.go @@ -68,6 +68,7 @@ func (pinger *Pinger) Stop() { func (pinger *Pinger) run() { result := &data.PingResult{} now := time.Now() + before := now.Add(-pinger.blacklistFor) count := 0 var nodes []*Node @@ -80,7 +81,7 @@ func (pinger *Pinger) run() { for _, node := range nodes { go func(n *Node) { defer wg.Done() - if n.Blacklist.After(now.Add(-pinger.blacklistFor)) { + if n.Blacklist != nil && n.Blacklist.After(before) { return } diff --git a/runtime/yanic.go b/runtime/yanic.go index 558d82e..df1a0f7 100644 --- a/runtime/yanic.go +++ b/runtime/yanic.go @@ -46,23 +46,26 @@ func (conn *YanicDB) InsertNode(n *runtimeYanic.Node) { } if conn.db.First(&lNode).Error == nil { lNode.Update(n, conn.prefix) - conn.db.Model(&lNode).Update(map[string]interface{}{"address": lNode.Address}) + conn.db.Model(&lNode).Update(map[string]interface{}{ + "address": lNode.Address, + "lastseen": now, + }) if lNode.Blacklist != nil && lNode.Blacklist.After(now.Add(-conn.blacklistFor)) { logger.Debug("on blacklist") return } - conn.sendNode(&lNode) if !lNode.CheckRespondd() { if !lNode.SSHUpdate(conn.ssh) { conn.db.Model(&lNode).Update(map[string]interface{}{"blacklist": &now}) logger.Warn("yanic trigger sshupdate failed - set blacklist") - } else { - logger.Debug("yanic trigger sshupdate again") + return } + logger.Debug("yanic trigger sshupdate again") } else { logger.Debug("yanic update") } + conn.sendNode(&lNode) return } node := NewNode(n, conn.prefix) diff --git a/websocket/hd_connect.go b/websocket/hd_connect.go index c087455..1b2e7ee 100644 --- a/websocket/hd_connect.go +++ b/websocket/hd_connect.go @@ -18,13 +18,17 @@ func (ws *WebsocketServer) connectHandler(logger *log.Entry, msg *wsLib.Message) var count int now := time.Now() + before := now.Add(-ws.blacklistFor) ws.db.Find(&nodes).Count(&count) ws.nodes.Lock() i := 0 for _, node := range nodes { - if node.Blacklist != nil && node.Blacklist.After(now.Add(-ws.blacklistFor)) { + if node.Blacklist != nil && node.Blacklist.After(before) { + continue + } + if node.Lastseen.Before(before) { continue } node.Update(ws.nodes.List[node.NodeID], ws.ipPrefix)