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:
Mike Ellery
2017-11-08 10:10:24 -08:00
parent fd4636b056
commit 08382d866b
41 changed files with 968 additions and 1253 deletions

View File

@@ -23,6 +23,7 @@
#include <ripple/protocol/SecretKey.h>
#include <ripple/protocol/Sign.h>
#include <ripple/basics/strHex.h>
#include <test/jtx/envconfig.h>
#include <boost/asio.hpp>
#include <boost/beast/core/detail/base64.hpp>
#include <boost/beast/http.hpp>
@@ -55,7 +56,6 @@ public:
};
TrustedPublisherServer(
endpoint_type const& ep,
boost::asio::io_service& ios,
std::pair<PublicKey, SecretKey> keys,
std::string const& manifest,
@@ -65,6 +65,9 @@ public:
std::vector<Validator> const& validators)
: sock_(ios), acceptor_(ios)
{
endpoint_type const& ep {
beast::IP::Address::from_string (ripple::test::getEnvLocalhostAddr()),
0}; // 0 means let OS pick the port based on what's available
std::string data = "{\"sequence\":" + std::to_string(sequence) +
",\"expiration\":" +
std::to_string(expiration.time_since_epoch().count()) +

View File

@@ -25,6 +25,15 @@
namespace ripple {
namespace test {
extern std::atomic<bool> envUseIPv4;
inline
const char *
getEnvLocalhostAddr()
{
return envUseIPv4 ? "127.0.0.1" : "::1";
}
/// @brief initializes a config object for use with jtx::Env
///
/// @param config the configuration object to be initialized

View File

@@ -49,9 +49,9 @@ class JSONRPCClient : public AbstractClient
parse_Port(pp, cfg[name], log);
if(pp.protocol.count("http") == 0)
continue;
using boost::asio::ip::address_v4;
if(*pp.ip == address_v4{0x00000000})
*pp.ip = address_v4{0x7f000001};
using namespace boost::asio::ip;
if(pp.ip && pp.ip->is_unspecified())
*pp.ip = pp.ip->is_v6() ? address{address_v6::loopback()} : address{address_v4::loopback()};
return { *pp.ip, *pp.port };
}
Throw<std::runtime_error>("Missing HTTP port");
@@ -83,7 +83,7 @@ public:
: ep_(getEndpoint(cfg))
, stream_(ios_)
, rpc_version_(rpc_version)
{
{
stream_.connect(ep_);
}

View File

@@ -64,9 +64,9 @@ class WSClientImpl : public WSClient
parse_Port(pp, cfg[name], log);
if(pp.protocol.count(ps) == 0)
continue;
using boost::asio::ip::address_v4;
if(*pp.ip == address_v4{0x00000000})
*pp.ip = address_v4{0x7f000001};
using namespace boost::asio::ip;
if(pp.ip && pp.ip->is_unspecified())
*pp.ip = pp.ip->is_v6() ? address{address_v6::loopback()} : address{address_v4::loopback()};
return { *pp.ip, *pp.port };
}
Throw<std::runtime_error>("Missing WebSocket port");

View File

@@ -30,6 +30,8 @@ void incPorts()
port_base += 3;
}
std::atomic<bool> envUseIPv4 {false};
void
setupConfigForUnitTests (Config& cfg)
{
@@ -43,19 +45,21 @@ setupConfigForUnitTests (Config& cfg)
cfg.legacy("database_path", "");
cfg.setupControl(true, true, true);
cfg["server"].append("port_peer");
cfg["port_peer"].set("ip", "127.0.0.1");
cfg["port_peer"].set("ip", getEnvLocalhostAddr());
cfg["port_peer"].set("port", port_peer);
cfg["port_peer"].set("protocol", "peer");
cfg["server"].append("port_rpc");
cfg["port_rpc"].set("ip", "127.0.0.1");
cfg["port_rpc"].set("ip", getEnvLocalhostAddr());
cfg["port_rpc"].set("admin", getEnvLocalhostAddr());
cfg["port_rpc"].set("port", port_rpc);
cfg["port_rpc"].set("protocol", "http,ws2");
cfg["port_rpc"].set("admin", "127.0.0.1");
cfg["server"].append("port_ws");
cfg["port_ws"].set("ip", "127.0.0.1");
cfg["port_ws"].set("ip", getEnvLocalhostAddr());
cfg["port_ws"].set("admin", getEnvLocalhostAddr());
cfg["port_ws"].set("port", port_ws);
cfg["port_ws"].set("protocol", "ws");
cfg["port_ws"].set("admin", "127.0.0.1");
}
namespace jtx {