Skip to content

Commit

Permalink
make nameservers configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
mackuba committed Mar 12, 2024
1 parent 0cd4c01 commit 2f83ee1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/didkit/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module DIDKit
class Resolver
RESERVED_DOMAINS = %w(alt arpa example internal invalid local localhost onion test)

attr_accessor :nameserver

def resolve_handle(handle)
domain = handle.gsub(/^@/, '')

Expand All @@ -25,7 +27,9 @@ def resolve_handle(handle)
end

def resolve_handle_by_dns(domain)
dns_records = Resolv::DNS.open { |d| d.getresources("_atproto.#{domain}", Resolv::DNS::Resource::IN::TXT) }
dns_records = Resolv::DNS.open(resolv_options) { |d|
d.getresources("_atproto.#{domain}", Resolv::DNS::Resource::IN::TXT)
}

if record = dns_records.first
if string = record.strings.first
Expand Down Expand Up @@ -55,6 +59,12 @@ def resolve_handle_by_well_known(domain)
nil
end

def resolv_options
options = Resolv::DNS::Config.default_config_hash.dup
options[:nameserver] = nameserver if nameserver
options
end

def parse_did_from_dns(txt)
txt =~ /\Adid\=(did\:\w+\:.*)\z/ ? $1 : nil
end
Expand Down

0 comments on commit 2f83ee1

Please sign in to comment.