diff options
author | rexxnor <rexxnor+gnunet@brief.li> | 2019-05-22 19:17:34 +0200 |
---|---|---|
committer | rexxnor <rexxnor+gnunet@brief.li> | 2019-05-22 19:17:34 +0200 |
commit | 1859a81b5b4783399fdc3743f8897ac94a78a41f (patch) | |
tree | 436ba2b7df7253682928afd47753e9b6b2e19502 /ascension | |
parent | 195317ee74428ef27e1da5704ac8a11bbeed1842 (diff) | |
download | ascension-1859a81b5b4783399fdc3743f8897ac94a78a41f.tar.gz ascension-1859a81b5b4783399fdc3743f8897ac94a78a41f.zip |
fixed style and logic issues, added some comments
Diffstat (limited to 'ascension')
-rw-r--r-- | ascension/ascension.py | 60 | ||||
-rw-r--r-- | ascension/test/gnunet.zone | 2 |
2 files changed, 31 insertions, 31 deletions
diff --git a/ascension/ascension.py b/ascension/ascension.py index 06bdd44..ffceba7 100644 --- a/ascension/ascension.py +++ b/ascension/ascension.py | |||
@@ -193,8 +193,8 @@ class Ascender(): | |||
193 | break | 193 | break |
194 | 194 | ||
195 | # execute thing to run on item | 195 | # execute thing to run on item |
196 | label, listofrdatasets = labelrecords | 196 | name, listofrdatasets = labelrecords |
197 | subzones = label.split('.') | 197 | subzones = str(name).split('.') |
198 | domain = self.domain | 198 | domain = self.domain |
199 | 199 | ||
200 | if len(subzones) > 1: | 200 | if len(subzones) > 1: |
@@ -236,9 +236,9 @@ class Ascender(): | |||
236 | # modify value to fit gns syntax | 236 | # modify value to fit gns syntax |
237 | rdtype, value, label = \ | 237 | rdtype, value, label = \ |
238 | self.transform_to_gns_format(record, | 238 | self.transform_to_gns_format(record, |
239 | rdtype, | 239 | rdtype, |
240 | domain, | 240 | domain, |
241 | label) | 241 | label) |
242 | # skip record if value is none | 242 | # skip record if value is none |
243 | if value is None: | 243 | if value is None: |
244 | continue | 244 | continue |
@@ -270,20 +270,19 @@ class Ascender(): | |||
270 | taskqueue.task_done() | 270 | taskqueue.task_done() |
271 | # End of worker | 271 | # End of worker |
272 | 272 | ||
273 | |||
274 | |||
275 | self.create_zone_hierarchy() | 273 | self.create_zone_hierarchy() |
276 | 274 | ||
277 | |||
278 | # Create one thread | 275 | # Create one thread |
279 | thread = threading.Thread(target=worker) | 276 | thread = threading.Thread(target=worker) |
280 | thread.start() | 277 | thread.start() |
281 | 278 | ||
282 | # add records | 279 | # add records |
283 | for label, value in customrdataset.items(): | 280 | for name, rdatasets in self.zone.nodes.items(): |
284 | if value is None: | 281 | # log if the rdataset is empty for some reason |
282 | if not rdatasets: | ||
283 | logging.warning("Empty Rdataset!") | ||
285 | continue | 284 | continue |
286 | taskqueue.put((label, value)) | 285 | taskqueue.put((name, rdatasets)) |
287 | 286 | ||
288 | # Block until all tasks are done | 287 | # Block until all tasks are done |
289 | taskqueue.join() | 288 | taskqueue.join() |
@@ -381,7 +380,7 @@ class Ascender(): | |||
381 | else: | 380 | else: |
382 | value = "%s.%s" % (value, self.domain) | 381 | value = "%s.%s" % (value, self.domain) |
383 | elif rdtype == 'NS': | 382 | elif rdtype == 'NS': |
384 | if self.subzonedict(str(label) + "." + zonename): | 383 | if self.subzonedict.get(str(label) + "." + zonename): |
385 | return (None, None, None) | 384 | return (None, None, None) |
386 | nameserver = str(record.target) | 385 | nameserver = str(record.target) |
387 | if nameserver[-1] == ".": | 386 | if nameserver[-1] == ".": |
@@ -584,7 +583,6 @@ class Ascender(): | |||
584 | """ | 583 | """ |
585 | Creates the zone hierarchy in GNS for label | 584 | Creates the zone hierarchy in GNS for label |
586 | """ | 585 | """ |
587 | |||
588 | # Extend Dictionary using GNS identities that already exist, | 586 | # Extend Dictionary using GNS identities that already exist, |
589 | # checking for conflicts with information in DNS | 587 | # checking for conflicts with information in DNS |
590 | ids = sp.run([GNUNET_ZONE_CREATION_COMMAND, '-d'], stdout=sp.PIPE) | 588 | ids = sp.run([GNUNET_ZONE_CREATION_COMMAND, '-d'], stdout=sp.PIPE) |
@@ -593,25 +591,29 @@ class Ascender(): | |||
593 | altdomainlist = [e for e in domainlist if self.domain + " " in e] | 591 | altdomainlist = [e for e in domainlist if self.domain + " " in e] |
594 | for zone in altdomainlist: | 592 | for zone in altdomainlist: |
595 | zonename, _, pkey = zone.split(" ") | 593 | zonename, _, pkey = zone.split(" ") |
596 | if not self.subzonedict[zonename]: | 594 | if self.subzonedict.get(zonename) is None: |
597 | self.subzonedict[zonename] = (pkey, self.minimum) | 595 | self.subzonedict[zonename] = (pkey, self.minimum) |
598 | else: | 596 | else: |
597 | # FIXME Christian what was that? | ||
599 | pkey_ttl = self.subzonedict[zonename] | 598 | pkey_ttl = self.subzonedict[zonename] |
600 | self.subzonedict[zonename] = (pkey, self.minimum) | 599 | self.subzonedict[zonename] = (pkey, self.minimum) |
601 | 600 | ||
602 | # Create missing zones (and add to dict) for GNS zones that are NOT DNS zones | 601 | # Create missing zones (and add to dict) for GNS zones that are NOT DNS zones |
603 | # ("." is not a zone-cut in DNS, but always in GNS). | 602 | # ("." is not a zone-cut in DNS, but always in GNS). |
604 | for name in self.zone.nodes(): | 603 | for name in self.zone.nodes.keys(): |
605 | # FIXME: name not right! | 604 | subzones = str(name).split('.') |
606 | subzones = name.split('.') | 605 | # FIXME Christian: For some reason this fails spectacularly |
607 | for i in xrange(1,length(subzones)-1): | 606 | for i in range(1, len(subzones)-1): |
608 | subdomain = ".".join(subzones[i:]) | 607 | subdomain = ".".join(subzones[i:]) |
608 | # FIXME Christian this seems superfluous | ||
609 | zonename = "%s.%s" % (subdomain, self.domain) | 609 | zonename = "%s.%s" % (subdomain, self.domain) |
610 | ttl = self.minimum # new record, cannot use existing one, might want to use larger value | 610 | ttl = self.minimum # new record, cannot use existing one, might want to use larger value |
611 | if not self.subzonedict[zonename]: | 611 | if self.subzonedict.get(zonename) is None: |
612 | pkey = self.create_zone_and_get_pkey(zonename + "." + self.domain) | 612 | pkey = self.create_zone_and_get_pkey("%s.%s" % |
613 | (zonename, | ||
614 | self.domain)) | ||
613 | self.subzonedict[zonename] = (pkey, ttl) | 615 | self.subzonedict[zonename] = (pkey, ttl) |
614 | 616 | ||
615 | # Check if a delegated zone is available in GNS as per NS record | 617 | # Check if a delegated zone is available in GNS as per NS record |
616 | # Adds NS records that contain "gns--pkey--" to dictionary | 618 | # Adds NS records that contain "gns--pkey--" to dictionary |
617 | nsrecords = self.zone.iterate_rdatasets(dns.rdatatype.NS) | 619 | nsrecords = self.zone.iterate_rdatasets(dns.rdatatype.NS) |
@@ -630,13 +632,14 @@ class Ascender(): | |||
630 | if num_gnspkeys > 1: | 632 | if num_gnspkeys > 1: |
631 | logging.critical("Detected ambiguous PKEY records for label \ | 633 | logging.critical("Detected ambiguous PKEY records for label \ |
632 | %s (not generating PKEY record)", name) | 634 | %s (not generating PKEY record)", name) |
633 | continue | 635 | continue |
634 | gnspkey = str(gnspkeys[0]) | 636 | gnspkey = str(gnspkeys[0]) |
635 | 637 | ||
636 | # FIXME: test strlen(gnspkey) "right length", theoretically: Crockford base32 decoder... | 638 | # FIXME: test strlen(gnspkey) "right length", theoretically: |
637 | zone = name + "." + self.domain | 639 | # Crockford base32 decoder... -> base32-crockford looks promising |
638 | if not self.subzonedict[zone]: | 640 | zone = "%s.%s" % (name, self.domain) |
639 | self.subzonedict[zone] = (gnspkey[11:],ttl) | 641 | if not self.subzonedict.get(zone): |
642 | self.subzonedict[zone] = (gnspkey[11:], ttl) | ||
640 | else: | 643 | else: |
641 | # This should be impossible!!? | 644 | # This should be impossible!!? |
642 | pkey_ttl = self.subzonedict[zone] | 645 | pkey_ttl = self.subzonedict[zone] |
@@ -646,8 +649,7 @@ class Ascender(): | |||
646 | continue | 649 | continue |
647 | 650 | ||
648 | # Generate PKEY records for all entries in subzonedict | 651 | # Generate PKEY records for all entries in subzonedict |
649 | 652 | for zone, pkeyttltuple in self.subzonedict.items(): | |
650 | for zone, pkeyttltuple in self.subzonedict: | ||
651 | pkey, ttl = pkeyttltuple | 653 | pkey, ttl = pkeyttltuple |
652 | domain = ".".join(zone.split('.')[1::]) | 654 | domain = ".".join(zone.split('.')[1::]) |
653 | label = zone.split('.')[0] | 655 | label = zone.split('.')[0] |
diff --git a/ascension/test/gnunet.zone b/ascension/test/gnunet.zone index e44173a..a5697ec 100644 --- a/ascension/test/gnunet.zone +++ b/ascension/test/gnunet.zone | |||
@@ -6,9 +6,7 @@ $TTL 3600 | |||
6 | 604800 ; Expire | 6 | 604800 ; Expire |
7 | 3600 ) ; Negative Cache TTL | 7 | 3600 ) ; Negative Cache TTL |
8 | @ IN NS ns1.gnunet.gnu. | 8 | @ IN NS ns1.gnunet.gnu. |
9 | @ IN NS gns--pkey--7h4hfww26fmdamt243dhssens2w5qevphbm9bhv54sz3cz1053ng.gnunet.gnu. | ||
10 | @ IN A 127.0.0.1 | 9 | @ IN A 127.0.0.1 |
11 | gns--pkey--7h4hfww26fmdamt243dhssens2w5qevphbm9bhv54sz3cz1053ng IN A 0.0.0.0 | ||
12 | foo IN AAAA 2002:: | 10 | foo IN AAAA 2002:: |
13 | asdf IN CNAME www | 11 | asdf IN CNAME www |
14 | $TTL 300 | 12 | $TTL 300 |