Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] fix link type detection by different sources #109

Merged
merged 1 commit into from
Jan 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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