transmission/libtransmission/torrent-magnet.h

85 lines
2.1 KiB
C
Raw Normal View History

// This file Copyright © 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),
// or any future license endorsed by Mnemosyne LLC.
// License text can be found in the licenses/ folder.
2009-11-24 02:16:31 +00:00
#pragma once
2009-11-24 02:16:31 +00:00
#ifndef __TRANSMISSION__
#error only libtransmission should #include this header.
2009-11-24 02:16:31 +00:00
#endif
#include <cstddef> // size_t
#include <cstdint> // int64_t
#include <ctime> // time_t
#include <deque>
refactor: convert `tr_incomplete_metadata` to c++ class (#6383) * refactor: unset peer BEP-9 support if size hint is invalid * fix: open torrent file in binary mode * refactor: move metadata size check to method * refactor: remove duplicate checks * refactor: reduce temp variable scope in `parseLtepHandshake()` * refactor: convert `get_piece_length()` to method * refactor: convert `tr_torrentSetMetadataSizeHint()` to method * refactor: convert `tr_torrentGetMetadataPiece()` to method * refactor: convert `tr_torrentUseMetainfoFromFile()` to method * refactor: convert `tr_torrentSetMetadataPiece()` to method * refactor: convert `tr_torrentGetNextMetadataRequest()` to method * refactor: convert `tr_torrentGetMetadataPercent()` to method * refactor: add basic framework for MagnetMediator * refactor: initialise `tr_incomplete_metadata` fields in constructor * refactor: check metadata transfer completion in `set_metadata_piece()` * refactor: convert `use_new_metainfo()` and `on_have_all_metainfo()` to methods * refactor: move parts of `tr_torrent::set_metadata_piece()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_next_metadata_request()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_metadata_percent()` into `tr_incomplete_metadata` * refactor: hide all `tr_incomplete_metadata` fields * refactor: move `incomplete_metadata` to private * feat: add test for `set_metadata_piece()` * refactor: unify integer types * refactor: rename `tr_incomplete_metadata` to `tr_metadata_download` * chore: make clang-tidy happy libtransmission/torrent-magnet.cc:117:68: warning: comparison of integers of different signs: 'long' and 'const uint64_t' (aka 'const unsigned long') [clang-diagnostic-sign-compare] * refactor: pass log name to `tr_metadata_download` constructor * chore: iwyu * fix: thread-safe `TorrentMagnetTest.setMetadataPiece` * chore: housekeeping * Revert "fix: thread-safe `TorrentMagnetTest.setMetadataPiece`" This reverts commit 2a7fcd93a262888f9f55d542b1a9a2da9ca72cea. * fix: stop soon instead of stop now in `on_metainfo_completed()` This is unreachable code now, but if it is ever reached, Transmission will very likely crash. * fix: maybe fix OpenBSD test failure
2024-01-03 03:04:17 +00:00
#include <limits>
#include <memory>
#include <optional>
refactor: convert `tr_incomplete_metadata` to c++ class (#6383) * refactor: unset peer BEP-9 support if size hint is invalid * fix: open torrent file in binary mode * refactor: move metadata size check to method * refactor: remove duplicate checks * refactor: reduce temp variable scope in `parseLtepHandshake()` * refactor: convert `get_piece_length()` to method * refactor: convert `tr_torrentSetMetadataSizeHint()` to method * refactor: convert `tr_torrentGetMetadataPiece()` to method * refactor: convert `tr_torrentUseMetainfoFromFile()` to method * refactor: convert `tr_torrentSetMetadataPiece()` to method * refactor: convert `tr_torrentGetNextMetadataRequest()` to method * refactor: convert `tr_torrentGetMetadataPercent()` to method * refactor: add basic framework for MagnetMediator * refactor: initialise `tr_incomplete_metadata` fields in constructor * refactor: check metadata transfer completion in `set_metadata_piece()` * refactor: convert `use_new_metainfo()` and `on_have_all_metainfo()` to methods * refactor: move parts of `tr_torrent::set_metadata_piece()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_next_metadata_request()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_metadata_percent()` into `tr_incomplete_metadata` * refactor: hide all `tr_incomplete_metadata` fields * refactor: move `incomplete_metadata` to private * feat: add test for `set_metadata_piece()` * refactor: unify integer types * refactor: rename `tr_incomplete_metadata` to `tr_metadata_download` * chore: make clang-tidy happy libtransmission/torrent-magnet.cc:117:68: warning: comparison of integers of different signs: 'long' and 'const uint64_t' (aka 'const unsigned long') [clang-diagnostic-sign-compare] * refactor: pass log name to `tr_metadata_download` constructor * chore: iwyu * fix: thread-safe `TorrentMagnetTest.setMetadataPiece` * chore: housekeeping * Revert "fix: thread-safe `TorrentMagnetTest.setMetadataPiece`" This reverts commit 2a7fcd93a262888f9f55d542b1a9a2da9ca72cea. * fix: stop soon instead of stop now in `on_metainfo_completed()` This is unreachable code now, but if it is ever reached, Transmission will very likely crash. * fix: maybe fix OpenBSD test failure
2024-01-03 03:04:17 +00:00
#include <string>
#include <string_view>
#include <vector>
2009-11-24 02:16:31 +00:00
#include <small/vector.hpp>
refactor: convert `tr_incomplete_metadata` to c++ class (#6383) * refactor: unset peer BEP-9 support if size hint is invalid * fix: open torrent file in binary mode * refactor: move metadata size check to method * refactor: remove duplicate checks * refactor: reduce temp variable scope in `parseLtepHandshake()` * refactor: convert `get_piece_length()` to method * refactor: convert `tr_torrentSetMetadataSizeHint()` to method * refactor: convert `tr_torrentGetMetadataPiece()` to method * refactor: convert `tr_torrentUseMetainfoFromFile()` to method * refactor: convert `tr_torrentSetMetadataPiece()` to method * refactor: convert `tr_torrentGetNextMetadataRequest()` to method * refactor: convert `tr_torrentGetMetadataPercent()` to method * refactor: add basic framework for MagnetMediator * refactor: initialise `tr_incomplete_metadata` fields in constructor * refactor: check metadata transfer completion in `set_metadata_piece()` * refactor: convert `use_new_metainfo()` and `on_have_all_metainfo()` to methods * refactor: move parts of `tr_torrent::set_metadata_piece()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_next_metadata_request()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_metadata_percent()` into `tr_incomplete_metadata` * refactor: hide all `tr_incomplete_metadata` fields * refactor: move `incomplete_metadata` to private * feat: add test for `set_metadata_piece()` * refactor: unify integer types * refactor: rename `tr_incomplete_metadata` to `tr_metadata_download` * chore: make clang-tidy happy libtransmission/torrent-magnet.cc:117:68: warning: comparison of integers of different signs: 'long' and 'const uint64_t' (aka 'const unsigned long') [clang-diagnostic-sign-compare] * refactor: pass log name to `tr_metadata_download` constructor * chore: iwyu * fix: thread-safe `TorrentMagnetTest.setMetadataPiece` * chore: housekeeping * Revert "fix: thread-safe `TorrentMagnetTest.setMetadataPiece`" This reverts commit 2a7fcd93a262888f9f55d542b1a9a2da9ca72cea. * fix: stop soon instead of stop now in `on_metainfo_completed()` This is unreachable code now, but if it is ever reached, Transmission will very likely crash. * fix: maybe fix OpenBSD test failure
2024-01-03 03:04:17 +00:00
#include "libtransmission/tr-macros.h"
// defined by BEP #9
refactor: convert `tr_incomplete_metadata` to c++ class (#6383) * refactor: unset peer BEP-9 support if size hint is invalid * fix: open torrent file in binary mode * refactor: move metadata size check to method * refactor: remove duplicate checks * refactor: reduce temp variable scope in `parseLtepHandshake()` * refactor: convert `get_piece_length()` to method * refactor: convert `tr_torrentSetMetadataSizeHint()` to method * refactor: convert `tr_torrentGetMetadataPiece()` to method * refactor: convert `tr_torrentUseMetainfoFromFile()` to method * refactor: convert `tr_torrentSetMetadataPiece()` to method * refactor: convert `tr_torrentGetNextMetadataRequest()` to method * refactor: convert `tr_torrentGetMetadataPercent()` to method * refactor: add basic framework for MagnetMediator * refactor: initialise `tr_incomplete_metadata` fields in constructor * refactor: check metadata transfer completion in `set_metadata_piece()` * refactor: convert `use_new_metainfo()` and `on_have_all_metainfo()` to methods * refactor: move parts of `tr_torrent::set_metadata_piece()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_next_metadata_request()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_metadata_percent()` into `tr_incomplete_metadata` * refactor: hide all `tr_incomplete_metadata` fields * refactor: move `incomplete_metadata` to private * feat: add test for `set_metadata_piece()` * refactor: unify integer types * refactor: rename `tr_incomplete_metadata` to `tr_metadata_download` * chore: make clang-tidy happy libtransmission/torrent-magnet.cc:117:68: warning: comparison of integers of different signs: 'long' and 'const uint64_t' (aka 'const unsigned long') [clang-diagnostic-sign-compare] * refactor: pass log name to `tr_metadata_download` constructor * chore: iwyu * fix: thread-safe `TorrentMagnetTest.setMetadataPiece` * chore: housekeeping * Revert "fix: thread-safe `TorrentMagnetTest.setMetadataPiece`" This reverts commit 2a7fcd93a262888f9f55d542b1a9a2da9ca72cea. * fix: stop soon instead of stop now in `on_metainfo_completed()` This is unreachable code now, but if it is ever reached, Transmission will very likely crash. * fix: maybe fix OpenBSD test failure
2024-01-03 03:04:17 +00:00
inline constexpr auto MetadataPieceSize = 1024 * 16;
2009-11-24 02:16:31 +00:00
using tr_metadata_piece = small::max_size_vector<std::byte, MetadataPieceSize>;
refactor: convert `tr_incomplete_metadata` to c++ class (#6383) * refactor: unset peer BEP-9 support if size hint is invalid * fix: open torrent file in binary mode * refactor: move metadata size check to method * refactor: remove duplicate checks * refactor: reduce temp variable scope in `parseLtepHandshake()` * refactor: convert `get_piece_length()` to method * refactor: convert `tr_torrentSetMetadataSizeHint()` to method * refactor: convert `tr_torrentGetMetadataPiece()` to method * refactor: convert `tr_torrentUseMetainfoFromFile()` to method * refactor: convert `tr_torrentSetMetadataPiece()` to method * refactor: convert `tr_torrentGetNextMetadataRequest()` to method * refactor: convert `tr_torrentGetMetadataPercent()` to method * refactor: add basic framework for MagnetMediator * refactor: initialise `tr_incomplete_metadata` fields in constructor * refactor: check metadata transfer completion in `set_metadata_piece()` * refactor: convert `use_new_metainfo()` and `on_have_all_metainfo()` to methods * refactor: move parts of `tr_torrent::set_metadata_piece()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_next_metadata_request()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_metadata_percent()` into `tr_incomplete_metadata` * refactor: hide all `tr_incomplete_metadata` fields * refactor: move `incomplete_metadata` to private * feat: add test for `set_metadata_piece()` * refactor: unify integer types * refactor: rename `tr_incomplete_metadata` to `tr_metadata_download` * chore: make clang-tidy happy libtransmission/torrent-magnet.cc:117:68: warning: comparison of integers of different signs: 'long' and 'const uint64_t' (aka 'const unsigned long') [clang-diagnostic-sign-compare] * refactor: pass log name to `tr_metadata_download` constructor * chore: iwyu * fix: thread-safe `TorrentMagnetTest.setMetadataPiece` * chore: housekeeping * Revert "fix: thread-safe `TorrentMagnetTest.setMetadataPiece`" This reverts commit 2a7fcd93a262888f9f55d542b1a9a2da9ca72cea. * fix: stop soon instead of stop now in `on_metainfo_completed()` This is unreachable code now, but if it is ever reached, Transmission will very likely crash. * fix: maybe fix OpenBSD test failure
2024-01-03 03:04:17 +00:00
class tr_metadata_download
{
refactor: convert `tr_incomplete_metadata` to c++ class (#6383) * refactor: unset peer BEP-9 support if size hint is invalid * fix: open torrent file in binary mode * refactor: move metadata size check to method * refactor: remove duplicate checks * refactor: reduce temp variable scope in `parseLtepHandshake()` * refactor: convert `get_piece_length()` to method * refactor: convert `tr_torrentSetMetadataSizeHint()` to method * refactor: convert `tr_torrentGetMetadataPiece()` to method * refactor: convert `tr_torrentUseMetainfoFromFile()` to method * refactor: convert `tr_torrentSetMetadataPiece()` to method * refactor: convert `tr_torrentGetNextMetadataRequest()` to method * refactor: convert `tr_torrentGetMetadataPercent()` to method * refactor: add basic framework for MagnetMediator * refactor: initialise `tr_incomplete_metadata` fields in constructor * refactor: check metadata transfer completion in `set_metadata_piece()` * refactor: convert `use_new_metainfo()` and `on_have_all_metainfo()` to methods * refactor: move parts of `tr_torrent::set_metadata_piece()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_next_metadata_request()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_metadata_percent()` into `tr_incomplete_metadata` * refactor: hide all `tr_incomplete_metadata` fields * refactor: move `incomplete_metadata` to private * feat: add test for `set_metadata_piece()` * refactor: unify integer types * refactor: rename `tr_incomplete_metadata` to `tr_metadata_download` * chore: make clang-tidy happy libtransmission/torrent-magnet.cc:117:68: warning: comparison of integers of different signs: 'long' and 'const uint64_t' (aka 'const unsigned long') [clang-diagnostic-sign-compare] * refactor: pass log name to `tr_metadata_download` constructor * chore: iwyu * fix: thread-safe `TorrentMagnetTest.setMetadataPiece` * chore: housekeeping * Revert "fix: thread-safe `TorrentMagnetTest.setMetadataPiece`" This reverts commit 2a7fcd93a262888f9f55d542b1a9a2da9ca72cea. * fix: stop soon instead of stop now in `on_metainfo_completed()` This is unreachable code now, but if it is ever reached, Transmission will very likely crash. * fix: maybe fix OpenBSD test failure
2024-01-03 03:04:17 +00:00
public:
tr_metadata_download(std::string_view log_name, int64_t size);
[[nodiscard]] static constexpr auto is_valid_metadata_size(int64_t const size) noexcept
{
refactor: convert `tr_incomplete_metadata` to c++ class (#6383) * refactor: unset peer BEP-9 support if size hint is invalid * fix: open torrent file in binary mode * refactor: move metadata size check to method * refactor: remove duplicate checks * refactor: reduce temp variable scope in `parseLtepHandshake()` * refactor: convert `get_piece_length()` to method * refactor: convert `tr_torrentSetMetadataSizeHint()` to method * refactor: convert `tr_torrentGetMetadataPiece()` to method * refactor: convert `tr_torrentUseMetainfoFromFile()` to method * refactor: convert `tr_torrentSetMetadataPiece()` to method * refactor: convert `tr_torrentGetNextMetadataRequest()` to method * refactor: convert `tr_torrentGetMetadataPercent()` to method * refactor: add basic framework for MagnetMediator * refactor: initialise `tr_incomplete_metadata` fields in constructor * refactor: check metadata transfer completion in `set_metadata_piece()` * refactor: convert `use_new_metainfo()` and `on_have_all_metainfo()` to methods * refactor: move parts of `tr_torrent::set_metadata_piece()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_next_metadata_request()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_metadata_percent()` into `tr_incomplete_metadata` * refactor: hide all `tr_incomplete_metadata` fields * refactor: move `incomplete_metadata` to private * feat: add test for `set_metadata_piece()` * refactor: unify integer types * refactor: rename `tr_incomplete_metadata` to `tr_metadata_download` * chore: make clang-tidy happy libtransmission/torrent-magnet.cc:117:68: warning: comparison of integers of different signs: 'long' and 'const uint64_t' (aka 'const unsigned long') [clang-diagnostic-sign-compare] * refactor: pass log name to `tr_metadata_download` constructor * chore: iwyu * fix: thread-safe `TorrentMagnetTest.setMetadataPiece` * chore: housekeeping * Revert "fix: thread-safe `TorrentMagnetTest.setMetadataPiece`" This reverts commit 2a7fcd93a262888f9f55d542b1a9a2da9ca72cea. * fix: stop soon instead of stop now in `on_metainfo_completed()` This is unreachable code now, but if it is ever reached, Transmission will very likely crash. * fix: maybe fix OpenBSD test failure
2024-01-03 03:04:17 +00:00
return size > 0 && size <= std::numeric_limits<int>::max();
}
[[nodiscard]] auto is_complete() const noexcept
{
return std::empty(pieces_needed_);
}
void set_metadata_piece(int64_t piece, void const* data, size_t len);
refactor: convert `tr_incomplete_metadata` to c++ class (#6383) * refactor: unset peer BEP-9 support if size hint is invalid * fix: open torrent file in binary mode * refactor: move metadata size check to method * refactor: remove duplicate checks * refactor: reduce temp variable scope in `parseLtepHandshake()` * refactor: convert `get_piece_length()` to method * refactor: convert `tr_torrentSetMetadataSizeHint()` to method * refactor: convert `tr_torrentGetMetadataPiece()` to method * refactor: convert `tr_torrentUseMetainfoFromFile()` to method * refactor: convert `tr_torrentSetMetadataPiece()` to method * refactor: convert `tr_torrentGetNextMetadataRequest()` to method * refactor: convert `tr_torrentGetMetadataPercent()` to method * refactor: add basic framework for MagnetMediator * refactor: initialise `tr_incomplete_metadata` fields in constructor * refactor: check metadata transfer completion in `set_metadata_piece()` * refactor: convert `use_new_metainfo()` and `on_have_all_metainfo()` to methods * refactor: move parts of `tr_torrent::set_metadata_piece()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_next_metadata_request()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_metadata_percent()` into `tr_incomplete_metadata` * refactor: hide all `tr_incomplete_metadata` fields * refactor: move `incomplete_metadata` to private * feat: add test for `set_metadata_piece()` * refactor: unify integer types * refactor: rename `tr_incomplete_metadata` to `tr_metadata_download` * chore: make clang-tidy happy libtransmission/torrent-magnet.cc:117:68: warning: comparison of integers of different signs: 'long' and 'const uint64_t' (aka 'const unsigned long') [clang-diagnostic-sign-compare] * refactor: pass log name to `tr_metadata_download` constructor * chore: iwyu * fix: thread-safe `TorrentMagnetTest.setMetadataPiece` * chore: housekeeping * Revert "fix: thread-safe `TorrentMagnetTest.setMetadataPiece`" This reverts commit 2a7fcd93a262888f9f55d542b1a9a2da9ca72cea. * fix: stop soon instead of stop now in `on_metainfo_completed()` This is unreachable code now, but if it is ever reached, Transmission will very likely crash. * fix: maybe fix OpenBSD test failure
2024-01-03 03:04:17 +00:00
[[nodiscard]] std::optional<int64_t> get_next_metadata_request(time_t now) noexcept;
refactor: convert `tr_incomplete_metadata` to c++ class (#6383) * refactor: unset peer BEP-9 support if size hint is invalid * fix: open torrent file in binary mode * refactor: move metadata size check to method * refactor: remove duplicate checks * refactor: reduce temp variable scope in `parseLtepHandshake()` * refactor: convert `get_piece_length()` to method * refactor: convert `tr_torrentSetMetadataSizeHint()` to method * refactor: convert `tr_torrentGetMetadataPiece()` to method * refactor: convert `tr_torrentUseMetainfoFromFile()` to method * refactor: convert `tr_torrentSetMetadataPiece()` to method * refactor: convert `tr_torrentGetNextMetadataRequest()` to method * refactor: convert `tr_torrentGetMetadataPercent()` to method * refactor: add basic framework for MagnetMediator * refactor: initialise `tr_incomplete_metadata` fields in constructor * refactor: check metadata transfer completion in `set_metadata_piece()` * refactor: convert `use_new_metainfo()` and `on_have_all_metainfo()` to methods * refactor: move parts of `tr_torrent::set_metadata_piece()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_next_metadata_request()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_metadata_percent()` into `tr_incomplete_metadata` * refactor: hide all `tr_incomplete_metadata` fields * refactor: move `incomplete_metadata` to private * feat: add test for `set_metadata_piece()` * refactor: unify integer types * refactor: rename `tr_incomplete_metadata` to `tr_metadata_download` * chore: make clang-tidy happy libtransmission/torrent-magnet.cc:117:68: warning: comparison of integers of different signs: 'long' and 'const uint64_t' (aka 'const unsigned long') [clang-diagnostic-sign-compare] * refactor: pass log name to `tr_metadata_download` constructor * chore: iwyu * fix: thread-safe `TorrentMagnetTest.setMetadataPiece` * chore: housekeeping * Revert "fix: thread-safe `TorrentMagnetTest.setMetadataPiece`" This reverts commit 2a7fcd93a262888f9f55d542b1a9a2da9ca72cea. * fix: stop soon instead of stop now in `on_metainfo_completed()` This is unreachable code now, but if it is ever reached, Transmission will very likely crash. * fix: maybe fix OpenBSD test failure
2024-01-03 03:04:17 +00:00
[[nodiscard]] double get_metadata_percent() const noexcept;
refactor: convert `tr_incomplete_metadata` to c++ class (#6383) * refactor: unset peer BEP-9 support if size hint is invalid * fix: open torrent file in binary mode * refactor: move metadata size check to method * refactor: remove duplicate checks * refactor: reduce temp variable scope in `parseLtepHandshake()` * refactor: convert `get_piece_length()` to method * refactor: convert `tr_torrentSetMetadataSizeHint()` to method * refactor: convert `tr_torrentGetMetadataPiece()` to method * refactor: convert `tr_torrentUseMetainfoFromFile()` to method * refactor: convert `tr_torrentSetMetadataPiece()` to method * refactor: convert `tr_torrentGetNextMetadataRequest()` to method * refactor: convert `tr_torrentGetMetadataPercent()` to method * refactor: add basic framework for MagnetMediator * refactor: initialise `tr_incomplete_metadata` fields in constructor * refactor: check metadata transfer completion in `set_metadata_piece()` * refactor: convert `use_new_metainfo()` and `on_have_all_metainfo()` to methods * refactor: move parts of `tr_torrent::set_metadata_piece()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_next_metadata_request()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_metadata_percent()` into `tr_incomplete_metadata` * refactor: hide all `tr_incomplete_metadata` fields * refactor: move `incomplete_metadata` to private * feat: add test for `set_metadata_piece()` * refactor: unify integer types * refactor: rename `tr_incomplete_metadata` to `tr_metadata_download` * chore: make clang-tidy happy libtransmission/torrent-magnet.cc:117:68: warning: comparison of integers of different signs: 'long' and 'const uint64_t' (aka 'const unsigned long') [clang-diagnostic-sign-compare] * refactor: pass log name to `tr_metadata_download` constructor * chore: iwyu * fix: thread-safe `TorrentMagnetTest.setMetadataPiece` * chore: housekeeping * Revert "fix: thread-safe `TorrentMagnetTest.setMetadataPiece`" This reverts commit 2a7fcd93a262888f9f55d542b1a9a2da9ca72cea. * fix: stop soon instead of stop now in `on_metainfo_completed()` This is unreachable code now, but if it is ever reached, Transmission will very likely crash. * fix: maybe fix OpenBSD test failure
2024-01-03 03:04:17 +00:00
[[nodiscard]] constexpr auto const& get_metadata() const noexcept
{
return metadata_;
}
2009-11-24 02:16:31 +00:00
refactor: convert `tr_incomplete_metadata` to c++ class (#6383) * refactor: unset peer BEP-9 support if size hint is invalid * fix: open torrent file in binary mode * refactor: move metadata size check to method * refactor: remove duplicate checks * refactor: reduce temp variable scope in `parseLtepHandshake()` * refactor: convert `get_piece_length()` to method * refactor: convert `tr_torrentSetMetadataSizeHint()` to method * refactor: convert `tr_torrentGetMetadataPiece()` to method * refactor: convert `tr_torrentUseMetainfoFromFile()` to method * refactor: convert `tr_torrentSetMetadataPiece()` to method * refactor: convert `tr_torrentGetNextMetadataRequest()` to method * refactor: convert `tr_torrentGetMetadataPercent()` to method * refactor: add basic framework for MagnetMediator * refactor: initialise `tr_incomplete_metadata` fields in constructor * refactor: check metadata transfer completion in `set_metadata_piece()` * refactor: convert `use_new_metainfo()` and `on_have_all_metainfo()` to methods * refactor: move parts of `tr_torrent::set_metadata_piece()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_next_metadata_request()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_metadata_percent()` into `tr_incomplete_metadata` * refactor: hide all `tr_incomplete_metadata` fields * refactor: move `incomplete_metadata` to private * feat: add test for `set_metadata_piece()` * refactor: unify integer types * refactor: rename `tr_incomplete_metadata` to `tr_metadata_download` * chore: make clang-tidy happy libtransmission/torrent-magnet.cc:117:68: warning: comparison of integers of different signs: 'long' and 'const uint64_t' (aka 'const unsigned long') [clang-diagnostic-sign-compare] * refactor: pass log name to `tr_metadata_download` constructor * chore: iwyu * fix: thread-safe `TorrentMagnetTest.setMetadataPiece` * chore: housekeeping * Revert "fix: thread-safe `TorrentMagnetTest.setMetadataPiece`" This reverts commit 2a7fcd93a262888f9f55d542b1a9a2da9ca72cea. * fix: stop soon instead of stop now in `on_metainfo_completed()` This is unreachable code now, but if it is ever reached, Transmission will very likely crash. * fix: maybe fix OpenBSD test failure
2024-01-03 03:04:17 +00:00
[[nodiscard]] TR_CONSTEXPR20 std::string_view log_name() const noexcept
{
return log_name_;
}
2009-11-24 02:16:31 +00:00
refactor: convert `tr_incomplete_metadata` to c++ class (#6383) * refactor: unset peer BEP-9 support if size hint is invalid * fix: open torrent file in binary mode * refactor: move metadata size check to method * refactor: remove duplicate checks * refactor: reduce temp variable scope in `parseLtepHandshake()` * refactor: convert `get_piece_length()` to method * refactor: convert `tr_torrentSetMetadataSizeHint()` to method * refactor: convert `tr_torrentGetMetadataPiece()` to method * refactor: convert `tr_torrentUseMetainfoFromFile()` to method * refactor: convert `tr_torrentSetMetadataPiece()` to method * refactor: convert `tr_torrentGetNextMetadataRequest()` to method * refactor: convert `tr_torrentGetMetadataPercent()` to method * refactor: add basic framework for MagnetMediator * refactor: initialise `tr_incomplete_metadata` fields in constructor * refactor: check metadata transfer completion in `set_metadata_piece()` * refactor: convert `use_new_metainfo()` and `on_have_all_metainfo()` to methods * refactor: move parts of `tr_torrent::set_metadata_piece()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_next_metadata_request()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_metadata_percent()` into `tr_incomplete_metadata` * refactor: hide all `tr_incomplete_metadata` fields * refactor: move `incomplete_metadata` to private * feat: add test for `set_metadata_piece()` * refactor: unify integer types * refactor: rename `tr_incomplete_metadata` to `tr_metadata_download` * chore: make clang-tidy happy libtransmission/torrent-magnet.cc:117:68: warning: comparison of integers of different signs: 'long' and 'const uint64_t' (aka 'const unsigned long') [clang-diagnostic-sign-compare] * refactor: pass log name to `tr_metadata_download` constructor * chore: iwyu * fix: thread-safe `TorrentMagnetTest.setMetadataPiece` * chore: housekeeping * Revert "fix: thread-safe `TorrentMagnetTest.setMetadataPiece`" This reverts commit 2a7fcd93a262888f9f55d542b1a9a2da9ca72cea. * fix: stop soon instead of stop now in `on_metainfo_completed()` This is unreachable code now, but if it is ever reached, Transmission will very likely crash. * fix: maybe fix OpenBSD test failure
2024-01-03 03:04:17 +00:00
private:
struct metadata_node
{
time_t requested_at = {};
int64_t piece = {};
};
2009-11-24 02:16:31 +00:00
refactor: convert `tr_incomplete_metadata` to c++ class (#6383) * refactor: unset peer BEP-9 support if size hint is invalid * fix: open torrent file in binary mode * refactor: move metadata size check to method * refactor: remove duplicate checks * refactor: reduce temp variable scope in `parseLtepHandshake()` * refactor: convert `get_piece_length()` to method * refactor: convert `tr_torrentSetMetadataSizeHint()` to method * refactor: convert `tr_torrentGetMetadataPiece()` to method * refactor: convert `tr_torrentUseMetainfoFromFile()` to method * refactor: convert `tr_torrentSetMetadataPiece()` to method * refactor: convert `tr_torrentGetNextMetadataRequest()` to method * refactor: convert `tr_torrentGetMetadataPercent()` to method * refactor: add basic framework for MagnetMediator * refactor: initialise `tr_incomplete_metadata` fields in constructor * refactor: check metadata transfer completion in `set_metadata_piece()` * refactor: convert `use_new_metainfo()` and `on_have_all_metainfo()` to methods * refactor: move parts of `tr_torrent::set_metadata_piece()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_next_metadata_request()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_metadata_percent()` into `tr_incomplete_metadata` * refactor: hide all `tr_incomplete_metadata` fields * refactor: move `incomplete_metadata` to private * feat: add test for `set_metadata_piece()` * refactor: unify integer types * refactor: rename `tr_incomplete_metadata` to `tr_metadata_download` * chore: make clang-tidy happy libtransmission/torrent-magnet.cc:117:68: warning: comparison of integers of different signs: 'long' and 'const uint64_t' (aka 'const unsigned long') [clang-diagnostic-sign-compare] * refactor: pass log name to `tr_metadata_download` constructor * chore: iwyu * fix: thread-safe `TorrentMagnetTest.setMetadataPiece` * chore: housekeeping * Revert "fix: thread-safe `TorrentMagnetTest.setMetadataPiece`" This reverts commit 2a7fcd93a262888f9f55d542b1a9a2da9ca72cea. * fix: stop soon instead of stop now in `on_metainfo_completed()` This is unreachable code now, but if it is ever reached, Transmission will very likely crash. * fix: maybe fix OpenBSD test failure
2024-01-03 03:04:17 +00:00
[[nodiscard]] constexpr size_t get_piece_length(int64_t const piece) const noexcept
{
return piece + 1 == piece_count_ ? // last piece
std::size(metadata_) - (piece * MetadataPieceSize) :
MetadataPieceSize;
}
2009-11-24 17:10:40 +00:00
refactor: convert `tr_incomplete_metadata` to c++ class (#6383) * refactor: unset peer BEP-9 support if size hint is invalid * fix: open torrent file in binary mode * refactor: move metadata size check to method * refactor: remove duplicate checks * refactor: reduce temp variable scope in `parseLtepHandshake()` * refactor: convert `get_piece_length()` to method * refactor: convert `tr_torrentSetMetadataSizeHint()` to method * refactor: convert `tr_torrentGetMetadataPiece()` to method * refactor: convert `tr_torrentUseMetainfoFromFile()` to method * refactor: convert `tr_torrentSetMetadataPiece()` to method * refactor: convert `tr_torrentGetNextMetadataRequest()` to method * refactor: convert `tr_torrentGetMetadataPercent()` to method * refactor: add basic framework for MagnetMediator * refactor: initialise `tr_incomplete_metadata` fields in constructor * refactor: check metadata transfer completion in `set_metadata_piece()` * refactor: convert `use_new_metainfo()` and `on_have_all_metainfo()` to methods * refactor: move parts of `tr_torrent::set_metadata_piece()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_next_metadata_request()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_metadata_percent()` into `tr_incomplete_metadata` * refactor: hide all `tr_incomplete_metadata` fields * refactor: move `incomplete_metadata` to private * feat: add test for `set_metadata_piece()` * refactor: unify integer types * refactor: rename `tr_incomplete_metadata` to `tr_metadata_download` * chore: make clang-tidy happy libtransmission/torrent-magnet.cc:117:68: warning: comparison of integers of different signs: 'long' and 'const uint64_t' (aka 'const unsigned long') [clang-diagnostic-sign-compare] * refactor: pass log name to `tr_metadata_download` constructor * chore: iwyu * fix: thread-safe `TorrentMagnetTest.setMetadataPiece` * chore: housekeeping * Revert "fix: thread-safe `TorrentMagnetTest.setMetadataPiece`" This reverts commit 2a7fcd93a262888f9f55d542b1a9a2da9ca72cea. * fix: stop soon instead of stop now in `on_metainfo_completed()` This is unreachable code now, but if it is ever reached, Transmission will very likely crash. * fix: maybe fix OpenBSD test failure
2024-01-03 03:04:17 +00:00
void create_all_needed(int64_t n_pieces) noexcept;
refactor: convert `tr_incomplete_metadata` to c++ class (#6383) * refactor: unset peer BEP-9 support if size hint is invalid * fix: open torrent file in binary mode * refactor: move metadata size check to method * refactor: remove duplicate checks * refactor: reduce temp variable scope in `parseLtepHandshake()` * refactor: convert `get_piece_length()` to method * refactor: convert `tr_torrentSetMetadataSizeHint()` to method * refactor: convert `tr_torrentGetMetadataPiece()` to method * refactor: convert `tr_torrentUseMetainfoFromFile()` to method * refactor: convert `tr_torrentSetMetadataPiece()` to method * refactor: convert `tr_torrentGetNextMetadataRequest()` to method * refactor: convert `tr_torrentGetMetadataPercent()` to method * refactor: add basic framework for MagnetMediator * refactor: initialise `tr_incomplete_metadata` fields in constructor * refactor: check metadata transfer completion in `set_metadata_piece()` * refactor: convert `use_new_metainfo()` and `on_have_all_metainfo()` to methods * refactor: move parts of `tr_torrent::set_metadata_piece()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_next_metadata_request()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_metadata_percent()` into `tr_incomplete_metadata` * refactor: hide all `tr_incomplete_metadata` fields * refactor: move `incomplete_metadata` to private * feat: add test for `set_metadata_piece()` * refactor: unify integer types * refactor: rename `tr_incomplete_metadata` to `tr_metadata_download` * chore: make clang-tidy happy libtransmission/torrent-magnet.cc:117:68: warning: comparison of integers of different signs: 'long' and 'const uint64_t' (aka 'const unsigned long') [clang-diagnostic-sign-compare] * refactor: pass log name to `tr_metadata_download` constructor * chore: iwyu * fix: thread-safe `TorrentMagnetTest.setMetadataPiece` * chore: housekeeping * Revert "fix: thread-safe `TorrentMagnetTest.setMetadataPiece`" This reverts commit 2a7fcd93a262888f9f55d542b1a9a2da9ca72cea. * fix: stop soon instead of stop now in `on_metainfo_completed()` This is unreachable code now, but if it is ever reached, Transmission will very likely crash. * fix: maybe fix OpenBSD test failure
2024-01-03 03:04:17 +00:00
std::vector<char> metadata_;
std::deque<metadata_node> pieces_needed_;
int64_t piece_count_ = {};
refactor: convert `tr_incomplete_metadata` to c++ class (#6383) * refactor: unset peer BEP-9 support if size hint is invalid * fix: open torrent file in binary mode * refactor: move metadata size check to method * refactor: remove duplicate checks * refactor: reduce temp variable scope in `parseLtepHandshake()` * refactor: convert `get_piece_length()` to method * refactor: convert `tr_torrentSetMetadataSizeHint()` to method * refactor: convert `tr_torrentGetMetadataPiece()` to method * refactor: convert `tr_torrentUseMetainfoFromFile()` to method * refactor: convert `tr_torrentSetMetadataPiece()` to method * refactor: convert `tr_torrentGetNextMetadataRequest()` to method * refactor: convert `tr_torrentGetMetadataPercent()` to method * refactor: add basic framework for MagnetMediator * refactor: initialise `tr_incomplete_metadata` fields in constructor * refactor: check metadata transfer completion in `set_metadata_piece()` * refactor: convert `use_new_metainfo()` and `on_have_all_metainfo()` to methods * refactor: move parts of `tr_torrent::set_metadata_piece()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_next_metadata_request()` into `tr_incomplete_metadata` * refactor: move parts of `tr_torrent::get_metadata_percent()` into `tr_incomplete_metadata` * refactor: hide all `tr_incomplete_metadata` fields * refactor: move `incomplete_metadata` to private * feat: add test for `set_metadata_piece()` * refactor: unify integer types * refactor: rename `tr_incomplete_metadata` to `tr_metadata_download` * chore: make clang-tidy happy libtransmission/torrent-magnet.cc:117:68: warning: comparison of integers of different signs: 'long' and 'const uint64_t' (aka 'const unsigned long') [clang-diagnostic-sign-compare] * refactor: pass log name to `tr_metadata_download` constructor * chore: iwyu * fix: thread-safe `TorrentMagnetTest.setMetadataPiece` * chore: housekeeping * Revert "fix: thread-safe `TorrentMagnetTest.setMetadataPiece`" This reverts commit 2a7fcd93a262888f9f55d542b1a9a2da9ca72cea. * fix: stop soon instead of stop now in `on_metainfo_completed()` This is unreachable code now, but if it is ever reached, Transmission will very likely crash. * fix: maybe fix OpenBSD test failure
2024-01-03 03:04:17 +00:00
std::string log_name_;
};