2017-04-16 13:12:23 +00: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
|
|
|
|
func BuildNodesV1(nodes *runtime.Nodes) interface{} {
|
|
|
|
meshviewerNodes := &NodesV1{
|
|
|
|
Version: 1,
|
|
|
|
List: make(map[string]*Node),
|
|
|
|
Timestamp: jsontime.Now(),
|
|
|
|
}
|
|
|
|
|
2017-05-20 12:46:29 +00:00
|
|
|
for nodeID, nodeOrigin := range nodes.List {
|
2017-04-16 13:12:23 +00:00
|
|
|
if nodeOrigin.Statistics == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
node := &Node{
|
|
|
|
Firstseen: nodeOrigin.Firstseen,
|
|
|
|
Lastseen: nodeOrigin.Lastseen,
|
|
|
|
Flags: Flags{
|
|
|
|
Online: nodeOrigin.Online,
|
2017-04-18 01:07:41 +00:00
|
|
|
Gateway: nodeOrigin.IsGateway(),
|
2017-04-16 13:12:23 +00:00
|
|
|
},
|
|
|
|
Nodeinfo: nodeOrigin.Nodeinfo,
|
|
|
|
}
|
2017-12-27 01:12:15 +00:00
|
|
|
node.Statistics = NewStatistics(nodeOrigin.Statistics, nodeOrigin.Online)
|
2017-04-16 13:12:23 +00:00
|
|
|
meshviewerNodes.List[nodeID] = node
|
|
|
|
}
|
|
|
|
return meshviewerNodes
|
|
|
|
}
|