20#include <xrpl/basics/BasicConfig.h>
21#include <xrpl/basics/contract.h>
22#include <xrpl/basics/safe_cast.h>
23#include <xrpl/beast/core/LexicalCast.h>
24#include <xrpl/beast/net/IPEndpoint.h>
25#include <xrpl/beast/rfc2616.h>
26#include <xrpl/server/Port.h>
28#include <boost/algorithm/string/predicate.hpp>
29#include <boost/algorithm/string/trim.hpp>
30#include <boost/asio/ip/address.hpp>
31#include <boost/asio/ip/impl/network_v4.ipp>
32#include <boost/asio/ip/impl/network_v6.ipp>
33#include <boost/system/system_error.hpp>
56 s += (iter !=
protocol.cbegin() ?
"," :
"") + *iter;
63 os <<
"'" << p.
name <<
"' (ip=" << p.
ip <<
":" << p.
port <<
", ";
70 os << net.to_string();
75 os << net.to_string();
82 os <<
"secure_gateway nets:";
85 os << net.to_string();
90 os << net.to_string();
109 auto const optResult = section.
get(field);
118 boost::algorithm::trim(ip);
120 boost::asio::ip::network_v4 v4Net;
121 boost::asio::ip::network_v6 v6Net;
130 if (is_unspecified(*addr))
133 boost::asio::ip::make_network_v4(
"0.0.0.0/0"));
134 nets6.
push_back(boost::asio::ip::make_network_v6(
"::/0"));
147 addressString +=
"/32";
148 v4Net = boost::asio::ip::make_network_v4(addressString);
152 addressString +=
"/128";
153 v6Net = boost::asio::ip::make_network_v6(addressString);
166 v4Net = boost::asio::ip::make_network_v4(ip);
169 catch (boost::system::system_error
const&)
171 v6Net = boost::asio::ip::make_network_v6(ip);
182 if (v4Net != v4Net.canonical())
184 log <<
"The configured subnet " << v4Net.to_string()
185 <<
" is not the same as the network address, which is "
186 << v4Net.canonical().to_string();
187 Throw<std::exception>();
193 if (v6Net != v6Net.canonical())
195 log <<
"The configured subnet " << v6Net.to_string()
196 <<
" is not the same as the network address, which is "
197 << v6Net.canonical().to_string();
198 Throw<std::exception>();
203 catch (boost::system::system_error
const& e)
205 log <<
"Invalid value '" << ip <<
"' for key '" << field <<
"' in ["
206 << section.
name() <<
"]: " << e.what();
207 Throw<std::exception>();
217 auto const optResult = section.
get(
"ip");
222 port.
ip = boost::asio::ip::address::from_string(*optResult);
226 log <<
"Invalid value '" << *optResult <<
"' for key 'ip' in ["
227 << section.
name() <<
"]";
234 auto const optResult = section.
get(
"port");
239 port.
port = beast::lexicalCastThrow<std::uint16_t>(*optResult);
242 if ((*port.
port == 0) && (port.
name ==
"server"))
243 Throw<std::exception>();
247 log <<
"Invalid value '" << *optResult <<
"' for key "
248 <<
"'port' in [" << section.
name() <<
"]";
255 auto const optResult = section.
get(
"protocol");
259 optResult->begin(), optResult->end()))
265 auto const lim =
get(section,
"limit",
"unlimited");
267 if (!boost::iequals(lim,
"unlimited"))
272 safe_cast<int>(beast::lexicalCastThrow<std::uint16_t>(lim));
276 log <<
"Invalid value '" << lim <<
"' for key "
277 <<
"'limit' in [" << section.
name() <<
"]";
284 auto const optResult = section.
get(
"send_queue_limit");
290 beast::lexicalCastThrow<std::uint16_t>(*optResult);
294 Throw<std::exception>();
298 log <<
"Invalid value '" << *optResult <<
"' for key "
299 <<
"'send_queue_limit' in [" << section.
name() <<
"]";
318 set(port.
user,
"user", section);
328 section.
value_or(
"permessage_deflate",
true);
330 section.
value_or(
"client_max_window_bits", 15);
332 section.
value_or(
"server_max_window_bits", 15);
334 section.
value_or(
"client_no_context_takeover",
false);
336 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::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.
std::optional< T > get(std::string const &name) const
Result split_commas(FwdIt first, FwdIt last)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
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)
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,...
void parse_Port(ParsedPort &port, Section const §ion, std::ostream &log)
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
void Rethrow()
Rethrow the exception currently being handled.
boost::beast::websocket::permessage_deflate pmd_options
std::optional< std::uint16_t > port
std::vector< boost::asio::ip::network_v4 > admin_nets_v4
std::uint16_t ws_queue_limit
std::vector< boost::asio::ip::network_v6 > secure_gateway_nets_v6
std::set< std::string, boost::beast::iless > protocol
std::string admin_password
std::vector< boost::asio::ip::network_v6 > admin_nets_v6
std::optional< boost::asio::ip::address > ip
std::vector< boost::asio::ip::network_v4 > secure_gateway_nets_v4
Configuration information for a Server listening port.
std::vector< boost::asio::ip::network_v6 > admin_nets_v6
std::string protocols() const
std::vector< boost::asio::ip::network_v6 > secure_gateway_nets_v6
std::vector< boost::asio::ip::network_v4 > secure_gateway_nets_v4
boost::asio::ip::address ip
std::vector< boost::asio::ip::network_v4 > admin_nets_v4