sparoid 1.0.10 → 1.0.14
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 +4 -4
- data/CHANGELOG.md +18 -1
- data/Gemfile +2 -5
- data/lib/sparoid.rb +41 -13
- data/lib/sparoid/cli.rb +2 -2
- data/lib/sparoid/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23058be45d03e24a374cdf7c2e1854f10c5c997eb8654a7af620a532a486cfd5
|
4
|
+
data.tar.gz: 38144ffb7b371f5c439efec31fd4c04323cf72ec4642f2b2b50da84dad7f7a25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0860c3a2edea2a2f35628941f790846985683d6df89a66f6ac6a714af1e3eae1dd4618e6d58de620fc48d85c4da5bf35b6d9470597942b9fdb4f3382cbe1ff3c'
|
7
|
+
data.tar.gz: 22b61f2d97b87b3dbf2458df57177f0122ee9dd87c837c86da366a5bcf34d7c531cfa15fe60f2bb6959b9b939ca30175ae0b1f954ca0534512b821c11f20a578
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,23 @@
|
|
1
|
+
## [1.0.14] - 2021-07-26
|
2
|
+
|
3
|
+
- Send UDP packets to all resolved IPs for a hostname
|
4
|
+
|
5
|
+
## [1.0.13] - 2021-06-30
|
6
|
+
|
7
|
+
- Do not warn on empty public ip cache file
|
8
|
+
- The public ip cache file path can be controlled using the `SPAROID_CACHE_PATH` environment variable
|
9
|
+
|
10
|
+
## [1.0.12] - 2021-06-14
|
11
|
+
|
12
|
+
- Use file locking to prevent multiple processes/threads to write to the public ip cache file
|
13
|
+
|
14
|
+
## [1.0.11] - 2021-06-14
|
15
|
+
|
16
|
+
- Log hostname when reporting unhandled exceptions
|
17
|
+
|
1
18
|
## [1.0.10] - 2021-06-09
|
2
19
|
|
3
|
-
- Cache public IP in
|
20
|
+
- Cache public IP in `/tmp/.sparoid_public_ip` for 1 min
|
4
21
|
|
5
22
|
## [1.0.9] - 2021-05-23
|
6
23
|
|
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
|
data/lib/sparoid.rb
CHANGED
@@ -9,6 +9,8 @@ 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)
|
14
16
|
msg = message(cached_public_ip)
|
@@ -40,10 +42,17 @@ module Sparoid
|
|
40
42
|
private
|
41
43
|
|
42
44
|
def sendmsg(host, port, data)
|
45
|
+
ok = false
|
43
46
|
UDPSocket.open do |socket|
|
44
|
-
|
45
|
-
|
47
|
+
Resolv.each_address(host) do |ip|
|
48
|
+
ok = true
|
49
|
+
socket.connect ip, port
|
50
|
+
socket.sendmsg data, 0
|
51
|
+
rescue StandardError => e
|
52
|
+
warn "Sparoid error: #{e.message}"
|
53
|
+
end
|
46
54
|
end
|
55
|
+
abort "Sparoid failed to resolv #{host}" unless ok
|
47
56
|
end
|
48
57
|
|
49
58
|
def encrypt(key, data)
|
@@ -76,23 +85,42 @@ module Sparoid
|
|
76
85
|
end
|
77
86
|
|
78
87
|
def cached_public_ip
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
Resolv::IPv4.create f.read
|
84
|
-
end
|
88
|
+
if up_to_date_cache?
|
89
|
+
read_cache
|
90
|
+
else
|
91
|
+
write_cache
|
85
92
|
end
|
86
93
|
rescue StandardError => e
|
87
94
|
warn "Sparoid: #{e.inspect}"
|
88
95
|
public_ip
|
89
96
|
end
|
90
97
|
|
91
|
-
def
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
98
|
+
def up_to_date_cache?
|
99
|
+
mtime = File.mtime(SPAROID_CACHE_PATH)
|
100
|
+
(Time.now - mtime) <= 60 # cache is valid for 1 min
|
101
|
+
rescue Errno::ENOENT
|
102
|
+
false
|
103
|
+
end
|
104
|
+
|
105
|
+
def read_cache
|
106
|
+
File.open(SPAROID_CACHE_PATH, "r") do |f|
|
107
|
+
f.flock(File::LOCK_SH)
|
108
|
+
Resolv::IPv4.create f.read
|
109
|
+
end
|
110
|
+
rescue ArgumentError => e
|
111
|
+
return write_cache if e.message =~ /cannot interpret as IPv4 address/
|
112
|
+
|
113
|
+
raise e
|
114
|
+
end
|
115
|
+
|
116
|
+
def write_cache
|
117
|
+
File.open(SPAROID_CACHE_PATH, File::WRONLY | File::CREAT, 0o0644) do |f|
|
118
|
+
f.flock(File::LOCK_EX)
|
119
|
+
ip = public_ip
|
120
|
+
f.truncate(0)
|
121
|
+
f.write ip.to_s
|
122
|
+
ip
|
123
|
+
end
|
96
124
|
end
|
97
125
|
|
98
126
|
def public_ip
|
data/lib/sparoid/cli.rb
CHANGED
@@ -13,7 +13,7 @@ module Sparoid
|
|
13
13
|
rescue Errno::ENOENT
|
14
14
|
abort "Sparoid: Config not found"
|
15
15
|
rescue StandardError => e
|
16
|
-
abort "Sparoid: #{e.message}"
|
16
|
+
abort "Sparoid: #{e.message} (#{host})"
|
17
17
|
end
|
18
18
|
|
19
19
|
desc "connect HOST PORT [SPA-PORT]", "Send a SPA, TCP connect, and then pass the FD back to the parent"
|
@@ -26,7 +26,7 @@ module Sparoid
|
|
26
26
|
end
|
27
27
|
Sparoid.fdpass(host, port)
|
28
28
|
rescue StandardError => e
|
29
|
-
abort "Sparoid: #{e.message}"
|
29
|
+
abort "Sparoid: #{e.message} (#{host})"
|
30
30
|
end
|
31
31
|
|
32
32
|
desc "keygen", "Generate an encryption key and a HMAC key"
|
data/lib/sparoid/version.rb
CHANGED
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.
|
4
|
+
version: 1.0.14
|
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-
|
11
|
+
date: 2021-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|