rippled
ripple/overlay/Peer.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_OVERLAY_PEER_H_INCLUDED
21 #define RIPPLE_OVERLAY_PEER_H_INCLUDED
22 
23 #include <ripple/basics/base_uint.h>
24 #include <ripple/beast/net/IPEndpoint.h>
25 #include <ripple/json/json_value.h>
26 #include <ripple/overlay/Message.h>
27 #include <ripple/protocol/PublicKey.h>
28 
29 namespace ripple {
30 
31 namespace Resource {
32 class Charge;
33 }
34 
35 // Maximum hops to relay the peer shard info request
36 static constexpr std::uint32_t relayLimit = 3;
37 
38 enum class ProtocolFeature {
42 };
43 
45 class Peer
46 {
47 public:
49 
56 
57  virtual ~Peer() = default;
58 
59  //
60  // Network
61  //
62 
63  virtual void
64  send(std::shared_ptr<Message> const& m) = 0;
65 
66  virtual beast::IP::Endpoint
67  getRemoteAddress() const = 0;
68 
70  virtual void
71  sendTxQueue() = 0;
72 
74  virtual void
75  addTxQueue(uint256 const&) = 0;
76 
78  virtual void
79  removeTxQueue(uint256 const&) = 0;
80 
82  virtual void
83  charge(Resource::Charge const& fee) = 0;
84 
85  //
86  // Identity
87  //
88 
89  virtual id_t
90  id() const = 0;
91 
93  virtual bool
94  cluster() const = 0;
95 
96  virtual bool
97  isHighLatency() const = 0;
98 
99  virtual int
100  getScore(bool) const = 0;
101 
102  virtual PublicKey const&
103  getNodePublic() const = 0;
104 
105  virtual Json::Value
106  json() = 0;
107 
108  virtual bool
109  supportsFeature(ProtocolFeature f) const = 0;
110 
112  publisherListSequence(PublicKey const&) const = 0;
113 
114  virtual void
116 
117  //
118  // Ledger
119  //
120 
121  virtual uint256 const&
122  getClosedLedgerHash() const = 0;
123  virtual bool
124  hasLedger(uint256 const& hash, std::uint32_t seq) const = 0;
125  virtual void
126  ledgerRange(std::uint32_t& minSeq, std::uint32_t& maxSeq) const = 0;
127  virtual bool
128  hasTxSet(uint256 const& hash) const = 0;
129  virtual void
130  cycleStatus() = 0;
131  virtual bool
132  hasRange(std::uint32_t uMin, std::uint32_t uMax) = 0;
133 
134  virtual bool
135  compressionEnabled() const = 0;
136 
137  virtual bool
138  txReduceRelayEnabled() const = 0;
139 };
140 
141 } // namespace ripple
142 
143 #endif
ripple::Peer::addTxQueue
virtual void addTxQueue(uint256 const &)=0
Aggregate transaction's hash.
ripple::Peer::ledgerRange
virtual void ledgerRange(std::uint32_t &minSeq, std::uint32_t &maxSeq) const =0
ripple::Peer::getClosedLedgerHash
virtual uint256 const & getClosedLedgerHash() const =0
std::shared_ptr
STL class.
ripple::Peer::hasRange
virtual bool hasRange(std::uint32_t uMin, std::uint32_t uMax)=0
ripple::Peer::cluster
virtual bool cluster() const =0
Returns true if this connection is a member of the cluster.
ripple::relayLimit
static constexpr std::uint32_t relayLimit
Definition: ripple/overlay/Peer.h:36
ripple::Peer::isHighLatency
virtual bool isHighLatency() const =0
ripple::Peer::cycleStatus
virtual void cycleStatus()=0
ripple::ProtocolFeature::LedgerReplay
@ LedgerReplay
ripple::Peer::getNodePublic
virtual PublicKey const & getNodePublic() const =0
ripple::Peer::hasTxSet
virtual bool hasTxSet(uint256 const &hash) const =0
ripple::Peer::send
virtual void send(std::shared_ptr< Message > const &m)=0
ripple::Peer::removeTxQueue
virtual void removeTxQueue(uint256 const &)=0
Remove hash from the transactions' hashes queue.
ripple::Peer::txReduceRelayEnabled
virtual bool txReduceRelayEnabled() const =0
ripple::Peer::charge
virtual void charge(Resource::Charge const &fee)=0
Adjust this peer's load balance based on the type of load imposed.
ripple::ProtocolFeature
ProtocolFeature
Definition: ripple/overlay/Peer.h:38
ripple::Peer::publisherListSequence
virtual std::optional< std::size_t > publisherListSequence(PublicKey const &) const =0
ripple::base_uint< 256 >
ripple::PublicKey
A public key.
Definition: PublicKey.h:59
ripple::Peer::json
virtual Json::Value json()=0
ripple::Peer::setPublisherListSequence
virtual void setPublisherListSequence(PublicKey const &, std::size_t const)=0
ripple::Peer::supportsFeature
virtual bool supportsFeature(ProtocolFeature f) const =0
std::uint32_t
ripple::Peer::hasLedger
virtual bool hasLedger(uint256 const &hash, std::uint32_t seq) const =0
ripple::Peer::getRemoteAddress
virtual beast::IP::Endpoint getRemoteAddress() const =0
ripple::Peer::sendTxQueue
virtual void sendTxQueue()=0
Send aggregated transactions' hashes.
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Peer::getScore
virtual int getScore(bool) const =0
ripple::ProtocolFeature::ValidatorList2Propagation
@ ValidatorList2Propagation
ripple::Resource::Charge
A consumption charge.
Definition: Charge.h:30
std::optional< std::size_t >
std::size_t
ripple::Peer::id
virtual id_t id() const =0
ripple::ProtocolFeature::ValidatorListPropagation
@ ValidatorListPropagation
beast::IP::Endpoint
A version-independent IP address and port combination.
Definition: IPEndpoint.h:38
ripple::Peer::~Peer
virtual ~Peer()=default
ripple::Peer::compressionEnabled
virtual bool compressionEnabled() const =0
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::Peer
Represents a peer connection in the overlay.
Definition: ripple/overlay/Peer.h:45