Remove indirection of Flags

Simplifies the code
This commit is contained in:
Julian Kornberger 2016-10-08 11:41:08 +02:00
parent cbe2577aa9
commit e9420828a2
5 changed files with 15 additions and 20 deletions

View File

@ -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:"-"`

View File

@ -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 {

View File

@ -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

View File

@ -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:"-"`

View File

@ -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,11 +167,9 @@ 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() {