class Zold::RemoteNode

One remote.

Attributes

idx[R]
touched[R]

Public Class Methods

new(host:, port:, score:, idx:, master:, network: 'test', log: Log::NULL) click to toggle source
# File lib/zold/remotes.rb, line 51
def initialize(host:, port:, score:, idx:, master:, network: 'test', log: Log::NULL)
  @host = host
  @port = port
  @score = score
  @idx = idx
  @master = master
  @network = network
  @log = log
  @touched = false
end

Public Instance Methods

assert_code(code, response) click to toggle source
# File lib/zold/remotes.rb, line 79
    def assert_code(code, response)
      msg = response.status_line.strip
      return if response.status.to_i == code
      if response.headers && response.headers['X-Zold-Error']
        raise CantAssert, "Error ##{response.status} \"#{response.headers['X-Zold-Error']}\" \
at #{response.headers['X-Zold-Path']}"
      end
      raise CantAssert, "Unexpected HTTP code #{response.status}, instead of #{code}" if msg.empty?
      raise CantAssert, "#{msg} (HTTP code #{response.status}, instead of #{code})"
    end
assert_score_ownership(score) click to toggle source
# File lib/zold/remotes.rb, line 95
def assert_score_ownership(score)
  raise CantAssert, "Masqueraded host #{@host} as #{score.host}: #{score.reduced(4)}" if @host != score.host
  raise CantAssert, "Masqueraded port #{@port} as #{score.port}: #{score.reduced(4)}" if @port != score.port
end
assert_score_strength(score) click to toggle source
# File lib/zold/remotes.rb, line 100
def assert_score_strength(score)
  return if score.strength >= Score::STRENGTH
  raise CantAssert, "Score #{score.strength} is too weak (<#{Score::STRENGTH}): #{score.reduced(4)}"
end
assert_score_value(score, min) click to toggle source
# File lib/zold/remotes.rb, line 105
def assert_score_value(score, min)
  raise CantAssert, "Score #{score.value} is too small (<#{min}): #{score.reduced(4)}" if score.value < min
end
assert_valid_score(score) click to toggle source
# File lib/zold/remotes.rb, line 90
def assert_valid_score(score)
  raise CantAssert, "Invalid score #{score.reduced(4)}" unless score.valid?
  raise CantAssert, "Expired score (#{Age.new(score.time)}) #{score.reduced(4)}" if score.expired?
end
http(path = '/') click to toggle source
# File lib/zold/remotes.rb, line 62
def http(path = '/')
  @touched = true
  Http.new(uri: "http://#{@host}:#{@port}#{path}", score: @score, network: @network)
end
master?() click to toggle source
# File lib/zold/remotes.rb, line 67
def master?
  @master
end
to_mnemo() click to toggle source
# File lib/zold/remotes.rb, line 75
def to_mnemo
  "#{@host}:#{@port}"
end
to_s() click to toggle source
# File lib/zold/remotes.rb, line 71
def to_s
  "#{@host}:#{@port}/#{@idx}"
end