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))
115 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();
169 Throw<std::exception>();
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();
180 Throw<std::exception>();
185 catch (boost::system::system_error
const& e)
187 log <<
"Invalid value '" << ip <<
"' for key '" << field <<
"' in ["
188 << section.
name() <<
"]: " << e.what();
189 Throw<std::exception>();
199 auto const optResult = section.
get(
"ip");
204 port.
ip = boost::asio::ip::make_address(*optResult);
208 log <<
"Invalid value '" << *optResult <<
"' for key 'ip' in ["
209 << section.
name() <<
"]";
216 auto const optResult = section.
get(
"port");
221 port.
port = beast::lexicalCastThrow<std::uint16_t>(*optResult);
224 if ((*port.
port == 0) && (port.
name ==
"server"))
225 Throw<std::exception>();
229 log <<
"Invalid value '" << *optResult <<
"' for key "
230 <<
"'port' in [" << section.
name() <<
"]";
237 auto const optResult = section.
get(
"protocol");
241 optResult->begin(), optResult->end()))
247 auto const lim =
get(section,
"limit",
"unlimited");
249 if (!boost::iequals(lim,
"unlimited"))
254 safe_cast<int>(beast::lexicalCastThrow<std::uint16_t>(lim));
258 log <<
"Invalid value '" << lim <<
"' for key "
259 <<
"'limit' in [" << section.
name() <<
"]";
266 auto const optResult = section.
get(
"send_queue_limit");
272 beast::lexicalCastThrow<std::uint16_t>(*optResult);
276 Throw<std::exception>();
280 log <<
"Invalid value '" << *optResult <<
"' for key "
281 <<
"'send_queue_limit' in [" << section.
name() <<
"]";
300 set(port.
user,
"user", section);
310 section.
value_or(
"permessage_deflate",
true);
312 section.
value_or(
"client_max_window_bits", 15);
314 section.
value_or(
"server_max_window_bits", 15);
316 section.
value_or(
"client_no_context_takeover",
false);
318 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