00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #if !defined(AFX_DOWNLOADSOURCE_H__F0391D3E_0376_4F0F_934A_2E80260C4ECA__INCLUDED_)
00023 #define AFX_DOWNLOADSOURCE_H__F0391D3E_0376_4F0F_934A_2E80260C4ECA__INCLUDED_
00024
00025 #pragma once
00026
00027 #include "FileFragments.hpp"
00028
00029 class CDownload;
00030 class CDownloadTransfer;
00031 class CQueryHit;
00032 class CEDClient;
00033
00034 class CDownloadSource
00035 {
00036
00037 public:
00038 CDownloadSource(CDownload* pDownload);
00039 CDownloadSource(CDownload* pDownload, CQueryHit* pHit);
00040 CDownloadSource(CDownload* pDownload, DWORD nClientID, WORD nClientPort, DWORD nServerIP, WORD nServerPort, GGUID* pGUID = NULL);
00041 CDownloadSource(CDownload* pDownload, SHA1* pGUID, IN_ADDR* pAddress, WORD nPort);
00042 CDownloadSource(CDownload* pDownload, LPCTSTR pszURL, BOOL bSHA1 = FALSE, BOOL bHashAuth = FALSE, FILETIME* pLastSeen = NULL);
00043 virtual ~CDownloadSource();
00044 private:
00045 inline void Construct(CDownload* pDownload);
00046
00047
00048 public:
00049 CDownload* m_pDownload;
00050 CDownloadSource* m_pPrev;
00051 CDownloadSource* m_pNext;
00052 CDownloadTransfer* m_pTransfer;
00053 BOOL m_bSelected;
00054 public:
00055 CString m_sURL;
00056 PROTOCOLID m_nProtocol;
00057 BOOL m_bGUID;
00058 GGUID m_pGUID;
00059 IN_ADDR m_pAddress;
00060 WORD m_nPort;
00061 IN_ADDR m_pServerAddress;
00062 WORD m_nServerPort;
00063 public:
00064 CString m_sName;
00065 DWORD m_nIndex;
00066 BOOL m_bHashAuth;
00067 BOOL m_bSHA1;
00068 BOOL m_bTiger;
00069 BOOL m_bED2K;
00070 public:
00071 CString m_sServer;
00072 CString m_sNick;
00073 DWORD m_nSpeed;
00074 BOOL m_bPushOnly;
00075 BOOL m_bCloseConn;
00076 BOOL m_bReadContent;
00077 FILETIME m_tLastSeen;
00078 int m_nGnutella;
00079 BOOL m_bClientExtended;
00080 public:
00081 DWORD m_nSortOrder;
00082 int m_nColour;
00083 DWORD m_tAttempt;
00084 int m_nFailures;
00085 FF::SimpleFragmentList m_oAvailable;
00086 FF::SimpleFragmentList m_oPastFragments;
00087
00088
00089 public:
00090 BOOL ResolveURL();
00091 void Serialize(CArchive& ar, int nVersion);
00092 public:
00093 inline BOOL CanInitiate(BOOL bNetwork, BOOL bEstablished) const;
00094 void Remove(BOOL bCloseTransfer, BOOL bBan);
00095 void OnFailure(BOOL bNondestructive);
00096 void OnResume();
00097 public:
00098 void SetValid();
00099 void SetLastSeen();
00100 void SetGnutella(int nGnutella);
00101 BOOL CheckHash(const SHA1* pSHA1);
00102 BOOL CheckHash(const TIGEROOT* pTiger);
00103 BOOL CheckHash(const MD4* pED2K);
00104 public:
00105 BOOL PushRequest();
00106 BOOL CheckPush(GGUID* pClientID);
00107 BOOL CheckDonkey(CEDClient* pClient);
00108 public:
00109 void AddFragment(QWORD nOffset, QWORD nLength, BOOL bMerge = FALSE);
00110 void SetAvailableRanges(LPCTSTR pszRanges);
00111 BOOL HasUsefulRanges() const;
00112 BOOL TouchedRange(QWORD nOffset, QWORD nLength) const;
00113 int GetColour();
00114
00115 CDownloadTransfer* CreateTransfer();
00116
00117
00118 public:
00119 inline BOOL CDownloadSource::Equals(CDownloadSource* pSource) const
00120 {
00121 if ( m_bGUID && pSource->m_bGUID ) return m_pGUID == pSource->m_pGUID;
00122
00123 if ( m_nServerPort != pSource->m_nServerPort )
00124 {
00125 return FALSE;
00126 }
00127 else if ( m_nServerPort > 0 )
00128 {
00129 if ( m_pServerAddress.S_un.S_addr != pSource->m_pServerAddress.S_un.S_addr ) return FALSE;
00130 if ( m_pAddress.S_un.S_addr != pSource->m_pAddress.S_un.S_addr ) return FALSE;
00131 }
00132 else
00133 {
00134 if ( m_pAddress.S_un.S_addr != pSource->m_pAddress.S_un.S_addr ) return FALSE;
00135 if ( m_nPort != pSource->m_nPort ) return FALSE;
00136 }
00137
00138 return TRUE;
00139 }
00140
00141 };
00142
00143 #endif // !defined(AFX_DOWNLOADSOURCE_H__F0391D3E_0376_4F0F_934A_2E80260C4ECA__INCLUDED_)