Class: Nesser::Transaction
- Inherits:
-
Object
- Object
- Nesser::Transaction
- Defined in:
- lib/nesser/transaction.rb
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
Returns the value of attribute response.
-
#sent ⇒ Object
readonly
Returns the value of attribute sent.
Instance Method Summary collapse
- #answer!(answers = []) ⇒ Object
- #error!(rcode) ⇒ Object
-
#initialize(s:, request:, host:, port:) ⇒ Transaction
constructor
A new instance of Transaction.
- #open? ⇒ Boolean
- #passthrough!(host: '8.8.8.8', port: 53) ⇒ Object
- #reply! ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(s:, request:, host:, port:) ⇒ Transaction
Returns a new instance of Transaction.
37 38 39 40 41 42 43 44 45 |
# File 'lib/nesser/transaction.rb', line 37 def initialize(s:, request:, host:, port:) @s = s @request = request @host = host @port = port @sent = false @response = request.answer() end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
29 30 31 |
# File 'lib/nesser/transaction.rb', line 29 def request @request end |
#response ⇒ Object
Returns the value of attribute response.
30 31 32 |
# File 'lib/nesser/transaction.rb', line 30 def response @response end |
#sent ⇒ Object (readonly)
Returns the value of attribute sent.
29 30 31 |
# File 'lib/nesser/transaction.rb', line 29 def sent @sent end |
Instance Method Details
#answer!(answers = []) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/nesser/transaction.rb', line 70 def answer!(answers=[]) answers.each do |answer| @response.add_answer(answer) end reply!() end |
#error!(rcode) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/nesser/transaction.rb', line 86 def error!(rcode) not_sent!() @response.rcode = rcode reply!() end |
#open? ⇒ Boolean
59 60 61 |
# File 'lib/nesser/transaction.rb', line 59 def open?() return !@sent end |
#passthrough!(host: '8.8.8.8', port: 53) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/nesser/transaction.rb', line 102 def passthrough!(host:'8.8.8.8', port:53) not_sent!() # Get a local handle to the socket s = @s Thread.new() do begin response = Nesser.query( s: s, hostname: @request.questions[0].name, server: host, port: port, type: @request.questions[0].type, cls: @request.questions[0].cls, ) if response.rcode != RCODE_SUCCESS error!(response.rcode) else answer!(response.answers) end rescue StandardError error!(RCODE_SERVER_FAILURE) end end end |
#reply! ⇒ Object
139 140 141 142 143 144 |
# File 'lib/nesser/transaction.rb', line 139 def reply!() not_sent!() @s.send(@response.to_bytes(), 0, @host, @port) @sent = true end |
#to_s ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/nesser/transaction.rb', line 147 def to_s() result = [] result << '== Nesser (DNS) Transaction ==' result << '-- Request --' result << @request.to_s() if !sent() result << '-- Response [not sent yet] --' else result << '-- Response [sent] --' end result << @response.to_s() result << '' return result.join("\n") end |