lib/zold/node/front.rb in zold-0.16.6 vs lib/zold/node/front.rb in zold-0.16.7

- old
+ new

@@ -98,13 +98,11 @@ if header != settings.protocol.to_s error(400, "Protocol mismatch, you are in '#{header}', we are in '#{settings.protocol}'") end end check_header(Http::SCORE_HEADER) do |header| - if settings.remotes.all.empty? - settings.log.debug("#{request.url}: we are in standalone mode, won't update remotes") - end + settings.log.debug("#{request.url}: we are in standalone mode, won't update remotes") if all_remotes.empty? s = Score.parse_text(header) error(400, 'The score is invalid') unless s.valid? error(400, 'The score is weak') if s.strength < Score::STRENGTH && !settings.ignore_score_weakness if settings.address == "#{s.host}:#{s.port}" && !settings.ignore_score_weakness error(400, 'Self-requests are prohibited') @@ -193,12 +191,12 @@ memory: GetProcessMem.new.bytes.to_i, platform: RUBY_PLATFORM, load: settings.cache.get(:load, lifetime: 5 * 60) { Usagewatch.uw_load.to_f }, threads: "#{Thread.list.select { |t| t.status == 'run' }.count}/#{Thread.list.count}", wallets: total_wallets, - remotes: settings.remotes.all.count, - nscore: settings.remotes.all.map { |r| r[:score] }.inject(&:+) || 0, + remotes: all_remotes.count, + nscore: all_remotes.map { |r| r[:score] }.inject(&:+) || 0, farm: settings.farm.to_json, entrance: settings.entrance.to_json, date: Time.now.utc.iso8601, hours_alive: ((Time.now - settings.start) / (60 * 60)).round(2), home: 'https://www.zold.io' @@ -366,11 +364,11 @@ content_type('application/json') JSON.pretty_generate( version: settings.version, alias: settings.node_alias, score: score.to_h, - all: settings.remotes.all, + all: all_remotes, mtime: settings.remotes.mtime.utc.iso8601 ) end get '/farm' do @@ -434,11 +432,17 @@ def total_wallets return 256 if settings.network == Wallet::MAIN_NETWORK settings.wallets.all.count end + def all_remotes + settings.cache.get(:remotes, lifetime: settings.network == Wallet::MAIN_NETWORK ? 60 : 0) do + settings.remotes.all + end + end + def score - settings.cache.get(:score, lifetime: settings.network == Wallet::MAIN_NETWORK ? 60 : 1) do + settings.cache.get(:score, lifetime: settings.network == Wallet::MAIN_NETWORK ? 60 : 0) do b = settings.farm.best raise 'Score is empty, there is something wrong with the Farm!' if b.empty? b[0] end end