So yeah, while TorrentRead is not compulsory to use, right now it'd be pretty inconvenient to not use it as the hash grouping function is fidgety to get right. I think group_torrent_hashes() eventually should be moved elsewhere.
73 lines
2.5 KiB
C++
73 lines
2.5 KiB
C++
/* Copyright 2025, Michele "King_DuckZ" Santullo
|
|
* This file is part of ducktorrent.
|
|
*
|
|
* Ducktorrent is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Ducktorrent is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with ducktorrent. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
//This file contains higher level helpers that build on top of the parser and
|
|
//the visitors in parser.hpp and visitors/find_t_visitor.hpp. It is just here
|
|
//for convenience and it is not strictly required to read and parse bencoded
|
|
//data.
|
|
|
|
#include <vector>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <filesystem>
|
|
#include <ostream>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <array>
|
|
|
|
namespace duck {
|
|
struct TorrentValue;
|
|
|
|
class TorrentRead {
|
|
public:
|
|
TorrentRead (std::string_view torrent_path, std::filesystem::path workdir);
|
|
TorrentRead (const TorrentRead&) = delete;
|
|
~TorrentRead() noexcept;
|
|
|
|
void print (std::ostream& out) const;
|
|
std::size_t raw_data_size() const;
|
|
const std::vector<TorrentValue>& parsed_values() const;
|
|
|
|
std::string_view read_name() const;
|
|
std::size_t read_piece_length() const;
|
|
std::int_fast32_t read_file_count() const;
|
|
std::vector<std::string_view> read_file_path(std::size_t index) const;
|
|
std::string read_joint_file_path(std::size_t index, char sep) const;
|
|
std::size_t read_file_size(std::size_t index) const;
|
|
bool read_is_private() const;
|
|
std::string_view read_comment() const;
|
|
std::string_view read_hashes() const;
|
|
std::string_view read_created_by() const;
|
|
std::string_view read_announce() const;
|
|
std::time_t read_creation_date() const;
|
|
|
|
private:
|
|
const TorrentValue& cached_info_files() const;
|
|
|
|
std::filesystem::path m_workdir;
|
|
std::filesystem::path m_torrent_path;
|
|
std::string m_raw_torrent;
|
|
std::vector<TorrentValue> m_parsed_values;
|
|
|
|
mutable const TorrentValue* m_cached_info_files;
|
|
};
|
|
|
|
std::vector<std::array<std::uint32_t, 5>> group_torrent_hashes (std::string_view hashes);
|
|
std::vector<std::array<std::uint32_t, 5>> group_torrent_hashes (const TorrentRead& torrent);
|
|
} //namespace duck
|