diff --git a/jsontime/jsontime.go b/jsontime/jsontime.go index 355af67..399f78a 100644 --- a/jsontime/jsontime.go +++ b/jsontime/jsontime.go @@ -29,7 +29,9 @@ func (t *Time) UnmarshalJSON(data []byte) (err error) { } return } - +func (t Time) GetTime() time.Time{ + return t.time +} func (t Time) Unix() int64 { return t.time.Unix() } @@ -37,3 +39,10 @@ func (t Time) Unix() int64 { func (t Time) IsZero() bool { return t.time.IsZero() } + +func (t Time) Add(d time.Duration) Time { + return Time{time: t.time.Add(d)} +} +func (t Time) After(u Time) bool { + return t.time.After(u.GetTime()) +} diff --git a/models/graph.go b/models/graph.go index 6e5914c..073b059 100644 --- a/models/graph.go +++ b/models/graph.go @@ -69,11 +69,13 @@ func (builder *GraphBuilder) readNodes(nodes map[string]*Node) { // Add links for sourceID, node := range nodes { - if neighbours := node.Neighbours; neighbours != nil { - for _, batadvNeighbours := range neighbours.Batadv { - for targetAddress, link := range batadvNeighbours.Neighbours { - if targetID, found := builder.macToID[targetAddress]; found { - builder.addLink(targetID, sourceID, link.Tq) + if flag := node.Flags; flag == nil || flag.Online { + if neighbours := node.Neighbours; neighbours != nil { + for _, batadvNeighbours := range neighbours.Batadv { + for targetAddress, link := range batadvNeighbours.Neighbours { + if targetID, found := builder.macToID[targetAddress]; found { + builder.addLink(targetID, sourceID, link.Tq) + } } } } diff --git a/models/nodes.go b/models/nodes.go index 68dbf88..842fa3b 100644 --- a/models/nodes.go +++ b/models/nodes.go @@ -139,7 +139,7 @@ func (nodes *Nodes) worker() { // // set node as offline (without statistics) for _, node := range nodes.List { - if node.Statistics != nil && node.Lastseen.Unix()+int64(5*nodes.config.Respondd.CollectInterval) < nodes.Timestamp.Unix() { + if node.Statistics != nil && nodes.Timestamp.After(node.Lastseen.Add( time.Second * time.Duration (5 * nodes.config.Respondd.CollectInterval ))) { if node.Flags != nil { node.Flags.Online = false }