8 #include "authority_discovery/protobuf/authority_discovery.v2.pb.h" 12 #define _PB_SPAN(f) [&](gsl::span<const uint8_t> a) { (f)(a.data(), a.size()); } 13 #define PB_SPAN_SET(a, b, c) _PB_SPAN((a).set_##b)(c) 14 #define PB_SPAN_ADD(a, b, c) _PB_SPAN((a).add_##b)(c) 18 std::vector<uint8_t> r(v.ByteSizeLong());
19 v.SerializeToArray(r.data(), r.size());
25 std::shared_ptr<runtime::AuthorityDiscoveryApi> authority_discovery_api,
27 std::shared_ptr<application::AppStateManager> app_state_manager,
28 std::shared_ptr<blockchain::BlockTree> block_tree,
29 std::shared_ptr<crypto::SessionKeys> keys,
30 const libp2p::crypto::KeyPair &libp2p_key,
31 const libp2p::crypto::marshaller::KeyMarshaller &key_marshaller,
32 std::shared_ptr<crypto::Ed25519Provider> ed_crypto_provider,
33 std::shared_ptr<crypto::Sr25519Provider> sr_crypto_provider,
35 std::shared_ptr<libp2p::protocol::kademlia::Kademlia> kademlia,
36 std::shared_ptr<libp2p::basic::Scheduler> scheduler)
37 : authority_discovery_api_(
std::move(authority_discovery_api)),
39 block_tree_(
std::move(block_tree)),
40 keys_(
std::move(keys)),
41 ed_crypto_provider_(
std::move(ed_crypto_provider)),
42 sr_crypto_provider_(
std::move(sr_crypto_provider)),
44 kademlia_(
std::move(kademlia)),
45 scheduler_(
std::move(scheduler)),
48 BOOST_ASSERT(app_state_manager !=
nullptr);
50 BOOST_ASSERT(
keys_ !=
nullptr);
55 app_state_manager->atLaunch([=] {
return start(); });
56 if (libp2p_key.privateKey.type == libp2p::crypto::Key::Type::Ed25519) {
59 crypto::Ed25519PrivateKey::fromSpan(libp2p_key.privateKey.data)
62 crypto::Ed25519PublicKey::fromSpan(libp2p_key.publicKey.data)
66 key_marshaller.marshal(libp2p_key.publicKey).value());
68 SL_WARN(
log_,
"Peer key is not ed25519");
81 if (maybe_error.has_error()) {
82 SL_ERROR(
log_,
"publishOwnAddress failed: {}", maybe_error.error());
88 auto addresses =
host_.getAddresses();
90 if (addresses.empty()) {
91 SL_ERROR(
log_,
"No listening addresses");
92 return outcome::success();
95 auto audi_key =
keys_->getAudiKeyPair();
97 SL_VERBOSE(
log_,
"No authority discovery key");
98 return outcome::success();
105 if (std::find(authorities.begin(), authorities.end(), audi_key->public_key)
106 == authorities.end()) {
108 return outcome::success();
111 ::authority_discovery::v2::AuthorityRecord record;
112 for (
const auto &address : addresses) {
113 PB_SPAN_ADD(record, addresses, address.getBytesAddress());
118 OUTCOME_TRY(auth_signature,
121 ::authority_discovery::v2::SignedAuthorityRecord signed_record;
122 PB_SPAN_SET(signed_record, auth_signature, auth_signature);
124 auto &ps = *signed_record.mutable_peer_signature();
129 return kademlia_->putValue({hash.begin(), hash.end()},
std::optional< crypto::Ed25519Keypair > libp2p_key_
struct kagome::network::Roles::@11 flags
std::shared_ptr< blockchain::BlockTree > block_tree_
outcome::result< void > publishOwnAddress()
#define PB_SPAN_SET(a, b, c)
std::vector< uint8_t > pbEncodeVec(const T &v)
std::shared_ptr< crypto::Ed25519Provider > ed_crypto_provider_
#define PB_SPAN_ADD(a, b, c)
Ed25519PrivateKey secret_key
std::shared_ptr< libp2p::basic::Scheduler > scheduler_
AddressPublisher(std::shared_ptr< runtime::AuthorityDiscoveryApi > authority_discovery_api, network::Roles roles, std::shared_ptr< application::AppStateManager > app_state_manager, std::shared_ptr< blockchain::BlockTree > block_tree, std::shared_ptr< crypto::SessionKeys > keys, const libp2p::crypto::KeyPair &libp2p_key, const libp2p::crypto::marshaller::KeyMarshaller &key_marshaller, std::shared_ptr< crypto::Ed25519Provider > ed_crypto_provider, std::shared_ptr< crypto::Sr25519Provider > sr_crypto_provider, libp2p::Host &host, std::shared_ptr< libp2p::protocol::kademlia::Kademlia > kademlia, std::shared_ptr< libp2p::basic::Scheduler > scheduler)
std::shared_ptr< crypto::SessionKeys > keys_
std::shared_ptr< libp2p::protocol::kademlia::Kademlia > kademlia_
std::optional< libp2p::crypto::ProtobufKey > libp2p_key_pb_
std::shared_ptr< runtime::AuthorityDiscoveryApi > authority_discovery_api_
common::Hash256 sha256(std::string_view input)
std::shared_ptr< crypto::Sr25519Provider > sr_crypto_provider_
Logger createLogger(const std::string &tag)