refactoring
This commit is contained in:
@@ -112,6 +112,9 @@ private:
|
||||
template <typename dest>
|
||||
auto get_value(const json &json_document, const std::string &name, dest &dst,
|
||||
bool &success_flag) -> bool {
|
||||
constexpr const auto *function_name =
|
||||
static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
auto ret = false;
|
||||
try {
|
||||
if (json_document.find(name) != json_document.end()) {
|
||||
@@ -121,7 +124,7 @@ private:
|
||||
success_flag = false;
|
||||
}
|
||||
} catch (const json::exception &ex) {
|
||||
utils::error::raise_error(__FUNCTION__, ex, "exception occurred");
|
||||
utils::error::raise_error(function_name, ex, "exception occurred");
|
||||
success_flag = false;
|
||||
ret = false;
|
||||
}
|
||||
|
@@ -30,8 +30,7 @@ namespace repertory {
|
||||
class packet_client final {
|
||||
private:
|
||||
struct client final {
|
||||
explicit client(boost::asio::io_context &ctx) : nonce(""), socket(ctx) {}
|
||||
|
||||
explicit client(boost::asio::io_context &ctx) : socket(ctx) {}
|
||||
std::string nonce;
|
||||
tcp::socket socket;
|
||||
};
|
||||
@@ -43,34 +42,40 @@ public:
|
||||
|
||||
~packet_client();
|
||||
|
||||
packet_client(const packet_client &) = delete;
|
||||
packet_client(packet_client &&) = delete;
|
||||
auto operator=(const packet_client &) -> packet_client & = delete;
|
||||
auto operator=(packet_client &&) -> packet_client & = delete;
|
||||
|
||||
private:
|
||||
boost::asio::io_context io_context_;
|
||||
const std::string host_name_or_ip_;
|
||||
const std::uint8_t max_connections_;
|
||||
const std::uint16_t port_;
|
||||
const std::uint16_t receive_timeout_;
|
||||
const std::uint16_t send_timeout_;
|
||||
const std::string encryption_token_;
|
||||
std::string host_name_or_ip_;
|
||||
std::uint8_t max_connections_;
|
||||
std::uint16_t port_;
|
||||
std::uint16_t receive_timeout_;
|
||||
std::uint16_t send_timeout_;
|
||||
std::string encryption_token_;
|
||||
std::string unique_id_;
|
||||
|
||||
bool allow_connections_ = true;
|
||||
private:
|
||||
bool allow_connections_{true};
|
||||
boost::asio::ip::basic_resolver<boost::asio::ip::tcp>::results_type
|
||||
resolve_results_;
|
||||
std::mutex clients_mutex_;
|
||||
std::vector<std::shared_ptr<client>> clients_;
|
||||
|
||||
private:
|
||||
void close(client &c) const;
|
||||
static void close(client &cli);
|
||||
|
||||
void close_all();
|
||||
|
||||
void connect(client &c);
|
||||
void connect(client &cli);
|
||||
|
||||
[[nodiscard]] auto get_client() -> std::shared_ptr<client>;
|
||||
|
||||
void put_client(std::shared_ptr<client> &c);
|
||||
void put_client(std::shared_ptr<client> &cli);
|
||||
|
||||
[[nodiscard]] auto read_packet(client &c, packet &response)
|
||||
[[nodiscard]] auto read_packet(client &cli, packet &response)
|
||||
-> packet::error_type;
|
||||
|
||||
void resolve();
|
||||
|
@@ -45,6 +45,12 @@ public:
|
||||
|
||||
~packet_server();
|
||||
|
||||
public:
|
||||
packet_server(const packet_server &) = delete;
|
||||
packet_server(packet_server &&) = delete;
|
||||
auto operator=(const packet_server &) -> packet_server & = delete;
|
||||
auto operator=(packet_server &&) -> packet_server & = delete;
|
||||
|
||||
private:
|
||||
struct connection {
|
||||
connection(boost::asio::io_service &io_service, tcp::acceptor &acceptor_)
|
||||
@@ -56,11 +62,11 @@ private:
|
||||
std::string client_id;
|
||||
std::string nonce;
|
||||
|
||||
void generate_nonce() { nonce = utils::generate_random_string(256u); }
|
||||
void generate_nonce() { nonce = utils::generate_random_string(256U); }
|
||||
};
|
||||
|
||||
private:
|
||||
const std::string encryption_token_;
|
||||
std::string encryption_token_;
|
||||
closed_callback closed_;
|
||||
message_handler_callback message_handler_;
|
||||
boost::asio::io_context io_context_;
|
||||
@@ -70,21 +76,22 @@ private:
|
||||
std::unordered_map<std::string, std::uint32_t> connection_lookup_;
|
||||
|
||||
private:
|
||||
void add_client(connection &c, const std::string &client_id);
|
||||
void add_client(connection &conn, const std::string &client_id);
|
||||
|
||||
void initialize(const uint16_t &port, uint8_t pool_size);
|
||||
|
||||
void listen_for_connection(tcp::acceptor &acceptor);
|
||||
|
||||
void on_accept(std::shared_ptr<connection> c, boost::system::error_code ec);
|
||||
void on_accept(std::shared_ptr<connection> conn,
|
||||
boost::system::error_code err);
|
||||
|
||||
void read_header(std::shared_ptr<connection> c);
|
||||
void read_header(std::shared_ptr<connection> conn);
|
||||
|
||||
void read_packet(std::shared_ptr<connection> c, std::uint32_t data_size);
|
||||
void read_packet(std::shared_ptr<connection> conn, std::uint32_t data_size);
|
||||
|
||||
void remove_client(connection &c);
|
||||
void remove_client(connection &conn);
|
||||
|
||||
void send_response(std::shared_ptr<connection> c,
|
||||
void send_response(std::shared_ptr<connection> conn,
|
||||
const packet::error_type &result, packet &response);
|
||||
};
|
||||
} // namespace repertory
|
||||
|
@@ -161,8 +161,11 @@ public:
|
||||
template <typename context_t> struct db_result final {
|
||||
db_result(std::shared_ptr<context_t> context, std::int32_t res)
|
||||
: context_(std::move(context)), res_(res) {
|
||||
constexpr const auto *function_name =
|
||||
static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
if (res == SQLITE_OK) {
|
||||
set_res(sqlite3_step(context_->stmt.get()), __FUNCTION__);
|
||||
set_res(sqlite3_step(context_->stmt.get()), function_name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,10 +196,13 @@ public:
|
||||
|
||||
[[nodiscard]] auto get_row(std::optional<db_row<context_t>> &row) const
|
||||
-> bool {
|
||||
constexpr const auto *function_name =
|
||||
static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
row.reset();
|
||||
if (has_row()) {
|
||||
row = db_row{context_};
|
||||
set_res(sqlite3_step(context_->stmt.get()), __FUNCTION__);
|
||||
set_res(sqlite3_step(context_->stmt.get()), function_name);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -205,8 +211,11 @@ public:
|
||||
[[nodiscard]] auto has_row() const -> bool { return res_ == SQLITE_ROW; }
|
||||
|
||||
void next_row() const {
|
||||
constexpr const auto *function_name =
|
||||
static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
if (has_row()) {
|
||||
set_res(sqlite3_step(context_->stmt.get()), __FUNCTION__);
|
||||
set_res(sqlite3_step(context_->stmt.get()), function_name);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@@ -54,7 +54,7 @@ private:
|
||||
const UINT32 &attributes,
|
||||
remote::file_info &file_info);
|
||||
|
||||
static void populate_stat(const struct stat64 &st1, remote::stat &st);
|
||||
static void populate_stat(const struct stat64 &unix_st, remote::stat &r_stat);
|
||||
|
||||
[[nodiscard]] auto update_to_windows_format(json &item) -> json &;
|
||||
|
||||
@@ -88,7 +88,7 @@ public:
|
||||
remote::file_offset &length, const remote::file_handle &handle) override
|
||||
;*/
|
||||
|
||||
[[nodiscard]] auto fuse_fgetattr(const char *path, remote::stat &st,
|
||||
[[nodiscard]] auto fuse_fgetattr(const char *path, remote::stat &r_stat,
|
||||
bool &directory,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
@@ -107,7 +107,7 @@ public:
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
[[nodiscard]] auto fuse_getattr(const char *path, remote::stat &st,
|
||||
[[nodiscard]] auto fuse_getattr(const char *path, remote::stat &r_stat,
|
||||
bool &directory)
|
||||
-> packet::error_type override;
|
||||
|
||||
@@ -196,11 +196,11 @@ public:
|
||||
std::int32_t &flags, std::uint32_t position) override ;*/
|
||||
|
||||
[[nodiscard]] auto fuse_statfs(const char *path, std::uint64_t frsize,
|
||||
remote::statfs &st)
|
||||
remote::statfs &r_stat)
|
||||
-> packet::error_type override;
|
||||
|
||||
[[nodiscard]] auto fuse_statfs_x(const char *path, std::uint64_t bsize,
|
||||
remote::statfs_x &st)
|
||||
remote::statfs_x &r_stat)
|
||||
-> packet::error_type override;
|
||||
|
||||
[[nodiscard]] auto fuse_truncate(const char *path,
|
||||
|
@@ -23,6 +23,8 @@
|
||||
#define INCLUDE_TYPES_REPERTORY_HPP_
|
||||
|
||||
namespace repertory {
|
||||
constexpr const auto max_time = 0xFFFFFFFFFFFFFFFFULL;
|
||||
|
||||
const std::string META_ACCESSED = "accessed";
|
||||
const std::string META_ATTRIBUTES = "attributes";
|
||||
const std::string META_BACKUP = "backup";
|
||||
|
Reference in New Issue
Block a user