From 90106313ebdb5d611d0e59b5631b3b188690e440 Mon Sep 17 00:00:00 2001 From: Daniel Ehlers Date: Sun, 29 Dec 2013 04:14:07 +0100 Subject: [PATCH 1/3] Method for searching a node by id. --- nodedb.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nodedb.py b/nodedb.py index 40d47cf..0feb841 100644 --- a/nodedb.py +++ b/nodedb.py @@ -36,6 +36,13 @@ class NodeDB: raise + def maybe_node_by_id(self, mac): + for node in self._nodes: + if mac.lower() == node.id: + return node + + raise + def parse_vis_data(self,vis_data): for x in vis_data: From 3557e471e158d668b7834cfc1c2e3dae438cb4cd Mon Sep 17 00:00:00 2001 From: Daniel Ehlers Date: Sun, 29 Dec 2013 04:15:40 +0100 Subject: [PATCH 2/3] Add client macs obscure option handling --- bat2nodes.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bat2nodes.py b/bat2nodes.py index 2a2d45b..8204ce7 100755 --- a/bat2nodes.py +++ b/bat2nodes.py @@ -29,6 +29,9 @@ parser.add_argument('-a', '--aliases', parser.add_argument('-m', '--mesh', action='append', help='batman mesh interface') +parser.add_argument('-o', '--obscure', action='store_true', + help='obscure client macs') + parser.add_argument('-d', '--destination-directory', action='store', help='destination directory for generated files',required=True) @@ -53,6 +56,9 @@ if options['aliases']: for aliases in options['aliases']: db.import_aliases(json.load(open(aliases))) +if options['obscure']: + db.obscure_clients() + scriptdir = os.path.dirname(os.path.realpath(__file__)) rrd = rrd(scriptdir + "/nodedb/", options['destination_directory'] + "/nodes") From a0c234ea052b1d65ccf2c66df2e6b0ac948e22c6 Mon Sep 17 00:00:00 2001 From: Andreas Baldeau Date: Sun, 29 Dec 2013 13:09:33 +0100 Subject: [PATCH 3/3] Add client mac obscuring methods. --- nodedb.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/nodedb.py b/nodedb.py index 0feb841..3812379 100644 --- a/nodedb.py +++ b/nodedb.py @@ -211,6 +211,69 @@ class NodeDB: link.type = "vpn" + def obscure_clients(self): + + globalIdCounter = 0 + nodeCounters = {} + clientIds = {} + + for node in self._nodes: + if node.flags['client']: + node.macs = set() + clientIds[node.id] = None + sys.stderr.write("client:" + node.id) + + for link in self._links: + ids = link.source.interface + idt = link.target.interface + try: + node_source = self.maybe_node_by_fuzzy_mac(ids) + node_target = self.maybe_node_by_id(idt) + if ids in clientIds and idt in clientIds: + # This is for corner cases, when a client + # is linked to another client. + clientIds[ids] = str(globalIdCounter) + id1 = str(globalIdCounter) + globalIdCounter += 1 + + clientIds[idt] = str(globalIdCounter) + idt = str(globalIdCounter) + globalIdCounter += 1 + + elif ids in clientIds: + sys.stderr.write("passed ids") + newId = generateId(idt) + clientIds[ids] = newId + ids = newId + + link.source.interface = ids; + node_source.id = ids; + + elif idt in clientIds: + sys.stderr.write("passed idt") + newId = generateId(ids,nodeCounters) + clientIds[idt] = newId + idt = newId + + link.target.interface = idt; + node_target.id = idt; + + link.id = ids + "-" + idt + + except: + raise + +# extends node id by incremented node counter +def generateId(nodeId,nodeCounters): + if nodeId in nodeCounters: + n = nodeCounters[nodeId] + nodeCounters[nodeId] = n + 1 + else: + nodeCounters[nodeId] = 1 + n = 0 + + return nodeId + "_" + str(n) + # compares two MACs and decides whether they are # similar and could be from the same node def is_similar(a, b):