SingleDownload.h
资源名称:GGBT.rar [点击查看]
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:3k
源码类别:
P2P编程
开发平台:
Visual C++
- // SingleDownload.h: interface for the CSingleDownload class.
- //
- //////////////////////////////////////////////////////////////////////
- #if !defined(AFX_SINGLEDOWNLOAD_H__ED8FB68A_724C_4B21_AB2A_DE37B7932B3C__INCLUDED_)
- #define AFX_SINGLEDOWNLOAD_H__ED8FB68A_724C_4B21_AB2A_DE37B7932B3C__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- #include "Measure.h"
- class CDownloader;
- class CConnection;
- class CDownloaderFeedback;
- class CRequestsItem
- {
- public:
- CRequestsItem(long index, long begin, long length)
- {
- m_index = index;
- m_begin = begin;
- m_length = length;
- }
- bool operator == (CRequestsItem& other)
- {
- if (m_index == other.m_index &&
- m_begin == other.m_begin &&
- m_length == other.m_length)
- return true;
- return false;
- }
- long m_index;
- long m_begin;
- long m_length;
- };
- class CSingleDownload
- {
- public:
- CSingleDownload(CDownloaderFeedback* pDownloaderFeedback,CDownloader* pDownloader, CConnection* pConnection);
- virtual ~CSingleDownload();
- void got_have_bitfield(vector<bool>& vHave);
- void got_have(long index);
- bool got_piece(long index,long begin, memstream& memPiece);
- void got_unchoke();
- void got_choke();
- void disconnected();
- bool is_snubbed();
- long get_rate();
- long get_total();
- bool is_interested();
- bool is_choked();
- float GetHaveCountPercent();
- void get_have(vector<bool>& vHave) ;
- long get_have_count() const;
- void get_new_have(vector<bool>& vHave);
- void download_more(vector<long>& vPieces = vector<long>());
- // for endgame.
- void cancel_endgame();
- void make_endgame(vector<CRequestsItem>& vRequests);
- void mak_endgameflush();
- private:
- void _check_interest(vector<long>& vHit);
- void _lost_interest(vector<long>& vHit);
- void _d(vector<long>&vPieces, vector<long>& vHit);
- void _letgo();
- CDownloader* m_pDownloader;
- CConnection* m_pConnection;
- bool m_bChoked;
- bool m_bInterested;
- vector<CRequestsItem> m_vActiveRequests;
- CMeasure m_measure;
- vector<bool> m_vHave;
- time_t m_tLast;
- // for endgame.
- void send_request_end(long index, long begin, long length);
- void got_have_bitfield_end(vector<bool>& vHave);
- void got_have_end(long index);
- bool got_piece_end(long index,long begin, memstream& memPiece);
- void got_unchoke_end();
- void got_choke_end();
- void disconnected_end();
- void SendCancel(long index, long begin, long length, CSingleDownload* pOwner);
- bool m_bEndgame;
- long m_lHave;
- // for feedback
- CDownloaderFeedback* m_pDownloaderFeedback;
- long m_lAddr;
- short m_sPort;
- vector<long> m_vNewHave;
- };
- #endif // !defined(AFX_SINGLEDOWNLOAD_H__ED8FB68A_724C_4B21_AB2A_DE37B7932B3C__INCLUDED_)