Module: DNS::ResolveHost::Controls::Server
- Defined in:
- lib/dns/resolve_host/controls/server.rb
Defined Under Namespace
Modules: BindAddress, Port Classes: Log
Class Method Summary collapse
Class Method Details
.start(hostname: nil, ip_addresses: nil, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dns/resolve_host/controls/server.rb', line 5 def self.start(hostname: nil, ip_addresses: nil, &block) hostname ||= Hostname.example ip_addresses ||= [IPAddress.example] bind_address = BindAddress.example port = Port.example interfaces = [[:udp, bind_address, port], [:tcp, bind_address, port]] Celluloid.logger = Log.get self dns_server = RubyDNS.run_server :listen => interfaces, :asynchronous => true do match %r{\A#{Regexp.escape hostname}\z} do |request| ip_addresses.each do |ip_address| request.respond! ip_address end end end nameserver = Nameserver.new bind_address, port block.(nameserver) # The rubydns library does not properly unbind its server socket when # the actor terminates. See the following github issue: # # https://github.com/ioquatix/rubydns/issues/60 # # The workaround discovered by the person who filed the issue is # pasted here. The proper way to stop the DNS server would be this: # # dns_server.terminate # # [Nathan Ladd, Fri 30 Dec 2016] dns_server.actors.first.links.each(&:terminate) end |