zold 0.10.12 → 0.10.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/INSTALL.md +54 -0
- data/README.md +5 -7
- data/lib/zold/commands/calculate.rb +2 -0
- data/lib/zold/commands/create.rb +2 -0
- data/lib/zold/commands/diff.rb +2 -0
- data/lib/zold/commands/fetch.rb +2 -0
- data/lib/zold/commands/invoice.rb +2 -0
- data/lib/zold/commands/merge.rb +2 -0
- data/lib/zold/commands/node.rb +5 -1
- data/lib/zold/commands/pay.rb +2 -0
- data/lib/zold/commands/propagate.rb +2 -0
- data/lib/zold/commands/push.rb +2 -0
- data/lib/zold/commands/remote.rb +24 -9
- data/lib/zold/commands/show.rb +2 -0
- data/lib/zold/commands/taxes.rb +2 -2
- data/lib/zold/http.rb +1 -1
- data/lib/zold/node/front.rb +13 -4
- data/lib/zold/score.rb +14 -14
- data/lib/zold/version.rb +1 -1
- data/test/node/fake_node.rb +4 -5
- data/test/node/test_front.rb +13 -8
- data/test/test__helper.rb +3 -0
- data/test/test_score.rb +6 -6
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6232c5057d899ff2c3600af61ca53b872a01c79
|
4
|
+
data.tar.gz: 5ad79a8d968e3e03fa70c3955bfe813c1c493bec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '01845774b4f1783571f47097513d006cbb670da6e0ca040df72039092cdafabd2e588bc470932eb8ee4bb84f423d52f4eabaa5a9c0ab353937d7ccde37e89e48'
|
7
|
+
data.tar.gz: 20cca37c6f77efdc6a150e73d574db3c92da458311197c639cc493c7b6f2297f956b90aeada211e44143ee2e7cc7d8ec16e62b870f910888e91406fd4708a1ff
|
data/INSTALL.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
<img src="http://www.zold.io/logo.svg" width="92px" height="92px"/>
|
2
|
+
|
3
|
+
This is how you install `zold` Ruby gem on different platform.
|
4
|
+
|
5
|
+
We are very interested in your contribution to this document.
|
6
|
+
If and when you experience any problems, make changes here via a pull request.
|
7
|
+
|
8
|
+
Basically, you need to
|
9
|
+
install [Ruby 2.3+](https://www.ruby-lang.org/en/documentation/installation/),
|
10
|
+
[Rubygems](https://rubygems.org/pages/download), and
|
11
|
+
then the [gem](https://rubygems.org/gems/zold).
|
12
|
+
|
13
|
+
## Ubuntu 16.04
|
14
|
+
|
15
|
+
```bash
|
16
|
+
$ sudo apt-get update -y
|
17
|
+
$ sudo apt-get install -y ruby-dev rubygems zlib1g-dev libssl-dev
|
18
|
+
$ gem install zold
|
19
|
+
```
|
20
|
+
|
21
|
+
## OSX
|
22
|
+
|
23
|
+
With homebrew:
|
24
|
+
|
25
|
+
```
|
26
|
+
$ brew install rbenv ruby-build
|
27
|
+
$ rbenv install 2.5.1
|
28
|
+
$ rbenv global 2.5.1
|
29
|
+
$ ruby -v
|
30
|
+
$ gem install zold
|
31
|
+
```
|
32
|
+
|
33
|
+
Without homebrew:
|
34
|
+
|
35
|
+
... no idea ...
|
36
|
+
|
37
|
+
## Windows
|
38
|
+
|
39
|
+
... please contribute ...
|
40
|
+
|
41
|
+
## CentOS
|
42
|
+
|
43
|
+
... please contribute ...
|
44
|
+
|
45
|
+
## Amazon Linux (AWS EC2 default image)
|
46
|
+
|
47
|
+
```
|
48
|
+
sudo yum install zlib-devel gcc gcc-c++ ruby-devel rubygems ruby
|
49
|
+
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
|
50
|
+
curl -sSL https://get.rvm.io | bash -s stable
|
51
|
+
source $HOME/.rvm/scripts/rvm
|
52
|
+
rvm install 2.5.1
|
53
|
+
gem install zold
|
54
|
+
```
|
data/README.md
CHANGED
@@ -27,12 +27,8 @@ The license is [MIT](https://github.com/yegor256/zold/blob/master/LICENSE.txt).
|
|
27
27
|
|
28
28
|
First, install [Ruby 2.3+](https://www.ruby-lang.org/en/documentation/installation/),
|
29
29
|
[Rubygems](https://rubygems.org/pages/download), and
|
30
|
-
the [gem](https://rubygems.org/gems/zold)
|
31
|
-
|
32
|
-
```bash
|
33
|
-
$ sudo apt-get install ruby-dev rubygems zlib1g-dev libssl-dev
|
34
|
-
$ gem install zold
|
35
|
-
```
|
30
|
+
the [gem](https://rubygems.org/gems/zold).
|
31
|
+
Here is [how](https://github.com/yegor256/zold/blob/master/INSTALL.md).
|
36
32
|
|
37
33
|
To make sure it's installed, try:
|
38
34
|
|
@@ -98,7 +94,9 @@ and your own public IP address instead of `4.4.4.4`):
|
|
98
94
|
$ zold node --trace --verbose --invoice=5f96e731e48ae21f --host=4.4.4.4
|
99
95
|
```
|
100
96
|
|
101
|
-
Then, open the page `4.4.4.4:4096` in your browser
|
97
|
+
Then, open the page `4.4.4.4:4096` in your browser
|
98
|
+
(you may need to open the inbound port at your
|
99
|
+
[IP firewall](https://www.howtogeek.com/177621/the-beginners-guide-to-iptables-the-linux-firewall/)).
|
102
100
|
If you see a simple JSON document, everything is fine.
|
103
101
|
Next, hit <kbd>Ctrl</kbd>+<kbd>c</kbd> and run this line, in order
|
104
102
|
to start the node and make sure it will be online even when you log off
|
data/lib/zold/commands/create.rb
CHANGED
data/lib/zold/commands/diff.rb
CHANGED
data/lib/zold/commands/fetch.rb
CHANGED
data/lib/zold/commands/merge.rb
CHANGED
data/lib/zold/commands/node.rb
CHANGED
@@ -62,6 +62,9 @@ module Zold
|
|
62
62
|
o.bool '--standalone',
|
63
63
|
'Never communicate with other nodes (mostly for testing)',
|
64
64
|
default: false
|
65
|
+
o.bool '--ignore-score-weakness',
|
66
|
+
'Ignore score weakness of incoming requests and register those nodes anyway',
|
67
|
+
default: false
|
65
68
|
o.bool '--never-reboot',
|
66
69
|
'Don\'t reboot when a new version shows up in the network',
|
67
70
|
default: false
|
@@ -87,6 +90,7 @@ module Zold
|
|
87
90
|
else
|
88
91
|
remotes = Remotes.new(File.join(opts[:home], 'zold-remotes'))
|
89
92
|
end
|
93
|
+
Front.set(:ignore_score_weakness, opts['ignore-score-weakness'])
|
90
94
|
wallets = Wallets.new(File.join(opts[:home], 'zold-wallets'))
|
91
95
|
Front.set(:wallets, wallets)
|
92
96
|
Front.set(:remotes, remotes)
|
@@ -124,7 +128,7 @@ module Zold
|
|
124
128
|
end
|
125
129
|
end
|
126
130
|
end
|
127
|
-
@log.debug(
|
131
|
+
@log.debug("Starting up the web front at http://#{opts[:host]}:#{opts[:port]}...")
|
128
132
|
begin
|
129
133
|
Front.run!
|
130
134
|
ensure
|
data/lib/zold/commands/pay.rb
CHANGED
data/lib/zold/commands/push.rb
CHANGED
data/lib/zold/commands/remote.rb
CHANGED
@@ -62,6 +62,9 @@ Available options:"
|
|
62
62
|
o.bool '--ignore-score-weakness',
|
63
63
|
'Don\'t complain when their score is too weak',
|
64
64
|
default: false
|
65
|
+
o.bool '--force',
|
66
|
+
'Add/remove if if this operation is not possible',
|
67
|
+
default: false
|
65
68
|
o.bool '--reboot',
|
66
69
|
'Exit if any node reports version higher than we have',
|
67
70
|
default: false
|
@@ -77,9 +80,9 @@ Available options:"
|
|
77
80
|
when 'reset'
|
78
81
|
reset
|
79
82
|
when 'add'
|
80
|
-
add(mine[1], mine[2] ? mine[2].to_i : Remotes::PORT)
|
83
|
+
add(mine[1], mine[2] ? mine[2].to_i : Remotes::PORT, opts)
|
81
84
|
when 'remove'
|
82
|
-
remove(mine[1], mine[2] ? mine[2].to_i : Remotes::PORT)
|
85
|
+
remove(mine[1], mine[2] ? mine[2].to_i : Remotes::PORT, opts)
|
83
86
|
when 'update'
|
84
87
|
update(opts)
|
85
88
|
update(opts, false)
|
@@ -88,6 +91,8 @@ Available options:"
|
|
88
91
|
end
|
89
92
|
end
|
90
93
|
|
94
|
+
private
|
95
|
+
|
91
96
|
def show
|
92
97
|
@remotes.all.each do |r|
|
93
98
|
score = Rainbow("/#{r[:score]}").color(r[:score] > 0 ? :green : :red)
|
@@ -105,15 +110,25 @@ Available options:"
|
|
105
110
|
@log.debug('Remote nodes set back to default')
|
106
111
|
end
|
107
112
|
|
108
|
-
def add(host, port)
|
109
|
-
@remotes.
|
110
|
-
|
113
|
+
def add(host, port, opts)
|
114
|
+
if @remotes.exists?(host, port)
|
115
|
+
raise "#{host}:#{port} already exists in the list" unless opts['force']
|
116
|
+
@log.info("#{host}:#{port} already exists in the list")
|
117
|
+
else
|
118
|
+
@remotes.add(host, port)
|
119
|
+
@log.info("#{host}:#{port} added to the list")
|
120
|
+
end
|
111
121
|
@log.info("There are #{@remotes.all.count} remote nodes in the list")
|
112
122
|
end
|
113
123
|
|
114
|
-
def remove(host, port)
|
115
|
-
@remotes.
|
116
|
-
|
124
|
+
def remove(host, port, opts)
|
125
|
+
if @remotes.exists?(host, port)
|
126
|
+
@remotes.remove(host, port)
|
127
|
+
@log.info("#{host}:#{port} removed from the list")
|
128
|
+
else
|
129
|
+
raise "#{host}:#{port} is not in the list" unless opts['force']
|
130
|
+
@log.info("#{host}:#{port} is not in the list")
|
131
|
+
end
|
117
132
|
@log.info("There are #{@remotes.all.count} remote nodes in the list")
|
118
133
|
end
|
119
134
|
|
@@ -135,7 +150,7 @@ Available options:"
|
|
135
150
|
end
|
136
151
|
if deep
|
137
152
|
json['all'].each do |s|
|
138
|
-
add(s['host'], s['port']) unless @remotes.exists?(s['host'], s['port'])
|
153
|
+
add(s['host'], s['port'], opts) unless @remotes.exists?(s['host'], s['port'])
|
139
154
|
end
|
140
155
|
end
|
141
156
|
capacity << { host: score.host, port: score.port, count: json['all'].count }
|
data/lib/zold/commands/show.rb
CHANGED
data/lib/zold/commands/taxes.rb
CHANGED
@@ -82,6 +82,8 @@ Available options:"
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
+
private
|
86
|
+
|
85
87
|
def pay(wallet, _)
|
86
88
|
raise 'The wallet is absent' unless wallet.exists?
|
87
89
|
tax = Tax.new(wallet)
|
@@ -113,8 +115,6 @@ Available options:"
|
|
113
115
|
raise 'Not implemented yet'
|
114
116
|
end
|
115
117
|
|
116
|
-
private
|
117
|
-
|
118
118
|
def top_scores
|
119
119
|
best = []
|
120
120
|
@remotes.iterate(@log) do |r|
|
data/lib/zold/http.rb
CHANGED
@@ -98,7 +98,7 @@ module Zold
|
|
98
98
|
'Connection': 'close'
|
99
99
|
}
|
100
100
|
headers[Http::VERSION_HEADER] = VERSION
|
101
|
-
headers[Http::SCORE_HEADER] = @score.reduced(4).
|
101
|
+
headers[Http::SCORE_HEADER] = @score.reduced(4).to_text if @score.valid? && !@score.expired?
|
102
102
|
headers
|
103
103
|
end
|
104
104
|
end
|
data/lib/zold/node/front.rb
CHANGED
@@ -45,6 +45,7 @@ module Zold
|
|
45
45
|
set :lock, false
|
46
46
|
set :show_exceptions, false
|
47
47
|
set :server, 'webrick'
|
48
|
+
set :ignore_score_weakness, false # to be injected at node.rb
|
48
49
|
set :reboot, false # to be injected at node.rb
|
49
50
|
set :home, nil? # to be injected at node.rb
|
50
51
|
set :logging, true # to be injected at node.rb
|
@@ -58,11 +59,18 @@ module Zold
|
|
58
59
|
end
|
59
60
|
|
60
61
|
before do
|
61
|
-
|
62
|
-
return unless
|
63
|
-
|
62
|
+
header = request.env["HTTP-#{Http::SCORE_HEADER}".upcase.tr('-', '_')]
|
63
|
+
return unless header
|
64
|
+
return if settings.remotes.all.empty?
|
65
|
+
s = Score.parse_text(header)
|
64
66
|
error(400, 'The score is invalid') unless s.valid?
|
65
|
-
|
67
|
+
error(400, 'The score is weak') if s.strength < Score::STRENGTH && !settings.ignore_score_weakness
|
68
|
+
if s.value > 3
|
69
|
+
require_relative '../commands/remote'
|
70
|
+
Remote.new(remotes: settings.remotes, log: settings.log).run(
|
71
|
+
['remote', 'add', s.host, s.port.to_s, '--force']
|
72
|
+
)
|
73
|
+
end
|
66
74
|
end
|
67
75
|
|
68
76
|
after do
|
@@ -70,6 +78,7 @@ module Zold
|
|
70
78
|
headers['Connection'] = 'close'
|
71
79
|
headers['X-Zold-Version'] = VERSION
|
72
80
|
headers['Access-Control-Allow-Origin'] = '*'
|
81
|
+
headers[Http::SCORE_HEADER] = score.reduced(16).to_s
|
73
82
|
end
|
74
83
|
|
75
84
|
get '/robots.txt' do
|
data/lib/zold/score.rb
CHANGED
@@ -64,10 +64,10 @@ module Zold
|
|
64
64
|
)
|
65
65
|
end
|
66
66
|
|
67
|
-
def self.parse(text
|
67
|
+
def self.parse(text)
|
68
68
|
m = Regexp.new(
|
69
69
|
'^' + [
|
70
|
-
'([0-9]
|
70
|
+
'([0-9]+)/(?<strength>[0-9]+):',
|
71
71
|
'(?<time>[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z)',
|
72
72
|
'(?<host>[0-9a-z\.\-]+)',
|
73
73
|
'(?<port>[0-9]+)',
|
@@ -80,19 +80,19 @@ module Zold
|
|
80
80
|
Time.parse(m[:time]), m[:host],
|
81
81
|
m[:port].to_i, m[:invoice],
|
82
82
|
m[:suffixes].split(' '),
|
83
|
-
strength: strength
|
83
|
+
strength: m[:strength].to_i
|
84
84
|
)
|
85
85
|
end
|
86
86
|
|
87
|
-
def self.parse_text(text
|
88
|
-
parts = text.split(' ',
|
87
|
+
def self.parse_text(text)
|
88
|
+
parts = text.split(' ', 7)
|
89
89
|
Score.new(
|
90
|
-
Time.at(parts[
|
91
|
-
parts[
|
92
|
-
parts[
|
93
|
-
"#{parts[
|
94
|
-
parts[
|
95
|
-
strength:
|
90
|
+
Time.at(parts[1].hex),
|
91
|
+
parts[2],
|
92
|
+
parts[3].hex,
|
93
|
+
"#{parts[4]}@#{parts[5]}",
|
94
|
+
parts[6] ? parts[6].split(' ') : [],
|
95
|
+
strength: parts[0].to_i
|
96
96
|
)
|
97
97
|
end
|
98
98
|
|
@@ -106,6 +106,7 @@ module Zold
|
|
106
106
|
def to_text
|
107
107
|
pfx, bnf = @invoice.split('@')
|
108
108
|
[
|
109
|
+
@strength,
|
109
110
|
@time.to_i.to_s(16),
|
110
111
|
@host,
|
111
112
|
@port.to_s(16),
|
@@ -117,7 +118,7 @@ module Zold
|
|
117
118
|
|
118
119
|
def to_s
|
119
120
|
[
|
120
|
-
"#{value}:",
|
121
|
+
"#{value}/#{@strength}:",
|
121
122
|
@time.utc.iso8601,
|
122
123
|
@host,
|
123
124
|
@port,
|
@@ -140,10 +141,9 @@ module Zold
|
|
140
141
|
end
|
141
142
|
|
142
143
|
def reduced(max = 4)
|
143
|
-
raise "The length of the score is #{@suffixes.count}, can't reduce to #{max}" if max > @suffixes.count
|
144
144
|
Score.new(
|
145
145
|
@time, @host, @port, @invoice,
|
146
|
-
@suffixes[0..max - 1], strength: @strength
|
146
|
+
@suffixes[0..[max, @suffixes.count].min - 1], strength: @strength
|
147
147
|
)
|
148
148
|
end
|
149
149
|
|
data/lib/zold/version.rb
CHANGED
data/test/node/fake_node.rb
CHANGED
@@ -33,7 +33,7 @@ class FakeNode
|
|
33
33
|
@log = log
|
34
34
|
end
|
35
35
|
|
36
|
-
def run
|
36
|
+
def run(args = ['--standalone'])
|
37
37
|
WebMock.allow_net_connect!
|
38
38
|
Dir.mktmpdir 'test' do |dir|
|
39
39
|
server = TCPServer.new('127.0.0.1', 0)
|
@@ -46,14 +46,13 @@ class FakeNode
|
|
46
46
|
require_relative '../../lib/zold/commands/node'
|
47
47
|
Zold::Node.new(log: @log).run(
|
48
48
|
[
|
49
|
-
'--standalone',
|
50
|
-
'--invoice', 'NOPREFIX@ffffffffffffffff',
|
51
49
|
'--port', port.to_s,
|
52
50
|
'--host=locahost',
|
53
51
|
'--bind-port', port.to_s,
|
54
52
|
'--threads=1',
|
55
|
-
'--home', home
|
56
|
-
|
53
|
+
'--home', home,
|
54
|
+
'--invoice=NOPREFIX@ffffffffffffffff'
|
55
|
+
] + args
|
57
56
|
)
|
58
57
|
end
|
59
58
|
end
|
data/test/node/test_front.rb
CHANGED
@@ -19,18 +19,15 @@
|
|
19
19
|
# SOFTWARE.
|
20
20
|
|
21
21
|
require 'minitest/autorun'
|
22
|
-
require '
|
23
|
-
require_relative '
|
24
|
-
require_relative '../../lib/zold/id'
|
25
|
-
require_relative '../../lib/zold/log'
|
26
|
-
require_relative '../../lib/zold/amount'
|
27
|
-
require_relative '../../lib/zold/wallet'
|
28
|
-
require_relative '../../lib/zold/http'
|
22
|
+
require 'json'
|
23
|
+
require_relative '../test__helper'
|
29
24
|
require_relative 'fake_node'
|
25
|
+
require_relative '../../lib/zold/http'
|
26
|
+
require_relative '../../lib/zold/score'
|
30
27
|
|
31
28
|
class FrontTest < Minitest::Test
|
32
29
|
def test_renders_public_pages
|
33
|
-
FakeNode.new.run do |port|
|
30
|
+
FakeNode.new(log: $log).run(['--ignore-score-weakness']) do |port|
|
34
31
|
{
|
35
32
|
'200' => [
|
36
33
|
'/robots.txt',
|
@@ -52,6 +49,14 @@ class FrontTest < Minitest::Test
|
|
52
49
|
)
|
53
50
|
end
|
54
51
|
end
|
52
|
+
score = Zold::Score.new(
|
53
|
+
Time.now, 'localhost', 999,
|
54
|
+
'NOPREFIX@ffffffffffffffff',
|
55
|
+
strength: 1
|
56
|
+
).next.next.next.next
|
57
|
+
Zold::Http.new(URI("http://localhost:#{port}/"), score).get
|
58
|
+
json = JSON.parse(Zold::Http.new(URI("http://localhost:#{port}/remotes"), score).get.body)
|
59
|
+
assert(json['all'].find { |r| r['host'] == 'localhost' })
|
55
60
|
end
|
56
61
|
end
|
57
62
|
end
|
data/test/test__helper.rb
CHANGED
data/test/test_score.rb
CHANGED
@@ -52,10 +52,10 @@ class TestScore < Minitest::Test
|
|
52
52
|
score = Zold::Score.parse(
|
53
53
|
Zold::Score.new(
|
54
54
|
time, 'localhost', 999, 'NOPREFIX@ffffffffffffffff',
|
55
|
-
|
56
|
-
).to_s
|
55
|
+
strength: 1
|
56
|
+
).next.next.to_s
|
57
57
|
)
|
58
|
-
assert_equal(
|
58
|
+
assert_equal(2, score.value)
|
59
59
|
assert_equal(score.time.to_s, time.to_s)
|
60
60
|
assert_equal('localhost', score.host)
|
61
61
|
assert_equal(999, score.port)
|
@@ -66,11 +66,11 @@ class TestScore < Minitest::Test
|
|
66
66
|
score = Zold::Score.parse_text(
|
67
67
|
Zold::Score.new(
|
68
68
|
time, 'a.example.com', 999, 'NOPREFIX@ffffffffffffffff',
|
69
|
-
|
70
|
-
).to_text
|
69
|
+
strength: 1
|
70
|
+
).next.next.next.to_text
|
71
71
|
)
|
72
72
|
assert_equal(3, score.value)
|
73
|
-
assert_equal(score.time.to_s, time.to_s)
|
73
|
+
assert_equal(score.time.utc.to_s, time.utc.to_s)
|
74
74
|
assert_equal('a.example.com', score.host)
|
75
75
|
assert_equal(999, score.port)
|
76
76
|
end
|
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.
|
4
|
+
version: 0.10.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
@@ -268,6 +268,7 @@ files:
|
|
268
268
|
- ".simplecov"
|
269
269
|
- ".travis.yml"
|
270
270
|
- Gemfile
|
271
|
+
- INSTALL.md
|
271
272
|
- LICENSE.txt
|
272
273
|
- Procfile
|
273
274
|
- README.md
|