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{
33
39 std::size_t outPeers = calcOutPeers(); // Note: relies on `maxPeers` being initialized
40
47
51 bool peerPrivate = true;
52
56 bool wantIncoming{true};
57
61 bool autoConnect{true};
62
67
72
76 int ipLimit{0};
77
81 bool verifyEndpoints = true;
82
83 //--------------------------------------------------------------------------
84
88 [[nodiscard]] std::size_t
89 calcOutPeers() const;
90
94 void
96
100 void
102
106 static Config
108 bool peerPrivate,
109 bool standalone,
110 PeerLimitConfig const& limits,
111 std::uint16_t port,
112 bool validationPublicKey,
113 int ipLimit,
114 bool verifyEndpoints);
115
119 friend bool
120 operator==(Config const& lhs, Config const& rhs) = default;
121};
122
123//------------------------------------------------------------------------------
124
129
144inline std::string_view
145to_string(Result result) noexcept
146{
147 switch (result)
148 {
149 case Result::InboundDisabled:
150 return "inbound disabled";
151 case Result::DuplicatePeer:
152 return "peer already connected";
153 case Result::IpLimitExceeded:
154 return "ip limit exceeded";
155 case Result::Full:
156 return "slots full";
157 case Result::Success:
158 return "success";
159 }
160
161 return "unknown";
162}
163
164} // 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.