2017-04-16 13:12:23 +00:00
|
|
|
package meshviewer
|
|
|
|
|
|
|
|
import (
|
2018-01-07 20:00:56 +00:00
|
|
|
"github.com/FreifunkBremen/yanic/lib/jsontime"
|
2017-04-16 13:12:23 +00:00
|
|
|
"github.com/FreifunkBremen/yanic/runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NodesV2 struct, to support new version of meshviewer (which are in legacy develop branch or newer)
|
|
|
|
// i.e. https://github.com/ffnord/meshviewer/tree/dev or https://github.com/ffrgb/meshviewer/tree/develop
|
|
|
|
type NodesV2 struct {
|
|
|
|
Version int `json:"version"`
|
|
|
|
Timestamp jsontime.Time `json:"timestamp"` // Timestamp of the generation
|
|
|
|
List []*Node `json:"nodes"` // the current nodemap, as array
|
|
|
|
}
|
|
|
|
|
|
|
|
// BuildNodesV2 transforms data to modern meshviewers
|
|
|
|
func BuildNodesV2(nodes *runtime.Nodes) interface{} {
|
|
|
|
meshviewerNodes := &NodesV2{
|
|
|
|
Version: 2,
|
|
|
|
Timestamp: jsontime.Now(),
|
|
|
|
}
|
|
|
|
|
2017-05-20 12:46:29 +00:00
|
|
|
for _, 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 = append(meshviewerNodes.List, node)
|
|
|
|
}
|
|
|
|
return meshviewerNodes
|
|
|
|
}
|