rubydns 0.6.0 → 2.0.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 (58) hide show
  1. checksums.yaml +6 -14
  2. data/.gitignore +23 -14
  3. data/.rspec +4 -0
  4. data/.simplecov +15 -0
  5. data/.travis.yml +9 -5
  6. data/.yardopts +1 -0
  7. data/Gemfile +6 -2
  8. data/README.md +82 -92
  9. data/Rakefile +2 -5
  10. data/bin/rubydns-check +374 -0
  11. data/examples/Gemfile +7 -0
  12. data/examples/README.md +137 -0
  13. data/examples/basic-dns.rb +24 -0
  14. data/examples/cname.rb +25 -0
  15. data/{test/examples/dropping-dns.rb → examples/flakey-dns.rb} +28 -31
  16. data/{test/examples → examples}/fortune-dns.rb +42 -46
  17. data/examples/geoip-dns.rb +115 -0
  18. data/examples/simple.rb +25 -0
  19. data/{test/examples → examples}/soa-dns.rb +27 -27
  20. data/{test/examples → examples}/test-dns-1.rb +26 -20
  21. data/{test/examples → examples}/test-dns-2.rb +17 -19
  22. data/examples/wikipedia-dns.rb +107 -0
  23. data/lib/rubydns/rule_based_server.rb +180 -0
  24. data/lib/rubydns/version.rb +1 -1
  25. data/lib/rubydns.rb +13 -63
  26. data/rubydns.gemspec +29 -23
  27. data/spec/rubydns/daemon_spec.rb +114 -0
  28. data/{test/test_system.rb → spec/rubydns/injected_supervisor_spec.rb} +32 -25
  29. data/spec/rubydns/passthrough_spec.rb +85 -0
  30. data/spec/rubydns/rules_spec.rb +74 -0
  31. data/spec/spec_helper.rb +30 -0
  32. metadata +101 -78
  33. data/bin/rd-dns-check +0 -374
  34. data/bin/rd-resolve-test +0 -160
  35. data/lib/rubydns/chunked.rb +0 -34
  36. data/lib/rubydns/extensions/hexdump.rb +0 -38
  37. data/lib/rubydns/extensions/logger.rb +0 -30
  38. data/lib/rubydns/extensions/resolv.rb +0 -53
  39. data/lib/rubydns/extensions/string-1.8.rb +0 -35
  40. data/lib/rubydns/extensions/string-1.9.2.rb +0 -29
  41. data/lib/rubydns/extensions/string-1.9.3.rb +0 -31
  42. data/lib/rubydns/extensions/string.rb +0 -27
  43. data/lib/rubydns/handler.rb +0 -140
  44. data/lib/rubydns/message.rb +0 -41
  45. data/lib/rubydns/resolver.rb +0 -239
  46. data/lib/rubydns/server.rb +0 -241
  47. data/lib/rubydns/system.rb +0 -146
  48. data/lib/rubydns/transaction.rb +0 -250
  49. data/test/examples/geoip-dns.rb +0 -86
  50. data/test/helper.rb +0 -9
  51. data/test/test_daemon.rb +0 -100
  52. data/test/test_domains.txt +0 -185
  53. data/test/test_passthrough.rb +0 -80
  54. data/test/test_resolver.rb +0 -105
  55. data/test/test_rules.rb +0 -74
  56. data/test/test_slow_server.rb +0 -98
  57. data/test/test_truncation.rb +0 -78
  58. /data/{test → spec/rubydns}/hosts.txt +0 -0
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NWFmMGQwYzlmMGFkMjczY2VlNzExMjdmMDI3NDZiNTFjMTc2Nzk4NQ==
5
- data.tar.gz: !binary |-
6
- MjljNzMxODYwNmZlNTdmNzBjMjFkNjRmYjYxZDIxZWRlZmIzYTQ0OA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MWZiMTBlY2YxYjdiYzIzMDU0OTBhMzBkN2RiZjY4OWZlNGFjNzM2ZGUxZTUx
10
- NDE0MzdiMjFiZTg5OTM2NmVhNjcwMmY0NjE1MzNlN2JmZWM4MTIxMjQwYjk2
11
- MjVjOTViMDNkYzQ0NTBlZTdlODIzM2IyZDg3NjEwZjNhMDBlNTM=
12
- data.tar.gz: !binary |-
13
- NzJiNGE4YjhjY2Q4MjQ3MWU0ODgwOTk4NWJlM2YwYmQ4OWZlNDdkYTIxOTU2
14
- Y2FjN2UwZjZhNGYzMzc5NDY2NDYyNDFmMmVkMDZkYjg4Zjk2MWQyZjA3YzEw
15
- NTRlYzZjM2JkYTFjNzUyZDYyNGMwODUxZDdiNjc5NTllZjhmODM=
2
+ SHA1:
3
+ metadata.gz: bac5139eae169f981088495e6dc4bde5d13fa966
4
+ data.tar.gz: 0ee8216c43d6600fb811ee83d708ac984d2807df
5
+ SHA512:
6
+ metadata.gz: caa862959c454afebceddbf387e5722ff6a013a6c1c6012f5cb5acf1ec4d6c9422ea1c641fb3b776ecd270ec9278640e6b7088b64cbcea9ce8e8783c579f45a1
7
+ data.tar.gz: 136467f2543e9eb1ae01b158cca987ec1757d01bd2aa10c695249a204a68a8e88137b39cc907f4bf9cc544c9046a94848542fddde3578f6bf553459e1c81c9bf
data/.gitignore CHANGED
@@ -1,17 +1,26 @@
1
1
  *.gem
2
2
  *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
17
10
  tmp
11
+
12
+ /.yardoc/
13
+ /_yardoc/
14
+ /doc/
15
+ /rdoc/
16
+
17
+ /.bundle/
18
+ /lib/bundler/man/
19
+
20
+ Gemfile.lock
21
+ .ruby-version
22
+ .ruby-gemset
23
+
24
+ /examples/log
25
+ /examples/run
26
+ /spec/rubydns/server/bind9/log/
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --format documentation
3
+ --warnings
4
+ --require spec_helper
data/.simplecov ADDED
@@ -0,0 +1,15 @@
1
+
2
+ SimpleCov.start do
3
+ add_filter "/spec/"
4
+ end
5
+
6
+ # Work correctly across forks:
7
+ pid = Process.pid
8
+ SimpleCov.at_exit do
9
+ SimpleCov.result.format! if Process.pid == pid
10
+ end
11
+
12
+ if ENV['TRAVIS']
13
+ require 'coveralls'
14
+ Coveralls.wear!
15
+ end
data/.travis.yml CHANGED
@@ -1,7 +1,11 @@
1
1
  language: ruby
2
+ sudo: false
2
3
  rvm:
3
- - "1.8.7"
4
- - "1.9.2"
5
- - "1.9.3"
6
- - rbx-18mode
7
- - rbx-19mode
4
+ - 2.2.6
5
+ - 2.3.0
6
+ - 2.4.0
7
+ - ruby-head
8
+ addons:
9
+ apt:
10
+ packages:
11
+ - bind9
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup=markdown
data/Gemfile CHANGED
@@ -1,8 +1,12 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in trenni.gemspec
4
3
  gemspec
5
4
 
5
+ group :development do
6
+ gem "process-daemon"
7
+ end
8
+
6
9
  group :test do
7
- gem "rake"
10
+ gem 'simplecov'
11
+ gem 'coveralls', require: false
8
12
  end
data/README.md CHANGED
@@ -1,144 +1,125 @@
1
1
  # RubyDNS
2
2
 
3
- RubyDNS is a high-performance DNS server which can be easily integrated into other projects or used as a stand-alone daemon (via RExec). By default it uses rule-based pattern matching. Results can be hard-coded, computed, fetched from a remote DNS server or fetched from a local cache, depending on requirements.
3
+ [![Gitter](https://badges.gitter.im/Join+Chat.svg)](https://gitter.im/ioquatix/rubydns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
4
 
5
- In addition, RubyDNS includes a high-performance asynchronous DNS resolver built on top of EventMachine. This module can be used by itself in client applications without using the full RubyDNS server stack.
5
+ RubyDNS is a high-performance DNS server which can be easily integrated into other projects or used as a stand-alone daemon. By default it uses rule-based pattern matching. Results can be hard-coded, computed, fetched from a remote DNS server or fetched from a local cache, depending on requirements.
6
6
 
7
- For examples and documentation please see the main [project page][1].
7
+ [![Build Status](https://travis-ci.org/ioquatix/rubydns.svg)](https://travis-ci.org/ioquatix/rubydns)
8
+ [![Code Climate](https://codeclimate.com/github/ioquatix/rubydns.svg)](https://codeclimate.com/github/ioquatix/rubydns)
9
+ [![Coverage Status](https://coveralls.io/repos/ioquatix/rubydns/badge.svg)](https://coveralls.io/r/ioquatix/rubydns)
8
10
 
9
- [1]: http://www.oriontransfer.co.nz/gems/rubydns
10
-
11
- [![Build Status](https://secure.travis-ci.org/ioquatix/rubydns.png)](http://travis-ci.org/ioquatix/rubydns)
11
+ [![RubyDNS Introduction](http://img.youtube.com/vi/B9ygq0xh3HQ/maxresdefault.jpg)](https://www.youtube.com/watch?v=B9ygq0xh3HQ&feature=youtu.be&hd=1 "RubyDNS Introduction")
12
12
 
13
13
  ## Installation
14
14
 
15
15
  Add this line to your application's Gemfile:
16
16
 
17
- gem 'rubydns'
17
+ gem 'rubydns'
18
18
 
19
19
  And then execute:
20
20
 
21
- $ bundle
21
+ $ bundle
22
22
 
23
23
  Or install it yourself as:
24
24
 
25
- $ gem install rubydns
25
+ $ gem install rubydns
26
26
 
27
27
  ## Usage
28
28
 
29
- This is copied from `test/examples/test-dns-2.rb`. It has been simplified slightly.
29
+ There are [lots of examples available](examples/README.md) in the `examples/` directory.
30
+
31
+ ### Basic DNS Server
32
+
33
+ Here is the code from `examples/basic-dns.rb`:
34
+
30
35
  ```ruby
31
36
  #!/usr/bin/env ruby
32
37
  require 'rubydns'
33
38
 
34
39
  INTERFACES = [
35
- [:udp, "0.0.0.0", 53],
36
- [:tcp, "0.0.0.0", 53]
40
+ [:udp, "0.0.0.0", 5300],
41
+ [:tcp, "0.0.0.0", 5300],
37
42
  ]
38
- Name = Resolv::DNS::Name
43
+
39
44
  IN = Resolv::DNS::Resource::IN
40
45
 
41
46
  # Use upstream DNS for name resolution.
42
47
  UPSTREAM = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
43
48
 
44
- def self.run
45
- # Start the RubyDNS server
46
- RubyDNS::run_server(:listen => INTERFACES) do
47
- match(/test.mydomain.org/, IN::A) do |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
49
+ # Start the RubyDNS server
50
+ RubyDNS::run_server(INTERFACES) do
51
+ match(%r{test.local}, IN::A) do |transaction|
52
+ transaction.respond!("10.0.0.80")
53
+ end
54
+
55
+ # Default DNS handler
56
+ otherwise do |transaction|
57
+ transaction.passthrough!(UPSTREAM)
58
+ end
56
59
  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
60
  ```
65
61
 
66
- ## Compatibility
62
+ Start the server using `RUBYOPT=-w ./examples/basic-dns.rb`. You can then test it using dig:
67
63
 
68
- ### Migrating from RubyDNS 0.5.x to 0.6.x ###
64
+ $ dig @localhost -p 5300 test.local
65
+ $ dig @localhost -p 5300 google.com
69
66
 
70
- The order of arguments to pattern based rules has changed. For regular expression based rules, the arguments are now ordered `|transaction, match_data|`. The main reason for this change was that in many cases match_data is not important and can thus be ignored, e.g. `|transaction|`.
67
+ ### File Handle Limitations
71
68
 
72
- ### Migrating from RubyDNS 0.3.x to 0.4.x ###
69
+ On some platforms (e.g. Mac OS X) the number of file descriptors is relatively low by default and should be increased by calling `ulimit -n 10000` before running tests or even before starting a server which expects a large number of concurrent incoming connections.
73
70
 
74
- 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.
75
- ```ruby
76
- match(..., :A)
77
- ```
78
- becomes
79
- ```ruby
80
- IN = Resolv::DNS::Resource::IN
81
- match(..., IN::A)
82
- ```
83
- ### Migrating from RubyDNS 0.4.x to 0.5.x ###
71
+ ### Custom Servers
84
72
 
85
- 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.
73
+ It is possible to create and integrate your own custom servers, however this functionality has now moved to [`Async::DNS::Server`](https://github.com/socketry/async-dns).
86
74
 
87
- 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:
88
75
  ```ruby
89
- resolver = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
90
-
91
- EventMachine::run do
92
- resolver.query('google.com', IN::A) do |response|
93
- case response
94
- when RubyDNS::Message
95
- puts "Got response: #{response.answers.first}"
96
- else
97
- # Response is of class RubyDNS::ResolutionFailure
98
- puts "Failed: #{response.message}"
99
- end
100
-
101
- EventMachine::stop
76
+ class MyServer < Async::DNS::Server
77
+ def process(name, resource_class, transaction)
78
+ transaction.fail!(:NXDomain)
102
79
  end
103
80
  end
104
- ```
105
- Existing code that uses `Resolv::DNS` as a resolver will need to be updated:
106
- ```ruby
107
- # 1/ Add this at the top of your file; Host specific system information:
108
- require 'rubydns/system'
81
+
82
+ Async::Reactor.run do
83
+ task = MyServer.run
84
+
85
+ # ... do other things
109
86
 
110
- # 2/ Change from R = Resolv::DNS.new to:
111
- R = RubyDNS::Resolver.new(RubyDNS::System::nameservers)
87
+ # Shut down the server:
88
+ task.stop
89
+ end
112
90
  ```
113
- Everything else in the server can remain the same. You can see a complete example in `test/test_resolver.rb`.
114
91
 
115
- #### Deferred Transactions ####
92
+ This is the best way to integrate with other projects.
116
93
 
117
- The implementation of the above depends on a new feature which was added in 0.5.0:
94
+ ## Performance
118
95
 
119
- ```ruby
120
- transaction.defer!
121
- ```
96
+ **Due to changes in the underlying code, there have been some very minor performance regressions. The numbers below will be updated in due course.**
122
97
 
123
- Once you call this, the transaction won't complete until you call either `transaction.succeed` or `transaction.fail`.
124
- ```ruby
125
- RubyDNS::run_server(:listen => SERVER_PORTS) do
126
- match(/\.*.com/, IN::A) do |transaction|
127
- transaction.defer!
128
-
129
- # No domain exists, after 5 seconds:
130
- EventMachine::Timer.new(5) do
131
- transaction.failure!(:NXDomain)
132
- end
133
- end
98
+ We welcome additional benchmarks and feedback regarding RubyDNS performance. To check the current performance results, consult the [travis build job output](https://travis-ci.org/ioquatix/rubydns).
134
99
 
135
- otherwise do
136
- transaction.failure!(:NXDomain)
137
- end
138
- end
139
- ```
100
+ ### Server
101
+
102
+ The performance is on the same magnitude as `bind9`. Some basic benchmarks resolving 1000 names concurrently, repeated 5 times, using `RubyDNS::Resolver` gives the following:
103
+
104
+ user system total real
105
+ RubyDNS::Server 4.280000 0.450000 4.730000 ( 4.854862)
106
+ Bind9 4.970000 0.520000 5.490000 ( 5.541213)
140
107
 
141
- You can see a complete example in `test/test_slow_server.rb`.
108
+ These benchmarks are included in the unit tests. To test bind9 performance, it must be installed and `which named` must return the executable.
109
+
110
+ ### Resolver
111
+
112
+ The `RubyDNS::Resolver` is highly concurrent and can resolve individual names as fast as the built in `Resolv::DNS` resolver. Because the resolver is asynchronous, when dealing with multiple names, it can work more efficiently:
113
+
114
+ user system total real
115
+ RubyDNS::Resolver 0.020000 0.010000 0.030000 ( 0.030507)
116
+ Resolv::DNS 0.070000 0.010000 0.080000 ( 1.465975)
117
+
118
+ These benchmarks are included in the unit tests.
119
+
120
+ ### DNSSEC support
121
+
122
+ DNSSEC is currently not supported and is [unlikely to be supported in the future](http://sockpuppet.org/blog/2015/01/15/against-dnssec/).
142
123
 
143
124
  ## Contributing
144
125
 
@@ -152,12 +133,21 @@ You can see a complete example in `test/test_slow_server.rb`.
152
133
 
153
134
  * Support for more features of DNS such as zone transfer.
154
135
  * Support reverse records more easily.
136
+ * Some kind of system level integration, e.g. registering a DNS server with the currently running system resolver.
137
+
138
+ ## See Also
139
+
140
+ The majority of this gem is now implemented by `async-dns`.
141
+
142
+ - [async-io](https://github.com/socketry/async-io) — Asynchronous networking and sockets.
143
+ - [async-dns](https://github.com/socketry/async-dns) — Asynchronous DNS resolver and server.
144
+ - [async-rspec](https://github.com/socketry/async-rspec) — Shared contexts for running async specs.
155
145
 
156
146
  ## License
157
147
 
158
148
  Released under the MIT license.
159
149
 
160
- Copyright, 2009, 2012, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
150
+ Copyright, 2017, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
161
151
 
162
152
  Permission is hereby granted, free of charge, to any person obtaining a copy
163
153
  of this software and associated documentation files (the "Software"), to deal
data/Rakefile CHANGED
@@ -1,9 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
- require "rake/testtask"
2
+ require "rspec/core/rake_task"
3
3
 
4
- Rake::TestTask.new do |t|
5
- t.libs << 'test'
6
- end
4
+ RSpec::Core::RakeTask.new(:test)
7
5
 
8
- desc "Run tests"
9
6
  task :default => :test