celluloid-dns 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/.coveralls.yml +1 -0
- data/.gitignore +17 -0
- data/.rspec +4 -0
- data/.travis.yml +16 -0
- data/CHANGES.md +3 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +69 -0
- data/Rakefile +5 -0
- data/celluloid-dns.gemspec +23 -0
- data/lib/celluloid/dns.rb +12 -0
- data/lib/celluloid/dns/request.rb +46 -0
- data/lib/celluloid/dns/server.rb +27 -0
- data/lib/celluloid/dns/version.rb +5 -0
- data/logo.png +0 -0
- data/spec/celluloid/dns/server_spec.rb +26 -0
- data/spec/spec_helper.rb +5 -0
- data/tasks/rspec.task +7 -0
- metadata +135 -0
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service-name: travis-pro
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
rvm:
|
2
|
+
- 1.9.3
|
3
|
+
- 2.0.0
|
4
|
+
- ruby-head
|
5
|
+
- jruby-19mode
|
6
|
+
- jruby-head
|
7
|
+
- rbx-19mode
|
8
|
+
|
9
|
+
matrix:
|
10
|
+
allow_failures:
|
11
|
+
- rvm: ruby-head
|
12
|
+
- rvm: jruby-head
|
13
|
+
- rvm: rbx-19mode # deadlocks :(
|
14
|
+
|
15
|
+
notifications:
|
16
|
+
irc: "irc.freenode.org#celluloid"
|
data/CHANGES.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Tony Arcieri
|
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,69 @@
|
|
1
|
+

|
2
|
+
=================
|
3
|
+
[](http://travis-ci.org/celluloid/celluloid-dns)
|
4
|
+
[](https://gemnasium.com/celluloid/celluloid-dns)
|
5
|
+
[](https://codeclimate.com/github/celluloid/celluloid-dns)
|
6
|
+
[](https://coveralls.io/r/celluloid/celluloid-dns)
|
7
|
+
|
8
|
+
Celluloid::DNS is a programmable Celluloid "cell" for answering DNS requests.
|
9
|
+
It's implemented using Celluloid::IO and is great for programatic DNS servers
|
10
|
+
which dynamically generate DNS responses, particularly within Celluloid-based
|
11
|
+
programs.
|
12
|
+
|
13
|
+
A nonblocking DNS client is already built into Celluloid::IO itself.
|
14
|
+
Celluloid::DNS is just for servers.
|
15
|
+
|
16
|
+
Installation
|
17
|
+
------------
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
gem 'celluloid-dns'
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install celluloid-dns
|
30
|
+
|
31
|
+
Inside of your Ruby project, use:
|
32
|
+
|
33
|
+
require 'celluloid/dns'
|
34
|
+
|
35
|
+
...to pull Celluloid::DNS in as a dependency.
|
36
|
+
|
37
|
+
Usage
|
38
|
+
-----
|
39
|
+
|
40
|
+
Start a DNS server that always resolves to `127.0.0.1`:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
require "celluloid/dns"
|
44
|
+
|
45
|
+
Celluloid::DNS::Server.new("127.0.0.1", 1234) do |request|
|
46
|
+
request.answer request.questions.map { |q| [q, "127.0.0.1"] }
|
47
|
+
end
|
48
|
+
|
49
|
+
sleep
|
50
|
+
```
|
51
|
+
|
52
|
+
Query the server:
|
53
|
+
|
54
|
+
$ dig @localhost -p 1234 anything.com
|
55
|
+
|
56
|
+
|
57
|
+
Contributing to Celluloid::DNS
|
58
|
+
------------------------------
|
59
|
+
|
60
|
+
* Fork this repository on github
|
61
|
+
* Make your changes and send me a pull request
|
62
|
+
* If I like them I'll merge them
|
63
|
+
* If I've accepted a patch, feel free to ask for commit access
|
64
|
+
|
65
|
+
License
|
66
|
+
-------
|
67
|
+
|
68
|
+
Copyright (c) 2012 Tony Arcieri. Distributed under the MIT License. See
|
69
|
+
LICENSE.txt for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/celluloid/dns/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Tony Arcieri"]
|
6
|
+
gem.email = ["tony.arcieri@gmail.com"]
|
7
|
+
gem.description = "Celluloid::IO-powered DNS server"
|
8
|
+
gem.summary = "Celluloid::DNS provides a DNS server implemented as a Celluloid cell"
|
9
|
+
gem.homepage = "https://github.com/celluloid/celluloid-dns"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "celluloid-dns"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Celluloid::DNS::VERSION
|
17
|
+
|
18
|
+
gem.add_runtime_dependency 'celluloid', '>= 0.11.0'
|
19
|
+
gem.add_runtime_dependency 'celluloid-io', '>= 0.11.0'
|
20
|
+
|
21
|
+
gem.add_development_dependency 'rake'
|
22
|
+
gem.add_development_dependency 'rspec'
|
23
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'resolv'
|
2
|
+
|
3
|
+
module Celluloid
|
4
|
+
module DNS
|
5
|
+
class Request
|
6
|
+
attr_reader :questions
|
7
|
+
|
8
|
+
def initialize(addr, port, socket, data)
|
9
|
+
@addr, @port, @socket = addr, port, socket
|
10
|
+
@message = Resolv::DNS::Message.decode(data)
|
11
|
+
@questions = @message.question.map { |question, resource| Question.new(question, resource) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def answer(responses)
|
15
|
+
response_message = Resolv::DNS::Message.new @message.id
|
16
|
+
response_message.qr = 1
|
17
|
+
response_message.opcode = @message.opcode
|
18
|
+
response_message.aa = 1
|
19
|
+
response_message.rd = @message.rd
|
20
|
+
response_message.ra = 0
|
21
|
+
response_message.rcode = 0
|
22
|
+
|
23
|
+
responses.each do |question, response|
|
24
|
+
response_object = question.resource.new(response)
|
25
|
+
response_message.add_answer question.name, DEFAULT_TTL, response_object
|
26
|
+
end
|
27
|
+
|
28
|
+
@socket.send response_message.encode, 0, @addr, @port
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Question
|
33
|
+
attr_reader :resource
|
34
|
+
|
35
|
+
def initialize(question, resource)
|
36
|
+
@question, @resource = question, resource
|
37
|
+
end
|
38
|
+
|
39
|
+
# Obtain the name being queried
|
40
|
+
def name
|
41
|
+
raise TypeError, "not a name query" unless @question.is_a? Resolv::DNS::Name
|
42
|
+
@question.to_s
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Celluloid
|
2
|
+
module DNS
|
3
|
+
class Server
|
4
|
+
# Maximum UDP packet we'll accept
|
5
|
+
MAX_PACKET_SIZE = 512
|
6
|
+
|
7
|
+
include Celluloid::IO
|
8
|
+
|
9
|
+
def initialize(addr, port, &block)
|
10
|
+
@block = block
|
11
|
+
|
12
|
+
# Create a non-blocking Celluloid::IO::UDPSocket
|
13
|
+
@socket = UDPSocket.new
|
14
|
+
@socket.bind(addr, port)
|
15
|
+
|
16
|
+
async.run
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
loop do
|
21
|
+
data, (_, port, addr) = @socket.recvfrom(MAX_PACKET_SIZE)
|
22
|
+
@block.call Request.new(addr, port, @socket, data)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/logo.png
ADDED
Binary file
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'resolv'
|
3
|
+
|
4
|
+
describe Celluloid::DNS::Server do
|
5
|
+
let(:example_host) { '127.0.0.1' }
|
6
|
+
let(:example_port) { 54321 }
|
7
|
+
let(:example_name) { 'example.com' }
|
8
|
+
let(:example_ip) { '1.2.3.4' }
|
9
|
+
|
10
|
+
it "answers DNS requests" do
|
11
|
+
server = Celluloid::DNS::Server.new(example_host, example_port) do |request|
|
12
|
+
question = request.questions.first
|
13
|
+
|
14
|
+
question.name.should == example_name
|
15
|
+
request.answer(question => example_ip)
|
16
|
+
end
|
17
|
+
|
18
|
+
begin
|
19
|
+
Resolv::DNS.open(nameserver_port: [[example_host, example_port]]) do |resolv|
|
20
|
+
resolv.getaddress(example_name).to_s.should eq example_ip
|
21
|
+
end
|
22
|
+
ensure
|
23
|
+
server.terminate
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/tasks/rspec.task
ADDED
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: celluloid-dns
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tony Arcieri
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: celluloid
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.11.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.11.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: celluloid-io
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.11.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.11.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Celluloid::IO-powered DNS server
|
79
|
+
email:
|
80
|
+
- tony.arcieri@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .coveralls.yml
|
86
|
+
- .gitignore
|
87
|
+
- .rspec
|
88
|
+
- .travis.yml
|
89
|
+
- CHANGES.md
|
90
|
+
- Gemfile
|
91
|
+
- LICENSE.txt
|
92
|
+
- README.md
|
93
|
+
- Rakefile
|
94
|
+
- celluloid-dns.gemspec
|
95
|
+
- lib/celluloid/dns.rb
|
96
|
+
- lib/celluloid/dns/request.rb
|
97
|
+
- lib/celluloid/dns/server.rb
|
98
|
+
- lib/celluloid/dns/version.rb
|
99
|
+
- logo.png
|
100
|
+
- spec/celluloid/dns/server_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
- tasks/rspec.task
|
103
|
+
homepage: https://github.com/celluloid/celluloid-dns
|
104
|
+
licenses: []
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
hash: -4517379908652224173
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
segments:
|
125
|
+
- 0
|
126
|
+
hash: -4517379908652224173
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 1.8.23
|
130
|
+
signing_key:
|
131
|
+
specification_version: 3
|
132
|
+
summary: Celluloid::DNS provides a DNS server implemented as a Celluloid cell
|
133
|
+
test_files:
|
134
|
+
- spec/celluloid/dns/server_spec.rb
|
135
|
+
- spec/spec_helper.rb
|