Skip to content

Commit

Permalink
[BUGFIX] fix link type detection by different sources
Browse files Browse the repository at this point in the history
  • Loading branch information
genofire committed Jan 15, 2018
1 parent 94c9dd2 commit dcf1b63
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
27 changes: 20 additions & 7 deletions output/meshviewer-ffrgb/meshviewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package meshviewerFFRGB

import (
"fmt"
"log"
"strings"

"github.com/FreifunkBremen/yanic/lib/jsontime"
Expand All @@ -17,6 +18,7 @@ func transform(nodes *runtime.Nodes) *Meshviewer {
}

links := make(map[string]*Link)
typeList := make(map[string]string)

nodes.RLock()
defer nodes.RUnlock()
Expand All @@ -29,8 +31,6 @@ func transform(nodes *runtime.Nodes) *Meshviewer {
continue
}

typeList := make(map[string]string)

if nodeinfo := nodeOrigin.Nodeinfo; nodeinfo != nil {
if meshes := nodeinfo.Network.Mesh; meshes != nil {
for _, mesh := range meshes {
Expand All @@ -56,18 +56,27 @@ func transform(nodes *runtime.Nodes) *Meshviewer {
if link := links[key]; link != nil {
if switchSourceTarget {
link.TargetTQ = float32(linkOrigin.TQ) / 255.0
if link.Type == "other" {
link.Type = typeList[linkOrigin.TargetMAC]
} else if link.Type != typeList[linkOrigin.TargetMAC] {
log.Printf("different linktypes %s:%s current: %s source: %s target: %s", linkOrigin.SourceMAC, linkOrigin.TargetMAC, link.Type, typeList[linkOrigin.SourceMAC], typeList[linkOrigin.TargetMAC])
}
} else {
link.SourceTQ = float32(linkOrigin.TQ) / 255.0
if link.Type == "other" {
link.Type = typeList[linkOrigin.SourceMAC]
} else if link.Type != typeList[linkOrigin.SourceMAC] {
log.Printf("different linktypes %s:%s current: %s source: %s target: %s", linkOrigin.SourceMAC, linkOrigin.TargetMAC, link.Type, typeList[linkOrigin.SourceMAC], typeList[linkOrigin.TargetMAC])
}
}
if link.Type == "" {
link.Type = "other"
}
continue
}
linkType := typeList[linkOrigin.SourceMAC]
if linkType == "" {
linkType = "other"
}
tq := float32(linkOrigin.TQ) / 255.0
link := &Link{
Type: linkType,
Type: typeList[linkOrigin.SourceMAC],
Source: linkOrigin.SourceID,
SourceMAC: linkOrigin.SourceMAC,
Target: linkOrigin.TargetID,
Expand All @@ -76,11 +85,15 @@ func transform(nodes *runtime.Nodes) *Meshviewer {
TargetTQ: tq,
}
if switchSourceTarget {
link.Type = typeList[linkOrigin.TargetMAC]
link.Source = linkOrigin.TargetID
link.SourceMAC = linkOrigin.TargetMAC
link.Target = linkOrigin.SourceID
link.TargetMAC = linkOrigin.SourceMAC
}
if link.Type == "" {
link.Type = "other"
}
links[key] = link
meshviewer.Links = append(meshviewer.Links, link)
}
Expand Down
13 changes: 5 additions & 8 deletions output/meshviewer/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func BuildGraph(nodes *runtime.Nodes) *Graph {
}

func (builder *graphBuilder) readNodes(nodes map[string]*runtime.Node) {
vpnInterface := make(map[string]interface{})

// Fill mac->id map
for sourceID, node := range nodes {
if nodeinfo := node.Nodeinfo; nodeinfo != nil {
Expand All @@ -67,6 +69,9 @@ func (builder *graphBuilder) readNodes(nodes map[string]*runtime.Node) {

// Batman neighbours
for _, batinterface := range nodeinfo.Network.Mesh {
for _, vpn := range batinterface.Interfaces.Tunnel {
vpnInterface[vpn] = nil
}
addresses := batinterface.Addresses()

for _, sourceAddress := range addresses {
Expand All @@ -86,14 +91,6 @@ func (builder *graphBuilder) readNodes(nodes map[string]*runtime.Node) {
// Add links
for sourceID, node := range nodes {
if node.Online {
vpnInterface := make(map[string]interface{})
if nodeinfo := node.Nodeinfo; nodeinfo != nil {
for _, batinterface := range nodeinfo.Network.Mesh {
for _, vpn := range batinterface.Interfaces.Tunnel {
vpnInterface[vpn] = nil
}
}
}
if neighbours := node.Neighbours; neighbours != nil {
// Batman neighbours
for sourceMAC, batadvNeighbours := range neighbours.Batadv {
Expand Down

0 comments on commit dcf1b63

Please sign in to comment.