[BUGFIX] fix link type detection by different sources

This commit is contained in:
Martin Geno 2018-01-03 15:30:28 +01:00 committed by Geno
parent 94c9dd2f6c
commit dcf1b6316c
2 changed files with 25 additions and 15 deletions

View File

@ -2,6 +2,7 @@ package meshviewerFFRGB
import ( import (
"fmt" "fmt"
"log"
"strings" "strings"
"github.com/FreifunkBremen/yanic/lib/jsontime" "github.com/FreifunkBremen/yanic/lib/jsontime"
@ -17,6 +18,7 @@ func transform(nodes *runtime.Nodes) *Meshviewer {
} }
links := make(map[string]*Link) links := make(map[string]*Link)
typeList := make(map[string]string)
nodes.RLock() nodes.RLock()
defer nodes.RUnlock() defer nodes.RUnlock()
@ -29,8 +31,6 @@ func transform(nodes *runtime.Nodes) *Meshviewer {
continue continue
} }
typeList := make(map[string]string)
if nodeinfo := nodeOrigin.Nodeinfo; nodeinfo != nil { if nodeinfo := nodeOrigin.Nodeinfo; nodeinfo != nil {
if meshes := nodeinfo.Network.Mesh; meshes != nil { if meshes := nodeinfo.Network.Mesh; meshes != nil {
for _, mesh := range meshes { for _, mesh := range meshes {
@ -56,18 +56,27 @@ func transform(nodes *runtime.Nodes) *Meshviewer {
if link := links[key]; link != nil { if link := links[key]; link != nil {
if switchSourceTarget { if switchSourceTarget {
link.TargetTQ = float32(linkOrigin.TQ) / 255.0 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 { } else {
link.SourceTQ = float32(linkOrigin.TQ) / 255.0 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 continue
} }
linkType := typeList[linkOrigin.SourceMAC]
if linkType == "" {
linkType = "other"
}
tq := float32(linkOrigin.TQ) / 255.0 tq := float32(linkOrigin.TQ) / 255.0
link := &Link{ link := &Link{
Type: linkType, Type: typeList[linkOrigin.SourceMAC],
Source: linkOrigin.SourceID, Source: linkOrigin.SourceID,
SourceMAC: linkOrigin.SourceMAC, SourceMAC: linkOrigin.SourceMAC,
Target: linkOrigin.TargetID, Target: linkOrigin.TargetID,
@ -76,11 +85,15 @@ func transform(nodes *runtime.Nodes) *Meshviewer {
TargetTQ: tq, TargetTQ: tq,
} }
if switchSourceTarget { if switchSourceTarget {
link.Type = typeList[linkOrigin.TargetMAC]
link.Source = linkOrigin.TargetID link.Source = linkOrigin.TargetID
link.SourceMAC = linkOrigin.TargetMAC link.SourceMAC = linkOrigin.TargetMAC
link.Target = linkOrigin.SourceID link.Target = linkOrigin.SourceID
link.TargetMAC = linkOrigin.SourceMAC link.TargetMAC = linkOrigin.SourceMAC
} }
if link.Type == "" {
link.Type = "other"
}
links[key] = link links[key] = link
meshviewer.Links = append(meshviewer.Links, link) meshviewer.Links = append(meshviewer.Links, link)
} }

View File

@ -57,6 +57,8 @@ func BuildGraph(nodes *runtime.Nodes) *Graph {
} }
func (builder *graphBuilder) readNodes(nodes map[string]*runtime.Node) { func (builder *graphBuilder) readNodes(nodes map[string]*runtime.Node) {
vpnInterface := make(map[string]interface{})
// Fill mac->id map // Fill mac->id map
for sourceID, node := range nodes { for sourceID, node := range nodes {
if nodeinfo := node.Nodeinfo; nodeinfo != nil { if nodeinfo := node.Nodeinfo; nodeinfo != nil {
@ -67,6 +69,9 @@ func (builder *graphBuilder) readNodes(nodes map[string]*runtime.Node) {
// Batman neighbours // Batman neighbours
for _, batinterface := range nodeinfo.Network.Mesh { for _, batinterface := range nodeinfo.Network.Mesh {
for _, vpn := range batinterface.Interfaces.Tunnel {
vpnInterface[vpn] = nil
}
addresses := batinterface.Addresses() addresses := batinterface.Addresses()
for _, sourceAddress := range addresses { for _, sourceAddress := range addresses {
@ -86,14 +91,6 @@ func (builder *graphBuilder) readNodes(nodes map[string]*runtime.Node) {
// Add links // Add links
for sourceID, node := range nodes { for sourceID, node := range nodes {
if node.Online { 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 { if neighbours := node.Neighbours; neighbours != nil {
// Batman neighbours // Batman neighbours
for sourceMAC, batadvNeighbours := range neighbours.Batadv { for sourceMAC, batadvNeighbours := range neighbours.Batadv {