rubydns 0.8.4 → 0.8.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -20
- data/lib/rubydns/handler.rb +3 -5
- data/lib/rubydns/server.rb +23 -5
- data/lib/rubydns/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 579892157e10443cf4e2959ff42da5f6d312a59b
|
4
|
+
data.tar.gz: eadc76b6e5c1bbc199aaecc6beae5ea6836ece29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dab4ccffd9bfc4d2ee23be3cee574f1925e152999e754ded886d80b9b45c427815ae7e02bafed735a454706ea76436f91f44f604fe2162198e2ea7a34e5dfbe
|
7
|
+
data.tar.gz: d4d47c5ed9316a1177d42a8cc403d690031c343e10bf0ab0a5b387d02ed8bcfaa91e5bb78c620134d65a18d7bf10233bff9e4269bd4be9dac53f0434b1ef3210
|
data/README.md
CHANGED
@@ -33,8 +33,8 @@ This is copied from `test/examples/test-dns-2.rb`. It has been simplified slight
|
|
33
33
|
require 'rubydns'
|
34
34
|
|
35
35
|
INTERFACES = [
|
36
|
-
[:udp, "0.0.0.0",
|
37
|
-
[:tcp, "0.0.0.0",
|
36
|
+
[:udp, "0.0.0.0", 5300],
|
37
|
+
[:tcp, "0.0.0.0", 5300]
|
38
38
|
]
|
39
39
|
Name = Resolv::DNS::Name
|
40
40
|
IN = Resolv::DNS::Resource::IN
|
@@ -42,26 +42,22 @@ This is copied from `test/examples/test-dns-2.rb`. It has been simplified slight
|
|
42
42
|
# Use upstream DNS for name resolution.
|
43
43
|
UPSTREAM = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
56
|
-
end
|
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
|
57
55
|
end
|
58
|
-
run
|
59
56
|
|
60
|
-
Start the server using
|
57
|
+
Start the server using `./test.rb`. You can then test it using dig:
|
61
58
|
|
62
|
-
$ dig @localhost
|
63
|
-
$ dig @localhost
|
64
|
-
$ dig @localhost google.com
|
59
|
+
$ dig @localhost -p 5300 test.mydomain.org
|
60
|
+
$ dig @localhost -p 5300 google.com
|
65
61
|
|
66
62
|
### File Handle Limitations
|
67
63
|
|
@@ -127,7 +123,7 @@ The asynchronous deferred processing became the default and only method for proc
|
|
127
123
|
|
128
124
|
RubyDNS::run_server(:listen => SERVER_PORTS) do
|
129
125
|
match(/\.*.com/, IN::A) do |transaction|
|
130
|
-
# Won't block and won't continue until
|
126
|
+
# Won't block and won't continue until fiber.resume is called.
|
131
127
|
defer do |fiber|
|
132
128
|
# No domain exists, after 5 seconds:
|
133
129
|
EventMachine::Timer.new(5) do
|
data/lib/rubydns/handler.rb
CHANGED
@@ -96,9 +96,6 @@ module RubyDNS
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
class LengthError < StandardError
|
100
|
-
end
|
101
|
-
|
102
99
|
module TCPHandler
|
103
100
|
include Peername
|
104
101
|
|
@@ -118,8 +115,9 @@ module RubyDNS
|
|
118
115
|
|
119
116
|
# Message includes a 16-bit length field.. we need to see if we have received it yet:
|
120
117
|
if @length == nil
|
118
|
+
# Not enough data received yet...
|
121
119
|
if (@buffer.size - @processed) < 2
|
122
|
-
|
120
|
+
return
|
123
121
|
end
|
124
122
|
|
125
123
|
# Grab the length field:
|
@@ -149,7 +147,7 @@ module RubyDNS
|
|
149
147
|
# Check that all data received was processed.
|
150
148
|
def unbind
|
151
149
|
if @processed != @buffer.size
|
152
|
-
|
150
|
+
@server.logger.debug "Unprocessed data remaining (#{@buffer.size - @processed} bytes unprocessed) on incoming TCP connection."
|
153
151
|
end
|
154
152
|
end
|
155
153
|
end
|
data/lib/rubydns/server.rb
CHANGED
@@ -122,11 +122,29 @@ module RubyDNS
|
|
122
122
|
|
123
123
|
# Setup server sockets
|
124
124
|
interfaces.each do |spec|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
125
|
+
if spec.is_a?(BasicSocket)
|
126
|
+
spec.do_not_reverse_lookup
|
127
|
+
optval = spec.getsockopt(Socket::SOL_SOCKET, Socket::SO_TYPE)
|
128
|
+
protocol = optval.unpack("i")[0]
|
129
|
+
ip = spec.local_address.ip_address
|
130
|
+
port = spec.local_address.ip_port
|
131
|
+
case protocol
|
132
|
+
when Socket::SOCK_DGRAM
|
133
|
+
@logger.info "Attaching to pre-existing UDP socket #{ip}:#{port}"
|
134
|
+
EventMachine.attach(spec, UDPHandler, self)
|
135
|
+
when Socket::SOCK_STREAM
|
136
|
+
@logger.info "Attaching to pre-existing TCP socket #{ip}:#{port}"
|
137
|
+
EventMachine.attach(spec, TCPHandler, self)
|
138
|
+
else
|
139
|
+
@logger.error "Ignoring unknown socket protocol: #{protocol}"
|
140
|
+
end
|
141
|
+
else
|
142
|
+
@logger.info "Listening on #{spec.join(':')}"
|
143
|
+
if spec[0] == :udp
|
144
|
+
EventMachine.open_datagram_socket(spec[1], spec[2], UDPHandler, self)
|
145
|
+
elsif spec[0] == :tcp
|
146
|
+
EventMachine.start_server(spec[1], spec[2], TCPHandler, self)
|
147
|
+
end
|
130
148
|
end
|
131
149
|
end
|
132
150
|
|
data/lib/rubydns/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubydns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|