Class: DoHClient::Server
- Inherits:
-
Async::DNS::Server
- Object
- Async::DNS::Server
- DoHClient::Server
- Defined in:
- lib/doh_client/server.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#initialize(endpoints, resolver = DoHClient::Client::Google) ⇒ Server
constructor
A new instance of Server.
- #process(name, resource_class, transaction) ⇒ Object
Constructor Details
#initialize(endpoints, resolver = DoHClient::Client::Google) ⇒ Server
Returns a new instance of Server.
8 9 10 11 |
# File 'lib/doh_client/server.rb', line 8 def initialize(endpoints, resolver = DoHClient::Client::Google) super(endpoints) @client = resolver end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/doh_client/server.rb', line 7 def client @client end |
Instance Method Details
#process(name, resource_class, transaction) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/doh_client/server.rb', line 13 def process(name, resource_class, transaction) type = resource_class.to_s.split('::').last begin response = client.resolve(name, type: type) rescue ResponseError => _ return transaction.fail!(:NXDomain) unless answers end answers = response["Answer"] return transaction.fail!(:NXDomain) unless answers transaction.append_question! answers.each do |answer| next unless klass = Resolv::DNS::Resource.get_class(answer["type"], resource_class::ClassValue) resource = klass < Resolv::DNS::Resource::DomainName ? klass.new(Resolv::DNS::Name.create(answer["data"])) : klass.new(answer["data"]) transaction.response.add_answer(answer["name"], answer["TTL"], resource) end end |