Remove indirection of Flags
Simplifies the code
This commit is contained in:
parent
cbe2577aa9
commit
e9420828a2
@ -11,7 +11,7 @@ import (
|
||||
type Node struct {
|
||||
Firstseen jsontime.Time `json:"firstseen"`
|
||||
Lastseen jsontime.Time `json:"lastseen"`
|
||||
Flags *Flags `json:"flags,omitempty"`
|
||||
Flags Flags `json:"flags"`
|
||||
Statistics *Statistics `json:"statistics"`
|
||||
Nodeinfo *data.NodeInfo `json:"nodeinfo"`
|
||||
Neighbours *data.Neighbours `json:"-"`
|
||||
|
@ -78,7 +78,7 @@ func (builder *GraphBuilder) readNodes(nodes map[string]*Node) {
|
||||
|
||||
// Add links
|
||||
for sourceID, node := range nodes {
|
||||
if flag := node.Flags; flag == nil || flag.Online {
|
||||
if node.Flags.Online {
|
||||
if neighbours := node.Neighbours; neighbours != nil {
|
||||
// Batman neighbours
|
||||
for _, batadvNeighbours := range neighbours.Batadv {
|
||||
|
@ -35,7 +35,11 @@ func testGetNodesByFile(files ...string) *Nodes {
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
nodes.List[file] = testGetNodeByFile(file)
|
||||
node := testGetNodeByFile(file)
|
||||
nodes.Update(file, &data.ResponseData{
|
||||
NodeInfo: node.Nodeinfo,
|
||||
Neighbours: node.Neighbours,
|
||||
})
|
||||
}
|
||||
|
||||
return nodes
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
type Node struct {
|
||||
Firstseen jsontime.Time `json:"firstseen"`
|
||||
Lastseen jsontime.Time `json:"lastseen"`
|
||||
Flags *meshviewer.Flags `json:"flags,omitempty"`
|
||||
Flags meshviewer.Flags `json:"flags"`
|
||||
Statistics *data.Statistics `json:"statistics"`
|
||||
Nodeinfo *data.NodeInfo `json:"nodeinfo"`
|
||||
Neighbours *data.Neighbours `json:"-"`
|
||||
|
@ -56,20 +56,13 @@ func (nodes *Nodes) Update(nodeID string, res *data.ResponseData) *Node {
|
||||
if node == nil {
|
||||
node = &Node{
|
||||
Firstseen: now,
|
||||
Flags: &meshviewer.Flags{
|
||||
Online: true,
|
||||
Gateway: false,
|
||||
},
|
||||
}
|
||||
nodes.List[nodeID] = node
|
||||
}
|
||||
nodes.Unlock()
|
||||
|
||||
node.Lastseen = now
|
||||
|
||||
if node.Flags != nil {
|
||||
node.Flags.Online = true
|
||||
}
|
||||
|
||||
// Update neighbours
|
||||
if val := res.Neighbours; val != nil {
|
||||
@ -174,12 +167,10 @@ func (nodes *Nodes) expire() {
|
||||
delete(nodes.List, id)
|
||||
} else if node.Lastseen.Before(offlineTime) {
|
||||
// set to offline
|
||||
if node.Flags != nil {
|
||||
node.Flags.Online = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (nodes *Nodes) save() {
|
||||
// Locking foo
|
||||
|
Loading…
Reference in New Issue
Block a user