Skip to content

Commit 26a777c

Browse files
committed
Updated README with notes for migrating from 0.4.0 to 0.5.0
1 parent b5dcdc5 commit 26a777c

File tree

1 file changed

+60
-7
lines changed

1 file changed

+60
-7
lines changed

README.md

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
RubyDNS
22
=======
33

4-
* Author: Samuel G. D. Williams (<http://www.oriontransfer.co.nz>)
5-
* Copyright (C) 2009, 2011 Samuel G. D. Williams.
64
* Released under the MIT license.
5+
* Copyright (C) 2009, 2011 [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams/).
76
* [![Build Status](https://secure.travis-ci.org/ioquatix/rubydns.png)](http://travis-ci.org/ioquatix/rubydns)
87

98
RubyDNS is a simple programmatic DSL (domain specific language) for configuring and running a DNS server. RubyDNS provides a daemon that runs a DNS server which can process DNS requests depending on specific policy. Rule selection is based on pattern matching, and results can be hard-coded, computed, fetched from a remote DNS server, fetched from a local cache, etc.
@@ -63,8 +62,6 @@ After starting this server you can test it using dig:
6362
Compatibility
6463
-------------
6564

66-
From RubyDNS version `0.4.0`, the recommended minimum Ruby version is `1.9.3` for complete support. Some features may not work as expected on Ruby version `1.8.x` and it is not tested significantly.
67-
6865
### Migrating from RubyDNS 0.3.x to 0.4.x ###
6966

7067
Due to changes in `resolv.rb`, superficial parts of RubyDNS have changed. Rather than using `:A` to specify A-records, one must now use the class name.
@@ -76,12 +73,68 @@ becomes
7673
IN = Resolv::DNS::Resource::IN
7774
match(..., IN::A)
7875

76+
### Migrating from RubyDNS 0.4.x to 0.5.x ###
77+
78+
The system standard resolver was synchronous, and this could stall the server when making upstream requests to other DNS servers. A new resolver `RubyDNS::Resolver` now provides an asynchronous interface and the `Transaction::passthrough` makes exclusive use of this to provide high performance asynchonous resolution.
79+
80+
Here is a basic example of how to use the new resolver in full. It is important to provide both `:udp` and `:tcp` connection specifications, so that large requests will be handled correctly:
81+
82+
resolver = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
83+
84+
EventMachine::run do
85+
resolver.query('google.com', IN::A) do |response|
86+
case response
87+
when RubyDNS::Message
88+
puts "Got response: #{response.answers.first}"
89+
else
90+
# Response is of class RubyDNS::ResolutionFailure
91+
puts "Failed: #{response.message}"
92+
end
93+
94+
EventMachine::stop
95+
end
96+
end
97+
98+
Existing code that uses `Resolv::DNS` as a resolver will need to be updated:
99+
100+
# 1/ Add this at the top of your file; Host specific system information:
101+
require 'rubydns/system'
102+
103+
# 2/ Change from R = Resolv::DNS.new to:
104+
R = RubyDNS::Resolver.new(RubyDNS::System::nameservers)
105+
106+
Everything else in the server can remain the same. You can see a complete example in `test/test_resolver.rb`.
107+
108+
#### Deferred Transactions ####
109+
110+
The implementation of the above depends on a new feature which was added in 0.5.0:
111+
112+
transaction.defer!
113+
114+
Once you call this, the transaction won't complete until you call either `transaction.succeed` or `transaction.fail`.
115+
116+
RubyDNS::run_server(:listen => SERVER_PORTS) do
117+
match(/\.*.com/, IN::A) do |match, transaction|
118+
transaction.defer!
119+
120+
# No domain exists, after 5 seconds:
121+
EventMachine::Timer.new(5) do
122+
transaction.failure!(:NXDomain)
123+
end
124+
end
125+
126+
otherwise do
127+
transaction.failure!(:NXDomain)
128+
end
129+
end
130+
131+
You can see a complete example in `test/test_slow_server.rb`.
132+
79133
Todo
80134
----
81135

82-
* Support for more features of DNS such as zone transfer
83-
* Support reverse records more easily
84-
* Better support for deferred requests/concurrency.
136+
* Support for more features of DNS such as zone transfer.
137+
* Support reverse records more easily.
85138

86139
License
87140
-------

0 commit comments

Comments
 (0)