Skip to content

Commit

Permalink
StreamProtocols are passed to p2p identify
Browse files Browse the repository at this point in the history
  • Loading branch information
ErakhtinB committed Sep 25, 2024
1 parent e153bdc commit 08396cc
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 15 deletions.
6 changes: 6 additions & 0 deletions cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ hunter_config(
SECP256K1_ENABLE_MODULE_RECOVERY=ON
)

hunter_config(
libp2p
URL https://github.com/ErakhtinB/cpp-libp2p/archive/af9cc1a4f966fa3816e1bc20d8457568c2265617.tar.gz
SHA1 36ba651683d14aa561d7a9075ce60adf94376ca5
)

hunter_config(
erasure_coding_crust
# VERSION 0.0.8
Expand Down
11 changes: 10 additions & 1 deletion core/injector/application_injector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,11 @@ namespace {
primitives::GenesisBlockHeader{*header_opt, hash});
}

sptr<libp2p::StreamProtocols> get_stream_protocols() {
return std::make_shared<libp2p::StreamProtocols>(
libp2p::StreamProtocols{{"/ipfs/id/1.0.0", "/substrate/1.0"}});
}

template <typename... Ts>
auto makeApplicationInjector(sptr<application::AppConfiguration> config,
Ts &&...args) {
Expand Down Expand Up @@ -854,6 +859,10 @@ namespace {
[](const auto &injector) {
return get_genesis_block_header(injector);
}),
bind_by_lambda<libp2p::StreamProtocols>(
[](const auto &injector) {
return get_stream_protocols();
}),
di::bind<telemetry::TelemetryService>.template to<telemetry::TelemetryServiceImpl>(),
di::bind<api::InternalApi>.template to<api::InternalApiImpl>(),
di::bind<consensus::babe::BabeConfigRepository>.template to<consensus::babe::BabeConfigRepositoryImpl>(),
Expand Down Expand Up @@ -923,7 +932,7 @@ namespace kagome::injector {
KagomeNodeInjector::KagomeNodeInjector(
sptr<application::AppConfiguration> app_config)
: pimpl_{std::make_unique<KagomeNodeInjectorImpl>(
makeKagomeNodeInjector(std::move(app_config)))} {}
makeKagomeNodeInjector(std::move(app_config)))} {}

sptr<application::AppConfiguration> KagomeNodeInjector::injectAppConfig() {
return pimpl_->injector_
Expand Down
11 changes: 6 additions & 5 deletions core/network/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,24 @@ namespace kagome::network {
const Args &...args) {
struct Visitor {
std::string_view format;
libp2p::StreamProtocols protocols;
libp2p::StreamProtocols streamProtocols;

void visit(const blockchain::GenesisBlockHash &arg) {
auto x = hex_lower(arg);
protocols.emplace_back(fmt::vformat(format, fmt::make_format_args(x)));
streamProtocols.protocols.emplace_back(
fmt::vformat(format, fmt::make_format_args(x)));
}
void visit(const application::ChainSpec &arg) {
protocols.emplace_back(
streamProtocols.protocols.emplace_back(
fmt::vformat(format, fmt::make_format_args(arg.protocolId())));
}
void visit(const ProtocolPrefix &arg) {
protocols.emplace_back(
streamProtocols.protocols.emplace_back(
fmt::vformat(format, fmt::make_format_args(arg.prefix)));
}
} visitor{format, {}};
(visitor.visit(args), ...);
return visitor.protocols;
return visitor.streamProtocols;
}

} // namespace kagome::network
5 changes: 3 additions & 2 deletions core/network/impl/protocols/parachain_protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ namespace kagome::network {
const std::string &protocolName() const override {
static std::optional<std::string> protocol_name;
if (!protocol_name) {
protocol_name = base_.protocolIds().size() > 0 ? base_.protocolIds()[0]
: base_.protocolName();
protocol_name = base_.protocolIds().protocols.size() > 0
? base_.protocolIds().protocols[0]
: base_.protocolName();
}
return protocol_name.value();
}
Expand Down
2 changes: 1 addition & 1 deletion core/network/impl/protocols/protocol_base_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace kagome::network {
host_{host},
protocols_{std::move(protocols)},
log_{std::move(logger)} {
BOOST_ASSERT(!protocols_.empty());
BOOST_ASSERT(!protocols_.protocols.empty());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/network/impl/router_libp2p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace kagome::network {
main_pool_handler_->execute([weak{weak_from_this()}] {
if (auto self = weak.lock()) {
self->host_.setProtocolHandler(
{self->ping_protocol_.get()->getProtocolId()},
{{self->ping_protocol_.get()->getProtocolId()}},
[weak](libp2p::StreamAndProtocol stream_and_proto) {
if (auto self = weak.lock()) {
auto &stream = stream_and_proto.stream;
Expand Down
4 changes: 2 additions & 2 deletions core/network/rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace kagome::network {
std::function<void(outcome::result<Response>)> cb) {
host.newStream(
peer_info.id,
{protocol},
{{protocol}},
[request = std::move(request),
cb = std::move(cb)](auto &&stream_res) mutable {
if (!stream_res) {
Expand Down Expand Up @@ -164,7 +164,7 @@ namespace kagome::network {
Request request,
std::function<void(outcome::result<void>)> cb) {
host.newStream(peer_info.id,
{protocol},
{{protocol}},
[request = std::move(request),
cb = std::move(cb)](auto &&stream_res) mutable {
if (!stream_res) {
Expand Down
6 changes: 3 additions & 3 deletions test/core/network/rpc_libp2p_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ TEST_F(RpcLibp2pTest, ReadWithoutResponse) {
*/
TEST_F(RpcLibp2pTest, WriteWithResponse) {
EXPECT_CALL(host_,
newStream(peer_info_.id, libp2p::StreamProtocols{protocol_}, _))
newStream(peer_info_.id, StreamProtocols{{protocol_}}, _))
.WillOnce(
testing::InvokeArgument<2>(StreamAndProtocol{stream_, protocol_}));

Expand Down Expand Up @@ -165,7 +165,7 @@ TEST_F(RpcLibp2pTest, WriteWithResponse) {
*/
TEST_F(RpcLibp2pTest, WriteWithResponseErroredResponse) {
EXPECT_CALL(host_,
newStream(peer_info_.id, libp2p::StreamProtocols{protocol_}, _))
newStream(peer_info_.id, StreamProtocols{{protocol_}}, _))
.WillOnce(
testing::InvokeArgument<2>(StreamAndProtocol{stream_, protocol_}));

Expand Down Expand Up @@ -195,7 +195,7 @@ TEST_F(RpcLibp2pTest, WriteWithResponseErroredResponse) {
*/
TEST_F(RpcLibp2pTest, WriteWithoutResponse) {
EXPECT_CALL(host_,
newStream(peer_info_.id, libp2p::StreamProtocols{protocol_}, _))
newStream(peer_info_.id, StreamProtocols{{protocol_}}, _))
.WillOnce(
testing::InvokeArgument<2>(StreamAndProtocol{stream_, protocol_}));

Expand Down

0 comments on commit 08396cc

Please sign in to comment.