Преглед изворни кода

correctly merge BATMAN neighbours

Helge Jung пре 10 година
родитељ
комит
18e2efde54
2 измењених фајлова са 21 додато и 4 уклоњено
  1. 18 1
      ffstatus/__init__.py
  2. 3 3
      ffstatus/batman.py

+ 18 - 1
ffstatus/__init__.py

@@ -34,6 +34,13 @@ def dict_merge(a, b):
 
 def merge_alfred_batman(alfreddata, batmandata):
 	merged = {}
+
+	batlookup = {}
+	for nodeid in batmandata:
+		batlookup[nodeid] = nodeid
+		for bda in batmandata[nodeid]['aliases']:
+			batlookup[bda] = nodeid
+
 	for nodeid in alfreddata:
 		nodeinfo = alfreddata[nodeid]
 		candidates = set()
@@ -43,7 +50,17 @@ def merge_alfred_batman(alfreddata, batmandata):
 			for mac in nodeinfo['macs']:
 				candidates.add(mac2id(mac))
 
-		for candidate in candidates:
+		if 'network' in nodeinfo:
+			n = nodeinfo['network']
+			if 'mac' in n: candidates.add(mac2id(n['mac']))
+			if 'mesh_interfaces' in n:
+				for mac in n['mesh_interfaces']:
+					candidates.add(mac2id(mac))
+
+		if not 'neighbours' in nodeinfo: nodeinfo['neighbours'] = []
+
+		for candidate_raw in candidates:
+			candidate = batlookup[candidate_raw] if candidate_raw in batlookup else candidate_raw
 			if candidate in batmandata:
 				nodeinfo = dict_merge(nodeinfo, batmandata[candidate])
 

+ 3 - 3
ffstatus/batman.py

@@ -60,9 +60,9 @@ class BatmanParser:
 			neighbours = {}
 			if 'neighbors' in item:
 				for neighbour in item['neighbors']:
-					if neighbour['router'] != item['primary']:
-						#print('node {0}\'s neighbor {1} has unexpected router {2}'.format(itemid, neighbour['neighbor'], neighbour['router']))
-						neighbours[self.mac2id(neighbour['neighbor'])] = float(neighbour['metric'])
+					#if neighbour['router'] != item['primary']:
+					#	print('node {0}\'s neighbor {1} has unexpected router {2}'.format(itemid, neighbour['neighbor'], neighbour['router']))
+					neighbours[self.mac2id(neighbour['neighbor'])] = float(neighbour['metric'])
 
 			data[itemid] = {
 				'aliases': aliases,