rippled
Validation.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012-2017 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 #ifndef RIPPLE_TEST_CSF_VALIDATION_H_INCLUDED
20 #define RIPPLE_TEST_CSF_VALIDATION_H_INCLUDED
21 
22 #include <ripple/basics/tagged_integer.h>
23 #include <boost/optional.hpp>
24 #include <memory>
25 #include <test/csf/ledgers.h>
26 #include <utility>
27 
28 namespace ripple {
29 namespace test {
30 namespace csf {
31 
32 struct PeerIDTag;
33 //< Uniquely identifies a peer
35 
43 
47 {
50 
55  bool trusted_ = false;
56  bool full_ = false;
57  boost::optional<std::uint32_t> loadFee_;
58 
59 public:
60  using NodeKey = PeerKey;
61  using NodeID = PeerID;
62 
64  Ledger::ID id,
68  PeerKey key,
69  PeerID nodeID,
70  bool full,
71  boost::optional<std::uint32_t> loadFee = boost::none)
72  : ledgerID_{id}
73  , seq_{seq}
74  , signTime_{sign}
75  , seenTime_{seen}
76  , key_{key}
77  , nodeID_{nodeID}
78  , full_{full}
79  , loadFee_{loadFee}
80  {
81  }
82 
84  ledgerID() const
85  {
86  return ledgerID_;
87  }
88 
90  seq() const
91  {
92  return seq_;
93  }
94 
96  signTime() const
97  {
98  return signTime_;
99  }
100 
102  seenTime() const
103  {
104  return seenTime_;
105  }
106 
107  PeerKey
108  key() const
109  {
110  return key_;
111  }
112 
113  PeerID
114  nodeID() const
115  {
116  return nodeID_;
117  }
118 
119  bool
120  trusted() const
121  {
122  return trusted_;
123  }
124 
125  bool
126  full() const
127  {
128  return full_;
129  }
130 
131  boost::optional<std::uint32_t>
132  loadFee() const
133  {
134  return loadFee_;
135  }
136 
137  Validation const&
138  unwrap() const
139  {
140  // For the rippled implementation in which RCLValidation wraps
141  // STValidation, the csf::Validation has no more specific type it
142  // wraps, so csf::Validation unwraps to itself
143  return *this;
144  }
145 
146  auto
147  asTie() const
148  {
149  // trusted is a status set by the receiver, so it is not part of the tie
150  return std::tie(
151  ledgerID_,
152  seq_,
153  signTime_,
154  seenTime_,
155  key_,
156  nodeID_,
157  loadFee_,
158  full_);
159  }
160  bool
161  operator==(Validation const& o) const
162  {
163  return asTie() == o.asTie();
164  }
165 
166  bool
167  operator<(Validation const& o) const
168  {
169  return asTie() < o.asTie();
170  }
171 
172  void
174  {
175  trusted_ = true;
176  }
177 
178  void
180  {
181  trusted_ = false;
182  }
183 
184  void
186  {
187  seenTime_ = seen;
188  }
189 };
190 
191 } // namespace csf
192 } // namespace test
193 } // namespace ripple
194 #endif
ripple::test::csf::Validation::Validation
Validation(Ledger::ID id, Ledger::Seq seq, NetClock::time_point sign, NetClock::time_point seen, PeerKey key, PeerID nodeID, bool full, boost::optional< std::uint32_t > loadFee=boost::none)
Definition: Validation.h:63
ripple::test::csf::Validation::asTie
auto asTie() const
Definition: Validation.h:147
utility
ripple::test::csf::Validation::seenTime
NetClock::time_point seenTime() const
Definition: Validation.h:102
ripple::test::csf::PeerID
tagged_integer< std::uint32_t, PeerIDTag > PeerID
Definition: Validation.h:34
std::pair< PeerID, std::uint32_t >
ripple::test::csf::Validation::setTrusted
void setTrusted()
Definition: Validation.h:173
ripple::test::csf::Validation::seq
Ledger::Seq seq() const
Definition: Validation.h:90
ripple::test::csf::Validation::unwrap
Validation const & unwrap() const
Definition: Validation.h:138
ripple::test::csf::Validation::seenTime_
NetClock::time_point seenTime_
Definition: Validation.h:52
ripple::test::csf::Validation::operator==
bool operator==(Validation const &o) const
Definition: Validation.h:161
ripple::test::csf::Validation::nodeID
PeerID nodeID() const
Definition: Validation.h:114
ripple::test::csf::Validation::trusted_
bool trusted_
Definition: Validation.h:55
ripple::test::csf::Validation::loadFee
boost::optional< std::uint32_t > loadFee() const
Definition: Validation.h:132
std::tie
T tie(T... args)
ripple::test::csf::Validation::ledgerID_
Ledger::ID ledgerID_
Definition: Validation.h:48
ripple::test::csf::Validation::seq_
Ledger::Seq seq_
Definition: Validation.h:49
ripple::test::csf::PeerKey
std::pair< PeerID, std::uint32_t > PeerKey
The current key of a peer.
Definition: Validation.h:42
std::chrono::time_point
ripple::test::csf::Validation::loadFee_
boost::optional< std::uint32_t > loadFee_
Definition: Validation.h:57
memory
ripple::test::csf::Validation::operator<
bool operator<(Validation const &o) const
Definition: Validation.h:167
ripple::test::jtx::seq
Set the sequence number on a JTx.
Definition: seq.h:32
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::test::csf::Validation::signTime
NetClock::time_point signTime() const
Definition: Validation.h:96
ripple::sign
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &m)
Generate a signature for a message.
Definition: SecretKey.cpp:124
ripple::test::csf::Validation
Validation of a specific ledger by a specific Peer.
Definition: Validation.h:46
ripple::test::csf::Validation::setSeen
void setSeen(NetClock::time_point seen)
Definition: Validation.h:185
ripple::test::csf::Ledger::ID
tagged_integer< std::uint32_t, IdTag > ID
Definition: ledgers.h:66
ripple::test::csf::Validation::full_
bool full_
Definition: Validation.h:56
ripple::test::csf::Validation::full
bool full() const
Definition: Validation.h:126
ripple::test::csf::Validation::key
PeerKey key() const
Definition: Validation.h:108
ripple::test::csf::Validation::ledgerID
Ledger::ID ledgerID() const
Definition: Validation.h:84
ripple::test::csf::Validation::key_
PeerKey key_
Definition: Validation.h:53
ripple::test::csf::Validation::nodeID_
PeerID nodeID_
Definition: Validation.h:54
ripple::test::csf::Validation::trusted
bool trusted() const
Definition: Validation.h:120
ripple::tagged_integer< std::uint32_t, PeerIDTag >
ripple::test::csf::Validation::setUntrusted
void setUntrusted()
Definition: Validation.h:179
ripple::test::csf::Validation::signTime_
NetClock::time_point signTime_
Definition: Validation.h:51