class Zold::Front
Web front
Constants
- MIN_SCORE
The minimum score required in order to recognize a requester as a valuable node and add it to the list of remotes.
Private Instance Methods
add_new_remote(score)
click to toggle source
# File lib/zold/node/front.rb, line 603 def add_new_remote(score) all = settings.remotes.all return if all.count > Remotes::MAX_NODES && all.none? { |r| r[:errors] > Remotes::TOLERANCE } begin require_relative '../commands/remote' Remote.new(remotes: settings.remotes, log: settings.log).run( [ 'remote', 'add', score.host, score.port.to_s, "--network=#{Shellwords.escape(settings.opts['network'])}", '--ignore-if-exists' ] + (settings.opts['ignore-score-weakness'] ? ['--skip-ping'] : []) ) rescue StandardError => e error(400, e.message) end end
all_remotes()
click to toggle source
# File lib/zold/node/front.rb, line 559 def all_remotes settings.zache.get(:remotes, lifetime: settings.opts['no-cache'] ? 0 : 60) do settings.remotes.all end end
ban(id)
click to toggle source
# File lib/zold/node/front.rb, line 587 def ban(id) return unless Id::BANNED.include?(id.to_s) error(404, "The wallet #{id} is banned") end
check_header(name) { |header| ... }
click to toggle source
# File lib/zold/node/front.rb, line 526 def check_header(name) name = "HTTP-#{name}".upcase.tr('-', '_') header = request.env[name] return unless header yield header end
checksum()
click to toggle source
# File lib/zold/node/front.rb, line 548 def checksum settings.zache.get(:checksum, lifetime: settings.opts['no-cache'] ? 0 : 60) do Digest::MD5.hexdigest( Dir[File.join(__dir__, '../**/*')] .reject { |f| File.directory?(f) } .map { |f| File.read(f) } .join ) end end
fetch(type = 'text/plain') { |wallet| ... }
click to toggle source
# File lib/zold/node/front.rb, line 592 def fetch(type = 'text/plain') error(404, 'FETCH is disabled with --disable-fetch') if settings.opts['disable-fetch'] id = Id.new(params[:id]) ban(id) settings.wallets.acq(id) do |wallet| error(404, "Wallet ##{id} doesn't exist on the node") unless wallet.exists? content_type(type) yield wallet end end
pretty(json)
click to toggle source
# File lib/zold/node/front.rb, line 575 def pretty(json) JSON.pretty_generate(json) end
processes()
click to toggle source
# File lib/zold/node/front.rb, line 571 def processes `ps ax`.split("\n").select { |t| t.include?('zold') } end
processes_count()
click to toggle source
# File lib/zold/node/front.rb, line 565 def processes_count settings.zache.get(:processes, lifetime: settings.opts['no-cache'] ? 0 : 60) do processes.count end end
score()
click to toggle source
# File lib/zold/node/front.rb, line 579 def score settings.zache.get(:score, lifetime: settings.opts['no-cache'] ? 0 : 60) do b = settings.farm.best raise 'Score is empty, there is something wrong with the Farm!' if b.empty? b[0] end end
total_mem()
click to toggle source
# File lib/zold/node/front.rb, line 533 def total_mem settings.zache.get(:total_mem, lifetime: settings.opts['no-cache'] ? 0 : 60) do Total::Mem.new.bytes rescue Total::CantDetect => e settings.log.error(e.message) 0 end end
total_wallets()
click to toggle source
# File lib/zold/node/front.rb, line 542 def total_wallets settings.zache.get(:wallets, lifetime: settings.opts['no-cache'] ? 0 : 60) do settings.wallets.count end end