2017-04-16 15:12:23 +02:00
|
|
|
package meshviewer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/FreifunkBremen/yanic/jsontime"
|
|
|
|
"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
|
2017-05-20 14:46:29 +02:00
|
|
|
func BuildNodesV2(toFilter filter, nodes *runtime.Nodes) interface{} {
|
2017-04-16 15:12:23 +02:00
|
|
|
meshviewerNodes := &NodesV2{
|
|
|
|
Version: 2,
|
|
|
|
Timestamp: jsontime.Now(),
|
|
|
|
}
|
|
|
|
|
|
|
|
for nodeID := range nodes.List {
|
|
|
|
nodeOrigin := nodes.List[nodeID]
|
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 = append(meshviewerNodes.List, node)
|
|
|
|
}
|
|
|
|
return meshviewerNodes
|
|
|
|
}
|