From 9c16434c0ec0da74522106156be61742964e2af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20W=C3=BCllhorst?= Date: Fri, 18 Aug 2017 22:07:40 +0200 Subject: [PATCH] Improved handling of invalid nodes data. --- NodeHierarchy.py | 5 +++-- cloud/GlobalGraph.py | 9 +++++---- cloud/Graph.py | 2 +- cloud/NodeInit.py | 9 ++++++--- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/NodeHierarchy.py b/NodeHierarchy.py index 7ae922f..414bb19 100755 --- a/NodeHierarchy.py +++ b/NodeHierarchy.py @@ -43,8 +43,9 @@ class NodeHierarchy(object): def __createNodeObjects__(self): nodes = {} for nodeID, nodeValue in self.__hopglass.nodes.items(): - print('Create Node object #',len(nodes), '\r',end = '') - nodes[nodeID] = Node(nodeValue) + if nodeValue['nodeinfo']['node_id']: + print('Create Node object #',len(nodes), '\r',end = '') + nodes[nodeID] = Node(nodeValue) print('') return nodes diff --git a/cloud/GlobalGraph.py b/cloud/GlobalGraph.py index d5c42d1..f369cce 100644 --- a/cloud/GlobalGraph.py +++ b/cloud/GlobalGraph.py @@ -26,18 +26,19 @@ class GlobalGraph(Graph): def __getConnectedNodes__(self, nodeID, trace = []): neighNodeIDs = self.getNeighbourNodeIDsForNodeID(nodeID) - trace_new = trace[:] + [x for x in neighNodeIDs if x not in trace] + trace_new = list(set(trace + neighNodeIDs)) for neighNodeID in neighNodeIDs: if neighNodeID not in trace: - trace_new = trace_new + [x for x in self.__getConnectedNodes__(neighNodeID, trace_new) if x not in trace_new] + trace_new = list(set(trace_new + self.__getConnectedNodes__(neighNodeID, trace_new))) return trace_new def __createLocalCloudByNodesList__(self, nodesIDList): nodes = {} links = [] for nodeID in nodesIDList: - nodes[nodeID] = self.__nodes__[nodeID] - links = links + [x for x in self.getLinksByNodeID(nodeID) if x not in links] + if nodeID: + nodes[nodeID] = self.__nodes__[nodeID] + links = list(set(links + self.getLinksByNodeID(nodeID))) return LocalGraph(nodes, links, self.__enableDebugPrinting__) def __debugPrint__(self): diff --git a/cloud/Graph.py b/cloud/Graph.py index 6f7b9e1..03d7d48 100644 --- a/cloud/Graph.py +++ b/cloud/Graph.py @@ -26,7 +26,7 @@ class Graph(object): if link.isVpn == False: endpoints = link.getEndpointNodeIDs(getGateways = False) if nodeID in endpoints: - neighNodeIDs = neighNodeIDs + [x for x in endpoints if x not in neighNodeIDs] + neighNodeIDs = list(set(neighNodeIDs + endpoints)) return neighNodeIDs def getLinksByNodeID(self, nodeID): diff --git a/cloud/NodeInit.py b/cloud/NodeInit.py index aa70ee9..a7abf1e 100644 --- a/cloud/NodeInit.py +++ b/cloud/NodeInit.py @@ -19,13 +19,16 @@ class NodeInit(object): return {} def __getAutoupdaterStatus__(self): - if 'autoupdater' in self.__jsonObject__['nodeinfo']['software']: + try: return self.__jsonObject__['nodeinfo']['software']['autoupdater']['enabled'] - else: + except: return False def __getBranch__(self): - return self.__jsonObject__.get('nodeinfo', {}).get('software', {}).get('autoupdater', {}).get('branch', None) + try: + return self.__jsonObject__['nodeinfo']['software']['autoupdater']['branch'] + except: + return None def __getGeo__(self): geo = {}