diff --git a/NodeHierarchy.py b/NodeHierarchy.py index bd31eb9..8e2b574 100755 --- a/NodeHierarchy.py +++ b/NodeHierarchy.py @@ -42,7 +42,7 @@ class NodeHierarchy(object): def __createNodeObjects__(self): nodes = {} - for nodeID, nodeValue in self.__nodesJson__.nodes.items(): + for nodeID, nodeValue in self.__hopglass.nodes.items(): print('Create Node object #',len(nodes), '\r',end = '') nodes[nodeID] = Node(nodeValue) print('') diff --git a/cloud/NodeInit.py b/cloud/NodeInit.py index 2ad9a16..aa70ee9 100644 --- a/cloud/NodeInit.py +++ b/cloud/NodeInit.py @@ -4,11 +4,11 @@ class NodeInit(object): self.nodeID = self.__jsonObject__['nodeinfo']['node_id'] self.interfaces = self.__getInterfaces__() self.hostname = self.__jsonObject__['nodeinfo']['hostname'] - self.isGateway = self.__jsonObject__['flags']['gateway'] + self.isGateway = self.__jsonObject__['nodeinfo']['isGateway'] self.geo = self.__getGeo__() self.isAutoupdaterEnabled = self.__getAutoupdaterStatus__() self.autoupdaterBranch = self.__getBranch__() - self.isOnline = self.__jsonObject__['flags']['online'] + self.isOnline = self.__jsonObject__['nodeinfo']['isOnline'] self.publicIPv6Addresses = self.__getPublicAddresses__() self.domID = self.__getSiteCode__() @@ -25,10 +25,7 @@ class NodeInit(object): return False def __getBranch__(self): - if 'autoupdater' in self.__jsonObject__['nodeinfo']['software']: - return self.__jsonObject__['nodeinfo']['software']['autoupdater']['branch'] - else: - return None + return self.__jsonObject__.get('nodeinfo', {}).get('software', {}).get('autoupdater', {}).get('branch', None) def __getGeo__(self): geo = {} diff --git a/parser/Hopglass.py b/parser/Hopglass.py index aa11eef..8bca9f2 100644 --- a/parser/Hopglass.py +++ b/parser/Hopglass.py @@ -8,6 +8,8 @@ class Hopglass(JsonParser): self.ifIDs = {} self.links = collections.defaultdict(dict) self.nodes = {} + self.gatewayMacs = [] + self.gateways = [] self.__aggregateData__() #print(self.ifIDs) for k, v in self.links.items(): @@ -17,11 +19,12 @@ class Hopglass(JsonParser): for nodeID, nodeData in self.__jsonData__.items(): # let pass nodes that provide all required informations only - if not set(('nodeinfo', 'neighbours')) <= set(nodeData): + if not set(('nodeinfo', 'neighbours', 'statistics')) <= set(nodeData): continue nodeInfo = nodeData['nodeinfo'] neighbours = nodeData['neighbours'] + statistics = nodeData['statistics'] if not 'batadv' in neighbours: continue @@ -29,6 +32,9 @@ class Hopglass(JsonParser): if not 'mesh' in nodeInfo.get('network', {}): continue + if statistics.get('gateway', False): + self.gatewayMacs.append(statistics['gateway']) + for batID, batVal in nodeInfo['network']['mesh'].items(): if not 'interfaces' in batVal: continue @@ -42,9 +48,13 @@ class Hopglass(JsonParser): self.nodes[nodeID] = nodeData for nodeID, nodeData in self.nodes.items(): + nodeData['nodeinfo']['isGateway'] = False + nodeData['nodeinfo']['isOnline'] = True # Todo: implement detection for iname, ivalue in nodeData['neighbours']['batadv'].items(): if 'neighbours' not in ivalue: continue + if iname in self.gatewayMacs: + nodeData['nodeinfo']['isGateway'] = True if not iname in self.ifIDs: continue for nname, nvalue in ivalue['neighbours'].items():