From: Michael Tremer Date: Fri, 15 Nov 2019 15:34:26 +0000 (+0000) Subject: database: Set flags when parsing A1-A3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=10df9f53c1f40752f4da6fa5c1ca21cbc390bed4;p=location%2Flocation-database.git database: Set flags when parsing A1-A3 Signed-off-by: Michael Tremer --- diff --git a/tools/database.py b/tools/database.py index 823faaf..252229f 100644 --- a/tools/database.py +++ b/tools/database.py @@ -47,15 +47,20 @@ class Database(object): def write(self, path): self.writer.write(path) - def import_rir(self, rir): - with open(rir.filename_asnums, "rb") as f: + def import_ases(self, filename): + with open(filename, "rb") as f: for block in util.iterate_over_blocks(f): self._parse_asnum_block(block) - with open(rir.filename_networks, "rb") as f: + def import_networks(self, filename): + with open(filename, "rb") as f: for block in util.iterate_over_blocks(f): self._parse_network_block(block) + def import_rir(self, rir): + self.import_ases(rir.filename_asnums) + self.import_networks(rir.filename_networks) + def _parse_asnum_block(self, block): asn = None name = None @@ -103,8 +108,19 @@ class Database(object): logging.warning("Skipping network %s, because one already exists at this address" % network) return - # Save attributes - n.country_code = country + # Translate some special country codes into flags + if country == "A1": + n.set_flag(location.NETWORK_FLAG_ANONYMOUS_PROXY) + elif country == "A2": + n.set_flag(location.NETWORK_FLAG_SATELLITE_PROVIDER) + elif country == "A3": + n.set_flag(location.NETWORK_FLAG_ANYCAST) + + # Set all other country codes + else: + n.country_code = country + + # Set ASN if available if asn: n.asn = asn