diff --git a/meshviewer/meshviewer.go b/meshviewer/meshviewer.go index 663f661..e2a8723 100644 --- a/meshviewer/meshviewer.go +++ b/meshviewer/meshviewer.go @@ -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:"-"` diff --git a/models/graph.go b/models/graph.go index f182be3..3fb35f2 100644 --- a/models/graph.go +++ b/models/graph.go @@ -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 { diff --git a/models/graph_test.go b/models/graph_test.go index 816e211..023996d 100644 --- a/models/graph_test.go +++ b/models/graph_test.go @@ -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 diff --git a/models/node.go b/models/node.go index d871a62..5359ac6 100644 --- a/models/node.go +++ b/models/node.go @@ -11,12 +11,12 @@ import ( // Node struct type Node struct { - Firstseen jsontime.Time `json:"firstseen"` - Lastseen jsontime.Time `json:"lastseen"` - Flags *meshviewer.Flags `json:"flags,omitempty"` - Statistics *data.Statistics `json:"statistics"` - Nodeinfo *data.NodeInfo `json:"nodeinfo"` - Neighbours *data.Neighbours `json:"-"` + Firstseen jsontime.Time `json:"firstseen"` + Lastseen jsontime.Time `json:"lastseen"` + Flags meshviewer.Flags `json:"flags"` + Statistics *data.Statistics `json:"statistics"` + Nodeinfo *data.NodeInfo `json:"nodeinfo"` + Neighbours *data.Neighbours `json:"-"` } // Returns tags and fields for InfluxDB diff --git a/models/nodes.go b/models/nodes.go index d0e2a18..7488022 100644 --- a/models/nodes.go +++ b/models/nodes.go @@ -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 - } + node.Flags.Online = true // Update neighbours if val := res.Neighbours; val != nil { @@ -174,9 +167,7 @@ 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 - } + node.Flags.Online = false } } }