From ac3366ff13f9cf71452d50aa6d2263f07a81c26c Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Thu, 10 Apr 2014 17:17:11 +0200 Subject: [PATCH] count clients and add clientcount attribute to each node --- bat2nodes.py | 2 ++ d3mapbuilder.py | 3 ++- node.py | 1 + nodedb.py | 19 +++++++++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/bat2nodes.py b/bat2nodes.py index 29ab3d8..8e6d738 100755 --- a/bat2nodes.py +++ b/bat2nodes.py @@ -64,6 +64,8 @@ if options['alfred']: af = alfred() db.import_aliases(af.aliases()) +db.count_clients() + if options['obscure']: db.obscure_clients() diff --git a/d3mapbuilder.py b/d3mapbuilder.py index 3daf1ee..ff7589f 100644 --- a/d3mapbuilder.py +++ b/d3mapbuilder.py @@ -16,7 +16,8 @@ class D3MapBuilder: 'macs': ', '.join(x.macs), 'geo': [float(x) for x in x.gps.split(" ")] if x.gps else None, 'firmware': x.firmware, - 'flags': x.flags + 'flags': x.flags, + 'clientcount': x.clientcount } for x in nodes] links = self._db.get_links() diff --git a/node.py b/node.py index ba0c3b0..0fe35fb 100644 --- a/node.py +++ b/node.py @@ -11,6 +11,7 @@ class Node(): }) self.gps = None self.firmware = None + self.clientcount = 0 def add_mac(self, mac): mac = mac.lower() diff --git a/nodedb.py b/nodedb.py index 65e4d5e..f1110aa 100644 --- a/nodedb.py +++ b/nodedb.py @@ -218,6 +218,25 @@ class NodeDB: link.type = "vpn" + def count_clients(self): + for link in self._links: + try: + a = self.maybe_node_by_id(link.source.interface) + b = self.maybe_node_by_id(link.target.interface) + + if a.flags['client']: + client = a + node = b + elif b.flags['client']: + client = b + node = a + else: + continue + + node.clientcount += 1 + except: + pass + def obscure_clients(self): globalIdCounter = 0