-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mikhail Boldyrev <miboldyrev@gmail.com>
- Loading branch information
Showing
13 changed files
with
342 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
irohad/network/impl/peer_tls_certificates_provider_root.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "network/impl/peer_tls_certificates_provider_root.hpp" | ||
|
||
using namespace iroha::network; | ||
using namespace iroha::expected; | ||
using namespace shared_model::interface::types; | ||
|
||
PeerTlsCertificatesProviderRoot::PeerTlsCertificatesProviderRoot( | ||
TLSCertificateType root_certificate) | ||
: root_certificate_(std::move(root_certificate)) {} | ||
|
||
Result<TLSCertificateType, std::string> PeerTlsCertificatesProviderRoot::get( | ||
const shared_model::interface::Peer &) const { | ||
return makeValue(root_certificate_); | ||
} | ||
|
||
Result<TLSCertificateType, std::string> PeerTlsCertificatesProviderRoot::get( | ||
const PubkeyType &) const { | ||
return makeValue(root_certificate_); | ||
} |
36 changes: 36 additions & 0 deletions
36
irohad/network/impl/peer_tls_certificates_provider_root.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef IROHA_PEER_TLS_CERTIFICATES_PROVIDER_ROOT_HPP | ||
#define IROHA_PEER_TLS_CERTIFICATES_PROVIDER_ROOT_HPP | ||
|
||
#include "network/peer_tls_certificates_provider.hpp" | ||
|
||
namespace iroha { | ||
namespace network { | ||
|
||
class PeerTlsCertificatesProviderRoot : public PeerTlsCertificatesProvider { | ||
public: | ||
PeerTlsCertificatesProviderRoot( | ||
shared_model::interface::types::TLSCertificateType root_certificate); | ||
|
||
iroha::expected::Result< | ||
shared_model::interface::types::TLSCertificateType, | ||
std::string> | ||
get(const shared_model::interface::Peer &) const override; | ||
|
||
iroha::expected::Result< | ||
shared_model::interface::types::TLSCertificateType, | ||
std::string> | ||
get(const shared_model::interface::types::PubkeyType &) const override; | ||
|
||
private: | ||
shared_model::interface::types::TLSCertificateType root_certificate_; | ||
}; | ||
|
||
} // namespace network | ||
} // namespace iroha | ||
|
||
#endif |
57 changes: 57 additions & 0 deletions
57
irohad/network/impl/peer_tls_certificates_provider_wsv.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "network/impl/peer_tls_certificates_provider_wsv.hpp" | ||
|
||
#include <mutex> | ||
|
||
#include "ametsuchi/peer_query.hpp" | ||
#include "cryptography/public_key.hpp" | ||
#include "interfaces/common_objects/peer.hpp" | ||
|
||
using namespace iroha::expected; | ||
using namespace iroha::network; | ||
using namespace shared_model::interface::types; | ||
|
||
class PeerTlsCertificatesProviderWsv::Impl { | ||
public: | ||
Impl(std::shared_ptr<iroha::ametsuchi::PeerQuery> peer_query) | ||
: peer_query_(std::move(peer_query)) {} | ||
|
||
boost::optional<std::shared_ptr<shared_model::interface::Peer>> | ||
getPeerFromWsv( | ||
const shared_model::interface::types::PubkeyType &public_key) const { | ||
std::lock_guard<std::mutex> lock(mutex_); | ||
return peer_query_->getLedgerPeerByPublicKey(public_key); | ||
} | ||
|
||
private: | ||
mutable std::mutex mutex_; | ||
std::shared_ptr<iroha::ametsuchi::PeerQuery> peer_query_; | ||
}; | ||
|
||
PeerTlsCertificatesProviderWsv::PeerTlsCertificatesProviderWsv( | ||
std::shared_ptr<iroha::ametsuchi::PeerQuery> peer_query) | ||
: impl_(std::make_unique<Impl>(std::move(peer_query))) {} | ||
|
||
PeerTlsCertificatesProviderWsv::~PeerTlsCertificatesProviderWsv() = default; | ||
|
||
Result<TLSCertificateType, std::string> PeerTlsCertificatesProviderWsv::get( | ||
const shared_model::interface::Peer &peer) const { | ||
if (not peer.tlsCertificate()) { | ||
return makeError(peer.toString() + " does not have a certificate."); | ||
} | ||
return makeValue(peer.tlsCertificate().value()); | ||
} | ||
|
||
Result<TLSCertificateType, std::string> PeerTlsCertificatesProviderWsv::get( | ||
const shared_model::interface::types::PubkeyType &public_key) const { | ||
auto opt_peer = impl_->getPeerFromWsv(public_key); | ||
if (not opt_peer) { | ||
return makeError(std::string{"Could not find peer by "} | ||
+ public_key.toString()); | ||
} | ||
return get(*opt_peer.value()); | ||
} |
53 changes: 53 additions & 0 deletions
53
irohad/network/impl/peer_tls_certificates_provider_wsv.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef IROHA_PEER_TLS_CERTIFICATES_PROVIDER_WSV_HPP | ||
#define IROHA_PEER_TLS_CERTIFICATES_PROVIDER_WSV_HPP | ||
|
||
#include "network/peer_tls_certificates_provider.hpp" | ||
|
||
#include <memory> | ||
|
||
#include "interfaces/common_objects/types.hpp" | ||
|
||
namespace shared_model { | ||
namespace interface { | ||
class Peer; | ||
} | ||
} // namespace shared_model | ||
|
||
namespace iroha { | ||
namespace ametsuchi { | ||
class PeerQuery; | ||
} | ||
namespace network { | ||
|
||
class PeerTlsCertificatesProviderWsv : public PeerTlsCertificatesProvider { | ||
public: | ||
PeerTlsCertificatesProviderWsv( | ||
std::shared_ptr<iroha::ametsuchi::PeerQuery> peer_query); | ||
|
||
~PeerTlsCertificatesProviderWsv(); | ||
|
||
iroha::expected::Result< | ||
shared_model::interface::types::TLSCertificateType, | ||
std::string> | ||
get(const shared_model::interface::Peer &peer) const override; | ||
|
||
iroha::expected::Result< | ||
shared_model::interface::types::TLSCertificateType, | ||
std::string> | ||
get(const shared_model::interface::types::PubkeyType &public_key) | ||
const override; | ||
|
||
private: | ||
class Impl; | ||
std::unique_ptr<Impl> impl_; | ||
}; | ||
|
||
}; // namespace network | ||
}; // namespace iroha | ||
|
||
#endif |
Oops, something went wrong.