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

P2P编程

开发平台:

Visual C++

  1. // Rerequester.h: interface for the CRerequester class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_REREQUESTER_H__79411383_1CEA_45EC_92A2_D1B53A363000__INCLUDED_)
  5. #define AFX_REREQUESTER_H__79411383_1CEA_45EC_92A2_D1B53A363000__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. #include <afxinet.h>
  10. #include "memstream.h"
  11. #include "Encrypter.h"
  12. class CConnector;
  13. class CStorageWrapper;
  14. class CMeasure;
  15. class CDownloaderFeedback;
  16. #define REQ_STARTED 0
  17. #define REQ_COMPLETED 1
  18. #define REQ_STOPPED 2
  19. #define REQ_QUERY 3
  20. class CRerequesterSingle
  21. {
  22. public:
  23. CRerequesterSingle();
  24. ~CRerequesterSingle();
  25. bool OpenUrlEx(string strUrl, HANDLE hHttpDone, long lEvent);
  26. int GetResult(string& strErr);
  27. void WaitTerminate();
  28. memstream m_RetStream;
  29. long m_lEvent;
  30. private:
  31. static DWORD WINAPI SendRequestProc(void *pParam);
  32. void SendRequest();
  33. void OpenUrl(string strUrl, memstream& buf);
  34. HANDLE m_hHttpDone;
  35. HANDLE m_hDone;
  36. CInternetSession m_session;
  37. string m_strUrl;
  38. bool m_iResult;
  39. string m_strErr;
  40. };
  41. class CRerequester  
  42. {
  43. public:
  44. CRerequester(long lConnectErrorMax, long lConnectIntval, long minpeers, long maxpeers);
  45. void Create(CDownloaderFeedback* pMain,CStorageWrapper* pStorageWrapper, CMeasure* pupmeasure,  CMeasure* pdownmeasure, 
  46. CConnector* pConnector, CEncrypter* pEncrypter, string strUrl, long port, string strIP, 
  47. char* pMyId, char* pInfoHash, long interval, 
  48. long lTimeOut, HANDLE hevDone);
  49. virtual ~CRerequester();
  50. void SetConnectErrorMax(long lConnectErrorMax, long lConnectIntval, long minpeers, long maxpeers);
  51. void AnnounceEx(long lEvent = REQ_QUERY);
  52. void PostExcute();
  53. void Excute();
  54. void Close();
  55. HANDLE GetHttpEvent();
  56. private:
  57. void announce(long lEvent = REQ_QUERY);
  58. bool postrequest();
  59. CDownloaderFeedback* m_pMain;
  60. CStorageWrapper* m_pStorageWrapper;
  61. CMeasure* m_pupmeasure;
  62. CMeasure* m_pdownmeasure;
  63. CConnector* m_pConnector;
  64. CEncrypter* m_pEncrypter;
  65. string m_strUrl;
  66. long m_minpeers;
  67. long m_maxpeers;
  68. long m_lTimeOut;
  69. HANDLE m_hevDone;
  70. long m_lAannounce_interval;
  71. long m_lInterval;
  72. string m_strTrackerid;
  73. long m_lLast;
  74. long m_lFileCount;
  75. long m_lConnectErrorMax;
  76. long m_lConnectIntval;
  77. HANDLE m_hHttpDone;
  78. time_t m_tLast;
  79. time_t m_tStartLast;
  80. bool m_never_succeeded;
  81. bool m_bStarted;
  82. vector<long> m_commands;
  83. bool m_bCommand;
  84. vector<CRerequesterSingle*> m_vSingles;
  85. CRerequesterSingle* m_pSingle;
  86. };
  87. #endif // !defined(AFX_REREQUESTER_H__79411383_1CEA_45EC_92A2_D1B53A363000__INCLUDED_)