Loading CMakeLists.txt +31 −4 Original line number Diff line number Diff line Loading @@ -4,20 +4,20 @@ # This software was partially supported by the EuroHPC-funded project ADMIRE # # (Project ID: 956748, https://www.admire-eurohpc.eu). # # # # This file is part of cargo. # # This file is part of Cargo. # # # # cargo is free software: you can redistribute it and/or modify # # Cargo is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # cargo is distributed in the hope that it will be useful, # # Cargo is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with cargo. If not, see <https://www.gnu.org/licenses/>. # # along with Cargo. If not, see <https://www.gnu.org/licenses/>. # # # # SPDX-License-Identifier: GPL-3.0-or-later # ################################################################################ Loading Loading @@ -258,6 +258,33 @@ FetchContent_Declare( FetchContent_MakeAvailable(expected) ### Threads: required by ASIO find_package(Threads REQUIRED) ### ASIO: used for signal handling ### ### ASIO is based on autotools and not CMake package. We can use ### FetchContent to download it but we need to manually define the imported ### target ourselves rather than relying on FetchContent_MakeAvailable() ### to do it. message(STATUS "[${PROJECT_NAME}] Searching for ASIO") FetchContent_Declare( asio GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git GIT_TAG asio-1-18-2 CONFIGURE_COMMAND "" BUILD_COMMAND "" ) FetchContent_GetProperties(asio) if(NOT asio_POPULATED) FetchContent_Populate(asio) endif() add_library(asio INTERFACE) target_include_directories(asio INTERFACE ${asio_SOURCE_DIR}/asio/include) target_link_libraries(asio INTERFACE Threads::Threads) add_library(asio::asio ALIAS asio) pkg_check_modules(LIBCONFIG IMPORTED_TARGET libconfig>=1.4.9) if (CARGO_BUILD_TESTS) Loading src/master.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -94,7 +94,7 @@ ping(const thallium::request& req) { } void transfer_datasets(const net::request& req, transfer_datasets(const network::request& req, const std::vector<cargo::dataset>& sources, const std::vector<cargo::dataset>& targets) { Loading Loading @@ -138,7 +138,7 @@ transfer_datasets(const net::request& req, void master(const config::settings& cfg) { net::server daemon(cfg); network::server daemon(cfg); daemon.set_handler("ping"s, handlers::ping); daemon.set_handler("transfer_datasets"s, handlers::transfer_datasets); Loading src/net/CMakeLists.txt +39 −3 Original line number Diff line number Diff line Loading @@ -22,10 +22,46 @@ # SPDX-License-Identifier: GPL-3.0-or-later # ################################################################################ add_subdirectory(net) add_library(rpc_common OBJECT) target_sources( rpc_common INTERFACE endpoint.hpp request.hpp serialization.hpp utilities.hpp signal_listener.hpp PRIVATE endpoint.cpp ) target_link_libraries(rpc_common PUBLIC logger::logger thallium asio::asio) target_include_directories( rpc_server INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} # get the parent directory of the current directory so we can include # headers from these libraries as `<net/*.hpp>` get_filename_component(PARENT_DIRECTORY "../" ABSOLUTE) add_library(rpc_client STATIC) target_sources( rpc_client INTERFACE client.hpp PRIVATE client.cpp ) target_link_libraries(rpc_client PUBLIC rpc_common) target_include_directories(rpc_client PUBLIC ${PARENT_DIRECTORY}) set_property(TARGET rpc_client PROPERTY POSITION_INDEPENDENT_CODE ON) add_library(net::rpc_client ALIAS rpc_client) add_library(rpc_server STATIC) target_sources( rpc_server INTERFACE server.hpp PRIVATE server.cpp ) target_link_libraries(rpc_server PUBLIC rpc_common) target_include_directories(rpc_server PUBLIC ${PARENT_DIRECTORY}) set_property(TARGET rpc_server PROPERTY POSITION_INDEPENDENT_CODE ON) add_library(net::rpc_server ALIAS rpc_server) add_library(net_net STATIC) target_include_directories(net_net PUBLIC ${PARENT_DIRECTORY}) target_link_libraries(net_net PUBLIC rpc_client rpc_server) set_property(TARGET net_net PROPERTY POSITION_INDEPENDENT_CODE ON) add_library(net::net ALIAS net_net) src/net/client.cpp 0 → 100644 +59 −0 Original line number Diff line number Diff line /****************************************************************************** * Copyright 2023, Barcelona Supercomputing Center (BSC), Spain * * This software was partially supported by the EuroHPC-funded project ADMIRE * (Project ID: 956748, https://www.admire-eurohpc.eu). * * This file is part of mochi-rpc-server-cxx. * * mochi-rpc-server-cxx is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * mochi-rpc-server-cxx is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with mochi-rpc-server-cxx. If not, see * <https://www.gnu.org/licenses/>. * * SPDX-License-Identifier: GPL-3.0-or-later *****************************************************************************/ #include <optional> #include <logger/logger.hpp> #include "client.hpp" #include "endpoint.hpp" using namespace std::literals; namespace network { client::client(const std::string& protocol) : m_engine(protocol, THALLIUM_CLIENT_MODE) {} std::optional<endpoint> client::lookup(const std::string& address) noexcept { try { return endpoint{m_engine, m_engine.lookup(address)}; } catch(const std::exception& ex) { LOGGER_ERROR("client::lookup() failed: {}", ex.what()); return std::nullopt; } } std::string client::self_address() const noexcept { try { return m_engine.self(); } catch(const std::exception& ex) { LOGGER_ERROR("client::self_address() failed: {}", ex.what()); return "unknown"s; } } } // namespace network src/net/client.hpp 0 → 100644 +51 −0 Original line number Diff line number Diff line /****************************************************************************** * Copyright 2023, Barcelona Supercomputing Center (BSC), Spain * * This software was partially supported by the EuroHPC-funded project ADMIRE * (Project ID: 956748, https://www.admire-eurohpc.eu). * * This file is part of mochi-rpc-server-cxx. * * mochi-rpc-server-cxx is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * mochi-rpc-server-cxx is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with mochi-rpc-server-cxx. If not, see * <https://www.gnu.org/licenses/>. * * SPDX-License-Identifier: GPL-3.0-or-later *****************************************************************************/ #ifndef NETWORK_CLIENT_HPP #define NETWORK_CLIENT_HPP #include <optional> #include <thallium.hpp> namespace network { class endpoint; class client { public: explicit client(const std::string& protocol); std::optional<endpoint> lookup(const std::string& address) noexcept; std::string self_address() const noexcept; private: thallium::engine m_engine; }; } // namespace network #endif // NETWORK_CLIENT_HPP Loading
CMakeLists.txt +31 −4 Original line number Diff line number Diff line Loading @@ -4,20 +4,20 @@ # This software was partially supported by the EuroHPC-funded project ADMIRE # # (Project ID: 956748, https://www.admire-eurohpc.eu). # # # # This file is part of cargo. # # This file is part of Cargo. # # # # cargo is free software: you can redistribute it and/or modify # # Cargo is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # cargo is distributed in the hope that it will be useful, # # Cargo is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with cargo. If not, see <https://www.gnu.org/licenses/>. # # along with Cargo. If not, see <https://www.gnu.org/licenses/>. # # # # SPDX-License-Identifier: GPL-3.0-or-later # ################################################################################ Loading Loading @@ -258,6 +258,33 @@ FetchContent_Declare( FetchContent_MakeAvailable(expected) ### Threads: required by ASIO find_package(Threads REQUIRED) ### ASIO: used for signal handling ### ### ASIO is based on autotools and not CMake package. We can use ### FetchContent to download it but we need to manually define the imported ### target ourselves rather than relying on FetchContent_MakeAvailable() ### to do it. message(STATUS "[${PROJECT_NAME}] Searching for ASIO") FetchContent_Declare( asio GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git GIT_TAG asio-1-18-2 CONFIGURE_COMMAND "" BUILD_COMMAND "" ) FetchContent_GetProperties(asio) if(NOT asio_POPULATED) FetchContent_Populate(asio) endif() add_library(asio INTERFACE) target_include_directories(asio INTERFACE ${asio_SOURCE_DIR}/asio/include) target_link_libraries(asio INTERFACE Threads::Threads) add_library(asio::asio ALIAS asio) pkg_check_modules(LIBCONFIG IMPORTED_TARGET libconfig>=1.4.9) if (CARGO_BUILD_TESTS) Loading
src/master.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -94,7 +94,7 @@ ping(const thallium::request& req) { } void transfer_datasets(const net::request& req, transfer_datasets(const network::request& req, const std::vector<cargo::dataset>& sources, const std::vector<cargo::dataset>& targets) { Loading Loading @@ -138,7 +138,7 @@ transfer_datasets(const net::request& req, void master(const config::settings& cfg) { net::server daemon(cfg); network::server daemon(cfg); daemon.set_handler("ping"s, handlers::ping); daemon.set_handler("transfer_datasets"s, handlers::transfer_datasets); Loading
src/net/CMakeLists.txt +39 −3 Original line number Diff line number Diff line Loading @@ -22,10 +22,46 @@ # SPDX-License-Identifier: GPL-3.0-or-later # ################################################################################ add_subdirectory(net) add_library(rpc_common OBJECT) target_sources( rpc_common INTERFACE endpoint.hpp request.hpp serialization.hpp utilities.hpp signal_listener.hpp PRIVATE endpoint.cpp ) target_link_libraries(rpc_common PUBLIC logger::logger thallium asio::asio) target_include_directories( rpc_server INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} # get the parent directory of the current directory so we can include # headers from these libraries as `<net/*.hpp>` get_filename_component(PARENT_DIRECTORY "../" ABSOLUTE) add_library(rpc_client STATIC) target_sources( rpc_client INTERFACE client.hpp PRIVATE client.cpp ) target_link_libraries(rpc_client PUBLIC rpc_common) target_include_directories(rpc_client PUBLIC ${PARENT_DIRECTORY}) set_property(TARGET rpc_client PROPERTY POSITION_INDEPENDENT_CODE ON) add_library(net::rpc_client ALIAS rpc_client) add_library(rpc_server STATIC) target_sources( rpc_server INTERFACE server.hpp PRIVATE server.cpp ) target_link_libraries(rpc_server PUBLIC rpc_common) target_include_directories(rpc_server PUBLIC ${PARENT_DIRECTORY}) set_property(TARGET rpc_server PROPERTY POSITION_INDEPENDENT_CODE ON) add_library(net::rpc_server ALIAS rpc_server) add_library(net_net STATIC) target_include_directories(net_net PUBLIC ${PARENT_DIRECTORY}) target_link_libraries(net_net PUBLIC rpc_client rpc_server) set_property(TARGET net_net PROPERTY POSITION_INDEPENDENT_CODE ON) add_library(net::net ALIAS net_net)
src/net/client.cpp 0 → 100644 +59 −0 Original line number Diff line number Diff line /****************************************************************************** * Copyright 2023, Barcelona Supercomputing Center (BSC), Spain * * This software was partially supported by the EuroHPC-funded project ADMIRE * (Project ID: 956748, https://www.admire-eurohpc.eu). * * This file is part of mochi-rpc-server-cxx. * * mochi-rpc-server-cxx is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * mochi-rpc-server-cxx is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with mochi-rpc-server-cxx. If not, see * <https://www.gnu.org/licenses/>. * * SPDX-License-Identifier: GPL-3.0-or-later *****************************************************************************/ #include <optional> #include <logger/logger.hpp> #include "client.hpp" #include "endpoint.hpp" using namespace std::literals; namespace network { client::client(const std::string& protocol) : m_engine(protocol, THALLIUM_CLIENT_MODE) {} std::optional<endpoint> client::lookup(const std::string& address) noexcept { try { return endpoint{m_engine, m_engine.lookup(address)}; } catch(const std::exception& ex) { LOGGER_ERROR("client::lookup() failed: {}", ex.what()); return std::nullopt; } } std::string client::self_address() const noexcept { try { return m_engine.self(); } catch(const std::exception& ex) { LOGGER_ERROR("client::self_address() failed: {}", ex.what()); return "unknown"s; } } } // namespace network
src/net/client.hpp 0 → 100644 +51 −0 Original line number Diff line number Diff line /****************************************************************************** * Copyright 2023, Barcelona Supercomputing Center (BSC), Spain * * This software was partially supported by the EuroHPC-funded project ADMIRE * (Project ID: 956748, https://www.admire-eurohpc.eu). * * This file is part of mochi-rpc-server-cxx. * * mochi-rpc-server-cxx is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * mochi-rpc-server-cxx is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with mochi-rpc-server-cxx. If not, see * <https://www.gnu.org/licenses/>. * * SPDX-License-Identifier: GPL-3.0-or-later *****************************************************************************/ #ifndef NETWORK_CLIENT_HPP #define NETWORK_CLIENT_HPP #include <optional> #include <thallium.hpp> namespace network { class endpoint; class client { public: explicit client(const std::string& protocol); std::optional<endpoint> lookup(const std::string& address) noexcept; std::string self_address() const noexcept; private: thallium::engine m_engine; }; } // namespace network #endif // NETWORK_CLIENT_HPP