From 5f5cdf3a2debdb70e2a7de372ceeb4f8711d3128 Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Wed, 3 Jan 2018 15:30:28 +0100 Subject: [PATCH] [BUGFIX] fix link type detection by different sources --- output/meshviewer-ffrgb/meshviewer.go | 27 ++++++++++++++++++++------- output/meshviewer/graph.go | 13 +++++-------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/output/meshviewer-ffrgb/meshviewer.go b/output/meshviewer-ffrgb/meshviewer.go index 98d3b21b..94ae5573 100644 --- a/output/meshviewer-ffrgb/meshviewer.go +++ b/output/meshviewer-ffrgb/meshviewer.go @@ -2,6 +2,7 @@ package meshviewerFFRGB import ( "fmt" + "log" "strings" "github.com/FreifunkBremen/yanic/jsontime" @@ -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() @@ -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 { @@ -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, @@ -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) } diff --git a/output/meshviewer/graph.go b/output/meshviewer/graph.go index 00211e34..ccde4422 100644 --- a/output/meshviewer/graph.go +++ b/output/meshviewer/graph.go @@ -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 { @@ -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 { @@ -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 {