mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Allow port numbers be be specified with a colon: (#4328)
Port numbers can now be specified using either a colon or a space. Examples: 1.2.3.4:51235 1.2.3.4 51235 - In the configuration file, an annoying "gotcha" for node operators is accidentally specifying IP:PORT combinations using a colon. The code previously expected a space, not a colon. It also does not provide good feedback when this operator error is made. - This change simply allows this mistake (using a colon) to be fixed automatically, preserving the intention of the operator. - Add unit tests, which test the functionality when specifying IP:PORT in the configuration file. - The RPCCall test regime is not specific enough to test this functionality, it has been tested by hand. - Ensure IPv6 addresses are not confused for ip:port --------- Co-authored-by: Elliot Lee <github.public@intelliot.com>
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <regex>
|
||||
#include <thread>
|
||||
|
||||
#if BOOST_OS_WINDOWS
|
||||
@@ -468,6 +469,28 @@ Config::loadFromString(std::string const& fileContents)
|
||||
if (auto s = getIniFileSection(secConfig, SECTION_SNTP))
|
||||
SNTP_SERVERS = *s;
|
||||
|
||||
// if the user has specified ip:port then replace : with a space.
|
||||
{
|
||||
auto replaceColons = [](std::vector<std::string>& strVec) {
|
||||
const static std::regex e(":([0-9]+)$");
|
||||
for (auto& line : strVec)
|
||||
{
|
||||
// skip anything that might be an ipv6 address
|
||||
if (std::count(line.begin(), line.end(), ':') != 1)
|
||||
continue;
|
||||
|
||||
std::string result = std::regex_replace(line, e, " $1");
|
||||
// sanity check the result of the replace, should be same length
|
||||
// as input
|
||||
if (result.size() == line.size())
|
||||
line = result;
|
||||
}
|
||||
};
|
||||
|
||||
replaceColons(IPS_FIXED);
|
||||
replaceColons(IPS);
|
||||
}
|
||||
|
||||
{
|
||||
std::string dbPath;
|
||||
if (getSingleSection(secConfig, "database_path", dbPath, j_))
|
||||
|
||||
Reference in New Issue
Block a user