rubydns 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4deb19b1b3f2428b941ec102d2cc15a640ad8211
4
- data.tar.gz: 13c3d5e62e811bbb25c2eee5123195c608b30303
3
+ metadata.gz: 898751427b20f0b4ca38ef3847c63846cb0f31bb
4
+ data.tar.gz: 87e103c621007b21ac049a3e00ebed1ea03b066b
5
5
  SHA512:
6
- metadata.gz: 532c64c0de7e2893704ff62e1cd523a155dacbc42e332aef20c44723d5fce08218cbfa371cb458049a94cf30a4d885b3787a8ee1ee2b525f21afa7d4dad5e0d0
7
- data.tar.gz: 250674b3f8554f7ceb493fdd0b0f7a4b8d1cee949ce27b16276db5ef83fe5ab2868fce3a8e4037976f8a307538bf116b0775271a6b07445f29f909448f4b3c4d
6
+ metadata.gz: 0d7600616e59ed6bf93c7da9b892d2dc71e181512ef1f85721057214bf86eb28c36b614013cc947685111a136b6fb57279411ed3ffe8a69bb1757782f34f9f5a
7
+ data.tar.gz: 16a27d29545fd438089be5f31bc5db1395038e5ddf06edc7913926ab5430f5c9f4f067b6485c70a4ea2cb5058766c0ebbe6a2ae2050bf3dda5d78ab9d5c477fb
data/README.md CHANGED
@@ -107,7 +107,7 @@ These benchmarks are included in the unit tests.
107
107
 
108
108
  ## Compatibility
109
109
 
110
- ### Migrating from RubyDNS 0.8.x 0.9.x
110
+ ### Migrating from RubyDNS 0.8.x to 0.9.x
111
111
 
112
112
  RubyDNS 0.9.0 is based on a branch which replaced EventMachine with Celluloid. This reduces the complexity in writing concurrent systems hugely, but it is also a largely untested code path. RubyDNS 0.8.x using EventMachine has been tested over 4 years now by many projects.
113
113
 
data/examples/README.md CHANGED
@@ -13,7 +13,7 @@ By default this server will listen for UDP requests on port 5300 and does not ne
13
13
  To start the server, ensure that you're in the examples subdirectory and type
14
14
 
15
15
  bundle
16
- bundle exec ./flakey-dns.rb
16
+ bundle exec ./flakey-dns.rb start
17
17
 
18
18
  To see it in action you can then query some domains. For example,
19
19
 
@@ -51,7 +51,7 @@ system.
51
51
  To start the server, ensure that you're in the examples subdirectory and type
52
52
 
53
53
  bundle
54
- sudo bundle exec ./fortune-dns.rb
54
+ sudo bundle exec ./fortune-dns.rb start
55
55
 
56
56
  To create a new fortune type
57
57
 
@@ -98,7 +98,7 @@ By default this server will listen for UDP requests on port 5300 and does not ne
98
98
  To start the server, ensure that you're in the examples subdirectory and type
99
99
 
100
100
  bundle
101
- sudo bundle exec ./geoip-dns.rb
101
+ sudo bundle exec ./geoip-dns.rb start
102
102
 
103
103
  To see the behavior, run a DNS query against the server where you are running the GeoIPDNS
104
104
  daemon. Depending on the continent to which the client machine's IP address is mapped,
@@ -124,7 +124,7 @@ system.
124
124
  To start the server, ensure that you're in the examples subdirectory and type
125
125
 
126
126
  bundle
127
- sudo bundle exec ./wikipedia-dns.rb
127
+ sudo bundle exec ./wikipedia-dns.rb start
128
128
 
129
129
  To query Wikipedia, pick a term - say, 'helium' - and make a DNS query like
130
130
 
@@ -39,6 +39,10 @@ class FlakeyDNS < Process::Daemon
39
39
 
40
40
  def startup
41
41
  RubyDNS.run_server(listen: INTERFACES) do
42
+ # Use a Celluloid supervisor so the system recovers if the actor dies
43
+ fallback_resolver_supervisor =
44
+ RubyDNS::Resolver.supervise(RubyDNS::System.nameservers)
45
+
42
46
  # Fail the resolution of certain domains ;)
43
47
  match(/(m?i?c?r?o?s?o?f?t)/) do |transaction, match_data|
44
48
  if match_data[1].size > 7
@@ -59,14 +63,10 @@ class FlakeyDNS < Process::Daemon
59
63
  # Default DNS handler
60
64
  otherwise do |transaction|
61
65
  logger.info 'Passing DNS request upstream...'
62
- transaction.passthrough!(FlakeyDNS.fallback_resolver)
66
+ transaction.passthrough!(fallback_resolver_supervisor.actors.first)
63
67
  end
64
68
  end
65
69
  end
66
-
67
- def self.fallback_resolver
68
- @resolver ||= RubyDNS::Resolver.new(RubyDNS::System.nameservers)
69
- end
70
70
  end
71
71
 
72
72
  FlakeyDNS.daemonize
@@ -58,6 +58,8 @@ class GeoIPDNS < Process::Daemon
58
58
 
59
59
  def startup
60
60
  RubyDNS.run_server(listen: INTERFACES) do
61
+ fallback_resolver_supervisor =
62
+ RubyDNS::Resolver.supervise(RubyDNS::System.nameservers)
61
63
  match(//, IN::A) do |transaction|
62
64
  logger.debug 'In block'
63
65
 
@@ -82,15 +84,11 @@ class GeoIPDNS < Process::Daemon
82
84
  # Default DNS handler
83
85
  otherwise do |transaction|
84
86
  logger.debug 'In otherwise'
85
- transaction.passthrough!(GeoIPDNS.fallback_resolver)
87
+ transaction.passthrough!(fallback_resolver_supervisor.actors.first)
86
88
  end
87
89
  end
88
90
  end
89
91
 
90
- def self.fallback_resolver
91
- @resolver ||= RubyDNS::Resolver.new(RubyDNS::System.nameservers)
92
- end
93
-
94
92
  # Maps each continent code to a fixed IP address for the response.
95
93
  # A simple mapper to demonstrate the behavior.
96
94
  def self.answer_for_continent_code(code)
@@ -81,7 +81,8 @@ class WikipediaDNS < Process::Daemon
81
81
 
82
82
  stats = { requested: 0 }
83
83
 
84
- fetcher = HttpFetcher.new
84
+ # Use a Celluloid supervisor so the system recovers if the actor dies
85
+ fetcher = HttpFetcher.supervise
85
86
 
86
87
  # Start the RubyDNS server
87
88
  RubyDNS.run_server do
@@ -102,7 +103,7 @@ class WikipediaDNS < Process::Daemon
102
103
  title = match_data[1]
103
104
  stats[:requested] += 1
104
105
 
105
- response = fetcher.get(Wikipedia.summary_url(title))
106
+ response = fetcher.actors.first.get(Wikipedia.summary_url(title))
106
107
 
107
108
  summary =
108
109
  Wikipedia.extract_summary(response).force_encoding('ASCII-8BIT')
@@ -124,7 +124,9 @@ module RubyDNS
124
124
 
125
125
  class UDPHandler < UDPSocketHandler
126
126
  def initialize(server, host, port)
127
- socket = UDPSocket.new
127
+ family = RubyDNS::address_family(host)
128
+ socket = UDPSocket.new(family)
129
+
128
130
  socket.bind(host, port)
129
131
 
130
132
  super(server, socket)
@@ -147,7 +147,8 @@ module RubyDNS
147
147
  end
148
148
 
149
149
  def try_udp_server(request, host, port)
150
- socket = UDPSocket.new
150
+ family = RubyDNS::address_family(host)
151
+ socket = UDPSocket.new(family)
151
152
 
152
153
  socket.send(request.packet, 0, host, port)
153
154
 
@@ -22,7 +22,7 @@ module RubyDNS
22
22
 
23
23
  # This class provides all details of a single DNS question and response. This is used by the DSL to provide DNS related functionality.
24
24
  #
25
- # The main functions to complete the trasaction are: {#append!} (evaluate a new query and append the results), {#passthrough!} (pass the query to an upstream server), {#respond!} (compute a specific response) and {#fail!} (fail with an error code).
25
+ # The main functions to complete the transaction are: {#append!} (evaluate a new query and append the results), {#passthrough!} (pass the query to an upstream server), {#respond!} (compute a specific response) and {#fail!} (fail with an error code).
26
26
  class Transaction
27
27
  # The default time used for responses (24 hours).
28
28
  DEFAULT_TTL = 86400
@@ -19,10 +19,15 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  require 'stringio'
22
+ require 'ipaddr'
22
23
 
23
24
  require_relative 'message'
24
25
 
25
26
  module RubyDNS
27
+ def self.address_family(host)
28
+ return IPAddr.new(host).family
29
+ end
30
+
26
31
  # A helper class for processing incoming network data.
27
32
  class BinaryStringIO < StringIO
28
33
  def initialize
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module RubyDNS
22
- VERSION = "0.9.1"
22
+ VERSION = "0.9.2"
23
23
  end
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright, 2014, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'rubydns'
24
+ require 'rubydns/system'
25
+
26
+ module RubyDNS::SocketSpec
27
+ IN = Resolv::DNS::Resource::IN
28
+
29
+ describe RubyDNS::TCPSocketHandler do
30
+ before(:all) do
31
+ Celluloid.shutdown
32
+ Celluloid.boot
33
+ end
34
+
35
+ it "should create server with existing TCP socket" do
36
+ @server = RubyDNS::run_server(:listen => [[:tcp, '::', 2002]], asynchronous: true) do
37
+ resolver = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
38
+
39
+ match(/.*\.com/, IN::A) do |transaction|
40
+ transaction.passthrough!(resolver)
41
+ end
42
+ end
43
+
44
+ resolver = RubyDNS::Resolver.new([[:tcp, '::1', 2002]])
45
+ response = resolver.query('google.com')
46
+ expect(response.class).to be == RubyDNS::Message
47
+ end
48
+ end
49
+
50
+ describe RubyDNS::UDPSocketHandler do
51
+ before(:all) do
52
+ Celluloid.shutdown
53
+ Celluloid.boot
54
+ end
55
+
56
+ it "should create server with existing UDP socket" do
57
+ @server = RubyDNS::run_server(:listen => [[:udp, '::', 2002]], asynchronous: true) do
58
+ resolver = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
59
+
60
+ match(/.*\.com/, IN::A) do |transaction|
61
+ transaction.passthrough!(resolver)
62
+ end
63
+ end
64
+
65
+ resolver = RubyDNS::Resolver.new([[:udp, '::1', 2002]])
66
+ response = resolver.query('google.com')
67
+ expect(response.class).to be == RubyDNS::Message
68
+ end
69
+ end
70
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubydns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-21 00:00:00.000000000 Z
11
+ date: 2014-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid
@@ -153,6 +153,7 @@ files:
153
153
  - spec/rubydns/daemon_spec.rb
154
154
  - spec/rubydns/hosts.txt
155
155
  - spec/rubydns/injected_supervisor_spec.rb
156
+ - spec/rubydns/ipv6_spec.rb
156
157
  - spec/rubydns/message_spec.rb
157
158
  - spec/rubydns/passthrough_spec.rb
158
159
  - spec/rubydns/resolver_performance_spec.rb
@@ -200,6 +201,7 @@ test_files:
200
201
  - spec/rubydns/daemon_spec.rb
201
202
  - spec/rubydns/hosts.txt
202
203
  - spec/rubydns/injected_supervisor_spec.rb
204
+ - spec/rubydns/ipv6_spec.rb
203
205
  - spec/rubydns/message_spec.rb
204
206
  - spec/rubydns/passthrough_spec.rb
205
207
  - spec/rubydns/resolver_performance_spec.rb