aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNils Schneider <nils@nilsschneider.net>2014-04-10 17:17:11 +0200
committerNils Schneider <nils@nilsschneider.net>2014-04-10 17:17:11 +0200
commitac3366ff13f9cf71452d50aa6d2263f07a81c26c (patch)
tree47bbb862c9b63046a9ce2b10897b22dc820c8218
parentfbc5c636dfc978877503bd67e14bc445edbb6fb6 (diff)
count clients and add clientcount attribute to each node
-rwxr-xr-xbat2nodes.py2
-rw-r--r--d3mapbuilder.py3
-rw-r--r--node.py1
-rw-r--r--nodedb.py19
4 files changed, 24 insertions, 1 deletions
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