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

HostCache.h

Go to the documentation of this file.
00001 //
00002 // HostCache.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_HOSTCACHE_H__7F2764B0_BB17_4FF0_AF03_7BB7D4E22F7F__INCLUDED_)
00023 #define AFX_HOSTCACHE_H__7F2764B0_BB17_4FF0_AF03_7BB7D4E22F7F__INCLUDED_
00024 
00025 #pragma once
00026 
00027 class CHostCacheHost;
00028 class CNeighbour;
00029 class CG1Packet;
00030 class CVendor;
00031 
00032 
00033 class CHostCacheList
00034 {
00035 // Construction
00036 public:
00037         CHostCacheList(PROTOCOLID nProtocol);
00038         virtual ~CHostCacheList();
00039 
00040 // Attributes
00041 public:
00042         PROTOCOLID              m_nProtocol;
00043         DWORD                   m_nHosts;
00044         DWORD                   m_nCookie;
00045         CHostCacheHost* m_pNewest;
00046         CHostCacheHost* m_pOldest;
00047 protected:
00048         DWORD                   m_nBuffer;
00049         CHostCacheHost* m_pBuffer;
00050         CHostCacheHost* m_pFree;
00051         CHostCacheHost* m_pHash[256];
00052         
00053 // Operations
00054 public:
00055         CHostCacheHost* Add(IN_ADDR* pAddress, WORD nPort, DWORD tSeen = 0, LPCTSTR pszVendor = NULL);
00056         BOOL                    Add(LPCTSTR pszHost, DWORD tSeen = 0, LPCTSTR pszVendor = NULL);
00057         CHostCacheHost* Find(IN_ADDR* pAddress) const;
00058         BOOL                    Check(CHostCacheHost* pHost) const;
00059         void                    Remove(CHostCacheHost* pHost);
00060         void                    OnFailure(IN_ADDR* pAddress, WORD nPort);
00061         DWORD                   CountHosts() const;
00062         void                    PruneByQueryAck();                      // For G2
00063         void                    PruneOldHosts();                        // For G1
00064         void                    Clear();
00065         void                    Serialize(CArchive& ar, int nVersion);
00066         int                             Import(LPCTSTR pszFile);
00067         int                             ImportMET(CFile* pFile);
00068         int                             LoadDefaultED2KServers();
00069 protected:
00070         CHostCacheHost* AddInternal(IN_ADDR* pAddress, WORD nPort, DWORD tSeen, LPCTSTR pszVendor);
00071         void                    RemoveOldest();
00072         
00073 // Inlines
00074 public:
00075 
00076         inline CHostCacheHost* GetNewest() const
00077         {
00078                 return m_pNewest;
00079         }
00080 
00081         inline CHostCacheHost* GetOldest() const
00082         {
00083                 return m_pOldest;
00084         }
00085 
00086 };
00087 
00088 class CHostCacheHost
00089 {
00090 // Construction
00091 public:
00092         CHostCacheHost();
00093         
00094 // Attributes : Linkage
00095 public:
00096         CHostCacheHost* m_pNextHash;
00097         CHostCacheHost* m_pPrevTime;
00098         CHostCacheHost* m_pNextTime;
00099 
00100 // Attributes: Host Information
00101 public:
00102         PROTOCOLID      m_nProtocol;
00103         IN_ADDR         m_pAddress;
00104         WORD            m_nPort;
00105         CVendor*        m_pVendor;
00106         BOOL            m_bPriority;
00107         DWORD           m_nUserCount;
00108         DWORD           m_nUserLimit;
00109         DWORD           m_nFileLimit;
00110         CString         m_sName;
00111         CString         m_sDescription;
00112         DWORD           m_nTCPFlags;
00113         DWORD           m_nUDPFlags;
00114 
00115 // Attributes: Contact Times
00116 public:
00117         DWORD           m_tAdded;
00118         DWORD           m_tSeen;
00119         DWORD           m_tRetryAfter;
00120         DWORD           m_tConnect;
00121         DWORD           m_tQuery;
00122         DWORD           m_tAck;
00123         DWORD           m_tStats;                       // ED2K stats UDP request
00124         DWORD           m_tFailure;
00125         DWORD           m_nFailures;
00126 
00127 // Attributes: Query Keys
00128 public:
00129         DWORD           m_tKeyTime;
00130         DWORD           m_nKeyValue;
00131         DWORD           m_nKeyHost;
00132 
00133 // Operations
00134 public:
00135         void            Update(WORD nPort, DWORD tSeen = 0, LPCTSTR pszVendor = NULL);
00136         CNeighbour*     ConnectTo(BOOL bAutomatic = FALSE);
00137         CG1Packet*      ToG1Ping(int nTTL = 0, GGUID* pGUID = NULL);
00138         CString         ToString() const;
00139         BOOL            CanConnect(DWORD tNow = 0) const;       // Can we connect to this host now?
00140         BOOL            CanQuote(DWORD tNow = 0) const;         // Is this a recently seen host?
00141         BOOL            CanQuery(DWORD tNow = 0) const;         // Can we UDP query this host? (G2/ed2k)
00142         void            SetKey(DWORD nKey, IN_ADDR* pHost = NULL);
00143 protected:
00144         void            Serialize(CArchive& ar, int nVersion);
00145         void            Reset(IN_ADDR* pAddress);
00146 
00147         friend class CHostCacheList;
00148         friend class CHostCacheLinks;
00149 };
00150 
00151 
00152 class CHostCache
00153 {
00154 // Construction
00155 public:
00156         CHostCache();
00157 
00158 // Attributes
00159 public:
00160         CHostCacheList  Gnutella1;
00161         CHostCacheList  Gnutella2;
00162         CHostCacheList  eDonkey;
00163         CPtrList                m_pList;
00164 
00165 // Operations
00166 public:
00167         BOOL            Load();
00168         BOOL            Save();
00169         void            Clear();
00170 protected:
00171         void            Serialize(CArchive& ar);
00172 public:
00173         CHostCacheHost* Find(IN_ADDR* pAddress) const;
00174         BOOL                    Check(CHostCacheHost* pHost) const;
00175         void                    Remove(CHostCacheHost* pHost);
00176         void                    OnFailure(IN_ADDR* pAddress, WORD nPort);
00177 
00178 // Inlines
00179 public:
00180         inline CHostCacheList* ForProtocol(PROTOCOLID nProtocol)
00181         {
00182                 switch ( nProtocol )
00183                 {
00184                 case PROTOCOL_G1:
00185                         return &Gnutella1;
00186                 case PROTOCOL_G2:
00187                         return &Gnutella2;
00188                 case PROTOCOL_ED2K:
00189                         return &eDonkey;
00190                 default:
00191                         ASSERT(FALSE);
00192                         return NULL;
00193                 }
00194         }
00195 };
00196 
00197 extern CHostCache HostCache;
00198 
00199 #endif // !defined(AFX_HOSTCACHE_H__7F2764B0_BB17_4FF0_AF03_7BB7D4E22F7F__INCLUDED_)

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