2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2008-2022 Mnemosyne LLC.
|
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0), GPLv3 (SPDX: GPL-3.0),
|
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2008-05-18 16:44:30 +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-01-17 16:20:12 +00:00
|
|
|
#include <memory>
|
2021-11-14 21:14:37 +00:00
|
|
|
#include <string>
|
2021-11-14 06:02:45 +00:00
|
|
|
#include <string_view>
|
2022-04-22 13:08:02 +00:00
|
|
|
#include <vector>
|
2021-11-14 06:02:45 +00:00
|
|
|
|
|
|
|
#include "transmission.h"
|
|
|
|
|
|
|
|
#include "net.h"
|
|
|
|
|
2022-01-17 16:20:12 +00:00
|
|
|
struct event;
|
|
|
|
struct evhttp;
|
2021-11-09 03:30:03 +00:00
|
|
|
struct tr_variant;
|
2022-02-23 21:09:54 +00:00
|
|
|
struct tr_rpc_address;
|
2022-01-17 16:20:12 +00:00
|
|
|
struct libdeflate_compressor;
|
2008-05-18 16:44:30 +00:00
|
|
|
|
2021-11-14 21:14:37 +00:00
|
|
|
class tr_rpc_server
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
tr_rpc_server(tr_session* session, tr_variant* settings);
|
|
|
|
~tr_rpc_server();
|
|
|
|
|
2021-11-18 00:17:09 +00:00
|
|
|
tr_rpc_server(tr_rpc_server&) = delete;
|
|
|
|
tr_rpc_server(tr_rpc_server&&) = delete;
|
|
|
|
tr_rpc_server& operator=(tr_rpc_server&) = delete;
|
|
|
|
tr_rpc_server& operator=(tr_rpc_server&&) = delete;
|
|
|
|
|
2022-04-21 15:58:13 +00:00
|
|
|
[[nodiscard]] constexpr tr_port port() const noexcept
|
|
|
|
{
|
|
|
|
return port_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setPort(tr_port) noexcept;
|
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
[[nodiscard]] constexpr auto isEnabled() const noexcept
|
|
|
|
{
|
|
|
|
return is_enabled_;
|
|
|
|
}
|
2021-11-14 21:14:37 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
void setEnabled(bool is_enabled);
|
2021-11-14 21:14:37 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
[[nodiscard]] constexpr auto isWhitelistEnabled() const noexcept
|
|
|
|
{
|
|
|
|
return is_whitelist_enabled_;
|
|
|
|
}
|
2021-11-14 21:14:37 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
constexpr void setWhitelistEnabled(bool is_whitelist_enabled) noexcept
|
|
|
|
{
|
|
|
|
is_whitelist_enabled_ = is_whitelist_enabled;
|
|
|
|
}
|
2021-11-14 21:14:37 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
[[nodiscard]] constexpr auto const& whitelist() const noexcept
|
|
|
|
{
|
|
|
|
return whitelist_str_;
|
|
|
|
}
|
2008-05-18 16:44:30 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
void setWhitelist(std::string_view whitelist);
|
2008-05-18 16:44:30 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
[[nodiscard]] constexpr auto const& username() const noexcept
|
|
|
|
{
|
|
|
|
return username_;
|
|
|
|
}
|
2008-05-18 16:44:30 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
void setUsername(std::string_view username);
|
2008-05-18 16:44:30 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
[[nodiscard]] constexpr auto isPasswordEnabled() const noexcept
|
|
|
|
{
|
|
|
|
return is_password_enabled_;
|
|
|
|
}
|
2010-12-12 18:22:11 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
void setPasswordEnabled(bool enabled);
|
2010-12-12 18:22:11 +00:00
|
|
|
|
2022-04-22 16:35:56 +00:00
|
|
|
[[nodiscard]] constexpr auto const& getSaltedPassword() const noexcept
|
2022-04-22 14:19:20 +00:00
|
|
|
{
|
|
|
|
return salted_password_;
|
|
|
|
}
|
2008-06-04 17:14:58 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
void setPassword(std::string_view salted) noexcept;
|
2008-10-01 22:59:29 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
[[nodiscard]] constexpr auto isAntiBruteForceEnabled() const noexcept
|
|
|
|
{
|
|
|
|
return is_anti_brute_force_enabled_;
|
|
|
|
}
|
2008-10-01 22:59:29 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
void setAntiBruteForceEnabled(bool enabled) noexcept;
|
2018-01-11 18:00:41 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
[[nodiscard]] constexpr auto getAntiBruteForceLimit() const noexcept
|
|
|
|
{
|
|
|
|
return anti_brute_force_limit_;
|
|
|
|
}
|
2022-02-23 21:09:54 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
constexpr void setAntiBruteForceLimit(int limit) noexcept
|
|
|
|
{
|
|
|
|
anti_brute_force_limit_ = limit;
|
|
|
|
}
|
2018-01-11 18:00:41 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
std::shared_ptr<libdeflate_compressor> compressor;
|
2008-06-05 16:23:03 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
[[nodiscard]] constexpr auto const& url() const noexcept
|
|
|
|
{
|
|
|
|
return url_;
|
|
|
|
}
|
2008-06-05 16:23:03 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
void setUrl(std::string_view url);
|
2008-06-05 16:23:03 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
[[nodiscard]] std::string getBindAddress() const;
|
2008-06-05 16:23:03 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
[[nodiscard]] constexpr auto socketMode() const noexcept
|
|
|
|
{
|
|
|
|
return socket_mode_;
|
|
|
|
}
|
2008-06-05 16:23:03 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
std::vector<std::string> hostWhitelist;
|
|
|
|
std::vector<std::string> whitelist_;
|
|
|
|
std::string salted_password_;
|
|
|
|
std::string username_;
|
|
|
|
std::string whitelist_str_;
|
|
|
|
std::string url_;
|
2008-08-15 20:28:43 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
std::unique_ptr<struct tr_rpc_address> bindAddress;
|
2020-11-14 18:43:42 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
struct event* start_retry_timer = nullptr;
|
|
|
|
struct evhttp* httpd = nullptr;
|
|
|
|
tr_session* const session;
|
2020-11-14 18:43:42 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
int anti_brute_force_limit_ = 0;
|
|
|
|
int login_attempts_ = 0;
|
|
|
|
int start_retry_counter = 0;
|
|
|
|
static int constexpr DefaultRpcSocketMode = 0750;
|
|
|
|
int socket_mode_ = DefaultRpcSocketMode;
|
2020-11-14 18:43:42 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
tr_port port_;
|
2020-11-14 18:43:42 +00:00
|
|
|
|
2022-04-22 14:19:20 +00:00
|
|
|
bool is_anti_brute_force_enabled_ = false;
|
|
|
|
bool is_enabled_ = false;
|
|
|
|
bool isHostWhitelistEnabled = false;
|
|
|
|
bool is_password_enabled_ = false;
|
|
|
|
bool is_whitelist_enabled_ = false;
|
|
|
|
};
|