sparoid 1.0.12 → 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: 12dad3dbab45bb38650465dab2b26f356c051569b06d20ba1bcfd6af11eb9701
4
- data.tar.gz: 0b17fe457b36978f1b682153cb14578192cb657a846fadcbb3abb2cf82e07bb6
3
+ metadata.gz: 11677eb6c66244eed7b68e11a2d543db02020701b990a3fdec1c6e230df7f883
4
+ data.tar.gz: 3a3c8c05b72ae568bf7edb0ff95e37fa60cb9173380283e626f07455d24e9064
5
5
  SHA512:
6
- metadata.gz: 1c31f7b1fa30e2d064b0e92e79b2b567bdfa4021995d7f52c25b6b4373d08062ed091aab8187aeb42051c11e0c7c1b994d158878e64311eed28e68d1e3fe4008
7
- data.tar.gz: cacd2adf45ed9fa8e31b063809e01cf0371c6d13670e24b5bdb17f7c2623c2f9592c7e38b6df18a5f529db9628d4197baf323a9d58124b8eb6ea75762c3a6d78
6
+ metadata.gz: bc14a72d7d060bad1b0bb813987a66c9464e89cb8e8dcd58cff28a91130560d91e3a5d5c49182be4465f0a8d3499f7d87e564a78b1abcf2576c4aa0bc3610550
7
+ data.tar.gz: b9dffb39f58ae71e43a54aa1417c0a1f69e25f398c6354497243b01a2f5604c26023624dffc33c3b55b7f8065c29789ef34f252298feb3f883d44ac5cc58f19a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ## [1.0.16] - 2021-08-23
2
+
3
+ - Resolv host IPs before generating message (in case resolving takes a lot of time)
4
+
5
+ ## [1.0.15] - 2021-08-11
6
+
7
+ - Raise an exception, don't abort, when resolving hostname fails
8
+
9
+ ## [1.0.14] - 2021-07-26
10
+
11
+ - Send UDP packets to all resolved IPs for a hostname
12
+
13
+ ## [1.0.13] - 2021-06-30
14
+
15
+ - Do not warn on empty public ip cache file
16
+ - The public ip cache file path can be controlled using the `SPAROID_CACHE_PATH` environment variable
17
+
1
18
  ## [1.0.12] - 2021-06-14
2
19
 
3
20
  - Use file locking to prevent multiple processes/threads to write to the public ip cache file
@@ -8,7 +25,7 @@
8
25
 
9
26
  ## [1.0.10] - 2021-06-09
10
27
 
11
- - Cache public IP in /tmp/.sparoid_public_ip for 1 min
28
+ - Cache public IP in `/tmp/.sparoid_public_ip` for 1 min
12
29
 
13
30
  ## [1.0.9] - 2021-05-23
14
31
 
data/Gemfile CHANGED
@@ -5,12 +5,9 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in sparoid.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
9
-
10
8
  gem "minitest", "~> 5.0"
11
-
9
+ gem "minitest-stub-const"
10
+ gem "rake", "~> 13.0"
12
11
  gem "rubocop", "~> 1.7"
13
-
14
12
  gem "rubocop-minitest", require: false
15
-
16
13
  gem "rubocop-rake", require: false
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sparoid
4
- VERSION = "1.0.12"
4
+ VERSION = "1.0.16"
5
5
  end
data/lib/sparoid.rb CHANGED
@@ -9,11 +9,16 @@ require "resolv"
9
9
  module Sparoid
10
10
  extend self
11
11
 
12
+ SPAROID_CACHE_PATH = ENV.fetch("SPAROID_CACHE_PATH", "/tmp/.sparoid_public_ip")
13
+
12
14
  # Send an authorization packet
13
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
+
14
19
  msg = message(cached_public_ip)
15
20
  data = prefix_hmac(hmac_key, encrypt(key, msg))
16
- sendmsg(host, port, data)
21
+ sendmsg(ips, port, data)
17
22
 
18
23
  # wait some time for the server to actually open the port
19
24
  # if we don't wait the next SYN package will be dropped
@@ -39,10 +44,14 @@ module Sparoid
39
44
 
40
45
  private
41
46
 
42
- def sendmsg(host, port, data)
47
+ def sendmsg(ips, port, data)
43
48
  UDPSocket.open do |socket|
44
- socket.connect host, port
45
- socket.sendmsg data, 0
49
+ ips.each do |ip|
50
+ socket.connect ip, port
51
+ socket.sendmsg data, 0
52
+ rescue StandardError => e
53
+ warn "Sparoid error: #{e.message}"
54
+ end
46
55
  end
47
56
  end
48
57
 
@@ -87,21 +96,25 @@ module Sparoid
87
96
  end
88
97
 
89
98
  def up_to_date_cache?
90
- mtime = File.mtime("/tmp/.sparoid_public_ip")
99
+ mtime = File.mtime(SPAROID_CACHE_PATH)
91
100
  (Time.now - mtime) <= 60 # cache is valid for 1 min
92
101
  rescue Errno::ENOENT
93
102
  false
94
103
  end
95
104
 
96
105
  def read_cache
97
- File.open("/tmp/.sparoid_public_ip", "r") do |f|
106
+ File.open(SPAROID_CACHE_PATH, "r") do |f|
98
107
  f.flock(File::LOCK_SH)
99
108
  Resolv::IPv4.create f.read
100
109
  end
110
+ rescue ArgumentError => e
111
+ return write_cache if e.message =~ /cannot interpret as IPv4 address/
112
+
113
+ raise e
101
114
  end
102
115
 
103
116
  def write_cache
104
- File.open("/tmp/.sparoid_public_ip", File::WRONLY | File::CREAT, 0o0644) do |f|
117
+ File.open(SPAROID_CACHE_PATH, File::WRONLY | File::CREAT, 0o0644) do |f|
105
118
  f.flock(File::LOCK_EX)
106
119
  ip = public_ip
107
120
  f.truncate(0)
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.12
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-06-24 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