zold 0.13.16 → 0.13.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3183919e57351739619bf518c2870c25ec473985
4
- data.tar.gz: 67635b036d23a07bf3f1d92d4c6b4513b3c9748f
3
+ metadata.gz: 7eec03fc76e3770883b2f0febeb6ff7d565cc0a0
4
+ data.tar.gz: 121dd3d167f8a894c6c7a6a222f67bcb67356621
5
5
  SHA512:
6
- metadata.gz: 75dfb39205b5b048471e8589462ca9dbf6607930077fdd649a80f2356bd5e7a10c35fd3064ed239bbb9f642b88eb039ac3d8c43e76b2bb36c43345169789943d
7
- data.tar.gz: 7ead05305c2aa61831803d031c1bd0da5dfa24894598a1a96d789cc2a6dc45b452aaba2e2daace99ba423767656546431386f9b7c37d768b72cf59571a29c44a
6
+ metadata.gz: 5a34855ba55d40556a011ab566962db6e072b6b97cf4eeef28491a9eb66d23db54fd64511e43ff69fec78324efcd75002dc6061ec5eb1c0773013eab2e26ea66
7
+ data.tar.gz: d04f55a00d7578f0ba7dca6b7ed1c9a351c5da22a0376e44fce9363ddb39c2484ec8f2194c0f4a65df82b605882af91d9a41d64d3681ca55d50840f12e22cec8
data/README.md CHANGED
@@ -11,7 +11,6 @@
11
11
  [![Gem Version](https://badge.fury.io/rb/zold.svg)](http://badge.fury.io/rb/zold)
12
12
  [![Test Coverage](https://img.shields.io/codecov/c/github/zold-io/zold.svg)](https://codecov.io/github/zold-io/zold?branch=master)
13
13
 
14
- [![Dependency Status](https://gemnasium.com/zold-io/zold.svg)](https://gemnasium.com/zold-io/zold)
15
14
  [![Maintainability](https://api.codeclimate.com/v1/badges/7489c1d2bacde40ffc09/maintainability)](https://codeclimate.com/github/zold-io/zold/maintainability)
16
15
 
17
16
  **NOTICE**: It's an experiment and a very early draft! Please, feel free to
@@ -59,8 +59,8 @@ module Zold
59
59
  o.integer '--bind-port',
60
60
  "TCP port to listen on (default: #{Remotes::PORT})",
61
61
  default: Remotes::PORT
62
- o.string '--host', "Host name (default: #{ip})",
63
- default: ip
62
+ o.string '--host',
63
+ 'Host name (will attempt to auto-detect it, if not specified)'
64
64
  o.integer '--strength',
65
65
  "The strength of the score (default: #{Score::STRENGTH})",
66
66
  default: Score::STRENGTH
@@ -125,6 +125,9 @@ module Zold
125
125
  @log.info("Home directory: #{Dir.pwd}")
126
126
  @log.info("Ruby version: #{RUBY_VERSION}")
127
127
  @log.info("Zold gem version: #{Zold::VERSION}")
128
+ host = opts[:host] || ip
129
+ address = "#{host}:#{opts[:port]}".downcase
130
+ @log.info("Node location: #{address}")
128
131
  Front.set(
129
132
  :server_settings,
130
133
  Logger: WebrickLog.new(@log),
@@ -138,7 +141,6 @@ module Zold
138
141
  Front.set(:wallets, @wallets)
139
142
  Front.set(:remotes, @remotes)
140
143
  Front.set(:copies, @copies)
141
- address = "#{opts[:host]}:#{opts[:port]}".downcase
142
144
  Front.set(:address, address)
143
145
  entrance = Entrance.new(@wallets, @remotes, @copies, address, log: @log)
144
146
  Front.set(:entrance, entrance)
@@ -160,7 +162,7 @@ module Zold
160
162
  Front.set(:farm, farm)
161
163
  metronome = metronome(farm, entrance, opts)
162
164
  begin
163
- @log.info("Starting up the web front at http://#{opts[:host]}:#{opts[:port]}...")
165
+ @log.info("Starting up the web front at http://#{host}:#{opts[:port]}...")
164
166
  Front.run!
165
167
  ensure
166
168
  farm.stop
@@ -242,7 +244,8 @@ module Zold
242
244
  addr = Socket.ip_address_list.detect do |i|
243
245
  i.ipv4? && !i.ipv4_loopback? && !i.ipv4_multicast? && !i.ipv4_private?
244
246
  end
245
- addr.nil? ? '127.0.0.1' : addr.ip_address
247
+ raise 'Can\'t detect your IP address, you have to specify it in --host' if addr.nil?
248
+ addr.ip_address
246
249
  end
247
250
 
248
251
  # Log facility for nohup
@@ -69,7 +69,7 @@ module Zold
69
69
  VerboseThread.new(@log).run do
70
70
  Thread.current.name = "farm-#{t}"
71
71
  loop do
72
- if @scores.length < 4
72
+ if @scores.length < threads
73
73
  @scores << Score.new(
74
74
  Time.now, host, port, @invoice,
75
75
  strength: strength
@@ -79,22 +79,22 @@ module Zold
79
79
  next unless s.valid?
80
80
  next unless s.host == host
81
81
  next unless s.port == port
82
- next if s.expired?(20)
83
- next if s.strength < strength
82
+ next unless s.strength >= strength
83
+ n = s.next
84
84
  @semaphore.synchronize do
85
- save(s)
86
85
  before = @best.map(&:value).max
87
- @best << s
86
+ save(n)
87
+ @best << n
88
88
  after = @best.map(&:value).max
89
- @best.reject! { |b| b.value < after }
90
- @log.debug("#{Thread.current.name}: best score is #{@best[0]}") if before != after
89
+ @best = @best.reject(&:expired?).sort_by(&:value).reverse.take(threads)
90
+ @log.debug("#{Thread.current.name}: best score is #{@best[0]}") if before != after && !after.zero?
91
91
  end
92
- @scores << s.next
92
+ @scores << n
93
93
  end
94
94
  end
95
95
  end
96
96
  end
97
- @log.info("Farm started with #{threads} threads at #{host}:#{port}")
97
+ @log.info("Farm started with #{threads} threads at #{host}:#{port}, strength is #{strength}")
98
98
  end
99
99
 
100
100
  def stop
@@ -119,7 +119,6 @@ module Zold
119
119
  AtomicFile.new(@cache).read
120
120
  .split(/\n/)
121
121
  .map { |t| Score.parse(t) }
122
- .reject(&:expired?)
123
122
  .select(&:valid?)
124
123
  .sort_by(&:value)
125
124
  .reverse
data/lib/zold/remotes.rb CHANGED
@@ -36,7 +36,7 @@ module Zold
36
36
  PORT = 4096
37
37
 
38
38
  # At what amount of errors we delete the remote automatically
39
- TOLERANCE = 50
39
+ TOLERANCE = 20
40
40
 
41
41
  # Empty, for standalone mode
42
42
  class Empty
data/lib/zold/version.rb CHANGED
@@ -23,5 +23,5 @@
23
23
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
24
24
  # License:: MIT
25
25
  module Zold
26
- VERSION = '0.13.16'.freeze
26
+ VERSION = '0.13.17'.freeze
27
27
  end
@@ -60,4 +60,24 @@ class FarmTest < Minitest::Test
60
60
  farm.stop
61
61
  end
62
62
  end
63
+
64
+ def test_drops_expired_scores_from_history
65
+ Dir.mktmpdir 'test' do |dir|
66
+ cache = File.join(dir, 'cache')
67
+ score = Zold::Score.new(
68
+ Time.parse('2017-07-19T21:24:51Z'),
69
+ 'some-host', 9999, 'NOPREFIX@ffffffffffffffff', ['13f7f01'],
70
+ strength: 6
71
+ )
72
+ File.write(cache, score.to_s)
73
+ farm = Zold::Farm.new('NOPREFIX@ffffffffffffffff', cache, log: test_log)
74
+ farm.start(score.host, score.port, threads: 1, strength: score.strength)
75
+ 10.times do
76
+ break if farm.best[0].value.zero?
77
+ sleep(1)
78
+ end
79
+ assert_equal(0, farm.best[0].value)
80
+ farm.stop
81
+ end
82
+ end
63
83
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.16
4
+ version: 0.13.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-13 00:00:00.000000000 Z
11
+ date: 2018-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby