]> git.ipfire.org Git - location/libloc.git/commitdiff
export flagged networks with their faked country names, too
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 5 Jun 2020 09:57:41 +0000 (09:57 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 5 Jun 2020 09:57:41 +0000 (09:57 +0000)
This will lead to some networks showing up twice. Once with
their real country and once with their faked one.

It is likely that the first one will match.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/export.py

index 69fe964a3df1640658c937e6e9fb6c3521adcecd..d0bbe77e9796a61a0bb38b3e063518e9f0cfba8e 100644 (file)
@@ -23,10 +23,18 @@ import logging
 import os
 import socket
 
+import _location
+
 # Initialise logging
 log = logging.getLogger("location.export")
 log.propagate = 1
 
+flags = {
+       _location.NETWORK_FLAG_ANONYMOUS_PROXY    : "A1",
+       _location.NETWORK_FLAG_SATELLITE_PROVIDER : "A2",
+       _location.NETWORK_FLAG_ANYCAST            : "A3",
+}
+
 class OutputWriter(object):
        suffix = "networks"
        mode = "w"
@@ -173,6 +181,17 @@ class Exporter(object):
                                except KeyError:
                                        pass
 
+                               # Handle flags
+                               for flag in flags:
+                                       if network.has_flag(flag):
+                                               # Fetch the "fake" country code
+                                               country = flags[flag]
+
+                                               try:
+                                                       writers[country].write(network)
+                                               except KeyError:
+                                                       pass
+
                        # Write everything to the filesystem
                        for writer in writers.values():
                                writer.finish()