cos_sys_config.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #ifndef COS_SYS_CONF_H
  2. #define COS_SYS_CONF_H
  3. #include <stdint.h>
  4. #include "cos_defines.h"
  5. #include "util/log_util.h"
  6. namespace qcloud_cos {
  7. class CosSysConfig {
  8. public:
  9. /// \brief 设置签名超时时间,单位:秒
  10. static void SetAuthExpiredTime(uint64_t time);
  11. /// \brief 设置本地时间与网络时间差值
  12. static void SetTimeStampDelta(int64_t dela);
  13. /// \brief 设置连接超时时间,单位:毫秒
  14. static void SetConnTimeoutInms(uint64_t time);
  15. /// \brief 设置接收超时时间,单位:毫秒
  16. static void SetRecvTimeoutInms(uint64_t time);
  17. /// \brief 设置上传分片大小,单位:字节,默认:10M
  18. static void SetUploadPartSize(uint64_t part_size);
  19. /// \brief 获取上传复制分片大小,单位:字节,默认: 20M
  20. static void SetUploadCopyPartSize(uint64_t part_size);
  21. /// \brief 设置文件分片并发上传线程池大小,默认: 5
  22. static void SetUploadThreadPoolSize(unsigned size);
  23. /// \brief 设置异步上传下载线程池大小,默认: 2
  24. static void SetAsynThreadPoolSize(unsigned size);
  25. /// \brief 设置log输出,1:屏幕,2:syslog,3:不输出,默认:1
  26. static void SetLogOutType(LOG_OUT_TYPE log);
  27. /// \brief 设置log输出等级,COS_LOG_ERR/WRAN/INFO/DBG
  28. static void SetLogLevel(LOG_LEVEL level);
  29. /// \brief 设置下载线程池的大小
  30. static void SetDownThreadPoolSize(unsigned size);
  31. /// \brief 设置下载分片的大小
  32. static void SetDownSliceSize(unsigned slice_size);
  33. /// \brief 设置长连接的参数
  34. static void SetKeepAlive(bool keepalive);
  35. /// \brief 设置长连接的参数
  36. static void SetKeepIdle(int64_t keepidle);
  37. /// \brief 设置长连接的参数
  38. static void SetKeepIntvl(int64_t keepintvl);
  39. static void SetDestDomain(const std::string& dest_domain);
  40. /// \brief 获取签名超时时间,单位秒
  41. static uint64_t GetAuthExpiredTime();
  42. /// \brief 获取本地时间与网络时间差值
  43. static int64_t GetTimeStampDelta();
  44. /// \brief 获取连接超时时间,单位:毫秒
  45. static uint64_t GetConnTimeoutInms();
  46. /// \brief 获取接收超时时间,单位:毫秒
  47. static uint64_t GetRecvTimeoutInms();
  48. /// \brief 获取上传分片大小,单位:字节
  49. static uint64_t GetUploadPartSize();
  50. /// \brief 获取上传复制分片大小,单位:字节
  51. static uint64_t GetUploadCopyPartSize();
  52. /// \brief 获取上传线程池大小
  53. static unsigned GetUploadThreadPoolSize();
  54. /// \brief 获取异步线程池大小
  55. static unsigned GetAsynThreadPoolSize();
  56. /// \brief 获取日志输出类型,默认输出到屏幕
  57. static int GetLogOutType();
  58. /// \brief 获取日志输出等级
  59. static int GetLogLevel();
  60. /// \brief 打印CosSysConfig的配置详情
  61. static void PrintValue();
  62. /// \brief 获取下载分片大小
  63. static unsigned GetDownSliceSize();
  64. /// \brief 获取下载线程池大小
  65. static unsigned GetDownThreadPoolSize();
  66. /// \brief 获取keepalive参数
  67. static bool GetKeepAlive();
  68. static int64_t GetKeepIdle();
  69. static int64_t GetKeepIntvl();
  70. /// \brief 下载过程中是否检查MD5
  71. static bool IsCheckMd5();
  72. /// \brief 设置下载过程中检查MD5
  73. static void SetCheckMd5(bool is_check_md5);
  74. static bool IsDomainSameToHost();
  75. static void SetDomainSameToHost(bool is_domain_same_to_host);
  76. /// \brief 根据传入appid、region、bucket_name返回对应的hostname
  77. static std::string GetHost(uint64_t app_id, const std::string& region,
  78. const std::string& bucket_name);
  79. /// \brief 获取CI域名
  80. static std::string GetCIHost(const std::string& bucket_name,
  81. const std::string& region);
  82. /// \brief 获取PIC域名
  83. static std::string GetPICHost(uint64_t app_id, const std::string& region,
  84. const std::string& bucket_name);
  85. static std::string GetDestDomain();
  86. /// \brief 获取是否使用特定ip和端口号
  87. static bool IsUseIntranet();
  88. static void SetIsUseIntranet(bool is_use_interanet);
  89. static void SetIntranetAddr(const std::string& intranet_addr);
  90. /// \brief 获取特定ip和端口号
  91. static std::string GetIntranetAddr();
  92. /// \brief 获取日志回调函数
  93. static LogCallback GetLogCallback();
  94. /// \brief 设置日志回调
  95. static void SetLogCallback(const LogCallback log_callback);
  96. /// \brief 设置是否使用dns cache
  97. static void SetUseDnsCache(bool is_use_dns_cache);
  98. /// \brief 获取是否使用dns cache
  99. static bool GetUseDnsCache();
  100. /// \brief 设置dns cache过期时间
  101. static void SetDnsCacheExpireSeconds(unsigned expire_secondes);
  102. /// \brief 获取dns cache过期时间
  103. static unsigned GetDnsCacheExpireSeconds();
  104. /// \breif 设置dns cache大小
  105. static void SetDnsCacheSize(unsigned cache_size);
  106. /// \brief 获取dns cache大小
  107. static unsigned GetDnsCacheSize();
  108. private:
  109. // 打印日志:0,不打印,1:打印到屏幕,2:打印到syslog
  110. static LOG_OUT_TYPE m_log_outtype;
  111. // 日志级别:1: ERR, 2: WARN, 3:INFO, 4:DBG
  112. static LOG_LEVEL m_log_level;
  113. // 上传分片大小
  114. static uint64_t m_upload_part_size;
  115. // 上传分片大小
  116. static uint64_t m_upload_copy_part_size;
  117. // 本地时间戳与网络时间服务器时间戳的差值,计算方法:
  118. // delta = network_ts - local_ts
  119. static int64_t m_timestamp_delta;
  120. // 签名超时时间(秒)
  121. static uint64_t m_sign_expire_in_s;
  122. // Http连接超时时间(毫秒)
  123. static uint64_t m_conn_timeout_in_ms;
  124. // Http接收超时时间(毫秒)
  125. static uint64_t m_recv_timeout_in_ms;
  126. // 单文件分片并发上传线程池大小(每个文件一个)
  127. static unsigned m_threadpool_size;
  128. // 异步上传下载线程池大小(全局就一个)
  129. static unsigned m_asyn_threadpool_size;
  130. // 下载文件到本地线程池大小
  131. static unsigned m_down_thread_pool_size;
  132. // 下载文件到本地,每次下载字节数
  133. static unsigned m_down_slice_size;
  134. // 是否开启长连接
  135. static bool m_keep_alive;
  136. // 空闲多久后,发送keepalive探针,单位s
  137. static int64_t m_keep_idle;
  138. // 每个keepalive探针时间间隔,单位s
  139. static int64_t m_keep_intvl;
  140. // 下载时是否检查md5
  141. static bool m_is_check_md5;
  142. static std::string m_dest_domain;
  143. static bool m_is_domain_same_to_host;
  144. static bool m_is_use_intranet;
  145. static std::string m_intranet_addr;
  146. // 日志回调
  147. static LogCallback m_log_callback;
  148. // 是否使用dns cache
  149. static bool m_use_dns_cache;
  150. // dns cache过期时间
  151. static unsigned m_dns_cache_expire_seconds;
  152. // dns cache大小
  153. static unsigned m_dns_cache_size;
  154. };
  155. } // namespace qcloud_cos
  156. #endif