Skip to content

Commit

Permalink
Merge 5b587d5 into 8175afd
Browse files Browse the repository at this point in the history
  • Loading branch information
genofire committed Mar 15, 2017
2 parents 8175afd + 5b587d5 commit 36c26a3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
11 changes: 7 additions & 4 deletions models/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,20 @@ func (nodes *Nodes) BuildGraph() *Graph {
vpn: make(map[string]interface{}),
}

builder.readNodes(nodes.List)
builder.readNodes(nodes)

graph := &Graph{Version: 1}
graph.Batadv.Directed = false
graph.Batadv.Nodes, graph.Batadv.Links = builder.extract()
return graph
}

func (builder *graphBuilder) readNodes(nodes map[string]*Node) {
func (builder *graphBuilder) readNodes(nodes *Nodes) {
nodes.RLock()
defer nodes.RUnlock()

// Fill mac->id map
for sourceID, node := range nodes {
for sourceID, node := range nodes.List {
if nodeinfo := node.Nodeinfo; nodeinfo != nil {
// is VPN address?
if nodeinfo.VPN {
Expand Down Expand Up @@ -89,7 +92,7 @@ func (builder *graphBuilder) readNodes(nodes map[string]*Node) {
}

// Add links
for sourceID, node := range nodes {
for sourceID, node := range nodes.List {
if node.Flags.Online {
if neighbours := node.Neighbours; neighbours != nil {
// Batman neighbours
Expand Down
5 changes: 3 additions & 2 deletions models/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"encoding/json"
"log"
"os"
"sync"
"time"

"github.com/sasha-s/go-deadlock"

"github.com/FreifunkBremen/yanic/data"
"github.com/FreifunkBremen/yanic/jsontime"
"github.com/FreifunkBremen/yanic/meshviewer"
Expand All @@ -16,7 +17,7 @@ import (
type Nodes struct {
List map[string]*Node `json:"nodes"` // the current nodemap, indexed by node ID
config *Config
sync.RWMutex
deadlock.RWMutex
}

// NewNodes create Nodes structs
Expand Down
4 changes: 2 additions & 2 deletions models/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewGlobalStats(nodes *Nodes) (result *GlobalStats) {
Models: make(CounterMap),
}

nodes.Lock()
nodes.RLock()
for _, node := range nodes.List {
if node.Flags.Online {
result.Nodes++
Expand All @@ -42,7 +42,7 @@ func NewGlobalStats(nodes *Nodes) (result *GlobalStats) {
}
}
}
nodes.Unlock()
nodes.RUnlock()
return
}

Expand Down

0 comments on commit 36c26a3

Please sign in to comment.