zold 0.1 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e97c8ea80595de8fb52f2e1171802cde078b02f
4
- data.tar.gz: 599819edb711070c723db98fdc8de0c2a506fce1
3
+ metadata.gz: 45f2fb7dcf69ce479ef15281f2e2ac5e60347eac
4
+ data.tar.gz: f177e99ee0e5925fb55a8c151301bc6d0fdfffce
5
5
  SHA512:
6
- metadata.gz: 22998fc542734a47363547652c21b2f2ca9226e74a0839008c039629c539e02dda14d7f5b5fc2bb6d17873b6df290cfb80ba24bba106a25866a1457a6b95d2cf
7
- data.tar.gz: ec7c957625795210afa0e1d458c1104c6015a0dac3d0b0b7fed6df7aea5b05414af7718362939c696e535a1420c7f281b91cd7d9407b8ed94d749c94c18e9d65
6
+ metadata.gz: 9444742027fab53cdbad0dbe72db8f0640c3e58a6b0c713e0f7e17dea39dc867cd9c44cdb0dfc4a695126a3ca3cd0dfa82cdf0629a560fc3f29c1dd1aec1fc48
7
+ data.tar.gz: 86ac46ae6fea92ea34f57a4d74ef06cbcffd7a807954ff4b74d16f541b76ac916b4222a760b1f588c63625d8aaeb5066a1b02ff3b1fb4626f8e0764579f187c3
data/README.md CHANGED
@@ -37,6 +37,7 @@ Thus, the technical capacity of the currency is 549,755,813,888 ZLD (half a tril
37
37
  Install Ruby 2.2+, [Rubygems](https://rubygems.org/pages/download), and then run:
38
38
 
39
39
  ```bash
40
+ $ sudo apt-get install ruby-dev rubygems zlib1g-dev
40
41
  $ gem install zold
41
42
  ```
42
43
 
@@ -63,6 +64,11 @@ For more options and commands just run:
63
64
  $ zold --help
64
65
  ```
65
66
 
67
+ You will need PGP keys in `~/.ssh`. To generate them, if you don't have them
68
+ yet, you can run:
69
+
70
+
71
+
66
72
  ## Glossary
67
73
 
68
74
  **Node** is an HTTP server with a RESTful API, a maintainer of wallets
@@ -64,7 +64,7 @@ module Zold
64
64
  @copies.add(json['body'], r[:host], r[:port], score.value)
65
65
  @log.info(
66
66
  "#{r[:host]}:#{r[:port]} #{json['body'].length}b/\
67
- #{Rainbow(score.value).green}"
67
+ #{Rainbow(score.value).green} (v.#{json['version']})"
68
68
  )
69
69
  end
70
70
  @log.debug("#{total} copies fetched, \
@@ -75,7 +75,21 @@ module Zold
75
75
  @log.debug("There are #{total} known remotes")
76
76
  end
77
77
  else
78
- raise "Command '#{command}' is not supported"
78
+ @log.info(
79
+ "Available commands:
80
+ #{Rainbow('remote show').green}
81
+ Show all registered remote nodes
82
+ #{Rainbow('remote clean').green}
83
+ Remove all registered remote nodes
84
+ #{Rainbow('remote reset').green}
85
+ Restore it back to the default list of nodes
86
+ #{Rainbow('remote add').green} host port
87
+ Add a new remote node
88
+ #{Rainbow('remote remove').green} host port
89
+ Remove the remote node
90
+ #{Rainbow('remote update').green}
91
+ Check each registered remote node for availability"
92
+ )
79
93
  end
80
94
  end
81
95
 
@@ -107,8 +121,13 @@ module Zold
107
121
  next
108
122
  end
109
123
  @remotes.rescore(r[:host], r[:port], score.value)
110
- json['all'].each { |s| run(['add', s['host'], s['port']]) }
111
- @log.info("#{r[:host]}:#{r[:port]}: #{Rainbow(score.value).green}")
124
+ json['all'].each do |s|
125
+ unless @remotes.exists?(s['host'], s['port'])
126
+ run(['add', s['host'], s['port']])
127
+ end
128
+ end
129
+ @log.info("#{r[:host]}:#{r[:port]}: #{Rainbow(score.value).green} \
130
+ (v.#{json['version']})")
112
131
  end
113
132
  end
114
133
  end
data/lib/zold/http.rb CHANGED
@@ -63,7 +63,9 @@ module Zold
63
63
  headers = {
64
64
  'User-Agent': 'Zold'
65
65
  }
66
- headers[SCORE_HEADER] = score.to_s if @score.valid? && @score.value >= 3
66
+ if @score.valid? && @score.value >= 3
67
+ headers[SCORE_HEADER] = score.reduced(4).to_s
68
+ end
67
69
  headers
68
70
  end
69
71
  end
@@ -45,6 +45,7 @@ module Zold
45
45
  # Web front
46
46
  class Front < Sinatra::Base
47
47
  configure do
48
+ set :bind, '0.0.0.0'
48
49
  set :logging, true
49
50
  set :start, Time.now
50
51
  set :lock, Mutex.new
@@ -63,6 +64,11 @@ module Zold
63
64
  end
64
65
  end
65
66
 
67
+ after do
68
+ headers['Cache-Control'] = 'no-cache'
69
+ headers['X-Zold-Version'] = VERSION
70
+ end
71
+
66
72
  get '/robots.txt' do
67
73
  'User-agent: *'
68
74
  end
@@ -84,6 +90,9 @@ module Zold
84
90
  processors: Facter.value(:processors)['count'],
85
91
  memory: Facter::Memory.mem_size
86
92
  },
93
+ wallets: {
94
+ total: wallets.all.count
95
+ },
87
96
  date: `date --iso-8601=seconds -u`.strip,
88
97
  age: Time.now - settings.start,
89
98
  home: 'https://www.zold.io'
@@ -114,6 +123,7 @@ module Zold
114
123
  get '/remotes' do
115
124
  content_type 'application/json'
116
125
  JSON.pretty_generate(
126
+ version: VERSION,
117
127
  score: score.to_h,
118
128
  all: remotes.all.map do |r|
119
129
  {
data/lib/zold/remotes.rb CHANGED
@@ -53,6 +53,10 @@ module Zold
53
53
  )
54
54
  end
55
55
 
56
+ def exists?(host, port = 80)
57
+ !load.find { |r| r[:host] == host && r[:port] == port }.nil?
58
+ end
59
+
56
60
  def add(host, port = 80)
57
61
  list = load
58
62
  list << { host: host, port: port, score: 0 }
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.1'.freeze
26
+ VERSION = '0.1.1'.freeze
27
27
  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.1'
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko