rubydns 0.8.5 → 0.9.0

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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -0
  3. data/Gemfile +0 -4
  4. data/README.md +16 -8
  5. data/Rakefile +6 -6
  6. data/{test/examples → examples}/dropping-dns.rb +0 -0
  7. data/lib/rubydns/handler.rb +133 -102
  8. data/lib/rubydns/message.rb +0 -1
  9. data/lib/rubydns/resolver.rb +135 -187
  10. data/lib/rubydns/server.rb +92 -86
  11. data/lib/rubydns/transaction.rb +24 -48
  12. data/lib/rubydns/{binary_string.rb → transport.rb} +38 -0
  13. data/lib/rubydns/version.rb +1 -1
  14. data/lib/rubydns.rb +15 -8
  15. data/rubydns.gemspec +5 -2
  16. data/{test/test_daemon.rb → spec/rubydns/daemon_spec.rb} +36 -48
  17. data/{test → spec/rubydns}/hosts.txt +0 -0
  18. data/{test/test_rules.rb → spec/rubydns/message_spec.rb} +26 -44
  19. data/spec/rubydns/passthrough_spec.rb +78 -0
  20. data/spec/rubydns/resolver_performance_spec.rb +110 -0
  21. data/spec/rubydns/resolver_spec.rb +144 -0
  22. data/spec/rubydns/rules_spec.rb +74 -0
  23. data/{test/performance → spec/rubydns/server}/benchmark.rb +0 -0
  24. data/{test/performance → spec/rubydns/server}/bind9/generate-local.rb +0 -0
  25. data/{test/performance → spec/rubydns/server}/bind9/local.zone +0 -0
  26. data/{test/performance → spec/rubydns/server}/bind9/named.conf +0 -0
  27. data/spec/rubydns/server/bind9/named.run +0 -0
  28. data/{test/performance → spec/rubydns/server}/million.rb +1 -3
  29. data/spec/rubydns/server/rubydns.stackprof +0 -0
  30. data/spec/rubydns/server_performance_spec.rb +136 -0
  31. data/spec/rubydns/slow_server_spec.rb +89 -0
  32. data/spec/rubydns/socket_spec.rb +77 -0
  33. data/{test/test_system.rb → spec/rubydns/system_spec.rb} +28 -22
  34. data/spec/rubydns/transaction_spec.rb +64 -0
  35. data/{test/test_truncation.rb → spec/rubydns/truncation_spec.rb} +22 -48
  36. metadata +91 -54
  37. data/test/examples/fortune-dns.rb +0 -107
  38. data/test/examples/geoip-dns.rb +0 -76
  39. data/test/examples/soa-dns.rb +0 -82
  40. data/test/examples/test-dns-1.rb +0 -77
  41. data/test/examples/test-dns-2.rb +0 -83
  42. data/test/examples/wikipedia-dns.rb +0 -112
  43. data/test/test_message.rb +0 -65
  44. data/test/test_passthrough.rb +0 -120
  45. data/test/test_resolver.rb +0 -106
  46. data/test/test_resolver_performance.rb +0 -123
  47. data/test/test_server_performance.rb +0 -134
  48. data/test/test_slow_server.rb +0 -125
@@ -1,134 +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 'minitest/autorun'
24
-
25
- require 'rubydns'
26
- require 'process/daemon'
27
-
28
- require 'benchmark'
29
-
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
- million = {}
39
-
40
- puts "Generating domains..."
41
- (1..5_000).each do |i|
42
- domain = "domain#{i}.local"
43
-
44
- million[domain] = "#{69}.#{(i >> 16)%256}.#{(i >> 8)%256}.#{i%256}"
45
- end
46
-
47
- puts "Starting DNS server..."
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
- puts "Responding to #{transaction.name}"
53
- transaction.respond!(million[transaction.name])
54
- end
55
-
56
- # Default DNS handler
57
- otherwise do |transaction|
58
- transaction.fail!(:NXDomain)
59
- end
60
- end
61
- end
62
- end
63
-
64
- class ServerPerformanceBind9 < Process::Daemon
65
- def working_directory
66
- File.expand_path("../performance/bind9", __FILE__)
67
- end
68
-
69
- def startup
70
- exec(self.class.named_executable, "-c", "named.conf", "-f", "-p", "5400", "-g")
71
- end
72
-
73
- def self.named_executable
74
- # Check if named executable is available:
75
- @named ||= `which named`.chomp
76
- end
77
- end
78
-
79
- class ServerPerformanceTest < MiniTest::Test
80
- DOMAINS = (1..1000).collect do |i|
81
- "domain#{i}.local"
82
- end
83
-
84
- def setup
85
- @servers = []
86
- @servers << ["RubyDNS::Server", 5300]
87
-
88
- ServerPerformanceRubyDNS.start
89
-
90
- unless ServerPerformanceBind9.named_executable.empty?
91
- ServerPerformanceBind9.start
92
- @servers << ["Bind9", 5400]
93
- end
94
-
95
- # Give the daemons some time to start up:
96
- sleep 2
97
- end
98
-
99
- def teardown
100
- ServerPerformanceRubyDNS.stop
101
-
102
- unless ServerPerformanceBind9.named_executable.empty?
103
- ServerPerformanceBind9.stop
104
- end
105
- end
106
-
107
- def test_server_performance
108
- resolved = {}
109
-
110
- puts nil, "Testing server performance..."
111
- Benchmark.bm(20) do |x|
112
- @servers.each do |name, port|
113
- x.report(name) do
114
- # Number of requests remaining since this is an asynchronous event loop:
115
- 5.times do
116
- pending = DOMAINS.size
117
-
118
- EventMachine::run do
119
- resolver = RubyDNS::Resolver.new([[:udp, '127.0.0.1', port]])
120
-
121
- DOMAINS.each do |domain|
122
- resolver.addresses_for(domain) do |addresses|
123
- resolved[domain] = addresses
124
-
125
- EventMachine::stop if (pending -= 1) == 0
126
- end
127
- end
128
- end
129
- end
130
- end
131
- end
132
- end
133
- end
134
- end
@@ -1,125 +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 'minitest/autorun'
24
-
25
- require 'rubydns'
26
-
27
- require 'process/daemon'
28
-
29
- class SlowServer < Process::Daemon
30
- SERVER_PORTS = [[:udp, '127.0.0.1', 5330], [:tcp, '127.0.0.1', 5330]]
31
-
32
- def working_directory
33
- File.expand_path("../tmp", __FILE__)
34
- end
35
-
36
- IN = Resolv::DNS::Resource::IN
37
-
38
- def startup
39
- RubyDNS::run_server(:listen => SERVER_PORTS) do
40
- match(/\.*.com/, IN::A) do |transaction|
41
- defer do |fiber|
42
- # No domain exists, after 2 seconds:
43
- EventMachine::Timer.new(2) do
44
- transaction.fail!(:NXDomain)
45
-
46
- fiber.resume
47
- end
48
- end
49
- end
50
-
51
- otherwise do |transaction|
52
- transaction.fail!(:NXDomain)
53
- end
54
- end
55
- end
56
- end
57
-
58
- class SlowServerTest < MiniTest::Test
59
- def setup
60
- SlowServer.controller output: File.open("/dev/null", "w")
61
- SlowServer.start
62
- end
63
-
64
- def teardown
65
- SlowServer.stop
66
- end
67
-
68
- IN = Resolv::DNS::Resource::IN
69
-
70
- def test_timeout
71
- start_time = Time.now
72
- end_time = nil
73
- got_response = false
74
-
75
- # Because there are two servers, the total timeout is actually, 2 seconds
76
- resolver = RubyDNS::Resolver.new(SlowServer::SERVER_PORTS, :timeout => 1)
77
-
78
- EventMachine::run do
79
- resolver.query("apple.com", IN::A) do |response|
80
- end_time = Time.now
81
-
82
- got_response = response
83
-
84
- EventMachine::stop
85
- end
86
- end
87
-
88
- assert_operator end_time - start_time, :<=, 2.5, "Response should fail within timeout period."
89
- assert_equal RubyDNS::ResolutionFailure, got_response.class, "Response should be resolution failure."
90
- end
91
-
92
- def test_slow_request
93
- start_time = Time.now
94
- end_time = nil
95
-
96
- resolver = RubyDNS::Resolver.new(SlowServer::SERVER_PORTS, :timeout => 10)
97
-
98
- EventMachine::run do
99
- resolver.query("apple.com", IN::A) do |response|
100
- end_time = Time.now
101
-
102
- EventMachine::stop
103
- end
104
- end
105
-
106
- assert_operator end_time - start_time, :>, 2.0, "Response should fail within timeout period."
107
- end
108
-
109
- def test_normal_request
110
- start_time = Time.now
111
- end_time = nil
112
-
113
- resolver = RubyDNS::Resolver.new(SlowServer::SERVER_PORTS, :timeout => 10)
114
-
115
- EventMachine::run do
116
- resolver.query("oriontransfer.org", IN::A) do |response|
117
- end_time = Time.now
118
-
119
- EventMachine::stop
120
- end
121
- end
122
-
123
- assert_operator end_time - start_time, :<, 2.0, "Response should fail immediately"
124
- end
125
- end