From d6d7d3e0c6fa6a3763f8fdb260fecbe1f341770a Mon Sep 17 00:00:00 2001 From: gavinhgchen Date: Wed, 20 Jul 2022 19:25:07 +0800 Subject: [PATCH] =?UTF-8?q?ip=E8=AE=BF=E9=97=AE=E6=A8=A1=E5=BC=8F=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=8C=89=E5=AE=9E=E4=BE=8B=E7=BA=A7=E5=88=AB=E5=8D=95?= =?UTF-8?q?=E7=8B=AC=E9=85=8D=E7=BD=AE(=E6=B2=A1=E6=9C=89=E4=B8=BB?= =?UTF-8?q?=E5=8A=A8=E8=AE=BE=E7=BD=AEip=E6=A8=A1=E5=BC=8F=E5=88=99?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E4=B9=8B=E5=89=8D=E7=9A=84ip=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=85=A8=E5=B1=80=E5=85=B1=E4=BA=AB=E6=96=B9=E5=BC=8F?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/cos_config.h | 8 ++++++++ include/cos_defines.h | 2 +- src/cos_config.cpp | 7 +++++++ src/cos_sys_config.cpp | 8 +++++++- src/op/base_op.cpp | 6 +++++- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/include/cos_config.h b/include/cos_config.h index 14eef56..2679cfa 100644 --- a/include/cos_config.h +++ b/include/cos_config.h @@ -25,6 +25,7 @@ class CosConfig { m_secret_key(""), m_region(""), m_tmp_token(""), + m_set_intranet_once(false), m_is_use_intranet(false), m_intranet_addr(""), m_config_parsed(false) {} @@ -42,6 +43,7 @@ class CosConfig { m_secret_key(secret_key), m_region(region), m_tmp_token(""), + m_set_intranet_once(false), m_is_use_intranet(false), m_intranet_addr(""), m_config_parsed(false) {} @@ -60,6 +62,7 @@ class CosConfig { m_secret_key(secret_key), m_region(region), m_tmp_token(tmp_token), + m_set_intranet_once(false), m_is_use_intranet(false), m_intranet_addr(""), m_config_parsed(false) {} @@ -73,6 +76,7 @@ class CosConfig { m_secret_key = config.m_secret_key; m_region = config.m_region; m_tmp_token = config.m_tmp_token; + m_set_intranet_once = config.m_set_intranet_once; m_is_use_intranet = config.m_is_use_intranet; m_intranet_addr = config.m_intranet_addr; m_config_parsed = config.m_config_parsed; @@ -87,6 +91,7 @@ class CosConfig { m_secret_key = config.m_secret_key; m_region = config.m_region; m_tmp_token = config.m_tmp_token; + m_set_intranet_once = config.m_set_intranet_once; m_is_use_intranet = config.m_is_use_intranet; m_intranet_addr = config.m_intranet_addr; m_config_parsed = config.m_config_parsed; @@ -159,6 +164,8 @@ class CosConfig { std::string GetIntranetAddr(); + bool GetSetIntranetOnce() const {return m_set_intranet_once;} + /// \brief 设置日志回调 void SetLogCallback(const LogCallback log_callback); @@ -179,6 +186,7 @@ class CosConfig { std::string m_region; std::string m_tmp_token; + bool m_set_intranet_once; bool m_is_use_intranet; std::string m_intranet_addr; bool m_config_parsed; diff --git a/include/cos_defines.h b/include/cos_defines.h index 00c32c6..9479e78 100644 --- a/include/cos_defines.h +++ b/include/cos_defines.h @@ -11,7 +11,7 @@ namespace qcloud_cos { -#define COS_CPP_SDK_VERSON "v5.5.6" +#define COS_CPP_SDK_VERSON "v5.5.7" /// 路径分隔符 const std::string kPathDelimiter = "/"; diff --git a/src/cos_config.cpp b/src/cos_config.cpp index 033dc00..fae2a4a 100644 --- a/src/cos_config.cpp +++ b/src/cos_config.cpp @@ -15,6 +15,7 @@ CosConfig::CosConfig(const std::string& config_file) m_secret_key(""), m_region(""), m_tmp_token(""), + m_set_intranet_once(false), m_is_use_intranet(false), m_intranet_addr(""), m_config_parsed(false) { @@ -191,11 +192,13 @@ bool CosConfig::InitConf(const std::string& config_file) { if (JsonObjectGetBoolValue(object, "IsUseIntranet", &bool_value)) { CosSysConfig::SetIsUseIntranet(bool_value); m_is_use_intranet = bool_value; + m_set_intranet_once = true; } if (JsonObjectGetStringValue(object, "IntranetAddr", &str_value)) { CosSysConfig::SetIntranetAddr(str_value); m_intranet_addr = str_value; + m_set_intranet_once = true; } CosSysConfig::PrintValue(); @@ -236,6 +239,8 @@ void CosConfig::SetConfigCredentail(const std::string& access_key, void CosConfig::SetIsUseIntranetAddr(bool is_use_intranet) { CosSysConfig::SetIsUseIntranet(is_use_intranet); m_is_use_intranet = is_use_intranet; + + m_set_intranet_once = true; } bool CosConfig::IsUseIntranet() { @@ -245,6 +250,8 @@ bool CosConfig::IsUseIntranet() { void CosConfig::SetIntranetAddr(const std::string& intranet_addr) { CosSysConfig::SetIntranetAddr(intranet_addr); m_intranet_addr = intranet_addr; + + m_set_intranet_once = true; } std::string CosConfig::GetIntranetAddr() { diff --git a/src/cos_sys_config.cpp b/src/cos_sys_config.cpp index e0afb73..6e7fcd7 100644 --- a/src/cos_sys_config.cpp +++ b/src/cos_sys_config.cpp @@ -57,6 +57,8 @@ unsigned CosSysConfig::m_dns_cache_expire_seconds = 600; // dns cache大小 unsigned CosSysConfig::m_dns_cache_size = 1000; +std::mutex m_intranet_addr_lock; + void CosSysConfig::PrintValue() { std::cout << "upload_part_size:" << m_upload_part_size << std::endl; std::cout << "upload_copy_part_size:" << m_upload_copy_part_size << std::endl; @@ -213,6 +215,7 @@ void CosSysConfig::SetIsUseIntranet(bool is_use_intranet) { bool CosSysConfig::IsUseIntranet() { return m_is_use_intranet; } void CosSysConfig::SetIntranetAddr(const std::string& intranet_addr) { + std::lock_guard lock(m_intranet_addr_lock); m_intranet_addr = intranet_addr; } @@ -248,7 +251,10 @@ std::string CosSysConfig::GetCIHost(const std::string& bucket_name, std::string CosSysConfig::GetDestDomain() { return m_dest_domain; } -std::string CosSysConfig::GetIntranetAddr() { return m_intranet_addr; } +std::string CosSysConfig::GetIntranetAddr() { + std::lock_guard lock(m_intranet_addr_lock); + return m_intranet_addr; +} LogCallback CosSysConfig::GetLogCallback() { return m_log_callback; } diff --git a/src/op/base_op.cpp b/src/op/base_op.cpp index bf39273..143ec32 100644 --- a/src/op/base_op.cpp +++ b/src/op/base_op.cpp @@ -305,9 +305,13 @@ std::string BaseOp::GetRealUrl(const std::string& host, const std::string& path, dest_path = "/" + dest_path; } - if (m_config->IsUseIntranet() && + if (m_config->GetSetIntranetOnce() && + m_config->IsUseIntranet() && !m_config->GetIntranetAddr().empty()) { dest_host = m_config->GetIntranetAddr(); + } else if (CosSysConfig::IsUseIntranet() && + !CosSysConfig::GetIntranetAddr().empty()) { + dest_host = CosSysConfig::GetIntranetAddr(); } else if (!CosSysConfig::GetDestDomain().empty()) { dest_host = CosSysConfig::GetDestDomain(); } else if (CosSysConfig::GetUseDnsCache()) {