ascension

Migrate DNS zones to the GNU Name System
Log | Files | Refs | README | LICENSE

commit 7623c3bd29f73afc7aaac07192e2f497736f5602
parent 9d54a0f108fa172a59e26380a4b6bcf10397c542
Author: rexxnor <rexxnor+gnunet@brief.li>
Date:   Sat, 29 Jun 2019 12:39:43 +0200

changed run to Popen for async processing, fixed zone creation bug

Diffstat:
Mascension/ascension.py | 59+++++++++++++++++++++++++++++++++++++----------------------
1 file changed, 37 insertions(+), 22 deletions(-)

diff --git a/ascension/ascension.py b/ascension/ascension.py @@ -345,26 +345,22 @@ class Ascender(): len(recordline)/2, label) if privkey: - ret = sp.run([GNUNET_NAMESTORE_COMMAND, - '-z', zonename, - '-n', str(label), - ] + recordline, - env=dict(os.environ, **{ - "GNUNET_NAMESTORE_EGO_PRIVATE_KEY": privkey - })) + ret = sp.Popen([GNUNET_NAMESTORE_COMMAND, + '-z', zonename, + '-n', str(label), + ] + recordline, + env=dict(os.environ, **{ + "GNUNET_NAMESTORE_EGO_PRIVATE_KEY": privkey + })) else: - ret = sp.run([GNUNET_NAMESTORE_COMMAND, - '-z', zonename, - '-n', str(label), - ] + recordline, - ) + ret = sp.Popen([GNUNET_NAMESTORE_COMMAND, + '-z', zonename, + '-n', str(label), + ] + recordline, + ) - if ret.returncode != 0: - logging.warning("failed adding record with name %s", - ' '.join(ret.args)) - else: - logging.info("successfully added record with command %s", - ' '.join(ret.args)) + logging.info("added record with command %s", + ' '.join(ret.args)) def resolve_glue(self, authorityname: str) -> list: @@ -433,7 +429,7 @@ class Ascender(): if str(value)[-1] == ".": # FQDN provided if value.endswith(".%s." % zonename): - # in bailiwick + # in bailiwick value = self.resolve_glue(record.target) else: # out of bailiwick @@ -660,11 +656,17 @@ class Ascender(): # Check if a delegated zone is available in GNS as per NS record # Adds NS records that contain "gns--pkey--" to dictionary nsrecords = self.zone.iterate_rdatasets(dns.rdatatype.NS) + nameserverlist = list() for nsrecord in nsrecords: name = str(nsrecord[0]) values = nsrecord[1] ttl = values.ttl + # save DNS name object of nameservers for later + for nameserver in values: + nameserverlist.append(nameserver.target) + + # filter for gns--pkey record in rdatas gnspkeys = list(filter(lambda record: str(record).startswith('gns--pkey--'), values)) @@ -693,9 +695,17 @@ class Ascender(): logging.critical("PKEY in DNS does not match PKEY in GNS for name %s", name) continue - # Create missing zones (and add to dict) for GNS zones that are NOT DNS zones - # ("." is not a zone-cut in DNS, but always in GNS). - for name in self.zone.nodes.keys(): + # Create missing zones (and add to dict) for GNS zones that are NOT DNS + # zones ("." is not a zone-cut in DNS, but always in GNS). Only add the + # records that there are no NS records for + remaining_nsrecords = list(filter(lambda name: not name.is_absolute(), + nameserverlist)) + remaining = list(filter(lambda name: name not in remaining_nsrecords, + self.zone.nodes.keys())) + final = list(filter(lambda name: len(str(name).split('.')) > 1, + remaining)) + + for name in final: subzones = str(name).split('.') for i in range(1, len(subzones)): subdomain = ".".join(subzones[i:]) @@ -804,11 +814,16 @@ def main(): continue else: logging.info("GNS zone is out of date, performing incremental transfer.") + if standalone: + return 1 print("GNS zone is out of date, performing incremental transfer.") try: + start = time.time() ascender.zone = dns.zone.from_xfr(ascender.zonegenerator, check_origin=False) + end = time.time() + print("Zone transferrred in %s seconds" % str(end - start)) ascender.soa = ascender.get_zone_soa(ascender.zone) refresh = int(str(ascender.soa[2]).split(" ")[3]) retry = int(str(ascender.soa[2]).split(" ")[4])