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_;
59 
60 public:
61  using NodeKey = PeerKey;
62  using NodeID = PeerID;
63 
65  Ledger::ID id,
69  PeerKey key,
70  PeerID nodeID,
71  bool full,
72  boost::optional<std::uint32_t> loadFee = boost::none,
74  : ledgerID_{id}
75  , seq_{seq}
76  , signTime_{sign}
77  , seenTime_{seen}
78  , key_{key}
79  , nodeID_{nodeID}
80  , full_{full}
81  , loadFee_{loadFee}
82  , cookie_{cookie}
83  {
84  }
85 
87  ledgerID() const
88  {
89  return ledgerID_;
90  }
91 
93  seq() const
94  {
95  return seq_;
96  }
97 
99  signTime() const
100  {
101  return signTime_;
102  }
103 
105  seenTime() const
106  {
107  return seenTime_;
108  }
109 
110  PeerKey
111  key() const
112  {
113  return key_;
114  }
115 
116  PeerID
117  nodeID() const
118  {
119  return nodeID_;
120  }
121 
122  bool
123  trusted() const
124  {
125  return trusted_;
126  }
127 
128  bool
129  full() const
130  {
131  return full_;
132  }
133 
135  cookie() const
136  {
137  return cookie_;
138  }
139 
140  boost::optional<std::uint32_t>
141  loadFee() const
142  {
143  return loadFee_;
144  }
145 
146  Validation const&
147  unwrap() const
148  {
149  // For the rippled implementation in which RCLValidation wraps
150  // STValidation, the csf::Validation has no more specific type it
151  // wraps, so csf::Validation unwraps to itself
152  return *this;
153  }
154 
155  auto
156  asTie() const
157  {
158  // trusted is a status set by the receiver, so it is not part of the tie
159  return std::tie(
160  ledgerID_,
161  seq_,
162  signTime_,
163  seenTime_,
164  key_,
165  nodeID_,
166  loadFee_,
167  full_);
168  }
169  bool
170  operator==(Validation const& o) const
171  {
172  return asTie() == o.asTie();
173  }
174 
175  bool
176  operator<(Validation const& o) const
177  {
178  return asTie() < o.asTie();
179  }
180 
181  void
183  {
184  trusted_ = true;
185  }
186 
187  void
189  {
190  trusted_ = false;
191  }
192 
193  void
195  {
196  seenTime_ = seen;
197  }
198 };
199 
200 } // namespace csf
201 } // namespace test
202 } // namespace ripple
203 
204 #endif
ripple::test::csf::Validation::asTie
auto asTie() const
Definition: Validation.h:156
utility
ripple::test::csf::Validation::seenTime
NetClock::time_point seenTime() const
Definition: Validation.h:105
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:182
ripple::test::csf::Validation::seq
Ledger::Seq seq() const
Definition: Validation.h:93
ripple::test::csf::Validation::unwrap
Validation const & unwrap() const
Definition: Validation.h:147
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:170
ripple::test::csf::Validation::nodeID
PeerID nodeID() const
Definition: Validation.h:117
ripple::test::csf::Validation::trusted_
bool trusted_
Definition: Validation.h:55
ripple::test::csf::Validation::cookie
std::uint64_t cookie() const
Definition: Validation.h:135
ripple::test::csf::Validation::loadFee
boost::optional< std::uint32_t > loadFee() const
Definition: Validation.h:141
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
std::uint64_t
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:176
ripple::test::jtx::seq
Set the sequence number on a JTx.
Definition: seq.h:32
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, std::uint64_t cookie=0)
Definition: Validation.h:64
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:99
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:194
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:129
ripple::test::csf::Validation::key
PeerKey key() const
Definition: Validation.h:111
ripple::test::csf::Validation::ledgerID
Ledger::ID ledgerID() const
Definition: Validation.h:87
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::cookie_
std::uint64_t cookie_
Definition: Validation.h:58
ripple::test::csf::Validation::trusted
bool trusted() const
Definition: Validation.h:123
ripple::tagged_integer< std::uint32_t, PeerIDTag >
ripple::test::csf::Validation::setUntrusted
void setUntrusted()
Definition: Validation.h:188
ripple::test::csf::Validation::signTime_
NetClock::time_point signTime_
Definition: Validation.h:51