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. 8
      include/libp2p/host/host.hpp
  3. 6
      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/host/host.hpp>
#include <libp2p/peer/identity_manager.hpp>
#include <libp2p/network/transport_manager.hpp>
#include <libp2p/peer/identity_manager.hpp>
namespace libp2p::host {
@ -28,7 +28,8 @@ namespace libp2p::host {
std::unique_ptr<network::Network> network,
std::unique_ptr<peer::PeerRepository> repo,
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;
@ -96,6 +97,7 @@ namespace libp2p::host {
std::unique_ptr<peer::PeerRepository> repo_;
std::shared_ptr<event::Bus> bus_;
std::shared_ptr<network::TransportManager> transport_manager_;
Libp2pClientVersion libp2p_client_version_;
};
} // namespace libp2p::host

8
include/libp2p/host/host.hpp

@ -23,6 +23,10 @@
#include <libp2p/protocol/base_protocol.hpp>
namespace libp2p {
struct Libp2pClientVersion {
std::string _;
};
/**
* Main class, which represents single peer in p2p network.
*
@ -198,8 +202,8 @@ 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,
virtual void newStream(const peer::PeerId &peer_id,
const peer::Protocol &protocol,
const StreamResultHandler &handler) = 0;
/**

6
include/libp2p/injector/host_injector.hpp

@ -17,6 +17,10 @@
#include <libp2p/protocol/common/asio/asio_scheduler.hpp>
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>
inline auto makeHostInjector(Ts &&...args) {
@ -35,6 +39,8 @@ namespace libp2p::injector {
di::bind<protocol::SchedulerConfig>.template to(protocol::SchedulerConfig {}),
di::bind<protocol::Scheduler>.template to<protocol::AsioScheduler>(),
di::bind<Libp2pClientVersion>.template to(Libp2pClientVersion{"libp2p"}),
di::bind<Host>.template to<host::BasicHost>(),
// 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<peer::PeerRepository> repo,
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)),
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 {

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

@ -47,7 +47,8 @@ struct BasicHostTest : public ::testing::Test {
idmgr, std::make_unique<network::NetworkMock>(),
std::make_unique<peer::PeerRepositoryMock>(),
std::make_shared<libp2p::event::Bus>(),
std::make_shared<libp2p::network::TransportManagerMock>());
std::make_shared<libp2p::network::TransportManagerMock>(),
Libp2pClientVersion{});
peer::PeerRepositoryMock &repo =
(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>(
std::move(addr_repo), std::move(key_repo), std::move(protocol_repo));
return std::make_shared<host::BasicHost>(idmgr, std::move(network),
std::move(peer_repo), std::move(bus),
std::move(tmgr));
return std::make_shared<host::BasicHost>(
idmgr, std::move(network), std::move(peer_repo), std::move(bus),
std::move(tmgr), Libp2pClientVersion{});
}

Loading…
Cancel
Save