zold 0.4.4 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/fixtures/scripts/push-and-pull.sh +2 -1
- data/lib/zold/commands/node.rb +17 -4
- data/lib/zold/commands/push.rb +1 -0
- data/lib/zold/node/entrance.rb +70 -0
- data/lib/zold/node/front.rb +15 -40
- data/lib/zold/version.rb +1 -1
- data/lib/zold/wallets.rb +3 -2
- data/zold.gemspec +1 -0
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28d39fb05a13cc3dc2a6856289b717c137e751dc
|
4
|
+
data.tar.gz: 42b2b142eb06e8f360b4d2f311bcf8c86aec7395
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63424ca129a20ac442879e53255572e885c952c32d10bc5b5cddaaca33a04d3698cc0c8114f8b79479988295df8c5bbe6f4bbd65a7c7752d1cbc031768272e68
|
7
|
+
data.tar.gz: f91e1c18246b1dd7f6fe790ac71a43e4cbdf0c2eae9a718229e7cc4004aea419352986f3b1036ff750200ed40be1aed1a21e9c82aba40de67529d091bbf2dbdd
|
data/lib/zold/commands/node.rb
CHANGED
@@ -20,7 +20,11 @@
|
|
20
20
|
|
21
21
|
require 'slop'
|
22
22
|
require_relative '../score'
|
23
|
+
require_relative '../wallets'
|
24
|
+
require_relative '../remotes'
|
25
|
+
require_relative '../node/entrance'
|
23
26
|
require_relative '../node/front'
|
27
|
+
require_relative '../node/farm'
|
24
28
|
|
25
29
|
# NODE command.
|
26
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -61,9 +65,10 @@ module Zold
|
|
61
65
|
@log.info(opts.to_s)
|
62
66
|
return
|
63
67
|
end
|
64
|
-
Zold::Front.set(:suppress_messages, true)
|
65
68
|
Zold::Front.set(:log, @log)
|
66
69
|
Zold::Front.set(:logging, @log.debug?)
|
70
|
+
FileUtils.mkdir_p(opts[:home])
|
71
|
+
Zold::Front.set(:home, opts[:home])
|
67
72
|
Zold::Front.set(
|
68
73
|
:server_settings,
|
69
74
|
Logger: WebrickLog.new(@log),
|
@@ -79,10 +84,18 @@ module Zold
|
|
79
84
|
)
|
80
85
|
)
|
81
86
|
end
|
87
|
+
wallets = Wallets.new(File.join(opts[:home], 'zold-wallets'))
|
88
|
+
Zold::Front.set(:wallets, wallets)
|
89
|
+
remotes = Remotes.new(File.join(opts[:home], 'zold-remotes'))
|
90
|
+
Zold::Front.set(:remotes, remotes)
|
91
|
+
copies = File.join(opts[:home], 'zold-copies')
|
92
|
+
Zold::Front.set(:copies, copies)
|
93
|
+
address = "#{opts[:host]}:#{opts[:port]}".downcase
|
94
|
+
Zold::Front.set(:address, address)
|
95
|
+
Zold::Front.set(
|
96
|
+
:entrance, Entrance.new(wallets, remotes, copies, address, log: @log)
|
97
|
+
)
|
82
98
|
Zold::Front.set(:port, opts['bind-port'])
|
83
|
-
FileUtils.mkdir_p(opts[:home])
|
84
|
-
Zold::Front.set(:home, opts[:home])
|
85
|
-
Zold::Front.set(:me, "#{opts[:host]}:#{opts[:port]}".downcase)
|
86
99
|
farm = Farm.new(log: @log)
|
87
100
|
farm.start(
|
88
101
|
opts[:host], opts[:port],
|
data/lib/zold/commands/push.rb
CHANGED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Copyright (c) 2018 Yegor Bugayenko
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
# SOFTWARE.
|
20
|
+
|
21
|
+
require 'concurrent'
|
22
|
+
require_relative '../log'
|
23
|
+
require_relative '../remotes'
|
24
|
+
require_relative '../copies'
|
25
|
+
require_relative '../commands/merge'
|
26
|
+
require_relative '../commands/fetch'
|
27
|
+
require_relative '../commands/push'
|
28
|
+
|
29
|
+
# The entrance of the web front.
|
30
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
31
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
32
|
+
# License:: MIT
|
33
|
+
module Zold
|
34
|
+
# The entrance
|
35
|
+
class Entrance
|
36
|
+
def initialize(wallets, remotes, copies, address, log: Log::Quiet.new)
|
37
|
+
@wallets = wallets
|
38
|
+
@remotes = remotes
|
39
|
+
@copies = copies
|
40
|
+
@address = address
|
41
|
+
@log = log
|
42
|
+
@semaphores = Concurrent::Map.new
|
43
|
+
end
|
44
|
+
|
45
|
+
def push(id, body)
|
46
|
+
@semaphores.put_if_absent(id, Mutex.new)
|
47
|
+
@semaphores.get(id).synchronize do
|
48
|
+
push_unsafe(id, body)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def push_unsafe(id, body)
|
53
|
+
copies = Copies.new(File.join(@copies, id.to_s))
|
54
|
+
copies.add(body, 'remote', Remotes::PORT, 0)
|
55
|
+
Zold::Fetch.new(
|
56
|
+
remotes: @remotes, copies: copies.root, log: @log
|
57
|
+
).run([id.to_s, "--ignore-node=#{@address}"])
|
58
|
+
modified = Zold::Merge.new(
|
59
|
+
wallets: @wallets, copies: copies.root, log: @log
|
60
|
+
).run([id.to_s])
|
61
|
+
copies.remove('remote', Remotes::PORT)
|
62
|
+
modified.each do |m|
|
63
|
+
Zold::Push.new(
|
64
|
+
wallets: @wallets, remotes: @remotes, log: @log
|
65
|
+
).run([m.to_s])
|
66
|
+
end
|
67
|
+
modified
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/zold/node/front.rb
CHANGED
@@ -20,17 +20,13 @@
|
|
20
20
|
|
21
21
|
STDOUT.sync = true
|
22
22
|
|
23
|
-
require 'slop'
|
24
23
|
require 'json'
|
25
24
|
require 'sinatra/base'
|
26
25
|
require 'webrick'
|
27
26
|
|
28
|
-
require_relative 'farm'
|
29
27
|
require_relative '../version'
|
30
28
|
require_relative '../wallet'
|
31
|
-
require_relative '../wallets'
|
32
29
|
require_relative '../log'
|
33
|
-
require_relative '../remotes'
|
34
30
|
require_relative '../id'
|
35
31
|
require_relative '../http'
|
36
32
|
|
@@ -43,16 +39,21 @@ module Zold
|
|
43
39
|
class Front < Sinatra::Base
|
44
40
|
configure do
|
45
41
|
set :bind, '0.0.0.0'
|
46
|
-
set :
|
42
|
+
set :suppress_messages, true
|
47
43
|
set :dump_errors, true
|
48
44
|
set :start, Time.now
|
49
45
|
set :lock, false
|
50
|
-
set :log, Log.new
|
51
46
|
set :show_exceptions, false
|
52
|
-
set :home, Dir.pwd
|
53
|
-
set :me, 'localhost:4096'
|
54
|
-
set :farm, Farm.new
|
55
47
|
set :server, 'webrick'
|
48
|
+
set :home, nil? # to be injected at node.rb
|
49
|
+
set :logging, true # to be injected at node.rb
|
50
|
+
set :log, nil? # to be injected at node.rb
|
51
|
+
set :address, nil? # to be injected at node.rb
|
52
|
+
set :farm, nil? # to be injected at node.rb
|
53
|
+
set :entrance, nil? # to be injected at node.rb
|
54
|
+
set :wallets, nil? # to be injected at node.rb
|
55
|
+
set :remotes, nil? # to be injected at node.rb
|
56
|
+
set :copies, nil? # to be injected at node.rb
|
56
57
|
end
|
57
58
|
|
58
59
|
before do
|
@@ -66,6 +67,7 @@ module Zold
|
|
66
67
|
|
67
68
|
after do
|
68
69
|
headers['Cache-Control'] = 'no-cache'
|
70
|
+
headers['Connection'] = 'close'
|
69
71
|
headers['X-Zold-Version'] = VERSION
|
70
72
|
end
|
71
73
|
|
@@ -83,7 +85,7 @@ module Zold
|
|
83
85
|
version: VERSION,
|
84
86
|
score: score.to_h,
|
85
87
|
uptime: `uptime`.strip,
|
86
|
-
wallets: wallets.all.count,
|
88
|
+
wallets: settings.wallets.all.count,
|
87
89
|
farm: settings.farm.to_json,
|
88
90
|
date: `date --iso-8601=seconds -u`.strip,
|
89
91
|
hours_alive: ((Time.now - settings.start) / (60 * 60)).round(2),
|
@@ -93,7 +95,7 @@ module Zold
|
|
93
95
|
|
94
96
|
get %r{/wallet/(?<id>[A-Fa-f0-9]{16})} do
|
95
97
|
id = Id.new(params[:id])
|
96
|
-
wallet = wallets.find(id)
|
98
|
+
wallet = settings.wallets.find(id)
|
97
99
|
error 404 unless wallet.exists?
|
98
100
|
content_type 'application/json'
|
99
101
|
{
|
@@ -105,33 +107,14 @@ module Zold
|
|
105
107
|
|
106
108
|
put %r{/wallet/(?<id>[A-Fa-f0-9]{16})/?} do
|
107
109
|
id = Id.new(params[:id])
|
108
|
-
wallet = wallets.find(id)
|
110
|
+
wallet = settings.wallets.find(id)
|
109
111
|
request.body.rewind
|
110
112
|
body = request.body.read
|
111
113
|
if wallet.exists? && File.read(wallet.path) == body
|
112
114
|
status 304
|
113
115
|
return
|
114
116
|
end
|
115
|
-
|
116
|
-
cps.add(body, 'remote', Remotes::PORT, 0)
|
117
|
-
require_relative '../commands/fetch'
|
118
|
-
Zold::Fetch.new(
|
119
|
-
remotes: settings.remotes, copies: cps.root,
|
120
|
-
log: settings.log
|
121
|
-
).run([id.to_s, "--ignore-node=#{settings.me}"])
|
122
|
-
require_relative '../commands/merge'
|
123
|
-
modified = Zold::Merge.new(
|
124
|
-
wallets: wallets, copies: cps.root,
|
125
|
-
log: settings.log
|
126
|
-
).run([id.to_s])
|
127
|
-
cps.remove('remote', Remotes::PORT)
|
128
|
-
require_relative '../commands/push'
|
129
|
-
modified.each do |m|
|
130
|
-
Zold::Push.new(
|
131
|
-
wallets: wallets, remotes: settings.remotes,
|
132
|
-
log: settings.log
|
133
|
-
).run([m.to_s])
|
134
|
-
end
|
117
|
+
modified = settings.entrance.push(id, body)
|
135
118
|
JSON.pretty_generate(
|
136
119
|
version: VERSION,
|
137
120
|
score: score.to_h,
|
@@ -175,14 +158,6 @@ module Zold
|
|
175
158
|
|
176
159
|
private
|
177
160
|
|
178
|
-
def copies(id)
|
179
|
-
Copies.new(File.join(settings.home, ".zoldata/copies/#{id}"))
|
180
|
-
end
|
181
|
-
|
182
|
-
def wallets
|
183
|
-
Wallets.new(settings.home)
|
184
|
-
end
|
185
|
-
|
186
161
|
def score
|
187
162
|
best = settings.farm.best
|
188
163
|
error 404 if best.empty?
|
data/lib/zold/version.rb
CHANGED
data/lib/zold/wallets.rb
CHANGED
@@ -33,11 +33,12 @@ module Zold
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def path
|
36
|
+
FileUtils.mkdir_p(@dir)
|
36
37
|
File.expand_path(@dir)
|
37
38
|
end
|
38
39
|
|
39
40
|
def all
|
40
|
-
Dir.new(
|
41
|
+
Dir.new(path).select do |f|
|
41
42
|
file = File.join(@dir, f)
|
42
43
|
File.file?(file) &&
|
43
44
|
!File.directory?(file) &&
|
@@ -47,7 +48,7 @@ module Zold
|
|
47
48
|
end
|
48
49
|
|
49
50
|
def find(id)
|
50
|
-
Zold::Wallet.new(File.join(
|
51
|
+
Zold::Wallet.new(File.join(path, id.to_s))
|
51
52
|
end
|
52
53
|
end
|
53
54
|
end
|
data/zold.gemspec
CHANGED
@@ -44,6 +44,7 @@ Gem::Specification.new do |s|
|
|
44
44
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
45
45
|
s.rdoc_options = ['--charset=UTF-8']
|
46
46
|
s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
|
47
|
+
s.add_runtime_dependency 'concurrent-ruby', '1.0.5'
|
47
48
|
s.add_runtime_dependency 'cucumber', '1.3.17'
|
48
49
|
s.add_runtime_dependency 'diffy', '3.2.0'
|
49
50
|
s.add_runtime_dependency 'openssl', '2.0.1'
|
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.
|
4
|
+
version: '0.5'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
@@ -10,6 +10,20 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2018-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: concurrent-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.5
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: cucumber
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -279,6 +293,7 @@ files:
|
|
279
293
|
- lib/zold/id.rb
|
280
294
|
- lib/zold/key.rb
|
281
295
|
- lib/zold/log.rb
|
296
|
+
- lib/zold/node/entrance.rb
|
282
297
|
- lib/zold/node/farm.rb
|
283
298
|
- lib/zold/node/front.rb
|
284
299
|
- lib/zold/patch.rb
|