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 <boost/optional.hpp>
23 #include <memory>
24 #include <ripple/basics/tagged_integer.h>
25 #include <test/csf/ledgers.h>
26 #include <utility>
27 
28 namespace ripple {
29 namespace test {
30 namespace csf {
31 
32 
33 struct PeerIDTag;
34 //< Uniquely identifies a peer
36 
44 
48 {
51 
56  bool trusted_ = false;
57  bool full_ = false;
58  boost::optional<std::uint32_t> loadFee_;
59 
60 public:
61  using NodeKey = PeerKey;
62  using NodeID = PeerID;
63 
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 
132  boost::optional<std::uint32_t>
133  loadFee() const
134  {
135  return loadFee_;
136  }
137 
138  Validation const&
139  unwrap() const
140  {
141  // For the rippled implementation in which RCLValidation wraps
142  // STValidation, the csf::Validation has no more specific type it
143  // wraps, so csf::Validation unwraps to itself
144  return *this;
145  }
146 
147  auto
148  asTie() const
149  {
150  // trusted is a status set by the receiver, so it is not part of the tie
151  return std::tie(
152  ledgerID_,
153  seq_,
154  signTime_,
155  seenTime_,
156  key_,
157  nodeID_,
158  loadFee_,
159  full_);
160  }
161  bool
162  operator==(Validation const& o) const
163  {
164  return asTie() == o.asTie();
165  }
166 
167  bool
168  operator<(Validation const& o) const
169  {
170  return asTie() < o.asTie();
171  }
172 
173  void
175  {
176  trusted_ = true;
177  }
178 
179  void
181  {
182  trusted_ = false;
183  }
184 
185  void
187  {
188  seenTime_ = seen;
189  }
190 };
191 
192 } // ripple
193 } // test
194 } // csf
195 #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:64
ripple::test::csf::Validation::asTie
auto asTie() const
Definition: Validation.h:148
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:35
std::pair< PeerID, std::uint32_t >
ripple::test::csf::Validation::setTrusted
void setTrusted()
Definition: Validation.h:174
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:139
ripple::test::csf::Validation::seenTime_
NetClock::time_point seenTime_
Definition: Validation.h:53
ripple::test::csf::Validation::operator==
bool operator==(Validation const &o) const
Definition: Validation.h:162
ripple::test::csf::Validation::nodeID
PeerID nodeID() const
Definition: Validation.h:114
ripple::test::csf::Validation::trusted_
bool trusted_
Definition: Validation.h:56
ripple::test::csf::Validation::loadFee
boost::optional< std::uint32_t > loadFee() const
Definition: Validation.h:133
std::tie
T tie(T... args)
ripple::test::csf::Validation::ledgerID_
Ledger::ID ledgerID_
Definition: Validation.h:49
ripple::test::csf::Validation::seq_
Ledger::Seq seq_
Definition: Validation.h:50
ripple::test::csf::PeerKey
std::pair< PeerID, std::uint32_t > PeerKey
The current key of a peer.
Definition: Validation.h:43
std::chrono::time_point
ripple::test::csf::Validation::loadFee_
boost::optional< std::uint32_t > loadFee_
Definition: Validation.h:58
memory
ripple::test::csf::Validation::operator<
bool operator<(Validation const &o) const
Definition: Validation.h:168
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:132
ripple::test::csf::Validation
Validation of a specific ledger by a specific Peer.
Definition: Validation.h:47
ripple::test::csf::Validation::setSeen
void setSeen(NetClock::time_point seen)
Definition: Validation.h:186
ripple::test::csf::Ledger::ID
tagged_integer< std::uint32_t, IdTag > ID
Definition: ledgers.h:67
ripple::test::csf::Validation::full_
bool full_
Definition: Validation.h:57
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:54
ripple::test::csf::Validation::nodeID_
PeerID nodeID_
Definition: Validation.h:55
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:180
ripple::test::csf::Validation::signTime_
NetClock::time_point signTime_
Definition: Validation.h:52