celluloid-dns 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ service-name: travis-pro
@@ -0,0 +1,17 @@
1
+ *.gem
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
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --format documentation
3
+ --backtrace
4
+ --default_path spec
@@ -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"
@@ -0,0 +1,3 @@
1
+ 0.0.1 (2013-03-18)
2
+ ------------------
3
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'celluloid', github: 'celluloid/celluloid'
4
+ gem 'celluloid-io', github: 'celluloid/celluloid-io'
5
+
6
+ gem 'coveralls', require: false
7
+
8
+ # Specify your gem's dependencies in celluloid-dns.gemspec
9
+ gemspec
@@ -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.
@@ -0,0 +1,69 @@
1
+ ![Celluloid::DNS](https://github.com/celluloid/celluloid-dns/raw/master/logo.png)
2
+ =================
3
+ [![Build Status](https://secure.travis-ci.org/celluloid/celluloid-dns.png?branch=master)](http://travis-ci.org/celluloid/celluloid-dns)
4
+ [![Dependency Status](https://gemnasium.com/celluloid/celluloid-dns.png)](https://gemnasium.com/celluloid/celluloid-dns)
5
+ [![Code Climate](https://codeclimate.com/github/celluloid/celluloid-dns.png)](https://codeclimate.com/github/celluloid/celluloid-dns)
6
+ [![Coverage Status](https://coveralls.io/repos/celluloid/celluloid-dns/badge.png?branch=master)](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.
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ Dir["tasks/**/*.task"].each { |task| load task }
4
+
5
+ task :default => :spec
@@ -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,12 @@
1
+ require 'celluloid/dns/version'
2
+ require 'celluloid/io'
3
+
4
+ require 'celluloid/dns/request'
5
+ require 'celluloid/dns/server'
6
+
7
+ module Celluloid
8
+ module DNS
9
+ # Default time-to-live for DNS responses
10
+ DEFAULT_TTL = 900
11
+ end
12
+ 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
@@ -0,0 +1,5 @@
1
+ module Celluloid
2
+ module DNS
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
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
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'celluloid/dns'
4
+ require 'coveralls'
5
+ Coveralls.wear!
@@ -0,0 +1,7 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new
4
+
5
+ RSpec::Core::RakeTask.new(:rcov) do |task|
6
+ task.rcov = true
7
+ end
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