xrpld
Loading...
Searching...
No Matches
include/xrpl/peerfinder/Config.h
1#pragma once
2
3#include <xrpl/beast/utility/PropertyStream.h>
4#include <xrpl/peerfinder/detail/Tuning.h>
5
6#include <cstddef>
7#include <cstdint>
8#include <optional>
9#include <string>
10#include <string_view>
11
13
20
24struct Config
25{
32
38 std::size_t outPeers = calcOutPeers(); // Note: relies on `maxPeers` being initialized
39
46
50 bool peerPrivate = true;
51
55 bool wantIncoming{true};
56
60 bool autoConnect{true};
61
66
71
75 int ipLimit{0};
76
80 bool verifyEndpoints = true;
81
82 //--------------------------------------------------------------------------
83
87 [[nodiscard]] std::size_t
88 calcOutPeers() const;
89
93 void
95
99 void
101
105 static Config
107 bool peerPrivate,
108 bool standalone,
109 PeerLimitConfig const& limits,
110 std::uint16_t port,
111 bool validationPublicKey,
112 int ipLimit,
113 bool verifyEndpoints);
114
118 friend bool
119 operator==(Config const& lhs, Config const& rhs) = default;
120};
121
122//------------------------------------------------------------------------------
123
128
143inline std::string_view
144to_string(Result result) noexcept
145{
146 switch (result)
147 {
148 case Result::InboundDisabled:
149 return "inbound disabled";
150 case Result::DuplicatePeer:
151 return "peer already connected";
152 case Result::IpLimitExceeded:
153 return "ip limit exceeded";
154 case Result::Full:
155 return "slots full";
156 case Result::Success:
157 return "success";
158 }
159
160 return "unknown";
161}
162
163} // namespace xrpl::peer_finder
static constexpr auto kDefaultMaxPeers
The default value of Config::maxPeers.
Result
Possible results from activating a slot.
std::string_view to_string(Result result) noexcept
Converts a Result enum value to its string representation.
PeerFinder configuration settings.
std::size_t outPeers
The number of automatic outbound connections to maintain.
void onWrite(beast::PropertyStream::Map &map) const
Write the configuration into a property stream.
bool wantIncoming
true if we want to accept incoming connections.
bool peerPrivate
true if we want our IP address kept private.
std::uint16_t listeningPort
The listening port number.
friend bool operator==(Config const &lhs, Config const &rhs)=default
Compares two configurations for equality field by field.
bool autoConnect
true if we want to establish connections automatically
void applyTuning()
Adjusts the values so they follow the business rules.
static Config makeConfig(bool peerPrivate, bool standalone, PeerLimitConfig const &limits, std::uint16_t port, bool validationPublicKey, int ipLimit, bool verifyEndpoints)
Make peer_finder::Config from peer limit and server mode parameters.
std::size_t inPeers
The number of automatic inbound connections to maintain.
std::size_t maxPeers
The largest number of public peer slots to allow.
int ipLimit
Limit how many incoming connections we allow per IP.
std::size_t calcOutPeers() const
Returns a suitable value for outPeers according to the rules.
bool verifyEndpoints
true if we want to verify endpoints in TMEndpoints messages
std::string features
The set of features we advertise.