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:
RichardAH
2023-03-15 05:06:30 +01:00
committed by GitHub
parent 84cde3ce0b
commit cb08f2b6ec
4 changed files with 125 additions and 7 deletions

View File

@@ -856,6 +856,84 @@ r.ripple.com 51235
cfg.section(SECTION_IPS_FIXED).values().size() == 2);
}
void
testColons()
{
Config cfg;
/* NOTE: this string includes some explicit
* space chars in order to verify proper trimming */
std::string toLoad(R"(
[port_rpc])"
"\x20"
R"(
# comment
# indented comment
)"
"\x20\x20"
R"(
[ips])"
"\x20"
R"(
r.ripple.com:51235
[ips_fixed])"
"\x20\x20"
R"(
# COMMENT
s1.ripple.com:51235
s2.ripple.com 51235
anotherserversansport
anotherserverwithport:12
1.1.1.1:1
1.1.1.1 1
12.34.12.123:12345
12.34.12.123 12345
::
2001:db8::
::1
::1:12345
[::1]:12345
2001:db8:3333:4444:5555:6666:7777:8888:12345
[2001:db8:3333:4444:5555:6666:7777:8888]:1
)");
cfg.loadFromString(toLoad);
BEAST_EXPECT(
cfg.exists("port_rpc") && cfg.section("port_rpc").lines().empty() &&
cfg.section("port_rpc").values().empty());
BEAST_EXPECT(
cfg.exists(SECTION_IPS) &&
cfg.section(SECTION_IPS).lines().size() == 1 &&
cfg.section(SECTION_IPS).values().size() == 1);
BEAST_EXPECT(
cfg.exists(SECTION_IPS_FIXED) &&
cfg.section(SECTION_IPS_FIXED).lines().size() == 15 &&
cfg.section(SECTION_IPS_FIXED).values().size() == 15);
BEAST_EXPECT(cfg.IPS[0] == "r.ripple.com 51235");
BEAST_EXPECT(cfg.IPS_FIXED[0] == "s1.ripple.com 51235");
BEAST_EXPECT(cfg.IPS_FIXED[1] == "s2.ripple.com 51235");
BEAST_EXPECT(cfg.IPS_FIXED[2] == "anotherserversansport");
BEAST_EXPECT(cfg.IPS_FIXED[3] == "anotherserverwithport 12");
BEAST_EXPECT(cfg.IPS_FIXED[4] == "1.1.1.1 1");
BEAST_EXPECT(cfg.IPS_FIXED[5] == "1.1.1.1 1");
BEAST_EXPECT(cfg.IPS_FIXED[6] == "12.34.12.123 12345");
BEAST_EXPECT(cfg.IPS_FIXED[7] == "12.34.12.123 12345");
// all ipv6 should be ignored by colon replacer, howsoever formated
BEAST_EXPECT(cfg.IPS_FIXED[8] == "::");
BEAST_EXPECT(cfg.IPS_FIXED[9] == "2001:db8::");
BEAST_EXPECT(cfg.IPS_FIXED[10] == "::1");
BEAST_EXPECT(cfg.IPS_FIXED[11] == "::1:12345");
BEAST_EXPECT(cfg.IPS_FIXED[12] == "[::1]:12345");
BEAST_EXPECT(
cfg.IPS_FIXED[13] ==
"2001:db8:3333:4444:5555:6666:7777:8888:12345");
BEAST_EXPECT(
cfg.IPS_FIXED[14] == "[2001:db8:3333:4444:5555:6666:7777:8888]:1");
}
void
testComments()
{
@@ -1147,6 +1225,7 @@ r.ripple.com 51235
testSetup(true);
testPort();
testWhitespace();
testColons();
testComments();
testGetters();
testAmendment();