Resolve hostnames found in the [ips] config section

This commit is contained in:
Nik Bougalis
2014-02-28 13:42:07 -08:00
committed by Vinnie Falco
parent 28c7827f14
commit 73485d5a23
5 changed files with 70 additions and 80 deletions

View File

@@ -60,39 +60,36 @@
# #
# [ips] # [ips]
# #
# List of ips where the Ripple protocol is served. For a starter list, # List of hostnames or ips where the Ripple protocol is served. For a starter
# you can copy entries from: https://ripple.com/ripple.txt # list, you can either copy entries from: https://ripple.com/ripple.txt or if
# you prefer you can specify r.ripple.com 51235
# #
# Domain names are not allowed. One ipv4 or ipv6 address per line. A port # One IPv4 address or domain names per line is allowed. A port may optionally
# may optionally be specified after adding a space to the address. By # be specified after adding a space to the address. By convention, if known,
# convention, if known, IPs are listed in from most to least trusted. # IPs are listed in from most to least trusted.
# #
# Examples: # Examples:
# 192.168.0.1 # 192.168.0.1
# 192.168.0.1 3939 # 192.168.0.1 3939
# 2001:0db8:0100:f101:0210:a4ff:fee3:9566 # r.ripple.com 51235
# #
# Here's the recent set of good, well known addresses: # This will give you a good, up-to-date list of addresses:
# #
# [ips] # [ips]
# 54.225.112.220 51235 # r.ripple.com 51235
# 54.225.123.13 51235
# 54.227.239.106 51235
# 107.21.251.218 51235
# 184.73.226.101 51235
# 23.23.201.55 51235
# #
# #
# #
# [ips_fixed] # [ips_fixed]
# #
# List of IP addresses to which rippled should always maintain peer # List of IP addresses or hostnames to which rippled should always attempt to
# connections with. This is useful for manually forming private networks, # maintain peer connections with. This is useful for manually forming private
# for example to configure a validation server that connects to the # networks, for example to configure a validation server that connects to the
# Ripple network through a public-facing server, or for building a set # Ripple network through a public-facing server, or for building a set
# of cluster peers. # of cluster peers.
# #
# # One IPv4 address or domain names per line is allowed. A port may optionally
# be specified after adding a space to the address.
# #
# [peer_ip] # [peer_ip]
# #
@@ -813,15 +810,9 @@ time.nist.gov
pool.ntp.org pool.ntp.org
# Where to find some other servers speaking the Ripple protocol. # Where to find some other servers speaking the Ripple protocol.
# This set of addresses is recent as of September 5, 2013
# #
[ips] [ips]
54.225.112.220 51235 r.ripple.com 51235
54.225.123.13 51235
54.227.239.106 51235
107.21.251.218 51235
184.73.226.101 51235
23.23.201.55 51235
# These validators are taken from the v0.16 release notes on the wiki: # These validators are taken from the v0.16 release notes on the wiki:
# https://ripple.com/wiki/Latest_rippled_release_notes # https://ripple.com/wiki/Latest_rippled_release_notes

View File

@@ -193,47 +193,39 @@ public:
HostAndPort parseName(std::string const& str) HostAndPort parseName(std::string const& str)
{ {
struct find_whitespace // Attempt to find the first and last non-whitespace
{ auto const find_whitespace = std::bind (
bool operator() (const char c) std::isspace <std::string::value_type>,
{ std::placeholders::_1,
return std::isspace (c); std::locale ());
}
};
struct find_port_separator
{
bool operator() (const char c)
{
if (std::isspace (c))
return true;
if (c == ':')
return true;
return false;
}
};
// Find the first non-whitespace
auto host_first = std::find_if_not ( auto host_first = std::find_if_not (
str.begin (), str.end (), find_whitespace ()); str.begin (), str.end (), find_whitespace);
// Find the last non-whitespace
auto port_last = std::find_if_not ( auto port_last = std::find_if_not (
str.rbegin (), str.rend(), find_whitespace ()).base(); str.rbegin (), str.rend(), find_whitespace).base();
// This should only happen for all-whitespace strings // This should only happen for all-whitespace strings
if (host_first >= port_last) if (host_first >= port_last)
return std::make_pair(std::string (), std::string ()); return std::make_pair(std::string (), std::string ());
// Attempt to find the first valid port separator // Attempt to find the first and last valid port separators
auto host_last = std::find_if ( auto const find_port_separator = [](char const c) -> bool
host_first, port_last, find_port_separator ()); {
if (std::isspace (c))
return true;
if (c == ':')
return true;
return false;
};
auto host_last = std::find_if (
host_first, port_last, find_port_separator);
// Attempt to find the last valid port separator
auto port_first = std::find_if_not ( auto port_first = std::find_if_not (
host_last, port_last, find_port_separator ()); host_last, port_last, find_port_separator);
return make_pair ( return make_pair (
std::string (host_first, host_last), std::string (host_first, host_last),

View File

@@ -946,11 +946,12 @@ public:
int addBootcacheAddresses (IPAddresses const& list) int addBootcacheAddresses (IPAddresses const& list)
{ {
int count (0); int count (0);
SharedState::Access state (m_state); SharedState::Access state (m_state);
for (IPAddresses::const_iterator iter ( for (auto addr : list)
list.begin()); iter != list.end(); ++iter) {
if (addBootcacheAddress (*iter, state)) if (addBootcacheAddress (addr, state))
++count; ++count;
}
return count; return count;
} }

View File

@@ -44,9 +44,9 @@ public:
results.addresses.reserve (m_strings.size()); results.addresses.reserve (m_strings.size());
for (int i = 0; i < m_strings.size (); ++i) for (int i = 0; i < m_strings.size (); ++i)
{ {
IP::Endpoint ep ( IP::Endpoint ep (IP::Endpoint::from_string (m_strings [i]));
IP::Endpoint::from_string_altform ( if (is_unspecified (ep))
m_strings [i])); ep = IP::Endpoint::from_string_altform (m_strings [i]);
if (! is_unspecified (ep)) if (! is_unspecified (ep))
results.addresses.push_back (ep); results.addresses.push_back (ep);
} }

View File

@@ -411,30 +411,36 @@ public:
m_peerFinder->setConfig (config); m_peerFinder->setConfig (config);
// Add the static IPs from the rippled.cfg file if (!getConfig ().IPS.empty ())
m_peerFinder->addFallbackStrings ("rippled.cfg", getConfig().IPS); {
m_resolver.resolve (getConfig ().IPS,
[this](
std::string const& name,
std::vector <IP::Endpoint> const& addresses)
{
std::vector <std::string> ips;
for (auto const& addr : addresses)
ips.push_back (to_string (addr));
std::string const base ("config: ");
if (!ips.empty ())
m_peerFinder->addFallbackStrings (base + name, ips);
});
}
// Add the ips_fixed from the rippled.cfg file // Add the ips_fixed from the rippled.cfg file
if (! getConfig ().RUN_STANDALONE && !getConfig ().IPS_FIXED.empty ()) if (! getConfig ().RUN_STANDALONE && !getConfig ().IPS_FIXED.empty ())
{ {
struct resolve_fixed_peers
{
PeerFinder::Manager* m_peerFinder;
resolve_fixed_peers (PeerFinder::Manager* peerFinder)
: m_peerFinder (peerFinder)
{ }
void operator()(std::string const& name,
std::vector <IP::Endpoint> const& address)
{
if (!address.empty())
m_peerFinder->addFixedPeer (name, address);
}
};
m_resolver.resolve (getConfig ().IPS_FIXED, m_resolver.resolve (getConfig ().IPS_FIXED,
resolve_fixed_peers (m_peerFinder.get ())); [this](
std::string const& name,
std::vector <IP::Endpoint> const& addresses)
{
if (!addresses.empty ())
m_peerFinder->addFixedPeer (name, addresses);
});
} }
// Configure the peer doors, which allow the server to accept incoming // Configure the peer doors, which allow the server to accept incoming