From e051d64780ff424c73dabad33d40e870bb4c3168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20W=C3=BCllhorst?= Date: Sun, 27 Mar 2016 19:15:16 +0200 Subject: [PATCH] Handle with IDs, which are not appear in nodes list --- graph.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/graph.py b/graph.py index bb090e9..39dad55 100644 --- a/graph.py +++ b/graph.py @@ -29,7 +29,7 @@ class Graph: def parseLinks(self): link_nodes = self.data['batadv']['nodes'] for link in self.data['batadv']['links']: - if 'node_id' in link_nodes[link['source']].keys() and 'node_id' in link_nodes[link['target']].keys():#else it is a vpn link + if 'node_id' in link_nodes[link['source']] and 'node_id' in link_nodes[link['target']]:#else it is a vpn link if self.nodes_list[link_nodes[link['source']]['node_id']].isGateway == True or self.nodes_list[link_nodes[link['target']]['node_id']].isGateway: self.setVpnLink(link['source'], link['target']) else: @@ -51,12 +51,12 @@ class Graph: } def setVpnLink(self, src, dst): - if 'node_id' not in self.data['batadv']['nodes'][src].keys() or self.nodes_list[self.data['batadv']['nodes'][src]['node_id']].isGateway == True: - if 'node_id' in self.data['batadv']['nodes'][dst]: - self.nodes_list[self.data['batadv']['nodes'][dst]['node_id']].stepsToVpn = 0 - elif 'node_id' not in self.data['batadv']['nodes'][dst].keys() or self.nodes_list[self.data['batadv']['nodes'][dst]['node_id']].isGateway == True: - if 'node_id' in self.data['batadv']['nodes'][src]: - self.nodes_list[self.data['batadv']['nodes'][src]['node_id']].stepsToVpn = 0 + if 'node_id' not in self.data['batadv']['nodes'][src] or (self.data['batadv']['nodes'][src]['node_id'] and self.nodes_list[self.data['batadv']['nodes'][src]['node_id']].isGateway == True): + if 'node_id' in self.data['batadv']['nodes'][dst] and self.data['batadv']['nodes'][dst]['node_id']: + self.nodes_list[self.data['batadv']['nodes'][dst]['node_id']].stepsToVpn = 0 + elif 'node_id' not in self.data['batadv']['nodes'][dst] or (self.data['batadv']['nodes'][dst]['node_id'] and self.nodes_list[self.data['batadv']['nodes'][dst]['node_id']].isGateway == True): + if 'node_id' in self.data['batadv']['nodes'][src] and self.data['batadv']['nodes'][src]['node_id']: + self.nodes_list[self.data['batadv']['nodes'][src]['node_id']].stepsToVpn = 0 def calculateStepsToVpn(self): for node in self.nodes_list.itervalues():