lib/zold/node/front.rb in zold-0.9.9 vs lib/zold/node/front.rb in zold-0.9.10
- old
+ new
@@ -21,11 +21,11 @@
STDOUT.sync = true
require 'json'
require 'sinatra/base'
require 'webrick'
-
+require 'semantic'
require_relative '../version'
require_relative '../wallet'
require_relative '../log'
require_relative '../id'
require_relative '../http'
@@ -43,10 +43,11 @@
set :dump_errors, true
set :start, Time.now
set :lock, false
set :show_exceptions, false
set :server, 'webrick'
+ set :reboot, false # to be injected at node.rb
set :home, nil? # to be injected at node.rb
set :logging, true # to be injected at node.rb
set :log, nil? # to be injected at node.rb
set :address, nil? # to be injected at node.rb
set :farm, nil? # to be injected at node.rb
@@ -55,15 +56,20 @@
set :remotes, nil? # to be injected at node.rb
set :copies, nil? # to be injected at node.rb
end
before do
- if request.env[Http::SCORE_HEADER] && !settings.remotes.empty?
- s = Score.parse(request.env[Http::SCORE_HEADER])
- error(400, 'The score is invalid') unless s.valid?
- settings.remotes.add(s.host, s.port) if s.value > 3
+ if request.env[Http::VERSION_HEADER] &&
+ Semantic::Version.new(VERSION) < Semantic::Version.new(request.env[Http::VERSION_HEADER]) &&
+ !settings.remotes.empty? && settings.reboot
+ exit(0)
end
+ return unless request.env[Http::SCORE_HEADER]
+ return unless settings.remotes.empty?
+ s = Score.parse(request.env[Http::SCORE_HEADER])
+ error(400, 'The score is invalid') unless s.valid?
+ settings.remotes.add(s.host, s.port) if s.value > 3
end
after do
headers['Cache-Control'] = 'no-cache'
headers['Connection'] = 'close'
@@ -83,9 +89,10 @@
JSON.pretty_generate(
version: VERSION,
score: score.to_h,
uptime: `uptime`.strip,
wallets: settings.wallets.all.count,
+ remotes: settings.remotes.all.count,
farm: settings.farm.to_json,
date: `date --iso-8601=seconds -u`.strip,
hours_alive: ((Time.now - settings.start) / (60 * 60)).round(2),
home: 'https://www.zold.io'
)