zeroconf 1.3.0 → 1.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b9ec7f1320fa0807e2cdb89addcc9b6796745c9248ac0463a72877d908b74f4
4
- data.tar.gz: 3be32a8bdabfc923576ce8ed0b8c9dbf430141aae8be1eaf9bc7898b1f425109
3
+ metadata.gz: 7e5fe766c828fdaf41bdacf9ecce12d863c4a636f7c2292ec3ca8aef89413950
4
+ data.tar.gz: 51786741d2dbc2dffb92a1b4ec25b31a994db81aa1d099dc6f530dded84964e7
5
5
  SHA512:
6
- metadata.gz: b3eedb494ee9507f0e4d541b05f2627fb94d9b63b90d1d1a27f303a901b02fa4c5640719857f35927fd922b511960e753b7e530dc40e30cccf106b0e2cc10168
7
- data.tar.gz: ef7526948bbe2a34ae9a850c48ba0d12760ad4acb846c33f808338c277d184d9056e8681246e7bbb6154ce1cd31398feb9a4336c4dc6835bc36a63c489642c6a
6
+ metadata.gz: 89974e69dce75b540f73e70313944bea011fcfe00bd8519af0cba02cb27e823600325d117efabe2febaac05d8d782edf2ecd5014143e35bfa8a31f27019314bc
7
+ data.tar.gz: e4f99e2f61956d457d2ae10fdb4969e682f86cb959a9bd7f4937c389a160c07c4a8e9f5f4ca4d5dab925390ed3ac80909b3603698c80629b70e83072ef51ea62
data/Rakefile CHANGED
@@ -7,6 +7,5 @@ Bundler::GemHelper.install_tasks
7
7
  Rake::TestTask.new do |t|
8
8
  t.libs << "test"
9
9
  t.test_files = FileList['test/*_test.rb']
10
- t.verbose = true
11
10
  t.warning = true
12
11
  end
@@ -23,18 +23,22 @@ module ZeroConf
23
23
  ::Resolv::DNS::Resource::ClassHash[[TypeValue, ClassValue]] = self # :nodoc:
24
24
  end
25
25
 
26
+ # ZeroConf::A and ZeroConf::SRV are referenced by name when constructing
27
+ # outgoing queries (see ZeroConf::Resolver). They share the numeric
28
+ # ClassValue (0x8001) with the MDNS::Announce::IN equivalents below, so
29
+ # only one of the two should populate Resolv's ClassHash to avoid
30
+ # "already initialized constant" warnings. The MDNS::Announce::IN side
31
+ # owns the registration.
26
32
  class A < Resolv::DNS::Resource::IN::A
27
33
  MDNS_UNICAST_RESPONSE = 0x8000
28
34
 
29
35
  ClassValue = Resolv::DNS::Resource::IN::ClassValue | MDNS_UNICAST_RESPONSE
30
- ClassHash[[TypeValue, ClassValue]] = self # :nodoc:
31
36
  end
32
37
 
33
38
  class SRV < Resolv::DNS::Resource::IN::SRV
34
39
  MDNS_UNICAST_RESPONSE = 0x8000
35
40
 
36
41
  ClassValue = Resolv::DNS::Resource::IN::ClassValue | MDNS_UNICAST_RESPONSE
37
- ClassHash[[TypeValue, ClassValue]] = self # :nodoc:
38
42
  end
39
43
 
40
44
  module MDNS
@@ -1,3 +1,3 @@
1
1
  module ZeroConf
2
- VERSION = "1.3.0"
2
+ VERSION = "1.3.1"
3
3
  end
data/lib/zeroconf.rb CHANGED
@@ -46,7 +46,7 @@ module ZeroConf
46
46
  port = nil
47
47
  ipv4 = []
48
48
  ipv6 = []
49
- r.additional.each { |name, ttl, data|
49
+ (r.answer + r.additional).each { |name, ttl, data|
50
50
  case data
51
51
  when Resolv::DNS::Resource::IN::SRV
52
52
  host = data.target.to_s
data/test/client_test.rb CHANGED
@@ -1,6 +1,45 @@
1
1
  require "helper"
2
2
 
3
3
  module ZeroConf
4
+ # Mimics responders like Nanoleaf which place SRV in the answer section of
5
+ # the PTR response instead of in the additional section. See
6
+ # https://github.com/tenderlove/zeroconf/issues/10
7
+ class NanoleafService < Service
8
+ private
9
+
10
+ def service_unicast_answer
11
+ msg = Resolv::DNS::Message.new(0)
12
+ msg.qr = 1
13
+ msg.aa = 1
14
+
15
+ # SRV goes in ANSWER (Nanoleaf-style), not additional
16
+ msg.add_answer service_name, 10,
17
+ Resolv::DNS::Resource::IN::SRV.new(0, 0, service_port, qualified_host)
18
+
19
+ service_interfaces.each do |iface|
20
+ if iface.addr.ipv4?
21
+ msg.add_additional qualified_host, 10,
22
+ Resolv::DNS::Resource::IN::A.new(iface.addr.ip_address)
23
+ else
24
+ msg.add_additional qualified_host, 10,
25
+ Resolv::DNS::Resource::IN::AAAA.new(iface.addr.ip_address)
26
+ end
27
+ end
28
+
29
+ if @text
30
+ msg.add_additional service_name, 10,
31
+ Resolv::DNS::Resource::IN::TXT.new(*@text)
32
+ end
33
+
34
+ msg.add_answer service, 10,
35
+ Resolv::DNS::Resource::IN::PTR.new(Resolv::DNS::Name.create(service_name))
36
+
37
+ msg.add_question service, PTR
38
+
39
+ msg
40
+ end
41
+ end
42
+
4
43
  class ClientTest < Test
5
44
  attr_reader :iface
6
45
 
@@ -9,6 +48,34 @@ module ZeroConf
9
48
  @iface = ZeroConf.interfaces.find_all { |x| x.addr.ipv4? }.first
10
49
  end
11
50
 
51
+ # Regression test for https://github.com/tenderlove/zeroconf/issues/10
52
+ # If a responder places SRV in the answer section (rather than additional),
53
+ # find_addrinfos must still return a usable [host, Addrinfo] tuple instead
54
+ # of crashing with "no implicit conversion from nil to integer".
55
+ def test_find_addrinfos_with_srv_in_answer
56
+ latch = Queue.new
57
+ s = NanoleafService.new SERVICE + ".",
58
+ 42424,
59
+ HOST_NAME,
60
+ service_interfaces: [iface],
61
+ text: ["test=1", "other=value"],
62
+ started_callback: -> { latch << :start }
63
+ runner = Thread.new { s.start }
64
+ latch.pop
65
+
66
+ addrinfos = ZeroConf.find_addrinfos(SERVICE, timeout: 1)
67
+
68
+ s.stop
69
+ runner.join
70
+
71
+ ours = addrinfos.find { |host, _| host == "#{HOST_NAME}.local" }
72
+ assert ours, "expected to find #{HOST_NAME}.local in #{addrinfos.inspect}"
73
+ host, addr = ours
74
+ assert_equal "#{HOST_NAME}.local", host
75
+ assert_equal 42424, addr.ip_port
76
+ assert_equal iface.addr.ip_address, addr.ip_address
77
+ end
78
+
12
79
  def test_resolve
13
80
  latch = Queue.new
14
81
  s = make_server iface, "coolhostname", started_callback: -> { latch << :start }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zeroconf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  requirements: []
97
- rubygems_version: 4.0.6
97
+ rubygems_version: 4.0.10
98
98
  specification_version: 4
99
99
  summary: Multicast DNS client and server
100
100
  test_files: