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 attempt when crawling shards. cs = crawl shards
36 static constexpr std::uint32_t csHopLimit = 3;
37 
38 enum class ProtocolFeature {
41 };
42 
44 class Peer
45 {
46 public:
48 
55 
56  virtual ~Peer() = default;
57 
58  //
59  // Network
60  //
61 
62  virtual void
63  send(std::shared_ptr<Message> const& m) = 0;
64 
65  virtual beast::IP::Endpoint
66  getRemoteAddress() const = 0;
67 
69  virtual void
70  charge(Resource::Charge const& fee) = 0;
71 
72  //
73  // Identity
74  //
75 
76  virtual id_t
77  id() const = 0;
78 
80  virtual bool
81  cluster() const = 0;
82 
83  virtual bool
84  isHighLatency() const = 0;
85 
86  virtual int
87  getScore(bool) const = 0;
88 
89  virtual PublicKey const&
90  getNodePublic() const = 0;
91 
92  virtual Json::Value
93  json() = 0;
94 
95  virtual bool
96  supportsFeature(ProtocolFeature f) const = 0;
97 
98  virtual boost::optional<std::size_t>
99  publisherListSequence(PublicKey const&) const = 0;
100 
101  virtual void
103 
104  //
105  // Ledger
106  //
107 
108  virtual uint256 const&
109  getClosedLedgerHash() const = 0;
110  virtual bool
111  hasLedger(uint256 const& hash, std::uint32_t seq) const = 0;
112  virtual void
113  ledgerRange(std::uint32_t& minSeq, std::uint32_t& maxSeq) const = 0;
114  virtual bool
115  hasShard(std::uint32_t shardIndex) const = 0;
116  virtual bool
117  hasTxSet(uint256 const& hash) const = 0;
118  virtual void
119  cycleStatus() = 0;
120  virtual bool
121  hasRange(std::uint32_t uMin, std::uint32_t uMax) = 0;
122 
123  virtual bool
124  compressionEnabled() const = 0;
125 };
126 
127 } // namespace ripple
128 
129 #endif
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
ripple::csHopLimit
static constexpr std::uint32_t csHopLimit
Definition: ripple/overlay/Peer.h:36
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::Peer::isHighLatency
virtual bool isHighLatency() const =0
ripple::Peer::cycleStatus
virtual void cycleStatus()=0
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::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::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
ripple::Peer::publisherListSequence
virtual boost::optional< std::size_t > publisherListSequence(PublicKey const &) 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
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::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:39
ripple::Peer::hasShard
virtual bool hasShard(std::uint32_t shardIndex) const =0
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:44