1#include <xrpl/server/Port.h>
3#include <xrpl/basics/contract.h>
4#include <xrpl/basics/safe_cast.h>
5#include <xrpl/beast/core/LexicalCast.h>
6#include <xrpl/beast/net/IPEndpoint.h>
7#include <xrpl/beast/rfc2616.h>
8#include <xrpl/config/BasicConfig.h>
9#include <xrpl/config/Constants.h>
11#include <boost/algorithm/string/predicate.hpp>
12#include <boost/algorithm/string/trim.hpp>
13#include <boost/asio/ip/address.hpp>
14#include <boost/asio/ip/impl/network_v4.ipp>
15#include <boost/asio/ip/impl/network_v6.ipp>
16#include <boost/system/system_error.hpp>
39 s += (iter !=
protocol.cbegin() ?
"," :
"") + *iter;
46 os <<
"'" << p.
name <<
"' (ip=" << p.
ip <<
":" << p.
port <<
", ";
53 os << net.to_string();
58 os << net.to_string();
65 os <<
"secure_gateway nets:";
68 os << net.to_string();
73 os << net.to_string();
92 auto const optResult = section.
get(field);
101 boost::algorithm::trim(ip);
103 boost::asio::ip::network_v4 v4Net;
104 boost::asio::ip::network_v6 v6Net;
113 if (isUnspecified(*addr))
115 nets4.
push_back(boost::asio::ip::make_network_v4(
"0.0.0.0/0"));
116 nets6.
push_back(boost::asio::ip::make_network_v6(
"::/0"));
129 addressString +=
"/32";
130 v4Net = boost::asio::ip::make_network_v4(addressString);
134 addressString +=
"/128";
135 v6Net = boost::asio::ip::make_network_v6(addressString);
148 v4Net = boost::asio::ip::make_network_v4(ip);
151 catch (boost::system::system_error
const&)
153 v6Net = boost::asio::ip::make_network_v6(ip);
164 if (v4Net != v4Net.canonical())
166 log <<
"The configured subnet " << v4Net.to_string()
167 <<
" is not the same as the network address, which is "
168 << v4Net.canonical().to_string();
175 if (v6Net != v6Net.canonical())
177 log <<
"The configured subnet " << v6Net.to_string()
178 <<
" is not the same as the network address, which is "
179 << v6Net.canonical().to_string();
185 catch (boost::system::system_error
const& e)
187 log <<
"Invalid value '" << ip <<
"' for key '" << field <<
"' in [" << section.
name()
188 <<
"]: " << e.what();
204 port.
ip = boost::asio::ip::make_address(*optResult);
208 log <<
"Invalid value '" << *optResult <<
"' for key 'ip' in [" << section.
name()
224 if ((*port.
port == 0) && (port.
name ==
"server"))
229 log <<
"Invalid value '" << *optResult <<
"' for key "
230 <<
"'port' in [" << section.
name() <<
"]";
248 if (!boost::iequals(lim,
"unlimited"))
256 log <<
"Invalid value '" << lim <<
"' for key "
257 <<
"'limit' in [" << section.
name() <<
"]";
277 log <<
"Invalid value '" << *optResult <<
"' for key "
278 <<
"'send_queue_limit' in [" << section.
name() <<
"]";
static std::optional< Endpoint > fromStringChecked(std::string const &s)
Create an Endpoint from a string.
Holds a collection of configuration values.
std::optional< T > get(std::string const &name) const
std::string const & name() const
Returns the name of this section.
T valueOr(std::string const &name, T const &other) const
Returns a value if present, else another value.
Result splitCommas(FwdIt first, FwdIt last)
Out lexicalCastThrow(In in)
Convert from one type to another, throw on error.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool set(T &target, std::string const &name, Section const §ion)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
static void populate(Section const §ion, std::string const &field, std::ostream &log, std::vector< boost::asio::ip::network_v4 > &nets4, std::vector< boost::asio::ip::network_v6 > &nets6)
void parsePort(ParsedPort &port, Section const §ion, std::ostream &log)
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
constexpr std::enable_if_t< std::is_integral_v< Dest > &&std::is_integral_v< Src >, Dest > safeCast(Src s) noexcept
std::ostream & operator<<(std::ostream &out, BaseUInt< Bits, Tag > const &u)
XRPL_NO_SANITIZE_ADDRESS void rethrow()
Rethrow the exception currently being handled.
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
static constexpr auto kSslChain
static constexpr auto kProtocol
static constexpr auto kLimit
static constexpr auto kClientNoContextTakeover
static constexpr auto kMemoryLevel
static constexpr auto kServerMaxWindowBits
static constexpr auto kPermessageDeflate
static constexpr auto kSslKey
static constexpr auto kAdminPassword
static constexpr auto kUser
static constexpr auto kAdmin
static constexpr auto kSslCiphers
static constexpr auto kPort
static constexpr auto kServerNoContextTakeover
static constexpr auto kSslCert
static constexpr auto kSecureGateway
static constexpr auto kClientMaxWindowBits
static constexpr auto kIp
static constexpr auto kCompressLevel
static constexpr auto kAdminUser
static constexpr auto kSendQueueLimit
static constexpr auto kPassword
std::set< std::string, boost::beast::iless > protocol
std::vector< boost::asio::ip::network_v4 > adminNetsV4
std::optional< boost::asio::ip::address > ip
std::vector< boost::asio::ip::network_v6 > adminNetsV6
std::vector< boost::asio::ip::network_v6 > secureGatewayNetsV6
std::optional< std::uint16_t > port
std::vector< boost::asio::ip::network_v4 > secureGatewayNetsV4
std::uint16_t wsQueueLimit
boost::beast::websocket::permessage_deflate pmdOptions
std::string adminPassword
Configuration information for a Server listening port.
std::string protocols() const
std::vector< boost::asio::ip::network_v6 > adminNetsV6
std::vector< boost::asio::ip::network_v4 > secureGatewayNetsV4
std::vector< boost::asio::ip::network_v4 > adminNetsV4
std::vector< boost::asio::ip::network_v6 > secureGatewayNetsV6
boost::asio::ip::address ip