zold 0.10.7 → 0.10.8

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: '0008825f612b15bbca2f63f1a20229bce08e28c9'
4
- data.tar.gz: 42d23123921ba6347cc2b234195d6cce30c7f471
3
+ metadata.gz: c2d0bc52f647f22b12dfb70543a113e7d4a0393a
4
+ data.tar.gz: f883780a0b2b0d5d4db0c261899ca4df7a357e15
5
5
  SHA512:
6
- metadata.gz: 8012e04638c964ced09998754700490f7e24175b066bf11ecc9240e0274654fa686b1157bf4c31995dce9ddca842b8f4bb51e7a32ca6c48b2de411f8016d0f42
7
- data.tar.gz: ab611b5530d5fea3362a67cd21cfd89855f9ce7bafcd320ac2a2a87bee3eff684f31a16996709bf9947d203ed8b68d21d9489c94d61689374570c37d4b47e51b
6
+ metadata.gz: e6657086782bfbd32fe8867a292ed7bc45e1e63d6640ff3bb148f1e7a322daa59c47a95278e276851693a223a4b88ecddd69dcc22591f43d1289dbde54e14f94
7
+ data.tar.gz: 17d58f71dc6a3a83334ab656cdd9c6a391da37ae544df9dac0a5a20f8ace8bec14fcaf294f7191bd4f81df80db6e93847676144feb9ac67e8f1d99685634dce9
data/.rultor.yml CHANGED
@@ -10,7 +10,7 @@ release:
10
10
  bundle install
11
11
  rake
12
12
  rm -rf *.gem
13
- sed -i "s/1\.0\.snapshot/${tag}/g" lib/zold/version.rb
13
+ sed -i "s/0\.0\.0/${tag}/g" lib/zold/version.rb
14
14
  git add lib/zold/version.rb
15
15
  git commit -m "version set to ${tag}"
16
16
  gem build zold.gemspec
@@ -34,7 +34,7 @@ zold show
34
34
  zold show 0000000000000000
35
35
 
36
36
  zold remote show
37
- zold push 0000000000000000
37
+ zold push 0000000000000000 --sync
38
38
  zold fetch 0000000000000000 --ignore-score-weakness
39
39
  zold diff 0000000000000000
40
40
  zold merge 0000000000000000
@@ -85,8 +85,8 @@ Available options:"
85
85
  r.assert_valid_score(score)
86
86
  raise "Score is too weak #{score.strength}" if score.strength < Score::STRENGTH && !opts['ignore-score-weakness']
87
87
  cps.add(json['body'], score.host, score.port, score.value)
88
- @log.info("#{r} #{json['body'].length}b/#{Rainbow(score.value).green} (#{json['version']}) \
89
- in #{(Time.now - start).round(2)}s")
88
+ @log.info("#{r} returned #{json['body'].length}b/#{Rainbow(score.value).green} \
89
+ of #{id} (#{json['version']}) in #{(Time.now - start).round(2)}s")
90
90
  end
91
91
  end
92
92
  end
@@ -114,7 +114,7 @@ module Zold
114
114
  )
115
115
  Zold::Front.set(:farm, farm)
116
116
  Thread.start do
117
- Zold::Remote.new(remotes: remotes, farm: farm, log: @log).run(%w[remote update]) unless best.nil?
117
+ Zold::Remote.new(remotes: remotes, farm: farm, log: @log).run(%w[remote update --reboot]) unless best.nil?
118
118
  end
119
119
  @log.debug('Starting up the web front...')
120
120
  begin
@@ -44,6 +44,9 @@ module Zold
44
44
  opts = Slop.parse(args, help: true, suppress_errors: true) do |o|
45
45
  o.banner = "Usage: zold push [ID...] [options]
46
46
  Available options:"
47
+ o.bool '--sync',
48
+ 'Wait until the server confirms merge and pushes all wallets further (default: false)',
49
+ default: false
47
50
  o.bool '--help', 'Print instructions'
48
51
  end
49
52
  mine = Args.new(opts, @log).take || return
@@ -55,13 +58,15 @@ Available options:"
55
58
  end
56
59
  end
57
60
 
58
- def push(wallet, _)
61
+ def push(wallet, opts)
59
62
  total = 0
60
63
  @remotes.iterate(@log) do |r|
61
64
  start = Time.now
62
- response = r.http("/wallet/#{wallet.id}").put(File.read(wallet.path))
65
+ response = r.http(
66
+ "/wallet/#{wallet.id}#{opts['sync'] ? '?sync=true' : ''}"
67
+ ).put(File.read(wallet.path))
63
68
  if response.code == '304'
64
- @log.info("#{r}: same version there")
69
+ @log.info("#{r}: same version of #{wallet.id} there")
65
70
  next
66
71
  end
67
72
  r.assert_code(200, response)
@@ -69,10 +74,10 @@ Available options:"
69
74
  score = Score.parse_json(json)
70
75
  r.assert_valid_score(score)
71
76
  raise "Score is too weak #{score}" if score.strength < Score::STRENGTH
72
- @log.info("#{r} accepted in #{(Time.now - start).round(2)}s: #{Rainbow(score.value).green}")
77
+ @log.info("#{r} accepted #{wallet.id} in #{(Time.now - start).round(2)}s: #{Rainbow(score.value).green}")
73
78
  total += score.value
74
79
  end
75
- @log.info("Total score is #{total}")
80
+ @log.info("Total score for #{wallet.id} is #{total}")
76
81
  end
77
82
  end
78
83
  end
@@ -19,6 +19,7 @@
19
19
  # SOFTWARE.
20
20
 
21
21
  require 'slop'
22
+ require 'semantic'
22
23
  require 'rainbow'
23
24
  require 'net/http'
24
25
  require 'json'
@@ -61,6 +62,9 @@ Available options:"
61
62
  o.bool '--ignore-score-weakness',
62
63
  'Don\'t complain when their score is too weak',
63
64
  default: false
65
+ o.bool '--reboot',
66
+ 'Exit if any node reports version higher than we have',
67
+ default: false
64
68
  o.bool '--help', 'Print instructions'
65
69
  end
66
70
  mine = Args.new(opts, @log).take || return
@@ -125,6 +129,10 @@ Available options:"
125
129
  raise "Score too weak: #{score.strength}" if score.strength < Score::STRENGTH && !opts['ignore-score-weakness']
126
130
  raise "Masqueraded as #{score.host}:#{score.port}" if r.host != score.host || r.port != score.port
127
131
  @remotes.rescore(score.host, score.port, score.value)
132
+ if opts['reboot'] && Semantic::Version.new(VERSION) < Semantic::Version.new(json['version'])
133
+ @log.info("#{r}: their version #{json['version']} is higher than mine #{VERSION}, reboot!")
134
+ exit(0)
135
+ end
128
136
  if deep
129
137
  json['all'].each do |s|
130
138
  add(s['host'], s['port']) unless @remotes.exists?(s['host'], s['port'])
data/lib/zold/http.rb CHANGED
@@ -48,7 +48,9 @@ module Zold
48
48
  def get
49
49
  http = Net::HTTP.new(@uri.host, @uri.port)
50
50
  http.read_timeout = 5
51
- return http.request_get(@uri.path, headers)
51
+ path = @uri.path
52
+ path += '?' + @uri.query if @uri.query
53
+ return http.request_get(path, headers)
52
54
  rescue StandardError => e
53
55
  Error.new(e)
54
56
  end
@@ -56,8 +58,10 @@ module Zold
56
58
  def put(body)
57
59
  http = Net::HTTP.new(@uri.host, @uri.port)
58
60
  http.read_timeout = 60
61
+ path = @uri.path
62
+ path += '?' + @uri.query if @uri.query
59
63
  return http.request_put(
60
- @uri.path, body,
64
+ path, body,
61
65
  headers.merge(
62
66
  'Content-Type': 'text/plain',
63
67
  'Content-Length': body.length.to_s
@@ -46,11 +46,14 @@ module Zold
46
46
  @semaphores = Concurrent::Map.new
47
47
  end
48
48
 
49
- def push(id, body)
49
+ def push(id, body, sync: true)
50
50
  check(body)
51
- @semaphores.put_if_absent(id, Mutex.new)
52
- @semaphores.get(id).synchronize do
53
- push_unsafe(id, body)
51
+ if sync
52
+ push_sync(id, body)
53
+ else
54
+ Thread.new do
55
+ push_sync(id, body)
56
+ end
54
57
  end
55
58
  end
56
59
 
@@ -60,7 +63,9 @@ module Zold
60
63
  wallet = Wallet.new(f)
61
64
  break unless wallet.network == Wallet::MAIN_NETWORK
62
65
  balance = wallet.balance
63
- raise "The balance #{balance} is negative and it's not a root wallet" if balance.negative? && !wallet.root?
66
+ if balance.negative? && !wallet.root?
67
+ raise "The balance #{balance} of #{wallet.id} is negative and it's not a root wallet"
68
+ end
64
69
  Emission.new(wallet).check
65
70
  tax = Tax.new(wallet)
66
71
  if tax.in_debt?
@@ -69,6 +74,15 @@ module Zold
69
74
  end
70
75
  end
71
76
 
77
+ def push_sync(id, body)
78
+ @semaphores.put_if_absent(id, Mutex.new)
79
+ @semaphores.get(id).synchronize do
80
+ modified = push_unsafe(id, body)
81
+ @log.info("Accepted #{id} and modified: #{modified.join(', ')}")
82
+ modified
83
+ end
84
+ end
85
+
72
86
  def push_unsafe(id, body)
73
87
  copies = Copies.new(File.join(@copies, id.to_s))
74
88
  copies.add(body, 'remote', Remotes::PORT, 0)
@@ -23,7 +23,6 @@ STDOUT.sync = true
23
23
  require 'json'
24
24
  require 'sinatra/base'
25
25
  require 'webrick'
26
- require 'semantic'
27
26
  require_relative '../version'
28
27
  require_relative '../wallet'
29
28
  require_relative '../log'
@@ -58,11 +57,6 @@ module Zold
58
57
  end
59
58
 
60
59
  before do
61
- if request.env[Http::VERSION_HEADER] &&
62
- Semantic::Version.new(VERSION) < Semantic::Version.new(request.env[Http::VERSION_HEADER]) &&
63
- !settings.remotes.empty? && settings.reboot
64
- exit(0)
65
- end
66
60
  return unless request.env[Http::SCORE_HEADER]
67
61
  return unless settings.remotes.empty?
68
62
  s = Score.parse(request.env[Http::SCORE_HEADER])
@@ -121,12 +115,10 @@ module Zold
121
115
  status 304
122
116
  return
123
117
  end
124
- modified = settings.entrance.push(id, body)
118
+ settings.entrance.push(id, body, sync: !params[:sync].nil?)
125
119
  JSON.pretty_generate(
126
120
  version: VERSION,
127
- score: score.to_h,
128
- balance: wallet.balance,
129
- modified: modified.count
121
+ score: score.to_h
130
122
  )
131
123
  end
132
124
 
data/lib/zold/version.rb CHANGED
@@ -23,5 +23,5 @@
23
23
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
24
24
  # License:: MIT
25
25
  module Zold
26
- VERSION = '0.10.7'.freeze
26
+ VERSION = '0.10.8'.freeze
27
27
  end
@@ -47,7 +47,7 @@ class TestNode < Minitest::Test
47
47
  remotes = Zold::Remotes.new(File.join(dir, 'remotes.csv'))
48
48
  remotes.clean
49
49
  remotes.add('localhost', port)
50
- Zold::Push.new(wallets: wallets, remotes: remotes, log: $log).run(['push'])
50
+ Zold::Push.new(wallets: wallets, remotes: remotes, log: $log).run(['push', '--sync'])
51
51
  Zold::Fetch.new(
52
52
  wallets: wallets, copies: File.join(dir, 'copies'),
53
53
  remotes: remotes, log: $log
@@ -22,6 +22,7 @@ require 'minitest/autorun'
22
22
  require 'tmpdir'
23
23
  require 'webmock/minitest'
24
24
  require_relative '../test__helper'
25
+ require_relative '../../lib/zold/version'
25
26
  require_relative '../../lib/zold/wallets'
26
27
  require_relative '../../lib/zold/remotes'
27
28
  require_relative '../../lib/zold/key'
@@ -41,6 +42,7 @@ class TestRemote < Minitest::Test
41
42
  stub_request(:get, "http://#{zero.host}:#{zero.port}/remotes").to_return(
42
43
  status: 200,
43
44
  body: {
45
+ version: Zold::VERSION,
44
46
  score: zero.to_h,
45
47
  all: [
46
48
  { host: 'localhost', port: 888 },
data/test/test_zold.rb CHANGED
@@ -52,7 +52,7 @@ class TestZold < Minitest::Test
52
52
 
53
53
  def test_show_version
54
54
  stdout = exec('--version')
55
- assert(stdout.include?('1.0.snapshot'))
55
+ assert(stdout.include?('0.0.0'))
56
56
  end
57
57
 
58
58
  def test_create_new_wallet
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.10.7
4
+ version: 0.10.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko