rubydns 1.0.3 → 2.0.0.pre.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +4 -0
  3. data/.travis.yml +9 -12
  4. data/Gemfile +4 -1
  5. data/README.md +49 -151
  6. data/Rakefile +2 -7
  7. data/examples/basic-dns.rb +24 -0
  8. data/examples/cname.rb +25 -0
  9. data/examples/flakey-dns.rb +2 -2
  10. data/examples/simple.rb +25 -0
  11. data/examples/soa-dns.rb +82 -0
  12. data/examples/test-dns-1.rb +83 -0
  13. data/examples/test-dns-2.rb +83 -0
  14. data/examples/wikipedia-dns.rb +4 -18
  15. data/lib/rubydns.rb +9 -23
  16. data/lib/rubydns/{server.rb → rule_based_server.rb} +2 -160
  17. data/lib/rubydns/version.rb +1 -1
  18. data/rubydns.gemspec +3 -6
  19. data/spec/rubydns/daemon_spec.rb +26 -22
  20. data/spec/rubydns/injected_supervisor_spec.rb +10 -7
  21. data/spec/rubydns/passthrough_spec.rb +31 -24
  22. data/spec/spec_helper.rb +43 -0
  23. metadata +21 -100
  24. data/lib/rubydns/chunked.rb +0 -34
  25. data/lib/rubydns/extensions/resolv.rb +0 -85
  26. data/lib/rubydns/extensions/string.rb +0 -28
  27. data/lib/rubydns/handler.rb +0 -188
  28. data/lib/rubydns/logger.rb +0 -31
  29. data/lib/rubydns/message.rb +0 -76
  30. data/lib/rubydns/resolver.rb +0 -294
  31. data/lib/rubydns/system.rb +0 -146
  32. data/lib/rubydns/transaction.rb +0 -204
  33. data/lib/rubydns/transport.rb +0 -75
  34. data/spec/rubydns/celluloid_bug_spec.rb +0 -92
  35. data/spec/rubydns/ipv6_spec.rb +0 -70
  36. data/spec/rubydns/message_spec.rb +0 -56
  37. data/spec/rubydns/origin_spec.rb +0 -106
  38. data/spec/rubydns/resolver_performance_spec.rb +0 -110
  39. data/spec/rubydns/resolver_spec.rb +0 -152
  40. data/spec/rubydns/server/bind9/generate-local.rb +0 -25
  41. data/spec/rubydns/server/bind9/local.zone +0 -5014
  42. data/spec/rubydns/server/bind9/named.conf +0 -14
  43. data/spec/rubydns/server/bind9/named.run +0 -0
  44. data/spec/rubydns/server/million.rb +0 -85
  45. data/spec/rubydns/server/rubydns.stackprof +0 -0
  46. data/spec/rubydns/server_performance_spec.rb +0 -136
  47. data/spec/rubydns/slow_server_spec.rb +0 -89
  48. data/spec/rubydns/socket_spec.rb +0 -77
  49. data/spec/rubydns/system_spec.rb +0 -60
  50. data/spec/rubydns/transaction_spec.rb +0 -138
  51. data/spec/rubydns/truncation_spec.rb +0 -59
@@ -1,14 +0,0 @@
1
-
2
- options {
3
- directory "./";
4
-
5
- listen-on-v6 { none; };
6
- listen-on { 127.0.0.1; };
7
-
8
- pid-file "./named.pid";
9
- };
10
-
11
- zone "local" {
12
- type master;
13
- file "./local.zone";
14
- };
File without changes
@@ -1,85 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Copyright, 2009, 2012, 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 'benchmark'
25
-
26
- require 'stackprof'
27
-
28
- Name = Resolv::DNS::Name
29
- IN = Resolv::DNS::Resource::IN
30
-
31
- # Generate a million A record "domains":
32
-
33
- million = {}
34
-
35
- Benchmark.bm do |x|
36
- x.report("Generate names") do
37
- (1..1_000_000).each do |i|
38
- domain = "domain#{i}.local"
39
-
40
- million[domain] = "#{69}.#{(i >> 16)%256}.#{(i >> 8)%256}.#{i%256}"
41
- end
42
- end
43
- end
44
-
45
- # Run the server:
46
-
47
- StackProf.run(mode: :cpu, out: 'rubydns.stackprof') do
48
- RubyDNS::run_server(:listen => [[:udp, '0.0.0.0', 5300]]) do
49
- @logger.level = Logger::WARN
50
-
51
- match(//, IN::A) do |transaction|
52
- transaction.respond!(million[transaction.name])
53
- end
54
-
55
- # Default DNS handler
56
- otherwise do |transaction|
57
- logger.info "Passing DNS request upstream..."
58
- transaction.fail!(:NXDomain)
59
- end
60
- end
61
- end
62
-
63
- # Expected output:
64
- #
65
- # > dig @localhost -p 5300 domain1000000
66
- #
67
- # ; <<>> DiG 9.8.3-P1 <<>> @localhost -p 5300 domain1000000
68
- # ; (3 servers found)
69
- # ;; global options: +cmd
70
- # ;; Got answer:
71
- # ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 50336
72
- # ;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
73
- # ;; WARNING: recursion requested but not available
74
- #
75
- # ;; QUESTION SECTION:
76
- # ;domain1000000. IN A
77
- #
78
- # ;; ANSWER SECTION:
79
- # domain1000000. 86400 IN A 69.15.66.64
80
- #
81
- # ;; Query time: 1 msec
82
- # ;; SERVER: 127.0.0.1#5300(127.0.0.1)
83
- # ;; WHEN: Fri May 16 19:17:48 2014
84
- # ;; MSG SIZE rcvd: 47
85
- #
@@ -1,136 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Copyright, 2012, 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 'benchmark'
25
- require 'process/daemon'
26
-
27
- module RubyDNS::ServerPerformanceSpec
28
- describe RubyDNS::Server do
29
- context 'benchmark' do
30
- class ServerPerformanceRubyDNS < Process::Daemon
31
- IN = Resolv::DNS::Resource::IN
32
-
33
- def working_directory
34
- File.expand_path("../tmp", __FILE__)
35
- end
36
-
37
- def startup
38
- puts "Booting celluloid..."
39
- Celluloid.boot
40
-
41
- million = {}
42
-
43
- puts "Generating domains..."
44
- (1..5_000).each do |i|
45
- domain = "domain#{i}.local"
46
-
47
- million[domain] = "#{69}.#{(i >> 16)%256}.#{(i >> 8)%256}.#{i%256}"
48
- end
49
-
50
- puts "Starting DNS server..."
51
- RubyDNS::run_server(:listen => [[:udp, '0.0.0.0', 5300]]) do
52
- @logger.level = Logger::WARN
53
-
54
- match(//, IN::A) do |transaction|
55
- puts "Responding to #{transaction.name}"
56
- transaction.respond!(million[transaction.name])
57
- end
58
-
59
- # Default DNS handler
60
- otherwise do |transaction|
61
- transaction.fail!(:NXDomain)
62
- end
63
- end
64
- end
65
- end
66
-
67
- class ServerPerformanceBind9 < Process::Daemon
68
- def working_directory
69
- File.expand_path("../server/bind9", __FILE__)
70
- end
71
-
72
- def startup
73
- exec(self.class.named_executable, "-c", "named.conf", "-f", "-p", "5400", "-g")
74
- end
75
-
76
- def self.named_executable
77
- # Check if named executable is available:
78
- @named ||= `which named`.chomp
79
- end
80
- end
81
-
82
- before do
83
- Celluloid.shutdown
84
-
85
- @servers = []
86
- @servers << ["RubyDNS::Server", 5300]
87
-
88
- @domains = (1..1000).collect do |i|
89
- "domain#{i}.local"
90
- end
91
-
92
- ServerPerformanceRubyDNS.start
93
-
94
- unless ServerPerformanceBind9.named_executable.empty?
95
- ServerPerformanceBind9.start
96
- @servers << ["Bind9", 5400]
97
- end
98
-
99
- sleep 2
100
-
101
- Celluloid.boot
102
- end
103
-
104
- after do
105
- ServerPerformanceRubyDNS.stop
106
-
107
- unless ServerPerformanceBind9.named_executable.empty?
108
- ServerPerformanceBind9.stop
109
- end
110
- end
111
-
112
- it 'it takes time' do
113
- Celluloid.logger.level = Logger::ERROR
114
-
115
- Benchmark.bm(20) do |x|
116
- @servers.each do |name, port|
117
- resolver = RubyDNS::Resolver.new([[:udp, '127.0.0.1', port]])
118
-
119
- x.report(name) do
120
- # Number of requests remaining since this is an asynchronous event loop:
121
- 5.times do
122
- pending = @domains.size
123
-
124
- futures = @domains.collect{|domain| resolver.future.addresses_for(domain)}
125
-
126
- futures.collect do |future|
127
- expect(future.value).to_not be nil
128
- end
129
- end
130
- end
131
- end
132
- end
133
- end
134
- end
135
- end
136
- end
@@ -1,89 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Copyright, 2012, 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
-
25
- module RubyDNS::SlowServerSpec
26
- SERVER_PORTS = [[:udp, '127.0.0.1', 5330], [:tcp, '127.0.0.1', 5330]]
27
- IN = Resolv::DNS::Resource::IN
28
-
29
- describe "RubyDNS Slow Server" do
30
- before(:all) do
31
- Celluloid.shutdown
32
- Celluloid.boot
33
-
34
- @server = RubyDNS::run_server(:listen => SERVER_PORTS, asynchronous: true) do
35
- match(/\.*.com/, IN::A) do |transaction|
36
- sleep 2
37
-
38
- transaction.fail!(:NXDomain)
39
- end
40
-
41
- otherwise do |transaction|
42
- transaction.fail!(:NXDomain)
43
- end
44
- end
45
- end
46
-
47
- it "get no answer after 2 seconds" do
48
- start_time = Time.now
49
-
50
- resolver = RubyDNS::Resolver.new(SERVER_PORTS, :timeout => 10)
51
-
52
- response = resolver.query("apple.com", IN::A)
53
-
54
- expect(response.answer.length).to be == 0
55
-
56
- end_time = Time.now
57
-
58
- expect(end_time - start_time).to be_within(0.1).of(2.0)
59
- end
60
-
61
- it "times out after 1 second" do
62
- start_time = Time.now
63
-
64
- resolver = RubyDNS::Resolver.new(SERVER_PORTS, :timeout => 0.5)
65
-
66
- response = resolver.query("apple.com", IN::A)
67
-
68
- expect(response).to be nil
69
-
70
- end_time = Time.now
71
-
72
- expect(end_time - start_time).to be_within(0.1).of(1.0)
73
- end
74
-
75
- it "gets no answer immediately" do
76
- start_time = Time.now
77
-
78
- resolver = RubyDNS::Resolver.new(SERVER_PORTS, :timeout => 0.5)
79
-
80
- response = resolver.query("oriontransfer.org", IN::A)
81
-
82
- expect(response.answer.length).to be 0
83
-
84
- end_time = Time.now
85
-
86
- expect(end_time - start_time).to be_within(0.1).of(0.0)
87
- end
88
- end
89
- end
@@ -1,77 +0,0 @@
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
- socket = TCPServer.new('127.0.0.1', 2002)
37
-
38
- # Start the RubyDNS server
39
- @server = RubyDNS::run_server(:listen => [socket], asynchronous: true) do
40
- resolver = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
41
-
42
- match(/.*\.com/, IN::A) do |transaction|
43
- transaction.passthrough!(resolver)
44
- end
45
- end
46
-
47
- resolver = RubyDNS::Resolver.new([[:tcp, '127.0.0.1', 2002]])
48
- response = resolver.query('google.com')
49
- expect(response.class).to be == RubyDNS::Message
50
- end
51
- end
52
-
53
- describe RubyDNS::UDPSocketHandler do
54
- before(:all) do
55
- Celluloid.shutdown
56
- Celluloid.boot
57
- end
58
-
59
- it "should create server with existing UDP socket" do
60
- socket = UDPSocket.new
61
- socket.bind('127.0.0.1', 2002)
62
-
63
- # Start the RubyDNS server
64
- @server = RubyDNS::run_server(:listen => [socket], asynchronous: true) do
65
- resolver = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
66
-
67
- match(/.*\.com/, IN::A) do |transaction|
68
- transaction.passthrough!(resolver)
69
- end
70
- end
71
-
72
- resolver = RubyDNS::Resolver.new([[:udp, '127.0.0.1', 2002]])
73
- response = resolver.query('google.com')
74
- expect(response.class).to be == RubyDNS::Message
75
- end
76
- end
77
- end
@@ -1,60 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Copyright, 2012, 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::SystemSpec
27
- describe RubyDNS::System do
28
- before(:all) do
29
- Celluloid.shutdown
30
- Celluloid.boot
31
- end
32
-
33
- it "should have at least one namesever" do
34
- expect(RubyDNS::System::nameservers.length).to be > 0
35
- end
36
-
37
- it "should respond to query for google.com" do
38
- resolver = RubyDNS::Resolver.new(RubyDNS::System::nameservers)
39
-
40
- response = resolver.query('google.com')
41
-
42
- expect(response.class).to be == RubyDNS::Message
43
- expect(response.rcode).to be == Resolv::DNS::RCode::NoError
44
- end
45
- end
46
-
47
- describe RubyDNS::System::Hosts do
48
- it "should parse the hosts file" do
49
- hosts = RubyDNS::System::Hosts.new
50
-
51
- # Load the test hosts data:
52
- File.open(File.expand_path("../hosts.txt", __FILE__)) do |file|
53
- hosts.parse_hosts(file)
54
- end
55
-
56
- expect(hosts.call('testing')).to be == true
57
- expect(hosts['testing']).to be == '1.2.3.4'
58
- end
59
- end
60
- end