rubydns 0.8.4 → 0.8.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 204ba4e799634855d87e3a5b0d4969e17b7aafcf
4
- data.tar.gz: 55f9a962495018de41eeb37656b61d2e9580e519
3
+ metadata.gz: 579892157e10443cf4e2959ff42da5f6d312a59b
4
+ data.tar.gz: eadc76b6e5c1bbc199aaecc6beae5ea6836ece29
5
5
  SHA512:
6
- metadata.gz: 9a08e54d3e38cb82e735a65750dae55452c94115d28a1ea115452069afacb6ac978645de0dd25a547c65168703249df4a6f5bbb75254e8a4d5b1e368db58229d
7
- data.tar.gz: 18220b387aec7b2b145f1af7760947b08aee115ab87a8e04fdbc34d0d230c0d49a3396c0252b3e87bf94d956982bba1aa905106f368059db6c286fbb42c03924
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", 53],
37
- [:tcp, "0.0.0.0", 53]
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
- def startup
46
- # Start the RubyDNS server
47
- RubyDNS::run_server(:listen => INTERFACES) do
48
- match(/test.mydomain.org/, IN::A) do |transaction|
49
- transaction.respond!("10.0.0.80")
50
- end
51
-
52
- # Default DNS handler
53
- otherwise do |transaction|
54
- transaction.passthrough!(UPSTREAM)
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 `rvmsudo ./test.rb`. You can then test it using dig:
57
+ Start the server using `./test.rb`. You can then test it using dig:
61
58
 
62
- $ dig @localhost test1.mydomain.org
63
- $ dig @localhost dev.mydomain.org
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 handle.resume is called.
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
@@ -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
- raise LengthError.new("Malformed message smaller than two bytes received")
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
- raise LengthError.new("Unprocessed data remaining (#{@buffer.size - @processed} bytes unprocessed)")
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
@@ -122,11 +122,29 @@ module RubyDNS
122
122
 
123
123
  # Setup server sockets
124
124
  interfaces.each do |spec|
125
- @logger.info "Listening on #{spec.join(':')}"
126
- if spec[0] == :udp
127
- EventMachine.open_datagram_socket(spec[1], spec[2], UDPHandler, self)
128
- elsif spec[0] == :tcp
129
- EventMachine.start_server(spec[1], spec[2], TCPHandler, self)
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
 
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module RubyDNS
22
- VERSION = "0.8.4"
22
+ VERSION = "0.8.5"
23
23
  end
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
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-05-17 00:00:00.000000000 Z
11
+ date: 2014-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine