@@ -34,8 +34,7 @@ using namespace bc::config;
3434
3535// TODO: change to network_address bimap hash table with services and age.
3636hosts::hosts (const settings& settings)
37- : capacity_(std::min(max_address, static_cast <size_t >(
38- settings.host_pool_capacity))),
37+ : capacity_(static_cast <size_t >(settings.host_pool_capacity)),
3938 buffer_ (std::max(capacity_, static_cast <size_t >(1u ))),
4039 stopped_(true ),
4140 file_path_(settings.hosts_file),
@@ -103,15 +102,18 @@ code hosts::fetch(address::list& out) const
103102 if (buffer_.empty ())
104103 return error::not_found;
105104
106- const auto out_count = std::min (buffer_.size (), capacity_) /
107- static_cast <size_t >(pseudo_random::next (1 , 20 ));
105+ const auto out_count = std::min (max_address, std::min ( buffer_.size (),
106+ capacity_) / static_cast <size_t >(pseudo_random::next (5 , 10 ) ));
108107
109108 if (out_count == 0 )
110109 return error::success;
111110
111+ const auto limit = buffer_.size () - 1 ;
112+ auto index = static_cast <size_t >(pseudo_random::next (0 , limit));
113+
112114 out.reserve (out_count);
113- for (size_t index = 0 ; index < out_count; ++index )
114- out.push_back (buffer_[index]);
115+ for (size_t count = 0 ; count < out_count; ++count )
116+ out.push_back (buffer_[index++ % limit ]);
115117 }
116118 // /////////////////////////////////////////////////////////////////////////
117119
0 commit comments