Skip to content

Commit

Permalink
Namecoin: Add support for DS DNS records
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyRand committed Dec 12, 2019
1 parent 602d0aa commit b555866
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
24 changes: 24 additions & 0 deletions electrum_nmc/electrum/gui/qt/configure_dns_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def __init__(self, value, parent):

self.ui.btnACreate.clicked.connect(self.create_address_record)
self.ui.btnCNAMECreate.clicked.connect(self.create_cname_record)
self.ui.btnDSCreate.clicked.connect(self.create_ds_record)
self.ui.btnTXTCreate.clicked.connect(self.create_txt_record)

self.ui.dialogButtons.accepted.connect(self.accept)
Expand Down Expand Up @@ -164,6 +165,26 @@ def create_cname_record(self):

self.insert_record(idx, record)

def create_ds_record(self):
model = self.ui.listDNSRecords.model()
idx = model.rowCount()

domain = self.get_selected_domain()
try:
data = [
int(self.ui.editDSKeyTag.text()),
int(self.ui.editDSAlgorithm.text()),
int(self.ui.editDSHashType.text()),
self.ui.editDSHash.text(),
]
except ValueError:
self.show_error(_("The Keytag, Algorithm, and Hashtype must be integers."))
return

record = [domain, "ds", data]

self.insert_record(idx, record)

def create_txt_record(self):
model = self.ui.listDNSRecords.model()
idx = model.rowCount()
Expand Down Expand Up @@ -226,6 +247,9 @@ def insert_record(self, idx, record):
elif record_type == "cname":
formatted_record_type = "CNAME"
formatted_data = data
elif record_type == "ds":
formatted_record_type = "DS"
formatted_data = json.dumps(data)
elif record_type == "txt":
formatted_record_type = "TXT"
formatted_data = json.dumps(data)
Expand Down
48 changes: 48 additions & 0 deletions electrum_nmc/electrum/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,12 @@ def get_domain_records(domain, value):
if value["alias"] == None:
del value["alias"]

if "ds" in value:
new_records, value["ds"] = get_domain_records_ds(domain, value["ds"])
records.extend(new_records)
if value["ds"] == []:
del value["ds"]

if "txt" in value:
new_records, value["txt"] = get_domain_records_txt(domain, value["txt"])
records.extend(new_records)
Expand Down Expand Up @@ -686,6 +692,38 @@ def get_domain_records_cname(domain, value):

return records, remaining

def get_domain_records_ds(domain, value):
# Must be array
if type(value) != list:
return [], value

# Parse each array item
records = []
remaining = []
for raw_address in value:
single_record, single_remaining = get_domain_records_ds_single(domain, raw_address)
if single_record is not None:
records.append(single_record)
if single_remaining is not None:
remaining.append(single_remaining)

return records, remaining

def get_domain_records_ds_single(domain, value):
# Must be array
if type(value) != list:
return None, value

# Must be length 4
if len(value) != 4:
return None, value

# Check value types
if type(value[0]) != int or type(value[1]) != int or type(value[2]) != int or type(value[3]) != str:
return None, value

return [domain, "ds", value], None

def get_domain_records_txt(domain, value):
# Process Tor specially
if domain.startswith("_tor."):
Expand Down Expand Up @@ -782,6 +820,8 @@ def add_domain_record(base_domain, value, record):
add_domain_record_address(subdomain_value, data)
elif record_type == "cname":
add_domain_record_cname(subdomain_value, data)
elif record_type == "ds":
add_domain_record_ds(subdomain_value, data)
elif record_type == "txt":
add_domain_record_txt(subdomain_value, data)

Expand Down Expand Up @@ -863,6 +903,14 @@ def add_domain_record_cname(value, data):
# Add the record
value["alias"] = data

def add_domain_record_ds(value, data):
# Make sure the field exists
if "ds" not in value:
value["ds"] = []

# Add the record
value["ds"].append(data)

def add_domain_record_txt(value, data):
# Make sure the field exists
if "txt" not in value:
Expand Down

0 comments on commit b555866

Please sign in to comment.