You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "Erixonich (via GitHub)" <gi...@apache.org> on 2026/02/16 21:02:48 UTC

[PR] IGNITE-27870 added proxy class. [ignite-3]

Erixonich opened a new pull request, #7607:
URL: https://github.com/apache/ignite-3/pull/7607

   https://issues.apache.org/jira/browse/IGNITE-27870
   
   Thank you for submitting the pull request.
   
   To streamline the review process of the patch and ensure better code quality
   we ask both an author and a reviewer to verify the following:
   
   ### The Review Checklist
   - [ ] **Formal criteria:** TC status, codestyle, mandatory documentation. Also make sure to complete the following:  
   \- There is a single JIRA ticket related to the pull request.  
   \- The web-link to the pull request is attached to the JIRA ticket.  
   \- The JIRA ticket has the Patch Available state.  
   \- The description of the JIRA ticket explains WHAT was made, WHY and HOW.  
   \- The pull request title is treated as the final commit message. The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
   - [ ] **Design:** new code conforms with the design principles of the components it is added to.
   - [ ] **Patch quality:** patch cannot be split into smaller pieces, its size must be reasonable.
   - [ ] **Code quality:** code is clean and readable, necessary developer documentation is added if needed.
   - [ ] **Tests code quality:** test set covers positive/negative scenarios, happy/edge cases. Tests are effective in terms of execution time and resources.
   
   ### Notes
   - [Apache Ignite Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Java+Code+Style+Guide)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2933092743


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }
+
+            self->do_write(std::move(m));
+        });
+    }
+
+    void do_write(message&& msg) {
+        asio::async_write(
+            *m_dst, asio::buffer(msg.data(), msg.size()),
+            [self = std::move(this->shared_from_this())](asio::error_code ec, size_t) {
+                if (ec) {
+                    if (ec == asio::error::eof) {
+                        return;
+                    }
+                    throw std::runtime_error("Error while writing to socket " + ec.message());
+                }
+
+                self->do_read();
+            });
+    }
+
+private:
+    std::shared_ptr<tcp::socket> m_src;
+    std::shared_ptr<tcp::socket> m_dst;
+    std::array<char, BUFF_SIZE> m_buf{};
+    std::shared_ptr<message_listener> m_listener{nullptr};
+
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(
+        std::shared_ptr<tcp::socket> in_sock,
+        std::shared_ptr<tcp::socket> out_sock,
+        std::shared_ptr<message_listener> listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+    {
+        m_forward_part = std::make_shared<session_part<direction::forward>>(m_in_sock, m_out_sock, listener);
+        m_reverse_part = std::make_shared<session_part<direction::reverse>>(m_out_sock, m_in_sock, listener);
+    }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return *m_out_sock; }
+
+private:
+    void do_serve() {
+        m_forward_part->do_read();
+        m_reverse_part->do_read();
+    }
+
+    std::shared_ptr<tcp::socket> m_in_sock;
+    std::shared_ptr<tcp::socket> m_out_sock;
+
+    std::shared_ptr<session_part<direction::forward>> m_forward_part;
+    std::shared_ptr<session_part<direction::reverse>> m_reverse_part;
+};
+
+class asio_proxy {
+public:
+    asio_proxy(std::vector<configuration> configurations)
+        : m_resolver(m_io_context)
+    {
+        for (auto &cfg : configurations) {
+            m_conn_map.emplace(
+                cfg.m_in_port,
+                proxy_entry{m_io_context, cfg.m_in_port, cfg.m_out_host_and_port, cfg.m_listener}
+            );
+        }
+
+        do_serve();
+
+        m_executor = std::make_unique<std::thread>([this]() {
+            m_io_context.run();
+        });
+    }
+
+    ~asio_proxy() {
+        m_stopped.store(true);
+        m_io_context.stop();
+
+        m_executor->join();
+    }
+
+private:
+    struct proxy_entry {
+        tcp::acceptor m_in_acceptor;
+        std::string m_out_host;
+        std::string m_out_port;
+        std::shared_ptr<message_listener> m_listener;
+
+        proxy_entry(
+            asio::io_context& io_context,
+            asio::ip::port_type in_port,
+            const std::string& out_host_and_port,
+            std::shared_ptr<message_listener> listener)
+            : m_in_acceptor(io_context, tcp::endpoint(tcp::v4(), in_port))
+            , m_listener(std::move(listener))
+        {
+            auto colon_pos = out_host_and_port.find(':');
+
+            if (colon_pos == std::string::npos) {
+                throw std::runtime_error("Incorrect host and part format. Expected 'hostname:port' but got " + out_host_and_port);
+            }
+
+            m_out_host = out_host_and_port.substr(0, colon_pos);
+            m_out_port = out_host_and_port.substr(colon_pos + 1);
+        }
+    };
+
+
+    void do_serve() {
+        for (auto& [_, entry]: m_conn_map) {
+            do_accept(entry);
+        }
+    }
+
+    void do_accept(proxy_entry& entry) {
+        if (m_stopped.load()) {
+            return;
+        }
+
+        entry.m_in_acceptor.async_accept([this, &entry](asio::error_code ec, tcp::socket in_sock) {
+            if (ec) {
+                throw std::runtime_error("Error accepting incoming connection " + ec.message());
+            }
+
+            auto p_in_sock = std::make_shared<tcp::socket>(std::move(in_sock));
+            auto p_out_sock = std::make_shared<tcp::socket>(m_io_context);
+            auto ses = std::make_shared<session>(p_in_sock, p_out_sock, entry.m_listener);
+
+            m_resolver.async_resolve(entry.m_out_host, entry.m_out_port,
+                [ses](asio::error_code ec, tcp::resolver::results_type endpoints) { // NOLINT(*-unnecessary-value-param)
+                    if (ec) {
+                        throw std::runtime_error("Error resolving server's address " + ec.message());
+                    }
+
+                    asio::async_connect(
+                        ses->get_out_sock(), endpoints, [ses](const asio::error_code &ec, const tcp::endpoint &e) {
+                            if (ec) {
+                                throw std::runtime_error(
+                                    "Error connecting to server " + ec.message()
+                                    + " port=" + std::to_string(e.port())
+                                );
+                            }
+
+                            ses->start();
+                        });

Review Comment:
   tbh, I we move only asio::async_connect, code would look like alienated.
   If we move resolve as well than we are no reusing acceptor and resolver objects, therefore we have pass them into session by reference/shared_ptr.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2883013389


##########
modules/platforms/cpp/cmake/dependencies.cmake:
##########
@@ -76,6 +99,7 @@ else()
     fetch_dependency(uni-algo https://github.com/uni-algo/uni-algo/archive/v1.2.0.tar.gz 6e0cce94a6b45ebee7b904316df9f87f)
     if (${ENABLE_TESTS})
         fetch_dependency(googletest https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz c8340a482851ef6a3fe618a082304cfc)
+        add_asio_dependency(https://github.com/chriskohlhoff/asio/archive/refs/tags/asio-1-36-0.tar.gz 6699ac1dea111c20d024f25e06e573db)
     endif()

Review Comment:
   it seems incorrect suggestion



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2884760092


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,271 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener)
+    { }
+
+    ~session() {
+        std::cout << "Session destructed " << this <<  std::endl;
+    }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        if (m_stopped.load())
+            return;
+
+        tcp::socket &src = direction == forward ? m_in_sock : m_out_sock;
+
+        auto self(shared_from_this());
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [direction, self](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            std::queue<message> &queue = direction == forward ? self->m_in_to_out : self->m_out_to_in;
+            bool &writable = direction == forward ? self->m_in_to_out_writable : self->m_out_to_in_writable;
+
+            // we have one-threaded executor no synchronization is needed
+            message& msg = queue.emplace(self->buf, len);
+
+            if (self->m_listener) {
+                if (direction == forward) {
+                    self->m_listener->register_out_message(msg);
+                } else {
+                    self->m_listener->register_in_message(msg);
+                }
+            }
+
+            if (writable) { // there are pending write operation on this socket

Review Comment:
   other way around



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "isapego (via GitHub)" <gi...@apache.org>.
isapego commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2933295549


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }

Review Comment:
   Not necessarily - user API can always be improved.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2930665783


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,266 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        if (m_stopped.load())
+            return;
+
+        tcp::socket &src = direction == forward ? m_in_sock : m_out_sock;
+
+        auto self(shared_from_this());
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [direction, self](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            std::queue<message> &queue = direction == forward ? self->m_in_to_out : self->m_out_to_in;
+            bool &writable = direction == forward ? self->m_in_to_out_writable : self->m_out_to_in_writable;
+
+            // we have one-threaded executor no synchronization is needed
+            message& msg = queue.emplace(self->buf, len);
+
+            if (self->m_listener) {
+                if (direction == forward) {
+                    self->m_listener->register_out_message(msg);
+                } else {
+                    self->m_listener->register_in_message(msg);
+                }
+            }
+
+            if (writable) { // there are pending write operation on this socket
+                self->do_write(direction);
+            }
+
+            self->do_read(direction);
+        });
+    }
+
+    void do_write(direction direction) {
+        tcp::socket &dst = direction == forward ? m_out_sock : m_in_sock;
+        std::queue<message> &queue = direction == forward ? m_in_to_out : m_out_to_in;
+        bool &writable = direction == forward ? m_in_to_out_writable : m_out_to_in_writable;
+
+        writable = false; // protects from writing same buffer twice (from head of queue).
+
+        auto self(shared_from_this());
+        if (!queue.empty()) {
+            message &msg = queue.front();
+
+            asio::async_write(
+                dst, asio::buffer(msg.m_arr, msg.m_size),
+                [direction, self](asio::error_code ec, size_t) {
+                    if (ec) {
+                        if (ec == asio::error::eof) {
+                            return;
+                        }
+                        throw std::runtime_error("Error while writing to socket " + ec.message());
+                    }
+
+                    std::queue<message> &queue = direction == forward ? self->m_in_to_out : self->m_out_to_in;
+                    bool &writable = direction == forward ? self->m_in_to_out_writable : self->m_out_to_in_writable;
+
+                    queue.pop();
+
+                    if (!queue.empty()) {
+                        // makes writes on the same socket strictly ordered
+                        self->do_write(direction);
+                    } else {
+                        writable = true; // now read operation can initiate writes
+                    }
+                });
+        }
+    }
+
+    tcp::socket m_in_sock;
+    tcp::socket m_out_sock;
+
+    bool m_in_to_out_writable{false};
+    bool m_out_to_in_writable{false};
+
+    std::queue<message> m_in_to_out;
+    std::queue<message> m_out_to_in;
+
+    static constexpr size_t BUFF_SIZE = 4096;
+
+    char buf[BUFF_SIZE]{};

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "isapego (via GitHub)" <gi...@apache.org>.
isapego commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2925472543


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,266 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        if (m_stopped.load())
+            return;
+
+        tcp::socket &src = direction == forward ? m_in_sock : m_out_sock;
+
+        auto self(shared_from_this());
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [direction, self](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            std::queue<message> &queue = direction == forward ? self->m_in_to_out : self->m_out_to_in;
+            bool &writable = direction == forward ? self->m_in_to_out_writable : self->m_out_to_in_writable;
+
+            // we have one-threaded executor no synchronization is needed
+            message& msg = queue.emplace(self->buf, len);

Review Comment:
   Wait, if every message refers to the same buffer, why do we even need a queue? Also, changing a buffer will affect all the messages, which does not look right to me. This logic here needs explanation.



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,260 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <iostream>
+#include <queue>
+#include <tuple>
+#include <map>
+
+#include <asio.hpp>
+#include <asio/ts/buffer.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener)
+    { }
+
+    ~session() {
+        std::cout << "Session destructed " << this <<  std::endl;
+    }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }

Review Comment:
   I actually agree with copilot here. Why not use separate buffers? We maybe have one thread now, but it's just cleaner code and easier to change in future. It's also a test infrastructure so we have not to safe memory here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2930598838


##########
modules/platforms/cpp/tests/fake_server/proxy/message.h:
##########
@@ -0,0 +1,62 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//
+
+#pragma once
+
+#include <cstring>
+#include <utility>
+
+namespace ignite::proxy {
+
+struct message {
+    char *m_arr{nullptr};
+    size_t m_size = 0;
+
+    friend void swap(message& lhs, message& rhs) noexcept {
+        using std::swap;
+        swap(lhs.m_arr, rhs.m_arr);
+        swap(lhs.m_size, rhs.m_size);
+    }
+
+    message(char *arr, size_t size)
+        : m_size(size)
+    {
+        m_arr = new char[m_size];
+        std::memcpy(m_arr, arr, size);
+    }

Review Comment:
   My motivation here is to have properly named types, instead of generic std::vectors. But ok, let have it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2932775869


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }
+
+            self->do_write(std::move(m));
+        });
+    }
+
+    void do_write(message&& msg) {
+        asio::async_write(
+            *m_dst, asio::buffer(msg.data(), msg.size()),

Review Comment:
   I've deleted message class, instead I am using vector directly



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2930592250


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,260 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <iostream>
+#include <queue>
+#include <tuple>
+#include <map>
+
+#include <asio.hpp>
+#include <asio/ts/buffer.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener)
+    { }
+
+    ~session() {
+        std::cout << "Session destructed " << this <<  std::endl;
+    }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2933200900


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }

Review Comment:
   I don't want to produce two listeners, as it would cause inconvenient interface for test users.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2932771260


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2884742725


##########
modules/platforms/cpp/cmake/dependencies.cmake:
##########
@@ -43,6 +43,24 @@ function(fetch_dependency NAME URL MD5)
     endif()
 endfunction()
 
+function(add_asio_dependency)
+    message(STATUS "Download dependency: asio")
+
+    FetchContent_Declare(
+            asio
+            URL https://github.com/chriskohlhoff/asio/archive/refs/tags/asio-1-36-0.tar.gz
+            URL_HASH MD5=6699ac1dea111c20d024f25e06e573db

Review Comment:
   should we change other instances as well?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2930572789


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,260 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <iostream>
+#include <queue>
+#include <tuple>
+#include <map>
+
+#include <asio.hpp>
+#include <asio/ts/buffer.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener)
+    { }
+
+    ~session() {
+        std::cout << "Session destructed " << this <<  std::endl;
+    }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        if (m_stopped.load())
+            return;
+
+        tcp::socket &src = direction == forward ? m_in_sock : m_out_sock;
+        std::queue<message> &queue = direction == forward ? m_in_to_out : m_out_to_in;
+        bool &writable = direction == forward ? m_in_to_out_writable : m_out_to_in_writable;
+
+        auto self(shared_from_this());
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [&queue, direction, &writable, self](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }

Review Comment:
   In this case recoverable error (eof) is handled, all other error, should stop app, as data would be corrupted.
   In other words we don't expect other errors at this point.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2933117593


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }
+
+            self->do_write(std::move(m));
+        });
+    }
+
+    void do_write(message&& msg) {
+        asio::async_write(
+            *m_dst, asio::buffer(msg.data(), msg.size()),
+            [self = std::move(this->shared_from_this())](asio::error_code ec, size_t) {
+                if (ec) {
+                    if (ec == asio::error::eof) {
+                        return;
+                    }
+                    throw std::runtime_error("Error while writing to socket " + ec.message());
+                }
+
+                self->do_read();
+            });
+    }
+
+private:
+    std::shared_ptr<tcp::socket> m_src;
+    std::shared_ptr<tcp::socket> m_dst;
+    std::array<char, BUFF_SIZE> m_buf{};
+    std::shared_ptr<message_listener> m_listener{nullptr};
+
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(
+        std::shared_ptr<tcp::socket> in_sock,
+        std::shared_ptr<tcp::socket> out_sock,
+        std::shared_ptr<message_listener> listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+    {
+        m_forward_part = std::make_shared<session_part<direction::forward>>(m_in_sock, m_out_sock, listener);
+        m_reverse_part = std::make_shared<session_part<direction::reverse>>(m_out_sock, m_in_sock, listener);

Review Comment:
   I tried to not to use server/client terms, because proxy can be used for other modes e.g server/server connections.
   We always have incoming connection (someone  connected to proxy) and corresponding related outgoing connection (proxy establish connection according to mapping).
   Would you like more:
   dirrection::forward => direction::in_to_out
   dirrection::reverse => direction::out_to_in



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2883086125


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,271 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener)
+    { }
+
+    ~session() {
+        std::cout << "Session destructed " << this <<  std::endl;
+    }

Review Comment:
   Unconditional `std::cout` output in test utilities tends to pollute test logs and makes failures harder to read. Consider removing these prints or using the existing test logger / a compile-time debug flag instead.



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,271 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener)
+    { }
+
+    ~session() {
+        std::cout << "Session destructed " << this <<  std::endl;
+    }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        if (m_stopped.load())
+            return;
+
+        tcp::socket &src = direction == forward ? m_in_sock : m_out_sock;
+
+        auto self(shared_from_this());
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [direction, self](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            std::queue<message> &queue = direction == forward ? self->m_in_to_out : self->m_out_to_in;
+            bool &writable = direction == forward ? self->m_in_to_out_writable : self->m_out_to_in_writable;
+
+            // we have one-threaded executor no synchronization is needed
+            message& msg = queue.emplace(self->buf, len);
+
+            if (self->m_listener) {
+                if (direction == forward) {
+                    self->m_listener->register_out_message(msg);
+                } else {
+                    self->m_listener->register_in_message(msg);
+                }
+            }
+
+            if (writable) { // there are pending write operation on this socket
+                self->do_write(direction);
+            }
+
+            self->do_read(direction);
+        });
+    }
+
+    void do_write(direction direction) {
+        tcp::socket &dst = direction == forward ? m_out_sock : m_in_sock;
+        std::queue<message> &queue = direction == forward ? m_in_to_out : m_out_to_in;
+        bool &writable = direction == forward ? m_in_to_out_writable : m_out_to_in_writable;
+
+        writable = false; // protects from writing same buffer twice (from head of queue).
+
+        auto self(shared_from_this());
+        if (!queue.empty()) {
+            message &msg = queue.front();
+
+            asio::async_write(
+                dst, asio::buffer(msg.m_arr, msg.m_size),
+                [direction, self](asio::error_code ec, size_t) {
+                    if (ec) {
+                        if (ec == asio::error::eof) {
+                            return;
+                        }
+                        throw std::runtime_error("Error while writing to socket " + ec.message());
+                    }
+
+                    std::queue<message> &queue = direction == forward ? self->m_in_to_out : self->m_out_to_in;
+                    bool &writable = direction == forward ? self->m_in_to_out_writable : self->m_out_to_in_writable;
+
+                    queue.pop();
+
+                    if (!queue.empty()) {
+                        // makes writes on the same socket strictly ordered
+                        self->do_write(direction);
+                    } else {
+                        writable = true; // now read operation can initiate writes
+                    }
+                });
+        }
+    }
+
+    tcp::socket m_in_sock;
+    tcp::socket m_out_sock;
+
+    bool m_in_to_out_writable{false};
+    bool m_out_to_in_writable{false};
+
+    std::queue<message> m_in_to_out;
+    std::queue<message> m_out_to_in;
+
+    static constexpr size_t BUFF_SIZE = 4096;
+
+    char buf[BUFF_SIZE]{};
+
+    std::atomic_bool& m_stopped;
+
+    message_listener* m_listener{nullptr};
+};
+
+class asio_proxy {
+public:
+    asio_proxy(std::vector<configuration> configurations)
+        : m_resolver(m_io_context)
+        , m_in_sock(m_io_context)
+    {
+        for (auto &cfg : configurations) {
+            m_conn_map.emplace(
+                cfg.m_in_port,
+                proxy_entry{m_io_context, cfg.m_in_port, cfg.m_out_host_and_port, cfg.m_listener}
+            );
+        }
+
+        do_serve();
+
+        m_executor = std::make_unique<std::thread>([this]() {
+            m_io_context.run();
+        });
+    }
+
+    ~asio_proxy() {
+        m_stopped.store(true);
+        m_io_context.stop();
+
+        m_executor->join();
+    }
+
+private:
+    struct proxy_entry {
+        tcp::acceptor m_in_acceptor;
+        std::string m_out_host;
+        std::string m_out_port;
+        message_listener* m_listener;
+
+        proxy_entry(asio::io_context& io_context, asio::ip::port_type in_port, const std::string& out_host_and_port, message_listener* listener)
+            : m_in_acceptor(io_context, tcp::endpoint(tcp::v4(), in_port))
+            , m_listener(listener)
+        {
+            auto colon_pos = out_host_and_port.find(':');
+
+            if (colon_pos == std::string::npos) {
+                throw std::runtime_error("Incorrect host and part format. Expected 'hostname:port' but got " + out_host_and_port);
+            }
+
+            m_out_host = out_host_and_port.substr(0, colon_pos);
+            m_out_port = out_host_and_port.substr(colon_pos + 1);
+        }
+    };
+
+
+    void do_serve() {
+        for (auto& [_, entry]: m_conn_map) {
+            do_accept(entry);
+        }
+    }
+
+    void do_accept(proxy_entry& entry) {
+        if (m_stopped.load()) {
+            return;
+        }
+
+        entry.m_in_acceptor.async_accept(m_in_sock, [this, &entry](asio::error_code ec) {
+            if (ec) {
+                throw std::runtime_error("Error accepting incoming connection " + ec.message());
+            }
+
+            auto ses = std::make_shared<session>(std::move(m_in_sock), tcp::socket{m_io_context}, m_stopped, entry.m_listener);
+
+            m_resolver.async_resolve(entry.m_out_host, entry.m_out_port,
+                [ses](asio::error_code ec, tcp::resolver::results_type endpoints) { // NOLINT(*-unnecessary-value-param)
+                    if (ec) {
+                        throw std::runtime_error("Error resolving server's address " + ec.message());
+                    }
+
+                    asio::async_connect(
+                        ses->get_out_sock(), endpoints, [ses](const asio::error_code &ec, const tcp::endpoint &e) {
+                            if (ec) {
+                                std::cout << e.port();
+                                throw std::runtime_error("Error connecting to server " + ec.message());

Review Comment:
   This `std::cout << e.port();` looks like leftover debug output and will add noise on failures (and it prints without newline). Consider removing it or integrating it into the error message/log output in a controlled way.
   ```suggestion
                                   throw std::runtime_error(
                                       "Error connecting to server on port " + std::to_string(e.port()) + ": " + ec.message());
   ```



##########
modules/platforms/cpp/cmake/dependencies.cmake:
##########
@@ -43,6 +43,24 @@ function(fetch_dependency NAME URL MD5)
     endif()
 endfunction()
 
+function(add_asio_dependency)
+    message(STATUS "Download dependency: asio")
+
+    FetchContent_Declare(
+            asio
+            URL https://github.com/chriskohlhoff/asio/archive/refs/tags/asio-1-36-0.tar.gz
+            URL_HASH MD5=6699ac1dea111c20d024f25e06e573db
+    )
+
+    FetchContent_Populate(asio)
+
+    add_library(asio INTERFACE)
+
+    target_include_directories(asio INTERFACE ${asio_SOURCE_DIR}/asio/include)
+
+    target_compile_definitions(asio INTERFACE ASIO_STANDALONE)

Review Comment:
   `add_asio_dependency()` uses `FetchContent_Populate(asio)` unconditionally and always creates the `asio` target. If this file is included more than once (or another target named `asio` exists), this can re-download/repopulate or fail with target redefinition. Consider following the existing `fetch_dependency()` pattern: `FetchContent_GetProperties` + `if(NOT asio_POPULATED)` and guard target creation with `if(NOT TARGET asio)`.
   ```suggestion
       FetchContent_GetProperties(asio)
       if (NOT asio_POPULATED)
           FetchContent_Populate(asio)
       endif()
   
       if (NOT TARGET asio)
           add_library(asio INTERFACE)
   
           target_include_directories(asio INTERFACE ${asio_SOURCE_DIR}/asio/include)
   
           target_compile_definitions(asio INTERFACE ASIO_STANDALONE)
       endif()
   ```



##########
modules/platforms/cpp/cmake/dependencies.cmake:
##########
@@ -43,6 +43,24 @@ function(fetch_dependency NAME URL MD5)
     endif()
 endfunction()
 
+function(add_asio_dependency)
+    message(STATUS "Download dependency: asio")
+
+    FetchContent_Declare(
+            asio
+            URL https://github.com/chriskohlhoff/asio/archive/refs/tags/asio-1-36-0.tar.gz
+            URL_HASH MD5=6699ac1dea111c20d024f25e06e573db

Review Comment:
   The `add_asio_dependency` function verifies the downloaded `asio` tarball using an MD5 hash (`URL_HASH MD5=...`), which relies on a cryptographically broken algorithm. An attacker capable of influencing the download (e.g., via network or repository compromise) could craft a malicious archive with the same MD5, bypassing this integrity check and introducing backdoored code into your build. Switch this integrity check to a stronger hash supported by CMake (for example, using `URL_HASH SHA256=...`) and regenerate the checksum from a trusted source.
   ```suggestion
               # NOTE: SHA256 checksum must be computed from a trusted copy of asio-1-36-0.tar.gz.
               URL_HASH SHA256=0f1a5b0a7d8c9e3f2b4c6d8e0f1a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c
   ```



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,271 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener)
+    { }
+
+    ~session() {
+        std::cout << "Session destructed " << this <<  std::endl;
+    }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        if (m_stopped.load())
+            return;
+
+        tcp::socket &src = direction == forward ? m_in_sock : m_out_sock;
+
+        auto self(shared_from_this());
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [direction, self](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            std::queue<message> &queue = direction == forward ? self->m_in_to_out : self->m_out_to_in;
+            bool &writable = direction == forward ? self->m_in_to_out_writable : self->m_out_to_in_writable;
+
+            // we have one-threaded executor no synchronization is needed
+            message& msg = queue.emplace(self->buf, len);
+
+            if (self->m_listener) {
+                if (direction == forward) {
+                    self->m_listener->register_out_message(msg);
+                } else {
+                    self->m_listener->register_in_message(msg);
+                }
+            }
+
+            if (writable) { // there are pending write operation on this socket

Review Comment:
   This comment contradicts the current logic: `writable` is set to `false` when a write is in-flight and reset to `true` when the queue becomes empty, so `if (writable)` means “no write in progress; safe to start one”, not “there are pending write operation”. Please update the comment to reflect the actual meaning to avoid confusion during maintenance.
   ```suggestion
               if (writable) { // no write in progress on this socket; safe to start one
   ```



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,271 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener)
+    { }
+
+    ~session() {
+        std::cout << "Session destructed " << this <<  std::endl;
+    }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        if (m_stopped.load())
+            return;
+
+        tcp::socket &src = direction == forward ? m_in_sock : m_out_sock;
+
+        auto self(shared_from_this());
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [direction, self](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            std::queue<message> &queue = direction == forward ? self->m_in_to_out : self->m_out_to_in;
+            bool &writable = direction == forward ? self->m_in_to_out_writable : self->m_out_to_in_writable;
+
+            // we have one-threaded executor no synchronization is needed
+            message& msg = queue.emplace(self->buf, len);
+
+            if (self->m_listener) {
+                if (direction == forward) {
+                    self->m_listener->register_out_message(msg);
+                } else {
+                    self->m_listener->register_in_message(msg);
+                }
+            }
+
+            if (writable) { // there are pending write operation on this socket
+                self->do_write(direction);
+            }
+
+            self->do_read(direction);
+        });
+    }
+
+    void do_write(direction direction) {
+        tcp::socket &dst = direction == forward ? m_out_sock : m_in_sock;
+        std::queue<message> &queue = direction == forward ? m_in_to_out : m_out_to_in;
+        bool &writable = direction == forward ? m_in_to_out_writable : m_out_to_in_writable;
+
+        writable = false; // protects from writing same buffer twice (from head of queue).
+
+        auto self(shared_from_this());
+        if (!queue.empty()) {
+            message &msg = queue.front();
+
+            asio::async_write(
+                dst, asio::buffer(msg.m_arr, msg.m_size),
+                [direction, self](asio::error_code ec, size_t) {
+                    if (ec) {
+                        if (ec == asio::error::eof) {
+                            return;
+                        }
+                        throw std::runtime_error("Error while writing to socket " + ec.message());

Review Comment:
   Same issue here: throwing from `async_write` completion handlers is unsafe and can terminate the process. Prefer handling the error in-place (close/cancel, stop the session) or route the error to the test harness via a callback/flag.
   ```suggestion
                           std::cerr << "Error while writing to socket: " << ec.message() << std::endl;
                           return;
   ```



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,271 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener)
+    { }
+
+    ~session() {
+        std::cout << "Session destructed " << this <<  std::endl;
+    }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        if (m_stopped.load())
+            return;
+
+        tcp::socket &src = direction == forward ? m_in_sock : m_out_sock;
+
+        auto self(shared_from_this());
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [direction, self](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            std::queue<message> &queue = direction == forward ? self->m_in_to_out : self->m_out_to_in;
+            bool &writable = direction == forward ? self->m_in_to_out_writable : self->m_out_to_in_writable;
+
+            // we have one-threaded executor no synchronization is needed
+            message& msg = queue.emplace(self->buf, len);
+
+            if (self->m_listener) {
+                if (direction == forward) {
+                    self->m_listener->register_out_message(msg);
+                } else {
+                    self->m_listener->register_in_message(msg);
+                }
+            }
+
+            if (writable) { // there are pending write operation on this socket
+                self->do_write(direction);
+            }
+
+            self->do_read(direction);
+        });
+    }
+
+    void do_write(direction direction) {
+        tcp::socket &dst = direction == forward ? m_out_sock : m_in_sock;
+        std::queue<message> &queue = direction == forward ? m_in_to_out : m_out_to_in;
+        bool &writable = direction == forward ? m_in_to_out_writable : m_out_to_in_writable;
+
+        writable = false; // protects from writing same buffer twice (from head of queue).
+
+        auto self(shared_from_this());
+        if (!queue.empty()) {
+            message &msg = queue.front();
+
+            asio::async_write(
+                dst, asio::buffer(msg.m_arr, msg.m_size),
+                [direction, self](asio::error_code ec, size_t) {
+                    if (ec) {
+                        if (ec == asio::error::eof) {
+                            return;
+                        }
+                        throw std::runtime_error("Error while writing to socket " + ec.message());
+                    }
+
+                    std::queue<message> &queue = direction == forward ? self->m_in_to_out : self->m_out_to_in;
+                    bool &writable = direction == forward ? self->m_in_to_out_writable : self->m_out_to_in_writable;
+
+                    queue.pop();
+
+                    if (!queue.empty()) {
+                        // makes writes on the same socket strictly ordered
+                        self->do_write(direction);
+                    } else {
+                        writable = true; // now read operation can initiate writes
+                    }
+                });
+        }
+    }
+
+    tcp::socket m_in_sock;
+    tcp::socket m_out_sock;
+
+    bool m_in_to_out_writable{false};
+    bool m_out_to_in_writable{false};
+
+    std::queue<message> m_in_to_out;
+    std::queue<message> m_out_to_in;
+
+    static constexpr size_t BUFF_SIZE = 4096;
+
+    char buf[BUFF_SIZE]{};
+
+    std::atomic_bool& m_stopped;
+
+    message_listener* m_listener{nullptr};
+};
+
+class asio_proxy {
+public:
+    asio_proxy(std::vector<configuration> configurations)
+        : m_resolver(m_io_context)
+        , m_in_sock(m_io_context)
+    {
+        for (auto &cfg : configurations) {
+            m_conn_map.emplace(
+                cfg.m_in_port,
+                proxy_entry{m_io_context, cfg.m_in_port, cfg.m_out_host_and_port, cfg.m_listener}
+            );
+        }
+
+        do_serve();
+
+        m_executor = std::make_unique<std::thread>([this]() {
+            m_io_context.run();
+        });
+    }
+
+    ~asio_proxy() {
+        m_stopped.store(true);
+        m_io_context.stop();
+
+        m_executor->join();
+    }
+
+private:
+    struct proxy_entry {
+        tcp::acceptor m_in_acceptor;
+        std::string m_out_host;
+        std::string m_out_port;
+        message_listener* m_listener;
+
+        proxy_entry(asio::io_context& io_context, asio::ip::port_type in_port, const std::string& out_host_and_port, message_listener* listener)
+            : m_in_acceptor(io_context, tcp::endpoint(tcp::v4(), in_port))
+            , m_listener(listener)
+        {
+            auto colon_pos = out_host_and_port.find(':');
+
+            if (colon_pos == std::string::npos) {
+                throw std::runtime_error("Incorrect host and part format. Expected 'hostname:port' but got " + out_host_and_port);
+            }
+
+            m_out_host = out_host_and_port.substr(0, colon_pos);
+            m_out_port = out_host_and_port.substr(colon_pos + 1);
+        }
+    };
+
+
+    void do_serve() {
+        for (auto& [_, entry]: m_conn_map) {
+            do_accept(entry);
+        }
+    }
+
+    void do_accept(proxy_entry& entry) {
+        if (m_stopped.load()) {
+            return;
+        }
+
+        entry.m_in_acceptor.async_accept(m_in_sock, [this, &entry](asio::error_code ec) {
+            if (ec) {
+                throw std::runtime_error("Error accepting incoming connection " + ec.message());
+            }
+
+            auto ses = std::make_shared<session>(std::move(m_in_sock), tcp::socket{m_io_context}, m_stopped, entry.m_listener);
+
+            m_resolver.async_resolve(entry.m_out_host, entry.m_out_port,
+                [ses](asio::error_code ec, tcp::resolver::results_type endpoints) { // NOLINT(*-unnecessary-value-param)
+                    if (ec) {
+                        throw std::runtime_error("Error resolving server's address " + ec.message());
+                    }
+
+                    asio::async_connect(
+                        ses->get_out_sock(), endpoints, [ses](const asio::error_code &ec, const tcp::endpoint &e) {
+                            if (ec) {
+                                std::cout << e.port();
+                                throw std::runtime_error("Error connecting to server " + ec.message());
+                            }
+
+                            ses->set_writable(true);
+                            ses->start();
+                        });
+                });
+
+            do_accept(entry);
+        });

Review Comment:
   `asio_proxy` starts an `async_accept` for each `proxy_entry` but all accepts share the same member socket `m_in_sock`. Multiple pending accepts must not use the same `tcp::socket` instance; this can lead to undefined behavior and incorrect/missed connections when more than one acceptor is active. Create a fresh `tcp::socket` per accept operation (e.g., local socket moved into the handler) or store a dedicated socket per entry.
   ```suggestion
           tcp::socket in_sock{m_io_context};
   
           entry.m_in_acceptor.async_accept(in_sock,
               [this, &entry, in_sock = std::move(in_sock)](asio::error_code ec) mutable {
                   if (ec) {
                       throw std::runtime_error("Error accepting incoming connection " + ec.message());
                   }
   
                   auto ses = std::make_shared<session>(std::move(in_sock), tcp::socket{m_io_context}, m_stopped, entry.m_listener);
   
                   m_resolver.async_resolve(entry.m_out_host, entry.m_out_port,
                       [ses](asio::error_code ec, tcp::resolver::results_type endpoints) { // NOLINT(*-unnecessary-value-param)
                           if (ec) {
                               throw std::runtime_error("Error resolving server's address " + ec.message());
                           }
   
                           asio::async_connect(
                               ses->get_out_sock(), endpoints, [ses](const asio::error_code &ec, const tcp::endpoint &e) {
                                   if (ec) {
                                       std::cout << e.port();
                                       throw std::runtime_error("Error connecting to server " + ec.message());
                                   }
   
                                   ses->set_writable(true);
                                   ses->start();
                               });
                       });
   
                   do_accept(entry);
               });
   ```



##########
modules/platforms/cpp/tests/fake_server/proxy/message.h:
##########
@@ -0,0 +1,62 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//
+
+#pragma once
+
+#include <cstring>
+#include <utility>
+
+namespace ignite::proxy {
+
+struct message {
+    char *m_arr{nullptr};
+    size_t m_size = 0;
+
+    friend void swap(message& lhs, message& rhs) noexcept {
+        using std::swap;
+        swap(lhs.m_arr, rhs.m_arr);
+        swap(lhs.m_size, rhs.m_size);
+    }
+
+    message(char *arr, size_t size)
+        : m_size(size)
+    {
+        m_arr = new char[m_size];
+        std::memcpy(m_arr, arr, size);
+    }

Review Comment:
   `message` manually manages a heap buffer (`new[]`/`delete[]`). This increases maintenance risk in tests (e.g., future changes to copying/moving). Prefer using `std::vector<std::byte>`/`std::vector<char>` (or `std::unique_ptr<char[]>`) to represent the payload and avoid manual memory management. Also, the input pointer should be `const char*` since the constructor does not modify the source buffer.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "isapego (via GitHub)" <gi...@apache.org>.
isapego commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2943735316


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,265 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+#include <gtest/gtest.h>
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_in_listener;
+    std::shared_ptr<message_listener> m_out_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> in_listener,
+        std::shared_ptr<message_listener> out_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_in_listener(std::move(in_listener))
+        , m_out_listener(std::move(out_listener)) {}
+};
+
+
+class session_part: public std::enable_shared_from_this<session_part> {
+public:
+    session_part(
+        std::shared_ptr<tcp::socket> src,
+        std::shared_ptr<tcp::socket> dst,
+        std::shared_ptr<message_listener> listener,
+        std::atomic_bool& failed
+        )
+        : m_src(std::move(src))
+        , m_dst(std::move(dst))
+        , m_listener(std::move(listener))
+        , m_failed(failed) {}
+
+    void do_read() {
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = this->shared_from_this()](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                std::cerr << "Error while reading from socket " << ec.message() << std::endl;

Review Comment:
   Let's use logger instead of plain print. It's implemented in a way so that the messages can be processed by gtest properly.



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }
+
+            self->do_write(std::move(m));
+        });
+    }
+
+    void do_write(message&& msg) {
+        asio::async_write(
+            *m_dst, asio::buffer(msg.data(), msg.size()),
+            [self = std::move(this->shared_from_this())](asio::error_code ec, size_t) {
+                if (ec) {
+                    if (ec == asio::error::eof) {
+                        return;
+                    }
+                    throw std::runtime_error("Error while writing to socket " + ec.message());
+                }
+
+                self->do_read();
+            });
+    }
+
+private:
+    std::shared_ptr<tcp::socket> m_src;
+    std::shared_ptr<tcp::socket> m_dst;
+    std::array<char, BUFF_SIZE> m_buf{};
+    std::shared_ptr<message_listener> m_listener{nullptr};
+
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(
+        std::shared_ptr<tcp::socket> in_sock,
+        std::shared_ptr<tcp::socket> out_sock,
+        std::shared_ptr<message_listener> listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+    {
+        m_forward_part = std::make_shared<session_part<direction::forward>>(m_in_sock, m_out_sock, listener);
+        m_reverse_part = std::make_shared<session_part<direction::reverse>>(m_out_sock, m_in_sock, listener);
+    }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return *m_out_sock; }
+
+private:
+    void do_serve() {
+        m_forward_part->do_read();
+        m_reverse_part->do_read();
+    }
+
+    std::shared_ptr<tcp::socket> m_in_sock;
+    std::shared_ptr<tcp::socket> m_out_sock;
+
+    std::shared_ptr<session_part<direction::forward>> m_forward_part;
+    std::shared_ptr<session_part<direction::reverse>> m_reverse_part;
+};
+
+class asio_proxy {
+public:
+    asio_proxy(std::vector<configuration> configurations)
+        : m_resolver(m_io_context)
+    {
+        for (auto &cfg : configurations) {
+            m_conn_map.emplace(
+                cfg.m_in_port,
+                proxy_entry{m_io_context, cfg.m_in_port, cfg.m_out_host_and_port, cfg.m_listener}
+            );
+        }
+
+        do_serve();
+
+        m_executor = std::make_unique<std::thread>([this]() {
+            m_io_context.run();
+        });
+    }
+
+    ~asio_proxy() {
+        m_stopped.store(true);
+        m_io_context.stop();
+
+        m_executor->join();
+    }
+
+private:
+    struct proxy_entry {
+        tcp::acceptor m_in_acceptor;
+        std::string m_out_host;
+        std::string m_out_port;
+        std::shared_ptr<message_listener> m_listener;
+
+        proxy_entry(
+            asio::io_context& io_context,
+            asio::ip::port_type in_port,
+            const std::string& out_host_and_port,
+            std::shared_ptr<message_listener> listener)
+            : m_in_acceptor(io_context, tcp::endpoint(tcp::v4(), in_port))
+            , m_listener(std::move(listener))
+        {
+            auto colon_pos = out_host_and_port.find(':');
+
+            if (colon_pos == std::string::npos) {
+                throw std::runtime_error("Incorrect host and part format. Expected 'hostname:port' but got " + out_host_and_port);
+            }
+
+            m_out_host = out_host_and_port.substr(0, colon_pos);
+            m_out_port = out_host_and_port.substr(colon_pos + 1);
+        }
+    };
+
+
+    void do_serve() {
+        for (auto& [_, entry]: m_conn_map) {
+            do_accept(entry);
+        }
+    }
+
+    void do_accept(proxy_entry& entry) {
+        if (m_stopped.load()) {
+            return;
+        }
+
+        entry.m_in_acceptor.async_accept([this, &entry](asio::error_code ec, tcp::socket in_sock) {
+            if (ec) {
+                throw std::runtime_error("Error accepting incoming connection " + ec.message());
+            }
+
+            auto p_in_sock = std::make_shared<tcp::socket>(std::move(in_sock));
+            auto p_out_sock = std::make_shared<tcp::socket>(m_io_context);
+            auto ses = std::make_shared<session>(p_in_sock, p_out_sock, entry.m_listener);
+
+            m_resolver.async_resolve(entry.m_out_host, entry.m_out_port,
+                [ses](asio::error_code ec, tcp::resolver::results_type endpoints) { // NOLINT(*-unnecessary-value-param)
+                    if (ec) {
+                        throw std::runtime_error("Error resolving server's address " + ec.message());
+                    }
+
+                    asio::async_connect(
+                        ses->get_out_sock(), endpoints, [ses](const asio::error_code &ec, const tcp::endpoint &e) {
+                            if (ec) {
+                                throw std::runtime_error(
+                                    "Error connecting to server " + ec.message()
+                                    + " port=" + std::to_string(e.port())
+                                );
+                            }
+
+                            ses->start();
+                        });

Review Comment:
   Why would it look alienated?



##########
modules/platforms/cpp/tests/fake_server/connection_test.cpp:
##########
@@ -76,3 +78,25 @@ TEST_F(connection_test, request_timeout) {
         EXPECT_EQ(error::code::OPERATION_TIMEOUT, err.get_status_code());
     }
 }
+
+TEST_F(connection_test, using_asio) {
+    fake_server fs{50900, get_logger()};
+    fs.start();
+
+    auto listener = std::make_shared<proxy::message_listener>();
+
+    proxy::asio_proxy proxy{
+        {proxy::configuration(50800, "127.0.0.1:50900", listener)}
+    };
+
+
+    ignite_client_configuration cfg;
+    cfg.set_logger(get_logger());
+    cfg.set_endpoints(get_endpoints());
+
+    auto cl = ignite_client::start(cfg, 5s);
+
+    auto cluster_nodes = cl.get_cluster_nodes();
+
+    ASSERT_EQ(1, cluster_nodes.size());

Review Comment:
   Probably no need to check for exact size - can cause flakiness because of heartbeats. Let's just check they are not empty.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2930665783


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,266 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        if (m_stopped.load())
+            return;
+
+        tcp::socket &src = direction == forward ? m_in_sock : m_out_sock;
+
+        auto self(shared_from_this());
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [direction, self](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            std::queue<message> &queue = direction == forward ? self->m_in_to_out : self->m_out_to_in;
+            bool &writable = direction == forward ? self->m_in_to_out_writable : self->m_out_to_in_writable;
+
+            // we have one-threaded executor no synchronization is needed
+            message& msg = queue.emplace(self->buf, len);
+
+            if (self->m_listener) {
+                if (direction == forward) {
+                    self->m_listener->register_out_message(msg);
+                } else {
+                    self->m_listener->register_in_message(msg);
+                }
+            }
+
+            if (writable) { // there are pending write operation on this socket
+                self->do_write(direction);
+            }
+
+            self->do_read(direction);
+        });
+    }
+
+    void do_write(direction direction) {
+        tcp::socket &dst = direction == forward ? m_out_sock : m_in_sock;
+        std::queue<message> &queue = direction == forward ? m_in_to_out : m_out_to_in;
+        bool &writable = direction == forward ? m_in_to_out_writable : m_out_to_in_writable;
+
+        writable = false; // protects from writing same buffer twice (from head of queue).
+
+        auto self(shared_from_this());
+        if (!queue.empty()) {
+            message &msg = queue.front();
+
+            asio::async_write(
+                dst, asio::buffer(msg.m_arr, msg.m_size),
+                [direction, self](asio::error_code ec, size_t) {
+                    if (ec) {
+                        if (ec == asio::error::eof) {
+                            return;
+                        }
+                        throw std::runtime_error("Error while writing to socket " + ec.message());
+                    }
+
+                    std::queue<message> &queue = direction == forward ? self->m_in_to_out : self->m_out_to_in;
+                    bool &writable = direction == forward ? self->m_in_to_out_writable : self->m_out_to_in_writable;
+
+                    queue.pop();
+
+                    if (!queue.empty()) {
+                        // makes writes on the same socket strictly ordered
+                        self->do_write(direction);
+                    } else {
+                        writable = true; // now read operation can initiate writes
+                    }
+                });
+        }
+    }
+
+    tcp::socket m_in_sock;
+    tcp::socket m_out_sock;
+
+    bool m_in_to_out_writable{false};
+    bool m_out_to_in_writable{false};
+
+    std::queue<message> m_in_to_out;
+    std::queue<message> m_out_to_in;
+
+    static constexpr size_t BUFF_SIZE = 4096;
+
+    char buf[BUFF_SIZE]{};

Review Comment:
   +



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2932764578


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2932766890


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }
+
+            self->do_write(std::move(m));
+        });
+    }
+
+    void do_write(message&& msg) {
+        asio::async_write(
+            *m_dst, asio::buffer(msg.data(), msg.size()),
+            [self = std::move(this->shared_from_this())](asio::error_code ec, size_t) {
+                if (ec) {
+                    if (ec == asio::error::eof) {
+                        return;
+                    }
+                    throw std::runtime_error("Error while writing to socket " + ec.message());
+                }
+
+                self->do_read();
+            });
+    }
+
+private:
+    std::shared_ptr<tcp::socket> m_src;
+    std::shared_ptr<tcp::socket> m_dst;
+    std::array<char, BUFF_SIZE> m_buf{};
+    std::shared_ptr<message_listener> m_listener{nullptr};
+

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2946203595


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,265 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+#include <gtest/gtest.h>
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_in_listener;
+    std::shared_ptr<message_listener> m_out_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> in_listener,
+        std::shared_ptr<message_listener> out_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_in_listener(std::move(in_listener))
+        , m_out_listener(std::move(out_listener)) {}
+};
+
+
+class session_part: public std::enable_shared_from_this<session_part> {
+public:
+    session_part(
+        std::shared_ptr<tcp::socket> src,
+        std::shared_ptr<tcp::socket> dst,
+        std::shared_ptr<message_listener> listener,
+        std::atomic_bool& failed
+        )
+        : m_src(std::move(src))
+        , m_dst(std::move(dst))
+        , m_listener(std::move(listener))
+        , m_failed(failed) {}
+
+    void do_read() {
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = this->shared_from_this()](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                std::cerr << "Error while reading from socket " << ec.message() << std::endl;

Review Comment:
   I'll fix it
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2933220659


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }

Review Comment:
   oh, well. I've decided to split
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "isapego (via GitHub)" <gi...@apache.org>.
isapego commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2932268476


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }
+
+            self->do_write(std::move(m));
+        });
+    }
+
+    void do_write(message&& msg) {
+        asio::async_write(
+            *m_dst, asio::buffer(msg.data(), msg.size()),
+            [self = std::move(this->shared_from_this())](asio::error_code ec, size_t) {
+                if (ec) {
+                    if (ec == asio::error::eof) {
+                        return;
+                    }
+                    throw std::runtime_error("Error while writing to socket " + ec.message());
+                }
+
+                self->do_read();
+            });
+    }
+
+private:
+    std::shared_ptr<tcp::socket> m_src;
+    std::shared_ptr<tcp::socket> m_dst;
+    std::array<char, BUFF_SIZE> m_buf{};
+    std::shared_ptr<message_listener> m_listener{nullptr};
+
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(
+        std::shared_ptr<tcp::socket> in_sock,
+        std::shared_ptr<tcp::socket> out_sock,

Review Comment:
   Suggestion (unnecessary): I'm not sure what is out and in for the socket. Are not they both in and out? Let's maybe call them something like server/client?



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }
+
+            self->do_write(std::move(m));
+        });
+    }
+
+    void do_write(message&& msg) {
+        asio::async_write(
+            *m_dst, asio::buffer(msg.data(), msg.size()),
+            [self = std::move(this->shared_from_this())](asio::error_code ec, size_t) {
+                if (ec) {
+                    if (ec == asio::error::eof) {
+                        return;
+                    }
+                    throw std::runtime_error("Error while writing to socket " + ec.message());
+                }
+
+                self->do_read();
+            });
+    }
+
+private:
+    std::shared_ptr<tcp::socket> m_src;
+    std::shared_ptr<tcp::socket> m_dst;
+    std::array<char, BUFF_SIZE> m_buf{};
+    std::shared_ptr<message_listener> m_listener{nullptr};
+
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(
+        std::shared_ptr<tcp::socket> in_sock,
+        std::shared_ptr<tcp::socket> out_sock,
+        std::shared_ptr<message_listener> listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+    {
+        m_forward_part = std::make_shared<session_part<direction::forward>>(m_in_sock, m_out_sock, listener);
+        m_reverse_part = std::make_shared<session_part<direction::reverse>>(m_out_sock, m_in_sock, listener);
+    }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return *m_out_sock; }
+
+private:
+    void do_serve() {
+        m_forward_part->do_read();
+        m_reverse_part->do_read();
+    }
+
+    std::shared_ptr<tcp::socket> m_in_sock;
+    std::shared_ptr<tcp::socket> m_out_sock;
+
+    std::shared_ptr<session_part<direction::forward>> m_forward_part;
+    std::shared_ptr<session_part<direction::reverse>> m_reverse_part;
+};
+
+class asio_proxy {
+public:
+    asio_proxy(std::vector<configuration> configurations)
+        : m_resolver(m_io_context)
+    {
+        for (auto &cfg : configurations) {
+            m_conn_map.emplace(
+                cfg.m_in_port,
+                proxy_entry{m_io_context, cfg.m_in_port, cfg.m_out_host_and_port, cfg.m_listener}
+            );
+        }
+
+        do_serve();
+
+        m_executor = std::make_unique<std::thread>([this]() {
+            m_io_context.run();
+        });
+    }
+
+    ~asio_proxy() {
+        m_stopped.store(true);
+        m_io_context.stop();
+
+        m_executor->join();
+    }
+
+private:
+    struct proxy_entry {
+        tcp::acceptor m_in_acceptor;
+        std::string m_out_host;
+        std::string m_out_port;
+        std::shared_ptr<message_listener> m_listener;
+
+        proxy_entry(
+            asio::io_context& io_context,
+            asio::ip::port_type in_port,
+            const std::string& out_host_and_port,
+            std::shared_ptr<message_listener> listener)
+            : m_in_acceptor(io_context, tcp::endpoint(tcp::v4(), in_port))
+            , m_listener(std::move(listener))
+        {
+            auto colon_pos = out_host_and_port.find(':');
+
+            if (colon_pos == std::string::npos) {
+                throw std::runtime_error("Incorrect host and part format. Expected 'hostname:port' but got " + out_host_and_port);
+            }
+
+            m_out_host = out_host_and_port.substr(0, colon_pos);
+            m_out_port = out_host_and_port.substr(colon_pos + 1);
+        }
+    };
+
+
+    void do_serve() {
+        for (auto& [_, entry]: m_conn_map) {
+            do_accept(entry);
+        }
+    }
+
+    void do_accept(proxy_entry& entry) {
+        if (m_stopped.load()) {
+            return;
+        }
+
+        entry.m_in_acceptor.async_accept([this, &entry](asio::error_code ec, tcp::socket in_sock) {
+            if (ec) {
+                throw std::runtime_error("Error accepting incoming connection " + ec.message());
+            }
+
+            auto p_in_sock = std::make_shared<tcp::socket>(std::move(in_sock));
+            auto p_out_sock = std::make_shared<tcp::socket>(m_io_context);
+            auto ses = std::make_shared<session>(p_in_sock, p_out_sock, entry.m_listener);
+
+            m_resolver.async_resolve(entry.m_out_host, entry.m_out_port,
+                [ses](asio::error_code ec, tcp::resolver::results_type endpoints) { // NOLINT(*-unnecessary-value-param)
+                    if (ec) {
+                        throw std::runtime_error("Error resolving server's address " + ec.message());
+                    }
+
+                    asio::async_connect(
+                        ses->get_out_sock(), endpoints, [ses](const asio::error_code &ec, const tcp::endpoint &e) {
+                            if (ec) {
+                                throw std::runtime_error(
+                                    "Error connecting to server " + ec.message()
+                                    + " port=" + std::to_string(e.port())
+                                );
+                            }
+
+                            ses->start();
+                        });

Review Comment:
   Suggestion: Maybe move this logic to `session` class? It seems like it should be `session::connect()`.



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,260 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <iostream>
+#include <queue>
+#include <tuple>
+#include <map>
+
+#include <asio.hpp>
+#include <asio/ts/buffer.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener)
+    { }
+
+    ~session() {
+        std::cout << "Session destructed " << this <<  std::endl;
+    }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        if (m_stopped.load())
+            return;
+
+        tcp::socket &src = direction == forward ? m_in_sock : m_out_sock;
+        std::queue<message> &queue = direction == forward ? m_in_to_out : m_out_to_in;
+        bool &writable = direction == forward ? m_in_to_out_writable : m_out_to_in_writable;
+
+        auto self(shared_from_this());
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [&queue, direction, &writable, self](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }

Review Comment:
   Let's maybe just close sockets and fail the test without closing the app?



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }
+
+            self->do_write(std::move(m));
+        });
+    }
+
+    void do_write(message&& msg) {
+        asio::async_write(
+            *m_dst, asio::buffer(msg.data(), msg.size()),

Review Comment:
   Minor: It seems like we quite often do `asio::buffer(msg.data(), msg.size())`. If we already have our own `message` type why not add a method to incapsulate this logic? Like:
   ```cpp
   asio::async_write(..., msg.as_asio_buffer(), ...);
   ```



##########
modules/platforms/cpp/tests/fake_server/connection_test.cpp:
##########
@@ -76,3 +78,25 @@ TEST_F(connection_test, request_timeout) {
         EXPECT_EQ(error::code::OPERATION_TIMEOUT, err.get_status_code());
     }
 }
+
+TEST_F(connection_test, using_asio) {
+    fake_server fs{50900, get_logger()};
+    fs.start();
+
+    auto listener = std::make_shared<proxy::message_listener>();
+
+    proxy::asio_proxy proxy{
+        {proxy::configuration(50800, "127.0.0.1:50900", listener)}
+    };
+
+
+    ignite_client_configuration cfg;
+    cfg.set_logger(get_logger());
+    cfg.set_endpoints(get_endpoints());
+
+    auto cl = ignite_client::start(cfg, 5s);
+
+    auto cluster_nodes = cl.get_cluster_nodes();
+
+    ASSERT_EQ(1, cluster_nodes.size());

Review Comment:
   Let's also check that our message queues in listener are not empty?



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}

Review Comment:
   Minor: 
   ```suggestion
       session_part(std::shared_ptr<tcp::socket> src, std::shared_ptr<tcp::socket> dst, std::shared_ptr<message_listener> listener)
           : m_src(std::move(src))
           , m_dst(std::move(dst))
           , m_listener(std::move(listener)) {}
   ```



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }
+
+            self->do_write(std::move(m));
+        });
+    }
+
+    void do_write(message&& msg) {
+        asio::async_write(
+            *m_dst, asio::buffer(msg.data(), msg.size()),
+            [self = std::move(this->shared_from_this())](asio::error_code ec, size_t) {
+                if (ec) {
+                    if (ec == asio::error::eof) {
+                        return;
+                    }
+                    throw std::runtime_error("Error while writing to socket " + ec.message());
+                }
+
+                self->do_read();
+            });
+    }
+
+private:
+    std::shared_ptr<tcp::socket> m_src;
+    std::shared_ptr<tcp::socket> m_dst;
+    std::array<char, BUFF_SIZE> m_buf{};
+    std::shared_ptr<message_listener> m_listener{nullptr};
+
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(
+        std::shared_ptr<tcp::socket> in_sock,
+        std::shared_ptr<tcp::socket> out_sock,
+        std::shared_ptr<message_listener> listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+    {
+        m_forward_part = std::make_shared<session_part<direction::forward>>(m_in_sock, m_out_sock, listener);
+        m_reverse_part = std::make_shared<session_part<direction::reverse>>(m_out_sock, m_in_sock, listener);

Review Comment:
   Suggestion (unnecessary): The same here: I'm actually not sure what is forward and what is reverse. I suppose forward is client -> server, but not sure. May as well be the other way around :) At least comment is required for the direction abstraction. Also, `server_part`, `client_part` seems understandable for me as well. I mean, it maybe makes it less generic, but we don't really need it to be very generic - we have our client/server use case.



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }
+
+            self->do_write(std::move(m));
+        });
+    }
+
+    void do_write(message&& msg) {
+        asio::async_write(
+            *m_dst, asio::buffer(msg.data(), msg.size()),
+            [self = std::move(this->shared_from_this())](asio::error_code ec, size_t) {

Review Comment:
   Minor: `std::move` is not needed in cases like this - the reference is already temporary here.
   ```suggestion
               [self = this->shared_from_this()](asio::error_code ec, size_t) {
   ```



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }

Review Comment:
   Looks like we actually need two listeners, and each part gets one. There are two queues in the listener anyway, and the `session_part` will be direction-agnostic in this case.



##########
modules/platforms/cpp/tests/fake_server/proxy/message.h:
##########
@@ -0,0 +1,62 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//
+
+#pragma once
+
+#include <cstring>
+#include <utility>
+
+namespace ignite::proxy {
+
+struct message {
+    char *m_arr{nullptr};
+    size_t m_size = 0;
+
+    friend void swap(message& lhs, message& rhs) noexcept {
+        using std::swap;
+        swap(lhs.m_arr, rhs.m_arr);
+        swap(lhs.m_size, rhs.m_size);
+    }
+
+    message(char *arr, size_t size)
+        : m_size(size)
+    {
+        m_arr = new char[m_size];
+        std::memcpy(m_arr, arr, size);
+    }

Review Comment:
   I mean, you can still have your own type, just put an `std::vector` inside, instead of raw memory.
   Also, you can make an alias:
   ```cpp
   using message = std::vector;
   ```
   



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";

Review Comment:
   Please, remove all usage of `std::cout`. It's ok to replace them with usage of `ignite_logger`, or just remove.



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }
+
+            self->do_write(std::move(m));
+        });
+    }
+
+    void do_write(message&& msg) {
+        asio::async_write(
+            *m_dst, asio::buffer(msg.data(), msg.size()),
+            [self = std::move(this->shared_from_this())](asio::error_code ec, size_t) {
+                if (ec) {
+                    if (ec == asio::error::eof) {
+                        return;
+                    }
+                    throw std::runtime_error("Error while writing to socket " + ec.message());
+                }
+
+                self->do_read();
+            });
+    }
+
+private:
+    std::shared_ptr<tcp::socket> m_src;
+    std::shared_ptr<tcp::socket> m_dst;
+    std::array<char, BUFF_SIZE> m_buf{};
+    std::shared_ptr<message_listener> m_listener{nullptr};
+
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(
+        std::shared_ptr<tcp::socket> in_sock,
+        std::shared_ptr<tcp::socket> out_sock,
+        std::shared_ptr<message_listener> listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+    {
+        m_forward_part = std::make_shared<session_part<direction::forward>>(m_in_sock, m_out_sock, listener);
+        m_reverse_part = std::make_shared<session_part<direction::reverse>>(m_out_sock, m_in_sock, listener);
+    }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return *m_out_sock; }
+
+private:
+    void do_serve() {
+        m_forward_part->do_read();
+        m_reverse_part->do_read();
+    }
+
+    std::shared_ptr<tcp::socket> m_in_sock;
+    std::shared_ptr<tcp::socket> m_out_sock;
+
+    std::shared_ptr<session_part<direction::forward>> m_forward_part;
+    std::shared_ptr<session_part<direction::reverse>> m_reverse_part;
+};
+
+class asio_proxy {
+public:
+    asio_proxy(std::vector<configuration> configurations)
+        : m_resolver(m_io_context)
+    {
+        for (auto &cfg : configurations) {
+            m_conn_map.emplace(
+                cfg.m_in_port,
+                proxy_entry{m_io_context, cfg.m_in_port, cfg.m_out_host_and_port, cfg.m_listener}
+            );
+        }
+
+        do_serve();
+
+        m_executor = std::make_unique<std::thread>([this]() {
+            m_io_context.run();
+        });
+    }
+
+    ~asio_proxy() {
+        m_stopped.store(true);
+        m_io_context.stop();
+
+        m_executor->join();
+    }
+
+private:
+    struct proxy_entry {
+        tcp::acceptor m_in_acceptor;
+        std::string m_out_host;
+        std::string m_out_port;
+        std::shared_ptr<message_listener> m_listener;
+
+        proxy_entry(
+            asio::io_context& io_context,
+            asio::ip::port_type in_port,
+            const std::string& out_host_and_port,

Review Comment:
   Why not accept host and port separately? This parsing part seem completely unnecessary while error-prone. 



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }
+
+            self->do_write(std::move(m));
+        });
+    }
+
+    void do_write(message&& msg) {
+        asio::async_write(
+            *m_dst, asio::buffer(msg.data(), msg.size()),
+            [self = std::move(this->shared_from_this())](asio::error_code ec, size_t) {
+                if (ec) {
+                    if (ec == asio::error::eof) {
+                        return;
+                    }
+                    throw std::runtime_error("Error while writing to socket " + ec.message());
+                }
+
+                self->do_read();
+            });
+    }
+
+private:
+    std::shared_ptr<tcp::socket> m_src;
+    std::shared_ptr<tcp::socket> m_dst;
+    std::array<char, BUFF_SIZE> m_buf{};
+    std::shared_ptr<message_listener> m_listener{nullptr};
+

Review Comment:
   Minor: Empty line :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2930657588


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,266 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;

Review Comment:
   Ok, but in this case lifetime of the object is clear, IMO



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2933278123


##########
modules/platforms/cpp/tests/fake_server/connection_test.cpp:
##########
@@ -76,3 +78,25 @@ TEST_F(connection_test, request_timeout) {
         EXPECT_EQ(error::code::OPERATION_TIMEOUT, err.get_status_code());
     }
 }
+
+TEST_F(connection_test, using_asio) {
+    fake_server fs{50900, get_logger()};
+    fs.start();
+
+    auto listener = std::make_shared<proxy::message_listener>();
+
+    proxy::asio_proxy proxy{
+        {proxy::configuration(50800, "127.0.0.1:50900", listener)}
+    };
+
+
+    ignite_client_configuration cfg;
+    cfg.set_logger(get_logger());
+    cfg.set_endpoints(get_endpoints());
+
+    auto cl = ignite_client::start(cfg, 5s);
+
+    auto cluster_nodes = cl.get_cluster_nodes();
+
+    ASSERT_EQ(1, cluster_nodes.size());

Review Comment:
   done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2946202595


##########
modules/platforms/cpp/tests/fake_server/connection_test.cpp:
##########
@@ -76,3 +78,25 @@ TEST_F(connection_test, request_timeout) {
         EXPECT_EQ(error::code::OPERATION_TIMEOUT, err.get_status_code());
     }
 }
+
+TEST_F(connection_test, using_asio) {
+    fake_server fs{50900, get_logger()};
+    fs.start();
+
+    auto listener = std::make_shared<proxy::message_listener>();
+
+    proxy::asio_proxy proxy{
+        {proxy::configuration(50800, "127.0.0.1:50900", listener)}
+    };
+
+
+    ignite_client_configuration cfg;
+    cfg.set_logger(get_logger());
+    cfg.set_endpoints(get_endpoints());
+
+    auto cl = ignite_client::start(cfg, 5s);
+
+    auto cluster_nodes = cl.get_cluster_nodes();
+
+    ASSERT_EQ(1, cluster_nodes.size());

Review Comment:
   Not sure what you are talking about. It is cluster size, later I've used ASSERT_GT, because at least 2 request would appear (handshake + how many nodes there) I don't see why It would be flaky.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2882968743


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,195 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <iostream>
+#include <queue>
+#include <tuple>
+
+#include <asio.hpp>
+#include <asio/ts/buffer.hpp>
+#include <asio/ts/internet.hpp>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct message {
+    char *m_arr;
+    size_t m_size;
+
+    message(char *arr, size_t size)
+        : m_arr(nullptr)
+        , m_size(size) {
+        m_arr = new char[m_size];
+        std::memcpy(m_arr, arr, size);
+    }
+
+    ~message() { delete[] m_arr; }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock)) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        auto tup = get_sockets_and_queue(direction);
+        tcp::socket &src = std::get<0>(tup);
+        std::queue<message> &queue = std::get<2>(tup);
+        bool &writable = std::get<3>(tup);
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [this, &queue, direction, &writable](asio::error_code ec, size_t len) {
+            if (ec) {
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            // we have one-threaded executor no synchronization is needed
+            queue.emplace(buf, len);
+
+            if (writable) { // there are pending write operation on this socket
+                do_write(direction);
+            }
+
+            do_read(direction);
+        });
+    }
+
+    void do_write(direction direction) {
+        auto tup = get_sockets_and_queue(direction);
+        tcp::socket &dst = std::get<1>(tup);
+        std::queue<message> &queue = std::get<2>(tup);
+        bool &writable = std::get<3>(tup);
+
+        writable = false; // protects from writing same buffer twice (from head of queue).
+
+        if (!queue.empty()) {
+            message &msg = queue.front();
+
+            asio::async_write(
+                dst, asio::buffer(msg.m_arr, msg.m_size), [this, &queue, direction, &writable](asio::error_code ec, size_t) {
+                    if (ec) {
+                        throw std::runtime_error("Error while writing to socket " + ec.message());
+                    }
+
+                    queue.pop();
+
+                    if (!queue.empty()) {
+                        // makes writes on the same socket strictly ordered
+                        do_write(direction);
+                    } else {
+                        writable = true; // now read operation can initiate writes
+                    }
+                });

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "isapego (via GitHub)" <gi...@apache.org>.
isapego commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2925165185


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,266 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        if (m_stopped.load())
+            return;
+
+        tcp::socket &src = direction == forward ? m_in_sock : m_out_sock;
+
+        auto self(shared_from_this());
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [direction, self](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            std::queue<message> &queue = direction == forward ? self->m_in_to_out : self->m_out_to_in;
+            bool &writable = direction == forward ? self->m_in_to_out_writable : self->m_out_to_in_writable;
+
+            // we have one-threaded executor no synchronization is needed
+            message& msg = queue.emplace(self->buf, len);
+
+            if (self->m_listener) {
+                if (direction == forward) {
+                    self->m_listener->register_out_message(msg);
+                } else {
+                    self->m_listener->register_in_message(msg);
+                }
+            }
+
+            if (writable) { // there are pending write operation on this socket
+                self->do_write(direction);
+            }
+
+            self->do_read(direction);
+        });
+    }
+
+    void do_write(direction direction) {
+        tcp::socket &dst = direction == forward ? m_out_sock : m_in_sock;
+        std::queue<message> &queue = direction == forward ? m_in_to_out : m_out_to_in;
+        bool &writable = direction == forward ? m_in_to_out_writable : m_out_to_in_writable;
+
+        writable = false; // protects from writing same buffer twice (from head of queue).
+
+        auto self(shared_from_this());
+        if (!queue.empty()) {
+            message &msg = queue.front();
+
+            asio::async_write(
+                dst, asio::buffer(msg.m_arr, msg.m_size),
+                [direction, self](asio::error_code ec, size_t) {
+                    if (ec) {
+                        if (ec == asio::error::eof) {
+                            return;
+                        }
+                        throw std::runtime_error("Error while writing to socket " + ec.message());
+                    }
+
+                    std::queue<message> &queue = direction == forward ? self->m_in_to_out : self->m_out_to_in;
+                    bool &writable = direction == forward ? self->m_in_to_out_writable : self->m_out_to_in_writable;
+
+                    queue.pop();
+
+                    if (!queue.empty()) {
+                        // makes writes on the same socket strictly ordered
+                        self->do_write(direction);
+                    } else {
+                        writable = true; // now read operation can initiate writes
+                    }
+                });
+        }
+    }
+
+    tcp::socket m_in_sock;
+    tcp::socket m_out_sock;
+
+    bool m_in_to_out_writable{false};
+    bool m_out_to_in_writable{false};
+
+    std::queue<message> m_in_to_out;
+    std::queue<message> m_out_to_in;
+
+    static constexpr size_t BUFF_SIZE = 4096;
+
+    char buf[BUFF_SIZE]{};

Review Comment:
   Let's use `std::array` here instead.



##########
modules/platforms/cpp/cmake/dependencies.cmake:
##########
@@ -43,6 +43,24 @@ function(fetch_dependency NAME URL MD5)
     endif()
 endfunction()
 
+function(add_asio_dependency)
+    message(STATUS "Download dependency: asio")
+
+    FetchContent_Declare(
+            asio
+            URL https://github.com/chriskohlhoff/asio/archive/refs/tags/asio-1-36-0.tar.gz
+            URL_HASH MD5=6699ac1dea111c20d024f25e06e573db

Review Comment:
   Yeah, let's actually do this.



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,266 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };

Review Comment:
   Let's use `enum class` instead
   ```suggestion
       enum class direction { forward, reverse };
   ```



##########
modules/platforms/cpp/tests/fake_server/proxy/message.h:
##########
@@ -0,0 +1,62 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//
+
+#pragma once
+
+#include <cstring>
+#include <utility>
+
+namespace ignite::proxy {
+
+struct message {
+    char *m_arr{nullptr};
+    size_t m_size = 0;
+
+    friend void swap(message& lhs, message& rhs) noexcept {
+        using std::swap;
+        swap(lhs.m_arr, rhs.m_arr);
+        swap(lhs.m_size, rhs.m_size);
+    }
+
+    message(char *arr, size_t size)
+        : m_size(size)
+    {
+        m_arr = new char[m_size];
+        std::memcpy(m_arr, arr, size);
+    }

Review Comment:
   I actually agree with copilot here. Why not using `std::vector`?



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,266 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        if (m_stopped.load())
+            return;
+
+        tcp::socket &src = direction == forward ? m_in_sock : m_out_sock;
+
+        auto self(shared_from_this());
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [direction, self](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            std::queue<message> &queue = direction == forward ? self->m_in_to_out : self->m_out_to_in;
+            bool &writable = direction == forward ? self->m_in_to_out_writable : self->m_out_to_in_writable;
+
+            // we have one-threaded executor no synchronization is needed
+            message& msg = queue.emplace(self->buf, len);

Review Comment:
   Wait, if every message refers to the same buffer, why do we even need a queue? Also, changing a buffer will affect all the messages, which does not look right to me. This logic here needs explanation.



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,260 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <iostream>
+#include <queue>
+#include <tuple>
+#include <map>
+
+#include <asio.hpp>
+#include <asio/ts/buffer.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener)
+    { }
+
+    ~session() {
+        std::cout << "Session destructed " << this <<  std::endl;
+    }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        if (m_stopped.load())
+            return;
+
+        tcp::socket &src = direction == forward ? m_in_sock : m_out_sock;
+        std::queue<message> &queue = direction == forward ? m_in_to_out : m_out_to_in;
+        bool &writable = direction == forward ? m_in_to_out_writable : m_out_to_in_writable;
+
+        auto self(shared_from_this());
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [&queue, direction, &writable, self](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }

Review Comment:
   Can you explain a bit? Why is it intended? Seems to me like read error is something that can happen and probably should not crash the process?



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,266 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        if (m_stopped.load())
+            return;

Review Comment:
   Why do we even need this flag here? What will happen if we remove it?



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,266 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;

Review Comment:
   Let's use `std::shared_ptr` here to avoid unnecessary debugging in future.
   
   ```suggestion
       std::shared_ptr<message_listener> m_listener;
   ```



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,266 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {

Review Comment:
   It's better not to name variable the same name as class - though it should work OK, in reality it may confuse some compilers in some cases and you will spend a long time figuring it out.



##########
modules/platforms/cpp/cmake/dependencies.cmake:
##########
@@ -76,6 +99,7 @@ else()
     fetch_dependency(uni-algo https://github.com/uni-algo/uni-algo/archive/v1.2.0.tar.gz 6e0cce94a6b45ebee7b904316df9f87f)
     if (${ENABLE_TESTS})
         fetch_dependency(googletest https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz c8340a482851ef6a3fe618a082304cfc)
+        add_asio_dependency(https://github.com/chriskohlhoff/asio/archive/refs/tags/asio-1-36-0.tar.gz 6699ac1dea111c20d024f25e06e573db)
     endif()

Review Comment:
   Why? Can you please clarify? Seems valid to me.



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,266 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        if (m_stopped.load())
+            return;
+
+        tcp::socket &src = direction == forward ? m_in_sock : m_out_sock;
+
+        auto self(shared_from_this());
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [direction, self](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            std::queue<message> &queue = direction == forward ? self->m_in_to_out : self->m_out_to_in;
+            bool &writable = direction == forward ? self->m_in_to_out_writable : self->m_out_to_in_writable;
+
+            // we have one-threaded executor no synchronization is needed
+            message& msg = queue.emplace(self->buf, len);
+
+            if (self->m_listener) {
+                if (direction == forward) {
+                    self->m_listener->register_out_message(msg);
+                } else {
+                    self->m_listener->register_in_message(msg);
+                }
+            }
+
+            if (writable) { // there are pending write operation on this socket
+                self->do_write(direction);
+            }
+
+            self->do_read(direction);
+        });
+    }
+
+    void do_write(direction direction) {
+        tcp::socket &dst = direction == forward ? m_out_sock : m_in_sock;
+        std::queue<message> &queue = direction == forward ? m_in_to_out : m_out_to_in;
+        bool &writable = direction == forward ? m_in_to_out_writable : m_out_to_in_writable;
+
+        writable = false; // protects from writing same buffer twice (from head of queue).
+
+        auto self(shared_from_this());
+        if (!queue.empty()) {
+            message &msg = queue.front();

Review Comment:
   Why not store messages as `std::shared_ptr`'s and pop them here right away? Won't it solve the issue and make `writable` flag unnecessary?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2930673978


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,266 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2931040056


##########
modules/platforms/cpp/cmake/dependencies.cmake:
##########
@@ -76,6 +99,7 @@ else()
     fetch_dependency(uni-algo https://github.com/uni-algo/uni-algo/archive/v1.2.0.tar.gz 6e0cce94a6b45ebee7b904316df9f87f)
     if (${ENABLE_TESTS})
         fetch_dependency(googletest https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz c8340a482851ef6a3fe618a082304cfc)
+        add_asio_dependency(https://github.com/chriskohlhoff/asio/archive/refs/tags/asio-1-36-0.tar.gz 6699ac1dea111c20d024f25e06e573db)
     endif()

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2932779034


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }
+
+            self->do_write(std::move(m));
+        });
+    }
+
+    void do_write(message&& msg) {
+        asio::async_write(
+            *m_dst, asio::buffer(msg.data(), msg.size()),
+            [self = std::move(this->shared_from_this())](asio::error_code ec, size_t) {

Review Comment:
   yep



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "isapego (via GitHub)" <gi...@apache.org>.
isapego commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2943759105


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }
+
+            self->do_write(std::move(m));
+        });
+    }
+
+    void do_write(message&& msg) {
+        asio::async_write(
+            *m_dst, asio::buffer(msg.data(), msg.size()),
+            [self = std::move(this->shared_from_this())](asio::error_code ec, size_t) {
+                if (ec) {
+                    if (ec == asio::error::eof) {
+                        return;
+                    }
+                    throw std::runtime_error("Error while writing to socket " + ec.message());
+                }
+
+                self->do_read();
+            });
+    }
+
+private:
+    std::shared_ptr<tcp::socket> m_src;
+    std::shared_ptr<tcp::socket> m_dst;
+    std::array<char, BUFF_SIZE> m_buf{};
+    std::shared_ptr<message_listener> m_listener{nullptr};
+
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(
+        std::shared_ptr<tcp::socket> in_sock,
+        std::shared_ptr<tcp::socket> out_sock,
+        std::shared_ptr<message_listener> listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+    {
+        m_forward_part = std::make_shared<session_part<direction::forward>>(m_in_sock, m_out_sock, listener);
+        m_reverse_part = std::make_shared<session_part<direction::reverse>>(m_out_sock, m_in_sock, listener);
+    }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return *m_out_sock; }
+
+private:
+    void do_serve() {
+        m_forward_part->do_read();
+        m_reverse_part->do_read();
+    }
+
+    std::shared_ptr<tcp::socket> m_in_sock;
+    std::shared_ptr<tcp::socket> m_out_sock;
+
+    std::shared_ptr<session_part<direction::forward>> m_forward_part;
+    std::shared_ptr<session_part<direction::reverse>> m_reverse_part;
+};
+
+class asio_proxy {
+public:
+    asio_proxy(std::vector<configuration> configurations)
+        : m_resolver(m_io_context)
+    {
+        for (auto &cfg : configurations) {
+            m_conn_map.emplace(
+                cfg.m_in_port,
+                proxy_entry{m_io_context, cfg.m_in_port, cfg.m_out_host_and_port, cfg.m_listener}
+            );
+        }
+
+        do_serve();
+
+        m_executor = std::make_unique<std::thread>([this]() {
+            m_io_context.run();
+        });
+    }
+
+    ~asio_proxy() {
+        m_stopped.store(true);
+        m_io_context.stop();
+
+        m_executor->join();
+    }
+
+private:
+    struct proxy_entry {
+        tcp::acceptor m_in_acceptor;
+        std::string m_out_host;
+        std::string m_out_port;
+        std::shared_ptr<message_listener> m_listener;
+
+        proxy_entry(
+            asio::io_context& io_context,
+            asio::ip::port_type in_port,
+            const std::string& out_host_and_port,

Review Comment:
   Ok, though in my opinion, concatenate two strings is much easier and less error-prone than parsing a single string into 3 parts. But since this is test, it's acceptable I guess.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2932795500


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }
+
+            self->do_write(std::move(m));
+        });
+    }
+
+    void do_write(message&& msg) {
+        asio::async_write(
+            *m_dst, asio::buffer(msg.data(), msg.size()),
+            [self = std::move(this->shared_from_this())](asio::error_code ec, size_t) {
+                if (ec) {
+                    if (ec == asio::error::eof) {
+                        return;
+                    }
+                    throw std::runtime_error("Error while writing to socket " + ec.message());
+                }
+
+                self->do_read();
+            });
+    }
+
+private:
+    std::shared_ptr<tcp::socket> m_src;
+    std::shared_ptr<tcp::socket> m_dst;
+    std::array<char, BUFF_SIZE> m_buf{};
+    std::shared_ptr<message_listener> m_listener{nullptr};
+
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(
+        std::shared_ptr<tcp::socket> in_sock,
+        std::shared_ptr<tcp::socket> out_sock,
+        std::shared_ptr<message_listener> listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+    {
+        m_forward_part = std::make_shared<session_part<direction::forward>>(m_in_sock, m_out_sock, listener);
+        m_reverse_part = std::make_shared<session_part<direction::reverse>>(m_out_sock, m_in_sock, listener);
+    }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return *m_out_sock; }
+
+private:
+    void do_serve() {
+        m_forward_part->do_read();
+        m_reverse_part->do_read();
+    }
+
+    std::shared_ptr<tcp::socket> m_in_sock;
+    std::shared_ptr<tcp::socket> m_out_sock;
+
+    std::shared_ptr<session_part<direction::forward>> m_forward_part;
+    std::shared_ptr<session_part<direction::reverse>> m_reverse_part;
+};
+
+class asio_proxy {
+public:
+    asio_proxy(std::vector<configuration> configurations)
+        : m_resolver(m_io_context)
+    {
+        for (auto &cfg : configurations) {
+            m_conn_map.emplace(
+                cfg.m_in_port,
+                proxy_entry{m_io_context, cfg.m_in_port, cfg.m_out_host_and_port, cfg.m_listener}
+            );
+        }
+
+        do_serve();
+
+        m_executor = std::make_unique<std::thread>([this]() {
+            m_io_context.run();
+        });
+    }
+
+    ~asio_proxy() {
+        m_stopped.store(true);
+        m_io_context.stop();
+
+        m_executor->join();
+    }
+
+private:
+    struct proxy_entry {
+        tcp::acceptor m_in_acceptor;
+        std::string m_out_host;
+        std::string m_out_port;
+        std::shared_ptr<message_listener> m_listener;
+
+        proxy_entry(
+            asio::io_context& io_context,
+            asio::ip::port_type in_port,
+            const std::string& out_host_and_port,

Review Comment:
   This is done for usability purposes. User of this class can reuse address list for ignite_client.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "isapego (via GitHub)" <gi...@apache.org>.
isapego commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2925267249


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,266 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        if (m_stopped.load())
+            return;
+
+        tcp::socket &src = direction == forward ? m_in_sock : m_out_sock;
+
+        auto self(shared_from_this());
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [direction, self](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            std::queue<message> &queue = direction == forward ? self->m_in_to_out : self->m_out_to_in;
+            bool &writable = direction == forward ? self->m_in_to_out_writable : self->m_out_to_in_writable;

Review Comment:
   Looks like we should just have two instances of contexts structures. Something like:
   ```cpp
   struct session_context {
       tcp::socket m_sock;
       bool m_writable{false};
       std::queue<message> m_incoming_messages;
       std::array<char, BUFF_SIZE> buf;
   
       void do_read() { /*...*/ }
       void do_write() { /*...*/ }
   };
   
   // ...
   
   session_context m_client;
   session_context m_server;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2933105755


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }
+
+            self->do_write(std::move(m));
+        });
+    }
+
+    void do_write(message&& msg) {
+        asio::async_write(
+            *m_dst, asio::buffer(msg.data(), msg.size()),
+            [self = std::move(this->shared_from_this())](asio::error_code ec, size_t) {
+                if (ec) {
+                    if (ec == asio::error::eof) {
+                        return;
+                    }
+                    throw std::runtime_error("Error while writing to socket " + ec.message());
+                }
+
+                self->do_read();
+            });
+    }
+
+private:
+    std::shared_ptr<tcp::socket> m_src;
+    std::shared_ptr<tcp::socket> m_dst;
+    std::array<char, BUFF_SIZE> m_buf{};
+    std::shared_ptr<message_listener> m_listener{nullptr};
+
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(
+        std::shared_ptr<tcp::socket> in_sock,
+        std::shared_ptr<tcp::socket> out_sock,

Review Comment:
   In my head 'in' means someone connects to proxy, 'out' proxy connects to someone.
   Flow of data aka direction: in -> out: forward, out -> in: reverse.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2933117593


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }
+
+            self->do_write(std::move(m));
+        });
+    }
+
+    void do_write(message&& msg) {
+        asio::async_write(
+            *m_dst, asio::buffer(msg.data(), msg.size()),
+            [self = std::move(this->shared_from_this())](asio::error_code ec, size_t) {
+                if (ec) {
+                    if (ec == asio::error::eof) {
+                        return;
+                    }
+                    throw std::runtime_error("Error while writing to socket " + ec.message());
+                }
+
+                self->do_read();
+            });
+    }
+
+private:
+    std::shared_ptr<tcp::socket> m_src;
+    std::shared_ptr<tcp::socket> m_dst;
+    std::array<char, BUFF_SIZE> m_buf{};
+    std::shared_ptr<message_listener> m_listener{nullptr};
+
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(
+        std::shared_ptr<tcp::socket> in_sock,
+        std::shared_ptr<tcp::socket> out_sock,
+        std::shared_ptr<message_listener> listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+    {
+        m_forward_part = std::make_shared<session_part<direction::forward>>(m_in_sock, m_out_sock, listener);
+        m_reverse_part = std::make_shared<session_part<direction::reverse>>(m_out_sock, m_in_sock, listener);

Review Comment:
   I tried to not to use server/client parts, because proxy can be used for other modes e.g server/server connections.
   We always have incoming connection (someone  connected to proxy) and corresponding related outgoing connection (proxy establish connection according to mapping).
   Would you like more:
   dirrection::forward => direction::in_to_out
   dirrection::reverse => direction::out_to_in



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2930673409


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,266 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2931128927


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,266 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        if (m_stopped.load())
+            return;

Review Comment:
   no more needed, removed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2930673409


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,266 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };

Review Comment:
   +



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,266 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {

Review Comment:
   +



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2946190676


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,248 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message_listener.h"
+
+#include <list>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+static constexpr size_t BUFF_SIZE = 4096;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    std::shared_ptr<message_listener> m_listener;
+
+    configuration(
+        asio::ip::port_type m_in_port,
+        const std::string &m_out_host_and_port,
+        std::shared_ptr<message_listener> m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(std::move(m_listener)) { }
+};
+
+enum class direction { forward, reverse };
+
+template<direction DIRECTION>
+class session_part: public std::enable_shared_from_this<session_part<DIRECTION>> {
+public:
+    session_part(std::shared_ptr<tcp::socket> m_src, std::shared_ptr<tcp::socket> m_dst, std::shared_ptr<message_listener> listener)
+        : m_src(std::move(m_src))
+        , m_dst(std::move(m_dst))
+        , m_listener(std::move(listener)) {}
+
+    void do_read() {
+        std::cout << "Reading from socket\n";
+
+        m_src->async_read_some(asio::buffer(m_buf, BUFF_SIZE),
+        [self = std::move(this->shared_from_this())](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            message m{self->m_buf.begin(), self->m_buf.begin() + len};
+
+            if (self->m_listener) {
+                if constexpr (DIRECTION == direction::forward) {
+                    self->m_listener->register_out_message(m);
+                } else {
+                    self->m_listener->register_in_message(m);
+                }
+            }
+
+            self->do_write(std::move(m));
+        });
+    }
+
+    void do_write(message&& msg) {
+        asio::async_write(
+            *m_dst, asio::buffer(msg.data(), msg.size()),
+            [self = std::move(this->shared_from_this())](asio::error_code ec, size_t) {
+                if (ec) {
+                    if (ec == asio::error::eof) {
+                        return;
+                    }
+                    throw std::runtime_error("Error while writing to socket " + ec.message());
+                }
+
+                self->do_read();
+            });
+    }
+
+private:
+    std::shared_ptr<tcp::socket> m_src;
+    std::shared_ptr<tcp::socket> m_dst;
+    std::array<char, BUFF_SIZE> m_buf{};
+    std::shared_ptr<message_listener> m_listener{nullptr};
+
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(
+        std::shared_ptr<tcp::socket> in_sock,
+        std::shared_ptr<tcp::socket> out_sock,
+        std::shared_ptr<message_listener> listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+    {
+        m_forward_part = std::make_shared<session_part<direction::forward>>(m_in_sock, m_out_sock, listener);
+        m_reverse_part = std::make_shared<session_part<direction::reverse>>(m_out_sock, m_in_sock, listener);
+    }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return *m_out_sock; }
+
+private:
+    void do_serve() {
+        m_forward_part->do_read();
+        m_reverse_part->do_read();
+    }
+
+    std::shared_ptr<tcp::socket> m_in_sock;
+    std::shared_ptr<tcp::socket> m_out_sock;
+
+    std::shared_ptr<session_part<direction::forward>> m_forward_part;
+    std::shared_ptr<session_part<direction::reverse>> m_reverse_part;
+};
+
+class asio_proxy {
+public:
+    asio_proxy(std::vector<configuration> configurations)
+        : m_resolver(m_io_context)
+    {
+        for (auto &cfg : configurations) {
+            m_conn_map.emplace(
+                cfg.m_in_port,
+                proxy_entry{m_io_context, cfg.m_in_port, cfg.m_out_host_and_port, cfg.m_listener}
+            );
+        }
+
+        do_serve();
+
+        m_executor = std::make_unique<std::thread>([this]() {
+            m_io_context.run();
+        });
+    }
+
+    ~asio_proxy() {
+        m_stopped.store(true);
+        m_io_context.stop();
+
+        m_executor->join();
+    }
+
+private:
+    struct proxy_entry {
+        tcp::acceptor m_in_acceptor;
+        std::string m_out_host;
+        std::string m_out_port;
+        std::shared_ptr<message_listener> m_listener;
+
+        proxy_entry(
+            asio::io_context& io_context,
+            asio::ip::port_type in_port,
+            const std::string& out_host_and_port,
+            std::shared_ptr<message_listener> listener)
+            : m_in_acceptor(io_context, tcp::endpoint(tcp::v4(), in_port))
+            , m_listener(std::move(listener))
+        {
+            auto colon_pos = out_host_and_port.find(':');
+
+            if (colon_pos == std::string::npos) {
+                throw std::runtime_error("Incorrect host and part format. Expected 'hostname:port' but got " + out_host_and_port);
+            }
+
+            m_out_host = out_host_and_port.substr(0, colon_pos);
+            m_out_port = out_host_and_port.substr(colon_pos + 1);
+        }
+    };
+
+
+    void do_serve() {
+        for (auto& [_, entry]: m_conn_map) {
+            do_accept(entry);
+        }
+    }
+
+    void do_accept(proxy_entry& entry) {
+        if (m_stopped.load()) {
+            return;
+        }
+
+        entry.m_in_acceptor.async_accept([this, &entry](asio::error_code ec, tcp::socket in_sock) {
+            if (ec) {
+                throw std::runtime_error("Error accepting incoming connection " + ec.message());
+            }
+
+            auto p_in_sock = std::make_shared<tcp::socket>(std::move(in_sock));
+            auto p_out_sock = std::make_shared<tcp::socket>(m_io_context);
+            auto ses = std::make_shared<session>(p_in_sock, p_out_sock, entry.m_listener);
+
+            m_resolver.async_resolve(entry.m_out_host, entry.m_out_port,
+                [ses](asio::error_code ec, tcp::resolver::results_type endpoints) { // NOLINT(*-unnecessary-value-param)
+                    if (ec) {
+                        throw std::runtime_error("Error resolving server's address " + ec.message());
+                    }
+
+                    asio::async_connect(
+                        ses->get_out_sock(), endpoints, [ses](const asio::error_code &ec, const tcp::endpoint &e) {
+                            if (ec) {
+                                throw std::runtime_error(
+                                    "Error connecting to server " + ec.message()
+                                    + " port=" + std::to_string(e.port())
+                                );
+                            }
+
+                            ses->start();
+                        });

Review Comment:
   It is would like as first part of the session (client -> proxy) is handled by proxy_itself, but second one (proxy->server) would be handled by session. For me it is inconsistent.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2882869699


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,195 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <iostream>
+#include <queue>
+#include <tuple>
+
+#include <asio.hpp>
+#include <asio/ts/buffer.hpp>
+#include <asio/ts/internet.hpp>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct message {
+    char *m_arr;
+    size_t m_size;
+
+    message(char *arr, size_t size)
+        : m_arr(nullptr)
+        , m_size(size) {
+        m_arr = new char[m_size];
+        std::memcpy(m_arr, arr, size);
+    }
+
+    ~message() { delete[] m_arr; }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock)) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        auto tup = get_sockets_and_queue(direction);
+        tcp::socket &src = std::get<0>(tup);
+        std::queue<message> &queue = std::get<2>(tup);
+        bool &writable = std::get<3>(tup);
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [this, &queue, direction, &writable](asio::error_code ec, size_t len) {
+            if (ec) {
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            // we have one-threaded executor no synchronization is needed
+            queue.emplace(buf, len);
+
+            if (writable) { // there are pending write operation on this socket
+                do_write(direction);
+            }
+
+            do_read(direction);
+        });

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Erixonich (via GitHub)" <gi...@apache.org>.
Erixonich commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2884680974


##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,271 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include <asio.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "message.h"
+#include "message_listener.h"
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct configuration {
+    asio::ip::port_type m_in_port;
+    std::string m_out_host_and_port;
+    message_listener* m_listener;
+
+    configuration(asio::ip::port_type m_in_port, const std::string &m_out_host_and_port, message_listener *m_listener)
+        : m_in_port(m_in_port)
+        , m_out_host_and_port(m_out_host_and_port)
+        , m_listener(m_listener) { }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock, std::atomic_bool& stopped, message_listener* listener)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock))
+        , m_stopped(stopped)
+        , m_listener(listener)
+    { }
+
+    ~session() {
+        std::cout << "Session destructed " << this <<  std::endl;
+    }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        if (m_stopped.load())
+            return;
+
+        tcp::socket &src = direction == forward ? m_in_sock : m_out_sock;
+
+        auto self(shared_from_this());
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [direction, self](const asio::error_code& ec, size_t len) {
+            if (ec) {
+                if (ec == asio::error::eof) {
+                    return;
+                }
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            std::queue<message> &queue = direction == forward ? self->m_in_to_out : self->m_out_to_in;
+            bool &writable = direction == forward ? self->m_in_to_out_writable : self->m_out_to_in_writable;
+
+            // we have one-threaded executor no synchronization is needed
+            message& msg = queue.emplace(self->buf, len);
+
+            if (self->m_listener) {
+                if (direction == forward) {
+                    self->m_listener->register_out_message(msg);
+                } else {
+                    self->m_listener->register_in_message(msg);
+                }
+            }
+
+            if (writable) { // there are pending write operation on this socket
+                self->do_write(direction);
+            }
+
+            self->do_read(direction);
+        });
+    }
+
+    void do_write(direction direction) {
+        tcp::socket &dst = direction == forward ? m_out_sock : m_in_sock;
+        std::queue<message> &queue = direction == forward ? m_in_to_out : m_out_to_in;
+        bool &writable = direction == forward ? m_in_to_out_writable : m_out_to_in_writable;
+
+        writable = false; // protects from writing same buffer twice (from head of queue).
+
+        auto self(shared_from_this());
+        if (!queue.empty()) {
+            message &msg = queue.front();
+
+            asio::async_write(
+                dst, asio::buffer(msg.m_arr, msg.m_size),
+                [direction, self](asio::error_code ec, size_t) {
+                    if (ec) {
+                        if (ec == asio::error::eof) {
+                            return;
+                        }
+                        throw std::runtime_error("Error while writing to socket " + ec.message());

Review Comment:
   intended



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27870 added proxy class. [ignite-3]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #7607:
URL: https://github.com/apache/ignite-3/pull/7607#discussion_r2829772091


##########
modules/platforms/cpp/cmake/dependencies.cmake:
##########
@@ -43,6 +43,29 @@ function(fetch_dependency NAME URL MD5)
     endif()
 endfunction()
 
+function(add_asio_dependency)
+    message(STATUS "Download dependency: asio")
+#    FetchContent_Declare(
+#            asio
+#            GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git
+#            GIT_TAG asio-1-36-0
+#    )

Review Comment:
   Commented-out code should be removed rather than left in the codebase. If this alternative implementation using GIT_REPOSITORY is needed for reference, consider documenting it in a comment or external documentation instead.
   ```suggestion
   
   ```



##########
modules/platforms/cpp/tests/fake_server/proxy/kgb_proxy.cpp:
##########
@@ -0,0 +1,290 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//
+
+#include "kgb_proxy.h"
+
+#include <ignite/network/detail/linux/sockets.h>
+
+#include <fcntl.h>
+#include <iostream>
+#include <cstring>
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/epoll.h>
+#include <sys/eventfd.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+namespace ignite::proxy {
+
+void set_socket_non_blocking(int fd) {
+    using network::detail::set_non_blocking_mode;
+
+    if (!set_non_blocking_mode(fd, true)) {
+        throw std::runtime_error("Error making socket non-blocking");
+    }
+}
+
+void kgb_proxy::enable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);
+}
+
+void kgb_proxy::disable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);
+}
+
+void kgb_proxy::do_serve() {
+    epoll_event events[MAX_EVENTS];
+
+    bool stopped = false;
+    while (!stopped) {
+        int event_cnt = epoll_wait(epoll_fd, events, MAX_EVENTS, -1);
+
+        for (int i = 0; i < event_cnt; ++i) {
+            int fd = events[i].data.fd;
+
+            if (fd == stop_event_fd) {
+                uint64_t val;
+                read(stop_event_fd, &val, sizeof(val));
+                stopped = true;
+            } else if (fd == server_fd) {
+                process_incoming_connection();
+            } else {
+                process_socket_event(events[i]);
+            }
+        }
+    }
+}
+
+void kgb_proxy::add_event_fd() {
+    stop_event_fd = eventfd(0, EFD_NONBLOCK);
+
+    epoll_event ev{};
+    ev.events = EPOLLIN;
+    ev.data.fd = stop_event_fd;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, stop_event_fd, &ev);
+}
+
+void kgb_proxy::fire_stop_event() { // NOLINT(*-make-member-function-const)
+    uint64_t one = 1;
+    write(stop_event_fd, &one, sizeof(one));
+}
+
+void kgb_proxy::start_server_socket() {
+    server_fd = socket(AF_INET, SOCK_STREAM, 0);
+    set_socket_non_blocking(server_fd);
+
+    int opt = 1;
+    setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+
+    sockaddr_in addr{};
+
+    addr.sin_family = AF_INET;
+    addr.sin_port = htons(in_port);
+    addr.sin_addr.s_addr = INADDR_ANY;
+
+    bind(server_fd, (sockaddr *) &addr, sizeof(addr));
+    listen(server_fd, 16);
+
+    epoll_event ev{};
+
+    ev.events = EPOLLIN;
+    ev.data.fd = server_fd;
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, server_fd, &ev);
+}
+
+void kgb_proxy::add_socket_to_epoll(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ev{};
+    ev.events = EPOLLIN | EPOLLET;
+    ev.data.fd = fd;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ev);
+}
+
+void kgb_proxy::process_incoming_connection() {
+    while (true) {
+        int in_fd;
+        {
+            sockaddr_in addr{};
+            socklen_t len = sizeof(addr);
+
+            in_fd = accept(server_fd, (sockaddr*) &addr, &len);
+
+            if (in_fd < 0) {
+                if (errno != EAGAIN) {
+                    std::error_code ec{errno, std::system_category()};
+                    std::cerr << "Unexpected issue when accepting connection err=" << ec.message() << "\n";
+                }
+                break;
+            }
+
+            set_socket_non_blocking(in_fd);
+
+            std::cout << "Client connected to proxy fd = " << in_fd << std::endl;
+        }
+
+        int out_fd;
+        {
+            out_fd = socket(AF_INET, SOCK_STREAM, 0);
+
+            set_socket_non_blocking(out_fd);
+
+            if (out_fd < 0) {
+                std::error_code ec{errno, std::system_category()};
+                throw std::runtime_error("Unable to create socket for outbound proxy connection err = " + ec.message());
+            }
+
+            sockaddr_in addr{};
+            addr.sin_family = AF_INET;
+            addr.sin_port = htons(out_port);
+
+            inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
+
+            int res = connect(out_fd, (sockaddr*) &addr, sizeof(addr));
+
+            if (res < 0) {
+                if (errno != EINPROGRESS) {
+                    std::error_code ec{errno, std::system_category()};
+                    throw std::runtime_error("Unable to connection to server err = " + ec.message());
+                }
+            }
+
+            std::cout << "Proxy connected to server fd = " << out_fd << std::endl;
+        }
+
+        std::shared_ptr<proxy_connection> conn = std::make_shared<proxy_connection>(in_fd, out_fd);
+
+        connections[in_fd] = conn;
+        connections[out_fd] = conn;
+
+        add_socket_to_epoll(in_fd);
+        add_socket_to_epoll(out_fd);
+
+        std::cout << "Socket pair has been created in_fd = " << in_fd << " out_fd = " << out_fd << std::endl;
+    }
+}
+
+void kgb_proxy::process_socket_event(const epoll_event& ep_ev) {
+    int fd = ep_ev.data.fd;
+
+    auto it = connections.find(fd);
+    if (it == connections.end()) {
+        throw std::runtime_error("Event for unknown socket occurred fd = " + std::to_string(fd));
+    }
+
+    auto conn = it->second;
+
+    if (ep_ev.events & EPOLLIN) {
+
+        char buf[BUFF_SIZE];
+
+        int src = fd;
+        int dst = src == conn->in_sock ? conn->out_sock : conn->in_sock;
+
+        while (true) {
+            ssize_t received = recv(src, buf, sizeof(buf), 0);
+
+            if (received < 0) {
+                if (errno == EAGAIN || errno == EWOULDBLOCK) {
+                    break;
+                }
+
+                perror("recv");
+                break;
+
+            }
+
+            if (received == 0) {
+                close(src);
+                close(dst);
+
+                connections.erase(src);
+                connections.erase(dst);
+                break;
+            }
+
+            auto& queue = src == conn->in_sock ? conn->in2out_queue : conn->out2in_queue;
+            queue.emplace(buf, received);
+
+            enable_writable_notification(dst);
+        }
+    }
+
+    if (ep_ev.events & EPOLLOUT) {
+        int dst = fd;
+        int src = dst == conn->in_sock ? conn->out_sock : conn->in_sock;
+
+        auto& queue = src == conn->in_sock ? conn->in2out_queue : conn->out2in_queue;
+
+        while (!queue.empty()) {
+
+            const message_chunk& chunk = queue.front();
+            ssize_t sent = send(dst, chunk.m_msg, chunk.m_size, 0);
+
+            if (sent <= 0) {
+                if (errno == EAGAIN || errno == EWOULDBLOCK) {
+                    break;
+                }
+
+                perror("send");
+                break;
+            }
+
+            queue.pop();

Review Comment:
   Potential partial send issue: send() may send fewer bytes than requested. The code assumes all bytes are sent in one call (line 249), but send() can return a value less than chunk.m_size. This could lead to incomplete message transmission. The message_chunk should track how many bytes have been sent and retry sending the remaining bytes.



##########
modules/platforms/cpp/tests/fake_server/proxy/kgb_proxy.cpp:
##########
@@ -0,0 +1,290 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//
+
+#include "kgb_proxy.h"
+
+#include <ignite/network/detail/linux/sockets.h>
+
+#include <fcntl.h>
+#include <iostream>
+#include <cstring>
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/epoll.h>
+#include <sys/eventfd.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+namespace ignite::proxy {
+
+void set_socket_non_blocking(int fd) {
+    using network::detail::set_non_blocking_mode;
+
+    if (!set_non_blocking_mode(fd, true)) {
+        throw std::runtime_error("Error making socket non-blocking");
+    }
+}
+
+void kgb_proxy::enable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);
+}
+
+void kgb_proxy::disable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);
+}
+
+void kgb_proxy::do_serve() {
+    epoll_event events[MAX_EVENTS];
+
+    bool stopped = false;
+    while (!stopped) {
+        int event_cnt = epoll_wait(epoll_fd, events, MAX_EVENTS, -1);
+
+        for (int i = 0; i < event_cnt; ++i) {
+            int fd = events[i].data.fd;
+
+            if (fd == stop_event_fd) {
+                uint64_t val;
+                read(stop_event_fd, &val, sizeof(val));
+                stopped = true;
+            } else if (fd == server_fd) {
+                process_incoming_connection();
+            } else {
+                process_socket_event(events[i]);
+            }
+        }
+    }
+}
+
+void kgb_proxy::add_event_fd() {
+    stop_event_fd = eventfd(0, EFD_NONBLOCK);
+
+    epoll_event ev{};
+    ev.events = EPOLLIN;
+    ev.data.fd = stop_event_fd;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, stop_event_fd, &ev);
+}
+
+void kgb_proxy::fire_stop_event() { // NOLINT(*-make-member-function-const)
+    uint64_t one = 1;
+    write(stop_event_fd, &one, sizeof(one));
+}
+
+void kgb_proxy::start_server_socket() {
+    server_fd = socket(AF_INET, SOCK_STREAM, 0);
+    set_socket_non_blocking(server_fd);
+
+    int opt = 1;
+    setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+
+    sockaddr_in addr{};
+
+    addr.sin_family = AF_INET;
+    addr.sin_port = htons(in_port);
+    addr.sin_addr.s_addr = INADDR_ANY;
+
+    bind(server_fd, (sockaddr *) &addr, sizeof(addr));
+    listen(server_fd, 16);
+
+    epoll_event ev{};
+
+    ev.events = EPOLLIN;
+    ev.data.fd = server_fd;
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, server_fd, &ev);
+}
+
+void kgb_proxy::add_socket_to_epoll(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ev{};
+    ev.events = EPOLLIN | EPOLLET;
+    ev.data.fd = fd;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ev);
+}
+
+void kgb_proxy::process_incoming_connection() {
+    while (true) {
+        int in_fd;
+        {
+            sockaddr_in addr{};
+            socklen_t len = sizeof(addr);
+
+            in_fd = accept(server_fd, (sockaddr*) &addr, &len);
+
+            if (in_fd < 0) {
+                if (errno != EAGAIN) {
+                    std::error_code ec{errno, std::system_category()};
+                    std::cerr << "Unexpected issue when accepting connection err=" << ec.message() << "\n";
+                }
+                break;
+            }
+
+            set_socket_non_blocking(in_fd);
+
+            std::cout << "Client connected to proxy fd = " << in_fd << std::endl;
+        }
+
+        int out_fd;
+        {
+            out_fd = socket(AF_INET, SOCK_STREAM, 0);
+
+            set_socket_non_blocking(out_fd);
+
+            if (out_fd < 0) {
+                std::error_code ec{errno, std::system_category()};
+                throw std::runtime_error("Unable to create socket for outbound proxy connection err = " + ec.message());
+            }
+
+            sockaddr_in addr{};
+            addr.sin_family = AF_INET;
+            addr.sin_port = htons(out_port);
+
+            inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
+
+            int res = connect(out_fd, (sockaddr*) &addr, sizeof(addr));
+
+            if (res < 0) {
+                if (errno != EINPROGRESS) {
+                    std::error_code ec{errno, std::system_category()};
+                    throw std::runtime_error("Unable to connection to server err = " + ec.message());
+                }
+            }
+
+            std::cout << "Proxy connected to server fd = " << out_fd << std::endl;
+        }
+
+        std::shared_ptr<proxy_connection> conn = std::make_shared<proxy_connection>(in_fd, out_fd);
+
+        connections[in_fd] = conn;
+        connections[out_fd] = conn;
+
+        add_socket_to_epoll(in_fd);
+        add_socket_to_epoll(out_fd);
+
+        std::cout << "Socket pair has been created in_fd = " << in_fd << " out_fd = " << out_fd << std::endl;
+    }
+}
+
+void kgb_proxy::process_socket_event(const epoll_event& ep_ev) {
+    int fd = ep_ev.data.fd;
+
+    auto it = connections.find(fd);
+    if (it == connections.end()) {
+        throw std::runtime_error("Event for unknown socket occurred fd = " + std::to_string(fd));
+    }
+
+    auto conn = it->second;
+
+    if (ep_ev.events & EPOLLIN) {
+
+        char buf[BUFF_SIZE];
+
+        int src = fd;
+        int dst = src == conn->in_sock ? conn->out_sock : conn->in_sock;
+
+        while (true) {
+            ssize_t received = recv(src, buf, sizeof(buf), 0);
+
+            if (received < 0) {
+                if (errno == EAGAIN || errno == EWOULDBLOCK) {
+                    break;
+                }
+
+                perror("recv");
+                break;
+
+            }
+
+            if (received == 0) {
+                close(src);
+                close(dst);
+
+                connections.erase(src);
+                connections.erase(dst);
+                break;

Review Comment:
   After closing sockets and erasing connections, the code breaks out of the while loop. However, if there are multiple connections in the connections map with the same src socket, this could lead to issues. Additionally, after erasing connections and closing sockets, the loop should return or continue carefully to avoid using invalidated references. The current implementation may access invalid memory after the erase operations.
   ```suggestion
                   return;
   ```



##########
modules/platforms/cpp/tests/fake_server/proxy/kgb_proxy.cpp:
##########
@@ -0,0 +1,290 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//
+
+#include "kgb_proxy.h"
+
+#include <ignite/network/detail/linux/sockets.h>
+
+#include <fcntl.h>
+#include <iostream>
+#include <cstring>
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/epoll.h>
+#include <sys/eventfd.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+namespace ignite::proxy {
+
+void set_socket_non_blocking(int fd) {
+    using network::detail::set_non_blocking_mode;
+
+    if (!set_non_blocking_mode(fd, true)) {
+        throw std::runtime_error("Error making socket non-blocking");
+    }
+}
+
+void kgb_proxy::enable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);
+}
+
+void kgb_proxy::disable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);
+}
+
+void kgb_proxy::do_serve() {
+    epoll_event events[MAX_EVENTS];
+
+    bool stopped = false;
+    while (!stopped) {
+        int event_cnt = epoll_wait(epoll_fd, events, MAX_EVENTS, -1);
+
+        for (int i = 0; i < event_cnt; ++i) {
+            int fd = events[i].data.fd;
+
+            if (fd == stop_event_fd) {
+                uint64_t val;
+                read(stop_event_fd, &val, sizeof(val));
+                stopped = true;
+            } else if (fd == server_fd) {
+                process_incoming_connection();
+            } else {
+                process_socket_event(events[i]);
+            }
+        }
+    }
+}
+
+void kgb_proxy::add_event_fd() {
+    stop_event_fd = eventfd(0, EFD_NONBLOCK);
+
+    epoll_event ev{};
+    ev.events = EPOLLIN;
+    ev.data.fd = stop_event_fd;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, stop_event_fd, &ev);
+}
+
+void kgb_proxy::fire_stop_event() { // NOLINT(*-make-member-function-const)
+    uint64_t one = 1;
+    write(stop_event_fd, &one, sizeof(one));
+}
+
+void kgb_proxy::start_server_socket() {
+    server_fd = socket(AF_INET, SOCK_STREAM, 0);
+    set_socket_non_blocking(server_fd);
+
+    int opt = 1;
+    setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+
+    sockaddr_in addr{};
+
+    addr.sin_family = AF_INET;
+    addr.sin_port = htons(in_port);
+    addr.sin_addr.s_addr = INADDR_ANY;
+
+    bind(server_fd, (sockaddr *) &addr, sizeof(addr));
+    listen(server_fd, 16);
+
+    epoll_event ev{};
+
+    ev.events = EPOLLIN;
+    ev.data.fd = server_fd;
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, server_fd, &ev);
+}
+
+void kgb_proxy::add_socket_to_epoll(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ev{};
+    ev.events = EPOLLIN | EPOLLET;
+    ev.data.fd = fd;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ev);
+}
+
+void kgb_proxy::process_incoming_connection() {
+    while (true) {
+        int in_fd;
+        {
+            sockaddr_in addr{};
+            socklen_t len = sizeof(addr);
+
+            in_fd = accept(server_fd, (sockaddr*) &addr, &len);
+
+            if (in_fd < 0) {
+                if (errno != EAGAIN) {
+                    std::error_code ec{errno, std::system_category()};
+                    std::cerr << "Unexpected issue when accepting connection err=" << ec.message() << "\n";
+                }
+                break;
+            }
+
+            set_socket_non_blocking(in_fd);
+
+            std::cout << "Client connected to proxy fd = " << in_fd << std::endl;
+        }
+
+        int out_fd;
+        {
+            out_fd = socket(AF_INET, SOCK_STREAM, 0);
+
+            set_socket_non_blocking(out_fd);
+
+            if (out_fd < 0) {
+                std::error_code ec{errno, std::system_category()};
+                throw std::runtime_error("Unable to create socket for outbound proxy connection err = " + ec.message());
+            }
+
+            sockaddr_in addr{};
+            addr.sin_family = AF_INET;
+            addr.sin_port = htons(out_port);
+
+            inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
+
+            int res = connect(out_fd, (sockaddr*) &addr, sizeof(addr));
+
+            if (res < 0) {
+                if (errno != EINPROGRESS) {
+                    std::error_code ec{errno, std::system_category()};
+                    throw std::runtime_error("Unable to connection to server err = " + ec.message());
+                }
+            }
+
+            std::cout << "Proxy connected to server fd = " << out_fd << std::endl;
+        }
+
+        std::shared_ptr<proxy_connection> conn = std::make_shared<proxy_connection>(in_fd, out_fd);
+
+        connections[in_fd] = conn;
+        connections[out_fd] = conn;
+
+        add_socket_to_epoll(in_fd);
+        add_socket_to_epoll(out_fd);
+
+        std::cout << "Socket pair has been created in_fd = " << in_fd << " out_fd = " << out_fd << std::endl;
+    }
+}
+
+void kgb_proxy::process_socket_event(const epoll_event& ep_ev) {
+    int fd = ep_ev.data.fd;
+
+    auto it = connections.find(fd);
+    if (it == connections.end()) {
+        throw std::runtime_error("Event for unknown socket occurred fd = " + std::to_string(fd));
+    }
+
+    auto conn = it->second;
+
+    if (ep_ev.events & EPOLLIN) {
+
+        char buf[BUFF_SIZE];
+
+        int src = fd;
+        int dst = src == conn->in_sock ? conn->out_sock : conn->in_sock;
+
+        while (true) {
+            ssize_t received = recv(src, buf, sizeof(buf), 0);
+
+            if (received < 0) {
+                if (errno == EAGAIN || errno == EWOULDBLOCK) {
+                    break;
+                }
+
+                perror("recv");
+                break;
+
+            }
+
+            if (received == 0) {
+                close(src);
+                close(dst);
+
+                connections.erase(src);
+                connections.erase(dst);
+                break;
+            }
+
+            auto& queue = src == conn->in_sock ? conn->in2out_queue : conn->out2in_queue;
+            queue.emplace(buf, received);
+
+            enable_writable_notification(dst);
+        }
+    }
+
+    if (ep_ev.events & EPOLLOUT) {
+        int dst = fd;
+        int src = dst == conn->in_sock ? conn->out_sock : conn->in_sock;
+
+        auto& queue = src == conn->in_sock ? conn->in2out_queue : conn->out2in_queue;
+
+        while (!queue.empty()) {
+
+            const message_chunk& chunk = queue.front();
+            ssize_t sent = send(dst, chunk.m_msg, chunk.m_size, 0);
+
+            if (sent <= 0) {
+                if (errno == EAGAIN || errno == EWOULDBLOCK) {
+                    break;
+                }
+
+                perror("send");
+                break;
+            }
+
+            queue.pop();
+        }
+
+        disable_writable_notification(dst);
+    }
+}
+
+kgb_proxy::~kgb_proxy() {
+    fire_stop_event();
+
+    m_polling_thread->join();
+
+    close(stop_event_fd);
+    close(server_fd);
+    close(epoll_fd);

Review Comment:
   File descriptors should only be closed if they are valid (>= 0). If start() was never called, these file descriptors will have their initial values of -1, and closing them will result in errors. Add checks to ensure file descriptors are valid before closing them.
   ```suggestion
       if (stop_event_fd >= 0) {
           close(stop_event_fd);
       }
       if (server_fd >= 0) {
           close(server_fd);
       }
       if (epoll_fd >= 0) {
           close(epoll_fd);
       }
   ```



##########
modules/platforms/cpp/tests/fake_server/proxy/kgb_proxy.cpp:
##########
@@ -0,0 +1,290 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//
+
+#include "kgb_proxy.h"
+
+#include <ignite/network/detail/linux/sockets.h>
+
+#include <fcntl.h>
+#include <iostream>
+#include <cstring>
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/epoll.h>
+#include <sys/eventfd.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+namespace ignite::proxy {
+
+void set_socket_non_blocking(int fd) {
+    using network::detail::set_non_blocking_mode;
+
+    if (!set_non_blocking_mode(fd, true)) {
+        throw std::runtime_error("Error making socket non-blocking");
+    }
+}
+
+void kgb_proxy::enable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);
+}
+
+void kgb_proxy::disable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);
+}
+
+void kgb_proxy::do_serve() {
+    epoll_event events[MAX_EVENTS];
+
+    bool stopped = false;
+    while (!stopped) {
+        int event_cnt = epoll_wait(epoll_fd, events, MAX_EVENTS, -1);

Review Comment:
   The return value of epoll_wait should be checked for errors. If epoll_wait returns -1, errno should be checked and an error should be handled appropriately. Currently, a negative return value would cause the loop to iterate with event_cnt < 0, which is incorrect behavior.



##########
modules/platforms/cpp/tests/fake_server/proxy/kgb_proxy.cpp:
##########
@@ -0,0 +1,290 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//
+
+#include "kgb_proxy.h"
+
+#include <ignite/network/detail/linux/sockets.h>
+
+#include <fcntl.h>
+#include <iostream>
+#include <cstring>
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/epoll.h>
+#include <sys/eventfd.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+namespace ignite::proxy {
+
+void set_socket_non_blocking(int fd) {
+    using network::detail::set_non_blocking_mode;
+
+    if (!set_non_blocking_mode(fd, true)) {
+        throw std::runtime_error("Error making socket non-blocking");
+    }
+}
+
+void kgb_proxy::enable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);
+}
+
+void kgb_proxy::disable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);
+}
+
+void kgb_proxy::do_serve() {
+    epoll_event events[MAX_EVENTS];
+
+    bool stopped = false;
+    while (!stopped) {
+        int event_cnt = epoll_wait(epoll_fd, events, MAX_EVENTS, -1);
+
+        for (int i = 0; i < event_cnt; ++i) {
+            int fd = events[i].data.fd;
+
+            if (fd == stop_event_fd) {
+                uint64_t val;
+                read(stop_event_fd, &val, sizeof(val));
+                stopped = true;
+            } else if (fd == server_fd) {
+                process_incoming_connection();
+            } else {
+                process_socket_event(events[i]);
+            }
+        }
+    }
+}
+
+void kgb_proxy::add_event_fd() {
+    stop_event_fd = eventfd(0, EFD_NONBLOCK);
+
+    epoll_event ev{};
+    ev.events = EPOLLIN;
+    ev.data.fd = stop_event_fd;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, stop_event_fd, &ev);
+}
+
+void kgb_proxy::fire_stop_event() { // NOLINT(*-make-member-function-const)
+    uint64_t one = 1;
+    write(stop_event_fd, &one, sizeof(one));
+}
+
+void kgb_proxy::start_server_socket() {
+    server_fd = socket(AF_INET, SOCK_STREAM, 0);
+    set_socket_non_blocking(server_fd);
+
+    int opt = 1;
+    setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+
+    sockaddr_in addr{};
+
+    addr.sin_family = AF_INET;
+    addr.sin_port = htons(in_port);
+    addr.sin_addr.s_addr = INADDR_ANY;
+
+    bind(server_fd, (sockaddr *) &addr, sizeof(addr));
+    listen(server_fd, 16);
+
+    epoll_event ev{};
+
+    ev.events = EPOLLIN;
+    ev.data.fd = server_fd;
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, server_fd, &ev);

Review Comment:
   The return values of socket, setsockopt, bind, listen, and epoll_ctl should be checked for errors. These system calls can fail and should have proper error handling. Without checks, failures will go undetected and could cause undefined behavior.



##########
modules/platforms/cpp/tests/fake_server/proxy/kgb_proxy.h:
##########
@@ -0,0 +1,96 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//
+
+#pragma once
+#include <cassert>
+#include <cstring>
+#include <memory>
+#include <queue>
+#include <sys/epoll.h>
+#include <thread>
+#include <unordered_map>
+
+namespace ignite::proxy {
+
+struct proxy_connection;
+
+class kgb_proxy {
+public:
+    static constexpr int MAX_EVENTS = 64;
+    static constexpr int BUFF_SIZE = 4096;
+
+    kgb_proxy(int in_port, int out_port)
+        : in_port(in_port)
+        , out_port(out_port) { }
+
+    ~kgb_proxy();
+    void start();
+
+private:
+    void enable_writable_notification(int fd);
+    void disable_writable_notification(int fd);
+    void do_serve();
+    void add_event_fd();
+    void fire_stop_event();
+    void start_server_socket();
+    void add_socket_to_epoll(int fd);
+    void process_incoming_connection();
+    void process_socket_event(const epoll_event &ep_ev);
+    const int in_port;
+    const int out_port;
+    int server_fd{-1};
+    int epoll_fd{-1};
+    int stop_event_fd{-1};
+    std::unique_ptr<std::thread> m_polling_thread{};
+    bool connected{false};

Review Comment:
   The member variable 'connected' is declared but never used anywhere in the class. Consider removing it to reduce clutter, or implement the intended functionality if it was meant to track connection state.
   ```suggestion
   
   ```



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,195 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <iostream>
+#include <queue>
+#include <tuple>
+
+#include <asio.hpp>
+#include <asio/ts/buffer.hpp>
+#include <asio/ts/internet.hpp>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct message {
+    char *m_arr;
+    size_t m_size;
+
+    message(char *arr, size_t size)
+        : m_arr(nullptr)
+        , m_size(size) {
+        m_arr = new char[m_size];
+        std::memcpy(m_arr, arr, size);
+    }
+
+    ~message() { delete[] m_arr; }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock)) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        auto tup = get_sockets_and_queue(direction);
+        tcp::socket &src = std::get<0>(tup);
+        std::queue<message> &queue = std::get<2>(tup);
+        bool &writable = std::get<3>(tup);
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [this, &queue, direction, &writable](asio::error_code ec, size_t len) {
+            if (ec) {
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            // we have one-threaded executor no synchronization is needed
+            queue.emplace(buf, len);
+
+            if (writable) { // there are pending write operation on this socket
+                do_write(direction);
+            }
+
+            do_read(direction);
+        });
+    }
+
+    void do_write(direction direction) {
+        auto tup = get_sockets_and_queue(direction);
+        tcp::socket &dst = std::get<1>(tup);
+        std::queue<message> &queue = std::get<2>(tup);
+        bool &writable = std::get<3>(tup);
+
+        writable = false; // protects from writing same buffer twice (from head of queue).
+
+        if (!queue.empty()) {
+            message &msg = queue.front();
+
+            asio::async_write(
+                dst, asio::buffer(msg.m_arr, msg.m_size), [this, &queue, direction, &writable](asio::error_code ec, size_t) {
+                    if (ec) {
+                        throw std::runtime_error("Error while writing to socket " + ec.message());
+                    }
+
+                    queue.pop();
+
+                    if (!queue.empty()) {
+                        // makes writes on the same socket strictly ordered
+                        do_write(direction);
+                    } else {
+                        writable = true; // now read operation can initiate writes
+                    }
+                });
+        }
+    }
+
+    std::tuple<tcp::socket &, tcp::socket &, std::queue<message> &, bool&> get_sockets_and_queue(direction direction) {
+        switch (direction) {
+            case forward:
+                return {m_in_sock, m_out_sock, m_in_to_out, m_in_to_out_writable};
+            case reverse:
+                return {m_out_sock, m_in_sock, m_out_to_in, m_out_to_in_writable};
+        }
+
+        throw std::runtime_error("Should be unreachable");
+    }
+
+    tcp::socket m_in_sock;
+    tcp::socket m_out_sock;
+
+    bool m_in_to_out_writable{false};
+    bool m_out_to_in_writable{false};
+
+    std::queue<message> m_in_to_out;
+    std::queue<message> m_out_to_in;
+
+    static constexpr size_t BUFF_SIZE = 4096;
+
+    char buf[BUFF_SIZE];
+};
+
+class asio_proxy {
+public:
+    asio_proxy(asio::io_context &io_context, short port)
+        : m_io_context(io_context)
+        , m_acceptor(m_io_context, tcp::endpoint(tcp::v4(), port))
+        , m_resolver(m_io_context)
+        , m_in_sock(m_io_context) {
+        do_accept();
+    }
+
+private:
+    void do_accept() {
+        m_acceptor.async_accept(m_in_sock, [this](asio::error_code ec) {
+            if (!ec) {
+                auto ses = m_sessons.emplace_back(
+                    std::make_shared<session>(std::move(m_in_sock), tcp::socket{m_io_context}));
+
+                m_resolver.async_resolve(
+                    "127.0.0.1", "50900", [ses](asio::error_code ec, tcp::resolver::results_type endpoints) {
+                        if (!ec) {
+                            asio::async_connect(ses->get_out_sock(), endpoints,
+                                [&ses](const asio::error_code &ec, const tcp::endpoint & e) {
+                                    if (!ec) {
+                                        ses->set_writable(true);
+                                        ses->start();
+                                    } else {
+                                        std::cout << e.port();
+                                        throw std::runtime_error("Error connecting to server " + ec.message());
+                                    }
+                                });
+                        } else {
+                            throw std::runtime_error("Error resolving server's address " + ec.message());
+                        }
+                    });
+
+                do_accept();
+
+            } else {
+                throw std::runtime_error("Error accepting incoming connection " + ec.message());
+            }
+        });
+    }
+
+    asio::io_context &m_io_context;
+    tcp::acceptor m_acceptor;
+    tcp::resolver m_resolver;
+    tcp::socket m_in_sock;
+
+    std::vector<std::shared_ptr<session>> m_sessons;

Review Comment:
   Typo in variable name: m_sessons should be m_sessions (missing 'i').



##########
modules/platforms/cpp/tests/fake_server/connection_test.cpp:
##########
@@ -76,3 +79,42 @@ TEST_F(connection_test, request_timeout) {
         EXPECT_EQ(error::code::OPERATION_TIMEOUT, err.get_status_code());
     }
 }
+
+// TEST_F(connection_test, using_proxy) {
+//     fake_server fs{50900, get_logger()};
+//     proxy::kgb_proxy proxy{50800, 50900};
+//
+//     fs.start();
+//     proxy.start();
+//
+//     ignite_client_configuration cfg;
+//     cfg.set_logger(get_logger());
+//     cfg.set_endpoints(get_endpoints());
+//
+//     auto cl = ignite_client::start(cfg, 5s);
+//
+//     auto cluster_nodes = cl.get_cluster_nodes();
+//
+//     ASSERT_EQ(1, cluster_nodes.size());
+// }
+
+TEST_F(connection_test, using_asio) {
+    fake_server fs{50900, get_logger()};
+    fs.start();
+    asio::io_context io_context;
+    proxy::asio_proxy proxy{io_context, static_cast<short>(50800)};
+
+    std::thread t{[&io_context]() {
+        io_context.run();
+    }};
+
+    ignite_client_configuration cfg;
+    cfg.set_logger(get_logger());
+    cfg.set_endpoints(get_endpoints());
+
+    auto cl = ignite_client::start(cfg, 500s);

Review Comment:
   The timeout value of 500 seconds seems excessively long for a unit test. This is inconsistent with other tests in the same file that use 5s timeout (line 50, 94). Consider using a more reasonable timeout value consistent with other tests.
   ```suggestion
       auto cl = ignite_client::start(cfg, 5s);
   ```



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,195 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <iostream>
+#include <queue>
+#include <tuple>
+
+#include <asio.hpp>
+#include <asio/ts/buffer.hpp>
+#include <asio/ts/internet.hpp>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct message {
+    char *m_arr;
+    size_t m_size;
+
+    message(char *arr, size_t size)
+        : m_arr(nullptr)
+        , m_size(size) {
+        m_arr = new char[m_size];
+        std::memcpy(m_arr, arr, size);
+    }
+
+    ~message() { delete[] m_arr; }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock)) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        auto tup = get_sockets_and_queue(direction);
+        tcp::socket &src = std::get<0>(tup);
+        std::queue<message> &queue = std::get<2>(tup);
+        bool &writable = std::get<3>(tup);
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [this, &queue, direction, &writable](asio::error_code ec, size_t len) {
+            if (ec) {
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            // we have one-threaded executor no synchronization is needed
+            queue.emplace(buf, len);
+
+            if (writable) { // there are pending write operation on this socket
+                do_write(direction);
+            }
+
+            do_read(direction);
+        });
+    }
+
+    void do_write(direction direction) {
+        auto tup = get_sockets_and_queue(direction);
+        tcp::socket &dst = std::get<1>(tup);
+        std::queue<message> &queue = std::get<2>(tup);
+        bool &writable = std::get<3>(tup);
+
+        writable = false; // protects from writing same buffer twice (from head of queue).
+
+        if (!queue.empty()) {
+            message &msg = queue.front();
+
+            asio::async_write(
+                dst, asio::buffer(msg.m_arr, msg.m_size), [this, &queue, direction, &writable](asio::error_code ec, size_t) {
+                    if (ec) {
+                        throw std::runtime_error("Error while writing to socket " + ec.message());
+                    }
+
+                    queue.pop();
+
+                    if (!queue.empty()) {
+                        // makes writes on the same socket strictly ordered
+                        do_write(direction);
+                    } else {
+                        writable = true; // now read operation can initiate writes
+                    }
+                });

Review Comment:
   Similar to the issue in do_read, the lambda captures references (&queue, &writable) which point to members of 'this'. If the session is destroyed before the async operation completes, these references will be dangling. The session should be kept alive by capturing shared_from_this() in the lambda.



##########
modules/platforms/cpp/tests/fake_server/proxy/kgb_proxy.cpp:
##########
@@ -0,0 +1,290 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//
+
+#include "kgb_proxy.h"
+
+#include <ignite/network/detail/linux/sockets.h>
+
+#include <fcntl.h>
+#include <iostream>
+#include <cstring>
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/epoll.h>
+#include <sys/eventfd.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+namespace ignite::proxy {
+
+void set_socket_non_blocking(int fd) {
+    using network::detail::set_non_blocking_mode;
+
+    if (!set_non_blocking_mode(fd, true)) {
+        throw std::runtime_error("Error making socket non-blocking");
+    }
+}
+
+void kgb_proxy::enable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);
+}
+
+void kgb_proxy::disable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);
+}
+
+void kgb_proxy::do_serve() {
+    epoll_event events[MAX_EVENTS];
+
+    bool stopped = false;
+    while (!stopped) {
+        int event_cnt = epoll_wait(epoll_fd, events, MAX_EVENTS, -1);
+
+        for (int i = 0; i < event_cnt; ++i) {
+            int fd = events[i].data.fd;
+
+            if (fd == stop_event_fd) {
+                uint64_t val;
+                read(stop_event_fd, &val, sizeof(val));
+                stopped = true;
+            } else if (fd == server_fd) {
+                process_incoming_connection();
+            } else {
+                process_socket_event(events[i]);
+            }
+        }
+    }
+}
+
+void kgb_proxy::add_event_fd() {
+    stop_event_fd = eventfd(0, EFD_NONBLOCK);
+
+    epoll_event ev{};
+    ev.events = EPOLLIN;
+    ev.data.fd = stop_event_fd;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, stop_event_fd, &ev);
+}
+
+void kgb_proxy::fire_stop_event() { // NOLINT(*-make-member-function-const)
+    uint64_t one = 1;
+    write(stop_event_fd, &one, sizeof(one));
+}
+
+void kgb_proxy::start_server_socket() {
+    server_fd = socket(AF_INET, SOCK_STREAM, 0);
+    set_socket_non_blocking(server_fd);
+
+    int opt = 1;
+    setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+
+    sockaddr_in addr{};
+
+    addr.sin_family = AF_INET;
+    addr.sin_port = htons(in_port);
+    addr.sin_addr.s_addr = INADDR_ANY;
+
+    bind(server_fd, (sockaddr *) &addr, sizeof(addr));
+    listen(server_fd, 16);
+
+    epoll_event ev{};
+
+    ev.events = EPOLLIN;
+    ev.data.fd = server_fd;
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, server_fd, &ev);
+}
+
+void kgb_proxy::add_socket_to_epoll(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ev{};
+    ev.events = EPOLLIN | EPOLLET;
+    ev.data.fd = fd;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ev);
+}
+
+void kgb_proxy::process_incoming_connection() {
+    while (true) {
+        int in_fd;
+        {
+            sockaddr_in addr{};
+            socklen_t len = sizeof(addr);
+
+            in_fd = accept(server_fd, (sockaddr*) &addr, &len);
+
+            if (in_fd < 0) {
+                if (errno != EAGAIN) {
+                    std::error_code ec{errno, std::system_category()};
+                    std::cerr << "Unexpected issue when accepting connection err=" << ec.message() << "\n";
+                }
+                break;
+            }
+
+            set_socket_non_blocking(in_fd);
+
+            std::cout << "Client connected to proxy fd = " << in_fd << std::endl;
+        }
+
+        int out_fd;
+        {
+            out_fd = socket(AF_INET, SOCK_STREAM, 0);
+
+            set_socket_non_blocking(out_fd);
+
+            if (out_fd < 0) {
+                std::error_code ec{errno, std::system_category()};
+                throw std::runtime_error("Unable to create socket for outbound proxy connection err = " + ec.message());
+            }
+
+            sockaddr_in addr{};
+            addr.sin_family = AF_INET;
+            addr.sin_port = htons(out_port);
+
+            inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
+
+            int res = connect(out_fd, (sockaddr*) &addr, sizeof(addr));
+
+            if (res < 0) {
+                if (errno != EINPROGRESS) {
+                    std::error_code ec{errno, std::system_category()};
+                    throw std::runtime_error("Unable to connection to server err = " + ec.message());
+                }
+            }
+
+            std::cout << "Proxy connected to server fd = " << out_fd << std::endl;
+        }
+
+        std::shared_ptr<proxy_connection> conn = std::make_shared<proxy_connection>(in_fd, out_fd);
+
+        connections[in_fd] = conn;
+        connections[out_fd] = conn;
+
+        add_socket_to_epoll(in_fd);
+        add_socket_to_epoll(out_fd);
+
+        std::cout << "Socket pair has been created in_fd = " << in_fd << " out_fd = " << out_fd << std::endl;
+    }
+}
+
+void kgb_proxy::process_socket_event(const epoll_event& ep_ev) {
+    int fd = ep_ev.data.fd;
+
+    auto it = connections.find(fd);
+    if (it == connections.end()) {
+        throw std::runtime_error("Event for unknown socket occurred fd = " + std::to_string(fd));
+    }
+
+    auto conn = it->second;
+
+    if (ep_ev.events & EPOLLIN) {
+
+        char buf[BUFF_SIZE];
+
+        int src = fd;
+        int dst = src == conn->in_sock ? conn->out_sock : conn->in_sock;
+
+        while (true) {
+            ssize_t received = recv(src, buf, sizeof(buf), 0);
+
+            if (received < 0) {
+                if (errno == EAGAIN || errno == EWOULDBLOCK) {
+                    break;
+                }
+
+                perror("recv");
+                break;
+
+            }
+
+            if (received == 0) {
+                close(src);
+                close(dst);
+
+                connections.erase(src);
+                connections.erase(dst);
+                break;
+            }
+
+            auto& queue = src == conn->in_sock ? conn->in2out_queue : conn->out2in_queue;
+            queue.emplace(buf, received);
+
+            enable_writable_notification(dst);
+        }
+    }
+
+    if (ep_ev.events & EPOLLOUT) {
+        int dst = fd;
+        int src = dst == conn->in_sock ? conn->out_sock : conn->in_sock;
+
+        auto& queue = src == conn->in_sock ? conn->in2out_queue : conn->out2in_queue;
+
+        while (!queue.empty()) {
+
+            const message_chunk& chunk = queue.front();
+            ssize_t sent = send(dst, chunk.m_msg, chunk.m_size, 0);
+
+            if (sent <= 0) {
+                if (errno == EAGAIN || errno == EWOULDBLOCK) {
+                    break;
+                }
+
+                perror("send");
+                break;
+            }
+
+            queue.pop();
+        }
+
+        disable_writable_notification(dst);
+    }
+}
+
+kgb_proxy::~kgb_proxy() {
+    fire_stop_event();
+
+    m_polling_thread->join();

Review Comment:
   The destructor assumes m_polling_thread is not null and attempts to join it without checking. If start() was never called, m_polling_thread will be nullptr and dereferencing it will cause a crash. Add a null check before calling join().
   ```suggestion
       if (m_polling_thread && m_polling_thread->joinable()) {
           m_polling_thread->join();
       }
   ```



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,195 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <iostream>
+#include <queue>
+#include <tuple>
+
+#include <asio.hpp>
+#include <asio/ts/buffer.hpp>
+#include <asio/ts/internet.hpp>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct message {
+    char *m_arr;
+    size_t m_size;
+
+    message(char *arr, size_t size)
+        : m_arr(nullptr)
+        , m_size(size) {
+        m_arr = new char[m_size];
+        std::memcpy(m_arr, arr, size);
+    }
+
+    ~message() { delete[] m_arr; }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock)) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        auto tup = get_sockets_and_queue(direction);
+        tcp::socket &src = std::get<0>(tup);
+        std::queue<message> &queue = std::get<2>(tup);
+        bool &writable = std::get<3>(tup);
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [this, &queue, direction, &writable](asio::error_code ec, size_t len) {
+            if (ec) {
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            // we have one-threaded executor no synchronization is needed
+            queue.emplace(buf, len);
+
+            if (writable) { // there are pending write operation on this socket
+                do_write(direction);
+            }
+
+            do_read(direction);
+        });
+    }
+
+    void do_write(direction direction) {
+        auto tup = get_sockets_and_queue(direction);
+        tcp::socket &dst = std::get<1>(tup);
+        std::queue<message> &queue = std::get<2>(tup);
+        bool &writable = std::get<3>(tup);
+
+        writable = false; // protects from writing same buffer twice (from head of queue).
+
+        if (!queue.empty()) {
+            message &msg = queue.front();
+
+            asio::async_write(
+                dst, asio::buffer(msg.m_arr, msg.m_size), [this, &queue, direction, &writable](asio::error_code ec, size_t) {
+                    if (ec) {
+                        throw std::runtime_error("Error while writing to socket " + ec.message());
+                    }
+
+                    queue.pop();
+
+                    if (!queue.empty()) {
+                        // makes writes on the same socket strictly ordered
+                        do_write(direction);
+                    } else {
+                        writable = true; // now read operation can initiate writes
+                    }
+                });
+        }
+    }
+
+    std::tuple<tcp::socket &, tcp::socket &, std::queue<message> &, bool&> get_sockets_and_queue(direction direction) {
+        switch (direction) {
+            case forward:
+                return {m_in_sock, m_out_sock, m_in_to_out, m_in_to_out_writable};
+            case reverse:
+                return {m_out_sock, m_in_sock, m_out_to_in, m_out_to_in_writable};
+        }
+
+        throw std::runtime_error("Should be unreachable");
+    }
+
+    tcp::socket m_in_sock;
+    tcp::socket m_out_sock;
+
+    bool m_in_to_out_writable{false};
+    bool m_out_to_in_writable{false};
+
+    std::queue<message> m_in_to_out;
+    std::queue<message> m_out_to_in;
+
+    static constexpr size_t BUFF_SIZE = 4096;
+
+    char buf[BUFF_SIZE];
+};
+
+class asio_proxy {
+public:
+    asio_proxy(asio::io_context &io_context, short port)
+        : m_io_context(io_context)
+        , m_acceptor(m_io_context, tcp::endpoint(tcp::v4(), port))
+        , m_resolver(m_io_context)
+        , m_in_sock(m_io_context) {
+        do_accept();
+    }
+
+private:
+    void do_accept() {
+        m_acceptor.async_accept(m_in_sock, [this](asio::error_code ec) {
+            if (!ec) {
+                auto ses = m_sessons.emplace_back(

Review Comment:
   Typo in variable name: m_sessons should be m_sessions (missing 'i'). This is the same variable referenced in line 193.



##########
modules/platforms/cpp/tests/fake_server/proxy/kgb_proxy.cpp:
##########
@@ -0,0 +1,290 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//
+
+#include "kgb_proxy.h"
+
+#include <ignite/network/detail/linux/sockets.h>
+
+#include <fcntl.h>
+#include <iostream>
+#include <cstring>
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/epoll.h>
+#include <sys/eventfd.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+namespace ignite::proxy {
+
+void set_socket_non_blocking(int fd) {
+    using network::detail::set_non_blocking_mode;
+
+    if (!set_non_blocking_mode(fd, true)) {
+        throw std::runtime_error("Error making socket non-blocking");
+    }
+}
+
+void kgb_proxy::enable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);
+}
+
+void kgb_proxy::disable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);
+}
+
+void kgb_proxy::do_serve() {
+    epoll_event events[MAX_EVENTS];
+
+    bool stopped = false;
+    while (!stopped) {
+        int event_cnt = epoll_wait(epoll_fd, events, MAX_EVENTS, -1);
+
+        for (int i = 0; i < event_cnt; ++i) {
+            int fd = events[i].data.fd;
+
+            if (fd == stop_event_fd) {
+                uint64_t val;
+                read(stop_event_fd, &val, sizeof(val));
+                stopped = true;
+            } else if (fd == server_fd) {
+                process_incoming_connection();
+            } else {
+                process_socket_event(events[i]);
+            }
+        }
+    }
+}
+
+void kgb_proxy::add_event_fd() {
+    stop_event_fd = eventfd(0, EFD_NONBLOCK);
+
+    epoll_event ev{};
+    ev.events = EPOLLIN;
+    ev.data.fd = stop_event_fd;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, stop_event_fd, &ev);
+}
+
+void kgb_proxy::fire_stop_event() { // NOLINT(*-make-member-function-const)
+    uint64_t one = 1;
+    write(stop_event_fd, &one, sizeof(one));
+}
+
+void kgb_proxy::start_server_socket() {
+    server_fd = socket(AF_INET, SOCK_STREAM, 0);
+    set_socket_non_blocking(server_fd);
+
+    int opt = 1;
+    setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+
+    sockaddr_in addr{};
+
+    addr.sin_family = AF_INET;
+    addr.sin_port = htons(in_port);
+    addr.sin_addr.s_addr = INADDR_ANY;
+
+    bind(server_fd, (sockaddr *) &addr, sizeof(addr));
+    listen(server_fd, 16);
+
+    epoll_event ev{};
+
+    ev.events = EPOLLIN;
+    ev.data.fd = server_fd;
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, server_fd, &ev);
+}
+
+void kgb_proxy::add_socket_to_epoll(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ev{};
+    ev.events = EPOLLIN | EPOLLET;
+    ev.data.fd = fd;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ev);
+}
+
+void kgb_proxy::process_incoming_connection() {
+    while (true) {
+        int in_fd;
+        {
+            sockaddr_in addr{};
+            socklen_t len = sizeof(addr);
+
+            in_fd = accept(server_fd, (sockaddr*) &addr, &len);
+
+            if (in_fd < 0) {
+                if (errno != EAGAIN) {
+                    std::error_code ec{errno, std::system_category()};
+                    std::cerr << "Unexpected issue when accepting connection err=" << ec.message() << "\n";
+                }
+                break;
+            }
+
+            set_socket_non_blocking(in_fd);
+
+            std::cout << "Client connected to proxy fd = " << in_fd << std::endl;
+        }
+
+        int out_fd;
+        {
+            out_fd = socket(AF_INET, SOCK_STREAM, 0);
+
+            set_socket_non_blocking(out_fd);
+
+            if (out_fd < 0) {
+                std::error_code ec{errno, std::system_category()};
+                throw std::runtime_error("Unable to create socket for outbound proxy connection err = " + ec.message());
+            }
+
+            sockaddr_in addr{};
+            addr.sin_family = AF_INET;
+            addr.sin_port = htons(out_port);
+
+            inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
+
+            int res = connect(out_fd, (sockaddr*) &addr, sizeof(addr));
+
+            if (res < 0) {
+                if (errno != EINPROGRESS) {
+                    std::error_code ec{errno, std::system_category()};
+                    throw std::runtime_error("Unable to connection to server err = " + ec.message());
+                }
+            }
+
+            std::cout << "Proxy connected to server fd = " << out_fd << std::endl;
+        }
+
+        std::shared_ptr<proxy_connection> conn = std::make_shared<proxy_connection>(in_fd, out_fd);
+
+        connections[in_fd] = conn;
+        connections[out_fd] = conn;
+
+        add_socket_to_epoll(in_fd);
+        add_socket_to_epoll(out_fd);
+
+        std::cout << "Socket pair has been created in_fd = " << in_fd << " out_fd = " << out_fd << std::endl;
+    }
+}
+
+void kgb_proxy::process_socket_event(const epoll_event& ep_ev) {
+    int fd = ep_ev.data.fd;
+
+    auto it = connections.find(fd);
+    if (it == connections.end()) {
+        throw std::runtime_error("Event for unknown socket occurred fd = " + std::to_string(fd));
+    }
+
+    auto conn = it->second;
+
+    if (ep_ev.events & EPOLLIN) {
+
+        char buf[BUFF_SIZE];
+
+        int src = fd;
+        int dst = src == conn->in_sock ? conn->out_sock : conn->in_sock;
+
+        while (true) {
+            ssize_t received = recv(src, buf, sizeof(buf), 0);
+
+            if (received < 0) {
+                if (errno == EAGAIN || errno == EWOULDBLOCK) {
+                    break;
+                }
+
+                perror("recv");
+                break;
+
+            }
+
+            if (received == 0) {
+                close(src);
+                close(dst);
+
+                connections.erase(src);
+                connections.erase(dst);
+                break;
+            }
+
+            auto& queue = src == conn->in_sock ? conn->in2out_queue : conn->out2in_queue;
+            queue.emplace(buf, received);
+
+            enable_writable_notification(dst);
+        }
+    }
+
+    if (ep_ev.events & EPOLLOUT) {
+        int dst = fd;
+        int src = dst == conn->in_sock ? conn->out_sock : conn->in_sock;
+
+        auto& queue = src == conn->in_sock ? conn->in2out_queue : conn->out2in_queue;
+
+        while (!queue.empty()) {
+
+            const message_chunk& chunk = queue.front();
+            ssize_t sent = send(dst, chunk.m_msg, chunk.m_size, 0);
+
+            if (sent <= 0) {
+                if (errno == EAGAIN || errno == EWOULDBLOCK) {
+                    break;
+                }
+
+                perror("send");
+                break;
+            }
+
+            queue.pop();
+        }
+
+        disable_writable_notification(dst);
+    }
+}
+
+kgb_proxy::~kgb_proxy() {
+    fire_stop_event();
+
+    m_polling_thread->join();
+
+    close(stop_event_fd);
+    close(server_fd);
+    close(epoll_fd);
+}
+
+void kgb_proxy::start() {
+    epoll_fd = epoll_create1(0);

Review Comment:
   The return value of epoll_create1 should be checked for errors. If epoll_create1 fails, it returns -1, and subsequent operations using epoll_fd will fail or behave incorrectly.



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,195 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <iostream>
+#include <queue>
+#include <tuple>
+
+#include <asio.hpp>
+#include <asio/ts/buffer.hpp>
+#include <asio/ts/internet.hpp>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct message {
+    char *m_arr;
+    size_t m_size;
+
+    message(char *arr, size_t size)
+        : m_arr(nullptr)
+        , m_size(size) {
+        m_arr = new char[m_size];
+        std::memcpy(m_arr, arr, size);
+    }
+
+    ~message() { delete[] m_arr; }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock)) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        auto tup = get_sockets_and_queue(direction);
+        tcp::socket &src = std::get<0>(tup);
+        std::queue<message> &queue = std::get<2>(tup);
+        bool &writable = std::get<3>(tup);
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [this, &queue, direction, &writable](asio::error_code ec, size_t len) {
+            if (ec) {
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            // we have one-threaded executor no synchronization is needed
+            queue.emplace(buf, len);
+
+            if (writable) { // there are pending write operation on this socket
+                do_write(direction);
+            }
+
+            do_read(direction);
+        });

Review Comment:
   The lambda captures references to queue and writable (&queue, &writable), which are local references in the do_read function that point to members of 'this'. If 'this' (the session) is destroyed before the async operation completes, these references will be dangling. The session should be kept alive by capturing shared_from_this() in the lambda to ensure the object outlives the async operation.



##########
modules/platforms/cpp/tests/fake_server/connection_test.cpp:
##########
@@ -76,3 +79,42 @@ TEST_F(connection_test, request_timeout) {
         EXPECT_EQ(error::code::OPERATION_TIMEOUT, err.get_status_code());
     }
 }
+
+// TEST_F(connection_test, using_proxy) {
+//     fake_server fs{50900, get_logger()};
+//     proxy::kgb_proxy proxy{50800, 50900};
+//
+//     fs.start();
+//     proxy.start();
+//
+//     ignite_client_configuration cfg;
+//     cfg.set_logger(get_logger());
+//     cfg.set_endpoints(get_endpoints());
+//
+//     auto cl = ignite_client::start(cfg, 5s);
+//
+//     auto cluster_nodes = cl.get_cluster_nodes();
+//
+//     ASSERT_EQ(1, cluster_nodes.size());
+// }
+
+TEST_F(connection_test, using_asio) {
+    fake_server fs{50900, get_logger()};
+    fs.start();
+    asio::io_context io_context;
+    proxy::asio_proxy proxy{io_context, static_cast<short>(50800)};
+
+    std::thread t{[&io_context]() {
+        io_context.run();
+    }};

Review Comment:
   The thread created for running io_context is not properly joined before the test ends. When the test finishes, the thread may still be running, which can lead to undefined behavior. The thread should be joined (or detached with proper cleanup) before the test exits. Consider using a RAII wrapper or ensuring proper cleanup in a test teardown.



##########
modules/platforms/cpp/tests/fake_server/connection_test.cpp:
##########
@@ -76,3 +79,42 @@ TEST_F(connection_test, request_timeout) {
         EXPECT_EQ(error::code::OPERATION_TIMEOUT, err.get_status_code());
     }
 }
+
+// TEST_F(connection_test, using_proxy) {
+//     fake_server fs{50900, get_logger()};
+//     proxy::kgb_proxy proxy{50800, 50900};
+//
+//     fs.start();
+//     proxy.start();
+//
+//     ignite_client_configuration cfg;
+//     cfg.set_logger(get_logger());
+//     cfg.set_endpoints(get_endpoints());
+//
+//     auto cl = ignite_client::start(cfg, 5s);
+//
+//     auto cluster_nodes = cl.get_cluster_nodes();
+//
+//     ASSERT_EQ(1, cluster_nodes.size());
+// }
+
+TEST_F(connection_test, using_asio) {
+    fake_server fs{50900, get_logger()};
+    fs.start();
+    asio::io_context io_context;
+    proxy::asio_proxy proxy{io_context, static_cast<short>(50800)};
+
+    std::thread t{[&io_context]() {
+        io_context.run();
+    }};
+
+    ignite_client_configuration cfg;
+    cfg.set_logger(get_logger());
+    cfg.set_endpoints(get_endpoints());
+
+    auto cl = ignite_client::start(cfg, 500s);
+
+    auto cluster_nodes = cl.get_cluster_nodes();
+
+    ASSERT_EQ(1, cluster_nodes.size());

Review Comment:
   The io_context.run() will continue executing until all work is completed or the io_context is stopped. When the test ends, there's no mechanism to stop the io_context, which means the thread will continue running indefinitely. The test should call io_context.stop() and then join the thread to ensure proper cleanup. Consider adding a test fixture teardown or ensuring cleanup at the end of the test.
   ```suggestion
       ASSERT_EQ(1, cluster_nodes.size());
   
       io_context.stop();
       t.join();
   ```



##########
modules/platforms/cpp/tests/fake_server/proxy/kgb_proxy.h:
##########
@@ -0,0 +1,96 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//
+
+#pragma once
+#include <cassert>
+#include <cstring>
+#include <memory>
+#include <queue>
+#include <sys/epoll.h>
+#include <thread>
+#include <unordered_map>
+
+namespace ignite::proxy {
+
+struct proxy_connection;
+
+class kgb_proxy {
+public:
+    static constexpr int MAX_EVENTS = 64;
+    static constexpr int BUFF_SIZE = 4096;
+
+    kgb_proxy(int in_port, int out_port)
+        : in_port(in_port)
+        , out_port(out_port) { }
+
+    ~kgb_proxy();
+    void start();
+
+private:
+    void enable_writable_notification(int fd);
+    void disable_writable_notification(int fd);
+    void do_serve();
+    void add_event_fd();
+    void fire_stop_event();
+    void start_server_socket();
+    void add_socket_to_epoll(int fd);
+    void process_incoming_connection();
+    void process_socket_event(const epoll_event &ep_ev);
+    const int in_port;
+    const int out_port;
+    int server_fd{-1};
+    int epoll_fd{-1};
+    int stop_event_fd{-1};
+    std::unique_ptr<std::thread> m_polling_thread{};
+    bool connected{false};
+    std::unordered_map<int, std::shared_ptr<proxy_connection>> connections{};
+};
+
+struct message_chunk {
+    char* m_msg = nullptr;
+    size_t m_size;
+
+    message_chunk(char *msg, size_t size)
+        : m_size(size)
+    {
+        assert(size <= kgb_proxy::BUFF_SIZE);
+
+        m_msg = new char[size];
+
+        std::memcpy(m_msg, msg, size);
+    }
+
+    ~message_chunk() {
+        delete[] m_msg;
+    }
+};

Review Comment:
   The message_chunk struct is missing copy constructor and copy assignment operator, but they should be deleted since the class manages raw memory via new/delete. Without explicit deletion, the default copy operations will perform shallow copies, leading to double-free errors. Add: message_chunk(const message_chunk&) = delete; and message_chunk& operator=(const message_chunk&) = delete;. Alternatively, implement proper deep copy semantics or use move semantics only.



##########
modules/platforms/cpp/tests/fake_server/CMakeLists.txt:
##########
@@ -22,6 +22,7 @@ set(SOURCES
     fake_server.cpp
     tcp_client_channel.cpp
     connection_test.cpp
+    proxy/asio_proxy.cpp

Review Comment:
   The kgb_proxy.cpp file is not included in the SOURCES list in CMakeLists.txt, which means it won't be compiled or linked. This makes the kgb_proxy.h header and kgb_proxy.cpp implementation dead code. Either add proxy/kgb_proxy.cpp to the SOURCES list if it's intended to be used, or remove the kgb_proxy files entirely.
   ```suggestion
       proxy/asio_proxy.cpp
       proxy/kgb_proxy.cpp
   ```



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,195 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <iostream>
+#include <queue>
+#include <tuple>
+
+#include <asio.hpp>
+#include <asio/ts/buffer.hpp>
+#include <asio/ts/internet.hpp>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct message {
+    char *m_arr;
+    size_t m_size;
+
+    message(char *arr, size_t size)
+        : m_arr(nullptr)
+        , m_size(size) {
+        m_arr = new char[m_size];
+        std::memcpy(m_arr, arr, size);
+    }
+
+    ~message() { delete[] m_arr; }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock)) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        auto tup = get_sockets_and_queue(direction);
+        tcp::socket &src = std::get<0>(tup);
+        std::queue<message> &queue = std::get<2>(tup);
+        bool &writable = std::get<3>(tup);
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [this, &queue, direction, &writable](asio::error_code ec, size_t len) {
+            if (ec) {
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            // we have one-threaded executor no synchronization is needed
+            queue.emplace(buf, len);
+
+            if (writable) { // there are pending write operation on this socket
+                do_write(direction);
+            }
+
+            do_read(direction);
+        });
+    }
+
+    void do_write(direction direction) {
+        auto tup = get_sockets_and_queue(direction);
+        tcp::socket &dst = std::get<1>(tup);
+        std::queue<message> &queue = std::get<2>(tup);
+        bool &writable = std::get<3>(tup);
+
+        writable = false; // protects from writing same buffer twice (from head of queue).
+
+        if (!queue.empty()) {
+            message &msg = queue.front();
+
+            asio::async_write(
+                dst, asio::buffer(msg.m_arr, msg.m_size), [this, &queue, direction, &writable](asio::error_code ec, size_t) {
+                    if (ec) {
+                        throw std::runtime_error("Error while writing to socket " + ec.message());
+                    }
+
+                    queue.pop();
+
+                    if (!queue.empty()) {
+                        // makes writes on the same socket strictly ordered
+                        do_write(direction);
+                    } else {
+                        writable = true; // now read operation can initiate writes
+                    }
+                });
+        }
+    }
+
+    std::tuple<tcp::socket &, tcp::socket &, std::queue<message> &, bool&> get_sockets_and_queue(direction direction) {
+        switch (direction) {
+            case forward:
+                return {m_in_sock, m_out_sock, m_in_to_out, m_in_to_out_writable};
+            case reverse:
+                return {m_out_sock, m_in_sock, m_out_to_in, m_out_to_in_writable};
+        }
+
+        throw std::runtime_error("Should be unreachable");
+    }
+
+    tcp::socket m_in_sock;
+    tcp::socket m_out_sock;
+
+    bool m_in_to_out_writable{false};
+    bool m_out_to_in_writable{false};
+
+    std::queue<message> m_in_to_out;
+    std::queue<message> m_out_to_in;
+
+    static constexpr size_t BUFF_SIZE = 4096;
+
+    char buf[BUFF_SIZE];

Review Comment:
   The session buffer is reused across multiple async read operations without proper synchronization. If multiple read operations are in progress (forward and reverse), they may both write to the same 'buf' array simultaneously, causing data corruption. Each direction should have its own buffer to prevent race conditions.



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,195 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <iostream>
+#include <queue>
+#include <tuple>
+
+#include <asio.hpp>
+#include <asio/ts/buffer.hpp>
+#include <asio/ts/internet.hpp>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct message {
+    char *m_arr;
+    size_t m_size;
+
+    message(char *arr, size_t size)
+        : m_arr(nullptr)
+        , m_size(size) {
+        m_arr = new char[m_size];
+        std::memcpy(m_arr, arr, size);
+    }
+

Review Comment:
   The message struct is missing copy constructor and copy assignment operator, but they should be deleted since the class manages raw memory via new/delete. Without explicit deletion, the default copy operations will perform shallow copies, leading to double-free errors. Add: message(const message&) = delete; and message& operator=(const message&) = delete;. Alternatively, implement proper deep copy semantics or use move semantics only.
   ```suggestion
   
       message(const message &) = delete;
       message &operator=(const message &) = delete;
   
       message(message &&other) noexcept
           : m_arr(other.m_arr)
           , m_size(other.m_size) {
           other.m_arr = nullptr;
           other.m_size = 0;
       }
   
       message &operator=(message &&other) noexcept {
           if (this != &other) {
               delete[] m_arr;
               m_arr = other.m_arr;
               m_size = other.m_size;
               other.m_arr = nullptr;
               other.m_size = 0;
           }
           return *this;
       }
   ```



##########
modules/platforms/cpp/tests/fake_server/proxy/kgb_proxy.cpp:
##########
@@ -0,0 +1,290 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//
+
+#include "kgb_proxy.h"
+
+#include <ignite/network/detail/linux/sockets.h>
+
+#include <fcntl.h>
+#include <iostream>
+#include <cstring>
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/epoll.h>
+#include <sys/eventfd.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+namespace ignite::proxy {
+
+void set_socket_non_blocking(int fd) {
+    using network::detail::set_non_blocking_mode;
+
+    if (!set_non_blocking_mode(fd, true)) {
+        throw std::runtime_error("Error making socket non-blocking");
+    }
+}
+
+void kgb_proxy::enable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);
+}
+
+void kgb_proxy::disable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);
+}
+
+void kgb_proxy::do_serve() {
+    epoll_event events[MAX_EVENTS];
+
+    bool stopped = false;
+    while (!stopped) {
+        int event_cnt = epoll_wait(epoll_fd, events, MAX_EVENTS, -1);
+
+        for (int i = 0; i < event_cnt; ++i) {
+            int fd = events[i].data.fd;
+
+            if (fd == stop_event_fd) {
+                uint64_t val;
+                read(stop_event_fd, &val, sizeof(val));
+                stopped = true;
+            } else if (fd == server_fd) {
+                process_incoming_connection();
+            } else {
+                process_socket_event(events[i]);
+            }
+        }
+    }
+}
+
+void kgb_proxy::add_event_fd() {
+    stop_event_fd = eventfd(0, EFD_NONBLOCK);
+
+    epoll_event ev{};
+    ev.events = EPOLLIN;
+    ev.data.fd = stop_event_fd;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, stop_event_fd, &ev);
+}
+
+void kgb_proxy::fire_stop_event() { // NOLINT(*-make-member-function-const)
+    uint64_t one = 1;
+    write(stop_event_fd, &one, sizeof(one));
+}
+
+void kgb_proxy::start_server_socket() {
+    server_fd = socket(AF_INET, SOCK_STREAM, 0);
+    set_socket_non_blocking(server_fd);
+
+    int opt = 1;
+    setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+
+    sockaddr_in addr{};
+
+    addr.sin_family = AF_INET;
+    addr.sin_port = htons(in_port);
+    addr.sin_addr.s_addr = INADDR_ANY;
+
+    bind(server_fd, (sockaddr *) &addr, sizeof(addr));
+    listen(server_fd, 16);
+
+    epoll_event ev{};
+
+    ev.events = EPOLLIN;
+    ev.data.fd = server_fd;
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, server_fd, &ev);
+}
+
+void kgb_proxy::add_socket_to_epoll(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ev{};
+    ev.events = EPOLLIN | EPOLLET;
+    ev.data.fd = fd;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ev);
+}
+
+void kgb_proxy::process_incoming_connection() {
+    while (true) {
+        int in_fd;
+        {
+            sockaddr_in addr{};
+            socklen_t len = sizeof(addr);
+
+            in_fd = accept(server_fd, (sockaddr*) &addr, &len);
+
+            if (in_fd < 0) {
+                if (errno != EAGAIN) {
+                    std::error_code ec{errno, std::system_category()};
+                    std::cerr << "Unexpected issue when accepting connection err=" << ec.message() << "\n";
+                }
+                break;
+            }
+
+            set_socket_non_blocking(in_fd);
+
+            std::cout << "Client connected to proxy fd = " << in_fd << std::endl;
+        }
+
+        int out_fd;
+        {
+            out_fd = socket(AF_INET, SOCK_STREAM, 0);
+
+            set_socket_non_blocking(out_fd);
+
+            if (out_fd < 0) {
+                std::error_code ec{errno, std::system_category()};
+                throw std::runtime_error("Unable to create socket for outbound proxy connection err = " + ec.message());
+            }
+
+            sockaddr_in addr{};
+            addr.sin_family = AF_INET;
+            addr.sin_port = htons(out_port);
+
+            inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
+
+            int res = connect(out_fd, (sockaddr*) &addr, sizeof(addr));
+
+            if (res < 0) {
+                if (errno != EINPROGRESS) {
+                    std::error_code ec{errno, std::system_category()};
+                    throw std::runtime_error("Unable to connection to server err = " + ec.message());
+                }
+            }
+
+            std::cout << "Proxy connected to server fd = " << out_fd << std::endl;
+        }
+
+        std::shared_ptr<proxy_connection> conn = std::make_shared<proxy_connection>(in_fd, out_fd);
+
+        connections[in_fd] = conn;
+        connections[out_fd] = conn;
+
+        add_socket_to_epoll(in_fd);
+        add_socket_to_epoll(out_fd);
+
+        std::cout << "Socket pair has been created in_fd = " << in_fd << " out_fd = " << out_fd << std::endl;
+    }
+}
+
+void kgb_proxy::process_socket_event(const epoll_event& ep_ev) {
+    int fd = ep_ev.data.fd;
+
+    auto it = connections.find(fd);
+    if (it == connections.end()) {
+        throw std::runtime_error("Event for unknown socket occurred fd = " + std::to_string(fd));
+    }
+
+    auto conn = it->second;
+
+    if (ep_ev.events & EPOLLIN) {
+
+        char buf[BUFF_SIZE];
+
+        int src = fd;
+        int dst = src == conn->in_sock ? conn->out_sock : conn->in_sock;
+
+        while (true) {
+            ssize_t received = recv(src, buf, sizeof(buf), 0);
+
+            if (received < 0) {
+                if (errno == EAGAIN || errno == EWOULDBLOCK) {
+                    break;
+                }
+
+                perror("recv");
+                break;
+
+            }
+
+            if (received == 0) {
+                close(src);
+                close(dst);
+
+                connections.erase(src);
+                connections.erase(dst);
+                break;
+            }
+
+            auto& queue = src == conn->in_sock ? conn->in2out_queue : conn->out2in_queue;
+            queue.emplace(buf, received);
+
+            enable_writable_notification(dst);
+        }
+    }
+
+    if (ep_ev.events & EPOLLOUT) {
+        int dst = fd;
+        int src = dst == conn->in_sock ? conn->out_sock : conn->in_sock;
+
+        auto& queue = src == conn->in_sock ? conn->in2out_queue : conn->out2in_queue;
+
+        while (!queue.empty()) {
+
+            const message_chunk& chunk = queue.front();
+            ssize_t sent = send(dst, chunk.m_msg, chunk.m_size, 0);
+
+            if (sent <= 0) {
+                if (errno == EAGAIN || errno == EWOULDBLOCK) {
+                    break;
+                }
+
+                perror("send");
+                break;
+            }
+
+            queue.pop();
+        }
+
+        disable_writable_notification(dst);

Review Comment:
   The disable_writable_notification is called unconditionally at the end of EPOLLOUT handling, even when the queue is not empty and more data needs to be sent. This could prevent the socket from being notified when it becomes writable again, potentially causing data to remain stuck in the queue. The notification should only be disabled when the queue becomes empty.
   ```suggestion
           if (queue.empty()) {
               disable_writable_notification(dst);
           }
   ```



##########
modules/platforms/cpp/tests/fake_server/proxy/kgb_proxy.cpp:
##########
@@ -0,0 +1,290 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//
+
+#include "kgb_proxy.h"
+
+#include <ignite/network/detail/linux/sockets.h>
+
+#include <fcntl.h>
+#include <iostream>
+#include <cstring>
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/epoll.h>
+#include <sys/eventfd.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+namespace ignite::proxy {
+
+void set_socket_non_blocking(int fd) {
+    using network::detail::set_non_blocking_mode;
+
+    if (!set_non_blocking_mode(fd, true)) {
+        throw std::runtime_error("Error making socket non-blocking");
+    }
+}
+
+void kgb_proxy::enable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);
+}
+
+void kgb_proxy::disable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);

Review Comment:
   The return value of epoll_ctl should be checked for errors. In the existing codebase (e.g., linux_async_worker_thread.cpp:77-83), epoll_ctl failures are checked and proper error handling is performed. Ignoring errors could lead to silent failures where events are not properly registered or modified.



##########
modules/platforms/cpp/tests/fake_server/proxy/asio_proxy.h:
##########
@@ -0,0 +1,195 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <iostream>
+#include <queue>
+#include <tuple>
+
+#include <asio.hpp>
+#include <asio/ts/buffer.hpp>
+#include <asio/ts/internet.hpp>
+
+namespace ignite::proxy {
+
+using asio::ip::tcp;
+
+struct message {
+    char *m_arr;
+    size_t m_size;
+
+    message(char *arr, size_t size)
+        : m_arr(nullptr)
+        , m_size(size) {
+        m_arr = new char[m_size];
+        std::memcpy(m_arr, arr, size);
+    }
+
+    ~message() { delete[] m_arr; }
+};
+
+class session : public std::enable_shared_from_this<session> {
+public:
+    session(tcp::socket in_sock, tcp::socket out_sock)
+        : m_in_sock(std::move(in_sock))
+        , m_out_sock(std::move(out_sock)) { }
+
+    void start() { do_serve(); }
+
+    tcp::socket &get_out_sock() { return m_out_sock; }
+
+    void set_writable(bool writable) {
+        m_in_to_out_writable = writable;
+        m_out_to_in_writable = writable;
+    }
+
+    enum direction { forward, reverse };
+
+private:
+    void do_serve() {
+        do_read(forward);
+        do_read(reverse);
+    }
+
+    void do_read(direction direction) {
+        auto tup = get_sockets_and_queue(direction);
+        tcp::socket &src = std::get<0>(tup);
+        std::queue<message> &queue = std::get<2>(tup);
+        bool &writable = std::get<3>(tup);
+
+        src.async_read_some(asio::buffer(buf, BUFF_SIZE),
+    [this, &queue, direction, &writable](asio::error_code ec, size_t len) {
+            if (ec) {
+                throw std::runtime_error("Error while reading from socket " + ec.message());
+            }
+
+            // we have one-threaded executor no synchronization is needed
+            queue.emplace(buf, len);
+
+            if (writable) { // there are pending write operation on this socket
+                do_write(direction);
+            }
+
+            do_read(direction);
+        });
+    }
+
+    void do_write(direction direction) {
+        auto tup = get_sockets_and_queue(direction);
+        tcp::socket &dst = std::get<1>(tup);
+        std::queue<message> &queue = std::get<2>(tup);
+        bool &writable = std::get<3>(tup);
+
+        writable = false; // protects from writing same buffer twice (from head of queue).
+
+        if (!queue.empty()) {
+            message &msg = queue.front();
+
+            asio::async_write(
+                dst, asio::buffer(msg.m_arr, msg.m_size), [this, &queue, direction, &writable](asio::error_code ec, size_t) {
+                    if (ec) {
+                        throw std::runtime_error("Error while writing to socket " + ec.message());
+                    }
+
+                    queue.pop();
+
+                    if (!queue.empty()) {
+                        // makes writes on the same socket strictly ordered
+                        do_write(direction);
+                    } else {
+                        writable = true; // now read operation can initiate writes
+                    }
+                });
+        }
+    }
+
+    std::tuple<tcp::socket &, tcp::socket &, std::queue<message> &, bool&> get_sockets_and_queue(direction direction) {
+        switch (direction) {
+            case forward:
+                return {m_in_sock, m_out_sock, m_in_to_out, m_in_to_out_writable};
+            case reverse:
+                return {m_out_sock, m_in_sock, m_out_to_in, m_out_to_in_writable};
+        }
+
+        throw std::runtime_error("Should be unreachable");
+    }
+
+    tcp::socket m_in_sock;
+    tcp::socket m_out_sock;
+
+    bool m_in_to_out_writable{false};
+    bool m_out_to_in_writable{false};
+
+    std::queue<message> m_in_to_out;
+    std::queue<message> m_out_to_in;
+
+    static constexpr size_t BUFF_SIZE = 4096;
+
+    char buf[BUFF_SIZE];
+};
+
+class asio_proxy {
+public:
+    asio_proxy(asio::io_context &io_context, short port)
+        : m_io_context(io_context)
+        , m_acceptor(m_io_context, tcp::endpoint(tcp::v4(), port))
+        , m_resolver(m_io_context)
+        , m_in_sock(m_io_context) {
+        do_accept();
+    }
+
+private:
+    void do_accept() {
+        m_acceptor.async_accept(m_in_sock, [this](asio::error_code ec) {
+            if (!ec) {
+                auto ses = m_sessons.emplace_back(
+                    std::make_shared<session>(std::move(m_in_sock), tcp::socket{m_io_context}));
+
+                m_resolver.async_resolve(
+                    "127.0.0.1", "50900", [ses](asio::error_code ec, tcp::resolver::results_type endpoints) {

Review Comment:
   The hardcoded port "50900" should be parameterized or made configurable. The asio_proxy constructor accepts a port parameter for the incoming connection but hardcodes the outgoing server port. This reduces flexibility and makes the proxy less reusable. Consider adding an out_port parameter to the constructor.



##########
modules/platforms/cpp/tests/fake_server/proxy/kgb_proxy.cpp:
##########
@@ -0,0 +1,290 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//
+
+#include "kgb_proxy.h"
+
+#include <ignite/network/detail/linux/sockets.h>
+
+#include <fcntl.h>
+#include <iostream>
+#include <cstring>
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/epoll.h>
+#include <sys/eventfd.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+namespace ignite::proxy {
+
+void set_socket_non_blocking(int fd) {
+    using network::detail::set_non_blocking_mode;
+
+    if (!set_non_blocking_mode(fd, true)) {
+        throw std::runtime_error("Error making socket non-blocking");
+    }
+}
+
+void kgb_proxy::enable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);
+}
+
+void kgb_proxy::disable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);
+}
+
+void kgb_proxy::do_serve() {
+    epoll_event events[MAX_EVENTS];
+
+    bool stopped = false;
+    while (!stopped) {
+        int event_cnt = epoll_wait(epoll_fd, events, MAX_EVENTS, -1);
+
+        for (int i = 0; i < event_cnt; ++i) {
+            int fd = events[i].data.fd;
+
+            if (fd == stop_event_fd) {
+                uint64_t val;
+                read(stop_event_fd, &val, sizeof(val));
+                stopped = true;
+            } else if (fd == server_fd) {
+                process_incoming_connection();
+            } else {
+                process_socket_event(events[i]);
+            }
+        }
+    }
+}
+
+void kgb_proxy::add_event_fd() {
+    stop_event_fd = eventfd(0, EFD_NONBLOCK);
+
+    epoll_event ev{};
+    ev.events = EPOLLIN;
+    ev.data.fd = stop_event_fd;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, stop_event_fd, &ev);
+}
+
+void kgb_proxy::fire_stop_event() { // NOLINT(*-make-member-function-const)
+    uint64_t one = 1;
+    write(stop_event_fd, &one, sizeof(one));
+}
+
+void kgb_proxy::start_server_socket() {
+    server_fd = socket(AF_INET, SOCK_STREAM, 0);
+    set_socket_non_blocking(server_fd);
+
+    int opt = 1;
+    setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+
+    sockaddr_in addr{};
+
+    addr.sin_family = AF_INET;
+    addr.sin_port = htons(in_port);
+    addr.sin_addr.s_addr = INADDR_ANY;
+
+    bind(server_fd, (sockaddr *) &addr, sizeof(addr));
+    listen(server_fd, 16);
+
+    epoll_event ev{};
+
+    ev.events = EPOLLIN;
+    ev.data.fd = server_fd;
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, server_fd, &ev);
+}
+
+void kgb_proxy::add_socket_to_epoll(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ev{};
+    ev.events = EPOLLIN | EPOLLET;
+    ev.data.fd = fd;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ev);

Review Comment:
   The return value of epoll_ctl should be checked for errors. In the existing codebase (e.g., linux_async_worker_thread.cpp:77-83), epoll_ctl failures are checked and proper error handling is performed.



##########
modules/platforms/cpp/tests/fake_server/proxy/kgb_proxy.cpp:
##########
@@ -0,0 +1,290 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//
+
+#include "kgb_proxy.h"
+
+#include <ignite/network/detail/linux/sockets.h>
+
+#include <fcntl.h>
+#include <iostream>
+#include <cstring>
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/epoll.h>
+#include <sys/eventfd.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+namespace ignite::proxy {
+
+void set_socket_non_blocking(int fd) {
+    using network::detail::set_non_blocking_mode;
+
+    if (!set_non_blocking_mode(fd, true)) {
+        throw std::runtime_error("Error making socket non-blocking");
+    }
+}
+
+void kgb_proxy::enable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);
+}
+
+void kgb_proxy::disable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);
+}
+
+void kgb_proxy::do_serve() {
+    epoll_event events[MAX_EVENTS];
+
+    bool stopped = false;
+    while (!stopped) {
+        int event_cnt = epoll_wait(epoll_fd, events, MAX_EVENTS, -1);
+
+        for (int i = 0; i < event_cnt; ++i) {
+            int fd = events[i].data.fd;
+
+            if (fd == stop_event_fd) {
+                uint64_t val;
+                read(stop_event_fd, &val, sizeof(val));
+                stopped = true;
+            } else if (fd == server_fd) {
+                process_incoming_connection();
+            } else {
+                process_socket_event(events[i]);
+            }
+        }
+    }
+}
+
+void kgb_proxy::add_event_fd() {
+    stop_event_fd = eventfd(0, EFD_NONBLOCK);
+
+    epoll_event ev{};
+    ev.events = EPOLLIN;
+    ev.data.fd = stop_event_fd;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, stop_event_fd, &ev);

Review Comment:
   The return values of socket system calls (eventfd, epoll_ctl) should be checked for errors before using them. Following the pattern in linux_async_worker_thread.cpp:65-83, these operations can fail and should be handled with appropriate error checking and cleanup.



##########
modules/platforms/cpp/cmake/dependencies.cmake:
##########
@@ -76,6 +99,7 @@ else()
     fetch_dependency(uni-algo https://github.com/uni-algo/uni-algo/archive/v1.2.0.tar.gz 6e0cce94a6b45ebee7b904316df9f87f)
     if (${ENABLE_TESTS})
         fetch_dependency(googletest https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz c8340a482851ef6a3fe618a082304cfc)
+        add_asio_dependency(https://github.com/chriskohlhoff/asio/archive/refs/tags/asio-1-36-0.tar.gz 6699ac1dea111c20d024f25e06e573db)

Review Comment:
   The add_asio_dependency function is called with two arguments (URL and MD5 hash) but is defined to take no parameters. This will cause a CMake error. Remove the arguments from the function call or update the function definition to accept and use these parameters.



##########
modules/platforms/cpp/tests/fake_server/connection_test.cpp:
##########
@@ -76,3 +79,42 @@ TEST_F(connection_test, request_timeout) {
         EXPECT_EQ(error::code::OPERATION_TIMEOUT, err.get_status_code());
     }
 }
+
+// TEST_F(connection_test, using_proxy) {
+//     fake_server fs{50900, get_logger()};
+//     proxy::kgb_proxy proxy{50800, 50900};
+//
+//     fs.start();
+//     proxy.start();
+//
+//     ignite_client_configuration cfg;
+//     cfg.set_logger(get_logger());
+//     cfg.set_endpoints(get_endpoints());
+//
+//     auto cl = ignite_client::start(cfg, 5s);
+//
+//     auto cluster_nodes = cl.get_cluster_nodes();
+//
+//     ASSERT_EQ(1, cluster_nodes.size());
+// }
+

Review Comment:
   The kgb_proxy class implementation is added but there is no active test for it. The test_F(connection_test, using_proxy) is commented out. While asio_proxy has a working test, leaving kgb_proxy untested could allow bugs to remain undetected. Either uncomment and fix the test, or remove the kgb_proxy implementation if it's not intended to be used.
   ```suggestion
   TEST_F(connection_test, using_proxy) {
       fake_server fs{50900, get_logger()};
       proxy::kgb_proxy proxy{50800, 50900};
   
       fs.start();
       proxy.start();
   
       ignite_client_configuration cfg;
       cfg.set_logger(get_logger());
       cfg.set_endpoints(get_endpoints());
   
       auto cl = ignite_client::start(cfg, 5s);
   
       auto cluster_nodes = cl.get_cluster_nodes();
   
       ASSERT_EQ(1, cluster_nodes.size());
   }
   ```



##########
modules/platforms/cpp/tests/fake_server/proxy/kgb_proxy.h:
##########
@@ -0,0 +1,96 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//
+
+#pragma once
+#include <cassert>
+#include <cstring>
+#include <memory>
+#include <queue>
+#include <sys/epoll.h>

Review Comment:
   The kgb_proxy class uses Linux-specific headers (sys/epoll.h, sys/eventfd.h) and system calls (epoll_create1, eventfd, epoll_ctl, epoll_wait) without any platform abstraction or guards. This code will not compile on non-Linux platforms (Windows, macOS). Consider adding platform guards or using a cross-platform abstraction layer, similar to how the codebase has separate linux/ and macos/ directories for network code.
   ```suggestion
   #include <queue>
   
   #if defined(__linux__)
   #include <sys/epoll.h>
   #else
   struct epoll_event;
   #endif
   ```



##########
modules/platforms/cpp/tests/fake_server/proxy/kgb_proxy.cpp:
##########
@@ -0,0 +1,290 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//
+
+#include "kgb_proxy.h"
+
+#include <ignite/network/detail/linux/sockets.h>
+
+#include <fcntl.h>
+#include <iostream>
+#include <cstring>
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/epoll.h>
+#include <sys/eventfd.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+namespace ignite::proxy {
+
+void set_socket_non_blocking(int fd) {
+    using network::detail::set_non_blocking_mode;
+
+    if (!set_non_blocking_mode(fd, true)) {
+        throw std::runtime_error("Error making socket non-blocking");
+    }
+}
+
+void kgb_proxy::enable_writable_notification(int fd) { // NOLINT(*-make-member-function-const)
+    epoll_event ep_ev{};
+
+    ep_ev.data.fd = fd;
+    ep_ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
+
+    epoll_ctl(epoll_fd, EPOLL_CTL_MOD, fd, &ep_ev);

Review Comment:
   The return value of epoll_ctl should be checked for errors. In the existing codebase (e.g., linux_async_worker_thread.cpp:77-83), epoll_ctl failures are checked and proper error handling is performed. Ignoring errors could lead to silent failures where events are not properly registered or modified.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org