config remove duplicates from address lists
This commit is contained in:
@@ -29,6 +29,8 @@ void split_addr_into(const char* name, std::vector<std::string>& out, const std:
|
||||
{
|
||||
size_t pos=0u;
|
||||
|
||||
// parse, resolve host names, then re-print.
|
||||
// Catch syntax errors early, and normalize prior to removing duplicates
|
||||
while(pos<inp.size()) {
|
||||
auto start = inp.find_first_not_of(" \t\r\n", pos);
|
||||
auto end = inp.find_first_of(" \t\r\n", start);
|
||||
@@ -52,6 +54,11 @@ void split_addr_into(const char* name, std::vector<std::string>& out, const std:
|
||||
out.emplace_back(strm.str());
|
||||
}
|
||||
}
|
||||
|
||||
// remove any duplicates
|
||||
std::sort(out.begin(), out.end());
|
||||
out.erase(std::unique(out.begin(), out.end()),
|
||||
out.end());
|
||||
}
|
||||
|
||||
std::string join_addr(const std::vector<std::string>& in)
|
||||
|
||||
+2
-2
@@ -101,7 +101,7 @@ void testDefs()
|
||||
testEq(conf.udp_port, 1234);
|
||||
testFalse(conf.autoAddrList);
|
||||
testEq(conf.addressList, std::vector<std::string>({"1.2.1.2:1234", "4.3.2.1:1234"}));
|
||||
testEq(conf.interfaces, std::vector<std::string>({"1.2.3.4", "1.1.1.1"}));
|
||||
testEq(conf.interfaces, std::vector<std::string>({"1.1.1.1", "1.2.3.4"}));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -141,7 +141,7 @@ void testDefs()
|
||||
testEq(conf.tcp_port, 5678);
|
||||
testFalse(conf.auto_beacon);
|
||||
testEq(conf.beaconDestinations, std::vector<std::string>({"1.2.1.2:1234", "4.3.2.1:1234"}));
|
||||
testEq(conf.interfaces, std::vector<std::string>({"1.2.3.4:5678", "1.1.1.1:5678"}));
|
||||
testEq(conf.interfaces, std::vector<std::string>({"1.1.1.1:5678", "1.2.3.4:5678"}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user