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

@@ -193,47 +193,39 @@ public:
HostAndPort parseName(std::string const& str)
{
struct find_whitespace
{
bool operator() (const char c)
{
return std::isspace (c);
}
};
// Attempt to find the first and last non-whitespace
auto const find_whitespace = std::bind (
std::isspace <std::string::value_type>,
std::placeholders::_1,
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 (
str.begin (), str.end (), find_whitespace ());
str.begin (), str.end (), find_whitespace);
// Find the last non-whitespace
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
if (host_first >= port_last)
return std::make_pair(std::string (), std::string ());
// Attempt to find the first valid port separator
auto host_last = std::find_if (
host_first, port_last, find_port_separator ());
// Attempt to find the first and last valid port separators
auto const find_port_separator = [](char const c) -> bool
{
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 (
host_last, port_last, find_port_separator ());
host_last, port_last, find_port_separator);
return make_pair (
std::string (host_first, host_last),

View File

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

View File

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

View File

@@ -411,30 +411,36 @@ public:
m_peerFinder->setConfig (config);
// Add the static IPs from the rippled.cfg file
m_peerFinder->addFallbackStrings ("rippled.cfg", getConfig().IPS);
if (!getConfig ().IPS.empty ())
{
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
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,
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