disable link for offline nodes + improve offline state

This commit is contained in:
Martin Geno 2016-06-22 09:16:06 +02:00
parent 9049b6d937
commit 719cf13f87
3 changed files with 18 additions and 7 deletions

View File

@ -29,7 +29,9 @@ func (t *Time) UnmarshalJSON(data []byte) (err error) {
} }
return return
} }
func (t Time) GetTime() time.Time{
return t.time
}
func (t Time) Unix() int64 { func (t Time) Unix() int64 {
return t.time.Unix() return t.time.Unix()
} }
@ -37,3 +39,10 @@ func (t Time) Unix() int64 {
func (t Time) IsZero() bool { func (t Time) IsZero() bool {
return t.time.IsZero() 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())
}

View File

@ -69,11 +69,13 @@ func (builder *GraphBuilder) readNodes(nodes map[string]*Node) {
// Add links // Add links
for sourceID, node := range nodes { for sourceID, node := range nodes {
if neighbours := node.Neighbours; neighbours != nil { if flag := node.Flags; flag == nil || flag.Online {
for _, batadvNeighbours := range neighbours.Batadv { if neighbours := node.Neighbours; neighbours != nil {
for targetAddress, link := range batadvNeighbours.Neighbours { for _, batadvNeighbours := range neighbours.Batadv {
if targetID, found := builder.macToID[targetAddress]; found { for targetAddress, link := range batadvNeighbours.Neighbours {
builder.addLink(targetID, sourceID, link.Tq) if targetID, found := builder.macToID[targetAddress]; found {
builder.addLink(targetID, sourceID, link.Tq)
}
} }
} }
} }

View File

@ -139,7 +139,7 @@ func (nodes *Nodes) worker() {
// //
// set node as offline (without statistics) // set node as offline (without statistics)
for _, node := range nodes.List { 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 { if node.Flags != nil {
node.Flags.Online = false node.Flags.Online = false
} }