em-udns-multi 0.0.1
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +1 -0
- data/em-udns-multi.gemspec +23 -0
- data/lib/em-udns-multi.rb +57 -0
- metadata +69 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Joshua M. Keyes
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# EventMachine::Udns::Multi
|
2
|
+
|
3
|
+
Aggregate a large number of asynchronous DNS queries together using `em-udns`.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'em-udns-multi'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install em-udns-multi
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
The following example is trivial but can be expanded on significantly.
|
22
|
+
|
23
|
+
#!/usr/bin/env ruby
|
24
|
+
|
25
|
+
require 'eventmachine'
|
26
|
+
require 'em-udns'
|
27
|
+
require 'em-udns-multi'
|
28
|
+
|
29
|
+
EventMachine.run do
|
30
|
+
# Create an aggregate resolver that must complete within 250ms.
|
31
|
+
resolver = EventMachine::Udns::Multi.new(0.250)
|
32
|
+
|
33
|
+
resolver.callback do |results|
|
34
|
+
puts "[x] Got a response: #{results.inspect}"
|
35
|
+
EventMachine.stop
|
36
|
+
end
|
37
|
+
|
38
|
+
resolver.query(:google, 'google.com', 'A')
|
39
|
+
end
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'em-udns-multi'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "em-udns-multi"
|
8
|
+
gem.version = EventMachine::Udns::Multi::VERSION
|
9
|
+
|
10
|
+
gem.authors = ["Joshua M. Keyes"]
|
11
|
+
gem.email = ["joshua.michael.keyes@gmail.com"]
|
12
|
+
|
13
|
+
gem.description = %q{Aggregate a large number of Udns queries together.}
|
14
|
+
gem.summary = %q{Aggregate DNS queries with EM::Udns.}
|
15
|
+
gem.homepage = "https://github.com/jmkeyes/em-udns-multi"
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split($/)
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
|
22
|
+
gem.add_dependency 'em-udns'
|
23
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'em-udns'
|
2
|
+
|
3
|
+
module EventMachine::Udns
|
4
|
+
class Multi
|
5
|
+
include EventMachine::Deferrable
|
6
|
+
|
7
|
+
VERSION = "0.0.1"
|
8
|
+
|
9
|
+
def initialize(timeout = nil)
|
10
|
+
@responses, @pending = {}, []
|
11
|
+
|
12
|
+
EventMachine.next_tick do
|
13
|
+
# Initialize the resolver.
|
14
|
+
EventMachine::Udns.run(resolver)
|
15
|
+
|
16
|
+
# Since udns's timeout is private, use our own.
|
17
|
+
on_timeout = proc { cancel_pending_queries! }
|
18
|
+
EventMachine::Timer.new(timeout, &on_timeout) if timeout
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def query(name, target, type = 'A')
|
23
|
+
raise "EM::Udns doesn't know about #{type} records!" unless known_record_type?(type)
|
24
|
+
|
25
|
+
# When a result comes in, add it to the list or results.
|
26
|
+
on_any_response = proc { |result| update_progress!(name, result) }
|
27
|
+
|
28
|
+
# Add this query to the list of pending ones, so the timer can cancel them if necessary.
|
29
|
+
@pending << @resolver.send("submit_#{type}", target).tap do |this|
|
30
|
+
this.callback(&on_any_response)
|
31
|
+
this.errback(&on_any_response)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def finished?
|
36
|
+
resolver.active == 0
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def resolver
|
41
|
+
@resolver ||= EventMachine::Udns::Resolver.new
|
42
|
+
end
|
43
|
+
|
44
|
+
def known_record_type?(type)
|
45
|
+
resolver.respond_to?("submit_#{type}")
|
46
|
+
end
|
47
|
+
|
48
|
+
def update_progress!(name, result = nil)
|
49
|
+
@responses[name] = result
|
50
|
+
succeed(@responses) if finished?
|
51
|
+
end
|
52
|
+
|
53
|
+
def cancel_pending_queries!
|
54
|
+
@pending.each { |query| resolver.cancel(query) }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: em-udns-multi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Joshua M. Keyes
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-03-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: em-udns
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Aggregate a large number of Udns queries together.
|
31
|
+
email:
|
32
|
+
- joshua.michael.keyes@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- em-udns-multi.gemspec
|
43
|
+
- lib/em-udns-multi.rb
|
44
|
+
homepage: https://github.com/jmkeyes/em-udns-multi
|
45
|
+
licenses: []
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.8.23
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Aggregate DNS queries with EM::Udns.
|
68
|
+
test_files: []
|
69
|
+
has_rdoc:
|