2023-02-11 20:49:42 +00:00
|
|
|
// This file Copyright © 2021-2023 Mnemosyne LLC.
|
2022-08-08 18:05:39 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2021-11-19 18:37:38 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifndef LIBTRANSMISSION_PEER_MODULE
|
|
|
|
#error only the libtransmission peer module should #include this header.
|
|
|
|
#endif
|
|
|
|
|
2021-12-15 21:25:42 +00:00
|
|
|
#include <cstddef> // size_t
|
|
|
|
#include <vector>
|
|
|
|
|
2021-11-19 18:37:38 +00:00
|
|
|
#include "transmission.h"
|
2021-12-15 21:25:42 +00:00
|
|
|
|
2021-11-19 18:37:38 +00:00
|
|
|
#include "torrent.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Figures out what blocks we want to request next.
|
|
|
|
*/
|
|
|
|
class Wishlist
|
|
|
|
{
|
|
|
|
public:
|
2022-02-22 15:09:24 +00:00
|
|
|
struct Mediator
|
2021-11-19 18:37:38 +00:00
|
|
|
{
|
2023-01-28 23:58:20 +00:00
|
|
|
[[nodiscard]] virtual bool clientCanRequestBlock(tr_block_index_t block) const = 0;
|
|
|
|
[[nodiscard]] virtual bool clientCanRequestPiece(tr_piece_index_t piece) const = 0;
|
|
|
|
[[nodiscard]] virtual bool isEndgame() const = 0;
|
|
|
|
[[nodiscard]] virtual size_t countActiveRequests(tr_block_index_t block) const = 0;
|
|
|
|
[[nodiscard]] virtual size_t countMissingBlocks(tr_piece_index_t piece) const = 0;
|
|
|
|
[[nodiscard]] virtual tr_block_span_t blockSpan(tr_piece_index_t) const = 0;
|
|
|
|
[[nodiscard]] virtual tr_piece_index_t countAllPieces() const = 0;
|
|
|
|
[[nodiscard]] virtual tr_priority_t priority(tr_piece_index_t) const = 0;
|
2022-02-22 15:09:24 +00:00
|
|
|
virtual ~Mediator() = default;
|
2021-11-19 18:37:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// get a list of the next blocks that we should request from a peer
|
2022-08-03 06:15:37 +00:00
|
|
|
static std::vector<tr_block_span_t> next(Mediator const& mediator, size_t n_wanted_blocks);
|
2021-11-19 18:37:38 +00:00
|
|
|
};
|