rubydns 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -1
- data/README.md +78 -68
- data/lib/rubydns/resolver.rb +1 -1
- data/lib/rubydns/version.rb +1 -1
- metadata +8 -2
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -27,103 +27,113 @@ Or install it yourself as:
|
|
27
27
|
## Usage
|
28
28
|
|
29
29
|
This is copied from `test/examples/test-dns-2.rb`. It has been simplified slightly.
|
30
|
-
|
31
|
-
|
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
|
-
|
30
|
+
```ruby
|
31
|
+
#!/usr/bin/env ruby
|
32
|
+
require 'rubydns'
|
33
|
+
|
34
|
+
INTERFACES = [
|
35
|
+
[:udp, "0.0.0.0", 53],
|
36
|
+
[:tcp, "0.0.0.0", 53]
|
37
|
+
]
|
38
|
+
Name = Resolv::DNS::Name
|
39
|
+
IN = Resolv::DNS::Resource::IN
|
40
|
+
|
41
|
+
# Use upstream DNS for name resolution.
|
42
|
+
UPSTREAM = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
|
43
|
+
|
44
|
+
def self.run
|
45
|
+
# Start the RubyDNS server
|
46
|
+
RubyDNS::run_server(:listen => INTERFACES) do
|
47
|
+
match(/test.mydomain.org/, IN::A) do |_host, transaction|
|
48
|
+
transaction.respond!("10.0.0.80")
|
49
|
+
end
|
50
|
+
|
51
|
+
# Default DNS handler
|
52
|
+
otherwise do |transaction|
|
53
|
+
transaction.passthrough!(UPSTREAM)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
run
|
58
|
+
```
|
59
|
+
Start the server using `rvmsudo ./test.rb`. You can then test it using dig:
|
60
|
+
```
|
61
|
+
$ dig @localhost test1.mydomain.org
|
62
|
+
$ dig @localhost dev.mydomain.org
|
63
|
+
$ dig @localhost google.com
|
64
|
+
```
|
58
65
|
|
59
66
|
## Compatibility
|
60
67
|
|
61
68
|
### Migrating from RubyDNS 0.3.x to 0.4.x ###
|
62
69
|
|
63
70
|
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.
|
64
|
-
|
65
|
-
|
66
|
-
|
71
|
+
```ruby
|
72
|
+
match(..., :A)
|
73
|
+
```
|
67
74
|
becomes
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
75
|
+
```ruby
|
76
|
+
IN = Resolv::DNS::Resource::IN
|
77
|
+
match(..., IN::A)
|
78
|
+
```
|
72
79
|
### Migrating from RubyDNS 0.4.x to 0.5.x ###
|
73
80
|
|
74
81
|
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.
|
75
82
|
|
76
83
|
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:
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
EventMachine::stop
|
84
|
+
```ruby
|
85
|
+
resolver = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
|
86
|
+
|
87
|
+
EventMachine::run do
|
88
|
+
resolver.query('google.com', IN::A) do |response|
|
89
|
+
case response
|
90
|
+
when RubyDNS::Message
|
91
|
+
puts "Got response: #{response.answers.first}"
|
92
|
+
else
|
93
|
+
# Response is of class RubyDNS::ResolutionFailure
|
94
|
+
puts "Failed: #{response.message}"
|
91
95
|
end
|
92
|
-
end
|
93
96
|
|
97
|
+
EventMachine::stop
|
98
|
+
end
|
99
|
+
end
|
100
|
+
```
|
94
101
|
Existing code that uses `Resolv::DNS` as a resolver will need to be updated:
|
95
|
-
|
96
|
-
|
97
|
-
|
102
|
+
```ruby
|
103
|
+
# 1/ Add this at the top of your file; Host specific system information:
|
104
|
+
require 'rubydns/system'
|
98
105
|
|
99
|
-
|
100
|
-
|
101
|
-
|
106
|
+
# 2/ Change from R = Resolv::DNS.new to:
|
107
|
+
R = RubyDNS::Resolver.new(RubyDNS::System::nameservers)
|
108
|
+
```
|
102
109
|
Everything else in the server can remain the same. You can see a complete example in `test/test_resolver.rb`.
|
103
110
|
|
104
111
|
#### Deferred Transactions ####
|
105
112
|
|
106
113
|
The implementation of the above depends on a new feature which was added in 0.5.0:
|
107
114
|
|
108
|
-
|
115
|
+
```ruby
|
116
|
+
transaction.defer!
|
117
|
+
```
|
109
118
|
|
110
119
|
Once you call this, the transaction won't complete until you call either `transaction.succeed` or `transaction.fail`.
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
# No domain exists, after 5 seconds:
|
117
|
-
EventMachine::Timer.new(5) do
|
118
|
-
transaction.failure!(:NXDomain)
|
119
|
-
end
|
120
|
-
end
|
120
|
+
```ruby
|
121
|
+
RubyDNS::run_server(:listen => SERVER_PORTS) do
|
122
|
+
match(/\.*.com/, IN::A) do |match, transaction|
|
123
|
+
transaction.defer!
|
121
124
|
|
122
|
-
|
125
|
+
# No domain exists, after 5 seconds:
|
126
|
+
EventMachine::Timer.new(5) do
|
123
127
|
transaction.failure!(:NXDomain)
|
124
128
|
end
|
125
129
|
end
|
126
130
|
|
131
|
+
otherwise do
|
132
|
+
transaction.failure!(:NXDomain)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
```
|
136
|
+
|
127
137
|
You can see a complete example in `test/test_slow_server.rb`.
|
128
138
|
|
129
139
|
## Contributing
|
data/lib/rubydns/resolver.rb
CHANGED
@@ -121,7 +121,7 @@ module RubyDNS
|
|
121
121
|
|
122
122
|
try_next_server!
|
123
123
|
elsif response.id != @message.id
|
124
|
-
@logger.warn "[#{@message.id}] Received response with incorrect message id: #{response.id}" if @
|
124
|
+
@logger.warn "[#{@message.id}] Received response with incorrect message id: #{response.id}" if @logger
|
125
125
|
|
126
126
|
try_next_server!
|
127
127
|
else
|
data/lib/rubydns/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubydns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rexec
|
@@ -110,12 +110,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
110
|
- - ! '>='
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: '0'
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
hash: 4471214807073304118
|
113
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
117
|
none: false
|
115
118
|
requirements:
|
116
119
|
- - ! '>='
|
117
120
|
- !ruby/object:Gem::Version
|
118
121
|
version: '0'
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
hash: 4471214807073304118
|
119
125
|
requirements: []
|
120
126
|
rubyforge_project:
|
121
127
|
rubygems_version: 1.8.24
|