2023-02-11 20:49:42 +00:00
|
|
|
// This file Copyright © 2008-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.
|
2008-03-29 18:37:07 +00:00
|
|
|
|
2017-11-14 20:21:28 +00:00
|
|
|
#pragma once
|
|
|
|
|
2008-11-24 20:17:36 +00:00
|
|
|
#ifndef __TRANSMISSION__
|
2017-04-19 12:04:45 +00:00
|
|
|
#error only libtransmission should #include this header.
|
2008-11-24 20:17:36 +00:00
|
|
|
#endif
|
|
|
|
|
2022-11-03 20:46:27 +00:00
|
|
|
#include <optional>
|
2022-05-15 16:32:22 +00:00
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
2022-11-03 20:46:27 +00:00
|
|
|
#include <utility> // for std::pair
|
2022-05-15 16:32:22 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2022-11-03 20:46:27 +00:00
|
|
|
#include "net.h" // for tr_address
|
2022-05-15 16:32:22 +00:00
|
|
|
|
2008-12-02 03:41:58 +00:00
|
|
|
struct tr_address;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2022-11-03 20:46:27 +00:00
|
|
|
namespace libtransmission
|
|
|
|
{
|
|
|
|
|
|
|
|
class Blocklist
|
2022-05-15 16:32:22 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-11-03 20:46:27 +00:00
|
|
|
[[nodiscard]] static std::vector<Blocklist> loadBlocklists(std::string_view const blocklist_dir, bool const is_enabled);
|
2022-05-15 16:32:22 +00:00
|
|
|
|
2022-11-03 20:46:27 +00:00
|
|
|
static std::optional<Blocklist> saveNew(std::string_view external_file, std::string_view bin_file, bool is_enabled);
|
2022-05-15 16:32:22 +00:00
|
|
|
|
2022-11-03 20:46:27 +00:00
|
|
|
Blocklist() = default;
|
2022-05-15 16:32:22 +00:00
|
|
|
|
2022-11-03 20:46:27 +00:00
|
|
|
Blocklist(std::string_view bin_file, bool is_enabled)
|
|
|
|
: bin_file_{ bin_file }
|
|
|
|
, is_enabled_{ is_enabled }
|
2022-05-15 16:32:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-11-03 20:46:27 +00:00
|
|
|
[[nodiscard]] bool contains(tr_address const& addr) const;
|
|
|
|
|
|
|
|
[[nodiscard]] auto size() const
|
2022-05-15 16:32:22 +00:00
|
|
|
{
|
|
|
|
ensureLoaded();
|
|
|
|
|
2022-08-27 19:05:21 +00:00
|
|
|
return std::size(rules_);
|
2022-05-15 16:32:22 +00:00
|
|
|
}
|
|
|
|
|
2022-11-03 20:46:27 +00:00
|
|
|
[[nodiscard]] constexpr bool enabled() const noexcept
|
2022-05-15 16:32:22 +00:00
|
|
|
{
|
|
|
|
return is_enabled_;
|
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2022-11-03 20:46:27 +00:00
|
|
|
void setEnabled(bool is_enabled) noexcept
|
2022-05-15 16:32:22 +00:00
|
|
|
{
|
2022-11-03 20:46:27 +00:00
|
|
|
is_enabled_ = is_enabled;
|
2022-05-15 16:32:22 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2022-11-03 20:46:27 +00:00
|
|
|
[[nodiscard]] constexpr auto const& binFile() const noexcept
|
|
|
|
{
|
|
|
|
return bin_file_;
|
|
|
|
}
|
2022-09-30 23:29:26 +00:00
|
|
|
|
2022-05-15 16:32:22 +00:00
|
|
|
private:
|
2022-08-27 19:05:21 +00:00
|
|
|
void ensureLoaded() const;
|
2022-05-15 16:32:22 +00:00
|
|
|
|
2022-11-03 20:46:27 +00:00
|
|
|
mutable std::vector<std::pair<tr_address, tr_address>> rules_;
|
2008-03-29 18:37:07 +00:00
|
|
|
|
2022-11-03 20:46:27 +00:00
|
|
|
std::string bin_file_;
|
2022-08-27 19:05:21 +00:00
|
|
|
bool is_enabled_ = false;
|
2022-05-15 16:32:22 +00:00
|
|
|
};
|
2022-11-03 20:46:27 +00:00
|
|
|
|
|
|
|
} // namespace libtransmission
|