1#include <xrpl/basics/BasicConfig.h>
2#include <xrpl/basics/contract.h>
3#include <xrpl/basics/safe_cast.h>
4#include <xrpl/beast/core/LexicalCast.h>
5#include <xrpl/beast/net/IPEndpoint.h>
6#include <xrpl/beast/rfc2616.h>
7#include <xrpl/server/Port.h>
9#include <boost/algorithm/string/predicate.hpp>
10#include <boost/algorithm/string/trim.hpp>
11#include <boost/asio/ip/address.hpp>
12#include <boost/asio/ip/impl/network_v4.ipp>
13#include <boost/asio/ip/impl/network_v6.ipp>
14#include <boost/system/system_error.hpp>
38 s += (iter !=
protocol.cbegin() ?
"," :
"") + *iter;
45 os <<
"'" << p.
name <<
"' (ip=" << p.
ip <<
":" << p.
port <<
", ";
52 os << net.to_string();
57 os << net.to_string();
64 os <<
"secure_gateway nets:";
67 os << net.to_string();
72 os << net.to_string();
91 auto const optResult = section.
get(field);
100 boost::algorithm::trim(ip);
102 boost::asio::ip::network_v4 v4Net;
103 boost::asio::ip::network_v6 v6Net;
112 if (is_unspecified(*addr))
114 nets4.
push_back(boost::asio::ip::make_network_v4(
"0.0.0.0/0"));
115 nets6.
push_back(boost::asio::ip::make_network_v6(
"::/0"));
128 addressString +=
"/32";
129 v4Net = boost::asio::ip::make_network_v4(addressString);
133 addressString +=
"/128";
134 v6Net = boost::asio::ip::make_network_v6(addressString);
147 v4Net = boost::asio::ip::make_network_v4(ip);
150 catch (boost::system::system_error
const&)
152 v6Net = boost::asio::ip::make_network_v6(ip);
163 if (v4Net != v4Net.canonical())
165 log <<
"The configured subnet " << v4Net.to_string()
166 <<
" is not the same as the network address, which is " << v4Net.canonical().to_string();
167 Throw<std::exception>();
173 if (v6Net != v6Net.canonical())
175 log <<
"The configured subnet " << v6Net.to_string()
176 <<
" is not the same as the network address, which is " << v6Net.canonical().to_string();
177 Throw<std::exception>();
182 catch (boost::system::system_error
const& e)
184 log <<
"Invalid value '" << ip <<
"' for key '" << field <<
"' in [" << section.
name() <<
"]: " << e.what();
185 Throw<std::exception>();
195 auto const optResult = section.
get(
"ip");
200 port.
ip = boost::asio::ip::make_address(*optResult);
204 log <<
"Invalid value '" << *optResult <<
"' for key 'ip' in [" << section.
name() <<
"]";
211 auto const optResult = section.
get(
"port");
216 port.
port = beast::lexicalCastThrow<std::uint16_t>(*optResult);
219 if ((*port.
port == 0) && (port.
name ==
"server"))
220 Throw<std::exception>();
224 log <<
"Invalid value '" << *optResult <<
"' for key "
225 <<
"'port' in [" << section.
name() <<
"]";
232 auto const optResult = section.
get(
"protocol");
241 auto const lim =
get(section,
"limit",
"unlimited");
243 if (!boost::iequals(lim,
"unlimited"))
247 port.
limit = safe_cast<int>(beast::lexicalCastThrow<std::uint16_t>(lim));
251 log <<
"Invalid value '" << lim <<
"' for key "
252 <<
"'limit' in [" << section.
name() <<
"]";
259 auto const optResult = section.
get(
"send_queue_limit");
264 port.
ws_queue_limit = beast::lexicalCastThrow<std::uint16_t>(*optResult);
268 Throw<std::exception>();
272 log <<
"Invalid value '" << *optResult <<
"' for key "
273 <<
"'send_queue_limit' in [" << section.
name() <<
"]";
287 set(port.
user,
"user", section);
299 port.
pmd_options.client_no_context_takeover = section.
value_or(
"client_no_context_takeover",
false);
300 port.
pmd_options.server_no_context_takeover = section.
value_or(
"server_no_context_takeover",
false);
static std::optional< Endpoint > from_string_checked(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 value_or(std::string const &name, T const &other) const
Returns a value if present, else another value.
Result split_commas(FwdIt first, FwdIt last)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void parse_Port(ParsedPort &port, Section const §ion, std::ostream &log)
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)
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
void Rethrow()
Rethrow the exception currently being handled.
std::set< std::string, boost::beast::iless > protocol
boost::beast::websocket::permessage_deflate pmd_options
std::optional< boost::asio::ip::address > ip
std::vector< boost::asio::ip::network_v6 > secure_gateway_nets_v6
std::string admin_password
std::vector< boost::asio::ip::network_v4 > secure_gateway_nets_v4
std::uint16_t ws_queue_limit
std::vector< boost::asio::ip::network_v4 > admin_nets_v4
std::optional< std::uint16_t > port
std::vector< boost::asio::ip::network_v6 > admin_nets_v6
Configuration information for a Server listening port.
std::vector< boost::asio::ip::network_v4 > admin_nets_v4
std::string protocols() const
std::vector< boost::asio::ip::network_v6 > secure_gateway_nets_v6
boost::asio::ip::address ip
std::vector< boost::asio::ip::network_v4 > secure_gateway_nets_v4
std::vector< boost::asio::ip::network_v6 > admin_nets_v6