async-dns 1.2.1 → 1.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/async/dns/extensions/resolv.rb +1 -2
- data/lib/async/dns/handler.rb +11 -9
- data/lib/async/dns/resolver.rb +6 -4
- data/lib/async/dns/server.rb +1 -1
- data/lib/async/dns/transport.rb +27 -51
- data/lib/async/dns/version.rb +1 -1
- metadata +50 -75
- data/.editorconfig +0 -6
- data/.gitignore +0 -14
- data/.rspec +0 -3
- data/.travis.yml +0 -27
- data/Gemfile +0 -18
- data/README.md +0 -148
- data/Rakefile +0 -32
- data/async-dns.gemspec +0 -31
- data/examples/cloudflare.rb +0 -24
- data/spec/async/dns/handler_spec.rb +0 -60
- data/spec/async/dns/hosts.txt +0 -2
- data/spec/async/dns/ipv6_spec.rb +0 -78
- data/spec/async/dns/junk_server_context.rb +0 -62
- data/spec/async/dns/message_spec.rb +0 -56
- data/spec/async/dns/origin_spec.rb +0 -106
- data/spec/async/dns/replace_spec.rb +0 -44
- data/spec/async/dns/resolver_performance_spec.rb +0 -108
- data/spec/async/dns/resolver_spec.rb +0 -104
- data/spec/async/dns/server/bind9/generate-local.rb +0 -25
- data/spec/async/dns/server/bind9/local.zone +0 -5014
- data/spec/async/dns/server/bind9/named.conf +0 -14
- data/spec/async/dns/server/bind9/named.run +0 -0
- data/spec/async/dns/server/million.rb +0 -83
- data/spec/async/dns/server_performance_spec.rb +0 -159
- data/spec/async/dns/slow_server_spec.rb +0 -97
- data/spec/async/dns/socket_spec.rb +0 -72
- data/spec/async/dns/system_spec.rb +0 -57
- data/spec/async/dns/transaction_spec.rb +0 -140
- data/spec/async/dns/truncation_spec.rb +0 -61
- data/spec/spec_helper.rb +0 -57
data/.travis.yml
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
dist: xenial
|
3
|
-
|
4
|
-
cache: bundler
|
5
|
-
|
6
|
-
addons:
|
7
|
-
apt:
|
8
|
-
packages:
|
9
|
-
- bind9
|
10
|
-
|
11
|
-
before_script:
|
12
|
-
- sudo sh -c 'echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6'
|
13
|
-
|
14
|
-
matrix:
|
15
|
-
include:
|
16
|
-
- rvm: 2.3
|
17
|
-
- rvm: 2.4
|
18
|
-
- rvm: 2.5
|
19
|
-
- rvm: 2.6
|
20
|
-
- rvm: truffleruby
|
21
|
-
- rvm: jruby-head
|
22
|
-
env: JRUBY_OPTS="--debug -X+O"
|
23
|
-
- rvm: ruby-head
|
24
|
-
allow_failures:
|
25
|
-
- rvm: ruby-head
|
26
|
-
- rvm: truffleruby
|
27
|
-
- rvm: jruby-head
|
data/Gemfile
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
gemspec
|
4
|
-
|
5
|
-
group :development do
|
6
|
-
gem "pry"
|
7
|
-
end
|
8
|
-
|
9
|
-
group :test do
|
10
|
-
gem 'ruby-prof', platforms: [:mri]
|
11
|
-
gem "benchmark-ips"
|
12
|
-
|
13
|
-
gem 'simplecov'
|
14
|
-
gem 'coveralls', require: false
|
15
|
-
|
16
|
-
# For comparisons:
|
17
|
-
gem "nokogiri"
|
18
|
-
end
|
data/README.md
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
# Async::DNS
|
2
|
-
|
3
|
-
Async::DNS is a high-performance DNS client resolver and server which can be easily integrated into other projects or used as a stand-alone daemon. It was forked from [RubyDNS] which is now implemented in terms of this library.
|
4
|
-
|
5
|
-
[RubyDNS]: https://github.com/ioquatix/rubydns
|
6
|
-
|
7
|
-
[![Build Status](https://secure.travis-ci.org/socketry/async-dns.svg)](http://travis-ci.org/socketry/async-dns)
|
8
|
-
[![Code Climate](https://codeclimate.com/github/socketry/async-dns.svg)](https://codeclimate.com/github/socketry/async-dns)
|
9
|
-
[![Coverage Status](https://coveralls.io/repos/socketry/async-dns/badge.svg)](https://coveralls.io/r/socketry/async-dns)
|
10
|
-
|
11
|
-
## Installation
|
12
|
-
|
13
|
-
Add this line to your application's Gemfile:
|
14
|
-
|
15
|
-
gem 'async-dns'
|
16
|
-
|
17
|
-
And then execute:
|
18
|
-
|
19
|
-
$ bundle
|
20
|
-
|
21
|
-
Or install it yourself as:
|
22
|
-
|
23
|
-
$ gem install async-dns
|
24
|
-
|
25
|
-
## Usage
|
26
|
-
|
27
|
-
### Resolver
|
28
|
-
|
29
|
-
Here is a simple example showing how to use the resolver:
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
Async::Reactor.run do
|
33
|
-
resolver = Async::DNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
|
34
|
-
|
35
|
-
addresses = resolver.addresses_for("www.google.com.")
|
36
|
-
|
37
|
-
puts addresses.inspect
|
38
|
-
end
|
39
|
-
=> [#<Resolv::IPv4 202.124.127.240>, #<Resolv::IPv4 202.124.127.216>, #<Resolv::IPv4 202.124.127.223>, #<Resolv::IPv4 202.124.127.227>, #<Resolv::IPv4 202.124.127.234>, #<Resolv::IPv4 202.124.127.230>, #<Resolv::IPv4 202.124.127.208>, #<Resolv::IPv4 202.124.127.249>, #<Resolv::IPv4 202.124.127.219>, #<Resolv::IPv4 202.124.127.218>, #<Resolv::IPv4 202.124.127.212>, #<Resolv::IPv4 202.124.127.241>, #<Resolv::IPv4 202.124.127.238>, #<Resolv::IPv4 202.124.127.245>, #<Resolv::IPv4 202.124.127.251>, #<Resolv::IPv4 202.124.127.229>]
|
40
|
-
```
|
41
|
-
|
42
|
-
### Server
|
43
|
-
|
44
|
-
Here is a simple example showing how to use the server:
|
45
|
-
|
46
|
-
```ruby
|
47
|
-
require 'async/dns'
|
48
|
-
|
49
|
-
class TestServer < Async::DNS::Server
|
50
|
-
def process(name, resource_class, transaction)
|
51
|
-
@resolver ||= Async::DNS::Resolver.new([[:udp, '8.8.8.8', 53], [:tcp, '8.8.8.8', 53]])
|
52
|
-
|
53
|
-
transaction.passthrough!(@resolver)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
server = TestServer.new([[:udp, '127.0.0.1', 2346]])
|
58
|
-
|
59
|
-
server.run
|
60
|
-
```
|
61
|
-
|
62
|
-
Then to test you could use `dig` like so:
|
63
|
-
|
64
|
-
dig @localhost -p 2346 google.com
|
65
|
-
|
66
|
-
## FAQ
|
67
|
-
|
68
|
-
### File Handle Limitations
|
69
|
-
|
70
|
-
I get the error `Errno::EMFILE: Too many open files - socket(2) - udp` when trying to run a server. What should I do?
|
71
|
-
|
72
|
-
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
|
-
|
74
|
-
### Server
|
75
|
-
|
76
|
-
The performance is on the same magnitude as `bind9`. Some basic benchmarks resolving 1000 names concurrently, repeated 5 times, using `Async::DNS::Resolver` gives the following:
|
77
|
-
|
78
|
-
user system total real
|
79
|
-
Async::DNS::Server 4.280000 0.450000 4.730000 ( 4.854862)
|
80
|
-
Bind9 4.970000 0.520000 5.490000 ( 5.541213)
|
81
|
-
|
82
|
-
These benchmarks are included in the unit tests. To test bind9 performance, it must be installed and `which named` must return the executable.
|
83
|
-
|
84
|
-
|
85
|
-
## Performance
|
86
|
-
|
87
|
-
We welcome additional benchmarks and feedback regarding Async::DNS performance. To check the current performance results, consult the [travis build job output](https://travis-ci.org/socketry/async-dns).
|
88
|
-
|
89
|
-
### Resolver
|
90
|
-
|
91
|
-
The `Async::DNS::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:
|
92
|
-
|
93
|
-
user system total real
|
94
|
-
Async::DNS::Resolver 0.020000 0.010000 0.030000 ( 0.030507)
|
95
|
-
Resolv::DNS 0.070000 0.010000 0.080000 ( 1.465975)
|
96
|
-
|
97
|
-
These benchmarks are included in the unit tests.
|
98
|
-
|
99
|
-
### Server
|
100
|
-
|
101
|
-
The performance is on the same magnitude as `bind9`. Some basic benchmarks resolving 1000 names concurrently, repeated 5 times, using `Async::DNS::Resolver` gives the following:
|
102
|
-
|
103
|
-
user system total real
|
104
|
-
Async::DNS::Server 4.280000 0.450000 4.730000 ( 4.854862)
|
105
|
-
Bind9 4.970000 0.520000 5.490000 ( 5.541213)
|
106
|
-
|
107
|
-
These benchmarks are included in the unit tests. To test bind9 performance, it must be installed and `which named` must return the executable.
|
108
|
-
|
109
|
-
### DNSSEC support
|
110
|
-
|
111
|
-
DNSSEC is currently not supported and is [unlikely to be supported in the future](http://sockpuppet.org/blog/2015/01/15/against-dnssec/). Feel free to submit a PR.
|
112
|
-
|
113
|
-
## Contributing
|
114
|
-
|
115
|
-
1. Fork it
|
116
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
117
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
118
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
119
|
-
5. Create new Pull Request
|
120
|
-
|
121
|
-
### Desired Features
|
122
|
-
|
123
|
-
* Support for more features of DNS such as zone transfer.
|
124
|
-
* Some kind of system level integration, e.g. registering a DNS server with the currently running system resolver.
|
125
|
-
|
126
|
-
## License
|
127
|
-
|
128
|
-
Released under the MIT license.
|
129
|
-
|
130
|
-
Copyright, 2015, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
131
|
-
|
132
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
133
|
-
of this software and associated documentation files (the "Software"), to deal
|
134
|
-
in the Software without restriction, including without limitation the rights
|
135
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
136
|
-
copies of the Software, and to permit persons to whom the Software is
|
137
|
-
furnished to do so, subject to the following conditions:
|
138
|
-
|
139
|
-
The above copyright notice and this permission notice shall be included in
|
140
|
-
all copies or substantial portions of the Software.
|
141
|
-
|
142
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
143
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
144
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
145
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
146
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
147
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
148
|
-
THE SOFTWARE.
|
data/Rakefile
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
require "rspec/core/rake_task"
|
3
|
-
|
4
|
-
RSpec::Core::RakeTask.new(:test)
|
5
|
-
|
6
|
-
task :default => :test
|
7
|
-
|
8
|
-
task :console do
|
9
|
-
require 'pry'
|
10
|
-
|
11
|
-
require_relative 'lib/async/dns'
|
12
|
-
|
13
|
-
Pry.start
|
14
|
-
end
|
15
|
-
|
16
|
-
task :server do
|
17
|
-
require_relative 'lib/async/dns'
|
18
|
-
|
19
|
-
class TestServer < Async::DNS::Server
|
20
|
-
def process(name, resource_class, transaction)
|
21
|
-
@resolver ||= Async::DNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
|
22
|
-
|
23
|
-
transaction.passthrough!(@resolver)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
server = TestServer.new([[:udp, '127.0.0.1', 2346]])
|
28
|
-
|
29
|
-
Async::Reactor.run do
|
30
|
-
server.run
|
31
|
-
end
|
32
|
-
end
|
data/async-dns.gemspec
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
|
2
|
-
require_relative 'lib/async/dns/version'
|
3
|
-
|
4
|
-
Gem::Specification.new do |spec|
|
5
|
-
spec.name = "async-dns"
|
6
|
-
spec.version = Async::DNS::VERSION
|
7
|
-
spec.authors = ["Samuel Williams"]
|
8
|
-
spec.email = ["samuel.williams@oriontransfer.co.nz"]
|
9
|
-
spec.description = <<-EOF
|
10
|
-
Async::DNS provides a high-performance DNS client resolver and server
|
11
|
-
which can be easily integrated into other projects or used as a stand-alone
|
12
|
-
daemon.
|
13
|
-
EOF
|
14
|
-
spec.summary = "An easy to use DNS client resolver and server for Ruby."
|
15
|
-
spec.homepage = "https://github.com/async/async-dns"
|
16
|
-
spec.license = "MIT"
|
17
|
-
|
18
|
-
spec.files = `git ls-files`.split($/)
|
19
|
-
spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
20
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
-
spec.require_paths = ["lib"]
|
22
|
-
|
23
|
-
spec.add_dependency("async-io", "~> 1.15")
|
24
|
-
|
25
|
-
spec.add_development_dependency "async-rspec", "~> 1.0"
|
26
|
-
spec.add_development_dependency "process-daemon", "~> 1.0"
|
27
|
-
|
28
|
-
spec.add_development_dependency "bundler"
|
29
|
-
spec.add_development_dependency "rspec", "~> 3.6"
|
30
|
-
spec.add_development_dependency "rake"
|
31
|
-
end
|
data/examples/cloudflare.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
gem 'async'
|
4
|
-
gem 'async-http'
|
5
|
-
gem 'trenni'
|
6
|
-
|
7
|
-
require 'async/reactor'
|
8
|
-
require 'async/http/client'
|
9
|
-
require 'async/http/url_endpoint'
|
10
|
-
|
11
|
-
require 'trenni/uri'
|
12
|
-
|
13
|
-
endpoint = Async::HTTP::URLEndpoint.parse("https://cloudflare-dns.com/dns-query")
|
14
|
-
client = Async::HTTP::Client.new(endpoint)
|
15
|
-
|
16
|
-
Async::Reactor.run do |task|
|
17
|
-
request_uri = Trenni::URI(endpoint.url.request_uri, ct: "application/dns-json", name: "microsoft.com", type: "MX")
|
18
|
-
|
19
|
-
puts "GET #{request_uri}"
|
20
|
-
response = client.get(request_uri.to_s, {})
|
21
|
-
|
22
|
-
puts "#{response.status} #{response.version} #{response.headers.inspect}"
|
23
|
-
puts response.read.inspect
|
24
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require 'async/dns'
|
22
|
-
require 'async/dns/system'
|
23
|
-
|
24
|
-
describe Async::DNS::StreamHandler do
|
25
|
-
include_context Async::RSpec::Reactor
|
26
|
-
|
27
|
-
let(:server) {Async::DNS::Server.new}
|
28
|
-
let(:endpoint) {Async::IO::Endpoint.tcp('127.0.0.1', 6666, reuse_port: true)}
|
29
|
-
|
30
|
-
it "can rebind port" do
|
31
|
-
2.times do
|
32
|
-
task = reactor.async do
|
33
|
-
endpoint.bind do |socket|
|
34
|
-
described_class.new(server, socket).run
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
task.stop
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe Async::DNS::DatagramHandler do
|
44
|
-
include_context Async::RSpec::Reactor
|
45
|
-
|
46
|
-
let(:server) {Async::DNS::Server.new}
|
47
|
-
let(:endpoint) {Async::IO::Endpoint.udp('127.0.0.1', 6666)}
|
48
|
-
|
49
|
-
it "can rebind port" do
|
50
|
-
2.times do
|
51
|
-
task = reactor.async do
|
52
|
-
endpoint.bind do |socket|
|
53
|
-
described_class.new(server, socket).run
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
task.stop
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
data/spec/async/dns/hosts.txt
DELETED
data/spec/async/dns/ipv6_spec.rb
DELETED
@@ -1,78 +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 'async/dns'
|
24
|
-
require 'async/dns/system'
|
25
|
-
|
26
|
-
module Async::DNS::IPv6Spec
|
27
|
-
IN = Resolv::DNS::Resource::IN
|
28
|
-
|
29
|
-
class TestServer < Async::DNS::Server
|
30
|
-
def process(name, resource_class, transaction)
|
31
|
-
@resolver ||= Async::DNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
|
32
|
-
|
33
|
-
transaction.passthrough!(@resolver)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe Async::DNS::StreamHandler do
|
38
|
-
include_context Async::RSpec::Reactor
|
39
|
-
|
40
|
-
let(:server_interfaces) {[[:tcp, '::', 2004]]}
|
41
|
-
let(:server) {TestServer.new(server_interfaces)}
|
42
|
-
|
43
|
-
it "should connect to the server using TCP via IPv6" do
|
44
|
-
task = server.run
|
45
|
-
|
46
|
-
resolver = Async::DNS::Resolver.new([[:tcp, '::1', 2004]])
|
47
|
-
|
48
|
-
response = resolver.query('google.com')
|
49
|
-
|
50
|
-
expect(response.class).to be == Async::DNS::Message
|
51
|
-
expect(response.rcode).to be == 0
|
52
|
-
expect(response.answer).to_not be_empty
|
53
|
-
|
54
|
-
task.stop
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe Async::DNS::DatagramHandler do
|
59
|
-
include_context Async::RSpec::Reactor
|
60
|
-
|
61
|
-
let(:server_interfaces) {[[:udp, '::', 2006]]}
|
62
|
-
let(:server) {TestServer.new(server_interfaces)}
|
63
|
-
|
64
|
-
it "should connect to the server using UDP via IPv6" do
|
65
|
-
task = server.run
|
66
|
-
|
67
|
-
resolver = Async::DNS::Resolver.new([[:udp, '::1', 2006]])
|
68
|
-
|
69
|
-
response = resolver.query('google.com')
|
70
|
-
|
71
|
-
expect(response.class).to be == Async::DNS::Message
|
72
|
-
expect(response.rcode).to be == 0
|
73
|
-
expect(response.answer).to_not be_empty
|
74
|
-
|
75
|
-
task.stop
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
RSpec.shared_context "Junk UDP Server" do
|
22
|
-
let(:server_endpoint) {Async::IO::Endpoint.udp('0.0.0.0', 6060, reuse_port: true)}
|
23
|
-
|
24
|
-
let!(:server_task) do
|
25
|
-
reactor.async do
|
26
|
-
server_endpoint.bind do |socket|
|
27
|
-
begin
|
28
|
-
while true
|
29
|
-
data, address = socket.recvfrom(1024)
|
30
|
-
socket.send("foobar", 0, address)
|
31
|
-
end
|
32
|
-
rescue
|
33
|
-
socket.close
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
after(:each) do
|
40
|
-
server_task.stop
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
RSpec.shared_context "Junk TCP Server" do
|
45
|
-
let(:server_endpoint) {Async::IO::Endpoint.tcp('0.0.0.0', 6060, reuse_port: true)}
|
46
|
-
|
47
|
-
let!(:server_task) do
|
48
|
-
reactor.async do
|
49
|
-
server_endpoint.accept do |socket|
|
50
|
-
begin
|
51
|
-
socket.write("f\0\0bar")
|
52
|
-
rescue
|
53
|
-
socket.close
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
after(:each) do
|
60
|
-
server_task.stop
|
61
|
-
end
|
62
|
-
end
|