diff --git a/include/libp2p/host/basic_host/basic_host.hpp b/include/libp2p/host/basic_host/basic_host.hpp index 638575bf..3fa7a2e1 100644 --- a/include/libp2p/host/basic_host/basic_host.hpp +++ b/include/libp2p/host/basic_host/basic_host.hpp @@ -8,8 +8,8 @@ #include #include -#include #include +#include namespace libp2p::host { @@ -28,7 +28,8 @@ namespace libp2p::host { std::unique_ptr network, std::unique_ptr repo, std::shared_ptr bus, - std::shared_ptr transport_manager); + std::shared_ptr transport_manager, + Libp2pClientVersion libp2p_client_version); std::string_view getLibp2pVersion() const override; @@ -96,6 +97,7 @@ namespace libp2p::host { std::unique_ptr repo_; std::shared_ptr bus_; std::shared_ptr transport_manager_; + Libp2pClientVersion libp2p_client_version_; }; } // namespace libp2p::host diff --git a/include/libp2p/host/host.hpp b/include/libp2p/host/host.hpp index 3a14b18f..08051f4d 100644 --- a/include/libp2p/host/host.hpp +++ b/include/libp2p/host/host.hpp @@ -23,6 +23,10 @@ #include namespace libp2p { + struct Libp2pClientVersion { + std::string _; + }; + /** * Main class, which represents single peer in p2p network. * @@ -101,10 +105,10 @@ namespace libp2p { virtual std::vector getObservedAddresses() const = 0; /** - * @brief Get connectedness information for given peer - * @param p Peer info - * @return Connectedness - */ + * @brief Get connectedness information for given peer + * @param p Peer info + * @return Connectedness + */ virtual Connectedness connectedness(const peer::PeerInfo &p) const = 0; /** @@ -198,9 +202,9 @@ namespace libp2p { * @param protocol "speak" using this protocol * @param handler callback, will be executed on success or fail */ - virtual void newStream( - const peer::PeerId &peer_id, const peer::Protocol &protocol, - const StreamResultHandler &handler) = 0; + virtual void newStream(const peer::PeerId &peer_id, + const peer::Protocol &protocol, + const StreamResultHandler &handler) = 0; /** * @brief Create listener on given multiaddress. diff --git a/include/libp2p/injector/host_injector.hpp b/include/libp2p/injector/host_injector.hpp index e9525939..3d3c0d21 100644 --- a/include/libp2p/injector/host_injector.hpp +++ b/include/libp2p/injector/host_injector.hpp @@ -17,9 +17,13 @@ #include namespace libp2p::injector { + inline auto useLibp2pClientVersion(Libp2pClientVersion _) { + return boost::di::bind().template to( + std::move(_))[boost::di::override]; + } template - inline auto makeHostInjector(Ts &&... args) { + inline auto makeHostInjector(Ts &&...args) { using namespace boost; // NOLINT // clang-format off @@ -35,6 +39,8 @@ namespace libp2p::injector { di::bind.template to(protocol::SchedulerConfig {}), di::bind.template to(), + di::bind.template to(Libp2pClientVersion{"libp2p"}), + di::bind.template to(), // user-defined overrides... diff --git a/src/host/basic_host/basic_host.cpp b/src/host/basic_host/basic_host.cpp index 9daa680a..06b642c9 100644 --- a/src/host/basic_host/basic_host.cpp +++ b/src/host/basic_host/basic_host.cpp @@ -16,12 +16,14 @@ namespace libp2p::host { std::unique_ptr network, std::unique_ptr repo, std::shared_ptr bus, - std::shared_ptr transport_manager) + std::shared_ptr transport_manager, + Libp2pClientVersion libp2p_client_version) : idmgr_(std::move(idmgr)), network_(std::move(network)), repo_(std::move(repo)), bus_(std::move(bus)), - transport_manager_(std::move(transport_manager)) { + transport_manager_(std::move(transport_manager)), + libp2p_client_version_(std::move(libp2p_client_version)) { BOOST_ASSERT(idmgr_ != nullptr); BOOST_ASSERT(network_ != nullptr); BOOST_ASSERT(repo_ != nullptr); @@ -34,7 +36,7 @@ namespace libp2p::host { } std::string_view BasicHost::getLibp2pClientVersion() const { - return "libp2p"; + return libp2p_client_version_._; } peer::PeerId BasicHost::getId() const { diff --git a/test/acceptance/p2p/host/basic_host_test.cpp b/test/acceptance/p2p/host/basic_host_test.cpp index 1811681a..73e91cb6 100644 --- a/test/acceptance/p2p/host/basic_host_test.cpp +++ b/test/acceptance/p2p/host/basic_host_test.cpp @@ -47,7 +47,8 @@ struct BasicHostTest : public ::testing::Test { idmgr, std::make_unique(), std::make_unique(), std::make_shared(), - std::make_shared()); + std::make_shared(), + Libp2pClientVersion{}); peer::PeerRepositoryMock &repo = (peer::PeerRepositoryMock &)host->getPeerRepository(); diff --git a/test/acceptance/p2p/host/peer/test_peer.cpp b/test/acceptance/p2p/host/peer/test_peer.cpp index 85af7206..1f87b453 100644 --- a/test/acceptance/p2p/host/peer/test_peer.cpp +++ b/test/acceptance/p2p/host/peer/test_peer.cpp @@ -183,7 +183,7 @@ Peer::sptr Peer::makeHost(const crypto::KeyPair &keyPair) { auto peer_repo = std::make_unique( std::move(addr_repo), std::move(key_repo), std::move(protocol_repo)); - return std::make_shared(idmgr, std::move(network), - std::move(peer_repo), std::move(bus), - std::move(tmgr)); + return std::make_shared( + idmgr, std::move(network), std::move(peer_repo), std::move(bus), + std::move(tmgr), Libp2pClientVersion{}); }