Skip to content

Commit

Permalink
codefix: Cleanup DNSResolver code
Browse files Browse the repository at this point in the history
Signed-off-by: Usman Saleem <[email protected]>
  • Loading branch information
usmansaleem committed Jun 8, 2024
1 parent a439163 commit b62aefd
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public long sequence() {
private void visitTree(final ENRTreeLink link, final DNSVisitor visitor) {
Optional<DNSEntry> optionalEntry = resolveRecord(link.domainName());
if (optionalEntry.isEmpty()) {
LOG.debug("No DNS record found for {}", link.domainName());
LOG.trace("No DNS record found for {}", link.domainName());
return;
}

Expand Down Expand Up @@ -142,19 +142,16 @@ private boolean internalVisit(
final String entryName, final String domainName, final DNSVisitor visitor) {
final Optional<DNSEntry> optionalDNSEntry = resolveRecord(entryName + "." + domainName);
if (optionalDNSEntry.isEmpty()) {
LOG.debug("No DNS record found for {}", entryName + "." + domainName);
return true;
}

final DNSEntry entry = optionalDNSEntry.get();
switch (entry) {
case ENRNode node -> {
// TODO: this always return true because the visitor is reference to list.add
return visitor.visit(node.nodeRecord());
}
case DNSEntry.ENRTree tree -> {
for (String e : tree.entries()) {
// TODO: When would this ever return false?
boolean keepGoing = internalVisit(e, domainName, visitor);
if (!keepGoing) {
return false;
Expand All @@ -168,7 +165,7 @@ private boolean internalVisit(
}

/**
* Resolves one DNS record associated with the given domain name.
* Maps TXT DNS record to DNSEntry.
*
* @param domainName the domain name to query
* @return the DNS entry read from the domain. Empty if no record is found.
Expand Down Expand Up @@ -197,7 +194,7 @@ Optional<String> resolveRawRecord(final String domainName) {

private boolean checkSignature(
final ENRTreeRoot root, final SECP256K1.PublicKey pubKey, final SECP256K1.Signature sig) {
Bytes32 hash =
final Bytes32 hash =
Hash.keccak256(Bytes.wrap(root.signedContent().getBytes(StandardCharsets.UTF_8)));
return SECP256K1.verifyHashed(hash, sig, pubKey);
}
Expand Down

0 comments on commit b62aefd

Please sign in to comment.