Browse Source

agent version

Signed-off-by: turuslan <turuslan.devbox@gmail.com>
tmp/fuhon2
turuslan 3 years ago
parent
commit
6d13dfecc5
  1. 6
      include/libp2p/host/basic_host/basic_host.hpp
  2. 18
      include/libp2p/host/host.hpp
  3. 8
      include/libp2p/injector/host_injector.hpp
  4. 8
      src/host/basic_host/basic_host.cpp
  5. 3
      test/acceptance/p2p/host/basic_host_test.cpp
  6. 6
      test/acceptance/p2p/host/peer/test_peer.cpp

6
include/libp2p/host/basic_host/basic_host.hpp

@ -8,8 +8,8 @@
#include <libp2p/event/bus.hpp> #include <libp2p/event/bus.hpp>
#include <libp2p/host/host.hpp> #include <libp2p/host/host.hpp>
#include <libp2p/peer/identity_manager.hpp>
#include <libp2p/network/transport_manager.hpp> #include <libp2p/network/transport_manager.hpp>
#include <libp2p/peer/identity_manager.hpp>
namespace libp2p::host { namespace libp2p::host {
@ -28,7 +28,8 @@ namespace libp2p::host {
std::unique_ptr<network::Network> network, std::unique_ptr<network::Network> network,
std::unique_ptr<peer::PeerRepository> repo, std::unique_ptr<peer::PeerRepository> repo,
std::shared_ptr<event::Bus> bus, std::shared_ptr<event::Bus> bus,
std::shared_ptr<network::TransportManager> transport_manager); std::shared_ptr<network::TransportManager> transport_manager,
Libp2pClientVersion libp2p_client_version);
std::string_view getLibp2pVersion() const override; std::string_view getLibp2pVersion() const override;
@ -96,6 +97,7 @@ namespace libp2p::host {
std::unique_ptr<peer::PeerRepository> repo_; std::unique_ptr<peer::PeerRepository> repo_;
std::shared_ptr<event::Bus> bus_; std::shared_ptr<event::Bus> bus_;
std::shared_ptr<network::TransportManager> transport_manager_; std::shared_ptr<network::TransportManager> transport_manager_;
Libp2pClientVersion libp2p_client_version_;
}; };
} // namespace libp2p::host } // namespace libp2p::host

18
include/libp2p/host/host.hpp

@ -23,6 +23,10 @@
#include <libp2p/protocol/base_protocol.hpp> #include <libp2p/protocol/base_protocol.hpp>
namespace libp2p { namespace libp2p {
struct Libp2pClientVersion {
std::string _;
};
/** /**
* Main class, which represents single peer in p2p network. * Main class, which represents single peer in p2p network.
* *
@ -101,10 +105,10 @@ namespace libp2p {
virtual std::vector<multi::Multiaddress> getObservedAddresses() const = 0; virtual std::vector<multi::Multiaddress> getObservedAddresses() const = 0;
/** /**
* @brief Get connectedness information for given peer * @brief Get connectedness information for given peer
* @param p Peer info * @param p Peer info
* @return Connectedness * @return Connectedness
*/ */
virtual Connectedness connectedness(const peer::PeerInfo &p) const = 0; virtual Connectedness connectedness(const peer::PeerInfo &p) const = 0;
/** /**
@ -198,9 +202,9 @@ namespace libp2p {
* @param protocol "speak" using this protocol * @param protocol "speak" using this protocol
* @param handler callback, will be executed on success or fail * @param handler callback, will be executed on success or fail
*/ */
virtual void newStream( virtual void newStream(const peer::PeerId &peer_id,
const peer::PeerId &peer_id, const peer::Protocol &protocol, const peer::Protocol &protocol,
const StreamResultHandler &handler) = 0; const StreamResultHandler &handler) = 0;
/** /**
* @brief Create listener on given multiaddress. * @brief Create listener on given multiaddress.

8
include/libp2p/injector/host_injector.hpp

@ -17,9 +17,13 @@
#include <libp2p/protocol/common/asio/asio_scheduler.hpp> #include <libp2p/protocol/common/asio/asio_scheduler.hpp>
namespace libp2p::injector { namespace libp2p::injector {
inline auto useLibp2pClientVersion(Libp2pClientVersion _) {
return boost::di::bind<Libp2pClientVersion>().template to(
std::move(_))[boost::di::override];
}
template <typename InjectorConfig = BOOST_DI_CFG, typename... Ts> template <typename InjectorConfig = BOOST_DI_CFG, typename... Ts>
inline auto makeHostInjector(Ts &&... args) { inline auto makeHostInjector(Ts &&...args) {
using namespace boost; // NOLINT using namespace boost; // NOLINT
// clang-format off // clang-format off
@ -35,6 +39,8 @@ namespace libp2p::injector {
di::bind<protocol::SchedulerConfig>.template to(protocol::SchedulerConfig {}), di::bind<protocol::SchedulerConfig>.template to(protocol::SchedulerConfig {}),
di::bind<protocol::Scheduler>.template to<protocol::AsioScheduler>(), di::bind<protocol::Scheduler>.template to<protocol::AsioScheduler>(),
di::bind<Libp2pClientVersion>.template to(Libp2pClientVersion{"libp2p"}),
di::bind<Host>.template to<host::BasicHost>(), di::bind<Host>.template to<host::BasicHost>(),
// user-defined overrides... // user-defined overrides...

8
src/host/basic_host/basic_host.cpp

@ -16,12 +16,14 @@ namespace libp2p::host {
std::unique_ptr<network::Network> network, std::unique_ptr<network::Network> network,
std::unique_ptr<peer::PeerRepository> repo, std::unique_ptr<peer::PeerRepository> repo,
std::shared_ptr<event::Bus> bus, std::shared_ptr<event::Bus> bus,
std::shared_ptr<network::TransportManager> transport_manager) std::shared_ptr<network::TransportManager> transport_manager,
Libp2pClientVersion libp2p_client_version)
: idmgr_(std::move(idmgr)), : idmgr_(std::move(idmgr)),
network_(std::move(network)), network_(std::move(network)),
repo_(std::move(repo)), repo_(std::move(repo)),
bus_(std::move(bus)), 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(idmgr_ != nullptr);
BOOST_ASSERT(network_ != nullptr); BOOST_ASSERT(network_ != nullptr);
BOOST_ASSERT(repo_ != nullptr); BOOST_ASSERT(repo_ != nullptr);
@ -34,7 +36,7 @@ namespace libp2p::host {
} }
std::string_view BasicHost::getLibp2pClientVersion() const { std::string_view BasicHost::getLibp2pClientVersion() const {
return "libp2p"; return libp2p_client_version_._;
} }
peer::PeerId BasicHost::getId() const { peer::PeerId BasicHost::getId() const {

3
test/acceptance/p2p/host/basic_host_test.cpp

@ -47,7 +47,8 @@ struct BasicHostTest : public ::testing::Test {
idmgr, std::make_unique<network::NetworkMock>(), idmgr, std::make_unique<network::NetworkMock>(),
std::make_unique<peer::PeerRepositoryMock>(), std::make_unique<peer::PeerRepositoryMock>(),
std::make_shared<libp2p::event::Bus>(), std::make_shared<libp2p::event::Bus>(),
std::make_shared<libp2p::network::TransportManagerMock>()); std::make_shared<libp2p::network::TransportManagerMock>(),
Libp2pClientVersion{});
peer::PeerRepositoryMock &repo = peer::PeerRepositoryMock &repo =
(peer::PeerRepositoryMock &)host->getPeerRepository(); (peer::PeerRepositoryMock &)host->getPeerRepository();

6
test/acceptance/p2p/host/peer/test_peer.cpp

@ -183,7 +183,7 @@ Peer::sptr<host::BasicHost> Peer::makeHost(const crypto::KeyPair &keyPair) {
auto peer_repo = std::make_unique<peer::PeerRepositoryImpl>( auto peer_repo = std::make_unique<peer::PeerRepositoryImpl>(
std::move(addr_repo), std::move(key_repo), std::move(protocol_repo)); std::move(addr_repo), std::move(key_repo), std::move(protocol_repo));
return std::make_shared<host::BasicHost>(idmgr, std::move(network), return std::make_shared<host::BasicHost>(
std::move(peer_repo), std::move(bus), idmgr, std::move(network), std::move(peer_repo), std::move(bus),
std::move(tmgr)); std::move(tmgr), Libp2pClientVersion{});
} }

Loading…
Cancel
Save