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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73c4792176a13df605a885ea46e4cb92b0df76c6
4
- data.tar.gz: 6ca3f32b2975db9dcf533aeb746e80e775224427
3
+ metadata.gz: bbeb43337cb9f0a00e30ea6898f5a03636fcf1bb
4
+ data.tar.gz: d141288a3fbeee753c6e8e961a63d9932086442d
5
5
  SHA512:
6
- metadata.gz: 6982d8437738d658d3d530c69525a501cc409237d2ae42c8affe8edc046636e83e06ae1cb51d0fbe8cefa0da9ae30e1a2da43a72c19037b721c631cb765fee73
7
- data.tar.gz: 14a0e10962910847fea075ea48b26063e2baac9ed91e1b46453cee53764ebbc641b773bb0de5d8aeb854881852941bad46a15e208e379b5f266017da98d8ce33
6
+ metadata.gz: 2aa295616ec945fbdf1106b741021c55bfb8f84200d9934d27a00324abf1fed3c4c54432f06f3943f8f46c625bf02cce079a55b813541fddfef12b0872e41456
7
+ data.tar.gz: 98225c2ffc7f126586241e62177c6c293d7c43e78c610843b4f462ca46f5552374d38849e33a18bc33f3088118fcb9f22a6102176779b56b6af3bf82d3967e6e
@@ -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
- raise "Score is too weak #{score.strength}" if score.strength < Score::STRENGTH && !opts['ignore-score-weakness']
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)
@@ -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("Total score for #{wallet.id} is #{total}")
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
- raise "Score is too weak #{score}" if score.strength < Score::STRENGTH
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
@@ -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
- raise "Score too weak: #{score.strength}" if score.strength < Score::STRENGTH && !opts['ignore-score-weakness']
159
- raise "Masqueraded as #{score.host}:#{score.port}" if r.host != score.host || r.port != score.port
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! \
@@ -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
- raise "Score is too weak (<#{Score::STRENGTH}) #{score}" if score.strength < Score::STRENGTH
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
@@ -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
- @log.info("Accepted #{id} in #{(Time.now - start) / 60}s and modified #{modified.join(', ')}")
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
- copies.add(body, '0.0.0.0', Remotes::PORT, 0)
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('remote', Remotes::PORT)
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
@@ -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)
@@ -23,5 +23,5 @@
23
23
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
24
24
  # License:: MIT
25
25
  module Zold
26
- VERSION = '0.11.8'.freeze
26
+ VERSION = '0.11.9'.freeze
27
27
  end
@@ -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://fake-1/wallet/#{id}").to_return(
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://fake-2/wallet/#{id}").to_return(
56
+ stub_request(:get, "http://localhost:81/wallet/#{id}").to_return(
57
57
  status: 404
58
58
  )
59
- remotes.add('fake-1', 80)
60
- remotes.add('fake-2', 80)
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://fake-1/wallet/#{id}").to_return(
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('fake-1', 80)
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
@@ -47,7 +47,7 @@ class FakeNode
47
47
  Zold::Node.new(log: @log).run(
48
48
  [
49
49
  '--port', port.to_s,
50
- '--host=locahost',
50
+ '--host=localhost',
51
51
  '--bind-port', port.to_s,
52
52
  '--threads=1',
53
53
  '--home', home,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.8
4
+ version: 0.11.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko