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 { type Node struct {
Firstseen jsontime.Time `json:"firstseen"` Firstseen jsontime.Time `json:"firstseen"`
Lastseen jsontime.Time `json:"lastseen"` Lastseen jsontime.Time `json:"lastseen"`
Flags *Flags `json:"flags,omitempty"` Flags Flags `json:"flags"`
Statistics *Statistics `json:"statistics"` Statistics *Statistics `json:"statistics"`
Nodeinfo *data.NodeInfo `json:"nodeinfo"` Nodeinfo *data.NodeInfo `json:"nodeinfo"`
Neighbours *data.Neighbours `json:"-"` Neighbours *data.Neighbours `json:"-"`

View File

@ -78,7 +78,7 @@ func (builder *GraphBuilder) readNodes(nodes map[string]*Node) {
// Add links // Add links
for sourceID, node := range nodes { for sourceID, node := range nodes {
if flag := node.Flags; flag == nil || flag.Online { if node.Flags.Online {
if neighbours := node.Neighbours; neighbours != nil { if neighbours := node.Neighbours; neighbours != nil {
// Batman neighbours // Batman neighbours
for _, batadvNeighbours := range neighbours.Batadv { for _, batadvNeighbours := range neighbours.Batadv {

View File

@ -35,7 +35,11 @@ func testGetNodesByFile(files ...string) *Nodes {
} }
for _, file := range files { 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 return nodes

View File

@ -13,7 +13,7 @@ import (
type Node struct { type Node struct {
Firstseen jsontime.Time `json:"firstseen"` Firstseen jsontime.Time `json:"firstseen"`
Lastseen jsontime.Time `json:"lastseen"` Lastseen jsontime.Time `json:"lastseen"`
Flags *meshviewer.Flags `json:"flags,omitempty"` Flags meshviewer.Flags `json:"flags"`
Statistics *data.Statistics `json:"statistics"` Statistics *data.Statistics `json:"statistics"`
Nodeinfo *data.NodeInfo `json:"nodeinfo"` Nodeinfo *data.NodeInfo `json:"nodeinfo"`
Neighbours *data.Neighbours `json:"-"` Neighbours *data.Neighbours `json:"-"`

View File

@ -56,20 +56,13 @@ func (nodes *Nodes) Update(nodeID string, res *data.ResponseData) *Node {
if node == nil { if node == nil {
node = &Node{ node = &Node{
Firstseen: now, Firstseen: now,
Flags: &meshviewer.Flags{
Online: true,
Gateway: false,
},
} }
nodes.List[nodeID] = node nodes.List[nodeID] = node
} }
nodes.Unlock() nodes.Unlock()
node.Lastseen = now node.Lastseen = now
if node.Flags != nil {
node.Flags.Online = true node.Flags.Online = true
}
// Update neighbours // Update neighbours
if val := res.Neighbours; val != nil { if val := res.Neighbours; val != nil {
@ -174,11 +167,9 @@ func (nodes *Nodes) expire() {
delete(nodes.List, id) delete(nodes.List, id)
} else if node.Lastseen.Before(offlineTime) { } else if node.Lastseen.Before(offlineTime) {
// set to offline // set to offline
if node.Flags != nil {
node.Flags.Online = false node.Flags.Online = false
} }
} }
}
} }
func (nodes *Nodes) save() { func (nodes *Nodes) save() {