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 <boost/container/static_vector.hpp>
32 #include <chrono>
33 #include <cstdint>
34 #include <string>
35 
36 namespace ripple {
37 
44 {
45 public:
46  //< The type of the proposed position
48 
60  PublicKey const& publicKey,
61  Slice const& signature,
62  uint256 const& suppress,
63  Proposal&& proposal);
64 
66  bool
67  checkSign() const;
68 
70  Slice
71  signature() const
72  {
73  return {signature_.data(), signature_.size()};
74  }
75 
77  PublicKey const&
78  publicKey() const
79  {
80  return publicKey_;
81  }
82 
84  uint256 const&
85  suppressionID() const
86  {
87  return suppression_;
88  }
89 
90  Proposal const&
91  proposal() const
92  {
93  return proposal_;
94  }
95 
98  getJson() const;
99 
100 private:
104  boost::container::static_vector<std::uint8_t, 72> signature_;
105 
106  template <class Hasher>
107  void
108  hash_append(Hasher& h) const
109  {
110  using beast::hash_append;
112  hash_append(h, std::uint32_t(proposal().proposeSeq()));
113  hash_append(h, proposal().closeTime());
114  hash_append(h, proposal().prevLedger());
115  hash_append(h, proposal().position());
116  }
117 };
118 
135 uint256
137  uint256 const& proposeHash,
138  uint256 const& previousLedger,
139  std::uint32_t proposeSeq,
140  NetClock::time_point closeTime,
141  Slice const& publicKey,
142  Slice const& signature);
143 
144 } // namespace ripple
145 
146 #endif
ripple::RCLCxPeerPos::proposal_
Proposal proposal_
Definition: RCLCxPeerPos.h:103
ripple::RCLCxPeerPos
A peer's signed, proposed position for use in RCLConsensus.
Definition: RCLCxPeerPos.h:43
ripple::RCLCxPeerPos::signature
Slice signature() const
Signature of the proposal (not necessarily verified)
Definition: RCLCxPeerPos.h:71
ripple::Slice
An immutable linear range of bytes.
Definition: Slice.h:44
ripple::RCLCxPeerPos::proposal
Proposal const & proposal() const
Definition: RCLCxPeerPos.h:91
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:550
ripple::RCLCxPeerPos::signature_
boost::container::static_vector< std::uint8_t, 72 > signature_
Definition: RCLCxPeerPos.h:104
ripple::base_uint< 256 >
ripple::PublicKey
A public key.
Definition: PublicKey.h:59
ripple::RCLCxPeerPos::suppression_
uint256 suppression_
Definition: RCLCxPeerPos.h:102
chrono
ripple::RCLCxPeerPos::Proposal
ConsensusProposal< NodeID, uint256, uint256 > Proposal
Definition: RCLCxPeerPos.h:47
ripple::RCLCxPeerPos::publicKey_
PublicKey publicKey_
Definition: RCLCxPeerPos.h:101
ripple::HashPrefix::proposal
@ proposal
proposal for signing
cstdint
std::uint32_t
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:66
ripple::RCLCxPeerPos::publicKey
PublicKey const & publicKey() const
Public key of peer that sent the proposal.
Definition: RCLCxPeerPos.h:78
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:55
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:85
ripple::RCLCxPeerPos::hash_append
void hash_append(Hasher &h) const
Definition: RCLCxPeerPos.h:108
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:48
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::ConsensusProposal< NodeID, uint256, uint256 >
string