[BUGFIX] store lastseen and not forward respondd of blacklisted nodes to websocket
This commit is contained in:
parent
b27c452fab
commit
63087001d3
|
@ -7,7 +7,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
yanicData "github.com/FreifunkBremen/yanic/data"
|
yanicData "github.com/FreifunkBremen/yanic/data"
|
||||||
"github.com/FreifunkBremen/yanic/lib/jsontime"
|
|
||||||
yanicRuntime "github.com/FreifunkBremen/yanic/runtime"
|
yanicRuntime "github.com/FreifunkBremen/yanic/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -57,7 +56,7 @@ func GetWirelessSettings(node *yanicRuntime.Node) *WirelessSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Node struct {
|
type Node struct {
|
||||||
Lastseen jsontime.Time `json:"lastseen" mapstructure:"-" gorm:"-"`
|
Lastseen time.Time `json:"lastseen" mapstructure:"-" gorm:"lastseen"`
|
||||||
NodeID string `json:"node_id" gorm:"primary_key" mapstructure:"node_id"`
|
NodeID string `json:"node_id" gorm:"primary_key" mapstructure:"node_id"`
|
||||||
Blacklist *time.Time `json:"-"`
|
Blacklist *time.Time `json:"-"`
|
||||||
Address string `json:"ip"`
|
Address string `json:"ip"`
|
||||||
|
@ -104,7 +103,7 @@ func (n *Node) Update(node *yanicRuntime.Node, ipPrefix string) {
|
||||||
if node == nil {
|
if node == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
n.Lastseen = jsontime.Now()
|
n.Lastseen = time.Now()
|
||||||
if nodeinfo := node.Nodeinfo; nodeinfo != nil {
|
if nodeinfo := node.Nodeinfo; nodeinfo != nil {
|
||||||
n.HostnameRespondd = nodeinfo.Hostname
|
n.HostnameRespondd = nodeinfo.Hostname
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,7 @@ func (pinger *Pinger) Stop() {
|
||||||
func (pinger *Pinger) run() {
|
func (pinger *Pinger) run() {
|
||||||
result := &data.PingResult{}
|
result := &data.PingResult{}
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
before := now.Add(-pinger.blacklistFor)
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
var nodes []*Node
|
var nodes []*Node
|
||||||
|
@ -80,7 +81,7 @@ func (pinger *Pinger) run() {
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
go func(n *Node) {
|
go func(n *Node) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
if n.Blacklist.After(now.Add(-pinger.blacklistFor)) {
|
if n.Blacklist != nil && n.Blacklist.After(before) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,23 +46,26 @@ func (conn *YanicDB) InsertNode(n *runtimeYanic.Node) {
|
||||||
}
|
}
|
||||||
if conn.db.First(&lNode).Error == nil {
|
if conn.db.First(&lNode).Error == nil {
|
||||||
lNode.Update(n, conn.prefix)
|
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)) {
|
if lNode.Blacklist != nil && lNode.Blacklist.After(now.Add(-conn.blacklistFor)) {
|
||||||
logger.Debug("on blacklist")
|
logger.Debug("on blacklist")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
conn.sendNode(&lNode)
|
|
||||||
if !lNode.CheckRespondd() {
|
if !lNode.CheckRespondd() {
|
||||||
if !lNode.SSHUpdate(conn.ssh) {
|
if !lNode.SSHUpdate(conn.ssh) {
|
||||||
conn.db.Model(&lNode).Update(map[string]interface{}{"blacklist": &now})
|
conn.db.Model(&lNode).Update(map[string]interface{}{"blacklist": &now})
|
||||||
logger.Warn("yanic trigger sshupdate failed - set blacklist")
|
logger.Warn("yanic trigger sshupdate failed - set blacklist")
|
||||||
} else {
|
return
|
||||||
logger.Debug("yanic trigger sshupdate again")
|
|
||||||
}
|
}
|
||||||
|
logger.Debug("yanic trigger sshupdate again")
|
||||||
} else {
|
} else {
|
||||||
logger.Debug("yanic update")
|
logger.Debug("yanic update")
|
||||||
}
|
}
|
||||||
|
conn.sendNode(&lNode)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
node := NewNode(n, conn.prefix)
|
node := NewNode(n, conn.prefix)
|
||||||
|
|
|
@ -18,13 +18,17 @@ func (ws *WebsocketServer) connectHandler(logger *log.Entry, msg *wsLib.Message)
|
||||||
var count int
|
var count int
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
before := now.Add(-ws.blacklistFor)
|
||||||
|
|
||||||
ws.db.Find(&nodes).Count(&count)
|
ws.db.Find(&nodes).Count(&count)
|
||||||
|
|
||||||
ws.nodes.Lock()
|
ws.nodes.Lock()
|
||||||
i := 0
|
i := 0
|
||||||
for _, node := range nodes {
|
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
|
continue
|
||||||
}
|
}
|
||||||
node.Update(ws.nodes.List[node.NodeID], ws.ipPrefix)
|
node.Update(ws.nodes.List[node.NodeID], ws.ipPrefix)
|
||||||
|
|
Loading…
Reference in New Issue