Class: CgminerApiClient::Miner

Inherits:
Object
  • Object
show all
Includes:
Commands, SocketWithTimeout
Defined in:
lib/cgminer_api_client/miner.rb,
lib/cgminer_api_client/miner/commands.rb

Defined Under Namespace

Modules: Commands

Constant Summary collapse

REDACTED_PARAM_INDEX =

Positional parameters at these indices carry user-controlled values (pool passwords, setconfig values, ascset/pgaset option values) that should not appear verbatim in wire-logs. The wire request is never modified; only the copy passed to the on_wire callback is redacted. If a new privileged command is added that accepts a secret positional arg, register its index here.

{
  addpool: 2,
  setconfig: 1,
  ascset: 2,
  pgaset: 2
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Commands::Privileged::System

#debug, #failover_only, #hotplug, #quit, #restart, #save, #setconfig, #zero

Methods included from Commands::Privileged::Pool

#addpool, #disablepool, #enablepool, #poolpriority, #poolquota, #removepool, #switchpool

Methods included from Commands::Privileged::Pga

#pgadisable, #pgaenable, #pgaidentify, #pgaset

Methods included from Commands::Privileged::Asc

#ascdisable, #ascenable, #ascidentify, #ascset

Methods included from Commands::ReadOnly

#asc, #asccount, #check, #coin, #config, #devdetails, #devs, #notify, #pga, #pgacount, #pools, #privileged, #stats, #summary, #usbstats, #version

Methods included from SocketWithTimeout

#open_socket

Constructor Details

#initialize(host = nil, port = nil, timeout = nil, on_wire: nil) ⇒ Miner

Returns a new instance of Miner.



26
27
28
29
30
31
# File 'lib/cgminer_api_client/miner.rb', line 26

def initialize(host = nil, port = nil, timeout = nil, on_wire: nil)
  @host    = host    || CgminerApiClient.default_host
  @port    = port    || CgminerApiClient.default_port
  @timeout = timeout || CgminerApiClient.default_timeout
  @on_wire = on_wire
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



52
53
54
# File 'lib/cgminer_api_client/miner.rb', line 52

def method_missing(name, *)
  query(name, *)
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



11
12
13
# File 'lib/cgminer_api_client/miner.rb', line 11

def host
  @host
end

#portObject

Returns the value of attribute port.



11
12
13
# File 'lib/cgminer_api_client/miner.rb', line 11

def port
  @port
end

#timeoutObject

Returns the value of attribute timeout.



11
12
13
# File 'lib/cgminer_api_client/miner.rb', line 11

def timeout
  @timeout
end

Instance Method Details

#available?Boolean

Reachability probe. Opens a fresh socket every call — no caching. Returns true on a successful connect, false on transport-level failure (DNS, refused, unreachable, timeout). Bugs like ArgumentError or NoMethodError propagate instead of being silently swallowed.

Returns:

  • (Boolean)


45
46
47
48
49
50
# File 'lib/cgminer_api_client/miner.rb', line 45

def available?
  open_socket(@host, @port, @timeout).close
  true
rescue SocketError, SystemCallError, CgminerApiClient::TimeoutError
  false
end

#query(method, *params) ⇒ Object



33
34
35
36
37
38
# File 'lib/cgminer_api_client/miner.rb', line 33

def query(method, *params)
  request, loggable_request = build_requests(method, params)
  response = perform_request(request, loggable_request: loggable_request)
  data = sanitized(response)
  method.to_s.match?('\+') ? data : data[method.to_sym]
end

#respond_to_missing?(name, _include_private = false) ⇒ Boolean

method_missing forwards everything to query as a cgminer command, so respond to anything except names that look like Ruby internals or implicit conversion probes (to_ary, to_str, to_int, to_hash, …).

Returns:

  • (Boolean)


59
60
61
# File 'lib/cgminer_api_client/miner.rb', line 59

def respond_to_missing?(name, _include_private = false)
  !name.to_s.start_with?('to_', '_')
end