Class: Celluloid::DNS::GenericHandler

Inherits:
Object
  • Object
show all
Includes:
IO
Defined in:
lib/celluloid/dns/handler.rb

Direct Known Subclasses

TCPSocketHandler, UDPSocketHandler

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ GenericHandler

Returns a new instance of GenericHandler.



27
28
29
30
31
32
# File 'lib/celluloid/dns/handler.rb', line 27

def initialize(server)
	@server = server
	@logger = @server.logger || Celluloid.logger
	
	@connections = Celluloid::Condition.new
end

Instance Method Details

#error_response(query = nil, code = Resolv::DNS::RCode::ServFail) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/celluloid/dns/handler.rb', line 49

def error_response(query = nil, code = Resolv::DNS::RCode::ServFail)
	# Encoding may fail, so we need to handle this particular case:
	server_failure = Resolv::DNS::Message::new(query ? query.id : 0)
	
	server_failure.qr = 1
	server_failure.opcode = query ? query.opcode : 0
	server_failure.aa = 1
	server_failure.rd = 0
	server_failure.ra = 0

	server_failure.rcode = code

	# We can't do anything at this point...
	return server_failure
end

#process_query(data, options) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/celluloid/dns/handler.rb', line 65

def process_query(data, options)
	@logger.debug "<> Receiving incoming query (#{data.bytesize} bytes) to #{self.class.name}..."
	query = nil

	begin
		query = Celluloid::DNS::decode_message(data)
		
		return @server.process_query(query, options)
	rescue StandardError => error
		@logger.error "<> Error processing request: #{error.inspect}!"
		Celluloid::DNS::log_exception(@logger, error)
		
		return error_response(query)
	end
end

#stopObject



34
35
36
37
38
# File 'lib/celluloid/dns/handler.rb', line 34

def stop
	shutdown
	
	@connections.wait
end