[BUGFIX] fix link type detection by different sources
This commit is contained in:
parent
94c9dd2f6c
commit
dcf1b6316c
|
@ -2,6 +2,7 @@ package meshviewerFFRGB
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/FreifunkBremen/yanic/lib/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)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue