zold 0.10.7 → 0.10.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rultor.yml +1 -1
- data/fixtures/scripts/push-and-pull.sh +1 -1
- data/lib/zold/commands/fetch.rb +2 -2
- data/lib/zold/commands/node.rb +1 -1
- data/lib/zold/commands/push.rb +10 -5
- data/lib/zold/commands/remote.rb +8 -0
- data/lib/zold/http.rb +6 -2
- data/lib/zold/node/entrance.rb +19 -5
- data/lib/zold/node/front.rb +2 -10
- data/lib/zold/version.rb +1 -1
- data/test/commands/test_node.rb +1 -1
- data/test/commands/test_remote.rb +2 -0
- data/test/test_zold.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2d0bc52f647f22b12dfb70543a113e7d4a0393a
|
4
|
+
data.tar.gz: f883780a0b2b0d5d4db0c261899ca4df7a357e15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6657086782bfbd32fe8867a292ed7bc45e1e63d6640ff3bb148f1e7a322daa59c47a95278e276851693a223a4b88ecddd69dcc22591f43d1289dbde54e14f94
|
7
|
+
data.tar.gz: 17d58f71dc6a3a83334ab656cdd9c6a391da37ae544df9dac0a5a20f8ace8bec14fcaf294f7191bd4f81df80db6e93847676144feb9ac67e8f1d99685634dce9
|
data/.rultor.yml
CHANGED
data/lib/zold/commands/fetch.rb
CHANGED
@@ -85,8 +85,8 @@ Available options:"
|
|
85
85
|
r.assert_valid_score(score)
|
86
86
|
raise "Score is too weak #{score.strength}" if score.strength < Score::STRENGTH && !opts['ignore-score-weakness']
|
87
87
|
cps.add(json['body'], score.host, score.port, score.value)
|
88
|
-
@log.info("#{r} #{json['body'].length}b/#{Rainbow(score.value).green}
|
89
|
-
in #{(Time.now - start).round(2)}s")
|
88
|
+
@log.info("#{r} returned #{json['body'].length}b/#{Rainbow(score.value).green} \
|
89
|
+
of #{id} (#{json['version']}) in #{(Time.now - start).round(2)}s")
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
data/lib/zold/commands/node.rb
CHANGED
@@ -114,7 +114,7 @@ module Zold
|
|
114
114
|
)
|
115
115
|
Zold::Front.set(:farm, farm)
|
116
116
|
Thread.start do
|
117
|
-
Zold::Remote.new(remotes: remotes, farm: farm, log: @log).run(%w[remote update]) unless best.nil?
|
117
|
+
Zold::Remote.new(remotes: remotes, farm: farm, log: @log).run(%w[remote update --reboot]) unless best.nil?
|
118
118
|
end
|
119
119
|
@log.debug('Starting up the web front...')
|
120
120
|
begin
|
data/lib/zold/commands/push.rb
CHANGED
@@ -44,6 +44,9 @@ module Zold
|
|
44
44
|
opts = Slop.parse(args, help: true, suppress_errors: true) do |o|
|
45
45
|
o.banner = "Usage: zold push [ID...] [options]
|
46
46
|
Available options:"
|
47
|
+
o.bool '--sync',
|
48
|
+
'Wait until the server confirms merge and pushes all wallets further (default: false)',
|
49
|
+
default: false
|
47
50
|
o.bool '--help', 'Print instructions'
|
48
51
|
end
|
49
52
|
mine = Args.new(opts, @log).take || return
|
@@ -55,13 +58,15 @@ Available options:"
|
|
55
58
|
end
|
56
59
|
end
|
57
60
|
|
58
|
-
def push(wallet,
|
61
|
+
def push(wallet, opts)
|
59
62
|
total = 0
|
60
63
|
@remotes.iterate(@log) do |r|
|
61
64
|
start = Time.now
|
62
|
-
response = r.http(
|
65
|
+
response = r.http(
|
66
|
+
"/wallet/#{wallet.id}#{opts['sync'] ? '?sync=true' : ''}"
|
67
|
+
).put(File.read(wallet.path))
|
63
68
|
if response.code == '304'
|
64
|
-
@log.info("#{r}: same version there")
|
69
|
+
@log.info("#{r}: same version of #{wallet.id} there")
|
65
70
|
next
|
66
71
|
end
|
67
72
|
r.assert_code(200, response)
|
@@ -69,10 +74,10 @@ Available options:"
|
|
69
74
|
score = Score.parse_json(json)
|
70
75
|
r.assert_valid_score(score)
|
71
76
|
raise "Score is too weak #{score}" if score.strength < Score::STRENGTH
|
72
|
-
@log.info("#{r} accepted in #{(Time.now - start).round(2)}s: #{Rainbow(score.value).green}")
|
77
|
+
@log.info("#{r} accepted #{wallet.id} in #{(Time.now - start).round(2)}s: #{Rainbow(score.value).green}")
|
73
78
|
total += score.value
|
74
79
|
end
|
75
|
-
@log.info("Total score is #{total}")
|
80
|
+
@log.info("Total score for #{wallet.id} is #{total}")
|
76
81
|
end
|
77
82
|
end
|
78
83
|
end
|
data/lib/zold/commands/remote.rb
CHANGED
@@ -19,6 +19,7 @@
|
|
19
19
|
# SOFTWARE.
|
20
20
|
|
21
21
|
require 'slop'
|
22
|
+
require 'semantic'
|
22
23
|
require 'rainbow'
|
23
24
|
require 'net/http'
|
24
25
|
require 'json'
|
@@ -61,6 +62,9 @@ Available options:"
|
|
61
62
|
o.bool '--ignore-score-weakness',
|
62
63
|
'Don\'t complain when their score is too weak',
|
63
64
|
default: false
|
65
|
+
o.bool '--reboot',
|
66
|
+
'Exit if any node reports version higher than we have',
|
67
|
+
default: false
|
64
68
|
o.bool '--help', 'Print instructions'
|
65
69
|
end
|
66
70
|
mine = Args.new(opts, @log).take || return
|
@@ -125,6 +129,10 @@ Available options:"
|
|
125
129
|
raise "Score too weak: #{score.strength}" if score.strength < Score::STRENGTH && !opts['ignore-score-weakness']
|
126
130
|
raise "Masqueraded as #{score.host}:#{score.port}" if r.host != score.host || r.port != score.port
|
127
131
|
@remotes.rescore(score.host, score.port, score.value)
|
132
|
+
if opts['reboot'] && Semantic::Version.new(VERSION) < Semantic::Version.new(json['version'])
|
133
|
+
@log.info("#{r}: their version #{json['version']} is higher than mine #{VERSION}, reboot!")
|
134
|
+
exit(0)
|
135
|
+
end
|
128
136
|
if deep
|
129
137
|
json['all'].each do |s|
|
130
138
|
add(s['host'], s['port']) unless @remotes.exists?(s['host'], s['port'])
|
data/lib/zold/http.rb
CHANGED
@@ -48,7 +48,9 @@ module Zold
|
|
48
48
|
def get
|
49
49
|
http = Net::HTTP.new(@uri.host, @uri.port)
|
50
50
|
http.read_timeout = 5
|
51
|
-
|
51
|
+
path = @uri.path
|
52
|
+
path += '?' + @uri.query if @uri.query
|
53
|
+
return http.request_get(path, headers)
|
52
54
|
rescue StandardError => e
|
53
55
|
Error.new(e)
|
54
56
|
end
|
@@ -56,8 +58,10 @@ module Zold
|
|
56
58
|
def put(body)
|
57
59
|
http = Net::HTTP.new(@uri.host, @uri.port)
|
58
60
|
http.read_timeout = 60
|
61
|
+
path = @uri.path
|
62
|
+
path += '?' + @uri.query if @uri.query
|
59
63
|
return http.request_put(
|
60
|
-
|
64
|
+
path, body,
|
61
65
|
headers.merge(
|
62
66
|
'Content-Type': 'text/plain',
|
63
67
|
'Content-Length': body.length.to_s
|
data/lib/zold/node/entrance.rb
CHANGED
@@ -46,11 +46,14 @@ module Zold
|
|
46
46
|
@semaphores = Concurrent::Map.new
|
47
47
|
end
|
48
48
|
|
49
|
-
def push(id, body)
|
49
|
+
def push(id, body, sync: true)
|
50
50
|
check(body)
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
if sync
|
52
|
+
push_sync(id, body)
|
53
|
+
else
|
54
|
+
Thread.new do
|
55
|
+
push_sync(id, body)
|
56
|
+
end
|
54
57
|
end
|
55
58
|
end
|
56
59
|
|
@@ -60,7 +63,9 @@ module Zold
|
|
60
63
|
wallet = Wallet.new(f)
|
61
64
|
break unless wallet.network == Wallet::MAIN_NETWORK
|
62
65
|
balance = wallet.balance
|
63
|
-
|
66
|
+
if balance.negative? && !wallet.root?
|
67
|
+
raise "The balance #{balance} of #{wallet.id} is negative and it's not a root wallet"
|
68
|
+
end
|
64
69
|
Emission.new(wallet).check
|
65
70
|
tax = Tax.new(wallet)
|
66
71
|
if tax.in_debt?
|
@@ -69,6 +74,15 @@ module Zold
|
|
69
74
|
end
|
70
75
|
end
|
71
76
|
|
77
|
+
def push_sync(id, body)
|
78
|
+
@semaphores.put_if_absent(id, Mutex.new)
|
79
|
+
@semaphores.get(id).synchronize do
|
80
|
+
modified = push_unsafe(id, body)
|
81
|
+
@log.info("Accepted #{id} and modified: #{modified.join(', ')}")
|
82
|
+
modified
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
72
86
|
def push_unsafe(id, body)
|
73
87
|
copies = Copies.new(File.join(@copies, id.to_s))
|
74
88
|
copies.add(body, 'remote', Remotes::PORT, 0)
|
data/lib/zold/node/front.rb
CHANGED
@@ -23,7 +23,6 @@ STDOUT.sync = true
|
|
23
23
|
require 'json'
|
24
24
|
require 'sinatra/base'
|
25
25
|
require 'webrick'
|
26
|
-
require 'semantic'
|
27
26
|
require_relative '../version'
|
28
27
|
require_relative '../wallet'
|
29
28
|
require_relative '../log'
|
@@ -58,11 +57,6 @@ module Zold
|
|
58
57
|
end
|
59
58
|
|
60
59
|
before do
|
61
|
-
if request.env[Http::VERSION_HEADER] &&
|
62
|
-
Semantic::Version.new(VERSION) < Semantic::Version.new(request.env[Http::VERSION_HEADER]) &&
|
63
|
-
!settings.remotes.empty? && settings.reboot
|
64
|
-
exit(0)
|
65
|
-
end
|
66
60
|
return unless request.env[Http::SCORE_HEADER]
|
67
61
|
return unless settings.remotes.empty?
|
68
62
|
s = Score.parse(request.env[Http::SCORE_HEADER])
|
@@ -121,12 +115,10 @@ module Zold
|
|
121
115
|
status 304
|
122
116
|
return
|
123
117
|
end
|
124
|
-
|
118
|
+
settings.entrance.push(id, body, sync: !params[:sync].nil?)
|
125
119
|
JSON.pretty_generate(
|
126
120
|
version: VERSION,
|
127
|
-
score: score.to_h
|
128
|
-
balance: wallet.balance,
|
129
|
-
modified: modified.count
|
121
|
+
score: score.to_h
|
130
122
|
)
|
131
123
|
end
|
132
124
|
|
data/lib/zold/version.rb
CHANGED
data/test/commands/test_node.rb
CHANGED
@@ -47,7 +47,7 @@ class TestNode < Minitest::Test
|
|
47
47
|
remotes = Zold::Remotes.new(File.join(dir, 'remotes.csv'))
|
48
48
|
remotes.clean
|
49
49
|
remotes.add('localhost', port)
|
50
|
-
Zold::Push.new(wallets: wallets, remotes: remotes, log: $log).run(['push'])
|
50
|
+
Zold::Push.new(wallets: wallets, remotes: remotes, log: $log).run(['push', '--sync'])
|
51
51
|
Zold::Fetch.new(
|
52
52
|
wallets: wallets, copies: File.join(dir, 'copies'),
|
53
53
|
remotes: remotes, log: $log
|
@@ -22,6 +22,7 @@ require 'minitest/autorun'
|
|
22
22
|
require 'tmpdir'
|
23
23
|
require 'webmock/minitest'
|
24
24
|
require_relative '../test__helper'
|
25
|
+
require_relative '../../lib/zold/version'
|
25
26
|
require_relative '../../lib/zold/wallets'
|
26
27
|
require_relative '../../lib/zold/remotes'
|
27
28
|
require_relative '../../lib/zold/key'
|
@@ -41,6 +42,7 @@ class TestRemote < Minitest::Test
|
|
41
42
|
stub_request(:get, "http://#{zero.host}:#{zero.port}/remotes").to_return(
|
42
43
|
status: 200,
|
43
44
|
body: {
|
45
|
+
version: Zold::VERSION,
|
44
46
|
score: zero.to_h,
|
45
47
|
all: [
|
46
48
|
{ host: 'localhost', port: 888 },
|
data/test/test_zold.rb
CHANGED