refactor: rename mediator classes (#2681)

This commit is contained in:
Charles Kerr 2022-02-22 09:09:24 -06:00 committed by GitHub
parent c0b09d0f47
commit 95e30768c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 130 additions and 130 deletions

View File

@ -64,20 +64,20 @@ struct Candidate
}
};
std::vector<Candidate> getCandidates(Wishlist::PeerInfo const& peer_info)
std::vector<Candidate> getCandidates(Wishlist::Mediator const& mediator)
{
// count up the pieces that we still want
auto wanted_pieces = std::vector<std::pair<tr_piece_index_t, size_t>>{};
auto const n_pieces = peer_info.countAllPieces();
auto const n_pieces = mediator.countAllPieces();
wanted_pieces.reserve(n_pieces);
for (tr_piece_index_t i = 0; i < n_pieces; ++i)
{
if (!peer_info.clientCanRequestPiece(i))
if (!mediator.clientCanRequestPiece(i))
{
continue;
}
size_t const n_missing = peer_info.countMissingBlocks(i);
size_t const n_missing = mediator.countMissingBlocks(i);
if (n_missing == 0)
{
continue;
@ -95,7 +95,7 @@ std::vector<Candidate> getCandidates(Wishlist::PeerInfo const& peer_info)
for (size_t i = 0; i < n; ++i)
{
auto const [piece, n_missing] = wanted_pieces[i];
candidates.emplace_back(piece, n_missing, peer_info.priority(piece), saltbuf[i]);
candidates.emplace_back(piece, n_missing, mediator.priority(piece), saltbuf[i]);
}
return candidates;
@ -129,7 +129,7 @@ std::vector<tr_block_span_t> makeSpans(tr_block_index_t const* sorted_blocks, si
} // namespace
std::vector<tr_block_span_t> Wishlist::next(Wishlist::PeerInfo const& peer_info, size_t n_wanted_blocks)
std::vector<tr_block_span_t> Wishlist::next(Wishlist::Mediator const& mediator, size_t n_wanted_blocks)
{
if (n_wanted_blocks == 0)
{
@ -141,7 +141,7 @@ std::vector<tr_block_span_t> Wishlist::next(Wishlist::PeerInfo const& peer_info,
// We usually won't need all the candidates until endgame, so don't
// waste cycles sorting all of them here. partial sort is enough.
auto candidates = getCandidates(peer_info);
auto candidates = getCandidates(mediator);
auto constexpr MaxSortedPieces = size_t{ 30 };
auto const middle = std::min(std::size(candidates), MaxSortedPieces);
std::partial_sort(std::begin(candidates), std::begin(candidates) + middle, std::end(candidates));
@ -155,20 +155,20 @@ std::vector<tr_block_span_t> Wishlist::next(Wishlist::PeerInfo const& peer_info,
}
// walk the blocks in this piece
auto const [begin, end] = peer_info.blockSpan(candidate.piece);
auto const [begin, end] = mediator.blockSpan(candidate.piece);
auto blocks = std::vector<tr_block_index_t>{};
blocks.reserve(end - begin);
for (tr_block_index_t block = begin; block < end && n_blocks + std::size(blocks) < n_wanted_blocks; ++block)
{
// don't request blocks we've already got
if (!peer_info.clientCanRequestBlock(block))
if (!mediator.clientCanRequestBlock(block))
{
continue;
}
// don't request from too many peers
size_t const n_peers = peer_info.countActiveRequests(block);
if (size_t const max_peers = peer_info.isEndgame() ? 2 : 1; n_peers >= max_peers)
size_t const n_peers = mediator.countActiveRequests(block);
if (size_t const max_peers = mediator.isEndgame() ? 2 : 1; n_peers >= max_peers)
{
continue;
}

View File

@ -22,7 +22,7 @@
class Wishlist
{
public:
struct PeerInfo
struct Mediator
{
virtual bool clientCanRequestBlock(tr_block_index_t block) const = 0;
virtual bool clientCanRequestPiece(tr_piece_index_t piece) const = 0;
@ -32,9 +32,9 @@ public:
virtual tr_block_span_t blockSpan(tr_piece_index_t) const = 0;
virtual tr_piece_index_t countAllPieces() const = 0;
virtual tr_priority_t priority(tr_piece_index_t) const = 0;
virtual ~PeerInfo() = default;
virtual ~Mediator() = default;
};
// get a list of the next blocks that we should request from a peer
static std::vector<tr_block_span_t> next(PeerInfo const& peer_info, size_t n_wanted_blocks);
static std::vector<tr_block_span_t> next(Mediator const& peer_info, size_t n_wanted_blocks);
};

View File

@ -546,17 +546,17 @@ static void updateEndgame(tr_swarm* s)
std::vector<tr_block_span_t> tr_peerMgrGetNextRequests(tr_torrent* torrent, tr_peer const* peer, size_t numwant)
{
class PeerInfoImpl final : public Wishlist::PeerInfo
class MediatorImpl final : public Wishlist::Mediator
{
public:
PeerInfoImpl(tr_torrent const* torrent_in, tr_peer const* peer_in)
MediatorImpl(tr_torrent const* torrent_in, tr_peer const* peer_in)
: torrent_{ torrent_in }
, swarm_{ torrent_in->swarm }
, peer_{ peer_in }
{
}
~PeerInfoImpl() override = default;
~MediatorImpl() override = default;
[[nodiscard]] bool clientCanRequestBlock(tr_block_index_t block) const override
{
@ -606,7 +606,7 @@ std::vector<tr_block_span_t> tr_peerMgrGetNextRequests(tr_torrent* torrent, tr_p
auto* const swarm = torrent->swarm;
updateEndgame(swarm);
return Wishlist::next(PeerInfoImpl(torrent, peer), numwant);
return Wishlist::next(MediatorImpl(torrent, peer), numwant);
}
/****

View File

@ -115,18 +115,18 @@ tr_peer_id_t tr_peerIdInit()
****
***/
std::optional<std::string> tr_session::WebController::cookieFile() const
std::optional<std::string> tr_session::WebMediator::cookieFile() const
{
auto const str = tr_strvPath(session_->config_dir, "cookies.txt");
return tr_sys_path_exists(str.c_str(), nullptr) ? std::optional<std::string>{ str } : std::nullopt;
}
std::optional<std::string> tr_session::WebController::userAgent() const
std::optional<std::string> tr_session::WebMediator::userAgent() const
{
return tr_strvJoin(TR_NAME, "/"sv, SHORT_VERSION_STRING);
}
std::optional<std::string> tr_session::WebController::publicAddress() const
std::optional<std::string> tr_session::WebMediator::publicAddress() const
{
for (auto const type : { TR_AF_INET, TR_AF_INET6 })
{
@ -141,14 +141,14 @@ std::optional<std::string> tr_session::WebController::publicAddress() const
return std::nullopt;
}
unsigned int tr_session::WebController::clamp(int torrent_id, unsigned int byte_count) const
unsigned int tr_session::WebMediator::clamp(int torrent_id, unsigned int byte_count) const
{
auto const lock = session_->unique_lock();
auto const it = session_->torrentsById.find(torrent_id);
return it == std::end(session_->torrentsById) ? 0U : it->second->bandwidth->clamp(TR_DOWN, byte_count);
}
void tr_session::WebController::notifyBandwidthConsumed(int torrent_id, size_t byte_count)
void tr_session::WebMediator::notifyBandwidthConsumed(int torrent_id, size_t byte_count)
{
auto const lock = session_->unique_lock();
auto const it = session_->torrentsById.find(torrent_id);
@ -158,7 +158,7 @@ void tr_session::WebController::notifyBandwidthConsumed(int torrent_id, size_t b
}
}
void tr_session::WebController::run(tr_web::FetchDoneFunc&& func, tr_web::FetchResponse&& response) const
void tr_session::WebMediator::run(tr_web::FetchDoneFunc&& func, tr_web::FetchResponse&& response) const
{
// marshall the `func` call into the libtransmission thread
@ -760,7 +760,7 @@ static void tr_sessionInitImpl(void* vdata)
tr_udpInit(session);
session->web = tr_web::create(session->web_controller);
session->web = tr_web::create(session->web_mediator);
if (session->isLPDEnabled)
{

View File

@ -352,14 +352,14 @@ public:
struct tr_cache* cache;
class WebController final : public tr_web::Controller
class WebMediator final : public tr_web::Mediator
{
public:
explicit WebController(tr_session* session)
explicit WebMediator(tr_session* session)
: session_{ session }
{
}
~WebController() override = default;
~WebMediator() override = default;
[[nodiscard]] std::optional<std::string> cookieFile() const override;
[[nodiscard]] std::optional<std::string> publicAddress() const override;
@ -373,7 +373,7 @@ public:
tr_session* const session_;
};
WebController web_controller{ this };
WebMediator web_mediator{ this };
std::unique_ptr<tr_web> web;
struct tr_session_id* session_id;

View File

@ -103,8 +103,8 @@ static CURLcode ssl_context_func(CURL* /*curl*/, void* ssl_ctx, void* /*user_dat
class tr_web::Impl
{
public:
explicit Impl(Controller& controller_in)
: controller{ controller_in }
explicit Impl(Mediator& mediator_in)
: mediator{ mediator_in }
{
std::call_once(curl_init_flag, curlInit);
@ -122,12 +122,12 @@ public:
tr_logAddNamedInfo("web", "NB: Invalid certs will appear as 'Could not connect to tracker' like many other errors");
}
if (auto const& file = controller.cookieFile(); file)
if (auto const& file = mediator.cookieFile(); file)
{
this->cookie_file = *file;
}
if (auto const& ua = controller.userAgent(); ua)
if (auto const& ua = mediator.userAgent(); ua)
{
this->user_agent = *ua;
}
@ -231,7 +231,7 @@ private:
}
response.body.assign(reinterpret_cast<char const*>(evbuffer_pullup(body(), -1)), evbuffer_get_length(body()));
impl.controller.run(std::move(options.done_func), std::move(this->response));
impl.mediator.run(std::move(options.done_func), std::move(this->response));
}
tr_web::Impl& impl;
@ -245,7 +245,7 @@ private:
bool const curl_ssl_verify = !tr_env_key_exists("TR_CURL_SSL_NO_VERIFY");
bool const curl_proxy_ssl_verify = !tr_env_key_exists("TR_CURL_PROXY_SSL_NO_VERIFY");
Controller& controller;
Mediator& mediator;
std::string curl_ca_bundle;
@ -274,13 +274,13 @@ private:
// If this is more bandwidth than is allocated for this tag,
// then pause the torrent for a tick. curl will deliver `data`
// again when the transfer is unpaused.
if (task->impl.controller.clamp(*tag, bytes_used) < bytes_used)
if (task->impl.mediator.clamp(*tag, bytes_used) < bytes_used)
{
task->impl.paused_easy_handles.emplace(tr_time_msec(), task->easy());
return CURL_WRITEFUNC_PAUSE;
}
task->impl.controller.notifyBandwidthConsumed(*tag, bytes_used);
task->impl.mediator.notifyBandwidthConsumed(*tag, bytes_used);
}
evbuffer_add(task->body(), data, bytes_used);
@ -365,7 +365,7 @@ private:
(void)curl_easy_setopt(e, CURLOPT_WRITEDATA, task);
(void)curl_easy_setopt(e, CURLOPT_WRITEFUNCTION, onDataReceived);
if (auto const addrstr = impl->controller.publicAddress(); addrstr)
if (auto const addrstr = impl->mediator.publicAddress(); addrstr)
{
(void)curl_easy_setopt(e, CURLOPT_INTERFACE, addrstr->c_str());
}
@ -533,16 +533,16 @@ private:
std::once_flag tr_web::Impl::curl_init_flag;
tr_web::tr_web(Controller& controller)
: impl_{ std::make_unique<Impl>(controller) }
tr_web::tr_web(Mediator& mediator)
: impl_{ std::make_unique<Impl>(mediator) }
{
}
tr_web::~tr_web() = default;
std::unique_ptr<tr_web> tr_web::create(Controller& controller)
std::unique_ptr<tr_web> tr_web::create(Mediator& mediator)
{
return std::unique_ptr<tr_web>(new tr_web(controller));
return std::unique_ptr<tr_web>(new tr_web(mediator));
}
void tr_web::fetch(FetchOptions&& options)

View File

@ -54,7 +54,7 @@ public:
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests
std::optional<std::string> range;
// Tag used by tr_web::Controller to limit some transfers' bandwidth
// Tag used by tr_web::Mediator to limit some transfers' bandwidth
std::optional<int> speed_limit_tag;
// Optionaly set the underlying sockets' send/receive buffers' size.
@ -96,10 +96,10 @@ public:
* NB: Note that tr_web calls all these methods from its own thread.
* Overridden methods should take care to be threadsafe.
*/
class Controller
class Mediator
{
public:
virtual ~Controller() = default;
virtual ~Mediator() = default;
// Return the location of the cookie file, or nullopt to not use one
[[nodiscard]] virtual std::optional<std::string> cookieFile() const
@ -137,14 +137,14 @@ public:
}
};
// Note that tr_web does no management of the `controller` reference.
// The caller must ensure `controller` is valid for tr_web's lifespan.
static std::unique_ptr<tr_web> create(Controller& controller);
// Note that tr_web does no management of the `mediator` reference.
// The caller must ensure `mediator` is valid for tr_web's lifespan.
static std::unique_ptr<tr_web> create(Mediator& mediator);
private:
class Impl;
std::unique_ptr<Impl> const impl_;
explicit tr_web(Controller& controller);
explicit tr_web(Mediator& mediator);
};
void tr_sessionFetch(struct tr_session* session, tr_web::FetchOptions&& options);

View File

@ -17,7 +17,7 @@
class PeerMgrWishlistTest : public ::testing::Test
{
protected:
struct MockPeerInfo : public Wishlist::PeerInfo
struct MockMediator : public Wishlist::Mediator
{
mutable std::map<tr_block_index_t, size_t> active_request_count_;
mutable std::map<tr_piece_index_t, size_t> missing_block_count_;
@ -72,59 +72,59 @@ protected:
TEST_F(PeerMgrWishlistTest, doesNotRequestPiecesThatCannotBeRequested)
{
auto peer_info = MockPeerInfo{};
auto mediator = MockMediator{};
// setup: three pieces, all missing
peer_info.piece_count_ = 3;
peer_info.missing_block_count_[0] = 100;
peer_info.missing_block_count_[1] = 100;
peer_info.missing_block_count_[2] = 50;
peer_info.block_span_[0] = { 0, 100 };
peer_info.block_span_[1] = { 100, 200 };
peer_info.block_span_[2] = { 200, 251 };
mediator.piece_count_ = 3;
mediator.missing_block_count_[0] = 100;
mediator.missing_block_count_[1] = 100;
mediator.missing_block_count_[2] = 50;
mediator.block_span_[0] = { 0, 100 };
mediator.block_span_[1] = { 100, 200 };
mediator.block_span_[2] = { 200, 251 };
// but we only want the first piece
peer_info.can_request_piece_.insert(0);
for (tr_block_index_t i = peer_info.block_span_[0].begin; i < peer_info.block_span_[0].end; ++i)
mediator.can_request_piece_.insert(0);
for (tr_block_index_t i = mediator.block_span_[0].begin; i < mediator.block_span_[0].end; ++i)
{
peer_info.can_request_block_.insert(i);
mediator.can_request_block_.insert(i);
}
// we should only get the first piece back
auto spans = Wishlist::next(peer_info, 1000);
auto spans = Wishlist::next(mediator, 1000);
ASSERT_EQ(1, std::size(spans));
EXPECT_EQ(peer_info.block_span_[0].begin, spans[0].begin);
EXPECT_EQ(peer_info.block_span_[0].end, spans[0].end);
EXPECT_EQ(mediator.block_span_[0].begin, spans[0].begin);
EXPECT_EQ(mediator.block_span_[0].end, spans[0].end);
}
TEST_F(PeerMgrWishlistTest, doesNotRequestBlocksThatCannotBeRequested)
{
auto peer_info = MockPeerInfo{};
auto mediator = MockMediator{};
// setup: three pieces, all missing
peer_info.piece_count_ = 3;
peer_info.missing_block_count_[0] = 100;
peer_info.missing_block_count_[1] = 100;
peer_info.missing_block_count_[2] = 50;
peer_info.block_span_[0] = { 0, 100 };
peer_info.block_span_[1] = { 100, 200 };
peer_info.block_span_[2] = { 200, 251 };
mediator.piece_count_ = 3;
mediator.missing_block_count_[0] = 100;
mediator.missing_block_count_[1] = 100;
mediator.missing_block_count_[2] = 50;
mediator.block_span_[0] = { 0, 100 };
mediator.block_span_[1] = { 100, 200 };
mediator.block_span_[2] = { 200, 251 };
// and we want all three pieces
peer_info.can_request_piece_.insert(0);
peer_info.can_request_piece_.insert(1);
peer_info.can_request_piece_.insert(2);
mediator.can_request_piece_.insert(0);
mediator.can_request_piece_.insert(1);
mediator.can_request_piece_.insert(2);
// but we've already requested blocks [0..10) from someone else,
// so we don't want to send repeat requests
for (tr_block_index_t i = 10; i < 250; ++i)
{
peer_info.can_request_block_.insert(i);
mediator.can_request_block_.insert(i);
}
// even if we ask wishlist for more blocks than exist,
// it should omit blocks 1-10 from the return set
auto spans = Wishlist::next(peer_info, 1000);
auto spans = Wishlist::next(mediator, 1000);
auto requested = tr_bitfield(250);
for (auto const& span : spans)
{
@ -137,31 +137,31 @@ TEST_F(PeerMgrWishlistTest, doesNotRequestBlocksThatCannotBeRequested)
TEST_F(PeerMgrWishlistTest, doesNotRequestTooManyBlocks)
{
auto peer_info = MockPeerInfo{};
auto mediator = MockMediator{};
// setup: three pieces, all missing
peer_info.piece_count_ = 3;
peer_info.missing_block_count_[0] = 100;
peer_info.missing_block_count_[1] = 100;
peer_info.missing_block_count_[2] = 50;
peer_info.block_span_[0] = { 0, 100 };
peer_info.block_span_[1] = { 100, 200 };
peer_info.block_span_[2] = { 200, 251 };
mediator.piece_count_ = 3;
mediator.missing_block_count_[0] = 100;
mediator.missing_block_count_[1] = 100;
mediator.missing_block_count_[2] = 50;
mediator.block_span_[0] = { 0, 100 };
mediator.block_span_[1] = { 100, 200 };
mediator.block_span_[2] = { 200, 251 };
// and we want everything
for (tr_piece_index_t i = 0; i < 3; ++i)
{
peer_info.can_request_piece_.insert(i);
mediator.can_request_piece_.insert(i);
}
for (tr_block_index_t i = 0; i < 250; ++i)
{
peer_info.can_request_block_.insert(i);
mediator.can_request_block_.insert(i);
}
// but we only ask for 10 blocks,
// so that's how many we should get back
auto const n_wanted = 10;
auto const spans = Wishlist::next(peer_info, n_wanted);
auto const spans = Wishlist::next(mediator, n_wanted);
auto n_got = size_t{};
for (auto const& span : spans)
{
@ -172,29 +172,29 @@ TEST_F(PeerMgrWishlistTest, doesNotRequestTooManyBlocks)
TEST_F(PeerMgrWishlistTest, prefersHighPriorityPieces)
{
auto peer_info = MockPeerInfo{};
auto mediator = MockMediator{};
// setup: three pieces, all missing
peer_info.piece_count_ = 3;
peer_info.missing_block_count_[0] = 100;
peer_info.missing_block_count_[1] = 100;
peer_info.missing_block_count_[2] = 100;
peer_info.block_span_[0] = { 0, 100 };
peer_info.block_span_[1] = { 100, 200 };
peer_info.block_span_[2] = { 200, 300 };
mediator.piece_count_ = 3;
mediator.missing_block_count_[0] = 100;
mediator.missing_block_count_[1] = 100;
mediator.missing_block_count_[2] = 100;
mediator.block_span_[0] = { 0, 100 };
mediator.block_span_[1] = { 100, 200 };
mediator.block_span_[2] = { 200, 300 };
// and we want everything
for (tr_piece_index_t i = 0; i < 3; ++i)
{
peer_info.can_request_piece_.insert(i);
mediator.can_request_piece_.insert(i);
}
for (tr_block_index_t i = 0; i < 299; ++i)
{
peer_info.can_request_block_.insert(i);
mediator.can_request_block_.insert(i);
}
// and the second piece is high priority
peer_info.piece_priority_[1] = TR_PRI_HIGH;
mediator.piece_priority_[1] = TR_PRI_HIGH;
// wishlist should pick the high priority piece's blocks first.
//
@ -205,14 +205,14 @@ TEST_F(PeerMgrWishlistTest, prefersHighPriorityPieces)
for (int run = 0; run < num_runs; ++run)
{
auto const n_wanted = 10;
auto spans = Wishlist::next(peer_info, n_wanted);
auto spans = Wishlist::next(mediator, n_wanted);
auto n_got = size_t{};
for (auto const& span : spans)
{
for (auto block = span.begin; block < span.end; ++block)
{
EXPECT_LE(peer_info.block_span_[1].begin, block);
EXPECT_LT(block, peer_info.block_span_[1].end);
EXPECT_LE(mediator.block_span_[1].begin, block);
EXPECT_LT(block, mediator.block_span_[1].end);
}
n_got += span.end - span.begin;
}
@ -222,36 +222,36 @@ TEST_F(PeerMgrWishlistTest, prefersHighPriorityPieces)
TEST_F(PeerMgrWishlistTest, onlyRequestsDupesDuringEndgame)
{
auto peer_info = MockPeerInfo{};
auto mediator = MockMediator{};
// setup: three pieces, all missing
peer_info.piece_count_ = 3;
peer_info.missing_block_count_[0] = 100;
peer_info.missing_block_count_[1] = 100;
peer_info.missing_block_count_[2] = 100;
peer_info.block_span_[0] = { 0, 100 };
peer_info.block_span_[1] = { 100, 200 };
peer_info.block_span_[2] = { 200, 300 };
mediator.piece_count_ = 3;
mediator.missing_block_count_[0] = 100;
mediator.missing_block_count_[1] = 100;
mediator.missing_block_count_[2] = 100;
mediator.block_span_[0] = { 0, 100 };
mediator.block_span_[1] = { 100, 200 };
mediator.block_span_[2] = { 200, 300 };
// and we want everything
for (tr_piece_index_t i = 0; i < 3; ++i)
{
peer_info.can_request_piece_.insert(i);
mediator.can_request_piece_.insert(i);
}
for (tr_block_index_t i = 0; i < 300; ++i)
{
peer_info.can_request_block_.insert(i);
mediator.can_request_block_.insert(i);
}
// and we've already requested blocks [0-150)
for (tr_block_index_t i = 0; i < 150; ++i)
{
peer_info.active_request_count_[i] = 1;
mediator.active_request_count_[i] = 1;
}
// even if we ask wishlist to list more blocks than exist,
// those first 150 should be omitted from the return list
auto spans = Wishlist::next(peer_info, 1000);
auto spans = Wishlist::next(mediator, 1000);
auto requested = tr_bitfield(300);
for (auto const& span : spans)
{
@ -263,8 +263,8 @@ TEST_F(PeerMgrWishlistTest, onlyRequestsDupesDuringEndgame)
// BUT during endgame it's OK to request dupes,
// so then we _should_ see the first 150 in the list
peer_info.is_endgame_ = true;
spans = Wishlist::next(peer_info, 1000);
mediator.is_endgame_ = true;
spans = Wishlist::next(mediator, 1000);
requested = tr_bitfield(300);
for (auto const& span : spans)
{
@ -277,32 +277,32 @@ TEST_F(PeerMgrWishlistTest, onlyRequestsDupesDuringEndgame)
TEST_F(PeerMgrWishlistTest, prefersNearlyCompletePieces)
{
auto peer_info = MockPeerInfo{};
auto mediator = MockMediator{};
// setup: three pieces, same size
peer_info.piece_count_ = 3;
peer_info.block_span_[0] = { 0, 100 };
peer_info.block_span_[1] = { 100, 200 };
peer_info.block_span_[2] = { 200, 300 };
mediator.piece_count_ = 3;
mediator.block_span_[0] = { 0, 100 };
mediator.block_span_[1] = { 100, 200 };
mediator.block_span_[2] = { 200, 300 };
// and we want everything
for (tr_piece_index_t i = 0; i < 3; ++i)
{
peer_info.can_request_piece_.insert(i);
mediator.can_request_piece_.insert(i);
}
// but some pieces are closer to completion than others
peer_info.missing_block_count_[0] = 10;
peer_info.missing_block_count_[1] = 20;
peer_info.missing_block_count_[2] = 100;
mediator.missing_block_count_[0] = 10;
mediator.missing_block_count_[1] = 20;
mediator.missing_block_count_[2] = 100;
for (tr_piece_index_t piece = 0; piece < 3; ++piece)
{
auto const& span = peer_info.block_span_[piece];
auto const& n_missing = peer_info.missing_block_count_[piece];
auto const& span = mediator.block_span_[piece];
auto const& n_missing = mediator.missing_block_count_[piece];
for (size_t i = 0; i < n_missing; ++i)
{
peer_info.can_request_block_.insert(span.begin + i);
mediator.can_request_block_.insert(span.begin + i);
}
}
@ -314,7 +314,7 @@ TEST_F(PeerMgrWishlistTest, prefersNearlyCompletePieces)
auto const num_runs = 1000;
for (int run = 0; run < num_runs; ++run)
{
auto const ranges = Wishlist::next(peer_info, 10);
auto const ranges = Wishlist::next(mediator, 10);
auto requested = tr_bitfield(300);
for (auto const& range : ranges)
{
@ -330,7 +330,7 @@ TEST_F(PeerMgrWishlistTest, prefersNearlyCompletePieces)
// those blocks should be next in line.
for (int run = 0; run < num_runs; ++run)
{
auto const ranges = Wishlist::next(peer_info, 20);
auto const ranges = Wishlist::next(mediator, 20);
auto requested = tr_bitfield(300);
for (auto const& range : ranges)
{