zold 0.11.8 → 0.11.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zold/commands/fetch.rb +3 -1
- data/lib/zold/commands/push.rb +3 -2
- data/lib/zold/commands/remote.rb +2 -2
- data/lib/zold/commands/taxes.rb +1 -1
- data/lib/zold/node/entrance.rb +12 -5
- data/lib/zold/remotes.rb +11 -0
- data/lib/zold/version.rb +1 -1
- data/test/commands/test_fetch.rb +6 -6
- data/test/node/fake_node.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: bbeb43337cb9f0a00e30ea6898f5a03636fcf1bb
|
4
|
+
data.tar.gz: d141288a3fbeee753c6e8e961a63d9932086442d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2aa295616ec945fbdf1106b741021c55bfb8f84200d9934d27a00324abf1fed3c4c54432f06f3943f8f46c625bf02cce079a55b813541fddfef12b0872e41456
|
7
|
+
data.tar.gz: 98225c2ffc7f126586241e62177c6c293d7c43e78c610843b4f462ca46f5552374d38849e33a18bc33f3088118fcb9f22a6102176779b56b6af3bf82d3967e6e
|
data/lib/zold/commands/fetch.rb
CHANGED
@@ -86,7 +86,9 @@ Available options:"
|
|
86
86
|
json = JSON.parse(res.body)
|
87
87
|
score = Score.parse_json(json['score'])
|
88
88
|
r.assert_valid_score(score)
|
89
|
-
|
89
|
+
r.assert_score_ownership(score)
|
90
|
+
r.assert_score_strength(score)
|
91
|
+
r.assert_score_strength(score) unless opts['ignore-score-weakness']
|
90
92
|
Tempfile.open do |f|
|
91
93
|
body = json['body']
|
92
94
|
File.write(f, body)
|
data/lib/zold/commands/push.rb
CHANGED
@@ -69,7 +69,7 @@ Available options:"
|
|
69
69
|
@remotes.iterate(@log) do |r|
|
70
70
|
total += push_one(wallet, r, opts)
|
71
71
|
end
|
72
|
-
@log.info("
|
72
|
+
@log.info("Push finished, total score for #{wallet.id} is #{total}")
|
73
73
|
end
|
74
74
|
|
75
75
|
def push_one(wallet, r, opts)
|
@@ -88,7 +88,8 @@ Available options:"
|
|
88
88
|
json = JSON.parse(response.body)
|
89
89
|
score = Score.parse_json(json['score'])
|
90
90
|
r.assert_valid_score(score)
|
91
|
-
|
91
|
+
r.assert_score_ownership(score)
|
92
|
+
r.assert_score_strength(score)
|
92
93
|
@log.info("#{r} accepted #{content.length}b/#{wallet.txns.count}t of #{wallet.id} \
|
93
94
|
in #{(Time.now - start).round(2)}s: #{Rainbow(score.value).green} (#{json['version']})")
|
94
95
|
score.value
|
data/lib/zold/commands/remote.rb
CHANGED
@@ -155,8 +155,8 @@ Available options:"
|
|
155
155
|
json = JSON.parse(res.body)
|
156
156
|
score = Score.parse_json(json['score'])
|
157
157
|
r.assert_valid_score(score)
|
158
|
-
|
159
|
-
|
158
|
+
r.assert_score_ownership(score)
|
159
|
+
r.assert_score_strength(score) unless opts['ignore-score-weakness']
|
160
160
|
@remotes.rescore(score.host, score.port, score.value)
|
161
161
|
if opts['reboot'] && Semantic::Version.new(VERSION) < Semantic::Version.new(json['version'])
|
162
162
|
@log.info("#{r}: their version #{json['version']} is higher than mine #{VERSION}, reboot! \
|
data/lib/zold/commands/taxes.rb
CHANGED
@@ -123,7 +123,7 @@ Available options:"
|
|
123
123
|
json = JSON.parse(res.body)
|
124
124
|
score = Score.parse_json(json['score'])
|
125
125
|
r.assert_valid_score(score)
|
126
|
-
|
126
|
+
r.assert_score_strength(score)
|
127
127
|
raise "Score is too small (<#{Tax::EXACT_SCORE})" if score.value < Tax::EXACT_SCORE
|
128
128
|
@log.info("#{r}: #{Rainbow(score.value).green}")
|
129
129
|
best << score
|
data/lib/zold/node/entrance.rb
CHANGED
@@ -101,11 +101,16 @@ module Zold
|
|
101
101
|
|
102
102
|
# Returns a list of modifed wallets (as Zold::Id)
|
103
103
|
def push_sync(id, body)
|
104
|
-
@semaphores.put_if_absent(id, Mutex.new)
|
105
|
-
@semaphores.get(id).synchronize do
|
104
|
+
@semaphores.put_if_absent(id.to_s, Mutex.new)
|
105
|
+
@semaphores.get(id.to_s).synchronize do
|
106
106
|
start = Time.now
|
107
107
|
modified = push_unsafe(id, body)
|
108
|
-
|
108
|
+
if modified.empty?
|
109
|
+
@log.info("Accepted #{id} in #{((Time.now - start) / 60).round(2)}s \
|
110
|
+
and modified nothing (this is most likely a bug!)")
|
111
|
+
else
|
112
|
+
@log.info("Accepted #{id} in #{((Time.now - start) / 60).round(2)}s and modified #{modified.join(', ')}")
|
113
|
+
end
|
109
114
|
modified
|
110
115
|
end
|
111
116
|
end
|
@@ -113,7 +118,8 @@ module Zold
|
|
113
118
|
# Returns a list of modifed wallets (as Zold::Id)
|
114
119
|
def push_unsafe(id, body)
|
115
120
|
copies = Copies.new(File.join(@copies, id.to_s))
|
116
|
-
|
121
|
+
localhost = '0.0.0.0'
|
122
|
+
copies.add(body, localhost, Remotes::PORT, 0)
|
117
123
|
Fetch.new(
|
118
124
|
wallets: @wallets, remotes: @remotes, copies: copies.root, log: @log
|
119
125
|
).run(['fetch', id.to_s, "--ignore-node=#{@address}"])
|
@@ -121,7 +127,7 @@ module Zold
|
|
121
127
|
wallets: @wallets, copies: copies.root, log: @log
|
122
128
|
).run(['merge', id.to_s])
|
123
129
|
Clean.new(wallets: @wallets, copies: copies.root, log: @log).run(['clean', id.to_s])
|
124
|
-
copies.remove(
|
130
|
+
copies.remove(localhost, Remotes::PORT)
|
125
131
|
@push_mutex.synchronize { @modified += modified }
|
126
132
|
@pushes.post { push_one } if @pushes.length < 2
|
127
133
|
modified
|
@@ -130,6 +136,7 @@ module Zold
|
|
130
136
|
def push_one
|
131
137
|
@push_mutex.synchronize do
|
132
138
|
id = @modified.to_a[0]
|
139
|
+
@modified.delete(id)
|
133
140
|
return if id.nil?
|
134
141
|
Push.new(
|
135
142
|
wallets: @wallets, remotes: @remotes, log: @log
|
data/lib/zold/remotes.rb
CHANGED
@@ -53,7 +53,9 @@ module Zold
|
|
53
53
|
attr_reader :host, :port
|
54
54
|
def initialize(host, port, score, log: Log::Quiet.new)
|
55
55
|
@host = host
|
56
|
+
raise 'Post must be Integer' unless port.is_a?(Integer)
|
56
57
|
@port = port
|
58
|
+
raise 'Score must be of type Score' unless score.is_a?(Score)
|
57
59
|
@score = score
|
58
60
|
@log = log
|
59
61
|
end
|
@@ -79,6 +81,15 @@ module Zold
|
|
79
81
|
raise "Invalid score #{score}" unless score.valid?
|
80
82
|
raise "Expired score #{score}" if score.expired?
|
81
83
|
end
|
84
|
+
|
85
|
+
def assert_score_ownership(score)
|
86
|
+
raise "Masqueraded host #{@host} as #{score.host}: #{score}" if @host != score.host
|
87
|
+
raise "Masqueraded port #{@port} as #{score.port}: #{score}" if @port != score.port
|
88
|
+
end
|
89
|
+
|
90
|
+
def assert_score_strength(score)
|
91
|
+
raise "Score is too weak #{score.strength}" if score.strength < Score::STRENGTH
|
92
|
+
end
|
82
93
|
end
|
83
94
|
|
84
95
|
def initialize(file)
|
data/lib/zold/version.rb
CHANGED
data/test/commands/test_fetch.rb
CHANGED
@@ -46,18 +46,18 @@ class TestFetch < Minitest::Test
|
|
46
46
|
wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
47
47
|
remotes = Zold::Remotes.new(File.join(dir, 'remotes.csv'))
|
48
48
|
remotes.clean
|
49
|
-
stub_request(:get, "http://
|
49
|
+
stub_request(:get, "http://localhost:80/wallet/#{id}").to_return(
|
50
50
|
status: 200,
|
51
51
|
body: {
|
52
52
|
'score': Zold::Score::ZERO.to_h,
|
53
53
|
'body': File.read(wallet.path)
|
54
54
|
}.to_json
|
55
55
|
)
|
56
|
-
stub_request(:get, "http://
|
56
|
+
stub_request(:get, "http://localhost:81/wallet/#{id}").to_return(
|
57
57
|
status: 404
|
58
58
|
)
|
59
|
-
remotes.add('
|
60
|
-
remotes.add('
|
59
|
+
remotes.add('localhost', 80)
|
60
|
+
remotes.add('localhost', 81)
|
61
61
|
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
62
62
|
Zold::Fetch.new(wallets: wallets, copies: copies.root, remotes: remotes, log: test_log).run(
|
63
63
|
['fetch', '--ignore-score-weakness', id.to_s]
|
@@ -73,14 +73,14 @@ class TestFetch < Minitest::Test
|
|
73
73
|
wallets = Zold::Wallets.new(dir)
|
74
74
|
remotes = Zold::Remotes.new(File.join(dir, 'remotes.csv'))
|
75
75
|
remotes.clean
|
76
|
-
stub_request(:get, "http://
|
76
|
+
stub_request(:get, "http://localhost:80/wallet/#{id}").to_return(
|
77
77
|
status: 200,
|
78
78
|
body: {
|
79
79
|
'score': Zold::Score::ZERO.to_h,
|
80
80
|
'body': 'the body'
|
81
81
|
}.to_json
|
82
82
|
)
|
83
|
-
remotes.add('
|
83
|
+
remotes.add('localhost', 80)
|
84
84
|
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
85
85
|
Zold::Fetch.new(
|
86
86
|
wallets: wallets, copies: copies.root, remotes: remotes, log: test_log
|
data/test/node/fake_node.rb
CHANGED