This is an automated email from the ASF dual-hosted git repository.
laiyingchun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git
The following commit(s) were added to refs/heads/master by this push:
new 7a20b5633 refactor(FQDN): resolve host:port to ip:port if -r parameter
is specified (#1954)
7a20b5633 is described below
commit 7a20b56337d270dc56ea9de2cc8d661608a5b50b
Author: Yingchun Lai <[email protected]>
AuthorDate: Fri Apr 12 19:40:44 2024 +0800
refactor(FQDN): resolve host:port to ip:port if -r parameter is specified
(#1954)
Now the shell CLI tools output host:port by default, if `-r` or
`--resolve_ip`
is specified, output ip:port instead.
---
src/client/replication_ddl_client.cpp | 40 ++++++-------
src/client/replication_ddl_client.h | 3 +
src/runtime/rpc/dns_resolver.cpp | 21 +++++++
src/runtime/rpc/dns_resolver.h | 4 ++
src/runtime/test/dns_resolver_test.cpp | 78 +++++++++++++++++++++++++
src/runtime/test/host_port_test.cpp | 30 ----------
src/shell/commands/node_management.cpp | 18 ++----
src/shell/commands/table_management.cpp | 17 +-----
src/utils/test/hostname_test.cpp | 62 +-------------------
src/utils/utils.cpp | 100 --------------------------------
src/utils/utils.h | 28 +--------
11 files changed, 133 insertions(+), 268 deletions(-)
diff --git a/src/client/replication_ddl_client.cpp
b/src/client/replication_ddl_client.cpp
index 70ad75bc7..f7aa503cf 100644
--- a/src/client/replication_ddl_client.cpp
+++ b/src/client/replication_ddl_client.cpp
@@ -34,6 +34,7 @@
#include <fstream>
#include <iomanip>
#include <iostream>
+#include <type_traits>
#include "backup_types.h"
#include "common//duplication_common.h"
@@ -54,7 +55,6 @@
#include "utils/fmt_logging.h"
#include "utils/output_utils.h"
#include "utils/time_utils.h"
-#include "utils/utils.h"
DSN_DEFINE_uint32(ddl_client,
ddl_client_max_attempt_count,
@@ -524,14 +524,13 @@ struct list_nodes_helper
}
};
-std::string host_name_resolve(bool resolve_ip, std::string value)
+std::string replication_ddl_client::node_name(const host_port &hp, bool
resolve_ip)
{
- if (resolve_ip) {
- std::string temp;
- if (dsn::utils::hostname_from_ip_port(value.c_str(), &temp))
- return temp;
+ if (!resolve_ip) {
+ return hp.to_string();
}
- return value;
+
+ return dns_resolver::instance().resolve_address(hp).to_string();
}
dsn::error_code replication_ddl_client::list_nodes(const
dsn::replication::node_status::type status,
@@ -547,14 +546,13 @@ dsn::error_code replication_ddl_client::list_nodes(const
dsn::replication::node_
std::map<dsn::host_port, list_nodes_helper> tmp_map;
int alive_node_count = 0;
- for (auto &kv : nodes) {
- if (kv.second == dsn::replication::node_status::NS_ALIVE)
+ for (const auto & [ hp, type ] : nodes) {
+ if (type == dsn::replication::node_status::NS_ALIVE) {
alive_node_count++;
- std::string status_str = enum_to_string(kv.second);
+ }
+ std::string status_str = enum_to_string(type);
status_str = status_str.substr(status_str.find("NS_") + 3);
- tmp_map.emplace(
- kv.first,
- list_nodes_helper(host_name_resolve(resolve_ip,
kv.first.to_string()), status_str));
+ tmp_map.emplace(hp, list_nodes_helper(node_name(hp, resolve_ip),
status_str));
}
if (detailed) {
@@ -691,10 +689,8 @@ replication_ddl_client::cluster_info(const std::string
&file_name, bool resolve_
if (resolve_ip) {
for (int i = 0; i < resp.keys.size(); ++i) {
- if (resp.keys[i] == "meta_servers") {
- dsn::utils::list_hostname_from_ip_port(resp.values[i].c_str(),
&resp.values[i]);
- } else if (resp.keys[i] == "primary_meta_server") {
- dsn::utils::hostname_from_ip_port(resp.values[i].c_str(),
&resp.values[i]);
+ if (resp.keys[i] == "meta_servers" || resp.keys[i] ==
"primary_meta_server") {
+ resp.values[i] =
dns_resolver::ip_ports_from_host_ports(resp.values[i]);
}
}
}
@@ -812,11 +808,11 @@ dsn::error_code replication_ddl_client::list_app(const
std::string &app_name,
tp_nodes.add_column("primary");
tp_nodes.add_column("secondary");
tp_nodes.add_column("total");
- for (auto &kv : node_stat) {
- tp_nodes.add_row(host_name_resolve(resolve_ip,
kv.first.to_string()));
- tp_nodes.append_data(kv.second.first);
- tp_nodes.append_data(kv.second.second);
- tp_nodes.append_data(kv.second.first + kv.second.second);
+ for (const auto & [ hp, pri_and_sec_rep_cnts ] : node_stat) {
+ tp_nodes.add_row(node_name(hp, resolve_ip));
+ tp_nodes.append_data(pri_and_sec_rep_cnts.first);
+ tp_nodes.append_data(pri_and_sec_rep_cnts.second);
+ tp_nodes.append_data(pri_and_sec_rep_cnts.first +
pri_and_sec_rep_cnts.second);
}
tp_nodes.add_row("");
tp_nodes.append_data(total_prim_count);
diff --git a/src/client/replication_ddl_client.h
b/src/client/replication_ddl_client.h
index 53f7538bd..7907aa79a 100644
--- a/src/client/replication_ddl_client.h
+++ b/src/client/replication_ddl_client.h
@@ -271,6 +271,9 @@ public:
static error_s validate_app_name(const std::string &app_name, bool
allow_empty_name = false);
+ // Resolve the host:port 'hp' to ip:port if 'resolve_ip' is true.
+ static std::string node_name(const host_port &hp, bool resolve_ip);
+
private:
void end_meta_request(const rpc_response_task_ptr &callback,
uint32_t attempt_count,
diff --git a/src/runtime/rpc/dns_resolver.cpp b/src/runtime/rpc/dns_resolver.cpp
index 06bf4aca1..2eab9d832 100644
--- a/src/runtime/rpc/dns_resolver.cpp
+++ b/src/runtime/rpc/dns_resolver.cpp
@@ -30,6 +30,8 @@
#include "runtime/rpc/group_host_port.h"
#include "utils/autoref_ptr.h"
#include "utils/fmt_logging.h"
+#include "utils/ports.h"
+#include "utils/strings.h"
METRIC_DEFINE_gauge_int64(server,
dns_resolver_cache_size,
@@ -141,4 +143,23 @@ rpc_address dns_resolver::resolve_address(const host_port
&hp)
}
}
+std::string dns_resolver::ip_ports_from_host_ports(const std::string
&host_ports)
+{
+ std::vector<std::string> host_port_vec;
+ dsn::utils::split_args(host_ports.c_str(), host_port_vec, ',');
+
+ if (dsn_unlikely(host_port_vec.empty())) {
+ return host_ports;
+ }
+
+ std::vector<std::string> ip_port_vec;
+ ip_port_vec.reserve(host_port_vec.size());
+ for (const auto &hp : host_port_vec) {
+ const auto addr =
dsn::dns_resolver::instance().resolve_address(host_port::from_string(hp));
+ ip_port_vec.emplace_back(addr.to_string());
+ }
+
+ return fmt::format("{}", fmt::join(ip_port_vec, ","));
+}
+
} // namespace dsn
diff --git a/src/runtime/rpc/dns_resolver.h b/src/runtime/rpc/dns_resolver.h
index b4a1f0395..f173db212 100644
--- a/src/runtime/rpc/dns_resolver.h
+++ b/src/runtime/rpc/dns_resolver.h
@@ -19,6 +19,7 @@
#pragma once
+#include <string>
#include <unordered_map>
#include <vector>
@@ -44,6 +45,9 @@ public:
// Resolve this host_port to an unique rpc_address.
rpc_address resolve_address(const host_port &hp);
+ // Resolve comma separated host:port list 'host_ports' to comma separated
ip:port list.
+ static std::string ip_ports_from_host_ports(const std::string &host_ports);
+
private:
dns_resolver();
~dns_resolver() = default;
diff --git a/src/runtime/test/dns_resolver_test.cpp
b/src/runtime/test/dns_resolver_test.cpp
new file mode 100644
index 000000000..86a0cc7e1
--- /dev/null
+++ b/src/runtime/test/dns_resolver_test.cpp
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <memory>
+#include <string>
+
+#include "gtest/gtest.h"
+#include "runtime/rpc/dns_resolver.h"
+#include "runtime/rpc/group_address.h"
+#include "runtime/rpc/group_host_port.h"
+#include "runtime/rpc/rpc_address.h"
+#include "runtime/rpc/rpc_host_port.h"
+
+namespace dsn {
+
+TEST(host_port_test, dns_resolver)
+{
+ // Resolve HOST_TYPE_IPV4 type host_port.
+ {
+ host_port hp("localhost", 8080);
+ const auto &addr = dns_resolver::instance().resolve_address(hp);
+ ASSERT_TRUE(rpc_address::from_ip_port("127.0.0.1", 8080) == addr ||
+ rpc_address::from_ip_port("127.0.1.1", 8080) == addr);
+ }
+
+ // Resolve HOST_TYPE_GROUP type host_port.
+ {
+ host_port hp_grp;
+ hp_grp.assign_group("test_group");
+ auto g_hp = hp_grp.group_host_port();
+
+ host_port hp1("localhost", 8080);
+ ASSERT_TRUE(g_hp->add(hp1));
+ host_port hp2("localhost", 8081);
+ g_hp->set_leader(hp2);
+
+ const auto &addr_grp =
dns_resolver::instance().resolve_address(hp_grp);
+ const auto *const g_addr = addr_grp.group_address();
+
+ ASSERT_EQ(g_addr->is_update_leader_automatically(),
g_hp->is_update_leader_automatically());
+ ASSERT_STREQ(g_addr->name(), g_hp->name());
+ ASSERT_EQ(g_addr->count(), g_hp->count());
+ ASSERT_EQ(host_port::from_address(g_addr->leader()), g_hp->leader());
+ }
+
+ // Resolve host_port list.
+ {
+ struct host_port_list_test_case
+ {
+ std::string host_ports;
+ std::string ip_ports;
+ } test_cases[] = {{"localhost:8080", "127.0.0.1:8080"},
+ {"localhost:8080,localhost:8081,localhost:8082",
+ "127.0.0.1:8080,127.0.0.1:8081,127.0.0.1:8082"}};
+
+ for (const auto &tc : test_cases) {
+ ASSERT_EQ(tc.ip_ports,
dns_resolver::ip_ports_from_host_ports(tc.host_ports));
+ }
+ }
+}
+
+} // namespace dsn
diff --git a/src/runtime/test/host_port_test.cpp
b/src/runtime/test/host_port_test.cpp
index 0c27d5e4a..dfa7b01bd 100644
--- a/src/runtime/test/host_port_test.cpp
+++ b/src/runtime/test/host_port_test.cpp
@@ -23,7 +23,6 @@
#include <vector>
#include "gtest/gtest.h"
-#include "runtime/rpc/dns_resolver.h"
#include "runtime/rpc/group_address.h"
#include "runtime/rpc/group_host_port.h"
#include "runtime/rpc/rpc_address.h"
@@ -228,35 +227,6 @@ TEST(host_port_test, transfer_rpc_address)
}
}
-TEST(host_port_test, dns_resolver)
-{
- {
- host_port hp("localhost", 8080);
- const auto &addr = dns_resolver::instance().resolve_address(hp);
- ASSERT_TRUE(rpc_address::from_ip_port("127.0.0.1", 8080) == addr ||
- rpc_address::from_ip_port("127.0.1.1", 8080) == addr);
- }
-
- {
- host_port hp_grp;
- hp_grp.assign_group("test_group");
- auto g_hp = hp_grp.group_host_port();
-
- host_port hp1("localhost", 8080);
- ASSERT_TRUE(g_hp->add(hp1));
- host_port hp2("localhost", 8081);
- g_hp->set_leader(hp2);
-
- const auto &addr_grp =
dns_resolver::instance().resolve_address(hp_grp);
- const auto *const g_addr = addr_grp.group_address();
-
- ASSERT_EQ(g_addr->is_update_leader_automatically(),
g_hp->is_update_leader_automatically());
- ASSERT_STREQ(g_addr->name(), g_hp->name());
- ASSERT_EQ(g_addr->count(), g_hp->count());
- ASSERT_EQ(host_port::from_address(g_addr->leader()), g_hp->leader());
- }
-}
-
void send_and_check_host_port_by_serialize(const host_port &hp,
dsn_msg_serialize_format t)
{
const auto &hp_str = hp.to_string();
diff --git a/src/shell/commands/node_management.cpp
b/src/shell/commands/node_management.cpp
index a613289af..2bff8b8ba 100644
--- a/src/shell/commands/node_management.cpp
+++ b/src/shell/commands/node_management.cpp
@@ -38,8 +38,6 @@
#include "common/replication_enums.h"
#include "dsn.layer2_types.h"
#include "meta_admin_types.h"
-#include "runtime/rpc/dns_resolver.h"
-#include "runtime/rpc/rpc_address.h"
#include "runtime/rpc/rpc_host_port.h"
#include "shell/command_executor.h"
#include "shell/command_helper.h"
@@ -327,10 +325,7 @@ bool ls_nodes(command_executor *e, shell_context *sc,
arguments args)
alive_node_count++;
std::string status_str = dsn::enum_to_string(kv.second);
status_str = status_str.substr(status_str.find("NS_") + 3);
- auto node_name = kv.first.to_string();
- if (resolve_ip) {
- node_name =
dsn::dns_resolver::instance().resolve_address(kv.first).to_string();
- }
+ const auto node_name = replication_ddl_client::node_name(kv.first,
resolve_ip);
tmp_map.emplace(kv.first, list_nodes_helper(node_name, status_str));
}
@@ -663,14 +658,9 @@ bool remote_command(command_executor *e, shell_context
*sc, arguments args)
int failed = 0;
// TODO (yingchun) output is hard to read, need do some refactor
for (int i = 0; i < node_list.size(); ++i) {
- node_desc &n = node_list[i];
- std::string hostname;
- if (resolve_ip) {
- hostname =
dsn::dns_resolver::instance().resolve_address(n.hp).to_string();
- } else {
- hostname = n.hp.to_string();
- }
- fprintf(stderr, "CALL [%s] [%s] ", n.desc.c_str(), hostname.c_str());
+ const auto &node = node_list[i];
+ const auto hostname = replication_ddl_client::node_name(node.hp,
resolve_ip);
+ fprintf(stderr, "CALL [%s] [%s] ", node.desc.c_str(),
hostname.c_str());
if (results[i].first) {
fprintf(stderr, "succeed:\n%s\n", results[i].second.c_str());
succeed++;
diff --git a/src/shell/commands/table_management.cpp
b/src/shell/commands/table_management.cpp
index 262cd6256..55f348689 100644
--- a/src/shell/commands/table_management.cpp
+++ b/src/shell/commands/table_management.cpp
@@ -52,7 +52,6 @@
#include "utils/ports.h"
#include "utils/string_conv.h"
#include "utils/strings.h"
-#include "utils/utils.h"
DSN_DEFINE_uint32(shell, tables_sample_interval_ms, 1000, "The interval
between sampling metrics.");
DSN_DEFINE_validator(tables_sample_interval_ms, [](uint32_t value) -> bool {
return value > 0; });
@@ -376,13 +375,7 @@ bool app_disk(command_executor *e, shell_context *sc,
arguments args)
}
}
std::stringstream oss;
- std::string hostname;
- const auto &ip = p.hp_primary.to_string();
- if (resolve_ip && dsn::utils::hostname_from_ip_port(ip.c_str(),
&hostname)) {
- oss << hostname << "(";
- } else {
- oss << p.hp_primary << "(";
- };
+ oss << replication_ddl_client::node_name(p.hp_primary, resolve_ip)
<< "(";
if (disk_found)
oss << disk_value;
else
@@ -427,13 +420,7 @@ bool app_disk(command_executor *e, shell_context *sc,
arguments args)
}
}
- std::string hostname;
- const auto &ip = p.hp_secondaries[j].to_string();
- if (resolve_ip &&
dsn::utils::hostname_from_ip_port(ip.c_str(), &hostname)) {
- oss << hostname << "(";
- } else {
- oss << p.hp_secondaries[j] << "(";
- };
+ oss << replication_ddl_client::node_name(p.hp_secondaries[j],
resolve_ip) << "(";
if (found)
oss << value;
else
diff --git a/src/utils/test/hostname_test.cpp b/src/utils/test/hostname_test.cpp
index 3a2f3e11e..29c94aa2d 100644
--- a/src/utils/test/hostname_test.cpp
+++ b/src/utils/test/hostname_test.cpp
@@ -27,73 +27,15 @@ namespace replication {
TEST(ip_to_hostname, localhost)
{
- std::string hostname_result;
-
const std::string valid_ip = "127.0.0.1";
const std::string expected_hostname = "localhost";
- const std::string valid_ip_port = "127.0.0.1:23010";
- const std::string expected_hostname_port = "localhost:23010";
-
- const std::string valid_ip_list = "127.0.0.1,127.0.0.1,127.0.0.1";
- const std::string expected_hostname_list = "localhost,localhost,localhost";
-
- const std::string valid_ip_port_list =
"127.0.0.1:8080,127.0.0.1:8080,127.0.0.1:8080";
- const std::string expected_hostname_port_list =
"localhost:8080,localhost:8080,localhost:8080";
-
const auto rpc_example_valid = rpc_address::from_ip_port(valid_ip, 23010);
- // static bool hostname(const rpc_address &address,std::string
*hostname_result);
- ASSERT_TRUE(dsn::utils::hostname(rpc_example_valid, &hostname_result));
- ASSERT_EQ(expected_hostname_port, hostname_result);
-
- // static bool hostname_from_ip(uint32_t ip, std::string* hostname_result);
+ // bool hostname_from_ip(uint32_t ip, std::string *hostname_result)
+ std::string hostname_result;
ASSERT_TRUE(dsn::utils::hostname_from_ip(htonl(rpc_example_valid.ip()),
&hostname_result));
ASSERT_EQ(expected_hostname, hostname_result);
-
- // static bool hostname_from_ip(const char *ip,std::string
*hostname_result);
- ASSERT_TRUE(dsn::utils::hostname_from_ip(valid_ip.c_str(),
&hostname_result));
- ASSERT_EQ(expected_hostname, hostname_result);
-
- // static bool hostname_from_ip_port(const char *ip_port,std::string
*hostname_result);
- ASSERT_TRUE(dsn::utils::hostname_from_ip_port(valid_ip_port.c_str(),
&hostname_result));
- ASSERT_EQ(expected_hostname_port, hostname_result);
-
- // static bool list_hostname_from_ip(const char *ip_port_list,std::string
- // *hostname_result_list);
- ASSERT_TRUE(dsn::utils::list_hostname_from_ip(valid_ip_list.c_str(),
&hostname_result));
- ASSERT_EQ(expected_hostname_list, hostname_result);
-
-
ASSERT_FALSE(dsn::utils::list_hostname_from_ip("127.0.0.1,127.0.0.23323,111127.0.0.3",
- &hostname_result));
- ASSERT_EQ("localhost,127.0.0.23323,111127.0.0.3", hostname_result);
-
-
ASSERT_FALSE(dsn::utils::list_hostname_from_ip("123.456.789.111,127.0.0.1",
&hostname_result));
- ASSERT_EQ("123.456.789.111,localhost", hostname_result);
-
- // static bool list_hostname_from_ip_port(const char
*ip_port_list,std::string
- // *hostname_result_list);
- ASSERT_TRUE(
- dsn::utils::list_hostname_from_ip_port(valid_ip_port_list.c_str(),
&hostname_result));
- ASSERT_EQ(expected_hostname_port_list, hostname_result);
-
- ASSERT_FALSE(dsn::utils::list_hostname_from_ip_port(
- "127.0.3333.1:23456,1127.0.0.2:22233,127.0.0.1:8080",
&hostname_result));
- ASSERT_EQ("127.0.3333.1:23456,1127.0.0.2:22233,localhost:8080",
hostname_result);
-}
-
-TEST(ip_to_hostname, invalid_ip)
-{
-
- std::string hostname_result;
- const std::string invalid_ip = "123.456.789.111";
- const std::string invalid_ip_port = "123.456.789.111:23010";
-
- ASSERT_FALSE(dsn::utils::hostname_from_ip(invalid_ip.c_str(),
&hostname_result));
- ASSERT_EQ(invalid_ip, hostname_result);
-
- ASSERT_FALSE(dsn::utils::hostname_from_ip_port(invalid_ip_port.c_str(),
&hostname_result));
- ASSERT_EQ(invalid_ip_port, hostname_result);
}
} // namespace replication
diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp
index be0d92e18..749933ffe 100644
--- a/src/utils/utils.cpp
+++ b/src/utils/utils.cpp
@@ -32,13 +32,9 @@
#include <netinet/in.h>
#include <string.h>
#include <sys/socket.h>
-#include <fstream>
#include <memory>
-#include <vector>
-#include "runtime/rpc/rpc_address.h"
#include "utils/fmt_logging.h"
-#include "utils/strings.h"
#if defined(__linux__)
#elif defined(__FreeBSD__)
@@ -80,101 +76,5 @@ bool hostname_from_ip(uint32_t ip, std::string
*hostname_result)
return true;
}
}
-
-bool hostname_from_ip(const char *ip, std::string *hostname_result)
-{
- uint32_t ip_addr;
- if (inet_pton(AF_INET, ip, &ip_addr) != 1) {
- // inet_pton() returns 1 on success (network address was successfully
converted)
- *hostname_result = ip;
- return false;
- }
- if (!hostname_from_ip(ip_addr, hostname_result)) {
- *hostname_result = ip;
- return false;
- }
- return true;
-}
-
-bool hostname_from_ip_port(const char *ip_port, std::string *hostname_result)
-{
- const auto addr = dsn::rpc_address::from_ip_port(ip_port);
- if (!addr) {
- LOG_WARNING("invalid ip_port({})", ip_port);
- *hostname_result = ip_port;
- return false;
- }
- if (!hostname(addr, hostname_result)) {
- *hostname_result = ip_port;
- return false;
- }
- return true;
-}
-
-bool hostname(const rpc_address &address, std::string *hostname_result)
-{
- if (address.type() != HOST_TYPE_IPV4) {
- return false;
- }
- if (hostname_from_ip(htonl(address.ip()), hostname_result)) {
- *hostname_result += ":" + std::to_string(address.port());
- return true;
- }
- return false;
-}
-
-bool list_hostname_from_ip(const char *ip_list, std::string
*hostname_result_list)
-{
- std::vector<std::string> splitted_ip;
- dsn::utils::split_args(ip_list, splitted_ip, ',');
-
- if (splitted_ip.empty()) {
- LOG_WARNING("invalid ip_list({})", ip_list);
- *hostname_result_list = *ip_list;
- return false;
- }
-
- std::string temp;
- std::stringstream result;
- bool all_ok = true;
- for (int i = 0; i < splitted_ip.size(); ++i) {
- result << (i ? "," : "");
- if (hostname_from_ip(splitted_ip[i].c_str(), &temp)) {
- result << temp;
- } else {
- result << splitted_ip[i].c_str();
- all_ok = false;
- }
- }
- *hostname_result_list = result.str();
- return all_ok;
-}
-
-bool list_hostname_from_ip_port(const char *ip_port_list, std::string
*hostname_result_list)
-{
- std::vector<std::string> splitted_ip_port;
- dsn::utils::split_args(ip_port_list, splitted_ip_port, ',');
-
- if (splitted_ip_port.empty()) {
- LOG_WARNING("invalid ip_list({})", ip_port_list);
- *hostname_result_list = *ip_port_list;
- return false;
- }
-
- std::string temp;
- std::stringstream result;
- bool all_ok = true;
- for (int i = 0; i < splitted_ip_port.size(); ++i) {
- result << (i ? "," : "");
- if (hostname_from_ip_port(splitted_ip_port[i].c_str(), &temp)) {
- result << temp;
- } else {
- result << splitted_ip_port[i].c_str();
- all_ok = false;
- }
- }
- *hostname_result_list = result.str();
- return all_ok;
-}
} // namespace utils
} // namespace dsn
diff --git a/src/utils/utils.h b/src/utils/utils.h
index fd40cb136..66d085eba 100644
--- a/src/utils/utils.h
+++ b/src/utils/utils.h
@@ -36,10 +36,6 @@
#include <string>
#include <utility>
-namespace dsn {
-class rpc_address;
-} // namespace dsn
-
#define TIME_MS_MAX 0xffffffff
// The COMPILE_ASSERT macro can be used to verify that a compile time
@@ -81,29 +77,7 @@ std::shared_ptr<T> make_shared_array(size_t size)
// and hostname_result
// will be the hostname, or it will be ip address or error message
-// valid a.b.c.d -> return TRUE && hostname_result=hostname | invalid
a.b.c.d:port1 -> return
-// FALSE
-// && hostname_result=a.b.c.d
-bool hostname_from_ip(const char *ip, std::string *hostname_result);
-
-// valid a.b.c.d:port -> return TRUE && hostname_result=hostname:port |
invalid a.b.c.d:port1
-// ->
-// return FALSE && hostname_result=a.b.c.d:port
-bool hostname_from_ip_port(const char *ip_port, std::string *hostname_result);
-
-// valid a.b.c.d,e.f.g.h -> return TRUE &&
hostname_result_list=hostname1,hostname2 | invalid
-// a.b.c.d,e.f.g.h -> return TRUE && hostname_result_list=a.b.c.d,e.f.g.h
-bool list_hostname_from_ip(const char *ip_port_list, std::string
*hostname_result_list);
-
-// valid a.b.c.d:port1,e.f.g.h:port2 -> return TRUE &&
-// hostname_result_list=hostname1:port1,hostname2:port2 | invalid
a.b.c.d:port1,e.f.g.h:port2 ->
-// return TRUE && hostname_result_list=a.b.c.d:port1,e.f.g.h:port2
-bool list_hostname_from_ip_port(const char *ip_port_list, std::string
*hostname_result_list);
-
-// valid_ipv4_rpc_address return TRUE && hostname_result=hostname:port |
invalid_ipv4 -> return
-// FALSE
-bool hostname(const dsn::rpc_address &address, std::string *hostname_result);
-
+// TODO(yingchun): Consider to move it to rpc_address.
// valid_ip_network_order -> return TRUE && hostname_result=hostname |
// invalid_ip_network_order -> return FALSE
bool hostname_from_ip(uint32_t ip, std::string *hostname_result);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]