Skip to content

Commit

Permalink
Use IPv6 on CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jul 16, 2024
1 parent 4efe3f4 commit 6761f6d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
50 changes: 25 additions & 25 deletions lib/async/dns/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,117 +14,117 @@ module Async::DNS
module System
RESOLV_CONF = "/etc/resolv.conf"
HOSTS = "/etc/hosts"

def self.hosts_path
if RUBY_PLATFORM =~ /mswin32|mingw|bccwin/
Win32::Resolv.get_hosts_path
else
HOSTS
end
end

# This code is very experimental
class Hosts
def initialize
@addresses = {}
@names = {}
end

attr :addresses
attr :names

# This is used to match names against the list of known hosts:
def call(name)
@names.include?(name)
end

def lookup(name)
addresses = @names[name]

if addresses
addresses.last
else
nil
end
end

alias [] lookup

def add(address, names)
@addresses[address] ||= []
@addresses[address] += names

names.each do |name|
@names[name] ||= []
@names[name] << address
end
end

def parse_hosts(io)
io.each do |line|
line.sub!(/#.*/, '')
address, hostname, *aliases = line.split(/\s+/)

add(address, [hostname] + aliases)
end
end

def self.local
hosts = self.new

path = System::hosts_path

if path and File.exist?(path)
File.open(path) do |file|
hosts.parse_hosts(file)
end
end

return hosts
end
end

def self.parse_resolv_configuration(path)
nameservers = []
File.open(path) do |file|
file.each do |line|
# Remove any comments:
line.sub!(/[#;].*/, '')

# Extract resolv.conf command:
keyword, *args = line.split(/\s+/)

case keyword
when 'nameserver'
nameservers += args
end
end
end

return nameservers
end

def self.standard_connections(nameservers, **options)
connections = []

nameservers.each do |host|
connections << IO::Endpoint.udp(host, 53, **options)
connections << IO::Endpoint.tcp(host, 53, **options)
end

return IO::Endpoint.composite(connections)
end

# Get a list of standard nameserver connections which can be used for querying any standard servers that the system has been configured with. There is no equivalent facility to use the `hosts` file at present.
def self.nameservers(**options)
nameservers = []

if File.exist? RESOLV_CONF
nameservers = parse_resolv_configuration(RESOLV_CONF)
elsif defined?(Win32::Resolv) and RUBY_PLATFORM =~ /mswin32|cygwin|mingw|bccwin/
search, nameservers = Win32::Resolv.get_resolv_info
end

return standard_connections(nameservers, **options)
end

Expand Down
4 changes: 2 additions & 2 deletions test/async/dns/resolver/consistency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ def before
resolver = Async::DNS::Resolver.new

resolved_a = DOMAINS.to_h do |domain|
[domain, resolver.addresses_for(domain)]
[domain, resolver.addresses_for(domain).map(&:to_s)]
end
end

resolv_dns_performance = Benchmark.measure do
resolver = Resolv::DNS.new
resolver = Resolv.new(use_ipv6: true)

resolved_b = DOMAINS.to_h do |domain|
[domain, resolver.getaddresses(domain)]
Expand Down

0 comments on commit 6761f6d

Please sign in to comment.