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 {
43 };
44 
46 class Peer
47 {
48 public:
50 
57 
58  virtual ~Peer() = default;
59 
60  //
61  // Network
62  //
63 
64  virtual void
65  send(std::shared_ptr<Message> const& m) = 0;
66 
67  virtual beast::IP::Endpoint
68  getRemoteAddress() const = 0;
69 
71  virtual void
72  sendTxQueue() = 0;
73 
75  virtual void
76  addTxQueue(uint256 const&) = 0;
77 
79  virtual void
80  removeTxQueue(uint256 const&) = 0;
81 
83  virtual void
84  charge(Resource::Charge const& fee) = 0;
85 
86  //
87  // Identity
88  //
89 
90  virtual id_t
91  id() const = 0;
92 
94  virtual bool
95  cluster() const = 0;
96 
97  virtual bool
98  isHighLatency() const = 0;
99 
100  virtual int
101  getScore(bool) const = 0;
102 
103  virtual PublicKey const&
104  getNodePublic() const = 0;
105 
106  virtual Json::Value
107  json() = 0;
108 
109  virtual bool
110  supportsFeature(ProtocolFeature f) const = 0;
111 
113  publisherListSequence(PublicKey const&) const = 0;
114 
115  virtual void
117 
118  //
119  // Ledger
120  //
121 
122  virtual uint256 const&
123  getClosedLedgerHash() const = 0;
124  virtual bool
125  hasLedger(uint256 const& hash, std::uint32_t seq) const = 0;
126  virtual void
127  ledgerRange(std::uint32_t& minSeq, std::uint32_t& maxSeq) const = 0;
128  virtual bool
129  hasTxSet(uint256 const& hash) const = 0;
130  virtual void
131  cycleStatus() = 0;
132  virtual bool
133  hasRange(std::uint32_t uMin, std::uint32_t uMax) = 0;
134 
135  virtual bool
136  compressionEnabled() const = 0;
137 
138  virtual bool
139  txReduceRelayEnabled() const = 0;
140 };
141 
142 } // namespace ripple
143 
144 #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::ProtocolFeature::StartProtocol
@ StartProtocol
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:61
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:46