hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
peer.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_SHARED_MODEL_PROTO_PEER_HPP
7 #define IROHA_SHARED_MODEL_PROTO_PEER_HPP
8 
10 
11 #include <boost/optional.hpp>
12 
14 #include "cryptography/hash.hpp"
16 #include "primitive.pb.h"
18 
19 namespace shared_model {
20  namespace proto {
21  class Peer final : public interface::Peer {
22  public:
23  template <typename PeerType>
24  explicit Peer(PeerType &&peer) : proto_(std::forward<PeerType>(peer)) {
25  if (proto_->certificate_case()) {
26  tls_certificate_ = proto_->tls_certificate();
27  }
28  }
29 
30  Peer(const Peer &o) : Peer(o.proto_) {}
31 
32  Peer(Peer &&o) noexcept : Peer(std::move(o.proto_)) {}
33 
34  const interface::types::AddressType &address() const override {
35  return proto_->address();
36  }
37 
38  const boost::optional<interface::types::TLSCertificateType>
39  &tlsCertificate() const override {
40  return tls_certificate_;
41  }
42 
43  const interface::types::PubkeyType &pubkey() const override {
44  return public_key_;
45  }
46 
47  private:
49  const interface::types::PubkeyType public_key_{
50  crypto::Hash::fromHexString(proto_->peer_key())};
51  boost::optional<std::string> tls_certificate_;
52  };
53  } // namespace proto
54 } // namespace shared_model
55 #endif // IROHA_SHARED_MODEL_PROTO_PEER_HPP
std::string AddressType
Type of peer address.
Definition: types.hpp:45
Peer(Peer &&o) noexcept
Definition: peer.hpp:32
Definition: peer.hpp:20
Definition: reference_holder.hpp:18
Definition: peer.hpp:48
const interface::types::PubkeyType & pubkey() const override
Definition: peer.hpp:43
Definition: peer.hpp:21
const boost::optional< interface::types::TLSCertificateType > & tlsCertificate() const override
Definition: peer.hpp:39
const interface::types::AddressType & address() const override
Definition: peer.hpp:34
Definition: public_key.hpp:16
Peer(const Peer &o)
Definition: peer.hpp:30
Peer(PeerType &&peer)
Definition: peer.hpp:24
Definition: command_executor.hpp:12
static Hash fromHexString(const std::string &hex)
Definition: hash.cpp:20