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/Protocol.h>
30 #include <ripple/protocol/PublicKey.h>
31 #include <ripple/protocol/SecretKey.h>
32 #include <boost/container/static_vector.hpp>
33 #include <chrono>
34 #include <cstdint>
35 #include <string>
36 
37 namespace ripple {
38 
45 {
46 public:
47  //< The type of the proposed position
49 
61  PublicKey const& publicKey,
62  Slice const& signature,
63  uint256 const& suppress,
64  Proposal&& proposal);
65 
67  bool
68  checkSign() const;
69 
71  Slice
72  signature() const
73  {
74  return {signature_.data(), signature_.size()};
75  }
76 
78  PublicKey const&
79  publicKey() const
80  {
81  return publicKey_;
82  }
83 
85  uint256 const&
86  suppressionID() const
87  {
88  return suppression_;
89  }
90 
91  Proposal const&
92  proposal() const
93  {
94  return proposal_;
95  }
96 
99  getJson() const;
100 
101 private:
105  boost::container::static_vector<std::uint8_t, 72> signature_;
106 
107  template <class Hasher>
108  void
109  hash_append(Hasher& h) const
110  {
111  using beast::hash_append;
113  hash_append(h, std::uint32_t(proposal().proposeSeq()));
114  hash_append(h, proposal().closeTime());
115  hash_append(h, proposal().prevLedger());
116  hash_append(h, proposal().position());
117  }
118 };
119 
136 uint256
138  uint256 const& proposeHash,
139  uint256 const& previousLedger,
140  std::uint32_t proposeSeq,
141  NetClock::time_point closeTime,
142  Slice const& publicKey,
143  Slice const& signature);
144 
145 } // namespace ripple
146 
147 #endif
ripple::RCLCxPeerPos::proposal_
Proposal proposal_
Definition: RCLCxPeerPos.h:104
ripple::RCLCxPeerPos
A peer's signed, proposed position for use in RCLConsensus.
Definition: RCLCxPeerPos.h:44
ripple::RCLCxPeerPos::signature
Slice signature() const
Signature of the proposal (not necessarily verified)
Definition: RCLCxPeerPos.h:72
ripple::Slice
An immutable linear range of bytes.
Definition: Slice.h:44
ripple::RCLCxPeerPos::Proposal
ConsensusProposal< NodeID, uint256, uint256, LedgerIndex > Proposal
Definition: RCLCxPeerPos.h:48
ripple::RCLCxPeerPos::proposal
Proposal const & proposal() const
Definition: RCLCxPeerPos.h:92
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:105
ripple::base_uint< 256 >
ripple::PublicKey
A public key.
Definition: PublicKey.h:61
ripple::RCLCxPeerPos::suppression_
uint256 suppression_
Definition: RCLCxPeerPos.h:103
chrono
ripple::RCLCxPeerPos::publicKey_
PublicKey publicKey_
Definition: RCLCxPeerPos.h:102
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:79
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:86
ripple::RCLCxPeerPos::hash_append
void hash_append(Hasher &h) const
Definition: RCLCxPeerPos.h:109
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, LedgerIndex >
string