fix remote server

This commit is contained in:
2025-10-01 20:41:34 -05:00
parent 8dbb0d9fd9
commit 4bee40228d
7 changed files with 430 additions and 438 deletions

View File

@@ -97,11 +97,11 @@ private:
static constexpr auto min_pool_size = 10U; static constexpr auto min_pool_size = 10U;
public: public:
void execute(std::string_view client_id, std::uint64_t thread_id, void execute(std::string client_id, std::uint64_t thread_id,
const worker_callback &worker, const worker_callback &worker,
const worker_complete_callback &worker_complete); const worker_complete_callback &worker_complete);
void remove_client(std::string_view client_id); void remove_client(std::string client_id);
void shutdown(); void shutdown();
}; };

View File

@@ -122,8 +122,8 @@ auto run_with_deadline(boost::asio::io_context &ctx,
} }
state_ptr->timer.cancel(); state_ptr->timer.cancel();
while (ctx.poll_one() > 0) { // while (ctx.poll_one() > 0) {
} // }
state_ptr->work_guard.reset(); state_ptr->work_guard.reset();

View File

@@ -32,11 +32,11 @@ using boost::asio::ip::tcp;
namespace repertory { namespace repertory {
class packet_server final { class packet_server final {
public: public:
using closed_callback = std::function<void(std::string_view)>; using closed_callback = std::function<void(std::string)>;
using message_complete_callback = client_pool::worker_complete_callback; using message_complete_callback = client_pool::worker_complete_callback;
using message_handler_callback = std::function<void( using message_handler_callback =
std::uint32_t, std::string_view, std::uint64_t, std::string_view, std::function<void(std::uint32_t, std::string, std::uint64_t, std::string,
packet *, packet &, message_complete_callback)>; packet *, packet &, message_complete_callback)>;
public: public:
packet_server(std::uint16_t port, std::string token, std::uint8_t pool_size, packet_server(std::uint16_t port, std::string token, std::uint8_t pool_size,
@@ -78,7 +78,7 @@ private:
std::unordered_map<std::string, std::uint32_t> connection_lookup_; std::unordered_map<std::string, std::uint32_t> connection_lookup_;
private: private:
void add_client(connection &conn, std::string_view client_id); void add_client(connection &conn, std::string client_id);
[[nodiscard]] auto handshake(std::shared_ptr<connection> conn) const -> bool; [[nodiscard]] auto handshake(std::shared_ptr<connection> conn) const -> bool;

View File

@@ -46,8 +46,8 @@ class remote_server_base : public remote_open_file_table,
public virtual remote_fuse::i_remote_instance { public virtual remote_fuse::i_remote_instance {
public: public:
using handler_callback = std::function<packet::error_type( using handler_callback = std::function<packet::error_type(
std::uint32_t, std::string_view, std::uint64_t, std::string_view, std::uint32_t, std::string, std::uint64_t, std::string, packet *,
packet *, packet &)>; packet &)>;
public: public:
remote_server_base(const remote_server_base &) = delete; remote_server_base(const remote_server_base &) = delete;
@@ -103,463 +103,461 @@ private:
std::unique_ptr<packet_server> packet_server_; std::unique_ptr<packet_server> packet_server_;
private: private:
const std::unordered_map<std::string_view, handler_callback> handler_lookup_ = const std::unordered_map<std::string, handler_callback> handler_lookup_ = {
{ {
{ "::check",
"::check", [this](auto && /* service_flags */, auto && /* client_id */,
[this](auto && /* service_flags */, auto && /* client_id */, auto && /* thread_id */, auto && /* method */,
auto && /* thread_id */, auto && /* method */, auto && /* request */,
auto && /* request */, auto && /* response */) -> auto { return 0; },
auto && /* response */) -> auto { return 0; }, },
{
"::fuse_access",
[this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto &&request,
auto && /* response */) -> auto {
return this->handle_fuse_access(request);
}, },
{ },
"::fuse_access", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_chflags",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_access(request); auto && /* response */) -> auto {
}, return this->handle_fuse_chflags(request);
}, },
{ },
"::fuse_chflags", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_chmod",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_chflags(request); auto && /* response */) -> auto {
}, return this->handle_fuse_chmod(request);
}, },
{ },
"::fuse_chmod", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_chown",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_chmod(request); auto && /* response */) -> auto {
}, return this->handle_fuse_chown(request);
}, },
{ },
"::fuse_chown", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_create",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto &&client_id,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_chown(request); auto &&response) -> auto {
}, return this->handle_fuse_create(client_id, request, response);
}, },
{ },
"::fuse_create", {
[this](auto && /* service_flags */, auto &&client_id, "::fuse_destroy",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */,
return this->handle_fuse_create(client_id, request, response); auto && /* request */, auto && /* response */) -> auto {
}, return this->handle_fuse_destroy();
}, },
{ },
"::fuse_destroy", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_fgetattr",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* request */, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_destroy(); auto &&response) -> auto {
}, return this->handle_fuse_fgetattr(request, response);
}, },
{ },
"::fuse_fgetattr", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_fsetattr_x",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_fgetattr(request, response); auto && /* response */) -> auto {
}, return this->handle_fuse_fsetattr_x(request);
}, },
{ },
"::fuse_fsetattr_x", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_fsync",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_fsetattr_x(request); auto && /* response */) -> auto {
}, return this->handle_fuse_fsync(request);
}, },
{ },
"::fuse_fsync", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_ftruncate",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_fsync(request); auto && /* response */) -> auto {
}, return this->handle_fuse_ftruncate(request);
}, },
{ },
"::fuse_ftruncate", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_getattr",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_ftruncate(request); auto &&response) -> auto {
}, return this->handle_fuse_getattr(request, response);
}, },
{ },
"::fuse_getattr", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_getxtimes",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_getattr(request, response); auto &&response) -> auto {
}, return this->handle_fuse_getxtimes(request, response);
}, },
{ },
"::fuse_getxtimes", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_init",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */,
return this->handle_fuse_getxtimes(request, response); auto && /* request */, auto && /* response */) -> auto {
}, return this->handle_fuse_init();
}, },
{ },
"::fuse_init", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_mkdir",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* request */, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_init(); auto && /* response */) -> auto {
}, return this->handle_fuse_mkdir(request);
}, },
{ },
"::fuse_mkdir", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_open",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto &&client_id,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_mkdir(request); auto &&response) -> auto {
}, return this->handle_fuse_open(client_id, request, response);
}, },
{ },
"::fuse_open", {
[this](auto && /* service_flags */, auto &&client_id, "::fuse_opendir",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto &&client_id,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_open(client_id, request, response); auto &&response) -> auto {
}, return this->handle_fuse_opendir(client_id, request, response);
}, },
{ },
"::fuse_opendir", {
[this](auto && /* service_flags */, auto &&client_id, "::fuse_read",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_opendir(client_id, request, response); auto &&response) -> auto {
}, return this->handle_fuse_read(request, response);
}, },
{ },
"::fuse_read", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_readdir",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto &&client_id,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_read(request, response); auto &&response) -> auto {
}, return this->handle_fuse_readdir(client_id, request, response);
}, },
{ },
"::fuse_readdir", {
[this](auto && /* service_flags */, auto &&client_id, "::fuse_release",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_readdir(client_id, request, response); auto && /* response */) -> auto {
}, return this->handle_fuse_release(request);
}, },
{ },
"::fuse_release", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_releasedir",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto &&client_id,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_release(request); auto && /* response */) -> auto {
}, return this->handle_fuse_releasedir(client_id, request);
}, },
{ },
"::fuse_releasedir", {
[this](auto && /* service_flags */, auto &&client_id, "::fuse_rename",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_releasedir(client_id, request); auto && /* response */) -> auto {
}, return this->handle_fuse_rename(request);
}, },
{ },
"::fuse_rename", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_rmdir",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_rename(request); auto && /* response */) -> auto {
}, return this->handle_fuse_rmdir(request);
}, },
{ },
"::fuse_rmdir", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_setattr_x",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_rmdir(request); auto && /* response */) -> auto {
}, return this->handle_fuse_setattr_x(request);
}, },
{ },
"::fuse_setattr_x", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_setbkuptime",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_setattr_x(request); auto && /* response */) -> auto {
}, return this->handle_fuse_setbkuptime(request);
}, },
{ },
"::fuse_setbkuptime", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_setchgtime",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_setbkuptime(request); auto && /* response */) -> auto {
}, return this->handle_fuse_setchgtime(request);
}, },
{ },
"::fuse_setchgtime", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_setcrtime",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_setchgtime(request); auto && /* response */) -> auto {
}, return this->handle_fuse_setcrtime(request);
}, },
{ },
"::fuse_setcrtime", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_setvolname",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_setcrtime(request); auto && /* response */) -> auto {
}, return this->handle_fuse_setvolname(request);
}, },
{ },
"::fuse_setvolname", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_statfs",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_setvolname(request); auto &&response) -> auto {
}, return this->handle_fuse_statfs(request, response);
}, },
{ },
"::fuse_statfs", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_statfs_x",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_statfs(request, response); auto &&response) -> auto {
}, return this->handle_fuse_statfs_x(request, response);
}, },
{ },
"::fuse_statfs_x", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_truncate",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_statfs_x(request, response); auto && /* response */) -> auto {
}, return this->handle_fuse_truncate(request);
}, },
{ },
"::fuse_truncate", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_unlink",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_truncate(request); auto && /* response */) -> auto {
}, return this->handle_fuse_unlink(request);
}, },
{ },
"::fuse_unlink", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_utimens",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_unlink(request); auto && /* response */) -> auto {
}, return this->handle_fuse_utimens(request);
}, },
{ },
"::fuse_utimens", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_write",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_utimens(request); auto && /* response */) -> auto {
}, return this->handle_fuse_write(request);
}, },
{ },
"::fuse_write", {
[this](auto && /* service_flags */, auto && /* client_id */, "::fuse_write_base64",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_write(request); auto && /* response */) -> auto {
}, return this->handle_fuse_write_base64(request);
}, },
{ },
"::fuse_write_base64", {
[this](auto && /* service_flags */, auto && /* client_id */, "::json_create_directory_snapshot",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto &&client_id,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_fuse_write_base64(request); auto &&response) -> auto {
}, return this->handle_json_create_directory_snapshot(
client_id, request, response);
}, },
{ },
"::json_create_directory_snapshot", {
[this](auto && /* service_flags */, auto &&client_id, "::json_read_directory_snapshot",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto &&client_id,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_json_create_directory_snapshot( auto &&response) -> auto {
client_id, request, response); return this->handle_json_read_directory_snapshot(client_id, request,
}, response);
}, },
{ },
"::json_read_directory_snapshot", {
[this](auto && /* service_flags */, auto &&client_id, "::json_release_directory_snapshot",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto &&client_id,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_json_read_directory_snapshot( auto && /* response */) -> auto {
client_id, request, response); return this->handle_json_release_directory_snapshot(client_id,
}, request);
}, },
{ },
"::json_release_directory_snapshot", {
[this](auto && /* service_flags */, auto &&client_id, "::winfsp_can_delete",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_json_release_directory_snapshot(client_id, auto && /* response */) -> auto {
request); return this->handle_winfsp_can_delete(request);
},
}, },
{ },
"::winfsp_can_delete", {
[this](auto && /* service_flags */, auto && /* client_id */, "::winfsp_cleanup",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_winfsp_can_delete(request); auto &&response) -> auto {
}, return this->handle_winfsp_cleanup(request, response);
}, },
{ },
"::winfsp_cleanup", {
[this](auto && /* service_flags */, auto && /* client_id */, "::winfsp_close",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_winfsp_cleanup(request, response); auto && /* response */) -> auto {
}, return this->handle_winfsp_close(request);
}, },
{ },
"::winfsp_close", {
[this](auto && /* service_flags */, auto && /* client_id */, "::winfsp_create",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto &&client_id,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_winfsp_close(request); auto &&response) -> auto {
}, return this->handle_winfsp_create(client_id, request, response);
}, },
{ },
"::winfsp_create", {
[this](auto && /* service_flags */, auto &&client_id, "::winfsp_flush",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_winfsp_create(client_id, request, response); auto &&response) -> auto {
}, return this->handle_winfsp_flush(request, response);
}, },
{ },
"::winfsp_flush", {
[this](auto && /* service_flags */, auto && /* client_id */, "::winfsp_get_file_info",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_winfsp_flush(request, response); auto &&response) -> auto {
}, return this->handle_winfsp_get_file_info(request, response);
}, },
{ },
"::winfsp_get_file_info", {
[this](auto && /* service_flags */, auto && /* client_id */, "::winfsp_get_security_by_name",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_winfsp_get_file_info(request, response); auto &&response) -> auto {
}, return this->handle_winfsp_get_security_by_name(request, response);
}, },
{ },
"::winfsp_get_security_by_name", {
[this](auto && /* service_flags */, auto && /* client_id */, "::winfsp_get_volume_info",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */,
return this->handle_winfsp_get_security_by_name(request, auto && /* request */, auto &&response) -> auto {
response); return this->handle_winfsp_get_volume_info(response);
},
}, },
{ },
"::winfsp_get_volume_info", {
[this](auto && /* service_flags */, auto && /* client_id */, "::winfsp_mounted",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* request */, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_winfsp_get_volume_info(response); auto && /* response */) -> auto {
}, return this->handle_winfsp_mounted(request);
}, },
{ },
"::winfsp_mounted", {
[this](auto && /* service_flags */, auto && /* client_id */, "::winfsp_open",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto &&client_id,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_winfsp_mounted(request); auto &&response) -> auto {
}, return this->handle_winfsp_open(client_id, request, response);
}, },
{ },
"::winfsp_open", {
[this](auto && /* service_flags */, auto &&client_id, "::winfsp_overwrite",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_winfsp_open(client_id, request, response); auto &&response) -> auto {
}, return this->handle_winfsp_overwrite(request, response);
}, },
{ },
"::winfsp_overwrite", {
[this](auto && /* service_flags */, auto && /* client_id */, "::winfsp_read",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_winfsp_overwrite(request, response); auto &&response) -> auto {
}, return this->handle_winfsp_read(request, response);
}, },
{ },
"::winfsp_read", {
[this](auto && /* service_flags */, auto && /* client_id */, "::winfsp_read_directory",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_winfsp_read(request, response); auto &&response) -> auto {
}, return this->handle_winfsp_read_directory(request, response);
}, },
{ },
"::winfsp_read_directory", {
[this](auto && /* service_flags */, auto && /* client_id */, "::winfsp_rename",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_winfsp_read_directory(request, response); auto && /* response */) -> auto {
}, return this->handle_winfsp_rename(request);
}, },
{ },
"::winfsp_rename", {
[this](auto && /* service_flags */, auto && /* client_id */, "::winfsp_set_basic_info",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_winfsp_rename(request); auto &&response) -> auto {
}, return this->handle_winfsp_set_basic_info(request, response);
}, },
{ },
"::winfsp_set_basic_info", {
[this](auto && /* service_flags */, auto && /* client_id */, "::winfsp_set_file_size",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_winfsp_set_basic_info(request, response); auto &&response) -> auto {
}, return this->handle_winfsp_set_file_size(request, response);
}, },
{ },
"::winfsp_set_file_size", {
[this](auto && /* service_flags */, auto && /* client_id */, "::winfsp_unmounted",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto &&response) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_winfsp_set_file_size(request, response); auto && /* response */) -> auto {
}, return this->handle_winfsp_unmounted(request);
}, },
{ },
"::winfsp_unmounted", {
[this](auto && /* service_flags */, auto && /* client_id */, "::winfsp_write",
auto && /* thread_id */, auto && /* method */, [this](auto && /* service_flags */, auto && /* client_id */,
auto &&request, auto && /* response */) -> auto { auto && /* thread_id */, auto && /* method */, auto &&request,
return this->handle_winfsp_unmounted(request); auto &&response) -> auto {
}, return this->handle_winfsp_write(request, response);
}, },
{ },
"::winfsp_write", };
[this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */,
auto &&request, auto &&response) -> auto {
return this->handle_winfsp_write(request, response);
},
},
};
private: private:
void closed_handler(std::string_view client_id) { void closed_handler(std::string client_id) {
client_pool_.remove_client(client_id); client_pool_.remove_client(client_id);
close_all(client_id); close_all(client_id);
} }
@@ -1615,14 +1613,13 @@ private:
} }
void void
message_handler(std::uint32_t service_flags, std::string_view client_id, message_handler(std::uint32_t service_flags, std::string client_id,
std::uint64_t thread_id, std::string_view method, std::uint64_t thread_id, std::string method, packet *request,
packet *request, packet &response, packet &response,
packet_server::message_complete_callback message_complete) { packet_server::message_complete_callback message_complete) {
auto idx{method.find_last_of("::")}; auto idx{method.find_last_of("::")};
auto lookup_method_name{ auto lookup_method_name{
((idx == std::string::npos) ? "::" + std::string{method} ((idx == std::string::npos) ? "::" + method : method.substr(idx - 1)),
: method.substr(idx - 1)),
}; };
if (handler_lookup_.find(lookup_method_name) == handler_lookup_.end()) { if (handler_lookup_.find(lookup_method_name) == handler_lookup_.end()) {
message_complete(static_cast<packet::error_type>(STATUS_NOT_IMPLEMENTED)); message_complete(static_cast<packet::error_type>(STATUS_NOT_IMPLEMENTED));

View File

@@ -130,7 +130,7 @@ void client_pool::pool::shutdown() {
pool_threads_.clear(); pool_threads_.clear();
} }
void client_pool::execute(std::string_view client_id, std::uint64_t thread_id, void client_pool::execute(std::string client_id, std::uint64_t thread_id,
const worker_callback &worker, const worker_callback &worker,
const worker_complete_callback &worker_complete) { const worker_complete_callback &worker_complete) {
unique_mutex_lock pool_lock(pool_mutex_); unique_mutex_lock pool_lock(pool_mutex_);
@@ -139,18 +139,17 @@ void client_pool::execute(std::string_view client_id, std::uint64_t thread_id,
throw std::runtime_error("Client pool is shutdown"); throw std::runtime_error("Client pool is shutdown");
} }
auto str_id = std::string{client_id}; if (not pool_lookup_[client_id]) {
if (not pool_lookup_[str_id]) { pool_lookup_[client_id] = std::make_shared<pool>(pool_size_);
pool_lookup_[str_id] = std::make_shared<pool>(pool_size_);
} }
pool_lookup_[str_id]->execute(thread_id, worker, worker_complete); pool_lookup_[client_id]->execute(thread_id, worker, worker_complete);
pool_lock.unlock(); pool_lock.unlock();
} }
void client_pool::remove_client(std::string_view client_id) { void client_pool::remove_client(std::string client_id) {
mutex_lock pool_lock(pool_mutex_); mutex_lock pool_lock(pool_mutex_);
pool_lookup_.erase(std::string{client_id}); pool_lookup_.erase(client_id);
} }
void client_pool::shutdown() { void client_pool::shutdown() {

View File

@@ -72,15 +72,14 @@ packet_server::~packet_server() {
"packet_server"); "packet_server");
} }
void packet_server::add_client(connection &conn, std::string_view client_id) { void packet_server::add_client(connection &conn, std::string client_id) {
conn.client_id = client_id; conn.client_id = client_id;
recur_mutex_lock connection_lock(connection_mutex_); recur_mutex_lock connection_lock(connection_mutex_);
auto str_id = std::string{client_id}; if (connection_lookup_.contains(client_id)) {
if (connection_lookup_.contains(str_id)) { connection_lookup_.at(client_id)++;
connection_lookup_.at(str_id)++;
} else { } else {
connection_lookup_[str_id] = 1U; connection_lookup_[client_id] = 1U;
} }
} }

View File

@@ -38,12 +38,10 @@ public:
test_packet_server(std::uint16_t port, std::string token, test_packet_server(std::uint16_t port, std::string token,
std::uint8_t pool_size = 2) std::uint8_t pool_size = 2)
: server_(std::make_unique<packet_server>( : server_(std::make_unique<packet_server>(
port, std::move(token), pool_size, port, std::move(token), pool_size, [](std::string /*client_id*/) {},
[](std::string_view /*client_id*/) {}, [](std::uint32_t /*service_flags_in*/, std::string /*client_id*/,
[](std::uint32_t /*service_flags_in*/, std::uint64_t /*thread_id*/, std::string method,
std::string_view /*client_id*/, std::uint64_t /*thread_id*/, packet * /*request*/, packet & /*response*/,
std::string_view method, packet * /*request*/,
packet & /*response*/,
packet_server::message_complete_callback done) { packet_server::message_complete_callback done) {
if (method == "ping") { if (method == "ping") {
done(packet::error_type{0}); done(packet::error_type{0});
@@ -132,11 +130,10 @@ TEST(packet_client_test, pooled_connection_reused_on_second_send) {
packet_server server{ packet_server server{
port, token, 2U, port, token, 2U,
[&close_count](std::string_view /*client_id*/) { ++close_count; }, [&close_count](std::string /*client_id*/) { ++close_count; },
[](std::uint32_t /*service_flags_in*/, std::string_view /*client_id*/, [](std::uint32_t /*service_flags_in*/, std::string /*client_id*/,
std::uint64_t /*thread_id*/, std::string_view method, std::uint64_t /*thread_id*/, std::string method, packet * /*request*/,
packet * /*request*/, packet & /*response*/, packet & /*response*/, packet_server::message_complete_callback done) {
packet_server::message_complete_callback done) {
if (method == "ping") { if (method == "ping") {
done(packet::error_type{0}); done(packet::error_type{0});
} else { } else {