2017-04-16 15:12:23 +02:00
|
|
|
package meshviewer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/FreifunkBremen/yanic/jsontime"
|
|
|
|
"github.com/FreifunkBremen/yanic/runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NodesV1 struct, to support legacy meshviewer (which are in master branch)
|
|
|
|
// i.e. https://github.com/ffnord/meshviewer/tree/master
|
|
|
|
type NodesV1 struct {
|
|
|
|
Version int `json:"version"`
|
|
|
|
Timestamp jsontime.Time `json:"timestamp"` // Timestamp of the generation
|
|
|
|
List map[string]*Node `json:"nodes"` // the current nodemap, indexed by node ID
|
|
|
|
}
|
|
|
|
|
|
|
|
// BuildNodesV1 transforms data to legacy meshviewer
|
2017-05-20 14:46:29 +02:00
|
|
|
func BuildNodesV1(toFilter filter, nodes *runtime.Nodes) interface{} {
|
2017-04-16 15:12:23 +02:00
|
|
|
meshviewerNodes := &NodesV1{
|
|
|
|
Version: 1,
|
|
|
|
List: make(map[string]*Node),
|
|
|
|
Timestamp: jsontime.Now(),
|
|
|
|
}
|
|
|
|
|
2017-06-03 04:02:13 +02:00
|
|
|
for nodeID, nodeOrigin := range nodes.List {
|
2017-05-20 14:46:29 +02:00
|
|
|
nodeFiltere := toFilter(nodeOrigin)
|
|
|
|
if nodeOrigin.Statistics == nil || nodeFiltere == nil {
|
2017-04-16 15:12:23 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
node := &Node{
|
2017-05-20 14:46:29 +02:00
|
|
|
Firstseen: nodeFiltere.Firstseen,
|
|
|
|
Lastseen: nodeFiltere.Lastseen,
|
2017-04-16 15:12:23 +02:00
|
|
|
Flags: Flags{
|
2017-05-20 14:46:29 +02:00
|
|
|
Online: nodeFiltere.Online,
|
|
|
|
Gateway: nodeFiltere.IsGateway(),
|
2017-04-16 15:12:23 +02:00
|
|
|
},
|
2017-05-20 14:46:29 +02:00
|
|
|
Nodeinfo: nodeFiltere.Nodeinfo,
|
2017-04-16 15:12:23 +02:00
|
|
|
}
|
2017-05-20 14:46:29 +02:00
|
|
|
node.Statistics = NewStatistics(nodeFiltere.Statistics)
|
2017-04-16 15:12:23 +02:00
|
|
|
meshviewerNodes.List[nodeID] = node
|
|
|
|
}
|
|
|
|
return meshviewerNodes
|
|
|
|
}
|