| 86 | } |
| 87 | |
| 88 | ClusterConnectionString::ClusterConnectionString(const std::string& connectionString) { |
| 89 | auto trimmed = trim(connectionString); |
| 90 | // Split on '@' into key@addrs |
| 91 | int pAt = trimmed.find_first_of('@'); |
| 92 | if (pAt == trimmed.npos) { |
| 93 | throw connection_string_invalid(); |
| 94 | } |
| 95 | std::string key = trimmed.substr(0, pAt); |
| 96 | std::string addrs = trimmed.substr(pAt + 1); |
| 97 | |
| 98 | parseKey(key); |
| 99 | std::set<Hostname> hostnameSet; |
| 100 | std::set<NetworkAddress> addressSet; |
| 101 | std::string curAddr; |
| 102 | for (int p = 0; p <= addrs.size();) { |
| 103 | int pComma = addrs.find_first_of(',', p); |
| 104 | if (pComma == addrs.npos) |
| 105 | pComma = addrs.size(); |
| 106 | curAddr = addrs.substr(p, pComma - p); |
| 107 | if (Hostname::isHostname(curAddr)) { |
| 108 | Hostname h = Hostname::parse(curAddr); |
| 109 | // Check that there are no duplicate hostnames |
| 110 | if (hostnameSet.find(h) != hostnameSet.end()) { |
| 111 | throw connection_string_invalid(); |
| 112 | } |
| 113 | hostnames.push_back(Hostname::parse(curAddr)); |
| 114 | hostnameSet.insert(h); |
| 115 | } else { |
| 116 | NetworkAddress n = NetworkAddress::parse(curAddr); |
| 117 | // Check that there are no duplicate addresses |
| 118 | if (addressSet.find(n) != addressSet.end()) { |
| 119 | throw connection_string_invalid(); |
| 120 | } |
| 121 | coords.push_back(n); |
| 122 | addressSet.insert(n); |
| 123 | } |
| 124 | p = pComma + 1; |
| 125 | } |
| 126 | ASSERT((coords.size() + hostnames.size()) > 0); |
| 127 | } |
| 128 | |
| 129 | TEST_CASE("/fdbclient/MonitorLeader/parseConnectionString/addresses") { |
| 130 | state std::string input; |