lib/universa/client.rb in universa-0.2.1 vs lib/universa/client.rb in universa-0.2.2

- old
+ new

@@ -68,10 +68,13 @@ # @return [Array(Connection)] array of count randomly selected connections def random_connections count = 1 @nodes.sample(count) end + def [] name + @nodes.find {|x| x.url =~ /#{name}/} + end private # Rescan the network collecting the networ map comparing results from random 70% of nodes. def scan_network @@ -141,10 +144,17 @@ # ordered by approval rate def < other rate < other.rate end + + def name + @name ||= begin + url =~ /^https{0,1}:\/\/([^:]*)/ + $1 + end + end end # Access to the single node using universa client protocol. # @@ -209,10 +219,26 @@ # @return [SmartHash] with the command result def execute(name, **kwargs) connection.command name.to_s, *kwargs.to_a.flatten end + # def stats days=0 + # connection.getStats(days.to_i) + # end + + def url + @node_info.url + end + + def name + @node_info.name + end + + def number + @node_info.number + end + def to_s "Conn<#{@node_info.url}>" end def inspect @@ -221,14 +247,16 @@ protected def connection @connection ||= retry_with_timeout(15, 3) { - Service.umi.instantiate "com.icodici.universa.node2.network.Client", - @node_info.url, - @client.private_key, - nil, - false + conn = Service.umi.instantiate("com.icodici.universa.node2.network.Client", + @node_info.url, + @client.private_key, + nil, + false) + .getClient(@node_info.number - 1) + conn } end end