dns-sd 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 81b5b6002fe75561ead81d663d48eedbe850efae
4
- data.tar.gz: 87ed58d93090f140f116841af9401ed4717c3e23
2
+ SHA256:
3
+ metadata.gz: 5fdcb5539e1d98f6f2869ebcf2989a701c8cff786437b4e153523792218dae82
4
+ data.tar.gz: '09c6dc66d34cb711961d8c5828c50c113f963c0cf243367f4367c0ef0699ab71'
5
5
  SHA512:
6
- metadata.gz: 972e8c15c66202907f6207b1616d742cbf096dbc71a41ed1315c820531b13b2f2af1874e6e32c3ad2c821262e1e41f663591bf62b44789c569080778c6273432
7
- data.tar.gz: 92e840beed3d2c919085f80651d8a188a348bcbac18977418d5e7cff9dd1a96ef967c4402b165db2b29363367de1fc4239c72ae4b0ac3f0c403ac944ed84ae04
6
+ metadata.gz: ce4db6e3274d9c635b1f0be3a12caf4ec8143c11857963a5e1d1f03bc9162732872e1a9da7faf946b4e85954eb32fd1460624af71280a45422c13f1a4ed4c61b
7
+ data.tar.gz: 24ca5820b7d7a289d98d5e9a2b8a371804697dc4a815338cefa9ce947d148743c801d433ed8b4bd52e3b11c45c3c699875ac65fad8e36dbd452b14d1da3b1dcd
data/.gitignore CHANGED
@@ -4,3 +4,5 @@
4
4
  /.yardoc
5
5
  /coverage
6
6
  /.bundle
7
+
8
+ .rubocop-https---raw-githubusercontent-com-discourse-discourse-master--rubocop-yml
data/.rubocop.yml CHANGED
@@ -1,104 +1 @@
1
- AllCops:
2
- TargetRubyVersion: 2.4
3
- DisabledByDefault: true
4
-
5
- # Prefer &&/|| over and/or.
6
- Style/AndOr:
7
- Enabled: true
8
-
9
- # Do not use braces for hash literals when they are the last argument of a
10
- # method call.
11
- Style/BracesAroundHashParameters:
12
- Enabled: true
13
-
14
- # Align `when` with `case`.
15
- Layout/CaseIndentation:
16
- Enabled: true
17
-
18
- # Align comments with method definitions.
19
- Layout/CommentIndentation:
20
- Enabled: true
21
-
22
- # No extra empty lines.
23
- Layout/EmptyLines:
24
- Enabled: true
25
-
26
- # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
27
- Style/HashSyntax:
28
- Enabled: true
29
-
30
- # Two spaces, no tabs (for indentation).
31
- Layout/IndentationWidth:
32
- Enabled: true
33
-
34
- Layout/SpaceAfterColon:
35
- Enabled: true
36
-
37
- Layout/SpaceAfterComma:
38
- Enabled: true
39
-
40
- Layout/SpaceAroundEqualsInParameterDefault:
41
- Enabled: true
42
-
43
- Layout/SpaceAroundKeyword:
44
- Enabled: true
45
-
46
- Layout/SpaceAroundOperators:
47
- Enabled: true
48
-
49
- Layout/SpaceBeforeFirstArg:
50
- Enabled: true
51
-
52
- # Defining a method with parameters needs parentheses.
53
- Style/MethodDefParentheses:
54
- Enabled: true
55
-
56
- # Use `foo {}` not `foo{}`.
57
- Layout/SpaceBeforeBlockBraces:
58
- Enabled: true
59
-
60
- # Use `foo { bar }` not `foo {bar}`.
61
- Layout/SpaceInsideBlockBraces:
62
- Enabled: true
63
-
64
- # Use `{ a: 1 }` not `{a:1}`.
65
- Layout/SpaceInsideHashLiteralBraces:
66
- Enabled: true
67
-
68
- Layout/SpaceInsideParens:
69
- Enabled: true
70
-
71
- # Detect hard tabs, no hard tabs.
72
- Layout/Tab:
73
- Enabled: true
74
-
75
- # Blank lines should not have any spaces.
76
- Layout/TrailingBlankLines:
77
- Enabled: true
78
-
79
- # No trailing whitespace.
80
- Layout/TrailingWhitespace:
81
- Enabled: true
82
-
83
- Lint/BlockAlignment:
84
- Enabled: true
85
-
86
- # Align `end` with the matching keyword or starting expression except for
87
- # assignments, where it should be aligned with the LHS.
88
- Lint/EndAlignment:
89
- Enabled: true
90
- EnforcedStyleAlignWith: variable
91
-
92
- # Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
93
- Lint/RequireParentheses:
94
- Enabled: true
95
-
96
- Layout/MultilineMethodCallIndentation:
97
- Enabled: true
98
- EnforcedStyle: indented
99
-
100
- Layout/AlignHash:
101
- Enabled: true
102
-
103
- Bundler/OrderedGems:
104
- Enabled: false
1
+ inherit_from: https://raw.githubusercontent.com/discourse/discourse/master/.rubocop.yml
data/CONTRIBUTING.md CHANGED
@@ -3,11 +3,11 @@
3
3
 
4
4
  * If you have found a discrepancy in documented and observed behaviour, that
5
5
  is a bug. Feel free to [report it as an
6
- issue](https://github.com/discourse/ddns-sd/issues), providing
6
+ issue](https://github.com/discourse/dns-sd/issues), providing
7
7
  sufficient detail to reproduce the problem.
8
8
 
9
9
  * If you would like to add new behaviour, please submit a well-tested and
10
10
  well-documented [pull
11
- request](https://github.com/discourse/ddns-sd/pulls).
11
+ request](https://github.com/discourse/dns-sd/pulls).
12
12
 
13
13
  * At all times, abide by the Code of Conduct (CODE_OF_CONDUCT.md).
@@ -3,6 +3,7 @@ require 'dns-sd/service'
3
3
  require 'dns-sd/target'
4
4
 
5
5
  require 'resolv'
6
+ require 'digest/md5'
6
7
 
7
8
  class DNSSD
8
9
  # A single instance of a service.
@@ -93,11 +94,30 @@ class DNSSD
93
94
  # but also because it'll ensure that the weight-based randomisation of the
94
95
  # server list is respected.
95
96
  #
97
+ # @param deterministic [String] (Optional) If provided, use the given string
98
+ # to create a seed to use when shuffling the records so that each time this
99
+ # method is called, the same set of records will be shuffled into the same
100
+ # order. By default, each time this method is called, records are (probably)
101
+ # returned in a different order.
102
+ #
96
103
  # @return [Array<DNSSD::Target>]
97
- def targets
104
+ def targets(deterministic: nil)
98
105
  [].tap do |list|
99
106
  left = cached_resources(@fqdn, Resolv::DNS::Resource::IN::SRV)
100
107
 
108
+ seed = if deterministic
109
+ left = left.sort_by { |rr| [rr.target.to_s, rr.port] }
110
+
111
+ Digest::MD5.hexdigest(
112
+ deterministic.to_s +
113
+ left.map { |rr| [rr.target.to_s, rr.port, rr.priority, rr.weight] }.inspect
114
+ ).hex
115
+ else
116
+ Random.new_seed
117
+ end
118
+
119
+ prng = Random.new(seed)
120
+
101
121
  # Happily, this algorithm, whilst a bit involved, maps quite directly
102
122
  # to the description from RFC2782, page 4, of which parts are quoted as
103
123
  # appropriate below. A practical example of how this process runs is
@@ -135,7 +155,7 @@ class DNSSD
135
155
  # > associate the running sum in the selected order. Then choose a
136
156
  # > uniform random number between 0 and the sum computed
137
157
  # > (inclusive)
138
- selector = rand(candidates.inject(1) { |n, rr| n + rr.weight })
158
+ selector = prng.rand(candidates.inject(1) { |n, rr| n + rr.weight })
139
159
 
140
160
  # > select the RR whose running sum value is the first in the
141
161
  # > selected order which is greater than or equal to the random
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dns-sd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Palmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-03 00:00:00.000000000 Z
11
+ date: 2019-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -206,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  version: '0'
207
207
  requirements: []
208
208
  rubyforge_project:
209
- rubygems_version: 2.6.13
209
+ rubygems_version: 2.7.7
210
210
  signing_key:
211
211
  specification_version: 4
212
212
  summary: Query RFC6763 DNS-SD records