Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

DownloadSource.h

Go to the documentation of this file.
00001 //
00002 // DownloadSource.h
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 // Construction
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 // Attributes
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;              // Does the user support extended (G2) functions? (In practice, this means can we use G2 chat, browse, etc...)
00080 public:
00081         DWORD                           m_nSortOrder;                   // How should this source be sorted in the list?
00082         int                                     m_nColour;
00083         DWORD                           m_tAttempt;
00084         int                                     m_nFailures;
00085     FF::SimpleFragmentList m_oAvailable;
00086     FF::SimpleFragmentList m_oPastFragments;
00087 
00088 // Operations
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 // Inlines
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_)

Generated on Thu Dec 15 10:39:40 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2