rippled
RCLCxPeerPos.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef RIPPLE_APP_CONSENSUS_RCLCXPEERPOS_H_INCLUDED
21 #define RIPPLE_APP_CONSENSUS_RCLCXPEERPOS_H_INCLUDED
22 
23 #include <ripple/basics/CountedObject.h>
24 #include <ripple/basics/base_uint.h>
25 #include <ripple/beast/hash/hash_append.h>
26 #include <ripple/consensus/ConsensusProposal.h>
27 #include <ripple/json/json_value.h>
28 #include <ripple/protocol/HashPrefix.h>
29 #include <ripple/protocol/PublicKey.h>
30 #include <ripple/protocol/SecretKey.h>
31 #include <chrono>
32 #include <cstdint>
33 #include <string>
34 
35 namespace ripple {
36 
43 {
44 public:
45  //< The type of the proposed position
47 
59  PublicKey const& publicKey,
60  Slice const& signature,
61  uint256 const& suppress,
62  Proposal&& proposal);
63 
65  uint256
66  signingHash() const;
67 
69  bool
70  checkSign() const;
71 
73  Slice
74  signature() const
75  {
76  return data_->signature_;
77  }
78 
80  PublicKey const&
81  publicKey() const
82  {
83  return data_->publicKey_;
84  }
85 
87  uint256 const&
88  suppressionID() const
89  {
90  return data_->suppression_;
91  }
92 
93  Proposal const&
94  proposal() const
95  {
96  return data_->proposal_;
97  }
98 
101  getJson() const;
102 
103 private:
104  struct Data : public CountedObject<Data>
105  {
110 
111  Data(
112  PublicKey const& publicKey,
113  Slice const& signature,
114  uint256 const& suppress,
115  Proposal&& proposal);
116  };
117 
119 
120  template <class Hasher>
121  void
122  hash_append(Hasher& h) const
123  {
124  using beast::hash_append;
126  hash_append(h, std::uint32_t(proposal().proposeSeq()));
127  hash_append(h, proposal().closeTime());
128  hash_append(h, proposal().prevLedger());
129  hash_append(h, proposal().position());
130  }
131 };
132 
149 uint256
151  uint256 const& proposeHash,
152  uint256 const& previousLedger,
153  std::uint32_t proposeSeq,
154  NetClock::time_point closeTime,
155  Slice const& publicKey,
156  Slice const& signature);
157 
158 } // namespace ripple
159 
160 #endif
ripple::RCLCxPeerPos
A peer's signed, proposed position for use in RCLConsensus.
Definition: RCLCxPeerPos.h:42
ripple::RCLCxPeerPos::Data::suppression_
uint256 suppression_
Definition: RCLCxPeerPos.h:108
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:124
ripple::RCLCxPeerPos::signature
Slice signature() const
Signature of the proposal (not necessarily verified)
Definition: RCLCxPeerPos.h:74
std::shared_ptr
STL class.
ripple::RCLCxPeerPos::Data::proposal_
Proposal proposal_
Definition: RCLCxPeerPos.h:109
ripple::Slice
An immutable linear range of bytes.
Definition: Slice.h:44
ripple::Buffer
Like std::vector<char> but better.
Definition: Buffer.h:35
ripple::RCLCxPeerPos::proposal
Proposal const & proposal() const
Definition: RCLCxPeerPos.h:94
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:526
ripple::base_uint< 256 >
ripple::PublicKey
A public key.
Definition: PublicKey.h:59
chrono
ripple::RCLCxPeerPos::Proposal
ConsensusProposal< NodeID, uint256, uint256 > Proposal
Definition: RCLCxPeerPos.h:46
ripple::RCLCxPeerPos::Data::publicKey_
PublicKey publicKey_
Definition: RCLCxPeerPos.h:106
ripple::RCLCxPeerPos::signingHash
uint256 signingHash() const
Create the signing hash for the proposal.
Definition: RCLCxPeerPos.cpp:44
ripple::HashPrefix::proposal
@ proposal
proposal for signing
cstdint
std::uint32_t
ripple::RCLCxPeerPos::Data
Definition: RCLCxPeerPos.h:104
ripple::RCLCxPeerPos::Data::signature_
Buffer signature_
Definition: RCLCxPeerPos.h:107
ripple::proposalUniqueId
uint256 proposalUniqueId(uint256 const &proposeHash, uint256 const &previousLedger, std::uint32_t proposeSeq, NetClock::time_point closeTime, Slice const &publicKey, Slice const &signature)
Calculate a unique identifier for a signed proposal.
Definition: RCLCxPeerPos.cpp:72
ripple::RCLCxPeerPos::data_
std::shared_ptr< Data > data_
Definition: RCLCxPeerPos.h:118
ripple::RCLCxPeerPos::publicKey
PublicKey const & publicKey() const
Public key of peer that sent the proposal.
Definition: RCLCxPeerPos.h:81
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::RCLCxPeerPos::getJson
Json::Value getJson() const
JSON representation of proposal.
Definition: RCLCxPeerPos.cpp:61
beast::hash_append
std::enable_if_t< is_contiguously_hashable< T, Hasher >::value > hash_append(Hasher &h, T const &t) noexcept
Logically concatenate input data to a Hasher.
Definition: hash_append.h:236
ripple::RCLCxPeerPos::RCLCxPeerPos
RCLCxPeerPos(PublicKey const &publicKey, Slice const &signature, uint256 const &suppress, Proposal &&proposal)
Constructor.
Definition: RCLCxPeerPos.cpp:30
ripple::RCLCxPeerPos::suppressionID
uint256 const & suppressionID() const
Unique id used by hash router to suppress duplicates.
Definition: RCLCxPeerPos.h:88
ripple::RCLCxPeerPos::hash_append
void hash_append(Hasher &h) const
Definition: RCLCxPeerPos.h:122
ripple::RCLCxPeerPos::Data::Data
Data(PublicKey const &publicKey, Slice const &signature, uint256 const &suppress, Proposal &&proposal)
Definition: RCLCxPeerPos.cpp:91
ripple::NetClock::time_point
std::chrono::time_point< NetClock > time_point
Definition: chrono.h:56
ripple::RCLCxPeerPos::checkSign
bool checkSign() const
Verify the signing hash of the proposal.
Definition: RCLCxPeerPos.cpp:55
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::ConsensusProposal< NodeID, uint256, uint256 >
string