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

P2P编程

开发平台:

Visual C++

  1. // Connector.h: interface for the CConnector class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_CONNECTOR_H__8E8443EF_9C62_41C9_947E_3AE7E12ABBC3__INCLUDED_)
  5. #define AFX_CONNECTOR_H__8E8443EF_9C62_41C9_947E_3AE7E12ABBC3__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. class CConnection;
  10. class CEncryptedConnection;
  11. class CDownloader;
  12. class CUploader;
  13. class CStorageWrapper;
  14. class CMeasure;
  15. class CChoker;
  16. class CAddrPort;
  17. class CConnector  
  18. {
  19. public:
  20. CConnector(long lMaxUploadRate);
  21. virtual ~CConnector();
  22. void Create(CDownloader* pDownloader, CUploader* pUploader, CChoker* pchoker, 
  23. long lNumPieces, CStorageWrapper* pStorage, CMeasure* pUpTotalMeasure );
  24. long how_many_connections();
  25. void connection_flushed(CEncryptedConnection* pEConnection);
  26. void connection_made(CEncryptedConnection* pEConnection);
  27. void connection_lost(CEncryptedConnection* pEConnection);
  28. void got_message(CEncryptedConnection* pEConnection, memstream& memMessage);
  29. void _update_upload_rate(long lAmount);
  30. bool IsRatecap();
  31. void uncap();
  32. void SetMaxUploadRate(long lMaxUploadRate);
  33. void PausePeer(CAddrPort addrPort, bool bPause = true);
  34. void ClosePeer(CAddrPort addrPort);
  35. void OnIdle();
  36. const CDownloader* const GetDownloader() const;
  37. const CMeasure* const GetUpTotalMeasure() const;
  38. vector<CConnection*> m_connections;
  39. private:
  40. void _OnIdle(vector<CAddrPort>& vToPause, vector<CAddrPort>& vToContinue, vector<CAddrPort>& vToClose);
  41. void check_endgame();
  42. // data
  43. CDownloader* m_pDownloader;
  44. CUploader* m_pUploader;
  45. CStorageWrapper* m_pStorage;
  46. CMeasure* m_pUpTotalMeasure;
  47. CChoker* m_pChoker;
  48. long m_lNumPieces;
  49. long m_lMaxUploadRate;
  50. bool m_bEndgame;
  51. bool m_bRateCapped;
  52. time_t m_tTimeUntilUncap;
  53. time_t m_tcap;
  54. vector<CAddrPort> m_vToPause;
  55. vector<CAddrPort> m_vToContinue;
  56. vector<CAddrPort> m_vToClose;
  57. CCriticalSection m_criticalSection;
  58. };
  59. #endif // !defined(AFX_CONNECTOR_H__8E8443EF_9C62_41C9_947E_3AE7E12ABBC3__INCLUDED_)