mirror of
https://github.com/transmission/transmission.git
synced 2026-02-15 07:26:49 +00:00
* fix: warning: declaration shadows a variable in the global namespace [clang-diagnostic-shadow] * fix: warning: use 'contains' to check for membership [readability-container-contains] * fix: warning: variable gl_confdir can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage] * warning: function 'TorrentFilter::match_mode' has a definition with different parameter names [readability-inconsistent-declaration-parameter-name] * build: add sigslot dependency * refactor: use sigslot for tr::Blocklists * refactor: use sigslot for torrent, peer-mgr, wishlist * refactor: remove tr::SimpleObservable * chore: make lint happy warning: method 'make_wishlist' can be made static [readability-convert-member-functions-to-static] warning: invalid case style for function 'make_wishlist' [readability-identifier-naming] warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays] * refactor: remove unused forward declaration of tr_peer * chore: remove slop * refactor: Blocklist::observe_changes() now returns a scoped connection * build: use transmission/sigslot fork * refactor: copyediting * refactor: fix cyclical dependency loop between Wishlist and tr_peerMgr::WishlistMediator
69 lines
2.5 KiB
C++
69 lines
2.5 KiB
C++
// This file Copyright © Mnemosyne LLC.
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
// License text can be found in the licenses/ folder.
|
|
|
|
#pragma once
|
|
|
|
#ifndef LIBTRANSMISSION_PEER_MODULE
|
|
#error only the libtransmission peer module should #include this header.
|
|
#endif
|
|
|
|
#include <cstddef> // size_t
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
#include "libtransmission/transmission.h"
|
|
|
|
class tr_bitfield;
|
|
|
|
/**
|
|
* Figures out what blocks we want to request next.
|
|
*/
|
|
class Wishlist
|
|
{
|
|
public:
|
|
struct Mediator
|
|
{
|
|
[[nodiscard]] virtual bool client_has_block(tr_block_index_t block) const = 0;
|
|
[[nodiscard]] virtual bool client_has_piece(tr_piece_index_t piece) const = 0;
|
|
[[nodiscard]] virtual bool client_wants_piece(tr_piece_index_t piece) const = 0;
|
|
[[nodiscard]] virtual bool is_sequential_download() const = 0;
|
|
[[nodiscard]] virtual tr_piece_index_t sequential_download_from_piece() const = 0;
|
|
[[nodiscard]] virtual size_t count_piece_replication(tr_piece_index_t piece) const = 0;
|
|
[[nodiscard]] virtual tr_block_span_t block_span(tr_piece_index_t piece) const = 0;
|
|
[[nodiscard]] virtual tr_piece_index_t piece_count() const = 0;
|
|
[[nodiscard]] virtual tr_priority_t priority(tr_piece_index_t piece) const = 0;
|
|
virtual ~Mediator() = default;
|
|
};
|
|
|
|
explicit Wishlist(Mediator& mediator_in);
|
|
~Wishlist();
|
|
|
|
void on_files_wanted_changed();
|
|
void on_got_bad_piece(tr_piece_index_t piece);
|
|
void on_got_bitfield(tr_bitfield const& bitfield);
|
|
void on_got_block(tr_block_index_t block);
|
|
void on_got_choke(tr_bitfield const& requests);
|
|
void on_got_have(tr_piece_index_t piece);
|
|
void on_got_have_all();
|
|
void on_got_reject(tr_block_index_t block);
|
|
void on_peer_disconnect(tr_bitfield const& have, tr_bitfield const& requests);
|
|
void on_piece_completed(tr_piece_index_t piece);
|
|
void on_priority_changed();
|
|
void on_sent_cancel(tr_block_index_t block);
|
|
void on_sent_request(tr_block_span_t block_span);
|
|
void on_sequential_download_changed();
|
|
void on_sequential_download_from_piece_changed();
|
|
|
|
// the next blocks that we should request from a peer
|
|
[[nodiscard]] std::vector<tr_block_span_t> next(
|
|
size_t n_wanted_blocks,
|
|
std::function<bool(tr_piece_index_t)> const& peer_has_piece);
|
|
|
|
private:
|
|
class Impl;
|
|
std::unique_ptr<Impl> impl_;
|
|
};
|