sparoid 1.0.15 → 1.0.16

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
2
  SHA256:
3
- metadata.gz: a696807043c46908b4bbeeb6e8636e33cea95673930442bfc24a3151fc190d28
4
- data.tar.gz: 5e2b64879d91183c6248e28f7fb6faf95ad8f249983f1d675ea17a4c74970758
3
+ metadata.gz: 11677eb6c66244eed7b68e11a2d543db02020701b990a3fdec1c6e230df7f883
4
+ data.tar.gz: 3a3c8c05b72ae568bf7edb0ff95e37fa60cb9173380283e626f07455d24e9064
5
5
  SHA512:
6
- metadata.gz: a9a278830be195e3534b076860bd775406bfd338dae9f5e1083f0bf7f66c17d779c169b5dde140e54690b544363a64538f91f108b3178f053714a362d960d1a2
7
- data.tar.gz: 32a8a77fb600b7f294b57a30f290e4fa9541ce27a94672173788db61211e2d9101ff7867476cbba08be3e38619cd5709534b2ad8caa896a6396e7280c6c03f51
6
+ metadata.gz: bc14a72d7d060bad1b0bb813987a66c9464e89cb8e8dcd58cff28a91130560d91e3a5d5c49182be4465f0a8d3499f7d87e564a78b1abcf2576c4aa0bc3610550
7
+ data.tar.gz: b9dffb39f58ae71e43a54aa1417c0a1f69e25f398c6354497243b01a2f5604c26023624dffc33c3b55b7f8065c29789ef34f252298feb3f883d44ac5cc58f19a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [1.0.16] - 2021-08-23
2
+
3
+ - Resolv host IPs before generating message (in case resolving takes a lot of time)
4
+
1
5
  ## [1.0.15] - 2021-08-11
2
6
 
3
7
  - Raise an exception, don't abort, when resolving hostname fails
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sparoid
4
- VERSION = "1.0.15"
4
+ VERSION = "1.0.16"
5
5
  end
data/lib/sparoid.rb CHANGED
@@ -13,9 +13,12 @@ module Sparoid
13
13
 
14
14
  # Send an authorization packet
15
15
  def auth(key, hmac_key, host, port)
16
+ ips = Resolv.getaddresses(host)
17
+ raise(Error, "Sparoid failed to resolv #{host}") if ips.empty?
18
+
16
19
  msg = message(cached_public_ip)
17
20
  data = prefix_hmac(hmac_key, encrypt(key, msg))
18
- sendmsg(host, port, data)
21
+ sendmsg(ips, port, data)
19
22
 
20
23
  # wait some time for the server to actually open the port
21
24
  # if we don't wait the next SYN package will be dropped
@@ -41,18 +44,15 @@ module Sparoid
41
44
 
42
45
  private
43
46
 
44
- def sendmsg(host, port, data) # rubocop:disable Metrics/MethodLength
45
- ok = false
47
+ def sendmsg(ips, port, data)
46
48
  UDPSocket.open do |socket|
47
- Resolv.each_address(host) do |ip|
48
- ok = true
49
+ ips.each do |ip|
49
50
  socket.connect ip, port
50
51
  socket.sendmsg data, 0
51
52
  rescue StandardError => e
52
53
  warn "Sparoid error: #{e.message}"
53
54
  end
54
55
  end
55
- raise Error, "Sparoid failed to resolv #{host}" unless ok
56
56
  end
57
57
 
58
58
  def encrypt(key, data)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sparoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.15
4
+ version: 1.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Hörberg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-11 00:00:00.000000000 Z
11
+ date: 2021-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor