Commit 910e19bc authored by Petr Špaček's avatar Petr Špaček

genednscomp: optimization

This algorithm works better on large zones and produces the same result.
parent 4d98dd5b
Pipeline #41244 passed with stage
in 1 minute and 24 seconds
......@@ -10,26 +10,28 @@ import dns.name
import dataapi
def get_ns_name_from_ip(ipaddr: str, nsname2ipset: Dict[dns.name.Name, Set[str]]):
def gen_ip_to_nsname(nsname2ipset: Dict[dns.name.Name, Set[str]]) -> Dict[str, dns.name.Name]:
"""
It should never happen that ipaddr is not present in nsname2ipset mapping.
If it happens, it is most likely caused by mixing data files from
two versions of DNS zone. Start from scratch!
Generate reverse mappping IP -> NS name.
"""
for name, ipset in nsname2ipset.items():
if ipaddr in ipset:
return name
raise ValueError('IP addr {} not found in nsname2ipset'.format(ipaddr))
ip2nsname = {}
for nsname, ipset in nsname2ipset.items():
ip2nsname.update({ip: nsname for ip in ipset})
return ip2nsname
def generate(nsname2ipset, domain2ipset):
"""Output format is: zone nsname NSipAddress"""
ip_done = set()
ip2nsname = gen_ip_to_nsname(nsname2ipset)
for domain, ipset in domain2ipset.items():
for ipaddr in ipset:
if ipaddr in ip_done:
continue
nsname = get_ns_name_from_ip(ipaddr, nsname2ipset)
# It should never happen that ipaddr is not present in nsname2ipset mapping.
# If it happens, it is most likely caused by mixing data files from
# two versions of DNS zone. Start from scratch!
nsname = ip2nsname[ipaddr]
yield '{} {} {}\n'.format(domain, nsname, ipaddr)
ip_done.add(ipaddr)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment