Skip to content

Commit caa92e9

Browse files
Merge pull request #222 from thecodefactory/address-increase
Increase the number of addresses to share when responding to peers.
2 parents fb8b041 + f334644 commit caa92e9

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/hosts.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ using namespace bc::config;
3434

3535
// TODO: change to network_address bimap hash table with services and age.
3636
hosts::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

Comments
 (0)