Class: Ddig::Ddr::DesignatedResolver
- Inherits:
-
Object
- Object
- Ddig::Ddr::DesignatedResolver
- Defined in:
- lib/ddig/ddr/designated_resolver.rb
Constant Summary collapse
- PROTOCOLS =
['http/1.1', 'h2', 'h3', 'dot', 'doq']
Instance Attribute Summary collapse
-
#a ⇒ Object
readonly
Returns the value of attribute a.
-
#aaaa ⇒ Object
readonly
Returns the value of attribute aaaa.
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#dohpath ⇒ Object
readonly
Returns the value of attribute dohpath.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
-
#resolver ⇒ Object
readonly
Returns the value of attribute resolver.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#unencrypted_resolver ⇒ Object
readonly
Returns the value of attribute unencrypted_resolver.
-
#verify_cert ⇒ Object
readonly
Returns the value of attribute verify_cert.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(unencrypted_resolver:, target:, protocol: nil, port: nil, dohpath: nil, address: nil, ip: nil) ⇒ DesignatedResolver
constructor
A new instance of DesignatedResolver.
- #lookup(hostname) ⇒ Object
-
#set_default_port ⇒ Object
Set default port by protocol ref: www.rfc-editor.org/rfc/rfc9461.html#section-4.2.
- #to_cli ⇒ Object
- #to_json(*args) ⇒ Object
- #to_s ⇒ Object
- #uniq_key ⇒ Object
- #verify ⇒ Object
Constructor Details
#initialize(unencrypted_resolver:, target:, protocol: nil, port: nil, dohpath: nil, address: nil, ip: nil) ⇒ DesignatedResolver
Returns a new instance of DesignatedResolver.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 12 def initialize(unencrypted_resolver:, target:, protocol: nil, port: nil, dohpath: nil, address: nil, ip: nil) @target = target @unencrypted_resolver = unencrypted_resolver @protocol = protocol @port = port @dohpath = dohpath @address = address @ip = ip # check protocol unless PROTOCOLS.include?(@protocol) raise Error.new("Not Supportted Protocol (protocol: #{@protocol}). Suported protocol is #{PROTOCOLS.join(' / ')}") end if @port.nil? set_default_port end end |
Instance Attribute Details
#a ⇒ Object (readonly)
Returns the value of attribute a.
8 9 10 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 8 def a @a end |
#aaaa ⇒ Object (readonly)
Returns the value of attribute aaaa.
8 9 10 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 8 def aaaa @aaaa end |
#address ⇒ Object (readonly)
Returns the value of attribute address.
6 7 8 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 6 def address @address end |
#dohpath ⇒ Object (readonly)
Returns the value of attribute dohpath.
6 7 8 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 6 def dohpath @dohpath end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 8 def errors @errors end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
8 9 10 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 8 def hostname @hostname end |
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
6 7 8 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 6 def ip @ip end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
6 7 8 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 6 def port @port end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
6 7 8 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 6 def protocol @protocol end |
#resolver ⇒ Object (readonly)
Returns the value of attribute resolver.
8 9 10 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 8 def resolver @resolver end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
6 7 8 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 6 def target @target end |
#unencrypted_resolver ⇒ Object (readonly)
Returns the value of attribute unencrypted_resolver.
6 7 8 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 6 def unencrypted_resolver @unencrypted_resolver end |
#verify_cert ⇒ Object (readonly)
Returns the value of attribute verify_cert.
7 8 9 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 7 def verify_cert @verify_cert end |
Instance Method Details
#as_json ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 66 def as_json(*) { unencrypted_resolver: @unencrypted_resolver, target: @target, protocol: @protocol, port: @port, dohpath: @dohpath, address: @address, ip: @ip, verify: @verify_cert&.verify, hostname: @hostname, a: @a, aaaa: @aaaa, errors: @errors, } end |
#lookup(hostname) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 36 def lookup(hostname) @hostname = hostname @errors = [] case @protocol when 'dot' @resolver = Ddig::Resolver::Dot.new(hostname: @hostname, server: @address, server_name: @target, port: @port).lookup unless @resolver.nil? @a = @resolver.a @aaaa = @resolver.aaaa return self end when 'http/1.1', 'h2', 'h3' @resolver = Ddig::Resolver::DohH1.new(hostname: @hostname, server: @address, address: @address, dohpath: @dohpath, port: @port).lookup unless @resolver.nil? @a = @resolver.a @aaaa = @resolver.aaaa return self end when 'doq' @errors << "#{@protocol} is not supportted protocol" end end |
#set_default_port ⇒ Object
Set default port by protocol ref: www.rfc-editor.org/rfc/rfc9461.html#section-4.2
101 102 103 104 105 106 107 108 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 101 def set_default_port case @protocol when 'http/1.1', 'h2', 'h3' @port = 443 when 'dot', 'doq' @port = 853 end end |
#to_cli ⇒ Object
87 88 89 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 87 def to_cli @resolver.to_cli end |
#to_json(*args) ⇒ Object
83 84 85 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 83 def to_json(*args) as_json.to_json end |
#to_s ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 91 def to_s if ['http/1.1', 'h2', 'h3'].include?(@protocol) "#{@protocol}: #{@target}:#{@port} (#{@address}),\tpath: #{@dohpath},\tunencrypted_resolver: #{@unencrypted_resolver}, \tverify cert: #{@verify_cert.verify}" else "#{@protocol}: #{@target}:#{@port} (#{@address}),\tunencrypted_resolver: #{@unencrypted_resolver}, \tverify cert: #{@verify_cert.verify}" end end |
#uniq_key ⇒ Object
110 111 112 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 110 def uniq_key "#{@unencrypted_resolver}-#{@target}-#{@protocol}-#{@port}-#{@dohpath}-#{@address}-#{@ip}" end |
#verify ⇒ Object
31 32 33 34 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 31 def verify @verify_cert = VerifyCert.new(hostname: @target, address: @address, port: @port, unencrypted_resolver: @unencrypted_resolver) @verify_cert.verify end |