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

P2P编程

开发平台:

Visual C++

  1. // Upload.h: interface for the CUpload class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_UPLOAD_H__0488CF2F_D474_4738_9253_5BBA416475A1__INCLUDED_)
  5. #define AFX_UPLOAD_H__0488CF2F_D474_4738_9253_5BBA416475A1__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. #include "Connection.h"
  10. #include "StorageWrapper.h"
  11. #include "Measure.h"
  12. #include "Choker.h"
  13. class CDownloaderFeedback;
  14. class CUpload  
  15. {
  16. class CRequestsItem
  17. {
  18. public:
  19. CRequestsItem(long index, long begin, long length)
  20. {
  21. m_index = index;
  22. m_begin = begin;
  23. m_length = length;
  24. }
  25. long m_index;
  26. long m_begin;
  27. long m_length;
  28. };
  29. public:
  30. CUpload(CDownloaderFeedback* pDownloaderFeedback,
  31. CConnection* pconnection,
  32. CChoker* pchoker,
  33. CStorageWrapper* pstorage,
  34. long lMaxSliceLength,
  35. long lMaxRatePeriod,
  36. long lFudge);
  37. virtual ~CUpload();
  38. long get_rate();
  39. long get_total();
  40. bool has_queries();
  41. bool is_interested();
  42. bool is_choked();
  43. void unchoke();
  44. void choke();
  45. bool flushed();
  46. void got_cancel(long index, long begin, long length);
  47. void got_request(long index, long begin, long length);
  48. void got_interested();
  49. void got_not_interested();
  50. private:
  51. CConnection* m_pconnection;
  52. CStorageWrapper* m_pstorage;
  53. long m_lMaxSliceLength;
  54. long m_lMaxRatePeriod;
  55. bool m_bChoked;
  56. bool m_bInterested;
  57. vector <CRequestsItem> m_vBuffer;
  58. CMeasure m_Measure;
  59. // for feedback
  60. CDownloaderFeedback* m_pDownloaderFeedback;
  61. long m_lAddr;
  62. short m_sPort;
  63. };
  64. class CUploader
  65. {
  66. public :
  67. CUploader(CDownloaderFeedback* pDownloaderFeedback, CStorageWrapper* pstorage, CChoker* pchoker,long lMaxSliceLength, long lMaxRatePeriod, long lFudge);
  68. CUpload* make_upload(CConnection* pconnection);
  69. private:
  70. CChoker* m_pChoker;
  71. CStorageWrapper* m_pstorage;
  72. long m_lMaxSliceLength;
  73. long m_lMaxRatePeriod;
  74. long m_lFudge;
  75. // for feedback
  76. CDownloaderFeedback* m_pDownloaderFeedback;
  77. };
  78. #endif // !defined(AFX_UPLOAD_H__0488CF2F_D474_4738_9253_5BBA416475A1__INCLUDED_)