zold 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Procfile +1 -1
- data/bin/zold +4 -4
- data/fixtures/scripts/print-helps.sh +0 -2
- data/fixtures/scripts/push-and-pull.sh +16 -17
- data/lib/zold/commands/fetch.rb +43 -30
- data/lib/zold/commands/merge.rb +13 -4
- data/lib/zold/commands/node.rb +15 -1
- data/lib/zold/commands/propagate.rb +11 -2
- data/lib/zold/commands/push.rb +20 -6
- data/lib/zold/http.rb +5 -4
- data/lib/zold/node/front.rb +28 -13
- data/lib/zold/patch.rb +5 -0
- data/lib/zold/remotes.rb +13 -9
- data/lib/zold/version.rb +1 -1
- data/test/commands/test_merge.rb +6 -2
- data/test/test_patch.rb +1 -1
- data/test/test_remotes.rb +4 -4
- 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: f998b2457e50fdca35b6c4ac18869a059aa3989b
|
4
|
+
data.tar.gz: 495db441ee37e8c7d4e3eb05554147bb720c1e45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ca78d5d43939e532d2e006e107165bb16e8daf091fe3c0da36f62758a5025261d3af405798ce6ff4d4188791a9af8cde2c6cac4be89c0366c204f19446f4d76
|
7
|
+
data.tar.gz: 2fd4122ff59c126eb7ac7796391b7bcc6f509e5d0eb2a028609f7d29be7833f5640a122cad7296f2938f16626817467e38ad029971be91279e57995ae1166b3b
|
data/Procfile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
web: LC_ALL=UTF-8 ./bin/zold --no-colors --verbose --trace node --bind-port=$PORT --port=80 --host=b1.zold.io --threads=0
|
1
|
+
web: LC_ALL=UTF-8 ./bin/zold --no-colors --verbose --trace node --bind-port=$PORT --port=80 --host=b1.zold.io --threads=0 --standalone
|
data/bin/zold
CHANGED
@@ -86,8 +86,8 @@ Available commands:
|
|
86
86
|
Generate score for the given host and port
|
87
87
|
Available options:"
|
88
88
|
o.string '-d', '--dir',
|
89
|
-
'The directory where wallets are stored (default:
|
90
|
-
default:
|
89
|
+
'The directory where wallets are stored (default: .)',
|
90
|
+
default: Dir.pwd
|
91
91
|
o.string '--private-key',
|
92
92
|
'The location of RSA private key (default: ~/.ssh/id_rsa)',
|
93
93
|
default: '~/.ssh/id_rsa'
|
@@ -120,8 +120,8 @@ Available options:"
|
|
120
120
|
args = args[(args.index(command) + 1)..-1]
|
121
121
|
|
122
122
|
wallets = Zold::Wallets.new(opts['dir'])
|
123
|
-
remotes = Zold::Remotes.new(File.join(opts['dir'], '.
|
124
|
-
copies = File.join(opts['dir'], '.
|
123
|
+
remotes = Zold::Remotes.new(File.join(opts['dir'], '.zoldata/remotes'))
|
124
|
+
copies = File.join(opts['dir'], '.zoldata/copies')
|
125
125
|
|
126
126
|
case command
|
127
127
|
when 'node'
|
@@ -9,7 +9,7 @@ port=`python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.gets
|
|
9
9
|
|
10
10
|
mkdir server
|
11
11
|
cd server
|
12
|
-
zold node --host=localhost --port=${port} --bind-port=${port} --threads=0 &
|
12
|
+
zold --trace node --host=localhost --port=${port} --bind-port=${port} --threads=0 --standalone &
|
13
13
|
pid=$!
|
14
14
|
trap "kill -9 $pid" EXIT
|
15
15
|
cd ..
|
@@ -18,22 +18,21 @@ while ! nc -z localhost ${port}; do
|
|
18
18
|
sleep 0.1
|
19
19
|
done
|
20
20
|
|
21
|
-
zold remote clean
|
22
|
-
zold remote add localhost ${port}
|
23
|
-
zold remote show
|
21
|
+
zold --trace remote clean
|
22
|
+
zold --trace remote add localhost ${port}
|
23
|
+
zold --trace remote show
|
24
24
|
|
25
|
-
zold --public-key id_rsa.pub create 0000000000000000
|
25
|
+
zold --trace --public-key id_rsa.pub create 0000000000000000
|
26
26
|
target=`zold --public-key id_rsa.pub create`
|
27
27
|
invoice=`zold invoice ${target}`
|
28
|
-
zold --private-key id_rsa pay 0000000000000000 ${invoice} 14.99 'To save the world!'
|
29
|
-
zold propagate 0000000000000000
|
30
|
-
zold show
|
31
|
-
zold show 0000000000000000
|
32
|
-
|
33
|
-
zold
|
34
|
-
zold
|
35
|
-
zold
|
36
|
-
zold
|
37
|
-
zold
|
38
|
-
|
39
|
-
echo 'DONE'
|
28
|
+
zold --trace --private-key id_rsa pay 0000000000000000 ${invoice} 14.99 'To save the world!'
|
29
|
+
zold --trace propagate 0000000000000000
|
30
|
+
zold --trace show
|
31
|
+
zold --trace show 0000000000000000
|
32
|
+
|
33
|
+
zold --trace remote show
|
34
|
+
zold --trace push 0000000000000000
|
35
|
+
zold --trace fetch 0000000000000000 --ignore-score-weakness
|
36
|
+
zold --trace diff 0000000000000000
|
37
|
+
zold --trace merge 0000000000000000
|
38
|
+
zold --trace clean 0000000000000000
|
data/lib/zold/commands/fetch.rb
CHANGED
@@ -47,6 +47,9 @@ Available options:"
|
|
47
47
|
o.bool '--ignore-score-weakness',
|
48
48
|
'Don\'t complain when their score is too weak',
|
49
49
|
default: false
|
50
|
+
o.array '--ignore-node',
|
51
|
+
'Ignore this node and don\'t fetch from it',
|
52
|
+
default: []
|
50
53
|
o.bool '--help', 'Print instructions'
|
51
54
|
end
|
52
55
|
if opts.help?
|
@@ -62,40 +65,50 @@ Available options:"
|
|
62
65
|
def fetch(id, cps, opts)
|
63
66
|
total = 0
|
64
67
|
@remotes.all.each do |r|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
68
|
+
total += 1 if fetch_one(id, r, cps, opts)
|
69
|
+
end
|
70
|
+
@log.debug("#{total} copies fetched, \
|
71
|
+
there are #{cps.all.count} available locally")
|
72
|
+
end
|
73
|
+
|
74
|
+
def fetch_one(id, r, cps, opts)
|
75
|
+
address = "#{r[:host]}:#{r[:port]}".downcase
|
76
|
+
if opts['ignore-node'].include?(address)
|
77
|
+
@log.info("#{address} ignored because of --ignore-node")
|
78
|
+
return false
|
79
|
+
end
|
80
|
+
uri = URI("#{r[:home]}wallet/#{id}")
|
81
|
+
res = Http.new(uri).get
|
82
|
+
unless res.code == '200'
|
83
|
+
@log.error(
|
84
|
+
"#{address} #{Rainbow(res.code).red}/#{res.message} at #{uri}"
|
78
85
|
)
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
+
return false
|
87
|
+
end
|
88
|
+
json = JSON.parse(res.body)
|
89
|
+
score = Score.new(
|
90
|
+
Time.parse(json['score']['time']),
|
91
|
+
r[:host],
|
92
|
+
r[:port],
|
93
|
+
json['score']['suffixes']
|
94
|
+
)
|
95
|
+
unless score.valid?
|
96
|
+
@log.error("#{address} invalid score")
|
97
|
+
return false
|
98
|
+
end
|
99
|
+
if score.strength < Score::STRENGTH && !opts['ignore-score-weakness']
|
100
|
+
@log.error(
|
101
|
+
"#{address} score is too weak: #{score.strength} \
|
86
102
|
(<#{Score::STRENGTH})"
|
87
|
-
)
|
88
|
-
next
|
89
|
-
end
|
90
|
-
total += 1
|
91
|
-
cps.add(json['body'], r[:host], r[:port], score.value)
|
92
|
-
@log.info(
|
93
|
-
"#{r[:host]}:#{r[:port]} #{json['body'].length}b/\
|
94
|
-
#{Rainbow(score.value).green} (v.#{json['version']})"
|
95
103
|
)
|
104
|
+
return false
|
96
105
|
end
|
97
|
-
|
98
|
-
|
106
|
+
cps.add(json['body'], r[:host], r[:port], score.value)
|
107
|
+
@log.info(
|
108
|
+
"#{address} #{json['body'].length}b/\
|
109
|
+
#{Rainbow(score.value).green} (v.#{json['version']})"
|
110
|
+
)
|
111
|
+
true
|
99
112
|
end
|
100
113
|
end
|
101
114
|
end
|
data/lib/zold/commands/merge.rb
CHANGED
@@ -37,6 +37,7 @@ module Zold
|
|
37
37
|
@log = log
|
38
38
|
end
|
39
39
|
|
40
|
+
# Returns the array of modified wallets (IDs)
|
40
41
|
def run(args = [])
|
41
42
|
opts = Slop.parse(args, help: true) do |o|
|
42
43
|
o.banner = "Usage: zold merge [ID...] [options]
|
@@ -48,12 +49,15 @@ Available options:"
|
|
48
49
|
return
|
49
50
|
end
|
50
51
|
raise 'At least one wallet ID is required' if opts.arguments.empty?
|
52
|
+
modified = []
|
51
53
|
opts.arguments.each do |id|
|
52
54
|
wallet = @wallets.find(Id.new(id))
|
53
|
-
merge(wallet, Copies.new(File.join(@copies, id)), opts)
|
55
|
+
next unless merge(wallet, Copies.new(File.join(@copies, id)), opts)
|
56
|
+
modified << Id.new(id)
|
54
57
|
require_relative 'propagate'
|
55
|
-
Propagate.new(wallets: @wallets, log: @log).run(args)
|
58
|
+
modified += Propagate.new(wallets: @wallets, log: @log).run(args)
|
56
59
|
end
|
60
|
+
modified
|
57
61
|
end
|
58
62
|
|
59
63
|
def merge(wallet, cps, _)
|
@@ -64,8 +68,13 @@ Available options:"
|
|
64
68
|
cps[1..-1].each do |c|
|
65
69
|
patch.join(Wallet.new(c[:path]))
|
66
70
|
end
|
67
|
-
patch.save(wallet.path, overwrite: true)
|
68
|
-
|
71
|
+
modified = patch.save(wallet.path, overwrite: true)
|
72
|
+
if modified
|
73
|
+
@log.debug("Merged successfully into #{wallet.path}")
|
74
|
+
else
|
75
|
+
@log.debug("Nothing changed in #{wallet.path} after merge")
|
76
|
+
end
|
77
|
+
modified
|
69
78
|
end
|
70
79
|
end
|
71
80
|
end
|
data/lib/zold/commands/node.rb
CHANGED
@@ -44,7 +44,7 @@ module Zold
|
|
44
44
|
default: Remotes::PORT
|
45
45
|
o.string '--host', 'Host name (default: 127.0.0.1)',
|
46
46
|
default: '127.0.0.1'
|
47
|
-
o.string '--home', 'Home directory (default:
|
47
|
+
o.string '--home', 'Home directory (default: .)',
|
48
48
|
default: Dir.pwd
|
49
49
|
o.integer '--strength',
|
50
50
|
"The strength of the score (default: #{Score::STRENGTH})",
|
@@ -52,6 +52,9 @@ module Zold
|
|
52
52
|
o.integer '--threads',
|
53
53
|
'How many threads to use for scores finding (default: 8)',
|
54
54
|
default: 8
|
55
|
+
o.bool '--standalone',
|
56
|
+
'Never communicate with other nodes (mostly for testing)',
|
57
|
+
default: false
|
55
58
|
o.bool '--help', 'Print instructions'
|
56
59
|
end
|
57
60
|
if opts.help?
|
@@ -66,9 +69,20 @@ module Zold
|
|
66
69
|
Logger: WebrickLog.new(@log),
|
67
70
|
AccessLog: []
|
68
71
|
)
|
72
|
+
if opts['standalone']
|
73
|
+
Zold::Front.set(:remotes, Remotes::Empty.new)
|
74
|
+
else
|
75
|
+
Zold::Front.set(
|
76
|
+
:remotes,
|
77
|
+
Remotes.new(
|
78
|
+
File.join(opts[:home], '.zoldata/remotes')
|
79
|
+
)
|
80
|
+
)
|
81
|
+
end
|
69
82
|
Zold::Front.set(:port, opts['bind-port'])
|
70
83
|
FileUtils.mkdir_p(opts[:home])
|
71
84
|
Zold::Front.set(:home, opts[:home])
|
85
|
+
Zold::Front.set(:me, "#{opts[:host]}:#{opts[:port]}".downcase)
|
72
86
|
farm = Farm.new(log: @log)
|
73
87
|
farm.start(
|
74
88
|
opts[:host], opts[:port],
|
@@ -35,6 +35,7 @@ module Zold
|
|
35
35
|
@log = log
|
36
36
|
end
|
37
37
|
|
38
|
+
# Returns list of Wallet IDs which were affected
|
38
39
|
def run(args = [])
|
39
40
|
opts = Slop.parse(args, help: true) do |o|
|
40
41
|
o.banner = "Usage: zold propagate [ID...] [options]
|
@@ -46,13 +47,17 @@ Available options:"
|
|
46
47
|
return
|
47
48
|
end
|
48
49
|
raise 'At least one wallet ID is required' if opts.arguments.empty?
|
50
|
+
modified = []
|
49
51
|
opts.arguments.each do |id|
|
50
|
-
propagate(@wallets.find(id), opts)
|
52
|
+
modified += propagate(@wallets.find(id), opts)
|
51
53
|
end
|
54
|
+
modified
|
52
55
|
end
|
53
56
|
|
57
|
+
# Returns list of Wallet IDs which were affected
|
54
58
|
def propagate(wallet, _)
|
55
59
|
me = wallet.id
|
60
|
+
modified = []
|
56
61
|
wallet.txns.select { |t| t.amount.negative? }.each do |t|
|
57
62
|
target = @wallets.find(t.bnf)
|
58
63
|
unless target.exists?
|
@@ -66,8 +71,12 @@ Available options:"
|
|
66
71
|
end
|
67
72
|
target.add(t.inverse(me))
|
68
73
|
@log.info("#{t.amount.mul(-1)} to #{t.bnf}")
|
74
|
+
modified << t.id
|
69
75
|
end
|
70
|
-
|
76
|
+
modified.uniq!
|
77
|
+
@log.debug("Wallet #{me} propagated successfully, \
|
78
|
+
#{modified.count} wallets affected")
|
79
|
+
modified
|
71
80
|
end
|
72
81
|
end
|
73
82
|
end
|
data/lib/zold/commands/push.rb
CHANGED
@@ -19,6 +19,7 @@
|
|
19
19
|
# SOFTWARE.
|
20
20
|
|
21
21
|
require 'slop'
|
22
|
+
require 'json'
|
22
23
|
require 'net/http'
|
23
24
|
require_relative '../log'
|
24
25
|
require_relative '../id'
|
@@ -55,13 +56,26 @@ Available options:"
|
|
55
56
|
|
56
57
|
def push(wallet, _)
|
57
58
|
raise 'The wallet is absent' unless wallet.exists?
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
total = 0
|
60
|
+
@remotes.all.each do |r|
|
61
|
+
uri = URI("#{r[:home]}wallet/#{wallet.id}")
|
62
|
+
response = Http.new(uri).put(File.read(wallet.path))
|
63
|
+
if response.code != '304' && response.code != '200'
|
64
|
+
@log.error("#{uri} failed as #{response.code}/#{response.message}")
|
65
|
+
next
|
66
|
+
end
|
67
|
+
json = JSON.parse(response.body)['score']
|
68
|
+
score = Score.new(
|
69
|
+
Time.parse(json['time']), json['host'],
|
70
|
+
json['port'], json['suffixes']
|
71
|
+
)
|
72
|
+
unless score.valid?
|
73
|
+
@log.error("#{uri} invalid score")
|
74
|
+
next
|
75
|
+
end
|
76
|
+
total += score.value
|
63
77
|
end
|
64
|
-
@log.info("
|
78
|
+
@log.info("Total score is #{total}")
|
65
79
|
end
|
66
80
|
end
|
67
81
|
end
|
data/lib/zold/http.rb
CHANGED
@@ -40,7 +40,6 @@ module Zold
|
|
40
40
|
def get
|
41
41
|
http = Net::HTTP.new(@uri.host, @uri.port)
|
42
42
|
http.read_timeout = 5
|
43
|
-
http.continue_timeout = 5
|
44
43
|
return http.request_get(@uri.path, headers)
|
45
44
|
rescue StandardError => e
|
46
45
|
return Net::HTTPServerError.new('1.1', '599', e.message)
|
@@ -48,11 +47,13 @@ module Zold
|
|
48
47
|
|
49
48
|
def put(body)
|
50
49
|
http = Net::HTTP.new(@uri.host, @uri.port)
|
51
|
-
http.read_timeout =
|
52
|
-
http.continue_timeout = 5
|
50
|
+
http.read_timeout = 60
|
53
51
|
return http.request_put(
|
54
52
|
@uri.path, body,
|
55
|
-
headers.merge(
|
53
|
+
headers.merge(
|
54
|
+
'Content-Type': 'text/plain',
|
55
|
+
'Content-Length': body.length.to_s
|
56
|
+
)
|
56
57
|
)
|
57
58
|
rescue StandardError => e
|
58
59
|
return Net::HTTPServerError.new('1.1', '599', e.message)
|
data/lib/zold/node/front.rb
CHANGED
@@ -50,12 +50,13 @@ module Zold
|
|
50
50
|
set :log, Log.new
|
51
51
|
set :show_exceptions, false
|
52
52
|
set :home, Dir.pwd
|
53
|
+
set :me, 'localhost:4096'
|
53
54
|
set :farm, Farm.new
|
54
55
|
set :server, 'webrick'
|
55
56
|
end
|
56
57
|
|
57
58
|
before do
|
58
|
-
if request.env[Http::SCORE_HEADER]
|
59
|
+
if request.env[Http::SCORE_HEADER] && !settings.remotes.empty?
|
59
60
|
s = Score.parse(request.env[Http::SCORE_HEADER])
|
60
61
|
error(400, 'The score is invalid') unless s.valid?
|
61
62
|
error(400, 'The score is weak') if s.strength < Score::STRENGTH
|
@@ -85,7 +86,7 @@ module Zold
|
|
85
86
|
wallets: wallets.all.count,
|
86
87
|
farm: settings.farm.to_json,
|
87
88
|
date: `date --iso-8601=seconds -u`.strip,
|
88
|
-
|
89
|
+
hours_alive: ((Time.now - settings.start) / (60 * 60)).round(2),
|
89
90
|
home: 'https://www.zold.io'
|
90
91
|
)
|
91
92
|
end
|
@@ -106,20 +107,38 @@ module Zold
|
|
106
107
|
id = Id.new(params[:id])
|
107
108
|
wallet = wallets.find(id)
|
108
109
|
request.body.rewind
|
110
|
+
body = request.body.read
|
111
|
+
if wallet.exists? && File.read(wallet.path) == body
|
112
|
+
status 304
|
113
|
+
return JSON.pretty_generate(
|
114
|
+
version: VERSION, score: score.to_h
|
115
|
+
)
|
116
|
+
end
|
109
117
|
cps = copies(id)
|
110
|
-
cps.add(
|
118
|
+
cps.add(body, 'remote', Remotes::PORT, 0)
|
111
119
|
require_relative '../commands/fetch'
|
112
120
|
Zold::Fetch.new(
|
113
|
-
remotes: remotes, copies: cps.root,
|
121
|
+
remotes: settings.remotes, copies: cps.root,
|
114
122
|
log: settings.log
|
115
|
-
).run([id.to_s])
|
123
|
+
).run([id.to_s, "--ignore-node=#{settings.me}"])
|
116
124
|
require_relative '../commands/merge'
|
117
|
-
Zold::Merge.new(
|
125
|
+
modified = Zold::Merge.new(
|
118
126
|
wallets: wallets, copies: cps.root,
|
119
127
|
log: settings.log
|
120
128
|
).run([id.to_s])
|
121
129
|
cps.remove('remote', Remotes::PORT)
|
122
|
-
|
130
|
+
modified.each do |m|
|
131
|
+
Zold::Push.new(
|
132
|
+
wallets: wallets, remotes: settings.remotes,
|
133
|
+
log: settings.log
|
134
|
+
).run([m.to_s])
|
135
|
+
end
|
136
|
+
JSON.pretty_generate(
|
137
|
+
version: VERSION,
|
138
|
+
score: score.to_h,
|
139
|
+
balance: wallet.balance,
|
140
|
+
modified: modified.count
|
141
|
+
)
|
123
142
|
end
|
124
143
|
|
125
144
|
get '/remotes' do
|
@@ -127,7 +146,7 @@ module Zold
|
|
127
146
|
JSON.pretty_generate(
|
128
147
|
version: VERSION,
|
129
148
|
score: score.to_h,
|
130
|
-
all: remotes.all.map do |r|
|
149
|
+
all: settings.remotes.all.map do |r|
|
131
150
|
{
|
132
151
|
host: r[:host],
|
133
152
|
port: r[:port]
|
@@ -158,11 +177,7 @@ module Zold
|
|
158
177
|
private
|
159
178
|
|
160
179
|
def copies(id)
|
161
|
-
Copies.new(File.join(settings.home, ".
|
162
|
-
end
|
163
|
-
|
164
|
-
def remotes
|
165
|
-
Remotes.new(File.join(settings.home, '.zold/remotes'))
|
180
|
+
Copies.new(File.join(settings.home, ".zoldata/copies/#{id}"))
|
166
181
|
end
|
167
182
|
|
168
183
|
def wallets
|
data/lib/zold/patch.rb
CHANGED
@@ -49,10 +49,15 @@ module Zold
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
# Returns TRUE if the file was actually modified
|
52
53
|
def save(file, overwrite: false)
|
54
|
+
before = ''
|
55
|
+
before = File.read(file) if File.exist?(file)
|
53
56
|
wallet = Zold::Wallet.new(file)
|
54
57
|
wallet.init(@id, @key, overwrite: overwrite)
|
55
58
|
@txns.each { |t| wallet.add(t) }
|
59
|
+
after = File.read(file)
|
60
|
+
before != after
|
56
61
|
end
|
57
62
|
end
|
58
63
|
end
|
data/lib/zold/remotes.rb
CHANGED
@@ -31,12 +31,15 @@ module Zold
|
|
31
31
|
class Remotes
|
32
32
|
PORT = 4096
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
# Empty, for standalone mode
|
35
|
+
class Empty
|
36
|
+
def all
|
37
|
+
[]
|
38
|
+
end
|
36
39
|
end
|
37
40
|
|
38
|
-
def
|
39
|
-
|
41
|
+
def initialize(file)
|
42
|
+
@file = file
|
40
43
|
end
|
41
44
|
|
42
45
|
def all
|
@@ -56,7 +59,8 @@ module Zold
|
|
56
59
|
end
|
57
60
|
|
58
61
|
def exists?(host, port = Remotes::PORT)
|
59
|
-
|
62
|
+
raise 'Port has to be of type Integer' unless port.is_a?(Integer)
|
63
|
+
!load.find { |r| r[:host] == host.downcase && r[:port] == port }.nil?
|
60
64
|
end
|
61
65
|
|
62
66
|
def add(host, port = Remotes::PORT)
|
@@ -64,7 +68,7 @@ module Zold
|
|
64
68
|
raise 'Port can\'t be negative' if port < 0
|
65
69
|
raise 'Port can\'t be over 65536' if port > 0xffff
|
66
70
|
list = load
|
67
|
-
list << { host: host, port: port, score: 0 }
|
71
|
+
list << { host: host.downcase, port: port, score: 0 }
|
68
72
|
list.uniq! { |r| "#{r[:host]}:#{r[:port]}" }
|
69
73
|
save(list)
|
70
74
|
end
|
@@ -72,20 +76,20 @@ module Zold
|
|
72
76
|
def remove(host, port = Remotes::PORT)
|
73
77
|
raise 'Port has to be of type Integer' unless port.is_a?(Integer)
|
74
78
|
list = load
|
75
|
-
list.reject! { |r| r[:host] == host && r[:port] == port }
|
79
|
+
list.reject! { |r| r[:host] == host.downcase && r[:port] == port }
|
76
80
|
save(list)
|
77
81
|
end
|
78
82
|
|
79
83
|
def score(host, port = Remotes::PORT)
|
80
84
|
raise 'Port has to be of type Integer' unless port.is_a?(Integer)
|
81
|
-
load.find { |r| r[:host] == host && r[:port] == port }[:score]
|
85
|
+
load.find { |r| r[:host] == host.downcase && r[:port] == port }[:score]
|
82
86
|
end
|
83
87
|
|
84
88
|
def rescore(host, port, score)
|
85
89
|
raise 'Port has to be of type Integer' unless port.is_a?(Integer)
|
86
90
|
list = load
|
87
91
|
list.find do |r|
|
88
|
-
r[:host] == host && r[:port] == port
|
92
|
+
r[:host] == host.downcase && r[:port] == port
|
89
93
|
end[:score] = score
|
90
94
|
save(list)
|
91
95
|
end
|
data/lib/zold/version.rb
CHANGED
data/test/commands/test_merge.rb
CHANGED
@@ -54,10 +54,12 @@ class TestMerge < Minitest::Test
|
|
54
54
|
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
55
55
|
copies.add(File.read(first.path), 'host-1', 80, 5)
|
56
56
|
copies.add(File.read(second.path), 'host-2', 80, 5)
|
57
|
-
Zold::Merge.new(
|
57
|
+
modified = Zold::Merge.new(
|
58
58
|
wallets: Zold::Wallets.new(dir),
|
59
59
|
copies: copies.root
|
60
60
|
).run([id.to_s])
|
61
|
+
assert(1, modified.count)
|
62
|
+
assert(id, modified[0])
|
61
63
|
end
|
62
64
|
end
|
63
65
|
|
@@ -78,10 +80,12 @@ class TestMerge < Minitest::Test
|
|
78
80
|
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
79
81
|
copies.add(File.read(first.path), 'host-1', 80, 5)
|
80
82
|
copies.add(File.read(second.path), 'host-2', 80, 5)
|
81
|
-
Zold::Merge.new(
|
83
|
+
modified = Zold::Merge.new(
|
82
84
|
wallets: Zold::Wallets.new(dir),
|
83
85
|
copies: copies.root
|
84
86
|
).run([id.to_s])
|
87
|
+
assert(1, modified.count)
|
88
|
+
assert(id, modified[0])
|
85
89
|
end
|
86
90
|
end
|
87
91
|
end
|
data/test/test_patch.rb
CHANGED
data/test/test_remotes.rb
CHANGED
@@ -34,7 +34,7 @@ class TestRemotes < Minitest::Test
|
|
34
34
|
remotes = Zold::Remotes.new(file)
|
35
35
|
remotes.add('127.0.0.1')
|
36
36
|
remotes.add('127.0.0.1')
|
37
|
-
assert(
|
37
|
+
assert(1, remotes.all.count)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -44,9 +44,9 @@ class TestRemotes < Minitest::Test
|
|
44
44
|
FileUtils.touch(file)
|
45
45
|
remotes = Zold::Remotes.new(file)
|
46
46
|
remotes.add('127.0.0.1')
|
47
|
-
remotes.add('
|
47
|
+
remotes.add('LOCALHOST', 433)
|
48
48
|
remotes.remove('localhost', 433)
|
49
|
-
assert(
|
49
|
+
assert(1, remotes.all.count)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -55,7 +55,7 @@ class TestRemotes < Minitest::Test
|
|
55
55
|
remotes = Zold::Remotes.new(File.join(dir, 'remotes'))
|
56
56
|
remotes.clean
|
57
57
|
remotes.reset
|
58
|
-
assert(!remotes.
|
58
|
+
assert(!remotes.all.empty?)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|