diff options
author | rexxnor <rexxnor+gnunet@brief.li> | 2019-06-29 12:39:43 +0200 |
---|---|---|
committer | rexxnor <rexxnor+gnunet@brief.li> | 2019-06-29 12:39:43 +0200 |
commit | 7623c3bd29f73afc7aaac07192e2f497736f5602 (patch) | |
tree | 552dcaf82db2b6798dc488396a2746e89dd3a7ed | |
parent | 9d54a0f108fa172a59e26380a4b6bcf10397c542 (diff) | |
download | ascension-7623c3bd29f73afc7aaac07192e2f497736f5602.tar.gz ascension-7623c3bd29f73afc7aaac07192e2f497736f5602.zip |
changed run to Popen for async processing, fixed zone creation bug
-rw-r--r-- | ascension/ascension.py | 59 |
1 files changed, 37 insertions, 22 deletions
diff --git a/ascension/ascension.py b/ascension/ascension.py index 31f0bc8..36fdfbf 100644 --- a/ascension/ascension.py +++ b/ascension/ascension.py | |||
@@ -345,26 +345,22 @@ class Ascender(): | |||
345 | len(recordline)/2, label) | 345 | len(recordline)/2, label) |
346 | 346 | ||
347 | if privkey: | 347 | if privkey: |
348 | ret = sp.run([GNUNET_NAMESTORE_COMMAND, | 348 | ret = sp.Popen([GNUNET_NAMESTORE_COMMAND, |
349 | '-z', zonename, | 349 | '-z', zonename, |
350 | '-n', str(label), | 350 | '-n', str(label), |
351 | ] + recordline, | 351 | ] + recordline, |
352 | env=dict(os.environ, **{ | 352 | env=dict(os.environ, **{ |
353 | "GNUNET_NAMESTORE_EGO_PRIVATE_KEY": privkey | 353 | "GNUNET_NAMESTORE_EGO_PRIVATE_KEY": privkey |
354 | })) | 354 | })) |
355 | else: | 355 | else: |
356 | ret = sp.run([GNUNET_NAMESTORE_COMMAND, | 356 | ret = sp.Popen([GNUNET_NAMESTORE_COMMAND, |
357 | '-z', zonename, | 357 | '-z', zonename, |
358 | '-n', str(label), | 358 | '-n', str(label), |
359 | ] + recordline, | 359 | ] + recordline, |
360 | ) | 360 | ) |
361 | 361 | ||
362 | if ret.returncode != 0: | 362 | logging.info("added record with command %s", |
363 | logging.warning("failed adding record with name %s", | 363 | ' '.join(ret.args)) |
364 | ' '.join(ret.args)) | ||
365 | else: | ||
366 | logging.info("successfully added record with command %s", | ||
367 | ' '.join(ret.args)) | ||
368 | 364 | ||
369 | def resolve_glue(self, | 365 | def resolve_glue(self, |
370 | authorityname: str) -> list: | 366 | authorityname: str) -> list: |
@@ -433,7 +429,7 @@ class Ascender(): | |||
433 | if str(value)[-1] == ".": | 429 | if str(value)[-1] == ".": |
434 | # FQDN provided | 430 | # FQDN provided |
435 | if value.endswith(".%s." % zonename): | 431 | if value.endswith(".%s." % zonename): |
436 | # in bailiwick | 432 | # in bailiwick |
437 | value = self.resolve_glue(record.target) | 433 | value = self.resolve_glue(record.target) |
438 | else: | 434 | else: |
439 | # out of bailiwick | 435 | # out of bailiwick |
@@ -660,11 +656,17 @@ class Ascender(): | |||
660 | # Check if a delegated zone is available in GNS as per NS record | 656 | # Check if a delegated zone is available in GNS as per NS record |
661 | # Adds NS records that contain "gns--pkey--" to dictionary | 657 | # Adds NS records that contain "gns--pkey--" to dictionary |
662 | nsrecords = self.zone.iterate_rdatasets(dns.rdatatype.NS) | 658 | nsrecords = self.zone.iterate_rdatasets(dns.rdatatype.NS) |
659 | nameserverlist = list() | ||
663 | for nsrecord in nsrecords: | 660 | for nsrecord in nsrecords: |
664 | name = str(nsrecord[0]) | 661 | name = str(nsrecord[0]) |
665 | values = nsrecord[1] | 662 | values = nsrecord[1] |
666 | ttl = values.ttl | 663 | ttl = values.ttl |
667 | 664 | ||
665 | # save DNS name object of nameservers for later | ||
666 | for nameserver in values: | ||
667 | nameserverlist.append(nameserver.target) | ||
668 | |||
669 | # filter for gns--pkey record in rdatas | ||
668 | gnspkeys = list(filter(lambda record: | 670 | gnspkeys = list(filter(lambda record: |
669 | str(record).startswith('gns--pkey--'), | 671 | str(record).startswith('gns--pkey--'), |
670 | values)) | 672 | values)) |
@@ -693,9 +695,17 @@ class Ascender(): | |||
693 | logging.critical("PKEY in DNS does not match PKEY in GNS for name %s", name) | 695 | logging.critical("PKEY in DNS does not match PKEY in GNS for name %s", name) |
694 | continue | 696 | continue |
695 | 697 | ||
696 | # Create missing zones (and add to dict) for GNS zones that are NOT DNS zones | 698 | # Create missing zones (and add to dict) for GNS zones that are NOT DNS |
697 | # ("." is not a zone-cut in DNS, but always in GNS). | 699 | # zones ("." is not a zone-cut in DNS, but always in GNS). Only add the |
698 | for name in self.zone.nodes.keys(): | 700 | # records that there are no NS records for |
701 | remaining_nsrecords = list(filter(lambda name: not name.is_absolute(), | ||
702 | nameserverlist)) | ||
703 | remaining = list(filter(lambda name: name not in remaining_nsrecords, | ||
704 | self.zone.nodes.keys())) | ||
705 | final = list(filter(lambda name: len(str(name).split('.')) > 1, | ||
706 | remaining)) | ||
707 | |||
708 | for name in final: | ||
699 | subzones = str(name).split('.') | 709 | subzones = str(name).split('.') |
700 | for i in range(1, len(subzones)): | 710 | for i in range(1, len(subzones)): |
701 | subdomain = ".".join(subzones[i:]) | 711 | subdomain = ".".join(subzones[i:]) |
@@ -804,11 +814,16 @@ def main(): | |||
804 | continue | 814 | continue |
805 | else: | 815 | else: |
806 | logging.info("GNS zone is out of date, performing incremental transfer.") | 816 | logging.info("GNS zone is out of date, performing incremental transfer.") |
817 | if standalone: | ||
818 | return 1 | ||
807 | print("GNS zone is out of date, performing incremental transfer.") | 819 | print("GNS zone is out of date, performing incremental transfer.") |
808 | 820 | ||
809 | try: | 821 | try: |
822 | start = time.time() | ||
810 | ascender.zone = dns.zone.from_xfr(ascender.zonegenerator, | 823 | ascender.zone = dns.zone.from_xfr(ascender.zonegenerator, |
811 | check_origin=False) | 824 | check_origin=False) |
825 | end = time.time() | ||
826 | print("Zone transferrred in %s seconds" % str(end - start)) | ||
812 | ascender.soa = ascender.get_zone_soa(ascender.zone) | 827 | ascender.soa = ascender.get_zone_soa(ascender.zone) |
813 | refresh = int(str(ascender.soa[2]).split(" ")[3]) | 828 | refresh = int(str(ascender.soa[2]).split(" ")[3]) |
814 | retry = int(str(ascender.soa[2]).split(" ")[4]) | 829 | retry = int(str(ascender.soa[2]).split(" ")[4]) |