32
33
34
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/srv/murakumo_server.rb', line 32
def run
EventMachine.epoll
RubyDNS.run_server(:listen => [[:udp, @@options[:dns_address], @@options[:dns_port]]]) do
@logger = @@options[:logger] if @@options[:logger]
on(:start) do
if @@options[:socket]
FileUtils.rm_f(@@options[:socket])
DRb.start_service("drbunix:#{@@options[:socket]}", @@cloud)
File.chmod(0700, @@options[:socket])
at_exit { FileUtils.rm_f(@@options[:socket]) }
end
if @@options[:logger]
trap(:HUP) do
if logger = @@options[:logger]
logdev = logger.instance_variable_get(:@logdev)
if (dev = logdev.dev).kind_of?(File)
path = dev.path
mutex = logdev.instance_variable_get(:@mutex)
mutex.synchronize do
dev.reopen(path, 'a')
dev.sync = true
end
end
end
end
end
@@cloud.start
end
match(@@cloud.method(:address_exist?), IN::A) do |transaction|
records = @@cloud.lookup_addresses(transaction.name)
addrs = []
min_ttl = nil
records.each do |r|
address, ttl = r
if min_ttl.nil? or ttl < min_ttl
min_ttl = ttl
end
addrs << Resolv::DNS::Resource::IN::A.new(address)
end
addrs << {:ttl => min_ttl}
transaction.append!(*addrs)
end
match(@@cloud.method(:name_exist?), IN::PTR) do |transaction|
name, ttl = @@cloud.lookup_name(transaction.name)
name += ".#{@@options[:domain]}" if @@options[:domain]
transaction.respond!(Resolv::DNS::Name.create("#{name}."), :ttl => ttl)
end
if @@options[:resolver]
otherwise do |transaction|
transaction.passthrough!(@@options[:resolver])
end
end
end end
|