Class: Dnsruby::ValidatorThread
- Inherits:
-
Object
- Object
- Dnsruby::ValidatorThread
- Defined in:
- lib/Dnsruby/validator_thread.rb
Overview
Takes care of the validation for the SelectThread. If queries need to be made in order to validate the response, then a separate thread is fired up to do this.
Class Method Summary collapse
Instance Method Summary collapse
- #cache_if_valid(query, response) ⇒ Object
-
#do_validate ⇒ Object
def add_to_queue(item) print “ADding to validator queuen” @@mutex.synchronize{ @@validation_queue.push(item) } end.
-
#initialize(*args) ⇒ ValidatorThread
constructor
include Singleton.
-
#run ⇒ Object
Create the validation thread, and a queue to receive validation requests Actually, need to have a thread per validator, as they make recursive calls.
- #should_validate ⇒ Object
- #validate(query, response, res) ⇒ Object
Constructor Details
#initialize(*args) ⇒ ValidatorThread
include Singleton
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/Dnsruby/validator_thread.rb', line 7 def initialize(*args) @client_id, @client_queue, @response, @err, @query, @st, @res = args # Create the validation thread, and a queue to receive validation requests # Actually, need to have a thread per validator, as they make recursive calls. # @@mutex = Mutex.new # @@validation_queue = Queue.new # @@validator_thread = Thread.new{ # do_validate # } end |
Class Method Details
.requires_validation?(query, response, error, res) ⇒ Boolean
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/Dnsruby/validator_thread.rb', line 68 def ValidatorThread.requires_validation?(query, response, error, res) # @error will be nil for DNS RCODE errors - it will be true for TsigError. really?! if ((!error || (error.instance_of?NXDomain)) && query.do_validation) if (res.dnssec) if (response.security_level != Message::SecurityLevel::SECURE) return true end end end return false end |
Instance Method Details
#cache_if_valid(query, response) ⇒ Object
103 104 105 106 |
# File 'lib/Dnsruby/validator_thread.rb', line 103 def cache_if_valid(query, response) return if @error PacketSender.cache(query, response) end |
#do_validate ⇒ Object
def add_to_queue(item)
print "ADding to validator queue\n"
@@mutex.synchronize{
@@validation_queue.push(item)
}
end
35 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 |
# File 'lib/Dnsruby/validator_thread.rb', line 35 def do_validate # while (true) # item = nil # print "Waiting to pop validation item\n" ## @@mutex.synchronize{ # item = @@validation_queue.pop ## } # print "Popped validation request\n" # client_id, client_queue, response, err, query, st, res = item validated_ok = validate(@query, @response, @res) validated_ok = false if @error cache_if_valid(@query, @response) # Now send the response back to the client... # print "#{Time.now} : Got result for #{@query.question()[0].qname}, #{@query.question()[0].qtype}\n" if (validated_ok) @st.push_validation_response_to_select(@client_id, @client_queue, @response, nil, @query, @res) else @st.push_validation_response_to_select(@client_id, @client_queue, @response, @response.security_error, @query, @res) end # end end |
#run ⇒ Object
Create the validation thread, and a queue to receive validation requests Actually, need to have a thread per validator, as they make recursive calls.
@@mutex = Mutex.new
@@validation_queue = Queue.new
@@validator_thread = Thread.new{
do_validate
}
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/Dnsruby/validator_thread.rb', line 17 def run # ONLY START THE NEW THREAD IF VALIDATION NEED OCCUR!! if (should_validate) Thread.new{ do_validate } else do_validate end end |
#should_validate ⇒ Object
64 65 66 |
# File 'lib/Dnsruby/validator_thread.rb', line 64 def should_validate return ValidatorThread.requires_validation?(@query, @response, @error, @res) end |
#validate(query, response, res) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/Dnsruby/validator_thread.rb', line 81 def validate(query, response, res) if (should_validate) begin # So, we really need to be able to take the response out of the select thread, along # with the responsibility for sending the answer to the client. # Should we have a validator thread? Or a thread per validation? # Then, select thread gets response. It performs basic checks here. # After basic checks, the select-thread punts the response (along with queues, etc.) # to the validator thread. # The validator validates it (or just releases it with no validation), and then # sends the request to the client via the client queue. Dnssec.validate_with_query(query,response) return true rescue VerifyError => e response.security_error = e # Response security_level should already be set return false end end return true end |