zold 0.6.1 → 0.6.2
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/Procfile +1 -1
- data/lib/zold/commands/fetch.rb +6 -1
- data/lib/zold/commands/remote.rb +6 -6
- data/lib/zold/remotes.rb +33 -2
- data/lib/zold/version.rb +1 -1
- data/resources/remotes +2 -2
- data/test/commands/test_remote.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: c34164f9da323f0a19a831a982d4904b2c3eaffd
|
4
|
+
data.tar.gz: 77d4935724eab082b127abdc5505be79d02fe6e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa900d58a11e33b2f8855b62a7bd8503a39c68d1cdd3a270ad85defac1529fb120c38b3be8437513120911a0ec6725d8d23749503c92bd0ac8809dd8aa1767ac
|
7
|
+
data.tar.gz: 9d73f149efa4a79c9acf55edec7caeb5c12613ec115310a5023ec962fd7786e6975b54c1070965bb21bc7484ff4ad01cb1a1e63ac79bd2a8c2895a4a29331e38
|
data/Procfile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
web: LC_ALL=UTF-8 ./bin/zold --no-colors --verbose --trace
|
1
|
+
web: LC_ALL=UTF-8 ./bin/zold node --no-colors --verbose --trace --bind-port=$PORT --port=80 --host=b1.zold.io --threads=0 --standalone --invoice=JKFq17yipfjLtX@0000000000000000
|
data/lib/zold/commands/fetch.rb
CHANGED
@@ -66,7 +66,12 @@ Available options:"
|
|
66
66
|
def fetch(id, cps, opts)
|
67
67
|
total = 0
|
68
68
|
@remotes.all.each do |r|
|
69
|
-
|
69
|
+
done = fetch_one(id, r, cps, opts)
|
70
|
+
if done
|
71
|
+
total += 1
|
72
|
+
else
|
73
|
+
@remotes.error(r[:host], r[:port])
|
74
|
+
end
|
70
75
|
end
|
71
76
|
@log.debug("#{total} copies fetched, there are #{cps.all.count} available locally")
|
72
77
|
end
|
data/lib/zold/commands/remote.rb
CHANGED
@@ -121,35 +121,35 @@ Available options:"
|
|
121
121
|
uri = URI("#{r[:home]}remotes")
|
122
122
|
res = Http.new(uri).get
|
123
123
|
unless res.code == '200'
|
124
|
-
@remotes.
|
124
|
+
@remotes.error(r[:host], r[:port])
|
125
125
|
@log.info("#{Rainbow(r[:host]).red} #{res.code} \"#{res.message}\" #{uri}")
|
126
126
|
next
|
127
127
|
end
|
128
128
|
begin
|
129
129
|
json = JSON.parse(res.body)
|
130
130
|
rescue JSON::ParserError => e
|
131
|
-
|
131
|
+
error(r[:host], r[:port])
|
132
132
|
@log.info("#{Rainbow(r[:host]).red} \"#{e.message}\": #{res.body}")
|
133
133
|
next
|
134
134
|
end
|
135
135
|
score = Score.parse_json(json['score'])
|
136
136
|
unless score.valid?
|
137
|
-
|
137
|
+
error(r[:host], r[:port])
|
138
138
|
@log.info("#{Rainbow(r[:host]).red} invalid score")
|
139
139
|
next
|
140
140
|
end
|
141
141
|
if score.expired?
|
142
|
-
|
142
|
+
error(r[:host], r[:port])
|
143
143
|
@log.info("#{Rainbow(r[:host]).red} expired score")
|
144
144
|
next
|
145
145
|
end
|
146
146
|
if score.strength < Score::STRENGTH && !opts['ignore-score-weakness']
|
147
|
-
|
147
|
+
error(r[:host], r[:port])
|
148
148
|
@log.info("#{Rainbow(r[:host]).red} score too weak: #{score.strength}")
|
149
149
|
next
|
150
150
|
end
|
151
151
|
if r[:host] != score.host || r[:port] != score.port
|
152
|
-
@remotes.
|
152
|
+
@remotes.error(r[:host], r[:port])
|
153
153
|
@remotes.add(score.host, score.port)
|
154
154
|
@log.info("#{r[:host]}:#{r[:port]} renamed to #{score.host}:#{score.port}")
|
155
155
|
end
|
data/lib/zold/remotes.rb
CHANGED
@@ -43,7 +43,14 @@ module Zold
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def all
|
46
|
-
|
46
|
+
list = load
|
47
|
+
max_score = list.map { |r| r[:score] }.max
|
48
|
+
max_score = 1 if max_score.zero?
|
49
|
+
max_errors = list.map { |r| r[:errors] }.max
|
50
|
+
max_errors = 1 if max_errors.zero?
|
51
|
+
list.sort_by do |r|
|
52
|
+
(1 - r[:errors] / max_errors) * 5 + (r[:score] / max_score)
|
53
|
+
end.reverse
|
47
54
|
end
|
48
55
|
|
49
56
|
def clean
|
@@ -88,6 +95,22 @@ module Zold
|
|
88
95
|
load.find { |r| r[:host] == host.downcase && r[:port] == port }[:score]
|
89
96
|
end
|
90
97
|
|
98
|
+
def errors(host, port = Remotes::PORT)
|
99
|
+
raise 'Port has to be of type Integer' unless port.is_a?(Integer)
|
100
|
+
raise "#{host}:#{port} is absent" unless exists?(host, port)
|
101
|
+
load.find { |r| r[:host] == host.downcase && r[:port] == port }[:errors]
|
102
|
+
end
|
103
|
+
|
104
|
+
def error(host, port = Remotes::PORT)
|
105
|
+
raise 'Port has to be of type Integer' unless port.is_a?(Integer)
|
106
|
+
raise "#{host}:#{port} is absent" unless exists?(host, port)
|
107
|
+
list = load
|
108
|
+
list.find do |r|
|
109
|
+
r[:host] == host.downcase && r[:port] == port
|
110
|
+
end[:errors] += 1
|
111
|
+
save(list)
|
112
|
+
end
|
113
|
+
|
91
114
|
def rescore(host, port, score)
|
92
115
|
raise 'Port has to be of type Integer' unless port.is_a?(Integer)
|
93
116
|
raise "#{host}:#{port} is absent" unless exists?(host, port)
|
@@ -106,6 +129,7 @@ module Zold
|
|
106
129
|
host: r[0],
|
107
130
|
port: r[1].to_i,
|
108
131
|
score: r[2].to_i,
|
132
|
+
errors: r[3].to_i,
|
109
133
|
home: URI("http://#{r[0]}:#{r[1]}/")
|
110
134
|
}
|
111
135
|
end
|
@@ -114,7 +138,14 @@ module Zold
|
|
114
138
|
def save(list)
|
115
139
|
File.write(
|
116
140
|
file,
|
117
|
-
list.map
|
141
|
+
list.map do |r|
|
142
|
+
[
|
143
|
+
r[:host],
|
144
|
+
r[:port],
|
145
|
+
r[:score],
|
146
|
+
r[:errors]
|
147
|
+
].join(',')
|
148
|
+
end.join("\n")
|
118
149
|
)
|
119
150
|
end
|
120
151
|
|
data/lib/zold/version.rb
CHANGED
data/resources/remotes
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
b1.zold.io,80,0
|
2
|
-
b2.zold.io,4096,0
|
1
|
+
b1.zold.io,80,0,0
|
2
|
+
b2.zold.io,4096,0,0
|
@@ -62,7 +62,7 @@ class TestRemote < Minitest::Test
|
|
62
62
|
cmd.run(%w[remote add localhost 2])
|
63
63
|
assert_equal(2, remotes.all.count)
|
64
64
|
cmd.run(['remote', 'update', '--ignore-score-weakness'])
|
65
|
-
assert_equal(
|
65
|
+
assert_equal(4, remotes.all.count)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|