DownloaderFeedback.h
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:6k
源码类别:

P2P编程

开发平台:

Visual C++

  1. // DownloaderFeedback.h: interface for the CDownloaderFeedback class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_DOWNLOADERFEEDBACK_H__80149D16_CB00_4E69_8B28_ED7F94457FC3__INCLUDED_)
  5. #define AFX_DOWNLOADERFEEDBACK_H__80149D16_CB00_4E69_8B28_ED7F94457FC3__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. #include "Connection.h"
  10. class CConnector;
  11. class CDownload;
  12. class CConncetionData
  13. {
  14. public:
  15. CConncetionData()
  16. {
  17. m_lAddr = 0;
  18. m_sPort = 0;
  19. m_bLocallyInitiated = 0;
  20. m_lUpRate = 0;
  21. m_lDownRate = 0;
  22. m_lDownCount = 0;
  23. m_lUpCount = 0;
  24. m_bInterested = 0;
  25. m_bInteresting = 0;
  26. m_bChoked = 0;
  27. m_bChoking = 0;
  28. m_fPeerHavePercent = 0;
  29. m_bPaused = 0;
  30. m_lIndex = 0;
  31. memset(m_lValueUp, 0, CConnection::eCount*sizeof(long));
  32. memset(m_lValueDown, 0, CConnection::eCount*sizeof(long));
  33. }
  34. bool operator != (const CConncetionData& other) const
  35. {
  36. return !(*this == other);
  37. }
  38. bool operator == (const CConncetionData& other) const
  39. {
  40. if (
  41. m_lAddr != other.m_lAddr ||
  42. m_sPort != other.m_sPort ||
  43. m_bLocallyInitiated != other.m_bLocallyInitiated ||
  44. m_lUpRate != other.m_lUpRate ||
  45. m_lDownRate != other.m_lDownRate ||
  46. m_lDownCount != other.m_lDownCount ||
  47. m_lUpCount != other.m_lUpCount ||
  48. m_bInterested != other.m_bInterested ||
  49. m_bInteresting != other.m_bInteresting ||
  50. m_bChoked != other.m_bChoked ||
  51. m_bChoking != other.m_bChoking ||
  52. m_fPeerHavePercent != other.m_fPeerHavePercent ||
  53. m_bPaused != other.m_bPaused
  54. )
  55. {
  56. return false;
  57. }
  58. return true;
  59. }
  60. /*
  61. CConncetionData(CConncetionData* pData)
  62. {
  63. *this = pData;
  64. }
  65. CConncetionData& operator = (CConncetionData* pData)
  66. {
  67. assert(pData);
  68. m_lAddr = pData->m_lAddr;
  69. m_sPort = pData->m_sPort;
  70. m_bLocallyInitiated = pData->m_bLocallyInitiated;
  71. m_lUpRate = pData->m_lUpRate ;
  72. m_lDownRate = pData->m_lDownRate ;
  73. m_lDownCount = pData->m_lDownCount ;
  74. m_lUpCount = pData->m_lUpCount ;
  75. m_bInterested = pData->m_bInterested ;
  76. m_bInteresting = pData->m_bInteresting ;
  77. m_bChoked = pData->m_bChoked ;
  78. m_bChoking = pData->m_bChoking ;
  79. m_fPeerHavePercent = pData->m_fPeerHavePercent ;
  80. m_bPaused = pData->m_bPaused;
  81. return *this;
  82. }
  83. //*/
  84. long m_lAddr;
  85. short m_sPort;
  86. bool m_bLocallyInitiated;
  87. long m_lUpRate;
  88. long m_lDownRate;
  89. long m_lDownCount;
  90. long m_lUpCount;
  91. bool m_bInterested;
  92. bool m_bInteresting;
  93. bool m_bChoked;
  94. bool m_bChoking;
  95. float m_fPeerHavePercent;
  96. bool m_bPaused;
  97. string m_strPeerId;
  98. long m_lValueUp[CConnection::eCount];
  99. long m_lValueDown[CConnection::eCount];
  100. long m_lIndex;
  101. vector<bool> m_vHave;
  102. // 对方是否优先传送。
  103. // 该站点总下载速度。
  104. };
  105. class CStatics
  106. {
  107. public:
  108. CStatics()
  109. {
  110. m_fCompletedPart = 0;
  111. m_fCompleted = 0;
  112. m_lSeedsCount = 0;
  113. m_lDownRate = 0;
  114. m_lUpRate = 0;
  115. m_tTimeLeft= 0;
  116. m_lPeersCount = 0;
  117. m_tTimeRunned = 0;
  118. m_fCheckingPercent = 0;
  119. m_bStorageChecking = true;
  120. m_fAllocatingPercent = 0;
  121. m_bAllocating = false;
  122. m_bTrackerConnected = false;
  123. m_bFired = false;
  124. m_bCheckingDone = false;
  125. }
  126. float m_fCompletedPart;
  127. float m_fCompleted;
  128. long m_lPeersCount;
  129. long m_lSeedsCount;
  130. long m_lDownRate;
  131. long m_lUpRate;
  132. time_t m_tTimeLeft;
  133. time_t m_tTimeRunned;
  134. float m_fCheckingPercent;
  135. bool m_bStorageChecking;
  136. bool m_bCheckingDone;
  137. float m_fAllocatingPercent;
  138. bool m_bAllocating;
  139. bool m_bTrackerConnected;
  140. bool m_bFired;
  141. };
  142. class CSystemMsg
  143. {
  144. public:
  145. enum eMSG_TYPE{eMsgOut, eMsgIn, eCmd, eBad} m_eMsgType;
  146. CSystemMsg(time_t t, string strMsg, eMSG_TYPE eMsgType)
  147. {
  148. m_time = t;
  149. m_strMsg = strMsg;
  150. m_eMsgType = eMsgType;
  151. }
  152. time_t m_time;
  153. string m_strMsg;
  154. };
  155. #define DOWNLOAD_TERMINATED (WM_USER+1012)
  156. #define STORAGE_CHECK_COMPLETE (WM_USER+1013)
  157. class CDownloaderFeedback  
  158. {
  159. public:
  160. CDownloaderFeedback();
  161. virtual ~CDownloaderFeedback();
  162. void SetCompleteKeepSeedHour(long lCompleteKeepSeedHour);
  163. void SetDownload(CDownload* pDownload, HTREEITEM curItem, HWND hFeedbackwnd, time_t tKeepSeedTime, long lParam);
  164. void Create(CConnector* pConnector, long lPutDataTimeSpan);
  165. void Completed();
  166. void data_flunked(long lAmount);
  167. void PartCompleted();
  168. void PutRunParameter(long lPort);
  169. void GetRunParameter(long& lPort);
  170. bool IsStorageChecking();
  171. void TrackerConnected();
  172. void SetStorageAllocating(bool bAllocating, float fAllocatingPercent = 0);
  173. void SetStorageChecking(bool bStorageChecking, float fCheckingPercent = 0);
  174. void SetCheckingDone(float fCompleted, float fPartCompletedPercent);
  175. void PutDataTime();
  176. vector<CConncetionData>& GetData();
  177. CStatics& GetStatics();
  178. void ClearSystemMessage();
  179. void ShowSystemMessage(string strMsg, CSystemMsg::eMSG_TYPE eMsgType);
  180. void GetSystemMessage(vector<CSystemMsg>& vMsg);
  181. void ShowSocketMessage(long lAddr, short sPort, string strMsg);
  182. string GetSocketMessage(long lAddr, short sPort);
  183. string GetSocketMessageAll();
  184. void ShowEncryptedMessage(string strMsg);
  185. void errorFunc(string e);
  186. string GetBadMsg();
  187. bool IsBad();
  188. void GetFractions(vector<long>& vFractions);
  189. void PutFractionsState(long lFractionInx, long lState);
  190. void PutFractions(const vector<bool>& vHaves);
  191. void QuitDownload();
  192. void StorageCheckComplete();
  193. void SetBadMsg(string strBad, bool bSendMessage = true);
  194. private:
  195. void SetCompleteMsg(string strMsg);
  196. void PutStatics();
  197. void PutData();
  198. CDownload* m_pDownload;
  199. clock_t m_lPutDataTimeSpan;
  200. clock_t m_lLast;
  201. time_t m_tStart;
  202. time_t m_tCompleted;
  203. time_t m_tKeepSeedTimeHour;
  204. // bool m_bCompleteKeepSeed;
  205. CConnector* m_pConnector;
  206. vector<CConncetionData> m_vConnectionDatas;
  207. map<CAddrPort, vector<string> > m_mapMsg;
  208. vector<CSystemMsg> m_vSystemMsg;
  209. CStatics m_statics;
  210. long m_lSystemMsgMaxCount;
  211. long m_lPort;
  212. bool m_bBad;
  213. string m_strBad;
  214. vector<long> m_vFractions;
  215. long m_lParam;
  216. HTREEITEM m_curItem;
  217. HWND m_hFeedbackwnd;
  218. CCriticalSection m_criticalSection;
  219. };
  220. #endif // !defined(AFX_DOWNLOADERFEEDBACK_H__80149D16_CB00_4E69_8B28_ED7F94457FC3__INCLUDED_)