mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Support ipv6 for peer and RPC comms:
Fixes: RIPD-1574 Alias beast address classes to the asio equivalents. Adjust users of address classes accordingly. Fix resolver class so that it can support ipv6 addresses. Make unit tests use ipv6 localhost network. Extend endpoint peer message to support string endpoint representations while also supporting the existing fields (both are optional/repeated types). Expand test for Livecache and Endpoint. Workaround some false positive ipaddr tests on windows (asio bug?) Replaced usage of address::from_string(deprecated) with free function make_address. Identified a remaining use of v4 address type and replaced with the more appropriate IPEndpoint type (rpc_ip cmdline option). Add CLI flag for using ipv4 with unit tests. Release Notes ------------- The optional rpc_port command line flag is deprecated. The rpc_ip parameter now works as documented and accepts ip and port combined.
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include <ripple/basics/ResolverAsio.h>
|
||||
#include <ripple/basics/Log.h>
|
||||
#include <ripple/beast/net/IPAddressConversion.h>
|
||||
#include <ripple/beast/net/IPEndpoint.h>
|
||||
#include <ripple/beast/core/WaitableEvent.h>
|
||||
#include <boost/asio.hpp>
|
||||
#include <atomic>
|
||||
@@ -259,6 +260,21 @@ public:
|
||||
|
||||
HostAndPort parseName(std::string const& str)
|
||||
{
|
||||
// first attempt to parse as an endpoint (IP addr + port).
|
||||
// If that doesn't succeed, fall back to generic name + port parsing
|
||||
|
||||
auto result {beast::IP::Endpoint::from_string_checked (str)};
|
||||
if (result.second)
|
||||
{
|
||||
return make_pair (
|
||||
result.first.address().to_string(),
|
||||
std::to_string(result.first.port()));
|
||||
}
|
||||
|
||||
// generic name/port parsing, which doesn't work for
|
||||
// IPv6 addresses in particular because it considers a colon
|
||||
// a port separator
|
||||
|
||||
// Attempt to find the first and last non-whitespace
|
||||
auto const find_whitespace = std::bind (
|
||||
&std::isspace <std::string::value_type>,
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <ripple/basics/ToString.h>
|
||||
#include <ripple/beast/core/LexicalCast.h>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/asio/ip/address.hpp>
|
||||
#include <ripple/beast/net/IPEndpoint.h>
|
||||
#include <boost/regex.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstdarg>
|
||||
@@ -93,24 +93,38 @@ uint64_t uintFromHex (std::string const& strSrc)
|
||||
bool parseUrl (parsedURL& pUrl, std::string const& strUrl)
|
||||
{
|
||||
// scheme://username:password@hostname:port/rest
|
||||
static boost::regex reUrl ("(?i)\\`\\s*([[:alpha:]][-+.[:alpha:][:digit:]]*)://([^:/]+)(?::(\\d+))?(/.*)?\\s*?\\'");
|
||||
static boost::regex reUrl ("(?i)\\`\\s*([[:alpha:]][-+.[:alpha:][:digit:]]*)://([^/]+)(/.*)?\\s*?\\'");
|
||||
boost::smatch smMatch;
|
||||
|
||||
bool bMatch = boost::regex_match (strUrl, smMatch, reUrl); // Match status code.
|
||||
|
||||
if (bMatch)
|
||||
{
|
||||
std::string strPort;
|
||||
|
||||
pUrl.scheme = smMatch[1];
|
||||
boost::algorithm::to_lower (pUrl.scheme);
|
||||
pUrl.path = smMatch[3];
|
||||
pUrl.domain = smMatch[2];
|
||||
if (smMatch[3].length ())
|
||||
|
||||
// now consider the domain/port fragment
|
||||
auto colonPos = pUrl.domain.find_last_of(':');
|
||||
if (colonPos != std::string::npos)
|
||||
{
|
||||
pUrl.port = beast::lexicalCast <std::uint16_t> (
|
||||
std::string (smMatch[3]));
|
||||
// use Endpoint class to see if this thing looks
|
||||
// like an IP addr...
|
||||
auto result {beast::IP::Endpoint::from_string_checked (pUrl.domain)};
|
||||
if (result.second)
|
||||
{
|
||||
pUrl.domain = result.first.address().to_string();
|
||||
pUrl.port = result.first.port();
|
||||
}
|
||||
else // otherwise we are DNS name + port
|
||||
{
|
||||
pUrl.port = beast::lexicalCast <std::uint16_t> (
|
||||
pUrl.domain.substr(colonPos+1));
|
||||
pUrl.domain = pUrl.domain.substr(0, colonPos);
|
||||
}
|
||||
}
|
||||
pUrl.path = smMatch[4];
|
||||
//else, the whole thing is domain, not port
|
||||
}
|
||||
|
||||
return bMatch;
|
||||
|
||||
Reference in New Issue
Block a user