http_cdn.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #pragma once
  2. #include "http_define.h"
  3. #include "http_reqpack.h"
  4. #include "http_interface.h"
  5. #include "http_client_plus.h"
  6. #include "util/thread.h"
  7. namespace ylib
  8. {
  9. namespace network
  10. {
  11. namespace http
  12. {
  13. class cnode :public ylib::error_base
  14. {
  15. public:
  16. cnode(const cdn_config::node_config& config);
  17. ~cnode();
  18. const cdn_config::node_config& config() { return m_config; }
  19. int score();
  20. bool update();
  21. private:
  22. network::http::client_plus m_client;
  23. private:
  24. cdn_config::node_config m_config;
  25. // 管理地址
  26. std::string m_mang_url;
  27. // 回复耗时
  28. timestamp m_reply_wait_msec;
  29. // 当前带宽上传
  30. uint64 m_send_bytes_sec;
  31. // 当前带宽下载
  32. uint64 m_recv_bytes_sec;
  33. // 更新时间
  34. timestamp m_update_sec;
  35. // 通信状态
  36. bool m_net_status;
  37. // 通信状态错误描述
  38. std::string m_net_errormsg;
  39. // 最大带宽
  40. uint64 m_max_band;
  41. };
  42. class cdn :public network::http::interface_, public ylib::error_base, private ylib::ithread
  43. {
  44. public:
  45. cdn();
  46. ~cdn();
  47. bool start(const cdn_config& config);
  48. void close();
  49. std::string host();
  50. virtual bool run() override;
  51. const cdn_config& config() { return m_config; }
  52. private:
  53. cdn_config m_config;
  54. std::vector<network::http::cnode*> m_nodes;
  55. std::string m_cdn_node_key;
  56. uint64 m_cdn_node_max_band;
  57. ylib::BandInfo m_cdn_node_bandinfo;
  58. };
  59. }
  60. }
  61. }