added check version support to remote mounts

This commit is contained in:
2025-09-22 12:02:54 -05:00
parent 23f869f464
commit ec4d3022ac
2 changed files with 28 additions and 8 deletions

View File

@@ -71,11 +71,17 @@ private:
[[nodiscard]] auto handshake(client &cli, std::uint32_t &min_version) const [[nodiscard]] auto handshake(client &cli, std::uint32_t &min_version) const
-> bool; -> bool;
[[nodiscard]] auto handshake(client &cli, boost::asio::io_context &ctx,
std::uint32_t &min_version) const -> bool;
void put_client(std::shared_ptr<client> &cli); void put_client(std::shared_ptr<client> &cli);
[[nodiscard]] auto read_packet(client &cli, packet &response) const [[nodiscard]] auto read_packet(client &cli, packet &response) const
-> packet::error_type; -> packet::error_type;
[[nodiscard]] auto read_packet(client &cli, boost::asio::io_context &ctx,
packet &response) const -> packet::error_type;
void resolve(); void resolve();
public: public:

View File

@@ -98,10 +98,16 @@ auto packet_client::check_version(std::uint32_t client_version,
cli.socket.set_option(boost::asio::socket_base::linger(false, 0)); cli.socket.set_option(boost::asio::socket_base::linger(false, 0));
cli.socket.set_option(boost::asio::socket_base::keep_alive(true)); cli.socket.set_option(boost::asio::socket_base::keep_alive(true));
if (not handshake(cli, min_version)) { if (not handshake(cli, ctx, min_version)) {
return api_error::comm_error; return api_error::comm_error;
} }
std::this_thread::sleep_for(2s);
if (cli.socket.available() != 0U) {
min_version = 0U;
return api_error::incompatible_version;
}
if (client_version < min_version) { if (client_version < min_version) {
return api_error::incompatible_version; return api_error::incompatible_version;
} }
@@ -126,7 +132,7 @@ void packet_client::connect(client &cli) {
cli.socket.set_option(boost::asio::socket_base::keep_alive(true)); cli.socket.set_option(boost::asio::socket_base::keep_alive(true));
std::uint32_t min_version{}; std::uint32_t min_version{};
if (not handshake(cli, min_version)) { if (not handshake(cli, io_context_, min_version)) {
close(cli); close(cli);
return; return;
} }
@@ -172,6 +178,11 @@ auto packet_client::get_client() -> std::shared_ptr<packet_client::client> {
auto packet_client::handshake(client &cli, std::uint32_t &min_version) const auto packet_client::handshake(client &cli, std::uint32_t &min_version) const
-> bool { -> bool {
return handshake(cli, io_context_, min_version);
}
auto packet_client::handshake(client &cli, boost::asio::io_context &ctx,
std::uint32_t &min_version) const -> bool {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
@@ -185,8 +196,7 @@ auto packet_client::handshake(client &cli, std::uint32_t &min_version) const
tmp.to_buffer(buffer); tmp.to_buffer(buffer);
} }
read_exact_with_deadline(io_context_, cli.socket, read_exact_with_deadline(ctx, cli.socket, boost::asio::buffer(buffer),
boost::asio::buffer(buffer),
std::chrono::milliseconds(cfg_.recv_timeout_ms)); std::chrono::milliseconds(cfg_.recv_timeout_ms));
packet response(buffer); packet response(buffer);
auto res = response.decode(min_version); auto res = response.decode(min_version);
@@ -197,8 +207,7 @@ auto packet_client::handshake(client &cli, std::uint32_t &min_version) const
response.encrypt(cfg_.encryption_token, false); response.encrypt(cfg_.encryption_token, false);
response.to_buffer(buffer); response.to_buffer(buffer);
write_all_with_deadline(io_context_, cli.socket, write_all_with_deadline(ctx, cli.socket, boost::asio::buffer(buffer),
boost::asio::buffer(buffer),
std::chrono::milliseconds(cfg_.send_timeout_ms)); std::chrono::milliseconds(cfg_.send_timeout_ms));
return true; return true;
} catch (const std::exception &e) { } catch (const std::exception &e) {
@@ -221,8 +230,13 @@ void packet_client::put_client(std::shared_ptr<client> &cli) {
auto packet_client::read_packet(client &cli, packet &response) const auto packet_client::read_packet(client &cli, packet &response) const
-> packet::error_type { -> packet::error_type {
return read_packet(cli, io_context_, response);
}
auto packet_client::read_packet(client &cli, boost::asio::io_context &ctx,
packet &response) const -> packet::error_type {
data_buffer buffer(sizeof(std::uint32_t)); data_buffer buffer(sizeof(std::uint32_t));
read_exact_with_deadline(io_context_, cli.socket, boost::asio::buffer(buffer), read_exact_with_deadline(ctx, cli.socket, boost::asio::buffer(buffer),
std::chrono::milliseconds(cfg_.recv_timeout_ms)); std::chrono::milliseconds(cfg_.recv_timeout_ms));
std::uint32_t to_read{}; std::uint32_t to_read{};
@@ -230,7 +244,7 @@ auto packet_client::read_packet(client &cli, packet &response) const
boost::endian::big_to_native_inplace(to_read); boost::endian::big_to_native_inplace(to_read);
buffer.resize(to_read); buffer.resize(to_read);
read_exact_with_deadline(io_context_, cli.socket, boost::asio::buffer(buffer), read_exact_with_deadline(ctx, cli.socket, boost::asio::buffer(buffer),
std::chrono::milliseconds(cfg_.recv_timeout_ms)); std::chrono::milliseconds(cfg_.recv_timeout_ms));
response = std::move(buffer); response = std::move(buffer);