zold 0.11.4 → 0.11.5
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 +9 -3
- data/lib/zold/commands/push.rb +4 -4
- data/lib/zold/node/front.rb +1 -0
- data/lib/zold/remotes.rb +8 -3
- data/lib/zold/version.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: 6c22d25b0575aa403b58457dc738b232a14e40c8
|
4
|
+
data.tar.gz: 40726c037b816bd370b41b2cd46c1dfd23d834d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdbfb12a088dbfc45ea613d5274c7bf1baf64d1864f939264bdd832cceb0c41988ba003fd27b3819a55a71ed4a599c847f65b676cc8e1052a6e27431cd053aa7
|
7
|
+
data.tar.gz: 2ea2de44216e0ef5f69f27b1c065fd2ec4570c0488a76d567572403cb284a72e72a872cccc4906e2528fc211e400143c9e04e94d973882be4d7c30a4223c3c67
|
data/lib/zold/commands/fetch.rb
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
require 'uri'
|
22
22
|
require 'json'
|
23
23
|
require 'time'
|
24
|
+
require 'tempfile'
|
24
25
|
require 'slop'
|
25
26
|
require 'rainbow'
|
26
27
|
require_relative 'args'
|
@@ -86,9 +87,14 @@ Available options:"
|
|
86
87
|
score = Score.parse_json(json['score'])
|
87
88
|
r.assert_valid_score(score)
|
88
89
|
raise "Score is too weak #{score.strength}" if score.strength < Score::STRENGTH && !opts['ignore-score-weakness']
|
89
|
-
|
90
|
-
|
91
|
-
|
90
|
+
Tempfile.open do |f|
|
91
|
+
body = json['body']
|
92
|
+
File.write(f, body)
|
93
|
+
wallet = Wallet.new(f.path)
|
94
|
+
cps.add(body, score.host, score.port, score.value)
|
95
|
+
@log.info("#{r} returned #{body.length}b/#{wallet.txns.count} \
|
96
|
+
of #{id} in #{(Time.now - start).round(2)}s: #{Rainbow(score.value).green} (#{json['version']})")
|
97
|
+
end
|
92
98
|
end
|
93
99
|
end
|
94
100
|
end
|
data/lib/zold/commands/push.rb
CHANGED
@@ -77,9 +77,8 @@ Available options:"
|
|
77
77
|
return 0
|
78
78
|
end
|
79
79
|
start = Time.now
|
80
|
-
|
81
|
-
|
82
|
-
).put(File.read(wallet.path))
|
80
|
+
content = File.read(wallet.path)
|
81
|
+
response = r.http("/wallet/#{wallet.id}#{opts['sync'] ? '?sync=true' : ''}").put(content)
|
83
82
|
if response.code == '304'
|
84
83
|
@log.info("#{r}: same version of #{wallet.id} there")
|
85
84
|
return 0
|
@@ -89,7 +88,8 @@ Available options:"
|
|
89
88
|
score = Score.parse_json(json)
|
90
89
|
r.assert_valid_score(score)
|
91
90
|
raise "Score is too weak #{score}" if score.strength < Score::STRENGTH
|
92
|
-
@log.info("#{r} accepted #{
|
91
|
+
@log.info("#{r} accepted #{content.length}b/#{wallet.txns.count}txns of #{wallet.id} \
|
92
|
+
in #{(Time.now - start).round(2)}s: #{Rainbow(score.value).green} (#{json['version']})")
|
93
93
|
score.value
|
94
94
|
end
|
95
95
|
end
|
data/lib/zold/node/front.rb
CHANGED
@@ -108,6 +108,7 @@ module Zold
|
|
108
108
|
pid: Process.pid,
|
109
109
|
cpus: Concurrent.processor_count,
|
110
110
|
uptime: `uptime`.strip,
|
111
|
+
threads: Thread.list.select { |t| t.status == 'run' }.count,
|
111
112
|
wallets: settings.wallets.all.count,
|
112
113
|
remotes: settings.remotes.all.count,
|
113
114
|
farm: settings.farm.to_json,
|
data/lib/zold/remotes.rb
CHANGED
@@ -47,10 +47,11 @@ module Zold
|
|
47
47
|
# One remote.
|
48
48
|
class Remote
|
49
49
|
attr_reader :host, :port
|
50
|
-
def initialize(host, port, score)
|
50
|
+
def initialize(host, port, score, log: Log::Quiet.new)
|
51
51
|
@host = host
|
52
52
|
@port = port
|
53
53
|
@score = score
|
54
|
+
@log = log
|
54
55
|
end
|
55
56
|
|
56
57
|
def http(path = '/')
|
@@ -63,7 +64,11 @@ module Zold
|
|
63
64
|
end
|
64
65
|
|
65
66
|
def assert_code(code, response)
|
66
|
-
|
67
|
+
@log.debug("#{response.code} \"#{response.message}\" at \"#{response.body}\"")
|
68
|
+
msg = response.message
|
69
|
+
return if response.code.to_i == code
|
70
|
+
raise "Unexpected HTTP code #{response.code}, instead of #{code}" if msg.empty?
|
71
|
+
raise "#{msg} (HTTP code #{response.code}, instead of #{code})"
|
67
72
|
end
|
68
73
|
|
69
74
|
def assert_valid_score(score)
|
@@ -129,7 +134,7 @@ module Zold
|
|
129
134
|
score = best.nil? ? Score::ZERO : best
|
130
135
|
all.each do |r|
|
131
136
|
begin
|
132
|
-
yield Remotes::Remote.new(r[:host], r[:port], score)
|
137
|
+
yield Remotes::Remote.new(r[:host], r[:port], score, log: log)
|
133
138
|
rescue StandardError => e
|
134
139
|
error(r[:host], r[:port])
|
135
140
|
log.info("#{Rainbow("#{r[:host]}:#{r[:port]}").red}: #{e.message}")
|
data/lib/zold/version.rb
CHANGED